United Kingdom
Asked — Edited
Resolved Resolved by Rich!

Ramp Down Speed Script Help For Roomba 530

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)...

$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.


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

United Kingdom
#1  

Check my speed ramping with a sabertooth example and adjust the serial commands to suit.

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

United Kingdom
#2  

Thanks Rich.

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.

#3  

I may be wrong but try putting your GetPing with a short Sleep inside of the loop. I think you may need to have the script relook where the Robot is each time it loops.

Edit: never mind. Your already doing that with the variable.

United Kingdom
#4  

Thanks anyway Dave. No, it's the main body of the script itself. It recognises the first IF, but ignores the rest. Like I say, my scripting knowledge is still pretty weak as I don't have much free time to learn it anymore. But I keep plugging away at it when I get the chance.

United Kingdom
#5  

Okay. So I had a further play about and got this that works...

:loop

$currentdistance = GetPing(D13, D14)
if($currentdistance<50)
uartWrite(0,1,137,0,180,128,0) #forward fast
sleep(200)

if($currentdistance<48)
uartWrite(0,1,137,0,140,128,0)
sleep(200)

if($currentdistance<46)
uartWrite(0,1,137,0,130,128,0) #forward fast
sleep(200)

if($currentdistance<44)
uartWrite(0,1,137,0,120,128,0) #forward fast
sleep(200)

if($currentdistance<39)
uartWrite(0,1,137,0,105,128,0) #forward fast
sleep(200)

if($currentdistance<35)
uartWrite(0,1,137,0,0,0,0)#Stop
sleep(10000)


endif
endif
endif
endif
endif
endif
goto(loop)

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.

United Kingdom
#6  

Well I got it pretty much sorted out. I modified the script above a bit more using some elements of Rich's ramping project and added a seperate script to stop the ramping one when needed. It's not pretty, but it does work. Thanks again for your input and project link Rich, and to Dave as well.:)

#7  

Glad you got it worked out. Sorry I wasn't much help but like you there's little time in my day anymore. Keep up the good work.

#8  

@SteveG 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)

Quote:


if($currentdistance<40) #If distance <40 then execute code
uartWrite(0,1,137,0,150,128,0)
sleep(10)
elseif($currentdistance<38) #If distance is not <40 but <38 then execute code.    This is not possible.
uartWrite(0,1,137,0,140,128,0)
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


$currentdistance = GetPing(D13, D14)
:loop
if($currentdistance<30)
uartWrite(0,1,137,0,150,255,255) #Roomba turns to avoid object.
sleep(1000)
elseif($currentdistance<32)
uartWrite(0,1,137,0,110,128,0)
sleep(10)
elseif($currentdistance<34)
uartWrite(0,1,137,0,120,128,0)
sleep(10)
elseif($currentdistance<36)
uartWrite(0,1,137,0,130,128,0)
sleep(10)
elseif($currentdistance<38)
uartWrite(0,1,137,0,140,128,0)
sleep(10)
elseif($currentdistance<40)
uartWrite(0,1,137,0,150,128,0)
sleep(10)
endif
goto(loop)

I think that should work. Hopefully that made sense :D

United Kingdom
#9  

@James.

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.