Tuesday, July 29, 2014

Beaglebone AutoTurret


The AutoTurret combines Dream Cheeky's USB Missile Launcher and the Beaglebone Black to create an auto-aiming rocket launcher that can be manually controlled from your Android phone. If the AutoTurret does not spot any targets within a certain period of time, it will begin to scan the room for some unfortunate victim. Simply mount the webcam onto your launcher, follow the instructions provided, and become the master of cubical warfare.

Team Members:
Stephen Arifin


- Missile launcher that shoots up to 30 feet
- Auto-aiming missile launcher using OpenCV's face detection
- Automatic scanning when idle and firing when locked on
- Android application that streams the webcam and allows manual control of the turret




You will require:
- A Beaglebone Black connected to the Internet (through Ethernet)
- Dream Cheeky's USB Missile Launcher
- A Webcam
- A USB Hub

1) Mount the webcam on the missile launcher
2) Download my code from GitHub (further down the page)
3) I put Debian on my Beaglebone rather than Angstrom, I highly suggest you do this as well
4) Transfer the server code to the Beaglebone
5) Run setup.sh to install the required dependencies
6) Install OpenCV in the same directory as the server files. I used this link:
7) Setup MJPEG Streamer by following the readme. Make sure you check if your webcam outputs MJPEG or YUV format. Adjust the launch_webcam.sh accordingly
8) Open the src files of the Android application. Adjust the IP address to the address of your Beaglebone Black. Make sure you also adjust the port values to whatever you use in the MJPG-Streamer and the Server
9) Build the Android application and transfer it to your Android phone. You should be able to just import the project into Eclipse, but you will probably to setup JavaCV and implement it into the project.
10) Control your turret from your phone! Settings to switch modes are at the top right corner.

Instructions To Run:
1) In the Beaglebone's terminal, type the following command:
sudo ./Server.py

2) Start the Android Application from you phone. Don't forget to adjust the IP Address and port numbers!


The AutoTurret incorporates several modules within the Beaglebone:

Block diagram for the Beaglebone AutoTurret

Console output during face detection
The mjpeg-streamer module receives the webcam's raw input, converts each frame into a jpeg file, and streams the video frames to an HTTP port. The Android phone is able to receive the video stream by establishing a TCP connection to the Beaglebone.

The mjpeg-streamer also dumps image files in a specific folder. These images are the source file for the face tracking algorithm to process. With options I have selected, the streamer uses a three image buffer and captures a new image every 150ms.

Image Processing
When a new image file is created, the script image_ready.py is run, sending a signal to the ImageListener thread, letting the thread know that the image is ready for processing. In order to increase the efficiency of the face detection algorithm, the image is gray-scaled and then equalized.

Using OpenCV's face detection algorithm, the image is analyzed and patterns similar to the given Haar Cascade are boxed. The Haar Cascade I decided to use was the haarcascade_frontalface_default.xml because it was the most reliable. After detecting the faces in the image, the program targets the largest rectangle and moves the launcher to aim directly in the center of the rectangle.

Image pre-processing of face detection

The Launcher
Controlling the launcher is pretty simple, thanks to Nathan Milford and his open-source code to manually control the launcher. By setting bits within the USB drive, specific commands can be sent to the launcher. An important thing to note that the "fire" command is a time consuming process and any command sent as it is firing will crash the program. I added a Thread.sleep() command to counter-act this.

User interface of the
 Android application
The Scanner thread is in charge of "scanning the room" when no faces have been detected in a certain amount of time. The Scanner achieves this by incrementing a counter for every image that does not have a face. Once the counter reaches a certain point, the AutoTurret will begin scanning the room.

The Android Phone
The last module is the Android application, which provides the user a client-side application to control the AutoTurret. After establishing a TCP connection to the Beaglebone, the Android phone can receive the webcam stream from the server and display it on the screen. Each button sends a command to the server, which then sends the command to the Launcher. Modes such auto-aiming and auto-scanning are also set through the Android application, in the Settings.




Fashion Guru

Come check out my latest project, Fashion Guru. Fashion Guru is an online personal stylist service that allows you to upload pictures of your outfit or clothing and receive feedback from stylists.