Pro Yearly is on sale from $80 to $50! »

Nodebotsday

 Nodebotsday

Overview on Nodebots

5d75f8af878f069a3b5939894c2e57ab?s=128

mulderp

July 27, 2015
Tweet

Transcript

  1. Nodebots! Day! 2015 Munich Maker Lab

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

  3. JavaScript … … is object-oriented … has a large ecosystem

    … runs on hardware
  4. Basic JavaScript var robot = {! color: ‘yellow’,! sound: ‘hello’,!

    ! blink: function() {! // action! }! }! ! robot.blink(); basic data functions as data
  5. 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;!
  6. events everywhere can make it difficult to work with “time

    critical” systems
  7. talking to robots

  8. node-serialport

  9. HOST Arduino Firmata! Protocol Firmata JS

  10. $ 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);! });!
  11. https://github.com/rwaldron/johnny-five Johnny-5 API Supports RPi, Edison, Galileo with “plugins”, e.g.

    https://github.com/nebrius/raspi-io
  12. 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
  13. 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
  14. 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.");! });! });
  15. 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 ! });!
  16. “full stack” JavaScript ! - ui - server - hardware

  17. 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);!
  18. User Interfaces - processing library: http://p5js.org/reference - jQuery/Backbone/Angular/Ember/React

  19. https://github.com/rockbot/vektor

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

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

  22. npm • world’s largest package management system • npm init

    • npm install —save
  23. JavaScript! inside