The GPIO library provides the set_servo_pulsewidth
method to control the width of a pulse signal within the range of [500-2500]
. We conducted an experiment to measure the steering angle of the servo induced from this pulse width range:
- Determine the relationship between pulse width and the induced steering angle on a servo
- Protractor
- Ruler
- 8.5"x11" Printing Paper
- Pencil
- Car Prototype
- Make sure the hardware connection is established between a GPIO pin and the servo
- Place the car prototype on a standard 8.5"x11" printing paper
- Place the servo on a neutral position and align a ruler with the axis of the wheel (simply place the protractor on the face of the wheel).
- Draw the line along the ruler
- Call
set_servo_pulsewidth(GPIO_PIN, PULSE_WIDTH)
whereGPIO_PIN
is the pin connected to the servo and selectPULSE_WIDTH
from the range[500-2500]
. - Align the ruler with the axis of the wheels and mark the position of the two wheels after turn
- Measure the steering angle with a protractor.
- Repeat Step 5-8 for each desired pulse width.
There is linear relationship between pulse width and the induced steering angle.
- Left Turn (width: 1200 - 1450):
17.9x + 1439
- Right Turn (width: 1550 - 1800):
15.9x + 1561
Through more test on the hardware, I found it more fitting to use one linear mapping, particularly 17.9x + 1439
, as it produce more balanced steering angle around the range between [-18, 18]
for steering angle degree and [1200, 1780]
for pulse width.