Getting on the Road!

Share for us

Make sure all the procedures have been finished, and check there is no problem about the mechanical assembly and software installation. Then you can start the car now. Install two batteries, and turn on the power switch.

Tips: If you keep the Raspberry Pi power on from the beginning, now you do not need to turn it off. DO NOT unplug the Micro USB cable until you’ve installed the batteries and switched it on. So you do not need to turn it on or off again. If later the batteries run out, or half does, and you want to do the debugging, you can also just plug in the USB cable for power without shutting down. The Robot HATS integrates a backflow prevention diode to protect it from being damaged by the USB power, so does the Raspberry Pi. So take it easy for using the two power sources at the same time!

Here is what we’re going to do:

Use the Raspberry Pi as the server. Run a web server with an API for controlling the car and transmitting images captured by the camera.

Then take a PC, cell phone, or tablet as the client, and acquire the images from the camera and control the car by calling the API of the web server.

1. Run the Server

Remotely log into the Raspberry Pi. You can find a startup script start under the remote_control directory. Run the script to start the web service.

cd ~/SunFounder_PiCar-V/remote_control 

sudo ./start 

The script will enable the service and the corresponding data will appear. The hardware is initialized at the same time, so the servos connected to the front wheels and the pan-and-tilt will turn, indicating the hardware initialization is done.

pi@raspberrypi:~ $ cd ~/SunFounder_PiCar-V/remote_control/
pi@raspberrypi:~/SunFounder_PiCar-V/remote_control $ sudo ./start
Server running
Performing system checks… 

DEBUG “front_wheels.py”: Set debug off
DEBUG “front_wheels.py”: Set wheel debug off
DEBUG “Servo.py”: Set debug off
DEBUG “back_wheels.py”: Set debug off
DEBUG “TB6612.py”: Set debug off
DEBUG “TB6612.py”: Set debug off
DEBUG “PCA9685.py”: Set debug off
DEBUG “camera.py”: Set debug off
DEBUG “camera.py”: Set pan servo and tilt servo debug off
DEBUG “Servo.py”: Set debug off
DEBUG “Servo.py”: Set debug off
None
System check identified no issues (0 silenced).
November 09, 2016 – 06:28:41
Django version 1.10.2, using settings ‘remote_control.settings’
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

If you get the result similar as shown above, the server is ready. Now move on to start the client.

2. Run the Client

There are TWO methods to run the client. On one hand, you can open Client in the directory of the SunFounder_PiCar-V in PC, run client.py by Python 3. Or, if you happen to fail to install PyQt 5 or Python 3, or just want to control it on your phone or tablet, we have also prepared a web client via web browser.

-       Method A

Open Client in the directory of the SunFounder_PiCar-V in PC, run client.py by Python 3.

If yours PC runs on Linux, you can run python 3 client.py in the terminal.

python client.py   # If Python 3 is the default or only python

python3 client.py  # Or you have both Python 2 and Python 3, and the default is Python 2

If it runs on Windows, since Python 3 has been installed previously, you can just double-click to run client.py. Make sure it runs under Python 3 not Python 2, if both are installed in your PC.

Notes:

In Linux, if only Python 3 is installed, python = python 3 in the terminal; if there’re both Python 2 and Python 3 (quite a lot of systems have those two pre-installed), the python command will start Python 2 by default. To use Python 3, you need to use python 3 commands. Or you can configure the Python environment, to set the Python 3 as default.

Run the client and you will see:

This is the login interface of the client. Enter your Raspberry Pi’s IP address and the port, 8000 by default, and then click Log in to connect to the Raspberry Pi. It may take a while to establish connection, sometimes may not respond at all, so just wait several seconds. If it’s successful, you’ll be on the operation interface. If not, double check your Raspberry Pi’s IP address and make sure the server script is run without error prompts. 

The interface will show the view captured by the camera in a real-time manner. 

There are some number buttons at the bottom to adjust the car’s speed,ascending from level 1 to 5. You can also press the key 1-5 on the keyboard. The rest control movements of the car are implemented by keyboard. 

On keyboard:

WS: to control the rear wheels to move forward/backward;

AD: to control the front wheels to turn left/right;

: to control the camera’s rotating up/down;

: to control the camera’s rotating left/right.

Click the left arrow button at the bottom left or press Alt + ← to return to the previous page, that is, the login.

For better application, you’re recommended to calibrate the assembled car first.

Click the setting button at the bottom right or press Alt S, and you will see the Calibration page as below (click the three larger icons for the corresponding calibration):

Camera – to calibrate the camera movement. Short cut: Alt + C.

Front Wheels – to calibrate the front wheels. Short cut: Alt + F.

Rear Wheels – to calibrate the rear wheels. Short cut: Alt + R.

Click the arrow return button or Alt + ← and you will go back to the operation interface.

Calibration: Camera

When completed, the camera should look like the figure above. The camera should be in the center line of the car and face exactly front. You can use the keyboard to adjust, by the arrow keys ↑, ←, ↓, and →, or WAS, and D. The servo turning angle is very small, so it’s quite suitable for fine tuning; press and hold it to coarsely adjust quickly. Click OK or press Alt + O to save the calibration result; click Cancel or press Alt + C to cancel the calibration and exit.

Notes:

During the calibration, the servo may get stuck with an abnormal sound, and heated abnormally after a while if the servo shaft is not adjusted to 90° in the previous mechanical assembly. You should at once disconnect the wires of the servo and remove the rocker arm to readjust the shaft to 90° (refer to the previous Servo Configuration part).

After all the adjustments are done, click OK, and the server will write the data into the database files. Then the servo will respond to the database initialization with a little movement. Only after the initialization is done can you start the next step, or the server will reject the calibration request.

Calibration: Front Wheels

Adjust the front wheels to the appropriate position according to the above figure. You can use the keyboard to adjust, that is, A, and D.

Click OK or press Alt + O to save the calibration result; click Cancel or press Alt + C to cancel the calibration and exit.

If the servo gets stuck, remove the rocker arm and readjust again (refer to the Servo Configuration).

Calibration: Rear Wheels

Adjust the rotating direction of the rear wheels, to make the car go forward. Adjust the wheels by the keys  and  or A and D. The left and right is to control the left and right wheels respectively and each clicking will reverse the rotation of the wheel.

After all the calibration is done, you can return to the operation interface. Make sure both LED indicators on the Robot HATS board light up. Now you can unplug the Micro USB cable and put the car on the ground. Let’s start the journey!

-       Method B

Visit the server of the car at http://<RPi_IP_address>:8000/. You will see a welcome page:

Click LET’S ROCK to go to the operation interface:

On this page, you can press the keys WAS, and D on the keyboard to control the car to move forwardbackwardturn left, and turn right, press the arrow keys to control the camera’s movement, and number 1~5 to change the speed level.

Also for mobile phones, tap the FULLSCREEN button to have a better view and performance. Then, tap the buttons of 5 speed levels on the page to control the speed, and the arrow buttons to control the direction of the car and the pan-and-tilt. But you can only tab one touchpoint at one time.

Click FULLSCREEN again to bring back the title bar. And then, tap the setting button at the top-right corner of the page to go to the calibration page:

There are three calibration parts: Camera CalibrationFront Wheels Calibration and Rear Wheels Calibration.

Do the calibration for the servos and motors just as done in the PyQt client. Click OK to save the result after all the calibration is done.

Take this screenshot from an Android phone:

Though the appearance may not be as good as on the PC. Later updates may be released irregularly on Github. You are welcome to fork our repository and submit a Pull request with your changes. If there is no problem after testing, we are more than pleased to merge your request.