Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hardware Hacking with JavaScript

Hardware Hacking with JavaScript

Presented at WXG 2014

Andrew Nesbitt

September 26, 2014
Tweet

More Decks by Andrew Nesbitt

Other Decks in Programming

Transcript

  1. Advanced Mathematics Mechanical Engineering Digital Electronics Analogue Electronics Computer Science

    Control Theory Neural Networking Microprocessor Design Playing with Robots LEARNING ROBOTICS
  2. Advanced Mathematics Advanced Mathematics Advanced Mathematics Advanced Mathematics Advanced Mathematics

    Advanced Mathematics Advanced Mathematics Advanced Mathematics Observing Robots behind glass LEARNING ROBOTICS
  3. EV3

  4. Node.js is a platform built on Chrome's JavaScript runtime for

    easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
  5. ! var Ev3 = require ("ev3-nodejs-bt");
 var Ev3_base = Ev3.base;


    
 var XboxController = require('xbox-controller');
 var xbox = new XboxController;
 
 var robot = new Ev3_base("/dev/tty.EV3-SerialPort");
 
 var maxAngle = 32768;
 var maxSpeed = 100;
 
 var speeds = { a: 0, b: 0, c: 0, d: 0 };
  6. ! robot.connect(function(){
 robot.start_program(function(ev3){
 var setSpeed = function(){
 var output =

    ev3.getOutputSequence(speeds.a,speeds.b,speeds.c,speeds.d);
 ev3.sp.write(output);
 }
 
 setInterval(setSpeed, 100)
 
 xbox.on('left:move', function(position){
 var x = -(position.x / maxAngle)*-maxSpeed
 var y = (position.y / maxAngle)*-maxSpeed
 
 var left = y-x
 var right = y+x
 
 speeds.b = left
 speeds.a = right
 })
 
 xbox.on('a:press', function(){
 speeds.d = 100
 })
 
 xbox.on('a:release', function(){
 speeds.d = 0
 })
 });
 });

  7. ! var five = require("johnny-five"),
 board = new five.Board();
 


    function randomFromInterval(from,to){
 return Math.floor(Math.random()*(to-from+1)+from); 
 }
 
 board.on("ready", function() {
 var servoX = new five.Servo(10);
 var servoY = new five.Servo(9);
 var laser = new five.Led(8);
 
 laser.on()
 
 setInterval(function(){
 x = randomFromInterval(80, 120)
 y = randomFromInterval(95, 145)
 servoX.move(x)
 servoY.move(y)
 }, 400)
 }) 

  8. £70 £21 £30 £40 Lua based Tiny-js Node.js or browser

    Node.js Plug and play Hacker friendly Tiny computer All the ports
  9. ! var arDrone = require('ar-drone');
 var client = arDrone.createClient(); 


    
 client.takeoff();
 
 client
 .after(5000, function() {
 this.clockwise(0.5);
 })
 .after(3000, function() {
 this.animate('flipLeft', 15);
 })
 .after(1000, function() {
 this.stop();
 this.land();
 });