
Hey guys.
Can someone assist me with the following script please. What I'm trying to do is to create a ramp down speed script for a Roomba, so that when an ultrasonic ping sensor detects an object, the Roomba slows down before it reaches the object, then turns away. Basicly I am trying to mimic the "Light touch" option the Roomba uses, but using a ping sensor. Here's what I have so far (which, due to my shoddy scripting skills, is not working)...Code:
$currentdistance = GetPing(D13, D14)
:loop
if($currentdistance<40)
uartWrite(0,1,137,0,150,128,0)
sleep(10)
elseif($currentdistance<38)
uartWrite(0,1,137,0,140,128,0)
sleep(10)
elseif($currentdistance<36)
uartWrite(0,1,137,0,130,128,0)
sleep(10)
elseif($currentdistance<34)
uartWrite(0,1,137,0,120,128,0)
sleep(10)
elseif($currentdistance<32)
uartWrite(0,1,137,0,110,128,0)
sleep(10)
elseif($currentdistance<30)
uartWrite(0,1,137,0,150,255,255) #Roomba turns to avoid object.
sleep(1000)
endif
goto(loop)
As always, I would be grateful for any help.
Thanks.
My speed ramping example is modular and uses multiple scripts to work but it's all commented and explained so should be easy enough to modify.
Sabertooth Ramping
I had a look at it earlier, and even though you have documented it well, I just couldn't get a hang on it, and couldn't get it to work the way I wanted with various changes made. So I attempted to try something different myself which is what I posted above.
Edit: never mind. Your already doing that with the variable.
Code:
How do I stop the loop from looping when the last "Stop" command is met? At the moment I have it set for 10 seconds, but would like to stop it completely.
The first line of code checks if the distance is less than 40. If it is less than 40 then it executes the uartWrite(0,1,137,0,150,128,0) and then sleep(10)
Since you are using elseif, if the first if is true, then the next elseif won't run. So in your case whenever the distance is less than 40 it only runs the first bit of code. To fix this just reverse the order that you check the distances in.
It would look like this
Code:
I think that should work.
Hopefully that made sense
Thanks for the reply. Yep, it did make sense thanks. I took out the Elseifs and just used Ifs instead which seems to be working, but I'll try your idea as well.
Thanks.