-1

I am using a Raspberry Pi 3B+ with servomotor shields to control multiple servomotors at once with Python. I know that the travel angle of a servomotor is controlled using PWM. So there exists a linear mapping between travel angle and duty cycle :

In order to achieve a particular travel angle depending on time, what is the function describing the angle, that is to say, what is ? I heard that it was more or less a "smooth step" (sigmoid) function of time. Is it possible to choose and modify that function? If yes, any suggestion on how?

2
  • Oh my goodness, so many scary Greek alphabets and math functions. Can you please use everyday English for dummies? Question - What is "travel angle"?
    – tlfong01
    Commented Apr 23, 2019 at 10:33
  • 1
    See en.wikipedia.org/wiki/Servo_control and similar. I do not understand the question.
    – joan
    Commented Apr 23, 2019 at 12:17

1 Answer 1

0

Question

When using Rpi3B+ python to control servo using PWM,

If d = f(t) where d = angular distance traversed, t = time

  1. Is f a smooth step function?

  2. Any suggestion to modify the function?

Answer

d = f(t), f is only a rough step function

Let us use a toy servo as an example. There is a 4 bit Amtel mcu inside doing simple proportional P (not PID) control. In other words, motor starts moving quickly and gradually slows down as the target position gets nearer and nearer. It is P, not PID, therefore the step with much overshooting/damping is not that smooth.

I know the speed of typical toy servo is about 60 degrees every 0.1 second. In other words, 0.1 x (360/60) = 0.6 sec per revolution, or 0.6 x 60 = 36 rpm. Usually we hobbyists use this kind of servos to control toy cars or drones. We don't know nothing of scary time functions! :)

However, we do know that the final steady, if not oscillating, trembling position, in degrees, (we don't know nothing of "radian") is a function (depends on) of the pulse width, or duty cycle, if frequency is fixed at the usual 50Hz, 20mS. In other words, the function mapping is something like below:

Domain/Range (independent variable/dependent variable)

pulse width (500uS ~ 2400uS) / +-90 degrees

motor power supply (4.8V ~ 6V) / speed, range with average speed 30rpm

loading / speed (non linear)

Suggestion to get a smooth step function

The very old design using a 4 bit mcu cannot do much more than simple proportional control. If space is not a problem, you can use modern 32bit controllers such as STM32, which is perhaps 1,000 times more powerful. But of course industrial/military/space digital servos are already using 32 bit controllers - toy motors are perhaps 10 years lagging behind! :)

servo operation

servo sg90

References

Your Guide To RC Servos - RC Helicopter Fun

How Do Servo Motors Work? - Jameco

Servo motors are small in size, used in radio-controlled toy cars, robots and airplanes.

How do the little guys work?

The servo circuitry is built right inside the motor unit and has a positionable shaft, which usually is fitted with a gear. The motor is controlled with an electric signal which determines the amount of movement of the shaft.

What's inside the servo?

Example - Hitec HS-322HD Standard Heavy Duty Servo

To fully understand how the servo works, you need to take a look under the hood. Inside there is a pretty simple set-up:

A small DC motor, potentiometer, and a control circuit.

The motor is attached by gears to the control wheel.

As the motor rotates, the potentiometer's resistance changes, so the control circuit can precisely regulate how much movement there is and in which direction.

When the shaft of the motor is at the desired position, power supplied to the motor is stopped. If not, the motor is turned in the appropriate direction. The desired position is sent via electrical pulses through the signal wire.

The motor's speed is proportional to the difference between its actual position and desired position. So if the motor is near the desired position, it will turn slowly, otherwise it will turn fast. This is called proportional control. This means the motor will only run as hard as necessary to accomplish the task at hand, a very efficient little guy.

How is the servo controlled?

Servos are controlled by sending an electrical pulse of variable width, or pulse width modulation (PWM), through the control wire.

There is a minimum pulse, a maximum pulse, and a repetition rate. A servo motor can usually only turn 90° in either direction for a total of 180° movement. The motor's neutral position is defined as the position where the servo has the same amount of potential rotation in the both the clockwise or counter-clockwise direction.

The PWM sent to the motor determines position of the shaft, and based on the duration of the pulse sent via the control wire; the rotor will turn to the desired position.

The servo motor expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will determine how far the motor turns. For example, a 1.5ms pulse will make the motor turn to the 90° position. Shorter than 1.5ms moves it in the counter clockwise direction toward the 0° position, and any longer than 1.5ms will turn the servo in a clockwise direction toward the 180° position.

Variable Pulse width control servo position

When these servos are commanded to move, they will move to the position and hold that position. If an external force pushes against the servo while the servo is holding a position, the servo will resist from moving out of that position. The maximum amount of force the servo can exert is called the torque rating of the servo. Servos will not hold their position forever though; the position pulse must be repeated to instruct the servo to stay in position.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.