Exclusive Smart Video Car

by Elecrow in Circuits > Raspberry Pi

503 Views, 4 Favorites, 0 Comments

Exclusive Smart Video Car

1-小车和crowpi2摆在一起的图片.jpg
2-1-CrowPi2通过wifi控制小车简示图.jpg

Create your mecanum exclusive smart video car with Raspberry pi and CrowPi2!

When I watched the Batman movie, I was deeply attracted by the cool batmobile, which inspired a long-held idea in my heart, that is to have a cool car like Batman. As a DIY maker, I start my journey to make a “batmobile”. The following are the main features of the car:

● Car can be remotely controlled through wifi

● Car can transfer the real-time video stream to display on CrowPi2’s screen

● Key needed to start the car, that is, the car is my exclusive car

● Car movement controlled by joystick on CrowPi2

● Car PTZ(Pan–tilt–zoom) controlled by button matrix

After reading this instructable, you will actually get an idea of how to make your own super cool car with Raspberry Pi. The steps will show you working principle of wifi remote control card and implementation method.

A video is worth a thousand words. The following video will show the smart wifi car you going to build:

What the CrowPi2 video car like?

The working principle of the wifi car is easy, the following figure explains it exactly (just like the second picture show):

Step 1: Prepare

To start the project, you should prepare these materials:

● CrowPi2 x1(https://www.elecrow.com/crowpi2-raspberry-pi-portable-laptop.html)

● USB Camera x1(https://www.elecrow.com/usb-camera-p-1538.html)

● Mecanum wheel x4(https://www.elecrow.com/mecanum-omnidirectional-wheel-kit-4pcs.html)

● Ready-to-use Raspberry Pi car x1

Step 2: Connection

4-小车图片.jpg

With a Ready-to-use Raspberry Pi car, it’s easy to connect all these materials we prepared. Take a look at the final car(as shown above)

You may have a different Raspberry Pi car from me, but they all have similar principles, and you can assemble a car of your imagination with just a little research. If you are not familiar with the car or the assembly, I suggest you buy a Ready-to-use Raspberry Pi car. The car comes with a driver board, Raspberry Pi, motor, power supply system, etc., which will greatly speed up The progress of the project. Okay, let's continue our greater works, programming to make the car have a “brain”!

Step 3: Open the Car’s Camera

(1) Install the system for the Raspberry Pi on the car.

You can download the latest image of Raspberry Pi here.

Install the image just download to SD card and insert it into SD card slot of Raspberry Pi. Boot up the Raspberry pi. You will need a screen and an HDMI cable to program for the car. For the keyboard and mouse, you can use the CrowPi2’s one.

(2) Use a shell to startup the camera when the Raspberry Pi is booted. I included a shell named start.sh to startup the camera, you just need to copy this shell to your image and run the following command in the same folder with the shell:

sudo ./start.sh 

Also, you can add the script to the system auto-start item, so that the camera can be automatically started as soon as the system boot up.

​Step 4: Transfer the Car’s Video Stream

first.png
second.png

I plan to transfer the car’s video to a web page and use the CrowPi2 to visit this web page to see the video transferred from the car. Therefore, I need to create an index.html file.

Wait...! To make sure the car can access the web page, you need to turn on the wifi of the Raspberry Pi and connect it to a router(whether can access to the internet or not) so that the car and CrowPi2 in the same WLAN network.

Okay, continue the work. Back to the index.html file, after connecting to a router and get an IP address, you need to modify the IP address in the index.html to car’s one(as the first picture shown):

Keep going. In order to load the index.html file, you will need a python script to achieve it. I create a python script named RPi_Server_Web.py to do so, the main part of the code is shown below (as the second picture shown):

Well done, next is the turn to check the video stream on the CrowPi2 side.

Step 5: Visit the Video Stream

In this step, you need to boot up the CrowPi2(with CrowPi2 system) and connect the same wifi as the car.

Then, open a browser and enter “car’s IP address:9093”

For example, if your car IP is 192.168.1.200, then you should enter 192.168.1.200:9093 in the search bar.

Finally, you should see the real-time video on the web page that transfers from the car.

please check the video 5

Step 6: Programming CrowPi2 to Send Commands

3.png

To transfer commands to the car, you need to “tell” the program the IP address of the car to communicate with. As shown in the following code, you need to change "SERVER_IP" to the IP address of your car(please check the first picture):

Then, programming for hardware that send commands to control the car. Three modules will be used on CrowPi2 to control the car. Listed as follows:

(1) RFID module

This module is used to detect whether there is an NFC, just like the key of the car. That is, the car can only be controlled when you have an NFC card.

When RFID module reads an NFC, it will send a command to the car side to unlock it, which will make the car automatically rotate clockwise and counterclockwise, and then calibrate the camera position.

After unlocking the car, I will make the CrowPi2’s screen display a gif animation to represent that unlock the car successfully. Please check the video 6

(2) Joystick module
Joystick module is used to control the movement of the car. There is mainly 5 direction when moving the joystick, which means there will be 5 different commands:

Joystick action Command sent
Joystick UP u
Joystick DOWN b
Joystick LEFT l
Joystick RIGHT r
Joystick STILL s

(3) Button matrix module

Button matrix module is used to control the movement of the PZT. The PZT includes 2 servos, one controls the horizontal movement of the camera, and the other controls the vertical movement. Also, each servo can turn counterclockwise or turn clockwise:

Button action Servo controlled Command sent
Key 8 pressed Vertical 3
Key 2 pressed Vertical 4
Key 4 pressed Horizontal 1
Key 6 pressed Horizontal 2

Step 7: Programming Car to Receive Commands

4.png
5.png

Similar to the CrowPi2 which act as the control side, in order to establish communication between the car and CrowPi2, you need to tell the program the IP address of the controlled side first, that is, the IP address of the car itself: please check the picture

After the communication is established, the next step is to programming for different received commands. Mainly for three parts:

(1) RFID module

When RFID module detects an NFC card, CrowPi2 will send a character “R” to unlock the car. To show the car has been unlocked, programming to achieve the following motion for the car:

● Rotate counterclockwise for 1.5 seconds

● Rotate clockwise for 1.5 seconds

● Camera PTZ automatic calibration

please check the video 7

After that, stop the car and wait for the further control commands from joystick module and button matrix module.

(2) Joystick module
There are 5 different commands that can be received from the joystick module, which can control the car movement:

Command received Car movement
u Forward
b Backward
l Turn left
r Turn right
s Stop

To achieve the car movement, you can define 5 functions for different movements. By setting up the motor, it’s easy to make the car move. As I am using the mecanum wheels, it’s necessary to learn mecanum wheel car movement principle, just like the third pictur shown below:

(3) Button matrix module
There are 4 commands that can be received from the button matrix module, which can control the movement of the car’s PZT:

Command received Servo Camera movement
1 Horizontal Turn Left
2 Horizontal Turn right
3 Vertical Up
4 Vertical Down

Now, you know how to control the camera movement based on the commands received from button matrix module, next it’s to create a function that controlling the rotation of servos through the PWM control.

Perfect! Running the python scripts for the CrowPi2 and car, having fun with your exclusive smart video car.

Step 8: Going Further

Now you have made your smart video car that controls by the modules on CrowPi2. There are many other functions and gameplays that can be added and implemented, for example, adding a speaker to the car and control it through the touch sensor on the CrowPi2. Have fun with this smart video car based on CrowPi2 and hope you can do more incredible projects with CrowPi2!