# Sensing servo feedback

Hi,

I'm new to this forum, robotics, electronics and microcontrollers, however I have been programming a long time and I'm currently studying computer science.

I recently bought an Arduino board with the purpose of making robots for experimenting with my special interest: AI.

I wish to build a walking robot and experiment with varios ways of giving it a nervous system. So I will need to find a way to get feedback directly from the servos, thereby being able to read the amount of stress (load) they experience at a given time.

So far I thought of 3 ways to do this:

1) The simplest way is connecting the servo output (=the servos ground wire) to an analog in port on the Arduino. My classmate who's into electronics said this was possible if I attached a small resisitor to the Arduino ground. The thing is he said that the Arduino would have a large resistor build in (so to speak) on the analog in. So if I just connected the servo output to the analog in without the resistor I would get no reading cause the electricity would flow into the Arduino ground where there is no resistance. Makes sense. He also calculated that I need a 6 ohm resistor based on the peak current draw of the servos I intend to use (HXT900 = 750mA). I'll try this out soon.

2) I could also use a current sensor (thermistor I believe they're called) to do the same thing, connecting it either to the servos 5V input or the output (not sure how?), and again reading the value from an analog in port. I'll also try this solution.

3) This is the really cool but difficult solution. A servo has build in a potentiometer. There are ways to modify servos so that you can read the position from this potentiomenter. Then one can actually move the servos position MANUALLY and later read it's position. And it can also provide a way of reading the stress of the servo.

Here is a manual on this conversion:

forums.trossenrobotics.com/tutorials/how-to-diy-128/get-position-feedback-from-a-standard-hobby-servo-3279/

So basically I need all the advice/input I can get. Does this sound plausible? Is there a 4th or 5th solution I haven't considered? Anyone has tried something similar? Any ideas would be appreciated...

Aniss1001 :)

## Comment viewing options

Hello Aniss,

I am not sure why the confusion, but (typical) servos use Pulse Width Modulation, the width of the pulse is what controls the output position, Servos are typically very tolerant of variations in the pulse interval. Finger Tech provided a good description of PWM vs PPM. The only thing I did not like was the "Pulse Width Modulation has a fixed frequency and variable period" statement, normally the term period refers the duration of cyclic wave form, thus period = 1/frequency, but I think we know that finger Tech was refering to the "On period". I have never seen a servo which uses PPM, that does not mean they don't exist. One could successfully control a servo by providing a pulse train which  is (control pulse) 20ms (control pulse) 20ms, this would keep the period within 25ms; so in this case the position of the pulse would vary but that is not what the servo looks at, in fact if the pulse is late this triggers a missing pulse detector, in this case the behaviour of the servo varies from manufacture to manufacture.

I thought I would add something on shunt resistors (sense resistors) there are two ways of using the shunt resistors, high side and low side, High side is where the resistor is on the posititive side of the load (motor), so as not to waste power it is important that the shunt resistor be of a reasonably low resistance so to make the signal useable we need to amplify it, the circuit below shows one way of doing this for high side sensing:

The uC is the microcontroller and is natually an Analog (A/D) port.

In this case Vout = Vsense x (R*/Rin)   = Rsense x Iload x (R*/Rin)

[R1 = R*]

Now for the low side:

In this case Vout = Vsense x (1 + R2/R1) = Rsense x Iload x ( 1 + R2/R1)

The Opamps are just configured as fixed gain amplifiers.

Now the trap, the servo motors are reversable, so in one direction the shunt is on the low side and the other way the high side.

A couple of other issues is the motors are inductive loads and generate a back EMF when the current stops, this could be enough to cook the Opamps. Normal practice is to tie Vsense line to the +V and Gnd rails by REVERSE BIASed diodes.

You can also sense the "speed of the motor" using the comutator noise (little DC can motors typically consist of 3 windings which are turned off and on) in the Automotive industry this is the common tecnique used with such things as Window Winder Motors (i.e. detecting you head is in the window).

any way got to fly, I am late again....

If this is of any use I can write a little more.

best regards

cliff

Hi again cwignell (and anyone who wish to contribute),

I've been looking at your solutions trying to understand them the best I can with my limited knowledge of electronics.

I tend to like the "low side" solution best because:

1) It's simpler. Easier to understand and has less components/resistors.

2) It seems easier to combine with an analog multiplexer (to measure the current draw of several servos from 1 analog input).

3) It seems similar to my ORIGINAL idea I mentioned as option 1 in the topic description.

Here is a diagram of that idea:

However this option has now been dumped because I was told it would cause servo noise. But the "low side" solution is basically the same just with a smaller resistor (I was told 0.1 Ohm would be appropriate) and the op amp. So I made a new drawing including the multiplexer, based on your "low side" solution (as well as others I've seen). Here it is:

I added 3 servos in the drawing but in reality I'll be using 12, so I'll probably use a 16 channel analog multiplexer like this one.

Questions:

Does this seem possible? What kind/size of resistors will I have to use as R1 and R2 given that the servos use 5V, the Arduino analog in can measure from 0V to 5V and the peak current draw of the servos I'm gonna use is ~750mA? Would it be easier/better to use a (hall effect) current sensor IC like this one (still using a multiplexer)?

And then you lost me when you said: "Now the trap, the servo motors are reversable, so in one direction the shunt is on the low side and the other way the high side". Are you sure you're not refferring to DC motors? I don't think servos are reversable?!

Best wishes

Aniss

PS: Please note that the diagrams are incomplete as I left of the digital outs (from Arduino) that control the servos as well as the multiplexer...

Hi (again ;-),

Measuring across the entire servo means you don't have to worry about the motor reversing, the current will alway flow neg to positive. I was refering to DC motors, the tecnique is normally used across DC motors. But I suppose we can treat the enire servo as a DC motor.

Yes 6ohm is too high, if you feed the servos with 5V, 6ohm would result in ~3V which would cause a couple of problems.

First the servo need a little more than 3Volts across for the onboard regulator to work,

Second, we push the servo's ground up, it is the reference for the signal and I think you might run in to problems here; also the 0 signal level will be below the servo ground, a lot of digital gates do not like the level to be pulled below ground.

For these reasons I would be inclind to go high side measurement, this has the advantage that the ground never changes so 2 is not a problem. But with a 0.1Omh shunt it probably wont be a problem.

So 0.1 Ohm is a good choice, with an Opamp you can adust the gain to get a nice full range (0-5V) signal although you may need to much around to match the gain to the servo performance.

You are going to have to do a bit of testing, running the servo and looking at the results so you can understand the Load vs Current, Starting currents etc, this may require you to expect a high start current and then a decreasing current until you hit something. You might even see little current pulses conenciding with the signal pulses; I am not sure how apparent these will be.

best regards

CW

Thanks for all you advice..it's all being taken under consideration.

However the pole shifting is going on INSIDE the servo. It's all being taken care of by the servo's motor controller. So I don't have to worry about that. And I very much doubt you can treat it like a DC motor. In fact I think it'll destroy the servo if one tried.

But you were on to something. Just read on the Arduino forum that a guy using a similar setup reported erratic readings (high current draw peaks) whenever a servo changes direction.

Regards

Aniss

Well, the confusion originates from this article and the fact that several very knowledgable people (on the Arduino forum) believe that PPM is more appropriate than PWM for describing servo signals.

Here is (a part of) an explanation that I'm still trying to fully understand (copied from this thread):

PWM involves the modulation of a signals duty cycle.  In controlling a servo, the duty cycle does not control the position of a servo. Servo position is controlled through modulating the on time of the pulse. Indeed it is possible to control a servo over its full range of movement by changing the on time but keeping the duty cycle constant. If servo control works perfectly well without changing the duty cycle then PWM modulation would not be the most appropriate term for the modulation used.

The terminology is confusing because servo control pulses do involve changing (modulating)  the pulse width. And a subset of PWM can be used to emulate the modulation needed to control a servo.  But its no more correct to say that this makes the servo signal PWM than it would be to say that an AC (Alternating Current) signal is PWM because PWM is capable of  alternating (switching on and off)  current. Indeed it is possible to emulate AC using PWM (along with a few passive components) but of course that doesn’t mean one should say that AC is PWM modulation.

Perhaps you will understand it better than me. I just understood what duty cycle means, but I'm still not clear on what the term modulation actually means...

And thanks for your thorough comments on the shunt resistor matter. I'll get back to you on that when I've studied it some more...

Best wishes :)

Aniss

Hello Aniss1001,

Duty cycle, in a repeating signal, the duty cycle is the percentage of the period which the signal is a high (on, a 1 what ever). Sof 50% (50/50) the signal is a high for half the time.

Modulation, refers to the method of encoding the signal on the carry, for example Amplitude Modulation (AM) Radio encodes the signal by increasting and decreasting the ampliture of the carrier. So PWM is just stating that the signal (servo position) is encoded by the width of the pulse (1 to 2ms).

I think the above explanation is splitting hairs and is not quite right.

The statement that PWM varies the duty cycle is true, sort of but this depends on keeping the pulse interval constant, it is not necessary to keep the pulse interval constant. PWM VARIES THE WIDTH OF THE PULSE. I think the author is thinking of PWM control of motors.

Servos are very tollerant of the pulse interval, my servos only start to play up if I get much faster than 10ms and slower than 70ms, I have a servo tester built with a 555, I can vary the pulse interval and duration, if the pulse interval stays at >10 <70 only the pulse duration (width) changes the postion.

So If I can vary the interval between pulse, then the pulse position has little to do with the servo output position. So I would not call it pulse position modulation.

If I vary the width of the pulse the output position changes, so I would personally call it PWM.

An the Signetics Databook (real paper!) calls it PWM.

Anyway it is a bit of a simantic argument, if you keep the pulse interval to >10 & < 70ms and the pulse duration between 1 and 2ms, your servos will be happy.

all the best CW

Well the discussion is still ongoing on the Arduino forum. However I decided just to call it servo signals/pulses from now on and leave it at that :)

But the author is DEFINATELY refferring to standard SERVOS. And perhaps he has a point (however nitpicky it may be)...

Quote from wikipedia: "PWM of a signal or power source involves the modulation of its duty cycle".

Quote from the author of the previous statement: "Are you aware that a servo can be operated correctly over its full range without altering the duty cycle of the control signal? If servo control can be achieved without modulating the duty cycle then PWM would seem a poor choice for describing its encoding".

If you note my first comment on this, I do acknowledge that the signal between the radio and the receiver can be PPM. However the signal(s) that come out of the receiver to drive the servos is PWM. The servos change position based on the width of the pulse from the receiver (or controlling electronics), not on when the pulse occurs. The radio transmitter sends out a series of pulses in a train over a specified frequency. The receiver can then decode from the position of the pulses which servo is being commanded to properly route the right pulse width it to the right servo. So with the radio control set-up, the PPM exists in the signal transmitted to the receiver and PWM exists from the receiver to each servo.

And yes, a servo can be operated over it's entire range without changing duty cycle but by changing the frequency of the signal being sent. Servo electronics are somewhat forgiving in the range of frequencies they will accept a pulse width. However, to change the frequency of pulse delivery also changes the servo response (faster pulse repetition means quicker response, more torque) as well as the way a micro can be programmed. In some cases you have to change both the frequency and duty cycle in programming to get this to occur, as the electronics are such that the primary (frequency) being adjusted requires the secondary (duty cycle) to be adjusted before any signal is output. If you want your servo to go as quickly and powerfully to a wide pulse position as to a narrow pulse position, then chaning the width rather than the frequency is the best method.

Thanks for a lot of wonderful input. Unfortunately I have classes now (mathematical analisis...sigh!) so I'll get back on the case as soon as I have time...

:)

Hello,

I think for walking machines servo feed back is useful, for example in the MIT 6 Legged robots (Genghis, Atila et al) they sampled the error signal as a way of detirmining if the Leg had bumped into something and to detect when it was on the ground. This information is used in conjunction with the command target position to control roll and pitch.

A point to note is that a typical servo (old) uses the Mitsubish M51660L (a replacement for the earlier Signetics NE544 chip).

So getting back to measuring the current position and torque, there are a couple of ways of doing this.

Typically Model servo drive the output shaft to the target position using a torque proportional to the distance between the current postion and the commanded position (linear proportional to error).

MIT basically tapped the motor (voltage) and used a high and a low comparitor, the idea being the Servo drive chip would drive the motor with a Voltage proportional to the error, if you bump something you should see result in the drive voltage not declining with time and if the motor goes to stall you should see this, you could also measure the current. This will require careful processing as it full of transisents such as the current / error when the motor first starts to move the leg.

Another way is the the M51660L has a pin (9) which provides an Error Signal (pulse output), I havent played with this signal, it is normally tied to pin (11) via a resistor which controls the deadband.

all the best

Cliff