0. Calibrating the PiCar-X

Calibrate Motors & Servo

Some servo angles may be slightly tilted due to possible deviations during PiCar-X installation or limitations of the servos themselves, so you can calibrate them.

Of course, you can skip this chapter if you think the assembly is perfect and doesn’t require calibration.

  1. Run the calibration.py.

    cd ~/picar-x/example/calibration
    sudo python3 calibration.py
    
  2. After running the code, you will see the following interface displayed in the terminal.

    ../_images/calibrate11.png
  3. The R key is used to test if the 3 servos are working properly. After selecting a servo with the 1, 2 or 3 keys, then press the R key to test that servo.

  4. Press the number key 1 to select the front wheel servo, and then press the W/S key to let the front wheel looks as forward as possible without skewing left and right.

    ../_images/calibrate21.png
  5. Press the number key 2 to select the Pan servo, then press the W/S key to make the pan/tilt platform look straight ahead and not tilt left or right.

    ../_images/calibrate31.png
  6. Press the number key 3 to select the tilt servo, then press the W/S key to make the pan/tilt platform look straight ahead and not tilt up and down.

    ../_images/calibrate41.png
  7. Since the wiring of the motors may be reversed during installation, you can press E to test whether the car can move forward normally. If not, use the number keys 4 and 5 to select the left and right motors, then press the Q key to calibrate the rotation direction.

    ../_images/calibrate6.png
  8. When the calibration is completed, press the Spacebar to save the calibration parameters. There will be a prompt to enter y to confirm, and then press Ctrl+C to exit the program to complete the calibration.

    ../_images/calibrate51.png

Calibrate Grayscale Module

Due to varying environmental conditions and lighting situations, the preset parameters for the greyscale module might not be optimal. You can fine-tune these settings through this program to achieve better results.

  1. Lay down a strip of black electrical tape, about 15cm long, on a light-colored floor. Center your PiCar-X so that it straddles the tape. In this setup, the middle sensor of the greyscale module should be directly above the tape, while the two flanking sensors should hover over the lighter surface.

  2. Run the grayscale_calibration.py.

    cd ~/picar-x/example/calibration
    sudo python3 grayscale_calibration.py
    
  3. After running the code, you will see the following interface displayed in the terminal.

    ../_images/calibrate_g1.png
  4. Press the “Q” key to initiate the greyscale calibration. You’ll then observe the PiCar-X make minor movements to both the left and the right. During this process, each of the three sensors should sweep across the electrical tape at least once.

  5. Additionally, you will notice three pairs of significantly different values appearing in the “threshold value” section, while the “line reference” will display two intermediate values, each representing the average of one of these pairs.

    ../_images/calibrate_g2.png
  6. Next, suspend the PiCar-X in mid-air (or position it over a cliff edge) and press the “E” key. You’ll observe that the “cliff reference” values are also updated accordingly.

    ../_images/calibrate_g3.png
  7. Once you’ve verified that all the values are accurate, press the “space” key to save the data. You can then exit the program by pressing Ctrl+C.