Batch file controlling Maestro

I have a Micro Maestro controlling a HiTec RC servo to rotate a monitor in an arcade cabinet… I’ve posted about it here before.

I’ve gotten back to this project after a lengthy absence and after some hardware fixes to the mount, have it all working well except for one detail.

I am using this batch file with a parameter to control the orientation of the monitor:

start /wait d:\Utilities\Pololu\Maestro\bin\usccmd.exe --accel 0,1
start /wait d:\Utilities\Pololu\Maestro\bin\usccmd.exe --speed 0,10

if "%1"=="90" goto vert

:horiz
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,7680
goto end

:vert
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,3456

:end
timeout /t 2 /nobreak
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,0

exit

Rotation works correctly, and the servo turns itself off when it reaches its target (where it is then held steady by natural balance and a couple of small magnets acting as latches).

However, it turns way too fast… well above the speed set in the first two commands. I have set the speed and acceleration limits in the Control Center, and I have tried it in this batch file. When I use the batch file, it always goes at top speed. I first had the --speed and --accel commands run directly, but I tried the “start /wait” approach in case they weren’t completing correctly before the movement command went through. The behavior was the same.

Any idea what I am doing wrong?

If the batch file doesn’t work, my next step would be to port it to subroutines in Pololu script…

I should add, I also tried just commenting the first two lines out and relying on the values set on the device.

usccmd --status

gave this output both before and after running the batch file:

 #  target   speed   accel     pos
 0       0      10       1       0
 1       0       0       0       0
 2       0       0       0       0
 3       0       0       0       0
 4       0       0       0       0
 5       0       0       0       0
errors: 0x0000
SCRIPT DONE
program counter: 5
stack:
call stack:

and yet, the servo still moved at maximum speed.

So then I tried using the command line directly. Status reported that the speed changed; but when I directly moved the servo, it did not respect the speed parameter.

Hello.

The Maestro needs your servo’s starting position to accurately set speed and acceleration (by breaking the movement between the last position and new position values into multiple smaller divisions). You can find more details about that under the “FAQs” tab on the Maestro product page. It looks like your script just sets the target position for servo channel 0 once before disabling it, meaning the servo’s position will always be unknown at the start of the script with each execution. Servos do not provide any position feedback, so the first position command you send will always move at full speed and acceleration, because the Maestro cannot initially know where the servo is.

Considering you know the position of the servo when you start your script, you should just send a command to set your servo to that position (without speed and acceleration limits) before sending the new position command (with speed and acceleration limits).

- Amanda

Amanda,

Thank you! I had been pointed to that FAQ earlier, but hadn’t understood the implications after following the advice to turn the servo off between rotations.

For those who are in need of a similar script, here’s the entirety of the batch file:

if "%1"=="90" goto vert

:horiz
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,3456
start /wait d:\Utilities\Pololu\Maestro\bin\usccmd.exe --accel 0,0
start /wait d:\Utilities\Pololu\Maestro\bin\usccmd.exe --speed 0,30
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,7680
goto end

:vert
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,7680
start /wait d:\Utilities\Pololu\Maestro\bin\usccmd.exe --accel 0,0
start /wait d:\Utilities\Pololu\Maestro\bin\usccmd.exe --speed 0,30
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,3456

:end
timeout /t 2 /nobreak
d:\Utilities\Pololu\Maestro\bin\usccmd.exe --servo 0,0

exit

Video of this project is now here:

https://t.co/NTG5CiShqT

Thanks for sharing a video of your project! It looks like your new post in the “Share your projects” section has a write-up with lots of details.

- Amanda