Understanding servos and calibration
What is a servo?
A servo is a motor that can rotate to a specific angle on command. Unlike a regular motor that just spins continuously, a servo holds a precise position — for example, “turn to exactly 15 degrees left.” Your PiCar-X has three servos:Why calibrate?
Every robot is slightly different due to manufacturing tolerances. Without calibration:- A “go straight” command might actually steer 5° to the left
- The camera might be tilted slightly down when it should be level
- Line-following code won’t detect tape correctly
/opt/picar-x/picar-x.conf. This file persists across reboots and is loaded automatically whenever any script creates a Picarx() object.The calibration script
Run the calibration script with:Mode 1 — Zero (for assembly only)
Mode 1 — Zero (for assembly only)
1, then press Enter when prompted. The servos snap to 0° and hold there until you press Ctrl+C.Servo calibration (mode 2)
Press2 at the main menu, then press Enter to begin. The script walks you through four steps in order: steering, camera pan, camera tilt, and motor direction.
Step 1: Steering servo
The steering servo controls which direction the front wheels point. Your goal is to make the car drive in a perfectly straight line. Controls:- The
|in the center represents 0° (no offset) - The
#shows your current offset position - The number (
-8.0) is your exact offset in degrees (1deg)shows your step size — pressfto switch to(FINE)for 0.5° steps
Start the car driving
t to toggle continuous driving. The car starts moving forward at low speed. It keeps driving until you press t again.Watch the car's path
Nudge the steering
a or d to adjust:- Car veers right → press
ato nudge left - Car veers left → press
dto nudge right
Fine-tune
f to switch to fine mode (0.5° steps). Make small adjustments until the car tracks straight.Verify
t to stop driving, then press Space for a clean 3-second test drive. Watch the car — it should drive forward in a straight line for the full 3 seconds without curving.If it still curves, keep adjusting and test again.Accept
Step 2: Camera pan servo
The camera pan servo rotates the camera left and right. Your goal is to make the camera face directly forward when at its zero position. Controls:Look at the camera from above
Nudge until centered
a or d to rotate the camera until it faces directly forward.Wiggle to verify
w to wiggle. The camera sweeps 15° left, then 15° right, then returns to center. Watch whether it sweeps equally in both directions. If the sweep looks lopsided (more to one side), nudge and wiggle again.Accept
w, the camera sweeps equally far to the left and to the right from its center position. The camera lens faces the same direction as the front of the car.Step 3: Camera tilt servo
The camera tilt servo angles the camera up and down. Your goal is to make the camera level — parallel to the ground, looking at the horizon. Controls: Same as camera pan (a/d, f, r, w, Enter).
How to calibrate camera tilt:
Look at the camera from the side
Nudge until level
a or d to tilt the camera until the lens is roughly parallel to the ground.Wiggle to verify
w to wiggle. The camera should tilt equally up and down from its center position.Accept
Step 4: Motor direction
The script now tests whether the motors spin in the correct direction. “Forward” should mean the car moves away from you (in the direction the camera faces).Test the motors
t. The car drives for 3 seconds, then stops.Check the direction
- Yes, it went forward → press
yto confirm. - No, it went backward → press
nto swap the motor direction.
Re-test if you swapped
n, press t again to verify the car now drives forward correctly, then press y.Save your calibration
After all four steps, the script shows a summary:y and press Enter to save. You see:
Grayscale sensor calibration (mode 3)
Run the calibration script again and press3 at the main menu:
What is the grayscale sensor?
On the bottom of your PiCar-X, there are 3 infrared sensors arranged in a row — left, center, and right. Each sensor shines an infrared light downward and measures how much light bounces back.- Line following — detecting a strip of dark tape on a light floor so the car can follow it
- Cliff detection — detecting when there’s nothing below (like a table edge) so the car can stop before falling
Step 1: Line tracking calibration
The car needs to learn what “dark tape” and “light floor” look like to its sensors. It does this by physically driving over the tape and recording the sensor readings. What you need: A strip of dark tape (black electrical tape works well) on a light-colored floor, at least 15 cm (6 inches) long.Position the car over the tape
Press Enter to start
Watch the car sweep
Review the results
Step 2: Cliff detection calibration
Now the car needs to learn what “nothing below” looks like. When the sensors see open air (no surface reflecting light back), the readings drop very low.Pick up the car
Press Enter
Hold steady for 2 seconds
Review the cliff reference
Testing the calibration
Before saving, you can test whether the calibration works correctly. The script shows:t to start live sensor readings. You see a table that updates every half-second:
Test on the light floor
[0, 0, 0] (no line detected), Cliff = noTest on dark tape
[0, 1, 0] (center sensor detects line), Cliff = noTest in the air
YES- Light floor → Line
[0, 0, 0], Cliffno - Center on tape → Line
[0, 1, 0], Cliffno - In the air → Cliff
YES
Save grayscale calibration
Typey and press Enter to save:
Verify calibration persisted
After saving, confirm your values actually stuck by restarting the script:Picarx(). You can press q to quit.
