A cool remotely controlled bot like the ones in movies, which can be controlled from anywhere in the world with a browser, with on board camera and full range motions.
Imagine this, while you are on vacation in Hawaii, someone breaks in your house. You wield your wiPiBot to confront the burglar from a distance.
Of course anyone, even hackers from Russia can remotely access your wiPiBot.
Of course, we do not offer security service. No verification needed to sign on to the robot.
Of course, anyone who has your IP address can fully seize your wiPiBot and manuver it around your house.
This is the power of wiPiBot that belongs to the era of the Internet of Things.
The objective of this project is to create a mobile robot platform powered by two servo motors. There is an onboard camera on the wiPiBot to give its pilot a view of the wiPiBot's sorroundings. The project utilizes a Raspberry Pi B2 model to command all the actions of the robot. Additionally, the Raspberry Pi hosts a server using the Django framework written in Python. The wiPiBot broadcasts the video and various data of its sorroundings to user, and the user controls the wiPiBot's motion through the dashboard that is hosted on the wiPiBot's server.
The major components of the wiPiBot consists of three major entities: the server on the Raspberry Pi, the webpage and dashboard hosted on the server, and the user who remotely access wiPiBot. In essence the whole project is about enabling communication among those three parties. The server hosted on the Pi connects the wiPiBot to the world. The html dashboard template stored on the Pi is then rendered as a webpage, acting as an interface for controlling the Pi. The user then accesses the server's IP address and controls wiPiBot through various buttons on the dashboard. When the buttons are clicked, they send Http GET request to the server, which in response sends control signals to wiPiBot to move, flashing the LED, or to launch the camera.
The server that wiPiBot projects is based on the Django framework, written in Python. The Django server utilizes Model View Template (MVT) model for constructing the database. Each of the three crucial component of the backend system, Model, View, and Template, is its own entity, and Django provides an easy interface to connect those three entities.
Model refers to the database object that the server implements. Any scalable websites need a place to store its user generated data, a database is the storage where such data resides. The database is a separate entity from the website's front and backend, and maintains a state of its own. Since database operations consist of a programming language of its own. It is not ideal for the backend programmer to program both in Python and the database query language. Django's Model simplify this process by creating a simpler interface to interact with the database. In other words, with Django, you can create database object, read and write to database all in Python! This Model interface is also universal across all database platforms. Should you switch from Sqlite to MySQL, you will not have to change your database query related code to fit the new database.
Other than database objects, Model can be a place that contains. All permanent objects needed by the backend. For wiFiBot, the camera object that it uses to broadcast video stream to network is stored in the Model object of the particular app.
View contains the bulk of the Python code that a Django project contains. View receives, generates, and handles Http response and requests. View fetchs html files from Templates and display it to the world. Often, View also interfaces with Model to fetch data and combine it with Templates to render the html page.
Template in short is simply the html and css file that will be used to create beautiful webpages. Those html, css, js, and static files such as images are stored in their own designated folders. In Django's setup, we specify the location of those folders, so that View will know where to load them. There are also Django specific tags called tempalte tags, which are used for the front-end html files. These tags enable Django to dynamically pass values and data to the html template to display.
The dashboard is the primary interface of the human and the robot. There are total 10 control buttons the dashboard supports which translates to 10 unique commands that can be issued to the robot:
- Move forward
- Move backward
- Turn left
- Turn right
- Increase speed
- Decrease speed
- Flash LED
- Record video
- Stop video
The layout of the dashboard is below:
Below is the structure of the layout of Django project:
The folder landing and wiPiBotServer are each an app within the project. The wiPiBotServer app is the default app that connects all apps in the Django project. The landing app controls the landing and dashboard page of wiPiBot's website and sends controls to the camera and motors. The stand alone file wiPiBotClient.py includes LED, motor, and direction control. The file camera_network.py contains code for camera control.
The movement of our wiPiBot is controlled by two servo motors and we used the PWM functionality on the Raspberry Pi to control the rotation direction and the speed of the two servo motors to let the wiPiBot go forward, backward, turn left, turn right and stop.
Based on the data sheet of the motors, the control of the servo is based on the duty cycle, and the total cycle is approximated to be 20ms (PWM=50Hz). According to the data sheet m with the total cycle approximated to 20ms, we need the pulse width to be 1.5ms to be at a stationary center which is 7.5% duty cycle. According to that, for the forward direction on the motor we need the duty cycle to be from 7.5% to 6.5%. With 6.5% being the fastest speed. For the motor to rotate reversely, we need to have a duty cycle from 7.5 % to 8.5% with 8.5% as the fastest. So by controlling the duty cycle of two motors, we can achieve different movements of our wiPiBot with different speeds and because the motors connected to the wheels in different directions, one wheel will rotate forward when the duty cycle of the motor is within 7.5%~6.5% and the other wheel will rotate forward when the duty cycle of the motor is within 8.5%~7.5%.In this project, the I/O pins of the two motors are connected to PWM GPIO pins 12 and 13 on the pi. And the power supply for the two motors are 4 AA batteries with 6V.
The motors functions are as follows:
One of the essential wiPiBot project's feature is that it is able to view the surroundings of wiPiBot and the video can be monitored remotely. To be able to achieve that, we will need a camera on the wiPiBot that records video stream and sends that to the network. We chose to use the Raspberry Pi camera module for this project because the Raspberry Pi camera module integrates with Raspberry Pi easily and smoothly. While we can interact with the camera with shell command, our goal is to write script that controls the camera based on user input and when to output the video stream to the network. There is an interface called "python-picamera" which is a pure Python interface to the Raspberry Pi camera module. We can simply write python script to control the camera.
We utilize Network socket for the communication between the server and the client: in this case our wiPiBot is used as the server and remote station is the client. In this scenario, the wiPiBot acts as a server waiting for a connection from the client. When it accepts a connection, the wiPiBot calls the video recording function in the python control script which will activate the camera to start streaming video over the connection. When user is done, he can send stop signal from the client which will stops the video streaming which will in turn close the connection as well as the socket.
The fundamental feature of wiPiBot is its connection to the wireless network. Since the station that controls the wiPiBot and monitor the camera are both come from remote website, the wiPiBot must equip with wireless connection to the internet to be able to receive the signals. Thanks to the development effort from Raspberry Pi community, we can easily enable our wiPiBot to connect to the internet by inserting a Edimax Wifi module into the USB port of wiPiBot. The setup and configuration of wifi module is simple on the Raspberry Pi. After the setup and configuration, simply re-enabling the Wifi service will establish wifi connection for the wiPiBot.
The setup and testing of the Django server was straight forward. Initially, there was a lot readings of documentations. But after thoroughly learned the structure of Django. It was trivial to run the server. Creating Model, View, and Templates to display the webpage.
For the motor control testing part, when we first tested it, we can control it by only one direction command (forward, backward, turn left or turn right), and after we press the stop button, it will not work again. The reason for this is that in our stop command, we use the GPIO.cleanup() command and it will clean up all the ports that we have used, so it won’t work next time. Our first solution is to delete this command and only use .stop() command to stop the wiPiBot. However, this won’t work either. The second solution which we used for this project is instead of deleting the GPIO.cleanup() command in the stop command, we added set up the GPIO pins in every other direction command. In this way, although after we implement the stop command, it will clean up the GPIO ports, but it will set up the ports again independently at the head of every command. Also, we set up the default speed of each servo for different commands as follows:
Speed control: 5 different speeds.
Speed up: Motor one decrease the duty cycle by 0.1% every time.
Motor two increase the duty cycle by 0.1% every time.
Speed down: Motor one increase the duty cycle by 0.1% every time.
Motor two decrease the duty cycle by 0.1% every time.
The frontend of the result turned out to be the same as the design in the design section. The Http GET request was sent when the buttons on the dashboard page were pressed and the program is able to correctly parse the content and control the motor. In addition, we are able to control wiPiBot's camera through the dashboard, and below is the team photo that we took through wiPiBot.
Install Django on Raspberry Pi from https://github.com/rmasters/DjangoPi
1. Download the whole project.
2. $ cd ... /wiPiBotServer
3. $ sudo python manage.py runserver 0.0.0.0:8000
4. Use your browser to navigate to your wiPiBot's IP and here comes the fun!
Once having the server running:
1. Download VLC Media Player
2. User your browser to navigate to your wiPiBots IP and go to dashboard.
3. Click on the record video button.
4. Open VLC player, Click Playlist >> Open Media >> Network. In URL field enter tcp/h264://my_pi_address:8001/. Click open to launch the video.
Based on this documentation
Special thanks to Professor Skovira and ECE 5990 course staff for their help in completing the project.
Alex Tan, Liwei Han, Victor Fei
Selfie taken on wiPiBot.