Share for us

Remember the commands to adjust the servo to 90 degrees previously? Now, let’s talk about the other two commands.

The second command front-wheel-test is used to test whether the front wheels can turn flexibly after assembly. When you run this command, it will drive them to turn left and right. Besides, there is an optional parameter [chn]. It will be used only when you change the PWM channel of the servo. If you use the default channel 0 according to the wiring diagram, there is no need to enter [chn].

pi@raspberrypi:~ $ picar front-wheel-testDEBUG “”: Set debug offDEBUG “”: Set wheel debug offDEBUG “”: Set debug offturn_leftturn_straightturn_rightturn_straightturn_leftturn_straightturn_right^Cturn_straight

You may find the direction of the front wheels is not facing exatly front when they are in the straight status (they will return to the status anytime the front wheels program stops running). If there is an obvious deviation from the middle line of the front chassis, remove the servo and run servo-install again; if it is just a little deviation (like about 0~15 degrees), it can be adjusted by software.

Get into the folder SunFounder_PiCar/picar:

cd /home/pi/SunFounder_PiCar/picar


pi@raspberrypi:~ $ cd /home/pi/SunFounder_PiCar/picarpi@raspberrypi:~/SunFounder_PiCar/picar $        SunFounder_PCA9685config        SunFounder_TB6612pi@raspberrypi:~/SunFounder_PiCar/picar $

Open the config file under the folder with an editor. You can see a few parameters. Modify the value of turning_offset (the first parameter) to adjust the front wheels. Its value is 0 by default, and you can turn the wheels left by decreasing the value, or turn right by increasing it. For example, if you want to make the front wheels turn right a bit, just modify it to a larger number; to make it more towards the left, you can set it smaller (it can even be a negative number).

But DO NOT over-configure the wheels (recommended a value between -30 and 30), or the servo may be stuck and broken.

pi@raspberrypi:~/SunFounder_PiCar/picar $ nano config

GNU nano 2.2.6                      File: config# File based database turning_offset = 10 forward_A = 1 forward_B = 1[ Read 9 lines ]^G Get Help   ^O WriteOut    ^R Read File   ^Y Prev Page  ^K Cut Text     ^C Cur Pos^X Exit       ^J Justify     ^W Where Is    ^V Next Page  ^U UnCut Text   ^T To Spell

After changing the value of turning_offset, press Ctrl O to save the changes, and press Ctrl + X to exit. Run the command picar servo-install to check the front wheel’s status.

pi@raspberrypi:~/SunFounder_PiCar/picar $ picar servo-installpi@raspberrypi:~/SunFounder_PiCar/picar $

If the front wheels is still not facing the exact front, you may need to edit the file config for a couple of times. The front wheels may need to be adjusted about 3 to 5 times usually. We can move on to calibration of the rear wheels when the front wheels are done.

Since the wiring of the two DC motors is random, the VCC and GND of a motor may be connected to the wheel reversely, causing the wheel to spin forward when it should do backward as configured in the code. Thus we can use the third command which will drive the rear wheels to simultaneously speed up and slow down alternately.

pi@raspberrypi:~ $ picar rear-wheel-testDEBUG “”: Set debug offDEBUG “”: Set debug offDEBUG “”: Set debug offDEBUG “”: Set debug offForward, speed = 0Forward, speed = 1Forward, speed = 2Forward, speed = 3Forward, speed = 4Forward, speed = 5Forward, speed = 6Forward, speed = 7Forward, speed = 8Forward, speed = 9Forward, speed = 10          .          .          .Backward, speed = 10Backward, speed = 9Backward, speed = 8Backward, speed = 7Backward, speed = 6Backward, speed = 5Backward, speed = 4Backward, speed = 3Backward, speed = 2Backward, speed = 1Finished, motor stop

Check whether both the two rear wheels rotate direction is the same as the screen promt. Note that the two wheels are driven by the two motors separately. It may happen that one rotates forward, while the other does backwards. If so, we need to adjust one or both two wheels which rotate reversely under that command.

The two other parameters in the file config are to set the rear wheels: forward_A and forward_B. They can change the default spinning direction of the two motors. The value can only be 0 or 1, which represents clockwise and counterclockwise rotation. By default, it’s 1 for both parameters. Thus if a wheel spins reversely, you only need to change the corresponding parameter for the wheel to 0.

Press Ctrl + O to save the changes, and press Ctrl + X to exit. Run the command picar rear-wheel-test again to check whether the rear wheels are rotating in accordance with the command.

Copy config to the directory example under PiCar-S.

pi@raspberrypi:~/SunFounder_PiCar/picar $ cp config ~/SunFounder_PiCar-S/example