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

Robotics 101

Andrew Nesbitt
September 19, 2014

Robotics 101

Presented at Hackference 2.0.14

Andrew Nesbitt

September 19, 2014
Tweet

More Decks by Andrew Nesbitt

Other Decks in Technology

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. robot /ˈrəʊbɒt/ a machine capable of carrying out a complex

    series of actions automatically, especially one programmable by a computer.
  4. EV3

  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. var five = require("johnny-five"), board = new five.Board(); ! var

    Zumo = function(){ this.leftMotor = new five.Motor({ pins: { pwm: 10, dir: 8 } }); ! this.rightMotor = new five.Motor({ pins: { pwm: 9, dir: 7 } }); ! this.move = function(x,y){ var left = y-x var right = y+x ! if(left > 0){ this.leftMotor.reverse(left) } else { this.leftMotor.forward(-left) } ! if(right > 0){ this.rightMotor.reverse(right) } else { this.rightMotor.forward(-right) } } }
  9. var XboxController = require('xbox-controller'), xbox = new XboxController; ! maxAngle

    = 32768 maxSpeed = 255 ! board.on("ready", function() { var zumo = new Zumo ! var x = 0 var y = 0 ! xbox.on('left:move', function(position){ x = (position.x / maxAngle)*-maxSpeed zumo.move(x,y) }) ! xbox.on('lefttrigger', function(position){ y = -position zumo.move(x,y) }) ! xbox.on('righttrigger', function(position){ y = position zumo.move(x,y) }) })
  10. AUDIO, VISION, MOTION, TEMPERATURE, POSITION, DISTANCE, TOUCH, FORCE, MAGNETIC, LIGHT,

    VIBRATION, MOISTURE, PRESSURE, PROXIMITY, CHEMICAL, ELECTRICAL, COLOR AND MORE INPUT SENSORS
  11. var Cylon = require('cylon'); ! Cylon.robot({ connection: { name: 'sphero',

    adaptor: 'sphero', port: '/dev/cu.Sphero-GGP-AMP-SPP' }, device: { name: 'sphero', driver: 'sphero' }, ! work: function(my) { var color = 0x00FF00, bitFilter = 0xFFFF00; ! after((1).seconds(), function() { console.log("Setting up Collision Detection..."); my.sphero.detectCollisions(); my.sphero.setDataStreaming(['locator', 'accelOne', 'velocity'], { n: 200, m: 1, pcnt: 0,}); my.sphero.setBackLED(255); my.sphero.setRGB(color); my.sphero.stop(); every(5..seconds(), function() { my.sphero.roll(128, Math.floor(Math.random() * 360)); }); }); ! my.sphero.on('data', function(data) { app.io.broadcast('draw', {color:color.toString(16), x:data[0], y:data[1]}) }); ! my.sphero.on('collision', function(data) { color = color ^ bitFilter; my.sphero.setRGB(color); my.sphero.roll(128, Math.floor(Math.random() * 360)); app.io.broadcast('collision', {color:color.toString(16)}) }); ! } }).start();
  12. // Input my.sphero.on('collision', function(data) { // Processing color = color

    ^ bitFilter; direction = Math.floor(Math.random() * 360) // Output my.sphero.roll(128, direction); my.sphero.setRGB(color); app.io.broadcast('collision', {color:color.toString(16)}) }); ! ! ! // Input my.sphero.on('data', function(data) { ! // Processing if(Math.abs(data[0]) > 1000 || Math.abs(data[1]) > 1000) { // Output my.sphero.roll(128, Math.abs(direction - 180)); } ! // Output app.io.broadcast('draw', {color:color.toString(16), x:data[0], y:data[1]}) });
  13. var express = require('express.io') var app = express().http().io() ! app.get('/',

    function(req, res) { res.sendfile(__dirname + '/client.html') }) ! app.listen(7076)
  14. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="//cdn.techpines.io/jquery.event.drag-2.0.js"></script> <script src="/socket.io/socket.io.js"></script> <script> App = {}

    App.socket = io.connect() ! var startX = 950; var startY = 500; ! var previousX = 950; var previousY = 500; ! App.draw = function(data) { App.ctx.beginPath() App.ctx.moveTo(previousX, previousY); App.ctx.lineWidth = 5; App.ctx.lineTo(data.x+startX,data.y+startY) App.ctx.strokeStyle = "#" + data.color App.ctx.stroke() previousX = data.x+startX; previousY = data.y+startY; } ! App.socket.on('draw', App.draw) ! $(function() { App.ctx = $('canvas')[0].getContext("2d") }) </script> <canvas width="1900px" height="1000px" style="margin: 0 auto;border:1px solid #eee;"></canvas>
  15. // Plan mission mission.takeoff() .zero() .hover(500) .altitude(3) .forward(2) .right(2) .backward(2)

    .go({x:0, y:0}) .hover(500) .land(); ! // Execute mission mission.run(function (err, result) { if (err) { console.trace("Oops: %s", err.message); mission.client().stop(); mission.client().land(); } else { console.log("We are done!"); process.exit(0); } });
  16. ! // Land on ctrl-c var exiting = false; process.on('SIGINT',

    function() { if (exiting) { process.exit(0); } else { console.log('Landing, Control-C again to force exit'); exiting = true; mission.control().disable(); mission.client().land(function() { process.exit(0); }); } }); !