Last active
August 29, 2015 14:01
-
-
Save zankich/271c472db89bc3e813a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Cylon = require('cylon'); | |
| var rest = require('restler'); | |
| var haarcascade = "" + __dirname + "/haarcascade_frontalface_alt.xml"; | |
| var DroneRobot = (function(){ | |
| function DroneRobot() {} | |
| DroneRobot.prototype.commands = ["faceOff"]; | |
| DroneRobot.prototype.connections = [ | |
| { name: 'opencv', adaptor: 'opencv' }, | |
| { name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1' } | |
| ]; | |
| DroneRobot.prototype.devices = [ | |
| { name: 'drone', driver: 'ardrone', connection: 'ardrone' }, | |
| { name: 'window', driver: 'window', conneciton: 'opencv' }, | |
| { name: 'mat', driver: 'mat', conneciton: 'opencv' } | |
| ]; | |
| DroneRobot.prototype.work = function(my) { | |
| console.log("SHOW ME YOUR FACE!"); | |
| }; | |
| DroneRobot.prototype.faceOff = function() { | |
| var my = this; | |
| var self = this; | |
| self.detect = false; | |
| self.image = null; | |
| my.drone.getPngStream().on('data', function(png) { | |
| my.mat.readImage(png, function(err, img) { | |
| self.image = img; | |
| if (self.detect === false) { | |
| my.window.show(img); | |
| } | |
| }); | |
| }); | |
| my.mat.on('facesDetected', function(err, im, faces) { | |
| var biggest, center_x, f, face, turn; | |
| biggest = 0; | |
| face = null; | |
| for (var i = 0; i < faces.length; i++) { | |
| f = faces[i]; | |
| if (f.width > biggest) { | |
| biggest = f.width; | |
| face = f; | |
| } | |
| } | |
| if (face !== null && (face.width <= 100 && face.width >= 45)) { | |
| rest.get('http://192.168.1.1:3000/robots/digispark/devices/led/commands/ToggleC').on('complete', function(result) { | |
| if (result instanceof Error) { | |
| console.log('Error:', result.message); | |
| } | |
| }); | |
| im.rectangle([face.x, face.y], [face.x + face.width, face.y + face.height], | |
| [0, 255, 0], 2); | |
| center_x = im.width() * 0.5; | |
| turn = -(face.x - center_x) / center_x; | |
| console.log("turning: " + turn); | |
| if (turn < 0) { | |
| my.drone.clockwise(Math.abs(turn * 0.7)); | |
| } else { | |
| my.drone.counterClockwise(Math.abs(turn * 0.7)); | |
| } | |
| } else { | |
| rest.get('http://192.168.1.1:3000/robots/digispark/devices/led/commands/OffC').on('complete', function(result) { | |
| if (result instanceof Error) { | |
| console.log('Error:', result.message); | |
| } | |
| }); | |
| } | |
| my.window.show(im); | |
| }); | |
| my.drone.takeoff(); | |
| after((8).seconds(), function() { my.drone.up(0.5); }); | |
| after((10).seconds(), function() { my.drone.hover(); }); | |
| after((13).seconds(), function() { | |
| self.detect = true; | |
| every(0.3.seconds(), function() { | |
| my.drone.hover(); | |
| my.mat.detectFaces(self.image, haarcascade); | |
| }); | |
| after((30).seconds(), function() { my.drone.land(); }); | |
| }); | |
| }; | |
| return DroneRobot; | |
| })(); | |
| var robot = new DroneRobot; | |
| robot.name = "drone"; | |
| Cylon.robot(robot); | |
| Cylon.api({ host: '192.168.1.3', port: '3000' }); | |
| Cylon.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'artoo' | |
| connection :ardrone, :adaptor => :ardrone, :port => '192.168.1.1:5556' | |
| device :drone, :driver => :ardrone, :connection => :ardrone | |
| connection :joystick, :adaptor => :joystick | |
| device :controller, :driver => :ps3, :connection => :joystick, :interval => 0.01 | |
| OFFSETS = { | |
| :dx => 32767.0 | |
| } | |
| @toggle_camera = 0 | |
| work do | |
| on controller, :button_square => proc { drone.take_off } | |
| on controller, :button_triangle => proc { drone.hover } | |
| on controller, :button_x => proc { drone.land } | |
| on controller, :button_circle => proc { | |
| unless @toggle_camera | |
| drone.bottom_camera | |
| @toggle_camera = 1 | |
| else | |
| drone.front_camera | |
| @toggle_camera = 0 | |
| end | |
| } | |
| on controller, :button_home => proc { drone.emergency } | |
| on controller, :button_start => proc { drone.start } | |
| on controller, :button_select => proc { drone.stop } | |
| on controller, :joystick_0 => proc { |*value| | |
| pair = value[1] | |
| if pair[:y] < 0 | |
| drone.forward(validate_pitch(pair[:y], OFFSETS[:dx])) | |
| elsif pair[:y] > 0 | |
| drone.backward(validate_pitch(pair[:y], OFFSETS[:dx])) | |
| else | |
| drone.forward(0.0) | |
| end | |
| if pair[:x] > 0 | |
| drone.right(validate_pitch(pair[:x], OFFSETS[:dx])) | |
| elsif pair[:x] < 0 | |
| drone.left(validate_pitch(pair[:x], OFFSETS[:dx])) | |
| else | |
| drone.right(0.0) | |
| end | |
| } | |
| on controller, :joystick_1 => proc { |*value| | |
| pair = value[1] | |
| if pair[:y] < 0 | |
| drone.up(validate_pitch(pair[:y], OFFSETS[:dx])) | |
| elsif pair[:y] > 0 | |
| drone.down(validate_pitch(pair[:y], OFFSETS[:dx])) | |
| else | |
| drone.up(0.0) | |
| end | |
| if pair[:x] > 0 | |
| drone.turn_right(validate_pitch(pair[:x], OFFSETS[:dx])) | |
| elsif pair[:x] < 0 | |
| drone.turn_left(validate_pitch(pair[:x], OFFSETS[:dx])) | |
| else | |
| drone.turn_right(0.0) | |
| end | |
| } | |
| end | |
| def validate_pitch(data, offset) | |
| value = data.abs / offset | |
| value >= 0.1 ? (value <= 1.0 ? value.round(2) : 1.0) : 0.0 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/hybridgroup/gobot" | |
| "github.com/hybridgroup/gobot-beaglebone" | |
| "github.com/hybridgroup/gobot-gpio" | |
| ) | |
| func main() { | |
| beaglebone := new(gobotBeaglebone.Beaglebone) | |
| beaglebone.Name = "beaglebone" | |
| led := gobotGPIO.NewLed(beaglebone) | |
| led.Name = "led" | |
| led.Pin = "P9_12" | |
| work := func() { | |
| gobot.Every("1s", func() { led.Toggle() }) | |
| } | |
| robot = gobot.Robot{ | |
| Connections: []gobot.Connection{beaglebone}, | |
| Devices: []gobot.Device{led}, | |
| Work: work, | |
| } | |
| robot.Start() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/hybridgroup/gobot" | |
| "github.com/hybridgroup/gobot-sphero" | |
| ) | |
| type conway struct { | |
| alive bool | |
| age int | |
| contacts int | |
| sphero *gobotSphero.SpheroDriver | |
| } | |
| func main() { | |
| master := gobot.GobotMaster() | |
| gobot.Api(master) | |
| var robots []*gobot.Robot | |
| spheros := map[string]string{ | |
| "/dev/rfcomm0": "Thelma", | |
| "/dev/rfcomm1": "Louise", | |
| "/dev/rfcomm2": "Grace", | |
| "/dev/rfcomm3": "Ada", | |
| "/dev/rfcomm4": "Mary", | |
| } | |
| for port, name := range spheros { | |
| spheroAdaptor := new(gobotSphero.SpheroAdaptor) | |
| spheroAdaptor.Name = "Sphero" | |
| spheroAdaptor.Port = port | |
| sphero := gobotSphero.NewSphero(spheroAdaptor) | |
| sphero.Name = name | |
| work := func() { | |
| conway := new(conway) | |
| conway.sphero = sphero | |
| sphero.SetBackLED(0) | |
| conway.birth() | |
| gobot.On(sphero.Events["Collision"], func(data interface{}) { | |
| conway.contact() | |
| }) | |
| gobot.Every("3s", func() { | |
| if conway.alive == true { | |
| conway.movement() | |
| } | |
| }) | |
| gobot.Every("10s", func() { | |
| if conway.alive == true { | |
| conway.birthday() | |
| } | |
| }) | |
| } | |
| robots = append(robots, &gobot.Robot{Name: name, Connections: []gobot.Connection{spheroAdaptor}, Devices: []gobot.Device{sphero}, Work: work}) | |
| } | |
| master.Robots = robots | |
| master.Start() | |
| } | |
| func (c *conway) resetContacts() { | |
| c.contacts = 0 | |
| } | |
| func (c *conway) contact() { | |
| c.contacts += 1 | |
| } | |
| func (c *conway) rebirth() { | |
| fmt.Println("Welcome back", c.sphero.Name, "!") | |
| c.life() | |
| } | |
| func (c *conway) birth() { | |
| c.resetContacts() | |
| c.age = 0 | |
| c.life() | |
| c.movement() | |
| } | |
| func (c *conway) life() { | |
| c.sphero.SetRGB(0, 255, 0) | |
| c.alive = true | |
| } | |
| func (c *conway) death() { | |
| fmt.Println(c.sphero.Name, "died :(") | |
| c.alive = false | |
| c.sphero.SetRGB(255, 0, 0) | |
| c.sphero.Stop() | |
| } | |
| func (c *conway) enoughContacts() bool { | |
| if c.contacts >= 2 && c.contacts < 7 { | |
| return true | |
| } else { | |
| return false | |
| } | |
| } | |
| func (c *conway) birthday() { | |
| c.age += 1 | |
| fmt.Println("Happy birthday", c.sphero.Name, "you are", c.age, "and had", c.contacts, "contacts.") | |
| if c.enoughContacts() == true { | |
| if c.alive == false { | |
| c.rebirth() | |
| } | |
| } else { | |
| c.death() | |
| } | |
| c.resetContacts() | |
| } | |
| func (c *conway) movement() { | |
| if c.alive == true { | |
| c.sphero.Roll(100, uint16(gobot.Rand(360))) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/hybridgroup/gobot" | |
| "github.com/hybridgroup/gobot-digispark" | |
| "github.com/hybridgroup/gobot-gpio" | |
| ) | |
| func main() { | |
| master := gobot.GobotMaster() | |
| gobot.Api(master) | |
| digispark := new(gobotDigispark.DigisparkAdaptor) | |
| digispark.Name = "digispark" | |
| led := gobotGPIO.NewLed(digispark) | |
| led.Name = "led" | |
| led.Pin = "2" | |
| master.Robots = append(master.Robots, &gobot.Robot{ | |
| Name: "digispark", | |
| Connections: []gobot.Connection{digispark}, | |
| Devices: []gobot.Device{red}, | |
| }) | |
| master.Start() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Check your project using Travis-CI | |
| # then displays your build status with a bright RGB LED | |
| # | |
| # Uses Digispark USB board (http://digistump.com/products/1) | |
| # and Digispark RGB shield (http://digistump.com/products/3) | |
| require 'artoo' | |
| require 'travis' | |
| connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f | |
| device :red, :driver => :led, :pin => 0 | |
| device :green, :driver => :led, :pin => 1 | |
| device :blue, :driver => :led, :pin => 2 | |
| work do | |
| turn_on(blue) | |
| #repo_name = 'hybridgroup/broken-arrow' | |
| repo_name = 'hybridgroup/artoo' | |
| puts "Connecting to repo: #{repo_name}" | |
| @repo = Travis::Repository.find(repo_name) | |
| every 10.seconds do | |
| puts "Checking #{repo_name}..." | |
| @repo.reload | |
| case | |
| when @repo.green? | |
| turn_on(green) | |
| when @repo.running? | |
| turn_on(blue) | |
| else | |
| turn_on(red) | |
| end | |
| end | |
| end | |
| def turn_on(led) | |
| turn_off_leds | |
| led.on | |
| end | |
| def turn_off_leds | |
| red.off | |
| green.off | |
| blue.off | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'artoo' | |
| connection :firmata, :adaptor => :firmata, :port => '/dev/ttyACM0' | |
| device :led, :driver => :led, :pin => 13 | |
| work do | |
| every 1.second do | |
| led.toggle | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //leap_sphero.js | |
| var Cylon = require('cylon'); | |
| Cylon.robot({ | |
| connections: [ | |
| { name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437' }, | |
| { name: 'sphero', adaptor: 'sphero', port: '/dev/rfcomm0' } | |
| ], | |
| devices: [ | |
| { name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion' }, | |
| { name: 'sphero', driver: 'sphero', connection: 'sphero' } | |
| ], | |
| work: function(my) { | |
| var y = 0; | |
| var x = 0; | |
| my.sphero.setBackLED(255) | |
| my.leapmotion.on('hand', function(hand) { | |
| y = hand.palmY.fromScale(50, 200).toScale(0, 90) | 0; | |
| x = hand.palmX.fromScale(-30, 50).toScale(0, 90) | 0; | |
| }); | |
| every((1).second(), function() { | |
| my.sphero.setRGB(Math.floor(Math.random() * 16777216)); | |
| }); | |
| every((0.01).second(), function() { | |
| if (x != 0) { | |
| if (x > 45) { | |
| my.sphero.roll(40, x.fromScale(45, 90).toScale(90, 180) | 0); | |
| } else { | |
| my.sphero.roll(40, x.fromScale(0, 45).toScale(270, 359) | 0); | |
| } | |
| } else { | |
| if (y > 45) { | |
| my.sphero.roll(40, y.fromScale(45, 90).toScale(0, 90) | 0); | |
| } else { | |
| my.sphero.roll(40, y.fromScale(0, 45).toScale(180, 270) | 0); | |
| } | |
| } | |
| }); | |
| } | |
| }) | |
| Cylon.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'artoo' | |
| require 'http' | |
| connection :pebble, :adaptor => :pebble | |
| device :watch, :driver => :pebble, :name => 'pebble' | |
| api :host => '0.0.0.0', :port => '8080' | |
| name 'pebble' | |
| def button_push(*data) | |
| unless data[1].nil? | |
| puts "Posting to Cylon" | |
| HTTP[:content_type => 'application/json'].get "https://192.168.1.3:3000/robots/drone/commands/faceOff" | |
| p "#{data[1]} button pushed" | |
| end | |
| end | |
| work do | |
| pebble.send_notification("Hello Pebble!") | |
| on pebble, :button => :button_push | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Cylon = require('cylon'); | |
| Cylon.robot({ | |
| connection: { name: 'tessel', adaptor: 'tessel', port: 'GPIO' }, | |
| device: { name: 'led', driver: 'led', pin: 3 }, | |
| work: function(my) { | |
| every((1).second(), my.led.toggle); | |
| } | |
| }).start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment