|
What you should do in instances like this is write psuedo-code in english. You should try this:
If the middle sensor is on, then I want to go straight.
If only the left sensor is on, then I want to turn left.
If only the right sensor is on, then I want to turn right.
If no sensors are on, then spin in a circle.
Now, go on to write your code:
If (rc_sw2) then gostraight
If (rc_sw1)&(rc_sw3 = 0) then turnleft
If (rc_sw3)&(rc_sw1 = 0) then turnright
goto turnleft
gostraight:
p1_x = 127
p1_y = 200 'random forward speed, should be tested on bot
goto restofcode
turnleft:
p1_x = 84
p1_y = 127
goto restofcode
turnright:
p1_x = 200
p1_y = 127
restofcode:
...
...
...
serout ...
__________________
"What most people do not understand is that the Buddha, the Godhead, resides just as comfortably in gears and circuits as in hills and trees. To believe otherwise is to dilute the Godhead."
-Robert Pirsig, Zen and the Art of Motorcycle Maintenance
|