
Rural Geek
Hey every one. I am trying to write my first script to work on a rolling chassis. I have three pings across the front and a sharp ir sensor under it at the front to keep from going over the edge.
I have three Distance detects open one for each ping ( which are parallax) and a sharp ir collision detect open for the ir sensor.
Here is my script and it will not stop the bot when I sensor is reading less than 40 or greater than 40 on the ir sensor.
# This the main forward script
:100
# this will get the ping data and
# and put it into a variable
$MAIN_PING = GetPing(d0,d0)
$LEFT_PING = GetPing(d1,d1)
$RIGHT_PING = GetPing(d2,d2)
#Using the Sharp sensor for edge detection and
#put the data into a variable
$FRONT_EDGE = GetADC(adc3)
Forward()
If($MAIN_PING = 40)
Stop
Else
If($MAIN_PING => 41), If($LEFT_PING => 41), If($RIGHT_PING => 41)
goto(100)
I dont get any syntax errors when i debug slow it runs to the first "if" line and that is it the bot just goes forward.
Any ideas on what I am messing up here.
Thanks
If statements with a state check require an elseif statement "elseif($mainping => 40)" you then need to give a result (do something about it).
elseif($main_ping => 40)
Stop()
Elseif($left_ping => 40)
Stop()
...
Each should be a separate statement.
My .02 cents. I'm not a programmer, but I thnk this syntax is correct.
If($MAIN_PING 40)
Please post the working code. I'd love to see it.
Try using the UBB code - Code (as seen when you look at the right side of your screen). Place your code between the [code] brackets where it says "text".
Here is the code. i am having some major brain farts today.
Code:
Now the problem is that the stop() is running on its own not after the if statement is true. it runs through all the code so it just starts and stops. I only want it to stop if the first "if" triggers it to stop.