Husky I : Quadruped Live Streaming Bot With Raspberry Pi
by HuskyRobo in Circuits > Robots
8715 Views, 169 Favorites, 0 Comments
Husky I : Quadruped Live Streaming Bot With Raspberry Pi
The Quadruped code name Husky I is a four legged crab like robot that used the raspberry pi 2 at it brain and main control center. In addition, Husky I also included a servo controller and motor driver for servo control and motor driving. There still many thing left to be done on the robot such as integration of sound module, autonomous algorithm. So look out for future update.
Materials
_The Frame
2x Aluminum Multi-Purpose Servo Bracket Two Pack(2x12 = $24)
2x Aluminum Long "C" Servo Bracket with Ball Bearings Two Pack (2x13 = $26)
2x Aluminum "L" Connector Bracket Two Pack (2x6 = $12)
buy at http://www.lynxmotion.com/c-87-standard-hitec-bra...
1x Quadruped Body Kit 2 ($20)
buy at http://www.lynxmotion.com/c-87-standard-hitec-bra...
_Printed Parts
4x Lower Leg
4x Inner Tread Cover
4x Outer Tread Cover
4x Main Motor Hub
8x Side Motor Hub _Electronics
_Electronics
1x Raspberry pi 2 ($40)
1x camera module ($8)
1x usb wifi adapter ($5)
1x Mini Maestro 18-Channel USB Servo Controller ($40)
1x raspberry pi motor hat ($22)
4x Pololu-Maestro 75:1 DC Micromotor ($15)
12x HS-645MG Servo Motor (30 each x 12 = $360)
1x BAT-05 6V / 2800 mAH Ni-MH Rechargeable Battery ($27)
1x 6V - 12V NiMH / NiCd Smart Charger ($22)
buy at http://www.lynxmotion.com/c-87-standard-hitec-bra...
Anker Astro E1 5200mAh Candy bar-Sized Ultra Compact Portable Charger ($15)
buy at http://www.amazon.com/gp/product/B00P7N0320?keywor...
Frame = $62
Electronics = $585
Total + tax + shipping = $705
Note: The most costly part of this project is the servos. If you want to cut back you can use the HS-422 servo($10 each) servo partially or fully, but you might need to get a lighter battery if you intended to use a full HS-422 build.
The Leg
This is a new variant of the Lynxmotion Quadruped Robot which features a new lower leg design that includes housing for a motor and an added tank module. The idea behind this new leg design is to allow the robot to transform between walking and driving at any given time. The bottom leg is made in Solidwork and printed using PLA filament. . All the leg files will be posted at the bottom of the page in .step format.
3D Viewer : https://sketchfab.com/models/14e2ce2c8d514292ac0ec...
Begin by Constructing the Multipurpose Servo Bracket, the C servo Bracket , and The L Connector Bracket. The instruction came in the package when you buy them so it is self explanatory on how to assemble this. Once you have these 3 pieces constructed move on to the next step.
First, attach a HS-422 servo to the side with the ball bearings and make sure that the servo head is directly above the ball bearing ( this is very important). Then attach the C servo bracket to the multipurpose servo bracket as shown in the second picture. After the 2 pieces have been attached together, put the HS-645 MG on as shown in the third picture. Finally attach the L servo bracket on the left side of the C servo bracket as show in picture 4. Note: it is very important that you put the right servo in the correct place or else it will affect the performance of the robot.
Next, attached the LowerLeg to the servo bracket as show in the first picture. Now you should have a single completed leg. The big hole in the LowerLeg served as the housing for the motor which will be used to put the robot to driving mode. If you want to have to have the driving mode go to the driving module section for instruction.
The Body
The body were made using Quadrapod Body Kit - Mini QBK-02. There are 2 batteries which are placed on the lower level. The green battery is the 6V NiMH/NiCD which is used to power the servo and the motor. The black battery is the Anker portable charger for the raspberry pi 2. I decided to use a second battery for the raspberry pi because the main battery is already under heavy load from all the servos and motors. Putting more load on it is not a good idea. Furthermore, the Anker portable charger can power the raspberry pi for about 1-2 hour with the camera plugin whereas the main battery can do 30 min max. After the batteries is placed in its appropriate spot, screw in the top cover and put the raspberry pi 2 near the end of the robot and the mini-maestro servo controller at the top as shown in the last picture. Now the main body is finished we will move on to constructing the camera module.
3D Viewer : https://sketchfab.com/models/9c0d9cc3603648c99de3c...
The Camera Module
The camera is 3D printed out using STL files from http://www.thingiverse.com/thing:350229 . Once you have printed out all the necessary components. I constructed the camera module by looking at the picture from the site. It is self explanatory. The Camera module is powered by 2 Hitec HS-5055 servos. These servo are relatively cheap and cost about 2 dollar each.
Putting Everything Together
At this point, the four leg should be completed and ready to be integrated into the body. At the four corner of the Quadruped body there is a big hole. This is where you put the leg. Look at picture one for reference.
Next ,we attached the camera module to the body. The camera will be placed on top of the mini-maestro servo controller. It should be placed high enough so that it is in the way of the wire. That about it for the placement of the camera. Refer to the above pictures to get an idea of where to place the camera module.
Setting Up the Raspberry Pi
Make sure you have Raspian installed on your raspberry pi 2. If not head over to https://www.raspberrypi.org/help/noobs-setup/ for instruction on how to install the operating system.
First, hook up your raspberry pi to a monitor/tv that had an HDMI port. The pi will boot up and ask you for password and username. The default username is "pi" and default password is "raspberry". Once you log in , type raspi-config and set the files-ystem to used all of the sd card space. Then go to advanced option and enabled the camera and ssh. Now we need the raspberry pi to make a connection with the wifi. Follow these step:
- sudo nano /etc/network/interfaces
you will see the text layout as follow
- auto lo
- iface lo inet loopback iface eth0 inet dhcp
- allow-hotplug wlan0
- iface wlan0 inet manual
- wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
- iface default inet dhcp
change it to
- auto lo
- iface lo inet loopback iface eth0 inet dhc
- pallow-hotplug wlan0
- iface wlan0 inet manual
- iface default inet dhcp
- ssid="your network name"
- psk="network passowrd"
Once we get internet connection on the raspberry pi, it is time to get the necessary libraries and framework to build our program.
First we need to get nodejs since it is the main framework for the robot to communicate through wifi. Type in the to install nodejs.
- curl -sLS https://apt.adafruit.com/add | sudo bash
- sudo apt-get install node
If you want to check your node version, you can type node -v and it should return a version around 12.0.0 .The version number might have gone up from the time i write this instruction.
- node -v
- v0.12.0
Now we need to get the necessary node module for the program. Type in the following
- npm install serialport (for UART communication )
- npm install socket.io (for websocket)
- npm install express
- npm install winston
That should be it for the npm install, now we need to get the javascript library for mini-maestro servo controller so go into you node_modules folder and clone back the driver library.
- cd node_modules
- git clone https://github.com/omcaree/node-pololumaestro.git
Next we need to get a streaming software for the raspberry pi so that the robot can have the ability to live stream. First :
- sudo apt-get update
- sudo apt-get install uv4l uv4l-raspicam
- sudo apt-get install uv4l-webrtc
This will install the camera software. Next you can test the to see if it is running properly by typing
- uv4l --driver raspicam --auto-video_nr --width 640 --height 480 --encoding h264 --framerate 20 --vflip yes --hflip yes
Here are some flag that is important when u run the uv4l camera software : --width and -- height set the resolution, --enconding specify the type of encoding , --vflip and --hflip is vertical and horizon flip so that the image isn't up side down. put this address in your browser : http://raspberrypi:8080/stream. You should see a stream with less than .5 s latency.Below is a demo of the camera.
Software
Here, I will just explain the important part of the software and not all of them since that would be tedious and not useful at all . The structure of the software is as follow
Main Folder
app.js (server side )
start.sh (bash script to run node and camera progarm)
Public (web interfaces folder)
index.html
js (javascript folder for the web interface)
client.js (client side)
socket.io.js (websocket libary)
jquery.min,js(jquery libary)
cube.js
interactive.js
Software: App.js
App.js is a local server written in javascript and it used websocket to communicate with other device through wifi.
The following code create an object to use function from within the socket.io library and then tell the app to listen to port 5000.
var app = require('http'); createServer(handler); io = require('socket.io').listen(app); url= require('url'); fs = require('fs'); app.listen(5000);
The next part of the code is simply forwarding the content in public through the wifi so that you can communicate with it via ip address.
// Http handler function function handler (req, res) { // Using URL to parse the requested URL var path = url.parse(req.url).pathname; // Managing the root route if (path == '/') { index = fs.readFile(__dirname+'/public/index.html', function(error,data) { if (error) { res.writeHead(500); return res.end("Error: unable to load index.html"); } res.writeHead(200,{'Content-Type': 'text/html'}); res.end(data); }); // Managing the route for the javascript files } else if( /\.(js)$/.test(path) ) { index = fs.readFile(__dirname+'/public'+path, function(error,data) { if (error) { res.writeHead(500); return res.end("Error: unable to load " + path); } res.writeHead(200,{'Content-Type': 'text/plain'}); res.end(data); }); } else { res.writeHead(404); res.end("Error: 404 - File not found."); } }
In addition we also put the code to control the servo inside app.js. First , you need to create an object for the mini-maestro library like socket.io.
var PololuMaestro = require("pololu-maestro"); var maestro = new PololuMaestro("/dev/ttyACM0");
Then you can use the function inside the mini-maestro library as follow.
// Initiate communication with the servo controller maestro.on("ready", function() { console.log("connection made");} //Set the speed of servo at pin 0 to 60 maestro.setSpeed(0, 60); // Set the angle ( you write in PWM value) at pin 0 maestro.setTarget(0, 1200); //Example function function CameraRight(){ yaw = yaw+100; maestro.setTarget(12, yaw); }
Next we need to include a portion of code to call these function when we get the data from the communication side that they want to run a certain function.
// Check for signal being sent io.sockets.on('connection', function (socket) { //If signal is CR, then run CameraRight(); socket.on('CR', function(data) { console.log("CameraRight"); CameraRight(); }); }
Software : Client.js
client.js handle all the input that the user do in the web intertfaces and send it back to the app.js so it interpret those command and execute the proper function. Here is a simple example of the code that need to in client.js
//Check to see if the keyboard is press $(document).keypress(function(e){ //If the letter K was press, send the string LF back to the server if(e.keyCode == 107){ socket.emit('LF'); } }
Software: Driving Module
This is the software part for the driving module. If you didn't put the wheels and motors on your robot you can skip this part.
In order to interact with the motor driver, we going to need to installed it library on the raspberry pi. First do these step.
- git clone https://github.com/adafruit/Adafruit-Motor-HAT-Py... Adafruit-Motor-HAT-Python-Library
- cd Adafruit-Motor-HAT-Python-Library
- sudo apt-get install python-dev
- sudo python setup.py install
Since this library is in python. We going to need to write 2 python script , one for forward and the other for backward. Then called these scripts in our app.js. In order to do this we going to need python-shell, python-shell allowed us to called on python script in javascript using nodejs.
- npm install python-shell
To install python-shell
The below is an example of a python script that move the motor forward.
#!/usr/bin/python from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor import time import atexit # create a default object, no changes to I2C address or frequency mh = Adafruit_MotorHAT(addr=0x60) # recommended for auto-disabling motors on shutdown! def turnOffMotors(): mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE) atexit.register(turnOffMotors) # Attached the motor to it respective pin myMotor1 = mh.getMotor(1) myMotor2 = mh.getMotor(2) myMotor3 = mh.getMotor(3) myMotor4 = mh.getMotor(4) # set the speed to start, from 0 (off) to 255 (max speed) myMotor.setSpeed(255) myMotor1.setSpeed(150) myMotor2.setSpeed(150) myMotor3.setSpeed(150) # set the motor to go forward for 3 second myMotor.run(Adafruit_MotorHAT.FORWARD) myMotor1.run(Adafruit_MotorHAT.FORWARD) myMotor2.run(Adafruit_MotorHAT.FORWARD) myMotor3.run(Adafruit_MotorHAT.FORWARD) time.sleep(3.0) # Adafruit_MotorHAT.FORWARD: going forward # Adafruit_MotorHAT.FORWARD: going forward # Adafruit_MotorHAT.FORWARD: going forward
This part here is in app,js that will called on the python script called "Motor.py".
var PythonShell = require('python-shell'); // create an object for python shell function MotorForward(){ // function that call on python script PythonShell.run('Motor.py', function (err) { if (err) throw err; console.log('finished'); }); } MotorForward(); // call the function