Slide 1

Slide 1 text

Nodebots! Day! 2015 Munich Maker Lab

Slide 2

Slide 2 text

Robots + JavaScript http://slides.millermedeiros.com/braziljs/ast/#/

Slide 3

Slide 3 text

JavaScript … … is object-oriented … has a large ecosystem … runs on hardware

Slide 4

Slide 4 text

Basic JavaScript var robot = {! color: ‘yellow’,! sound: ‘hello’,! ! blink: function() {! // action! }! }! ! robot.blink(); basic data functions as data

Slide 5

Slide 5 text

event-loop var repl = require('repl');! ! var robot = {! blink: function(color, delay) {! setTimeout(function() {! console.log('** ' + color + ' **');! }, delay)! }! }! ! var local = repl.start('command> ');! local.context.robot = robot;!

Slide 6

Slide 6 text

events everywhere can make it difficult to work with “time critical” systems

Slide 7

Slide 7 text

talking to robots

Slide 8

Slide 8 text

node-serialport

Slide 9

Slide 9 text

HOST Arduino Firmata! Protocol Firmata JS

Slide 10

Slide 10 text

$ npm install --save firmata! ! // The Firmata protocol provides a simple protocol to an embedded system! var firmata = require('firmata');! ! // Change this line to the serial port of a device! var modem = '/dev/cu.usbserial-DJ008CEA';! ! // Main part! var board = new firmata.Board(modem, function(err){! console.log('connected: ' + modem);! var ledOn = true;! ! // Configure pin 13 as output! board.pinMode(13, board.MODES.OUTPUT);! ! ! // Blink the LED! setInterval(function() {! ! if (ledOn) {! console.log('ON');! board.digitalWrite(13, board.HIGH);! } else {! console.log('OFF');! board.digitalWrite(13, board.LOW);! }! ! ledOn = !ledOn;! ! }, 500);! });!

Slide 11

Slide 11 text

https://github.com/rwaldron/johnny-five Johnny-5 API Supports RPi, Edison, Galileo with “plugins”, e.g. https://github.com/nebrius/raspi-io

Slide 12

Slide 12 text

Basic LED var five = require("johnny-five");! var board = new five.Board();! ! board.on("ready", function() {! ! var led = new five.Led(13);! ! // "blink" the led in 500ms on-off phase periods! led.blink(500);! }); https://github.com/rwaldron/johnny-five/blob/master/eg/led-blink.js

Slide 13

Slide 13 text

Nodebot var five, temporal, Nodebot;! ! five = require("johnny-five");! ! temporal = require("temporal");! ! five.Board().on("ready", function() {! ! Nodebot = new five.Nodebot({! right: 10,! left: 11! });! ! this.repl.inject({! n: Nodebot! });! ! })! ! https://github.com/rwaldron/johnny-five/blob/master/eg/nodebot.js

Slide 14

Slide 14 text

Proximity var five = require("johnny-five");! var board = new five.Board();! ! board.on("ready", function() {! var proximity = new five.Proximity({! controller: "SRF10"! });! ! proximity.on("data", function() {! console.log(this.cm + "cm", this.in + "in");! });! ! proximity.on("change", function() {! console.log("The obstruction has moved.");! });! });

Slide 15

Slide 15 text

Direct I2C https://www.npmjs.com/package/i2c var i2c = require('i2c');! var address = 0x18;! var wire = new i2c(address, {device: '/dev/i2c-1'}); // point to your i2c address, debug provides REPL interface ! ! wire.scan(function(err, data) {! // result contains an array of addresses ! });! ! wire.writeByte(byte, function(err) {});! ! wire.writeBytes(command, [byte0, byte1], function(err) {});! ! wire.readByte(function(err, res) { // result is single byte }) ! ! wire.readBytes(command, length, function(err, res) {! // result contains a buffer of bytes ! });! ! wire.on('data', function(data) {! // result for continuous stream contains data buffer, address, length, timestamp ! });!

Slide 16

Slide 16 text

“full stack” JavaScript ! - ui - server - hardware

Slide 17

Slide 17 text

Server and adding sockets: https://github.com/lmccart/itp-creative-js/blob/master/Spring-2014/week6/04_socket_server/server.js var http = require('http');! var fs = require('fs');! var port = 3474;! ! // we create the server here! http.createServer(function (req, res) {! // simple logging of an incoming request! console.log(req.url);! ! // simple routing! if (req.url == '/') {! res.writeHead(200, {'Content-Type': ‘text/html'});! ! // serving a file! res.end(fs.readFileSync('static/index.html'));! }! }).listen(port);!

Slide 18

Slide 18 text

User Interfaces - processing library: http://p5js.org/reference - jQuery/Backbone/Angular/Ember/React

Slide 19

Slide 19 text

https://github.com/rockbot/vektor

Slide 20

Slide 20 text

nodecopter http://www.nodecopter.com/ https://github.com/MobileRobotics-Ulaval/CollaborativeDroneLocalization

Slide 21

Slide 21 text

projects + libs http://www.openrov.com/

Slide 22

Slide 22 text

npm • world’s largest package management system • npm init • npm install —save

Slide 23

Slide 23 text

JavaScript! inside