Machines might be rising by humans are not going to give up. And this time, humans are using machines to beat machines. To protect themselves and future generations from skynet, they designed 'Protect U'. ProtectUs will help human in the battle field against Skynet and secure human camps against any attacks from those skynet drones. Equipped with nest gen EMP system, ProtectU can paralyze enemy bots and crushed into sand. What more, ProtectU is hardwired with the will to go on and protect human race.
ProtectU is a robot with Ci20 as it's brain and a TI MSP430G2553 powering its muscles. I wanted to design a robot that can be built by anyone around the world. So I decide to use commonly available materials to built the chasis of robot. These days I see many projects boasting about 3D printed parts and multi layer PCBs, but from my maker perspective not many have access to 3D printer or and multilayer PCB etching facility. Hence I decide to keep this simple. Apart from the electronics parts, the bot chasis, place holders and fixtures are build out of hard carboard and thermocol sheets, which I believe are very cheap and commonly available across the world. Any maker can buy it with out adding much to the project expense.
Building the ChasisLets start by building the body of ProtectU. Chasis for this bot is built using hard cardboard sheets. 4 square card board sheets are cut out with dimensions 21cm x 21cm and stackek together to build the base plate. Two DC motors and castor wheel is then attached to the bottom of the plate using high quality glue. Height of the castor wheel is adjusted using thermocol piece of appropriate height. On the top the plate, positions of the holes in Ci20 board is marked and small trinagluar peices of cardboards with appropriate cuts are sticked togther. With the white plastic screw legs provided with Ci20 box, the board can be hold tight here by inserting into it.
After the chasis is built, its time to test the motor functionalities. A motor driver IC L293D is used to control the motor directions. Using bread board, motors are attached to the IC and entire setuo was powered by a 12V DC adaptor. A 5V regulated power line is drwan from 12V to power the IC. Motor Supply in the IC (Pin#9) is supplied with 12V. The control pins for each motor are manually switched to check the functionality. Both the directions of motors are tested along with the enable/disable pin functionality.
eNext step was to add the electronics for automatic motor controller. I used TI's MSP430G2 launchpad for controlling the motors. I could have done this directly from Ci20 and L293D motor driver. But as of now Ci20 software lacks a Python interface for PWM functionality which is cruicial for controlling the speed of each motors. So I wanted a MCU in the middle to take commands from Ci20 and set the motor speed. I considered arduino first, being the most popular MCU. But soon I realised the ATmega328 works at 5V which is not compactable with Ci20 3V3 IO pins. Although we can run arduino down at 3.3V, I chose MSP430G2553 for the task because of its simplicity. MSP430G2 requires nothing but a 3.3V line to run as compared to the added complexity of crystal circuit of an arduino. Now my major doubt was whether a 3.3V logic can be given as input for L293D. After my tests, I found that it's possible though it's not recommended. But I decided to go ahead with it, as making is always about exploring new things.
Then came the time to add the barin. Ci20 is inserted into the place holders provided by the small cutouts.
Now I wanted to create a serial bridge between Ci20 and MSP430G2. Ci20 has 4 UART ports. I decide to use UART0 located at the 26 pin header. But it's in this port, the serail TTY login session is also running. So first I need to stop it at this port. Still this functionality is available at UART4 - which is provided as a dedicated connector near the HDMI port.
To disable stty session at UART0, go to \etc\inittab. Find the lines
T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100
T4:23:respawn:/sbin/getty -L ttyS4 115200 vt100
and edit as below
# T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100
T4:23:respawn:/sbin/getty -L ttyS4 115200 vt100
This will disable the login terminal at UART0 freeing it for communication with MCU. But still during the boot stage, it was sending some text out. So I need to handle this as MCu and ignore all those bootup garbases. So I decide to send a sequence of bytes initially to the MSP430G2 to activate it. Only once it recieves this, it will start responding to the commands from Ci20. Fo now I fixed this is 8 0xF1 bytes to be send consecutively to activate the MCU.
Next challenge I faced was with power supply. Being untethered from the wall adaptor, ProtectU needs a portable power source. I decide to use a 4 cell Li-Ion battery of 8.4V. My initial idea was to derive 5V from battery using a 7805 linear regulator and power the Ci20. Then the 3V3 from Ci20 can be used to power the MSP430G2. But when I tried this, 7805 was getting heated up fast and Ci20 was getting reset. Next version I tried was to use an additional 3.3V regulator ro seperately power MCU, but then MCu was getting resetted every now and then. SO I finally decided to use two power supplies. A 5V power bank powering the Ci20 board. From the 5V line of Ci20, a 3.3V is derived using AMS1117 3V3 lin regulator to power MSP430G2. Additionally the Li Ion 8.4V battery is used as supply for DC motors. So far, this setup is working flawlessly.
With all components in place, now it's time to finalize the hardware design. A block diagram of the design is given below:
Schematic for the motor control is designed in Eagle and the design is attached below. No PCB design is generated as I was planning to wire it in dot pcb.
After soldering the aircuit above, connections are made as follows:
- Ci20 -> Motor Control
- 5V -> VCC
- GND -> GND
- RXD -> TXD
- TXD -> RXD
Then the then the Li-Ion battery is connected to the battery connector and Ci20 is powered up by the USB power bank(blue cylinder in the image).
Next step id to give eyes to ProtectU. A USB webcam is connected to USB port of Ci20 and is accessible via /dev/video0 from the device. Next I installed mjpg-streamer in Ci20 to enable realtiem streaming ver nerwork. I cloned the repository at and decided to build from source. But it was not a sweet peice of cake. After following this tutorial and a little bit of hacking, I was finally able to get the thing working in Ci20.
Once you install it, you will be able to start the streaming by:
/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /usr/local/www"
One you start this, you will be able to go your browser and type the IP address of your Ci20 with port 8080 and will be able to get the stream.
Software DesignNow it's time to write software to controll ProtectU remotely. I wanted to create a webapp through which I will be able to control the movements of ProtectU and also to get a live feed from it.
I decide to write this is Python using Flask framework. Flask is an easy to use Python frameowrk for writing WebApps. Along with the serial library of Python, I will be able to use Flask to create a web app for controlling ProtectU.
You can download the code from :
Copy the code to some folder in your Ci20. Then through commandline open that folder and execute:
$sudo python webUI.py
This will start both the MJPG streamer and the flask web app.
Now in your PC, open browser(firefox recommended) and navigate to http://:5000/ . You will be able to see a window like this with live feed from Ci20.
You can then use the control button provided to move Protect U around. A short video is given below.
Playing with OpenCV
After a little bit of hacking and almost 9 hrs of build time, I was able get openCV working in Ci20. You can follow instructions here. But it was not giving a good performance. Face detection demo was taking around 3sec for one frame. So I decide to drop opencv processing onboard, but would rather stream the video to a power full PC and do it there. I will soon be posting my experiment results here itself.
Q & AWhy are you not directly controlling motor driver with Ci20?
I want to control the speed of motor. This is possible only with a PWM control. As of noe Ci20 dont have a PWM control method in python. So I decide to off load this task to an MCU.
Why are you not using an arduino?
For being 3.3V compactable and simplicity. MSP430G2 requires only 3V3 power line and GND to work, when compared to arduino which need added complexity of crystal.
Why are you using two different power supplies?
I think I messed design here. When I use only one power suply either Ci20 or MSP430G2 is getting resetted. So I decided to go with two power sources.
Why are not having any pan/tilt mechanism for camera?
To control a servo motor, a PWM wave is needed. So for for a pan-tilt mechanism we need two PWM waves. Each such setup takes 1 timer. Then I need motor control PWM - 2 more timers. Then UARt - another 1 timer. So if I want to implement the system without an RTOS, I require 5 timers. But MSP430G2 has only three. So I decided to drop the pan-tilt mechanism. May be with an RTOS, I'll be able to acheive that.
Comments