# 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

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.

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

Hmm...the more I look at the original circuit...

...vs. my multiplexed one...

...the more I think it's all wrong. The thing is..in the original the low side of a single sense resistor is being fed to the op amp's negative input. While in my version the low side of ALL the sense resistors are being fed to ditto.

I'm no wiz (as ya'll should know by now) but I can't help thinking this will mess up the readings? Perhaps I'm wrong. I hope so, but I did come up with a new circuit using 2 multiplexers. It also includes two 0.1uf capacitors that I was adviced to add for less noisy readings...

Any opinions on this?

Best wishes

Aniss

Hi Aniss1001,

You don't need the bottom Mux (2), the connections to this mux will always be at ground, thus it wont matter which is selecte so get rid of it. The caps are ok they will by pass the hi-freq stuff. but other than that should be ok

That's good news (about mux 2). It was getting rather complicated. I just couldn't help thinking it would be better to feed the op amp with a matching high+low side of one sense resistor at a time..

But I'm glad I don't have to go there.

Thanks for a VERY quick answer :)