Hi Everybody, I have been recruited as a programmer for my school robotics team for the upcoming robotics ring it up competition. I have been programming the autonomous portion of the competition and have everything working except for one last thing. First Heres the basics of our program so you can understand the problem. Basically there are 3 positions that our bot could potentially have to drive to, so we decided that the easiest way forward would be to have 3 sets of preset instructions for the bot to drive to and it would use the IRSeeker to decide which set of instructions to run. So basically if the seeker detects the bot is to the left, do this, if its to the right, do this, and if its straight ahead of you do this. This all should work fine in theory but the problem is I dont know how to say IF you detect the sensor is to the right (for example) THEN and NOTHING ELSE. The problem is the sensor will detect the signal is to the right start moving and then detect the sensor is straight ahead or to the left and try to do that set of instructions. So how do I tell my sensor IF this THEN that but ONLY that and forget the rest of the code?
Wed Jan 16, 2013 4:57 pm
amcerbu
Novice
Joined: Sun Oct 21, 2012 10:01 pm Posts: 76
Re: Help With An Autonomous Programming Problem
I think you're looking for the else-if statement.
Code:
task main() { waitForStart(); wait10Msec(20); // Wait a little.
int IRVal = SensorValue(IRSeeker);
if (IRVal < 5) { // All driving code for left column } else if (IRVal > 5) { // All driving code for right column } else { // All driving code for center } }
Wed Jan 16, 2013 5:47 pm
Timtempor
Rookie
Joined: Wed Jan 16, 2013 4:45 pm Posts: 2
Re: Help With An Autonomous Programming Problem
Well, I guess I just thought that would do the exact same thing as \
Code:
If { // All driving code for left column } if (IRVal > 5) { // All driving code for right column } if { // All driving code for center } }
But that seems to work for me so far, thank you SO much, should of tried that earlier.
Users browsing this forum: No registered users and 6 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum