Skip to content

Balancing bot, one line of code

February 23, 2011

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;
int new_x;
task main(){
SetSensorLight(S2, true);
PlayTone(440, 25);
PlayTone(440, 25);
PlayTone(600, 50);
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.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: