Asked
— Edited

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