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

BathRuby on Robots

BathRuby on Robots

Andrew Nesbitt

June 12, 2014
Tweet

More Decks by Andrew Nesbitt

Other Decks in Programming

Transcript

  1. require 'artoo'
 
 connection :arduino, :adaptor => :firmata, 
 :port

    => '/dev/cu.usbmodem1411'
 device :led, driver: :led, pin: 9
 
 work do
 loop do
 led.toggle
 sleep 1
 end
 end Hello World
  2. ! require 'artoo' ! connection :arduino, :adaptor => :firmata, :port

    => '/dev/cu.usbmodem1411' ! device :board, :driver => :device_info device :left_motor, :driver => :motor, :forward_pin => 6, # hack! :backward_pin => 8, :speed_pin => 10 ! device :right_motor, :driver => :motor, :forward_pin => 6, # hack! :backward_pin => 7, :speed_pin => 9 ! MAX_SPEED = 60 ! connection :keyboard, adaptor: :keyboard device :keyboard, driver: :keyboard, connection: :keyboard
  3. def keypress(sender, key) puts key case key when 'left' left_motor.backward

    MAX_SPEED right_motor.forward MAX_SPEED when 'right' left_motor.forward MAX_SPEED right_motor.backward MAX_SPEED when 'up' left_motor.forward MAX_SPEED right_motor.forward MAX_SPEED when 'down' left_motor.backward MAX_SPEED right_motor.backward MAX_SPEED when 'space' left_motor.stop right_motor.stop end end ! work do puts "Ready!" on keyboard, :key => :keypress end
  4. require 'artoo'
 
 connection :ardrone, :adaptor => :ardrone, :port =>

    '192.168.1.1:5556'
 device :drone, :driver => :ardrone, :connection => :ardrone
 
 work do
 drone.start
 drone.take_off
 
 after(10.seconds) { drone.hover.land }
 after(15.seconds) { drone.stop }
 end AR DRONE