360 degree servo vs Continuous Rotation


13 posts
by Thommango » Mon Sep 30, 2013 3:02 am
Hi all,

I just brought home a servo that does full rotation, and I'm having a hard time getting it to behave as expected. I think I've figured out the problem in the course of creating this posting, but I'll continue anyways, as it may save others some of the frustration I've had today.

So, the project I have in mind uses something like an analog clock face. It will have one arm that points to the appropriate condition. For this I bought a servo that moves the full 360 degrees. However, it turns out this servo is a "Continuous rotation" servo (SM-S4303R). I didn't think much about that at the time, but the net result seems to be that it cannot be commanded to go to a particular spot on the dial. Instead, this servo is basically a motor, but with fine grain control over the velocity.

I tried following a number of tutorials, but the results never seem as expected. For example, this code snippet...

Code: Select all
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.OUT)

p = GPIO.PWM(17, 50)

p.start(7.5)

try:
        while True:
                p.ChangeDutyCycle(7.5)
                time.sleep(1)
                p.ChangeDutyCycle(12.5)
                time.sleep(1)
                p.ChangeDutyCycle(2.5)
                time.sleep(1)

except KeyboardInterrupt:
        GPIO.cleanup()


...just causes the servo to spin around in one direction or another, varying speed but never stopping at a given location. If I change the time.sleep duration to 60, it will just spin around for a full minute. This being a servo, my expectation was that the servo would stop at a given orientation.

If you think I've got this wrong, please let me know. I will go shopping again tomorrow and try for a 360 servo that is not continuous rotation.

Cheers,

Thom
Posts: 6
Joined: Sat Mar 02, 2013 2:58 pm
by ame » Mon Sep 30, 2013 4:48 am
You've got it right.

As you know, the pulse width of the RC servo control signal sets the output position of the servo arm. Typically the servo arm has a range of about 180 degrees. A pulse of 1.5ms will move the servo arm to the centre position (say, 90 degrees) and pulse widths of 1ms and 2ms will move the servo to 0 degrees and 180 degrees (approximately).

It is possible to modify a regular RC servo for continuous rotation. You do this by replacing the position potentiometer inside with a voltage divider set to 50%, or disconnect the drive linkage to the potentiometer and set it to the half-way position. In this case, since a pulse of 1.5ms corresponds to the centre position, and the servo always 'thinks' it's in the centre position then the servo won't move. Pulses of less than 1.5ms will cause the motor to run continuously one way, and pulses of greater than 1.5ms will cause it to run the other way, since the servo controller will try to move the motor to return the servo arm to the centre position. This will never happen of course, so the motor keeps running.

The 360 degree servo has a potentiometer that will allow the output arm to turn through 360 degrees. Again, a pulse of 1.5ms will move the servo arm to the centre position (say, 180 degrees) and pulse widths of 1ms and 2ms will move the servo to 0 degrees and 360 degrees (approximately). Obviously this is the same point, but you arrive from a different direction.

There are also multi-turn servos (720 degrees or more), used for RC model boat sail winches.

I think the servo you have is no good for your application. If you can't find a servo with a wider output range then how about a stepper motor? Or try dismantling a regular servo and adding a gear to extend the range of the potentiometer. Or have a regular servo drive a pulley with a 1:2 ratio. I expect your clock face indicator has very little load.

Good luck.
Posts: 2323
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea
by Thommango » Tue Oct 01, 2013 2:02 pm
Thanks. I ended up buying a step motor and a daughter board controller. But this project is going to go on my urban lawn and will be subjected to weather, snowballs and curious/nefarious teens, so I want to keep the parts cost down. So, after thinking it through some more (albeit belatedly), I've decided on a cheaper approach:

A simple motor will drive a "clock arm" that includes a magnet. Gearing will ensure that the clock arms move at a gentle pace. Reed switches will be placed at the target stop points. When the correct reed switch is sensed, power to the motor will be cut.

So now I've got to learn about using gears, I guess.
Posts: 6
Joined: Sat Mar 02, 2013 2:58 pm
by Thommango » Tue Oct 01, 2013 2:39 pm
Actually, now I'm noticing that I can get very cheap stepper motors on ebay. So, I'll try that approach.
Posts: 6
Joined: Sat Mar 02, 2013 2:58 pm
by hnajibeddine » Fri Jan 16, 2015 12:02 am
Hi,

If we want to generate a 1.5 ms pulse every 20 ms, shouldn't the period be considered T=21.5ms instead of T=20 ms? The Frequency would then be F=1/21.5ms~46.5HZ.
Thanks!
Hassan
Posts: 4
Joined: Thu Jan 15, 2015 11:54 pm
Location: Canada
by ame » Fri Jan 16, 2015 2:17 am
hnajibeddine wrote:Hi,

If we want to generate a 1.5 ms pulse every 20 ms, shouldn't the period be considered T=21.5ms instead of T=20 ms? The Frequency would then be F=1/21.5ms~46.5HZ.
Thanks!
Hassan


No.
Posts: 2323
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea
by joan » Fri Jan 16, 2015 8:44 am
hnajibeddine wrote:Hi,

If we want to generate a 1.5 ms pulse every 20 ms, shouldn't the period be considered T=21.5ms instead of T=20 ms? The Frequency would then be F=1/21.5ms~46.5HZ.
Thanks!
Hassan

No, the manufacturer should indicate the update rate, for a lot of hobby servos that would be a figure between 50 and 60 times a second. You should give the servo updates at that rate regardless of whether the current pulse width is 1000 µs or 2000 µs (although I think most servos won't know if you do manipulate the frequency as you suggest).
User avatar
Posts: 8520
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by hnajibeddine » Tue Jan 20, 2015 6:02 pm
Many thanks for your reply Joan.
It seems some Trial and error would definitely end up determining the optimal values for how to control a servo, but I noticed they don't always coincide with the theoretical values, specially when converting the pulse width from ms to ticks (on the raspberry, https://learn.adafruit.com/adafruit-16- ... -reference ): per ex, one of my servos requires a 1.5 ms pulse every 20 ms to rotate to the center position; i tried to different approaches:

1- Assuming full cycle to be 20 ms: leads to F=1/20ms= 50 Hz. In this case, the duty cycle (1.5ms) would correspond to (1.5ms x4096)/20ms=307 ticks

2-Assuming full cycle to be 21.5 ms: leads to F=1/21.5ms= 46.5Hz. In this case, the duty cycle (1.5ms) would correspond to (1.5ms x4096)/21.5ms=285 ticks.

In both cases, the servo does not rotate exactly to its center position, although close to it.
The reason I considered the full cycle to be 21.5ms instead of 20 ms, is to make sure there is 20 ms between each 1.5ms high pulse, as required by the servo manufacturer. If we consider each full cycle to be 20 ms instead, then the time between each high pulse would become 18.5ms, which is not what the servo spec requires.

So I had to "manually" adjust the number of ticks to reach the optimal 0, 90 & 180 degrees position of the servo.

Thanks,
Hassan
Posts: 4
Joined: Thu Jan 15, 2015 11:54 pm
Location: Canada
by ame » Tue Jan 20, 2015 8:50 pm
hnajibeddine wrote:Many thanks for your reply Joan.
It seems some Trial and error would definitely end up determining the optimal values for how to control a servo, but I noticed they don't always coincide with the theoretical values, specially when converting the pulse width from ms to ticks (on the raspberry, https://learn.adafruit.com/adafruit-16- ... -reference ): per ex, one of my servos requires a 1.5 ms pulse every 20 ms to rotate to the center position; i tried to different approaches:

1- Assuming full cycle to be 20 ms: leads to F=1/20ms= 50 Hz. In this case, the duty cycle (1.5ms) would correspond to (1.5ms x4096)/20ms=307 ticks

2-Assuming full cycle to be 21.5 ms: leads to F=1/21.5ms= 46.5Hz. In this case, the duty cycle (1.5ms) would correspond to (1.5ms x4096)/21.5ms=285 ticks.

In both cases, the servo does not rotate exactly to its center position, although close to it.
The reason I considered the full cycle to be 21.5ms instead of 20 ms, is to make sure there is 20 ms between each 1.5ms high pulse, as required by the servo manufacturer. If we consider each full cycle to be 20 ms instead, then the time between each high pulse would become 18.5ms, which is not what the servo spec requires.

So I had to "manually" adjust the number of ticks to reach the optimal 0, 90 & 180 degrees position of the servo.

Thanks,
Hassan


This is just muddy thinking. If you are required to send a pulse every 20ms then you should measure 20ms between leading edges. That's how it should be. However, no servo requires such accuracy, and this timing is purely nominal. You could send pulses twice as often, or half as often and it would still work. Certainly, the difference between 20ms and 21.5ms is of no consequence.

Secondly, servos are consumer items and bound to vary in construction and calibration. It is no surprise that a 1.5ms pulse does not move the servo arm precisely to its centre position.

Servo control signals are nominally 1 to 2ms, with 1.5ms representing the centre position. But, this range might be wider or narrower for any particular servo. Furthermore, the position at each end of the range is not standard. For one servo, 1ms might be the leftmost extent of travel. For another, it might be the rightmost.

If you look at radio control transmitters you will see adjustments for centre, range and direction. Your software should have the same parameters, and you should not expect them to be the same for each servo.
Posts: 2323
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea
by hnajibeddine » Wed Jan 21, 2015 3:06 am
First, Thanks for taking the time to respond.
I must say I have limited experience with servos, but It's clear to me every servo comes with different specs, but it wasn't clear how accurate I need to be with the pulse width and frequency. Now it's clear to me that it's not as critical unless I'm working with highly accurate servos, in which case I wouldn't consider the thinking exposed in my previous response as muddy, as we would need to accurately generate the pulse at the required frequency, specified by the Servo manufacturer.
Posts: 4
Joined: Thu Jan 15, 2015 11:54 pm
Location: Canada
by ame » Wed Jan 21, 2015 3:23 am
hnajibeddine wrote:First, Thanks for taking the time to respond.
I must say I have limited experience with servos, but It's clear to me every servo comes with different specs, but it wasn't clear how accurate I need to be with the pulse width and frequency. Now it's clear to me that it's not as critical unless I'm working with highly accurate servos, in which case I wouldn't consider the thinking exposed in my previous response as muddy, as we would need to accurately generate the pulse at the required frequency, specified by the Servo manufacturer.


You are confusing the effect that the pulse width or duty cycle has on the frequency (hint: none).
Posts: 2323
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea
by joan » Wed Jan 21, 2015 9:04 am
hnajibeddine wrote:First, Thanks for taking the time to respond.
I must say I have limited experience with servos, but It's clear to me every servo comes with different specs, but it wasn't clear how accurate I need to be with the pulse width and frequency. Now it's clear to me that it's not as critical unless I'm working with highly accurate servos, in which case I wouldn't consider the thinking exposed in my previous response as muddy, as we would need to accurately generate the pulse at the required frequency, specified by the Servo manufacturer.

The pulse width is critical for all but the poorest quality servos. The number of pulses transmitted per second is not so important.
User avatar
Posts: 8520
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by hnajibeddine » Wed Jan 21, 2015 8:16 pm
Perfect, got it. Thank you guys for all the help, much appreciated.
Posts: 4
Joined: Thu Jan 15, 2015 11:54 pm
Location: Canada