controlling robots using javascript

20
Controlling robots using JavaScript Sudar Muthu (@sudarmuthu) Research Engineer, Yahoo! Labs http://hardwarefun.com http ://github.com/sudar

Upload: sudar-muthu

Post on 28-Jan-2015

117 views

Category:

Technology


1 download

DESCRIPTION

Controlling Robots using JavaScript. Slides from my talk at jsfoo. Details at http://sudarmuthu.com/blog/controlling-robots-using-javascript

TRANSCRIPT

Page 1: Controlling robots using javascript

Controlling robots using JavaScript

Sudar Muthu (@sudarmuthu)Research Engineer, Yahoo! Labshttp://hardwarefun.comhttp://github.com/sudar

Page 2: Controlling robots using javascript

Who am I?

Research Engineer by profession Creates robots as hobby Prefers Arduino Prefers JavaScript at work Why not combine both of them? .. and that’s what I am going to talk about today

Page 3: Controlling robots using javascript

Why hardware for a software hacker?

Fun!

Page 4: Controlling robots using javascript

Demohttp://hardwarefun.com/projects/asimijs

Let’s start with a demo

Page 5: Controlling robots using javascript

Participate in the demo

Visithttp://hardwarefun.com:3000

Page 6: Controlling robots using javascript

http://hardwarefun.com/projects/asimijs

Control the bot at stage

#asimijs @hardwarefun

Page 7: Controlling robots using javascript

Arduino Visual Basic for hardware Includes both Hardware and software

Photo credit Arduino team

Page 8: Controlling robots using javascript

Interfacing Arduino with JavaScript

Using serial connection (node-serialport) Using abstraction (like johnny-five or duino) Using serial Bluetooth connection (asimijs)

Page 9: Controlling robots using javascript

Using Serial Connection

You need node-serialport - https://github.com/voodootikigod/node-serialport

var SerialPort = require("serialport").SerialPort, arduino = new SerialPort("/dev/tty/ACM1");

// when data is received from arduinoarduino.on("data", function (data) { arduino.write(new Buffer[data]); console.log("Got: " + data);});

// if there was any errorarduino.on("error", function (data) { console.log("Error: " + data);});

Page 10: Controlling robots using javascript

Using Abstraction

Build on top of node-serialport - https://github.com/voodootikigod/node-serialport

Options include Johnny-five - https://github.com/rwldrn/johnny-five and duino - https://github.com/ecto/duino

Load the firmdata program into Arduino It provides the necessary abstraction Write code using a node.js library Profit

Page 11: Controlling robots using javascript

Demo

Let there be LIGHT

Page 12: Controlling robots using javascript

Codevar five = require("johnny-five"), board = new five.Board();

board.on("ready", function() {

// Create an Led on pin 13 (new five.Led(13)).strobe(1000);

});

Page 13: Controlling robots using javascript

Hardware setup

Page 14: Controlling robots using javascript

Reading sensor data

What you need?

Any sensor and a LED

Page 15: Controlling robots using javascript

Reading sensor datavar five = require("johnny-five"), board, led, photoresistor;

board = new five.Board();board.on("ready", function() {

// Create a new `photoresistor` hardware instance. photoresistor = new five.Sensor({pin: "A2”, freq: 250}); led = new five.Led(13);

// "read" get the current reading from the photoresistor photoresistor.on("read", function( err, value ) { if (value > 50) { led.on(); } else { led.off(); } console.log( value, this.normalized ); }); // Inject the `sensor` hardware into the Repl instance's context; // allows direct command line access board.repl.inject({ pot: photoresistor });});

Page 16: Controlling robots using javascript

Using serial Bluetooth connection

Bluetooth shield gives wireless capability to Arduino A Bluetooth connection appears as serial port in your

computer Using node-serialport you can talk wirelessly to Arduino And that’s what I did for demo ;)

Page 17: Controlling robots using javascript

Using serial Bluetooth connection

var SerialPort = require("serialport").SerialPort, bt = new SerialPort("/dev/cu.FireFly-CCFA-SPP");

// when data is received from bluetoothbt.on("data", function (data) { bt.write(new Buffer[data]); console.log("Got: " + data);});

// error reading bluetooth serial portbt.on("error", function (data) { console.log("Error: " + data);});

Page 18: Controlling robots using javascript

How the demo worked

Node.js Server

Admin page

User pageUser page

User page

Node Client

Page 19: Controlling robots using javascript

Links

AsimiJS – The demo that I showed initially http://hardwarefun.com/projects/asimijs

Asimi – A simple bot using Arduino http://hardwarefun.com/project/asimi

Getting started with hardware programming http://hardwarefun.com/tutorials/getting-started-with-hardware-programming

Getting started with Arduino http://hardwarefun.com/tutorials/getting-started-with-arduino-and-avr

Node-serialport https://github.com/voodootikigod/node-serialport

Johnny Five https://github.com/rwldrn/johnny-five

Page 20: Controlling robots using javascript

Questions

Thank You

Sudar Muthu (@sudarmuthu)http://hardwarefun.comhttp://gitbub.com/sudar