Asked — Edited

Moving A Servo In A Goto Loop

Is there any way to set a servo value in a loop without running it in another script window? When I try to set a servo value in Goto loop, it only runs once. When I use multiple windows, the servo doesn't always update to the new value. Here is the script from my main window, it takes a potentiometer value, does some math, then starts a window that sets a servo to that value.

 :Start

   Release(D7)

   $PotCurrent = GetADC(adc0)
   $ServoValue = $PotCurrent / (189 / 81) - 25

   ControlCommand("SetServo",scriptStart)

 Goto(Start)

Then here is the other window.

 $ValueServo = $ServoValue

 Servo(D7,$ValueServo)

Not having that first line gives an error about setting servo positions to variables.

Please help!


ARC Pro

Upgrade to ARC Pro

Elevate your robot's capabilities to the next level with Synthiam ARC Pro, unlocking a world of possibilities in robot programming.

PRO
Synthiam
#1  

Why not do it in one script? What you have won't work because it's multithreaded. You'd want to use the ScriptStartWait command...


:Start

$PotCurrent = GetADC(adc0)
$ServoValue = $PotCurrent / (189 / 81) - 25

Servo(d7, $servovalue)

Sleep(100)

Goto(Start)

Or if you insist on doing it your suggested way


:Start

$PotCurrent = GetADC(adc0)
$ServoValue = $PotCurrent / (189 / 81) - 25

ControlCommand("SetServo",scriptStartWait)

Sleep(100)

Goto(Start)
#2  

Well, I copied and pasted this code and it only ran once. When you do anything to a servo, Goto loops don't work, they run only once. The only way I could get it to work was what I pasted above, and it ran very slowly.

PRO
Synthiam
#3  

That's not true. I didn't notice when I edited your code that the release statement is there lol. If you release a servo, it's not going to move. Take the release out. Picture what that loop was doing. Move servo but 1 ms later release it. So it never ends up moving at all:)

Also I'd put a sleep in there for 100ms or so. I'm on my iPhone so no code samples, you can figure it out I bet:D

PRO
Synthiam
#4  

Updated above code samples