Incrementing servo motors

Hi there I recently bought a pololu 6 channel maestro servo controller,

I’ve been using the TrySetTarget() method built into the C# MaestroEasyExample code that comes with the SDK. This allows me to set my servos to a specific position. Is there a way to simply tell the motors to just go forward or back without specifying a specific position? Essentially what I want to do is have it so the servos move in accordance to the arrow keys on the keyboard.

At the moment I’ve written a work around using several boolean values and a timer. When a button is depressed the motor is set to move forward by a set increment every tick of the timer. This is jerky and slow however. Is there any way around this?

Sorry if this question has been asked before.

Hello, supercow.

You can probably make your timer code less jerky and slow. How often is the timer firing? You should be able to send an update to the Maestro every 20 ms, which should result in smooth motion. Just make sure you aren’t doing any expensive/slow actions during that 20 ms. You might need to change the code to keep a handle to the Maestro open instead of opening it every time a command is sent.

Alternatively you could use the Maestro’s built in speed control to perform smooth movements. I can give more details if needed.

If you don’t care about position control or having a limited range of movement, then you could get a continuous rotation servo. Then your code would just set the target to something like 1.5 ms when the keys are not pressed, and 1.0 or 2.0 ms when an arrow key is pressed. You wouldn’t need to update the target so frequently.

–David

Excellent. I’m totally new to servo controllers so this is a great help.

I’ll try adjusting the timer and increments to get smoother motion and report back.

Thanks. :smiley:

EDIT: Works perfectly with the timer set to trigger every 20ms and the increment set at 200. Thanks!

Here’s a sample of the code I used for anyone else doing the same thing. The following function runs every 20ms on a timer;

        public void update()
        {
            if (right == true)
            {
                if (test > 3000)
                {
                    test -= 200;
                    TrySetTarget(0, test); 
                }
            }
            if (left == true)
            {
                if (test < 8000)
                {
                    test += 200;
                    TrySetTarget(0, test);
                }
            }