Asked — Edited
Resolved Resolved by Dave Schulpius!

Trouble With Simple Script

This is my first time using ARC and EZ-Script. I'm having trouble with what I think should be a very straight forward script.

I have Revolution Six outfitted with an HC-SR04 ultrasonic sensors on a head-mounted servo. The Ping Distance control shows that the sensor is working fine.

My issue is that when I hit 'Start' on the Script control, the robot doesn't move. Actually, the servo d20 (which controls the Ping sensor position) moves, but Six doesn't walk. I can see in the Auto Position control that the Forward Action is repeating (see attached screenshot), but the robot doesn't move...

Until I hit 'Stop' in the Script control. Then Six moves forward as expected, but he doesn't follow the rest of his program. He never responds to his Ping sensor and reverses. I also noticed that the Auto Position control stops updating with Six's movements after I hit 'Stop' in the Script control.

Here's my code:


servo(d20, 90)
:loop

$dist = getping(d21,d22)

if ($dist < 20)
  ControlCommand("Auto Position", AutoPositionAction, "Reverse")
else
  ControlCommand("Auto Position", AutoPositionAction, "Forward")
endif

goto(loop)

What am I doing wrong?

User-inserted image


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#1  

This my not help your problem but install a Sleep command after the endif line. like this:

Sleep(0500)

This example is a 1/2 second. You can adjust the time to anything that works for you. 1000 would be one full second. Your script may be running too fast for anything to respond. You need to give your devices time to either move to the position you want them to move to or return the info you are seeking.

#2  

OK. That helps. It's working better, but still kinda twitchy. I'll keep plugging away.

Thanks for the assist.:)

#3  

Glad it helped. What do you mean by Twitchy? Maybe you need to adjust either the Sleep or the $dist variable. I've not played around with the ping feature so my help is limited here with smoothing out your bots response. Sorry.

#4  

I've got it worked out now. It was largely a matter of playing with sleep() durations. I also found I could use the forward() and reverse() functions instead of the Auto Position versions. It seemed to work better for me for some movements.

Code posted below for reference. This is a Six robot with ultrasonic sensor on a head-mounted servo.


servo(d20, 90)
:loop

goto(getdist)

if ($dist <= 20)
  goto(getback)
elseif($dist > 20 AND $dist < 30)
  stop()
  sleep(500)
  goto(whichway)  
  if ($distright > $distleft)
    ControlCommand("Auto Position", AutoPositionAction, "Fast-Right ")
    sleep(2500)
    stop()
  else
    ControlCommand("Auto Position", AutoPositionAction, "Fast-Left")
    sleep(3500)
    stop()
  endif
elseif($dist >= 30)
#  forward(200,2000)
  ControlCommand("Auto Position", AutoPositionAction, "Fast-Forward")

  sleep(100)
endif

 sleep(200)

goto(loop)

:getback
  reverse(255, 3000)
  stop()
#  ControlCommand("Auto Position", AutoPositionAction, "Reverse")
#  sleep(1000)
return  

:whichway
  servo(d20, 130)
  sleep(300)
  goto(getdist)
  $distleft = $dist
  sleep(25)
  servo(d20, 50)
  sleep(300)
  goto(getdist)
  sleep(25)
  $distright = $dist
  servo(d20, 90)
return

:getdist
  sleep(25)
  $dist = getping(d21,d22)
  sleep(25)
return