Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Bug in IR sensor code (http://www.chiefdelphi.com/forums/showthread.php?t=18007)

Tazlikesrobots 16-02-2003 00:53

Bug in IR sensor code
 
I got a problem with my IR sensors code. Everything works ok until the robot reaches the end of the white line. I thought i'd be cleaver and wrote an if statement that says if rc_sw 1,2 & 3 =0 then go straight, however the robot goes into a left hand loop.

Any help or suggestions would be greatly appreciated!!

Here is the code I wrote:

FullAutoMode:

if rc_sw2=1 then straight:
if rc_sw1=1 & rc_sw3=0 then turnleft:
if rc_sw3=1 & rc_sw1=0 then turnright:
if rc_sw1 & rc_sw2 & rc_sw3=0 then straight:
goto endir:
straight:
debug "staight",cr
p1_y = 234
p3_y = 254
goto endir:

turnleft:
debug "left",cr
p1_y = 84
p3_y = 127
goto endir:

turnright:
debug "right",cr
p1_y = 127
p3_y = 84
goto endir:





KillAuto:

endir:

rbayer 16-02-2003 01:40

I believe the problem is centered around improper use of the &. Try replacing them with the keyword AND as well as splitting up that last if into multiple equlaties joined with the AND keyword.

Gadget470 16-02-2003 02:03

Code:

if rc_sw2=1 then straight:
if rc_sw1=1 AND rc_sw3=0 then turnleft:
if rc_sw3=1 AND rc_sw1=0 then turnright:
if rc_sw1=0 AND rc_sw2=0 AND rc_sw3=0 then straight:


Tazlikesrobots 16-02-2003 13:48

Thanks for the help. It does not make a whole lot of sence since "&" and "and" are the same thing, however it works now!


_______________
Very funny Scottie....NOW BEAM DOWN MY CLOTHES!

rbayer 16-02-2003 13:52

Quote:

Originally posted by Tazlikesrobots
Thanks for the help. It does not make a whole lot of sence since "&" and "and" are the same thing, however it works now!

They actually aren't AND is the logical version (like C's && if that helps) whereas & is the bitwise version (like C's &). For more detail, see this post.

Taking your previous code, assume sw1=1, sw2=0, sw3=1. Evaluate left to right:

sw1 & sw2 & sw3 => 1 & 0 & 1, which is 0. Then apply the comparison evaluator, 0=0, which evaluates to true. Thus if any of the switches are 0, this will evaluate to true.

Tazlikesrobots 16-02-2003 18:38

Oh! I understand now! I just had an id-10-t error!

Once again, thanks for your input.


All times are GMT -5. The time now is 04:28.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi