Authorized Online Retailers

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES

Objective

In this lesson, we will learn how to let the robot car has vision to see front environtment and how to control the robot car through web browser or mobile APP.

To complete this task, we need install a web server software called "mjpg-streamer" in Raspberry Pi, this software will catch video from Robot Car camera and send the video to a web page.

We also need to install another web server software called "WebIOPi" in Raspberry Pi. This software will allow use to control Raspberry Pi GPIO input/output and therefore control the movement of our robot motor.

 

Parts and Devicess

Device

Picture
Qty.

Accessories

Raspberry Pi 3 Board

(Not in Package)

1

M2.5*5 Plastic Screw x 4

M2.5 Plastic Nut x 4

M2.5*5+6 Plastic Pillar x 4

OSOYOO Model-Pi Motor Driver Module
1

M3*6 Plastic Screw x 4

M3 Plastic Nut x 4

M3*5+6 Plastic Pillar x 4

PAC9685 Module
1

M2.5*5 Plastic Screw x 4

M2.5 Plastic Nut x 4

M2.5*5+6 Plastic Pillar x 4

Camera with mount holder
1

M3*10 Screw x2

M3 Nut x 2

Voltage Meter
1

M2.5*5 Plastic Screw x 2

M2.5 Plastic Nut x 2

M2.5*5+6 Plastic Pillar x 2

Tracking Sensor Module
5

M2.5*5 Plastic Screw x 5

M2.5 Plastic Nut x 5

M2.5*5+6 Plastic Pillar x 5

Car Chassis
1
Motors with wires
2
Wheels
2

Universal Wheel

1 M3*10 Screw *2

M3 nut x 2

18650 Battery Box
with 2Pin
connectors
1 M3*10 Screw x 4

M3*10 Nut x 4

Metal Motor Holders
2
SD Card Reader
1
16GB TF card
1
Phillips Screwdriver
1
Slot Type Screwdriver
1
HDMI to HDMI Cable
1
L USB port to Micro USB port cable
1
Camera to Raspberry Pi cable
1
5Pin x20cm, 4pin x20cm, 4pin x10cm, 3pin x15cm, 2pin
x20cm, 2pin x10cm, 1 female to 5 female red, 1 female to
5 female black jumper wire
1
Cable Tie 20
Black electrician tape 1

top

Software Installation((if you use our image as OS system,
please skip Software Installation):

Step 1: Download WebIOPi/mjpg-streamer installation package by running following terminal commands

cd ~

sudo  apt-get  install  rpi.gpio  -y

mkdir   osoyoo-robot/cam-robot

cd   osoyoo-robot/cam-robot

wget  http://osoyoo.com/driver/WebIOPi-0.7.1.tar.gz

wget  http://osoyoo.com/driver/mjpg-streamer.tar.gz

wget  http://osoyoo.com/driver/robot.tar.gz

tar  -xzvf  WebIOPi-0.7.1.tar.gz

tar  -xzvf   mjpg-streamer.tar.gz

tar  -xzvf  robot.tar.gz

 

Following Step 2 to 4 are for WebIOPI server Installation

Step 2: Download and install WebIOPi patch by running
following terminal command

cd  ~/osoyoo-robot/cam-robot/WebIOPi-0.7.1/

wget   http://osoyoo.com/driver/webiopi-pi2bplus.patch

patch    -p1   -i  webiopi-pi2bplus.patch

 

Step 3: Install WebIOPi  by running following terminal command

sudo  ./setup.sh

You need verify the installation by typing following command

webiopi  -h

If WebIOPi is installed successfully, you will see following message in terminal,
otherwise you might need redo the downlo and and installation.

 sudo webiopi [-h] [-c config] [-l log] [-s script] [-d] [port]

    Options:
      -h, --help           Display this help
      -c, --config  file   Load config from file
      -l, --log     file   Log to file
      -s, --script  file   Load script from file
      -d, --debug          Enable DEBUG

    Arguments:
      port                 Port to bind the HTTP Server

Step 4: Run webiopi by typing following command:

sudo  webiopi  -d  -c  /etc/webiopi/config

Use a browser in another computer (in same LAN of your Pi)
to visit your Pi's Ip address with port 8000( i.e
http://192.168.1.16:8000 if 192.168.1.16
is your Pi's local IP address), your browser will show WebIOPi login page.
 
You need use default WebIOPi user name webiopi and default password raspberry
to login to the server. Once you are logged into WebIOPi page, you will see
WebIOPI Main Menu as following. If you can not see this page , you need to
reinstall the WebIOPI software.

To end WebIOPi running, press Ctrl-C then Ctrl-Z .




Following Step 5 to 7 is for  mjpg-streamer server Installation

Step 5.  If you are using CSI camera , please take following
action as per step A and B.

 If you are using USB camera which comes with the car, please skip this step




A. enable camera in Raspberry Pi

sudo  raspi-config

Select Enable Camera

B. use nanoe to edit /etc/modules file (otherwise /dev has
no camera device node) by typing following command

sudo   nano  /etc/modules

in the bottom of the /etc/modules file, add following
line

bcm2835-v4l2

use ctrl x to save and exist nano editor

 

Step 6: download and install mjpg-streamer support library by typing following command

cd ~

sudo apt-get update

sudo apt-get install libv4l-dev libjpeg8-dev -y

sudo apt-get install subversion -y

Step 7: Compile mjpg-streamer

First we need use nano to edit the configuration file input_uvc.c

cd  ~/osoyoo-robot/cam-robot/mjpg-streamer/plugins/input_uvc

sudo  nano  input_uvc.c

find following line

 int width=640, height=480, fps=5, format=V4L2_PIX_FMT_MJPEG

replace the string V4L2_PIX_FMT_MJPEG 
in above line with new string V4L2_PIX_FMT_YUYV

Then use Ctrl X save and exit

Now we need compile the source code with following commands:
cd  ~/osoyoo-robot/cam-robot/mjpg-streamer
make all

Test camera installation
Plug your camera into Raspberry Pi, then type following command:
 ls   /dev/video*

You should see following result in your terminal, /dev/video0 is the camera
installed in Pi

 

Run mjpg-streamer Server by typing following command in terminal:

Now use browser in another computer to access your Raspberry Pi IP
address with port 8899 (i.e, if your Pi IP address is 192.168.0.16, visit
http://192.168.0.16:8899 in your
browser), you will see following image. click Stream button in left menu, you
will see the real time video captched by the camera in your Raspberry Pi

You can use Ctrl C command in terminal to end the  mjpg-streamer server

If you don't know your raspberry pi IP address, type following command in your
terminal,

ifconfig  wlan0


Your  raspberry Pi IP address is in the right side of
the word
inet addr:


To combine webiopi and  mjpg-streamer into same webpage which allows we
"see" video from camera and control Robot Car with brower, we need change some
default setting of WebIOPi and MJPG-streamer. To do so, we need use nano to edit
config file as following:

sudo  nano  /etc/webiopi/config

Modification A: replace webiopi default script
python file which allow us to send control signal to Pi from Browser, please add
following pink line into /etc/webiopi/config
file

[SCRIPTS]
# Load custom scripts syntax :
# name = sourcefile
#each sourcefile may have setup, loop and destroy functions and macros
#myscript = /home/pi/WebIOPi-0.7.1/examples/scripts/macros/script.py
myscript = /home/pi/osoyoo-robot/cam-robot/robot/script.py

Modification B. change webiopi default html file
path by adding following pink line:

# Use doc-root to change default HTML and resource files location
#doc-root = /home/pi/WebIOPi-0.7.1/examples/servo-control
doc-root = /home/pi/osoyoo-robot/cam-robot/robot

Modification C. Add PCA9685 address into config by
addling following pink line

[DEVICES]]
# Device configuration syntax:
# name = device [args...]
# name   : used in the URL mapping
#device : device name
#args   : (optional) see device driver doc
#If enabled, devices configured here are mapped on REST API /device/name
#Devices are also accessible in custom scripts using deviceInstance(name)
#See device driver doc for methods and URI scheme available

# Raspberry native UART on GPIO, uncomment to enable
# Don't forget to remove console on ttyAMA0 in /boot/cmdline.txt
# And also disable getty on ttyAMA0 in /etc/inittab
#serial0 = Serial device:ttyAMA0 baudrate:9600

# USB serial adapters
#usb0 = Serial device:ttyUSB0 baudrate:9600
#usb1 = Serial device:ttyACM0 baudrate:9600

#temp0 = TMP102
#temp1 = TMP102 slave:0x49
#temp2 = DS18B20
#temp3 = DS18B20 slave:28-0000049bc218

#bmp = BMP085

#gpio0 = PCF8574
#gpio1 = PCF8574 slave:0x21

#light0 = TSL2561T
#light1 = TSL2561T slave:0b0101001

#gpio0 = MCP23017
#gpio1 = MCP23017 slave:0x21
#gpio2 = MCP23017 slave:0x22
pwm0 = PCA9685 slave:0x40
#pwm1 = PCA9685 slave:0x41

#adc0 = MCP3008
#adc1 = MCP3008 chip:1 vref:5
#dac1 = MCP4922 chip:1

Finally use ctrl X to save and exit

Testing:

Now you can put your car on the ground and turn on the power-switch in battery
box. We need to use SSH to control the car. So you must enable SSH with
raspi-config command before testing.  If you are using windows, please use
download Putty to ssh your Pi, if you are using MacBook, please directly use ssh
command in terminal.

To start mjpg-streamer, in ssh terminal, please type followinig command:

cd ~/osoyoo-robot/cam-robot/mjpg-streamer

sudo ./start.sh

To start webiopi, please open another ssh window and type following command:

sudo webiopi -d -c /etc/webiopi/config

Now you can use your browse to acess Raspberry IP with port 8000(i.e, if your Pi
IP address is 192.168.0.16, please visit
http://192.168.0.16:8000
), you will see following picture in your browser
(请补充图片), click arrow buttons, you can make car moving to your desired
directions.

You can also use our free Android App instead of browser to control the car.
Download the app from
http://osoyoo.com/driver/picar.apk
, run the App, click set up and enter
config page set the fields as following:

Robot IP :your_raspberrr_pi_ip  Port:
8000
Video URL:
http://your_raspberry_pi_ip:8899/?action=stream

UserName: webiopi
Password: raspberry

Click Save button and exit config page

Now you can use the arrow buttons in App to control  the car