Best way to simultaneously control two servos positioned horizontally and vertically

cservo

I'm trying to set up a C program where a servo (servo1) sweeps to a position, waits a few seconds, moves to another position and repeats 4 more times. Another servo, positioned vertically, (servo2) is supposed to move up and hold its position, especially during the period where servo1 is waiting. I have servo2 running in an infinite loop as a separate thread, but I am unsure if if this is the best course of action.

The problem is that servo2 either falls and loses its position if it is not consistently receiving a signal,
or if it keeps getting a signal, it constantly hums and sometimes jumps around. I'm not sure if it jumps because if there are interrupts in the background (I'm using a cubieboard running linux).

I'd like servo 2 to not jerk around at all. Any help or suggestions on implementation would be appreciated.

Best Answer

What kind of servos do you have?

As far as i know there ar analog servos which you can drive with a pwm. Every microcontroller i have seen has some pwm outputs. With them you can generate the signal and it runs in the background without any processor resources needed.

When you then stepwise change the ontime period of one pwm the other one should rest as it was. So no multi threading is needed in this case and solving your problem is really easy and straighforward.