Skip to content

Instantly share code, notes, and snippets.

@elcuervo
Created October 9, 2013 01:36
Show Gist options
  • Save elcuervo/6894788 to your computer and use it in GitHub Desktop.
Save elcuervo/6894788 to your computer and use it in GitHub Desktop.
require 'artoo'
connection :ardrone, :adaptor => :ardrone, :port => '192.168.1.1:5556'
connection :leapmotion, :adaptor => :leapmotion, :port => '127.0.0.1:6437'
device :leapmotion, :connection => :leapmotion, :driver => :leapmotion
device :drone, :driver => :ardrone, :connection => :ardrone
class Overlord
attr_reader :drone
def initialize
reset_count
end
def drone=(drone)
@drone = drone
drone.start
drone.take_off
end
def read_palm(hand)
puts hand.palm_z
case hand.palm_z
when 0..100 then fly(:stop)
when 200..300 then fly(:down)
when 300..500 then fly(:up)
else
reset_count
end
end
def die_you_monster!
drone.hover.land if drone
end
def fly(direction)
puts direction
die_you_monster! if direction == :stop
if @action_times > 0
case direction
when :up then drone.turn_right(1)
when :down then drone.turn_left(1)
end
@action_times -= 1
end
end
private
def reset_count
@action_times = 2
end
end
overlord = Overlord.new
work do
overlord.drone = drone
on leapmotion, hand: -> sender, hand {
overlord.read_palm(hand)
}
end
at_exit { overlord.die_you_monster! }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment