## Let me get this straight about servos & motors...

mrpi64
Posts: 931
Joined: Sat Feb 16, 2013 5:13 pm

### Let me get this straight about servos & motors...

So, a motor can turn around an infinite amount of times, and a servo can turn up to 360 degrees, noo more (but it can turn backwards to 0). Right?
I'm happy to help.
https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 - List of games that work on the Pi.

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

### Re: Let me get this straight about servos & motors...

By default, for common sorts, yes.

But you can easily modify servos to carry on indefinitely - it's a good way to get a compact highly-geared motor. Also some specific servos come out-of-the-box doing more than one revolution (sail winch servos for radio control sailing boats, for example, can often do 6 turns).

The main difference is that by default a servo runs to a position and then stops. The servo needs a power supply and a position signal (in normal RC, a PWM signal). A motor just runs, but only needs a power supply.

(I'm assuming you don't want to talk about stepper motors, which do run to a position then stop, but the position is just a few degrees further than they are now, and they can keep doing that indefinitely).

joan
Posts: 14177
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: Let me get this straight about servos & motors...

mrpi64 wrote:So, a motor can turn around an infinite amount of times, and a servo can turn up to 360 degrees, noo more (but it can turn backwards to 0). Right?
No.

A DC motor can rotate continuously clockwise and anti-clockwise.

A servo generally rotates between end stops which limit its continuous rotation to between something like +100 to -100 degrees from centre. The degrees from centre can be accurately set by using the pulse width (generally 1 to 2 millseconds) sent via its control wire.

Servos can be modified to be continuously rotating (by a hardware change). Then the pulse width sets the servo's speed and direction of rotation.

mrpi64
Posts: 931
Joined: Sat Feb 16, 2013 5:13 pm

### Re: Let me get this straight about servos & motors...

Do servos normally return back to their original position without prompt?
I'm happy to help.
https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 - List of games that work on the Pi.

Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

### Re: Let me get this straight about servos & motors...

Generally they don't. If the PWM signal stops or doesn't meet specification, the servo motor controller stops working. They usually require something like PWM pulse every 20ms. The length of the pulse will determine the desired servo position, usually ranging from 0.5ms to 1.5ms, with 1ms indicating centre.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Contact: Website

### Re: Let me get this straight about servos & motors...

A servo is merely a motor with feedback, so it depends very much on how that feedback works as to what it does.

As far as I can see, most servos on sale seem to be fitted with a pot for sensing position.
If it also has a spring to return it to "home", then it will go back.
Also, if you remove the input signal the feedback electronics may assume you want it to return to "home".
Or it may not.

Of course you may have a servo that senses speed rather than position, so it will go until you tell it to stop.

joan
Posts: 14177
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: Let me get this straight about servos & motors...

Burngate wrote:A servo is merely a motor with feedback, so it depends very much on how that feedback works as to what it does.

As far as I can see, most servos on sale seem to be fitted with a pot for sensing position.
If it also has a spring to return it to "home", then it will go back.
Also, if you remove the input signal the feedback electronics may assume you want it to return to "home".
Or it may not.

Of course you may have a servo that senses speed rather than position, so it will go until you tell it to stop.
I have never seen a servo fitted with springs or firmware to return to a neutral position if the pulses are stopped.

DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

### Re: Let me get this straight about servos & motors...

Servos come in all kinds. Most are controlled by PWM, and most have a stop to prevent complete rotation, though continous rotation servos are comon as well, often for around \$13USD for a continous rotation servo with a maximum speed of 50RPM and a torque of around 30oz/inch. Or you could also look at continous rotation servos that have speeds up to 180RPM for about \$20USD. Of cource if you need more torque than that you will spend more. Such as a 10lb/inch servo that I use costs \$45USD.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

### Re: Let me get this straight about servos & motors...

Mortimer wrote:Generally they don't. If the PWM signal stops or doesn't meet specification, the servo motor controller stops working. They usually require something like PWM pulse every 20ms. The length of the pulse will determine the desired servo position, usually ranging from 0.5ms to 1.5ms, with 1ms indicating centre.
My (slightly elderly futaba) gear works with pulses at 54.3Hz with a pulse duration between 1.0 and 2.0 mS (ie, 0.5mS offset from the figures you've quoted).

I've written PIC assembly code that drives servos (decent futaba and less decent nameless chinese ones) with various frequencies - you don't need to be very close to 50Hz. My most complex setup generated the servo pulses at 48.8Hz and worked flawlessly.

mrpi64
Posts: 931
Joined: Sat Feb 16, 2013 5:13 pm

### Re: Let me get this straight about servos & motors...

Burngate wrote:A servo is merely a motor with feedback, so it depends very much on how that feedback works as to what it does.

As far as I can see, most servos on sale seem to be fitted with a pot for sensing position.
If it also has a spring to return it to "home", then it will go back.
Also, if you remove the input signal the feedback electronics may assume you want it to return to "home".
Or it may not.

Of course you may have a servo that senses speed rather than position, so it will go until you tell it to stop.
I think that the spring thing might be the problem. No worries. Hmmm, I might unscrew it, to see the inside. Good idea or bad?
I'm happy to help.
https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 - List of games that work on the Pi.

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

### Re: Let me get this straight about servos & motors...

mrpi64 wrote:Hmmm, I might unscrew it, to see the inside. Good idea or bad?
You can if you want.

You'll find a plastic gear-train, a small dc motor and a small circuit board (unless it's an expensive and/or special servo). The circuit board has a feedback system that compares the output from a potentiometer to the incoming pulse train. Pay attention to what you're doing and it should still work when you put it back together.

mrpi64
Posts: 931
Joined: Sat Feb 16, 2013 5:13 pm

### Re: Let me get this straight about servos & motors...

achrn wrote:
mrpi64 wrote:Hmmm, I might unscrew it, to see the inside. Good idea or bad?
You can if you want.

You'll find a plastic gear-train, a small dc motor and a small circuit board (unless it's an expensive and/or special servo). The circuit board has a feedback system that compares the output from a potentiometer to the incoming pulse train. Pay attention to what you're doing and it should still work when you put it back together.
Ok. One final question- if I physically turn it when it's not connected to anything, will it try to reset itself when a signal is given.
I'm happy to help.
https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 - List of games that work on the Pi.

joan
Posts: 14177
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: Let me get this straight about servos & motors...

The servo will move to the commanded position (determined by the pulse width). That is unless you have forced it to turn too far and have stripped its gears.

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

### Re: Let me get this straight about servos & motors...

mrpi64 wrote: Ok. One final question- if I physically turn it when it's not connected to anything, will it try to reset itself when a signal is given.
I don't understand exactly what you are asking.

If you connect the power and ground lines and leave the PWM signal wire floating, I don't know what it will do - it probably depends upon the detail of the circuit embedded within it and possibly varies according to manufacturer. My guess is that it will either stay stationary, or move to one limit of travel, or jitter randomly. Since that about covers all options it's not a useful guess. Try it and see, and be ready to disconnect the supply if bad things happen.

When you do connect a PWM signal, it will move to the position indicated by the signal, irrespective of what it was doing or where it was beforehand. The PWM signal indicates an absolute position - it doesn't matter what happened previously, every time the servo receives a PWM signal it tries to move to the position implied by the signal. It may get another pulse before it gets there, but it just starts again - trying to get to the position described by the latest pulse.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

### Re: Let me get this straight about servos & motors...

One thing to consider - the servos I've seen can be turned by hand with the power off (be careful not to damage them though.) However when the model is switched on, the software or controller has to start with the servo set to go to some position. If the servo isn't already at that position, it will jump rapidly to it.

So when switching on, you might see a twitch of the servos as they all jump to their start positions. This may or may not be a problem for you. (Very complicated to get around this problem reliably, such as in an industrial robot arm or something.)

mrpi64
Posts: 931
Joined: Sat Feb 16, 2013 5:13 pm

### Re: Let me get this straight about servos & motors...

Ok, so I twist it with my hand. I connect it to an Arduino, and tell it to turn to 45 degrees. I give it half a second to do that. In the remaining time after it has reached it's goal, it suddenly starts turning back towards its starting place. Until the Arduino tells it to turn back to 40D.
I'm happy to help.
https://www.raspberrypi.org/forums/viewtopic.php?f=78&t=51794 - List of games that work on the Pi.

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

### Re: Let me get this straight about servos & motors...

No, because you can't just tell it where to go once. You need to tell it where to go 50 times a second, and keep telling it. If you send one PWM pulse and nothing more (ie stop telling it where to go), its performance is undefined and anything might happen.

The servo hardware needs a train of pulses, at about 50Hz. If you want it to go to 45 degrees for half a second you need to send the appropriate width pulse, then send it again 1/50 second later, then send it again 1/50 second after that and carry on for half a second. If you then stop, the behaviour is undefined, but if you want it to move to a different defined location, you need to send the relevant pulse, then 1/50 second later the relevant pulse again, and so on.

Just try it. It's probably quicker to try it than post the message here and wait for replies.

In my opinion, however, this sort of thing that relies on a simple, repetitive, timing-critical operation is better done on something other than a pi. An arduino might be a bit better, but when I implemented it myself I did it in assembler on PIC, because then you get control of your timing at a clock-cycle resolution - http://www.astounding.org.uk/ian/hovercraft/mixer.html If you want to control servos it might be better to put some dedicated hardware between pi and servo to do the timing.

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

### Re: Let me get this straight about servos & motors...

I' d stop thinking about forcing a servo by hand - plastic gears are easily broken that way.

joan
Posts: 14177
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

### Re: Let me get this straight about servos & motors...

achrn wrote:...
In my opinion, however, this sort of thing that relies on a simple, repetitive, timing-critical operation is better done on something other than a pi. An arduino might be a bit better, but when I implemented it myself I did it in assembler on PIC, because then you get control of your timing at a clock-cycle resolution - http://www.astounding.org.uk/ian/hovercraft/mixer.html If you want to control servos it might be better to put some dedicated hardware between pi and servo to do the timing.
There are plenty of modules/libraries on the Pi which provide accurate pulses. In my opinion they can be better than an Arduino.

Good job on the hovercraft.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

### Re: Let me get this straight about servos & motors...

I always thought that, on an Arduino or whatever other controller, there is always a background thing running that re-sends the servo pulse every 50ms. So you set the servo position you want, and can set it any time, but the controller automatically sends the refresh pulses for you. (I've only used servos on a picaxe, but most other controllers should do the same.)

These days some fancy modern servos might be capable of remembering the last pulse and holding that position, if pulses stop. The constant pulses are really needed because in the early days the electronics were pretty primitive and everything was based on analogue electronics, which have no memory to speak of.

And yes as mikerr says, don't ever try to stop a servo while powered (as I said before). The gears can be damaged or the electronics, cramped in that tiny case, might even overheat. They can usually be turned by hand, carefully, with the power off - but don't do that unless necessary, like when bolting them into place.

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

### Re: Let me get this straight about servos & motors...

Ravenous wrote:I always thought that, on an Arduino or whatever other controller, there is always a background thing running that re-sends the servo pulse every 50ms. So you set the servo position you want, and can set it any time, but the controller automatically sends the refresh pulses for you. (I've only used servos on a picaxe, but most other controllers should do the same.)
That clearly depends on how the 'background thing' has been created. If it's just a basic bare microcontroller that doesn't have PWM generators, clearly not. If it's a sligfhtly more capable one that has PWM implemented in the hardware (and you're using it), clearly yes. With a pi, presumably it does if you're using a specific PWM library but not if you're bit-banging GPIOs for yourself.
Ravenous wrote:These days some fancy modern servos might be capable of remembering the last pulse and holding that position, if pulses stop. The constant pulses are really needed because in the early days the electronics were pretty primitive and everything was based on analogue electronics, which have no memory to speak of.
My understanding is that the whole discussion has an over-arching caveat along the lines of "assuming you're talking about ordinary / cheap / old (pick any one) servos". I agree a modern digital servo with embedded microprocessor might do almost anything. If I were implementing it I might have it hold last requested position for a short while, then a slow move to a defined safe (or park) position. Or I might not. What the manufacturer implements on actual servos bought in a shop, I have no idea.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

### Re: Let me get this straight about servos & motors...

Quite right. The "Background thing" I vaguely mentioned is because if Mrpi is going to use an arduino (servo library) or raspi (servoblaster or alternative) then the library will handle the repeat pulses for him. It's only necessary to set a value when a change is required (and perhaps an initial angle when the program starts up - the servo may jump at switch-on, which is what I think he wanted to know).

In the case of a bare microcontroller like your mixer example (nice hovercraft by the way!) the programmer needs to take care of all those pulses by himself and it all gets a bit college-level.

I've also heard that some servos go a bit inaccurate if the pulses aren't arriving every 50 milli seconds, while some are the opposite and tolerate pulses that go astray for quite some time. Most of this shouldn't matter if decent servo software is available of course...

mikronauts
Posts: 2716
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

### Re: Let me get this straight about servos & motors...

No.

If you stop sending the control pulse:

- a standard servo will stay in the last position it was in (unless weight on the servo horn drags it down)
- a continuous rotation servo will stop turning
mrpi64 wrote:Do servos normally return back to their original position without prompt?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Posts: 9
Joined: Wed Nov 02, 2016 11:50 am

### Re: Let me get this straight about servos & motors...

Sorry to resurrect an old thread, but above there are two different timings specified:

One set of posts say 50 Hz (which is 20 ms), while others say 50 ms (which is 20 Hz).

I also note that different servos use different timings, and that the timings are not absolutely critical - but which is the most common?

achrn
Posts: 373
Joined: Wed Feb 13, 2013 1:22 pm

50Hz.