Multiple servos & the Arduino

I have a question about how the Servo object works...

I'd like to use the Wii Nunchuck to control 4 different servos on a robotic arm.

Xaccel base (rotates on axis normal to ground)
Yaccel shoulder
Yjoystick elbow
Xjoystick wrist

My question is that when you call: servoname.write(val) does the arduino setup a recurring PWM on servoname's pin with the correct duty cycle? Or does it instead just output a single pulse for each call to write(val)?

if its just a one-shot output for each call to write(val), will the Arduino be fast enough to read the data from the nunchuck, map the data to the correct servo values and write these values to the servo in 20ms or less? (I assume you would have to update write(val) every 20ms or less since the servos require a PWM frequency of 50Hz)

does the arduino setup a recurring PWM on servoname's pin with the correct duty cycle

Firstly, it is not PWM, and I don't care what other sites say. You can do it on any pin because it is PPM (pulse position modulation).

Or does it instead just output a single pulse for each call to write(val)

It sets the servo to the val that you have called (many pulses - unless it is only one step)

if its just a one-shot output for each call to write(val), will the Arduino be fast enough to read the data from the nunchuck, map the data to the correct servo values and write these values to the servo in 20ms or less? (I assume you would have to update write(val) every 20ms or less since the servos require a PPM frequency of 50Hz)

You will be able to do this , maybe not quite in 20ms but it depends on the speed of your servo motors among other things.

Mowcius

I see; thanks for the reply.

I found this in the Arduino Servo.cpp documentation: "A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method.
The servos are pulsed in the background using the value most recently written using the write() method"

Sounds like the Arduino will be capable of what I have in mind.

However, I don't understand how you claim servo positioning to be encoded using PPM instead of PWM.

Servos read the duration that an incoming pulse is high and set the position accordingly. (PWM)

PPM pulse are uniform height and width with variable displacement from each other. The signal you send the servo has nonuniform width for both the high and low duration, so I don't see how you make the connection.

EDIT:

Additionally, why wouldn't you be able to setup PWM on multiple pins?
All you would need to do is start the value for all servo pins high at the beginning of the signal period and one-by-one turn the signal low according to the desired output pulse widths based on some known timer value.

However, I don't understand how you claim servo positioning to be encoded using PPM instead of PWM

The distinction is a fine one, but PPM is the correct term for the modulation for R/C servos.

However, I don't understand how you claim servo positioning to be encoded using PPM instead of PWM.

The manufacturers of hobby radio control equipment refer to the modulation used to encode servo information to be sent from transmitter to receiver as PPM.

There have been a number of threads discussing this terminology in the past and I don't want to turn this into another one, but PWM involves modulation of the duty cycle, servo position is independent of duty cycle (it's determined solely by pulse duration). The current Arduino servo library does not use PWM to produce servo pulses and the duty cycle can change even if a servos pulse width (and therefore position) does not change.

Using the term PWM to refer to the control of servos in the Arduino environment can be confusing because PWM is what analogWrite produces (there is some discussion in the developers mailing list about changing the name of the current analgWrite functionality to pwmWrite and leaving analgWrite free to be used when arduino supports true digital to analog conversion – not sure if this will happen, but I like the idea)

Anyway, people have tried to drive servos using analogWrite (heck the Arduino analogWrite reference says it produces PWM and if servos use PWM then it should work, right?). This can damage servos and is not to be encouraged.

But back on topic, Yes, the arduino servo library should do what you want.

Have fun!

(there is some discussion in the developers mailing list about changing the name of the current analgWrite functionality to pwmWrite and leaving analgWrite free to be used when arduino supports true digital to analog conversion – not sure if this will happen, but I like the idea)

I've always liked the idea of changing it to pwmWrite over analogWrite. I understand (but don't agree) the reasoning orginally used but it just seems a mangling of terms that either confuses one early or later in their learning curve.

Lefty

I've always liked the idea of changing it to pwmWrite over analogWrite. I understand (but don't agree) the reasoning orginally used but it just seems a mangling of terms that either confuses one early or later in their learning curve.

Yes, I agree, change it to pwmWrite

Mowcius