Balancing bot, one line of code
Alright, so a few things: this title might have grabbed your attention by making you think that my balancing bot program is only one line of code. This isn’t entirely accurate. (And yes, I could delete all the whitespace, but that’s cheating.)
The part of the code that runs the balancing process is, indeed, on one line. In fact, it’s one math statement.
While it’s not yet perfect (it needs an ever-so-gentle guiding hand), it’s almost there. Of course, it’s using the Light Sensor, so what would you expect….
here’s my current code:
int x, x1, x2;
x1 = SensorRaw(S2);
x2 = SensorRaw(S2);
x = (x1 + x2)/2;
OnFwd(OUT_BC, (1023 – ((x-(GetOutput(OUT_B, RotationCount))/7) – SensorRaw(S2)))*2); //PI
Obviously I don’t have a full PID algorithm, just P and most of I (but I’m doing it my own way rather than using a bunch of variables, so it runs… differently).
I still need to work out a few things, but I think I’m almost there.