Upload
mike-anderson
View
264
Download
0
Embed Size (px)
Citation preview
/* * __ __ ______ _____ ______ ______ ______ ______ * /\ "-.\ \ /\ __ \ /\ __-. /\ ___\ /\ == \ /\ __ \ /\__ _\ * \ \ \-. \ \ \ \/\ \ \ \ \/\ \ \ \ __\ \ \ __< \ \ \/\ \ \/_/\ \/ * \ \_\\"\_\ \ \_____\ \ \____- \ \_____\ \ \_____\ \ \_____\ \ \_\ * \/_/ \/_/ \/_____/ \/____/ \/_____/ \/_____/ \/_____/ \/_/ * `` ``` `. * .-. .` ..-.` `:-/+` .` * `-``:-` ` -` .+``-/:/. /+` - * :. `+/ /. .- `+: `/- `+- - * .`.--./ -o. :// :. `//. // .` *`:+-::-.-. `o/:-`/ ``` :- .//.`:/` `. *././o-o- .-.:+``.. `-` ./ .::/` `.` *`-.:o+-/. `+o. `. ::` ``.` * :o/o/:`..-++. :--.` `.` :: .-.`` ```` * `/o+/--.`:/. /-/``.-.` `+o. `` `..--..` `.````````` *`/:+/:--:.` `/. .-` `.--` `/-` ./. ::``` *.++.-://` `/` -:::.` `-:-``+: `/- `-- *.+/: /: -: -/ `-::.` `:+/ `/- .:. *-:/-`o :- -/ `-:-` ...--` `/-`:-` *`::`-+ `-.. :. :: .-:-` `--.` .+:--` *-:.`.o:/:+::/. `:- ` `-:-` `.-.` `..` *`+/`.o:``+`// `/- :o/` `---. -. * ./://. +``o `:. :+:` `--.`:. * ./. `` +` :.-` `-. -/: `.-: * .-` :. ``` :/-:-.` `sso ./. * -: ` ...` `--/-:-.` .-` :+. .` ``` * -+- .-. `... `.--::.+.` /+` `:..:- `/-:. * `//` `---` `--.` `.://+: `//` .. :- `.-: * :+- .-..` `---. `-:` `+: .-``:/-`. -- * `//` ``...``.--.` .:. ./::::://:/:` *`/- ```````.```-/: `/+/.--....://` * ` `.` ````.-//o `//--//:::..+/ * `/-...` ````-: `.---:-.-//:.` :/` * ./. .....` --.--.-..-`..:/-`-/` * -/` `..` `...` :. .. .`-``-`..:/./` * ::` ```.. ``.`` `:/ ..-``.`:`.. -`--` * .- ``.-` ``-. ``-::``-.- -..- -`-.:. * .-` `:-` `..-+..`:`/`-: :. -.-` * `` -:` .--.-/- ./ /../ .-`-.` * -. `:://:::` /- :.`/`.::. * `-` ./-:/--/` ./` :.`:--` * `. -:`.--./.``:-.--:-`` * `:- ```......`` * .:. */
Node.js + Robots
Nodebots!
Mike Anderson! @mike0x41
VicJS May 2015
Hello
• My name is Mike Anderson
• I work at Echosec Systems
• I used to do embedded development
• Sometimes I miss it
Solution
Build robots and connect them to the internet
The Internet of Things (We put a chip in it!)
DoodleBot
The Mobile Web Client
• Try and get doodlebot to draw something by connecting points on an HTML canvas element
• Yes, this is horribly insecure
• DoodleBot is very bad at drawing
its a cloud!
What is DoodleBot?
What do I need to make my own robot with poor drawing abilities?
You Need
Robot Chassis Johnny-Five
The Robot Chassis• Chassis
• Motors
• Battery / Battery Holder
• Wiring
• Tools / Fasteners
• Motor Driver
• Microcontroller
• I recommend SparkFun or Seeed Studio or HobbyKing
2CH Motor Driver
Multi-Chassis - Tank Version
The Micro Controller
What’s Johnny-Five• Robot control framework built
on node.js released in 2012
• Very solid and active community
• Communicates with Arduino micro controller or similar device via the Firmata protocol
• Has support for
• >30 microcontrollers
• >40 components
How To Johnny-Five
• Load the StandardFirmata firmware onto an arduino compatible micro controller
• Connect stuff to the Arduino pins
• Connect the Arduino to the host machine over USB serial
• Initialize a the board and connected components in node on the host machine
One Example
ControllersArduino Raspberry Pi Beaglebone
Black Intel Edison
WiFi / BT Extra Shield USB Dongle USB Dongle Low power
built in
Power ~1.5 W (5V) ~3.2W (5V) ~2.25W (5V) <1W (7-15V)
PinsArduino
shield layout 5V
Needs breakout
3.3V
Arduino shield layout
5V
Needs breakout
1.8VRuns Node Nope Yup You bet Comes
installed
Cost $25 $50 + $15 $60 + $15 $85
Controllers I went with
Arduino Raspberry Pi Beaglebone Black Intel Edison
WiFi / BT Extra Shield USB Dongle USB Dongle Low power
built in
Power ~1.5 W (5V) ~3.2W (5V) ~2.25W (5V) <1W (7-15V)
PinsArduino
shield layout 5V
Needs breakout
3.3V
Arduino shield layout
5V
Needs breakout
1.8VRuns Node Nope Yup You bet Comes
installed
Cost $25 $50 + $15 $60 + $15 $85
Johnny-Five
Why Javascript for robots?
!
Isn’t it like the worst possible language for embedded development?
No, It’s AwesomeHere’s Why
var five = require("johnny-five"); var board = new five.Board(); !board.on("ready", function() { var led = new five.Led(13); var markerServo = new five.Servo(12); var motorLeft = new five.Motor([9,7]); var motorRight = new five.Motor([10,8]); var encoderLeft = new five.Button(3); //currently broken var encoderRight = new five.Button(2); ! this.repl.inject({ markerServo: markerServo, motorLeft: motorLeft, motorRight: motorRight, encoderLeft: encoderLeft, encoderRight: encoderRight }); }
Read–eval–print loop
/** * Go straight forward or back * Turns out this kit can't really do speed * * @param {String} dir - either 'fwd', or 'rev' * @param {Number} time - the amount of time in ms * to head in that direction * @return {Promise} when complete */ var go = function (dir, time) { return new Promise( function (resolve) { motorLeft[dir](255); motorRight[dir](255); currentDirection = dir; setTimeout( function () { motorRight.stop(); motorLeft.stop(); currentDirection = null; resolve(); },time); }); };
Create task blocks for common actions
Wrap them in promises to get around asnyc issues
Use promise chaining to create sequences of activities
Integrate with well known libraries like socket-io// robot/socket.js !var socket = require('socket.io-client')(appServerAddress); !socket.on('connect', function() { control.queueUpCommand(0,'marker',['down']); control.queueUpCommand(1,'marker',['up']); socket.emit('IAMAROBOT'); }); !socket.on('command', function(cmd) { control.queueUpCommand(cmd.id, cmd.command, cmd.args); }); !// server.js !socket.on('IAMAROBOT', function () { doodlebot = socket; ! socket.emit('command',{ id: 'server', command: 'marker', args: ['down'] });
//client.js !function onMouseDown(event) { if (points.length >= 2) { var coordinate = getCoordinate([event.clientX, event.clientY]); points.push(coordinate); var line = points.slice(-2); drawLine(line[0],line[1]); socket.emit('point',coordinate); } } !//server.js !socket.on('point', function(point) { console.log('point: ', point); points.push(point); socket.broadcast.emit('point', point); if (doodlebot) { generatePathCommands(socket.id, points.slice(-3)); } });
The drawing app
function generatePathCommands(id, points) { if (points.length === 3) { var angle = findAngle(points[0],points[1],points[2]); angle = angle / 3.1415 * 360; //degrees! angle = angle - 180; //bearing! if (angle > 2) { doodlebot.emit('command',{ id: id, command: 'turn', args: [angle] }); } var distance = findDistance(points[1],points[2]); if (distance > 0.05) { doodlebot.emit('command',{ id: id, command: 'go', args:['fwd',distance*50] }); } } }
You now have an internet enabled smart robot that
draws poorly!
Pitfalls• The Edison has very odd behaviour and issues
• Stick to the supported platforms list on Johnny five
• The Dagu Mini Driver board is cheap for a reason (Firmata firmware doesn’t fit without modification)
!
!
• Even trying to stay super cheap, robots are expensive projects
Total Cost CAD with Tax, Shipping, Duty, Fees, etc
Intel Edison W/ Mini Breakout Board
Amazon Canada (Prime) $96.31
USB Micro B OTG to Micro A
Amazon Canada (Prime) $7.71
DoodleBot Robot Kit HobbyKing $76.50
9V Battery pack + batteries DigiKey $23.51
Total $204.03
/* * __ __ ______ _____ ______ ______ ______ ______ * /\ "-.\ \ /\ __ \ /\ __-. /\ ___\ /\ == \ /\ __ \ /\__ _\ * \ \ \-. \ \ \ \/\ \ \ \ \/\ \ \ \ __\ \ \ __< \ \ \/\ \ \/_/\ \/ * \ \_\\"\_\ \ \_____\ \ \____- \ \_____\ \ \_____\ \ \_____\ \ \_\ * \/_/ \/_/ \/_____/ \/____/ \/_____/ \/_____/ \/_____/ \/_/ * `` ``` `. * .-. .` ..-.` `:-/+` .` * `-``:-` ` -` .+``-/:/. /+` - * :. `+/ /. .- `+: `/- `+- - * .`.--./ -o. :// :. `//. // .` *`:+-::-.-. `o/:-`/ ``` :- .//.`:/` `. *././o-o- .-.:+``.. `-` ./ .::/` `.` *`-.:o+-/. `+o. `. ::` ``.` * :o/o/:`..-++. :--.` `.` :: .-.`` ```` * `/o+/--.`:/. /-/``.-.` `+o. `` `..--..` `.````````` *`/:+/:--:.` `/. .-` `.--` `/-` ./. ::``` *.++.-://` `/` -:::.` `-:-``+: `/- `-- *.+/: /: -: -/ `-::.` `:+/ `/- .:. *-:/-`o :- -/ `-:-` ...--` `/-`:-` *`::`-+ `-.. :. :: .-:-` `--.` .+:--` *-:.`.o:/:+::/. `:- ` `-:-` `.-.` `..` *`+/`.o:``+`// `/- :o/` `---. -. * ./://. +``o `:. :+:` `--.`:. * ./. `` +` :.-` `-. -/: `.-: * .-` :. ``` :/-:-.` `sso ./. * -: ` ...` `--/-:-.` .-` :+. .` ``` * -+- .-. `... `.--::.+.` /+` `:..:- `/-:. * `//` `---` `--.` `.://+: `//` .. :- `.-: * :+- .-..` `---. `-:` `+: .-``:/-`. -- * `//` ``...``.--.` .:. ./::::://:/:` *`/- ```````.```-/: `/+/.--....://` * ` `.` ````.-//o `//--//:::..+/ * `/-...` ````-: `.---:-.-//:.` :/` * ./. .....` --.--.-..-`..:/-`-/` * -/` `..` `...` :. .. .`-``-`..:/./` * ::` ```.. ``.`` `:/ ..-``.`:`.. -`--` * .- ``.-` ``-. ``-::``-.- -..- -`-.:. * .-` `:-` `..-+..`:`/`-: :. -.-` * `` -:` .--.-/- ./ /../ .-`-.` * -. `:://:::` /- :.`/`.::. * `-` ./-:/--/` ./` :.`:--` * `. -:`.--./.``:-.--:-`` * `:- ```......`` * .:. */
Totally Worth
It
! @mike0x41
Thank you for coming out