Created
November 6, 2012 20:20
-
-
Save jimweirich/4027249 to your computer and use it in GitHub Desktop.
Ruby control of an Parrot AR Drone
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
| # See video at: http://www.youtube.com/watch?v=3NlYGn3QY4U&feature=youtu.be | |
| require 'socket' | |
| class ATCommand | |
| def initialize(socket, host=nil) | |
| @host = host || '192.168.1.1' | |
| @socket = socket | |
| @tick = 0 | |
| @buffer = "" | |
| end | |
| def ref(take_off=false, emergency=false) | |
| flags = 0 | |
| flags |= 512 if take_off | |
| flags |= 256 if emergency | |
| command("REF", flags) | |
| end | |
| def pcmd() | |
| command("PCMD", "0,0,0,0,0") | |
| end | |
| def flush | |
| @socket.send(@buffer, 0, @host, 5556) | |
| @buffer = "" | |
| end | |
| private | |
| def command(name, args) | |
| @tick += 1 | |
| @buffer << "AT*#{name}=#{@tick},#{args}\r" | |
| end | |
| end | |
| s = UDPSocket.new | |
| host = ARGV.shift | |
| at = ATCommand.new(s, host) | |
| running = true | |
| flying = true | |
| t = Thread.new { | |
| while running | |
| at.ref(flying) | |
| at.pcmd | |
| at.flush | |
| sleep(0.020) | |
| end | |
| } | |
| sleep 5 | |
| flying = false | |
| sleep 5 | |
| running = false | |
| t.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment