ignoblegnome
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?
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.
OK. That helps. It's working better, but still kinda twitchy. I'll keep plugging away.
Thanks for the assist.
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.
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.