Award
Congratulations Rich, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Ramp Down Speed Script Help For Roomba 530

Assistance Requested

Help Steve G with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

Steve G claims to have checked these sources:
 
#1

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.

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

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

#3

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.

#4

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.

#5

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.

#6

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

Code:

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

#7

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

#8

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.

#9

@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:


Code:


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

Code:


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

#10

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