Skip to content

OOPS!

February 24, 2011

Well, I accidentally uploaded some code that doesn’t even compile. :facepalm: I am very, very sorry about that.

This code, however, not only works but also works well:
int x, x1, x2;
int new_x;
task main(){
SetSensorLight(S2, true);
PlayTone(440, 25);
Wait(625);
PlayTone(440, 25);
Wait(625);
PlayTone(600, 50);
x1 = SensorRaw(S2);
x2 = SensorRaw(S2);
x = (x1 + x2)/2;
while(true){
OnFwd(OUT_BC, ((1023 – ((x – ((GetOutput(OUT_B, RotationCount) / 128)) – (SensorRaw(S2)))) * 4) ^ (1/2)));
}
}

While I’m still tweaking some of the values (128 and 4, to be specific), this works better than I had ever imagined, for a few reasons. First, I am not a programmer; I am a newbie. Second, The light sensor programs I’ve seen and ran before didn’t work as well, but they were implementing full PID so they ran a little slower. Third, I’ve never done anything other than just P before, so adding my version of I was…. frustrating.

P.S. This setup is for a Light Sensor placed near the robot. A new one with the sensor farther away is in the works as well.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: