Difference between revisions of "Controlling Smart Video Car for RPi on Windows"

From Wiki
Jump to: navigation, search
(Preparation)
(5. Get on the Road!)
Line 156: Line 156:
  
 
You can click '''buttons''' such as '''Forward''' and Backward to control the car moving remotely. Or click '''X+''', '''X-''', '''Y+''', and '''Y-''' to control the coverage of the camera.<br>  
 
You can click '''buttons''' such as '''Forward''' and Backward to control the car moving remotely. Or click '''X+''', '''X-''', '''Y+''', and '''Y-''' to control the coverage of the camera.<br>  
<font color="color:red">Note: <br>
+
<font color="color:red">Note:</font> <br>
 
The server program must be run before you run the client program. Some settings must be completed for the server before the service is done. A communication endpoint needs to be created for the server to "listen" to requests from the client. Take the server as a receptionist or an operator of the bus phone in a company. Once the phone and device installation is completed and the receptionist or operator is in place, the service begins.</font><br>  
 
The server program must be run before you run the client program. Some settings must be completed for the server before the service is done. A communication endpoint needs to be created for the server to "listen" to requests from the client. Take the server as a receptionist or an operator of the bus phone in a company. Once the phone and device installation is completed and the receptionist or operator is in place, the service begins.</font><br>  
 
<font color="color:blue">This article is mainly for Windows users. If you're using Linux, please check our user manual.<br>  
 
<font color="color:blue">This article is mainly for Windows users. If you're using Linux, please check our user manual.<br>  
For further questions, please publish posts on our '''FORUM'''.</font><br>
+
For further questions, please publish posts on our '''FORUM'''.<br>

Revision as of 06:08, 8 August 2017

Note: This article is abstracted from our latest user manual. So if you have one with "Reprint 3.0" at the Preface, you can just follow the book.

1. Download and Install Raspbian on a TF Card

If you've already installed the Raspbian system, please skip this step.
Search out the installation guide for Raspbian on the Raspberry Pi website at https://www.raspberrypi.org/downloads/. Then download the Raspbian to your TF card and install it.
After the installation, you may need some basic settings for the Raspberry Pi. Check out the guide for the setting on our website https://www.sunfounder.com.

2. Get Source Code

Step 1. Download the source code directly from Github to your Raspberry Pi.

cd ~
git clone https://github.com/sunfounder/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi.git

Step 2. Download the source code directly from Github to your PC:
https://github.com/sunfounder/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi,
Or search for Sunfounder in Github and find the repository:
Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi.
Click Download ZIP on the sidebar of the page, as shown below.

Gitclone.png

After download, go to the file and extract it. So now you have the source code folder.

3. Basic Software Environment

Operation on PC

Go to the Python website https://www.python.org, find the latest Python 2 and install. After installation, DO restart the computer.  

Operation on Raspberry Pi

Install python-dev, python-smbus

Install python-dev and python-smbus:

sudo apt-get update
sudo apt-get upgrade 
sudo apt-get install python-dev
sudo apt-get install python-smbus

Setup I2C port

Run the command to open Raspberry Pi Software Configuration Tool (raspi-config)

sudo raspi-config

Enable I2C:
Select Advanced Options => I2C => <Yes> => <Ok> => <Yes>
Select <Finish>. Close the window.
If a message of rebooting appears, click <No>. Before reboot, we still need to complete some configurations.

MJPG-streamer

1. Installation
Plug the USB camera into Raspberry Pi, and run the command lsusb. The GEMBIRD represents the USB camera; since it is printed on the screen, it indicates the system has recognized the camera.

lsusb

You'll see:

pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 1908:2310 GEMBIRD
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Check whether the driver for the camera works normally:

ls /dev/vid*

You'll see:

pi@raspberrypi:~ $ ls /dev/vid*
/dev/video0

If /dev/video0 is printed, the driver is in the normal state.
Then, install the following software needed:

sudo apt-get install subversion
sudo apt-get install libv4l-dev
sudo apt-get install libjpeg8-dev
sudo apt-get install imagemagick

Compile the source code of MJPG-streamer:

cd /home/pi/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/mjpg-streamer/mjpg-streamer
sudo make USE_LIBV4L2=true clean all

Install:

sudo make DESTDIR=/usr install

2. Testing
Type in sudo sh start.sh and press Enter.
On your computer, open a web browser (Chrome or Firefox recommended).
Type in the following address (replace 192.168.0.126 with your Raspberry Pi IP address) at the address bar of your browser:
http://192.168.0.126:8080
Press Enter and you will see the view captured by the camera displayed on the screen in a real-time manner.

2.png

4. Calibration

Preparation

1. Run the Server
Run the calibration server on the Raspberry Pi, and wait for client to connect.
Make sure that the circuit is connected properly. Power the smart car, open a terminal in Linux. Connect with your Raspberry Pi via the ssh. Go to the directory Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/server, run the server cali_server.py: if the servo gets stuck with an abnormal sound, unplug the wires at once, and redo servo adjustment for calibration in case of further damages.

cd ~/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/server
sudo python cali_server.py

Shuixingban-19.png

Then the contents of config are printed and the last line: Waiting for connection…
At this time, the car might move a bit (this is the original position set).
2. Run the Client
Run the calibration client on PC to connect the server on Raspberry Pi.
Unzip the code package you downloaded.
Click the Start button on your computer, and type in python in the search bar, and you can find the IDLE (Python GUI). Click it and then a window will pop up.

11-2.png

Click File -> Open -> Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi-master -> client -> cali_client.py to open this file, modify the value of HOST for the IP address of the Raspberry Pi.

Shuixingban-23.png

After modification, save the file and click the Run menu, and select Run Module. Then a window Raspberry Pi Smart Video Car Calibration will pop up:
Shuixingban-24.png

In the terminal remotely connected with the Raspberry Pi, the IP address of the PC will be printed.

Shuixingban-25.png

Then you can start calibrating. Before that, take out your package box and place it vertically with the side face to the table. Put the car onside the box and keep it balanced. The purpose is to keep the wheels of the car off the table.
By default, the front wheels should be directly pointed towards the front; the camera on the tilt servo should be face up no matter what directions the pan servo is pointed at. If not, you may adjust the directions in Raspberry Pi Smart Video Car Calibration.
For the detailed calibration instructions, please follow the user manual in your package.

5. Get on the Road!

1. Run the Server
Run the TCP server on the Raspberry Pi, and wait for the client to connect to control the car.
You need two terminals to run the server. One is to run tcp_client.py to receive commands to control the car, and the other to run mjpg-streamer to provide video streams. In Windows, you can use PuTTy to remotely log into the Raspberry Pi to start the server.
Open a terminal.
The Raspberry Pi may be still at the server directory:

pi@raspberrypi ~/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/server $ 

If not, go to the directory with cd.

cd ~/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/server

Then run tcp_server.py:

sudo python tcp_server.py

The server program on the Raspberry Pi will be running and waiting for the client to connect to the Raspberry Pi.

Shuixingban-20.png

Open another terminal. Log in the Raspberry Pi remotely, and switch to the directory under which the program of MJPG-streamer lies:

cd ~/Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/mjpg-streamer/mjpg-streamer

Vijayanagara time kannada letter 'a'.png

Run the program:

sudo sh start.sh

Then the video data acquisition will start, like this:

10.png

Type in the following address (replace 192.168.0.xxx with the IP address of your Raspberry Pi) at the address bar of your browser (Firefox is recommended):
http://192.168.0.xxx:8080/stream.html
Press Enter and you will see the view captured by the camera displayed on the screen in a real-time manner.
2. Run the Client
Run the client on PC to connect the server on the Raspberry Pi.
Open the IDLE

11-2.png

Click File -> Open -> Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi-master -> client -> client App.py to open this file, modify the value of the HOST for the IP address of the Raspberry Pi.

Shuixingban-21.png

After modification, save the file and select Run -> Run Module.
Then the following window will appear on your screen:

13.png

You can click buttons such as Forward and Backward to control the car moving remotely. Or click X+, X-, Y+, and Y- to control the coverage of the camera.
Note:
The server program must be run before you run the client program. Some settings must be completed for the server before the service is done. A communication endpoint needs to be created for the server to "listen" to requests from the client. Take the server as a receptionist or an operator of the bus phone in a company. Once the phone and device installation is completed and the receptionist or operator is in place, the service begins.</font>
This article is mainly for Windows users. If you're using Linux, please check our user manual.
For further questions, please publish posts on our FORUM.