Asked — Edited

Could Use Some More Scripting Help. Again

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


ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

#1  

I am going to make a wild a$$ guess(looking for the correct answer too), and suggest that you should remove all the Ifs following the Else and replace with Elses. Also not sure the commas are correct and the Elses should be on their own lines........my less the one cent(canadian) worth :)

#2  

Stop needs to read stop()

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.

#4  

Thanks guys i figured it out. you can use one if, and use and-or in the statement.

If($MAIN_PING 40)

#5  

@Rural Geek,

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

 brackets where it says "text".
#6  

Dave

Here is the code. i am having some major brain farts today.

# 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(50)

 If($MAIN_PING  41)
   stop()

 If($MAIN_PING > 41 or $LEFT_PING > 41 or $RIGHT_PING > 41 or $FRONT_EDGE < 41)
    Goto(100)

Sleep(100)

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.

#7  

You know what I think some of my problem is this computer I was mucking about with win7 and not i am having trouble. its not posting the all of the code right no matter how I write it and i cant type a bunch of characters. i am going to try my xp unit and see if I have better luck. confused :(