The JavaScript Evolution Of Open Source Robotics – cylonjs.com – Blink



The JavaScript Evolution Of Open Source Robotics – cylonjs.com – Blink

0 0


cylon-preso-intel-iot-hack-2014

A preso

On Github hybridgroup / cylon-preso-intel-iot-hack-2014

The JavaScript Evolution Of Open Source Robotics

cylonjs.com

Good Morning

This is @IntelIOT Roadshow

I am @deadprogram

Ringleader

@hybrid_group

The other guy is @adzankich

Serious Programming Guy

@hybrid_group

hybridgroup.com

kidsruby.com

JavaScript Robotics

The future is already here, it's just not very evenly distributed William Gibson

A JavaScript Framework for Robotics & Physical Computing

Multiple Hardware Devices

Different Hardware Devices

At the Same Time!

Cylon.js makes programming devices as easy as web development

Built-in API

Test-Driven Robotics

Command Line Interface

gort.io

RobotOps - DevOps For Robots

robotops.com

Show Me The Demo!

General Purpose Input/Output (GPIO)

Digital Output

Blink

var cylon = require('cylon');

cylon.robot({
  connection: { name: 'edison', adaptor: 'intel-iot' },
  device: {name: 'led', driver: 'led', pin: 13 },
})

.on('ready', function(bot) {
  setInterval(function() {
    bot.led.toggle();
  }, 1000);
})

.start();

Analog Input + Pulse Width Modulation (PWM) Output

Potentiometer and LED

var cylon = require('cylon');

cylon.robot({
  connection: { name: 'edison', adaptor: 'intel-iot' },
  devices: [
    { name: 'sensor', driver: 'analogSensor', pin: 0 },
    { name: 'led', driver: 'led', pin: 3 }
  ]
})

.on('ready', function(bot) {
  bot.sensor.on('analogRead', function(val) {
    brightness = val.fromScale(0, 1024).toScale(0, 255) | 0;
    console.log('brightness => ', brightness);
    bot.led.brightness(brightness)
  });
})

.start();

Inter-Integrated Circuit (i2c) Communication

Potentiometer and BlinkM

var cylon = require('cylon');

cylon.robot({
  connection: { name: 'edison', adaptor: 'intel-iot' },
  devices: [
    { name: 'sensor', driver: 'analogSensor', pin: 0 },
    { name: 'blinkm', driver: 'blinkm' }
  ]
})

.on('ready', function(bot) {
  bot.blinkm.stopScript();

  bot.sensor.on('analogRead', function(val) {
    brightness = val.fromScale(0, 1024).toScale(0, 255) | 0;
    console.log('brightness => ', brightness);
    bot.blinkm.goToRGB(brightness, brightness, brightness);
  });
})

.start();

Bluetooth

Sphero

var cylon = require('cylon');

cylon.robot({
  connection: { name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' },
  device: { name: 'sphero', driver: 'sphero' },
})

.on('ready', function(bot) {
  setInterval(function() {
    bot.sphero.roll(60, Math.floor(Math.random() * 360));
  }, 1000);
})

.start();

Multiple Spheros

Conway's Game Of Life

Conway's Game Of Life... With ROBOTS!

var Cylon = require("cylon");

var Green = 0x0000FF,
    Red = 0xFF0000;

var bots = {
  'Thelma': '/dev/rfcomm0',
  'Louise': '/dev/rfcomm1',
  'Grace':  '/dev/rfcomm2',
  'Ada':    '/dev/rfcomm3'
};

Object.keys(bots).forEach(function(name) {
  var port = bots[name];

  var robot = Cylon.robot({
    name: name,
    connection: { name: 'sphero', adaptor: 'sphero', port: port },
    device: { name: 'sphero', driver: 'sphero' }
  });

  robot.move = function() {
    robot.sphero.roll(60, Math.floor(Math.random() * 360));
  };

  robot.born = function() {
    robot.contacts = 0;
    robot.age = 0;
    robot.life();
    robot.move();
  };

  robot.life = function() {
    robot.alive = true;
    robot.sphero.setRGB(Green);
  };

  robot.death = function() {
    robot.alive = false;
    robot.sphero.setRGB(Red);
    robot.sphero.stop();
  };

  robot.enoughContacts = function() {
    return robot.contacts >= 2 && robot.contacts < 7;
  };

  robot.birthday = function() {
    robot.age += 1;

    if (robot.alive) {
      console.log("Happy birthday, " + robot.name + ". You are " + robot.age + " and had " + robot.contacts + " contacts.");
    }

    if (robot.enoughContacts()) {
      if (!robot.alive) {
        robot.born();
      }
    } else {
      robot.death();
    }

    robot.contacts = 0;
  };

  robot.on('ready', function() {
    robot.born();

    robot.sphero.on('collision', function() {
      robot.contacts += 1;
    });

    every((3).seconds(), function() {
      if (robot.alive) {
        robot.move();
      }
    });

    every((10).seconds(), function() {
      robot.birthday();
    });
  });
});

Cylon.start();

Was that fun?

Join the Robot Evolution!

cylonjs.com

@cylonjs

Thank you!

@deadprogram

@adzankich