artoo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/.gitignore +25 -0
  2. data/Gemfile +26 -0
  3. data/Gemfile.lock +144 -0
  4. data/Guardfile +15 -0
  5. data/LICENSE +13 -0
  6. data/README.md +97 -0
  7. data/Rakefile +11 -0
  8. data/api/assets/compass.rb +25 -0
  9. data/api/assets/javascripts/artoo/controllers/robot.js.coffee +27 -0
  10. data/api/assets/javascripts/artoo/routes.js.coffee +23 -0
  11. data/api/assets/javascripts/core.js.coffee +6 -0
  12. data/api/assets/javascripts/vendor/angular.min.js +161 -0
  13. data/api/assets/javascripts/vendor/bootstrap.min.js +6 -0
  14. data/api/assets/javascripts/vendor/jquery.min.js +5 -0
  15. data/api/assets/stylesheets/artoo/_core.css.scss +3 -0
  16. data/api/assets/stylesheets/artoo/_font-awesome.scss +534 -0
  17. data/api/assets/stylesheets/artoo/_variables.scss +8 -0
  18. data/api/assets/stylesheets/core.scss +70 -0
  19. data/api/public/core.css +9848 -0
  20. data/api/public/core.js +259 -0
  21. data/api/public/favicon.ico +0 -0
  22. data/api/public/font/FontAwesome.otf +0 -0
  23. data/api/public/font/fontawesome-webfont.eot +0 -0
  24. data/api/public/font/fontawesome-webfont.svg +284 -0
  25. data/api/public/font/fontawesome-webfont.ttf +0 -0
  26. data/api/public/font/fontawesome-webfont.woff +0 -0
  27. data/api/public/html5shiv.js +8 -0
  28. data/api/public/images/devices/ardrone.jpg +0 -0
  29. data/api/public/images/devices/arduino.jpg +0 -0
  30. data/api/public/images/devices/sphero.png +0 -0
  31. data/api/public/images/glyphicons-halflings-white.png +0 -0
  32. data/api/public/images/glyphicons-halflings.png +0 -0
  33. data/api/public/index.html +36 -0
  34. data/api/public/partials/robot-detail.html +111 -0
  35. data/api/public/partials/robot-device-detail.html +0 -0
  36. data/api/public/partials/robot-index.html +26 -0
  37. data/artoo.gemspec +21 -0
  38. data/bin/retry.sh +8 -0
  39. data/bin/sphero.sh +8 -0
  40. data/examples/ardrone.rb +12 -0
  41. data/examples/ardrone_nav.rb +22 -0
  42. data/examples/ardrone_nav_video.rb +33 -0
  43. data/examples/ardrone_video.rb +22 -0
  44. data/examples/conway_sphero.rb +65 -0
  45. data/examples/firmata.rb +13 -0
  46. data/examples/firmata_button.rb +9 -0
  47. data/examples/hello.rb +12 -0
  48. data/examples/hello_api.rb +9 -0
  49. data/examples/hello_api_multiple.rb +25 -0
  50. data/examples/hello_modular.rb +16 -0
  51. data/examples/hello_multiple.rb +22 -0
  52. data/examples/notifications.rb +9 -0
  53. data/examples/sphero.rb +11 -0
  54. data/examples/sphero_color.rb +13 -0
  55. data/examples/sphero_firmata.rb +17 -0
  56. data/examples/sphero_messages.rb +22 -0
  57. data/examples/sphero_multiple.rb +33 -0
  58. data/examples/wiiclassic.rb +94 -0
  59. data/lib/artoo.rb +3 -0
  60. data/lib/artoo/adaptors/adaptor.rb +54 -0
  61. data/lib/artoo/adaptors/ardrone.rb +32 -0
  62. data/lib/artoo/adaptors/ardrone_navigation.rb +26 -0
  63. data/lib/artoo/adaptors/ardrone_video.rb +27 -0
  64. data/lib/artoo/adaptors/firmata.rb +25 -0
  65. data/lib/artoo/adaptors/loopback.rb +8 -0
  66. data/lib/artoo/adaptors/sphero.rb +46 -0
  67. data/lib/artoo/api.rb +48 -0
  68. data/lib/artoo/api_route_helpers.rb +197 -0
  69. data/lib/artoo/connection.rb +70 -0
  70. data/lib/artoo/delegator.rb +49 -0
  71. data/lib/artoo/device.rb +61 -0
  72. data/lib/artoo/device_event_client.rb +27 -0
  73. data/lib/artoo/drivers/ardrone.rb +9 -0
  74. data/lib/artoo/drivers/ardrone_navigation.rb +21 -0
  75. data/lib/artoo/drivers/ardrone_video.rb +22 -0
  76. data/lib/artoo/drivers/button.rb +40 -0
  77. data/lib/artoo/drivers/driver.rb +48 -0
  78. data/lib/artoo/drivers/led.rb +37 -0
  79. data/lib/artoo/drivers/passthru.rb +9 -0
  80. data/lib/artoo/drivers/pinger.rb +19 -0
  81. data/lib/artoo/drivers/pinger2.rb +18 -0
  82. data/lib/artoo/drivers/sphero.rb +57 -0
  83. data/lib/artoo/drivers/wiichuck.rb +29 -0
  84. data/lib/artoo/drivers/wiiclassic.rb +137 -0
  85. data/lib/artoo/main.rb +32 -0
  86. data/lib/artoo/master.rb +16 -0
  87. data/lib/artoo/port.rb +51 -0
  88. data/lib/artoo/robot.rb +299 -0
  89. data/lib/artoo/utility.rb +39 -0
  90. data/lib/artoo/version.rb +5 -0
  91. data/test/adaptors/adaptor_test.rb +18 -0
  92. data/test/adaptors/ardrone_test.rb +24 -0
  93. data/test/adaptors/firmata_test.rb +25 -0
  94. data/test/adaptors/loopback_test.rb +18 -0
  95. data/test/adaptors/sphero_test.rb +24 -0
  96. data/test/api_test.rb +61 -0
  97. data/test/artoo_test.rb +12 -0
  98. data/test/connection_test.rb +28 -0
  99. data/test/delegator_test.rb +71 -0
  100. data/test/device_test.rb +41 -0
  101. data/test/drivers/ardrone_navigation_test.rb +11 -0
  102. data/test/drivers/ardrone_test.rb +11 -0
  103. data/test/drivers/ardrone_video_test.rb +11 -0
  104. data/test/drivers/driver_test.rb +21 -0
  105. data/test/drivers/led_test.rb +52 -0
  106. data/test/drivers/sphero_test.rb +54 -0
  107. data/test/drivers/wiichuck_test.rb +11 -0
  108. data/test/port_test.rb +33 -0
  109. data/test/robot_test.rb +96 -0
  110. data/test/test_helper.rb +8 -0
  111. data/test/utility_test.rb +27 -0
  112. metadata +185 -0
@@ -0,0 +1,25 @@
1
+ require 'artoo/robot'
2
+
3
+ class HelloRobot < Artoo::Robot
4
+ connection :loopback1
5
+ connection :loopback2
6
+ connection :loopback3
7
+ device :passthru1
8
+ device :passthru2
9
+ device :pinger, :driver => :pinger
10
+ device :pinger2, :driver => :pinger2
11
+
12
+ api :host => '127.0.0.1', :port => '4321'
13
+
14
+ work do
15
+ puts "Hello from '#{name}' attached to API running at #{api_host}:#{api_port}..."
16
+ end
17
+ end
18
+
19
+ robots = []
20
+ 5.times do |i|
21
+ robots << HelloRobot.new(:name => "Number #{i}")
22
+ end
23
+
24
+ HelloRobot.work!(robots)
25
+ sleep
@@ -0,0 +1,16 @@
1
+ require 'artoo/robot'
2
+
3
+ class HelloRobot < Artoo::Robot
4
+ connection :loop
5
+
6
+ work do
7
+ every(3.seconds) do
8
+ puts "hello"
9
+ end
10
+ after(10.seconds) do
11
+ puts "wow"
12
+ end
13
+ end
14
+ end
15
+
16
+ HelloRobot.work!
@@ -0,0 +1,22 @@
1
+ require 'artoo/robot'
2
+
3
+ class HelloRobot < Artoo::Robot
4
+ connection :loop
5
+
6
+ work do
7
+ every(3.seconds) do
8
+ puts "Hello from #{name}"
9
+ end
10
+ after(10.seconds) do
11
+ puts "#{name} is alive!" if name == 'Number 5'
12
+ end
13
+ end
14
+ end
15
+
16
+ robots = []
17
+ 5.times do |i|
18
+ robots << HelloRobot.new(:name => "Number #{i}")
19
+ end
20
+
21
+ HelloRobot.work!(robots)
22
+ sleep
@@ -0,0 +1,9 @@
1
+ require 'artoo'
2
+
3
+ connection :loop
4
+ device :pinger, :driver => :pinger
5
+
6
+ work do
7
+ puts 'Starting...'
8
+ on pinger, :alive => proc {puts 'I am awesome!'}
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'artoo'
2
+
3
+ connection :sphero, :adaptor => :sphero, :port => '4560' #/dev/tty.Sphero-YRR-RN-SPP'
4
+ device :sphero, :driver => :sphero
5
+
6
+ work do
7
+ every(3.seconds) do
8
+ puts "Rolling..."
9
+ sphero.roll 60, rand(360)
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'artoo'
2
+
3
+ connection :sphero, :adaptor => :sphero, :port => '4560' #/dev/tty.Sphero-YRR-RN-SPP'
4
+ device :sphero, :driver => :sphero
5
+
6
+ work do
7
+ @count = 1
8
+ every(3.seconds) do
9
+ sphero.set_color(@count % 2 == 0 ? :green : :red)
10
+ @count += 1
11
+ sphero.roll 60, rand(360)
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'artoo'
2
+
3
+ connection :sphero, :adaptor => :sphero, :port => '/dev/tty.Sphero-BRG-RN-SPP'
4
+ device :sphero, :driver => :sphero, :connection => :sphero
5
+
6
+ connection :arduino, :adaptor => :firmata, :port => '/dev/cu.usbserial-A700636n'
7
+ device :led, :driver => :led, :connection => :arduino, :pin => 13
8
+
9
+ work do
10
+ every 3.seconds do
11
+ sphero.roll 60, rand(360)
12
+ end
13
+
14
+ every 1.second do
15
+ led.toggle
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'artoo'
2
+
3
+ connection :sphero, :adaptor => :sphero, :port => '4560' #'/dev/tty.Sphero-BWY-RN-SPP'
4
+ device :sphero, :driver => :sphero
5
+
6
+ work do
7
+ puts "Configuring..."
8
+ sphero.detect_collisions
9
+
10
+ every(3.seconds) do
11
+ puts "Rolling..."
12
+ sphero.roll 60, rand(360)
13
+ unless sphero.collisions.empty?
14
+ puts "----------"
15
+ sphero.collisions.each do |c|
16
+ puts c
17
+ end
18
+ puts "=========="
19
+ sphero.async_messages.clear
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ require 'artoo/robot'
2
+
3
+ #SPHEROS = ["4567", "4568", "4569", "4570", "4571"]
4
+ SPHEROS = {"4560" => "/dev/tty.Sphero-BRG-RN-SPP",
5
+ "4561" => "/dev/tty.Sphero-YBW-RN-SPP",
6
+ "4562" => "/dev/tty.Sphero-BWY-RN-SPP",
7
+ "4563" => "/dev/tty.Sphero-YRR-RN-SPP",
8
+ "4564" => "/dev/tty.Sphero-OBG-RN-SPP",
9
+ "4565" => "/dev/tty.Sphero-GOB-RN-SPP",
10
+ "4566" => "/dev/tty.Sphero-PYG-RN-SPP"}
11
+
12
+ class SpheroRobot < Artoo::Robot
13
+ connection :sphero, :adaptor => :sphero
14
+ device :sphero, :driver => :sphero
15
+
16
+ work do
17
+ @count = 1
18
+ every(3.seconds) do
19
+ sphero.set_color(@count % 2 == 0 ? :green : :red)
20
+ @count += 1
21
+ sphero.roll 90, rand(360)
22
+ end
23
+ end
24
+ end
25
+
26
+ robots = []
27
+ SPHEROS.each_key {|p|
28
+ robots << SpheroRobot.new(:connections =>
29
+ {:sphero =>
30
+ {:port => p}})
31
+ }
32
+
33
+ SpheroRobot.work!(robots)
@@ -0,0 +1,94 @@
1
+ require 'artoo'
2
+
3
+ connection :ardrone, :adaptor => :ardrone, :port => '192.168.1.1:5556'
4
+ #connection :ardrone, :adaptor => :ardrone, :port => '192.168.0.100:5556'
5
+ device :drone, :driver => :ardrone, :connection => :ardrone
6
+
7
+ #connection :arduino, :adaptor => :firmata, :port => "/dev/ttyACM0"
8
+ connection :arduino, :adaptor => :firmata, :port => "8023"
9
+ device :classic, :driver => :wiiclassic, :connection => :arduino, :interval => 0.1
10
+
11
+ work do
12
+ @rotate_pitch = 0.5
13
+ @fly_pitch = 0.7
14
+ @altitude_pitch = 1
15
+ @toggle_camera = 0
16
+ on classic, :a_button => proc {
17
+ puts "Take Off"
18
+ drone.take_off
19
+ }
20
+ on classic, :b_button => proc {
21
+ puts "Hover"
22
+ drone.hover
23
+ }
24
+ on classic, :x_button => proc {
25
+ puts "Land"
26
+ drone.land
27
+ }
28
+ on classic, :y_button => proc {
29
+ puts "Toggle camera"
30
+ if @toggle_camera == 0
31
+ puts "Bottom Camera Enabled"
32
+ drone.bottom_camera
33
+ @toggle_camera = 1
34
+ else
35
+ puts "Front Camera Enabled"
36
+ drone.front_camera
37
+ @toggle_camera = 0
38
+ end
39
+ }
40
+ on classic, :home_button => proc {
41
+ puts "EMERGENGY!!!"
42
+ drone.emergency
43
+ }
44
+ on classic, :start_button => proc {
45
+ puts "Start"
46
+ drone.start
47
+ }
48
+ on classic, :select_button => proc {
49
+ puts "Stop"
50
+ drone.stop
51
+ }
52
+ on classic, :ry_up => proc {
53
+ puts "Up"
54
+ drone.up(@altitude_pitch)
55
+ }
56
+ on classic, :ry_down => proc {
57
+ puts "Down"
58
+ drone.down(@altitude_pitch)
59
+ }
60
+ on classic, :ly_up => proc {
61
+ puts "Forward"
62
+ drone.forward(@fly_pitch)
63
+ }
64
+ on classic, :ly_down => proc {
65
+ puts "Backward"
66
+ drone.backward(@fly_pitch)
67
+ }
68
+ on classic, :lx_right => proc {
69
+ puts "Right"
70
+ drone.right(@fly_pitch)
71
+ }
72
+ on classic, :lx_left => proc {
73
+ puts "Left"
74
+ drone.left(@fly_pitch)
75
+ }
76
+ on classic, :reset_pitch_roll => proc {
77
+ drone.left(0.0)
78
+ drone.forward(0.0)
79
+ }
80
+ on classic, :rotate_left => proc {
81
+ puts "rotate left"
82
+ drone.turn_left(@rotate_pitch)
83
+ }
84
+ on classic, :rotate_right => proc {
85
+ puts "rotate right"
86
+ drone.turn_right(@rotate_pitch)
87
+ }
88
+ on classic, :reset_rotate => proc {
89
+ drone.turn_left(0.0)
90
+ }
91
+ on classic, :reset_altitude => proc {
92
+ drone.up(0.0)
93
+ }
94
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'artoo/robot'
3
+ require 'artoo/main'
@@ -0,0 +1,54 @@
1
+ module Artoo
2
+ module Adaptors
3
+ # The Adaptor class is the base class used to
4
+ # connect to a specific group of hardware devices. Examples
5
+ # would be an Arduino, a Sphero, or an ARDrone.
6
+ #
7
+ # Derive a class from this class, in order to implement communication
8
+ # with a new type of hardware device.
9
+ class Adaptor
10
+ include Celluloid::IO
11
+
12
+ attr_reader :parent, :port
13
+
14
+ def initialize(params={})
15
+ @parent = params[:parent]
16
+ @port = params[:port]
17
+ @connected = false
18
+ end
19
+
20
+ def connect
21
+ @connected = true
22
+ end
23
+
24
+ def disconnect
25
+ @connected = false
26
+ true
27
+ end
28
+
29
+ def reconnect
30
+ connect unless connected?
31
+ end
32
+
33
+ def connected?
34
+ @connected == true
35
+ end
36
+
37
+ def connect_to
38
+ if port.is_tcp?
39
+ connect_to_tcp
40
+ else
41
+ port.port
42
+ end
43
+ end
44
+
45
+ def connect_to_tcp
46
+ @socket ||= TCPSocket.new(port.host, port.port)
47
+ end
48
+
49
+ def connect_to_udp
50
+ @udp_socket ||= UDPSocket.new
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,32 @@
1
+ require 'artoo/adaptors/adaptor'
2
+
3
+ module Artoo
4
+ module Adaptors
5
+ # Connect to a ARDrone 2.0 (http://ardrone2.parrot.com/)
6
+ class Ardrone < Adaptor
7
+ attr_reader :ardrone
8
+
9
+ def finalize
10
+ if connected?
11
+ ardrone.land
12
+ ardrone.stop
13
+ end
14
+ end
15
+
16
+ def connect
17
+ require 'argus' unless defined?(::Argus)
18
+ @ardrone = Argus::Drone.new(connect_to_udp, port.host, port.port)
19
+ super
20
+ end
21
+
22
+ def disconnect
23
+ ardrone.stop
24
+ super
25
+ end
26
+
27
+ def method_missing(method_name, *arguments, &block)
28
+ ardrone.send(method_name, *arguments, &block)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'artoo/adaptors/adaptor'
2
+
3
+ module Artoo
4
+ module Adaptors
5
+ # Connect to a ARDrone 2.0 (http://ardrone2.parrot.com/) navigation data stream
6
+ class ArdroneNavigation < Adaptor
7
+ attr_reader :ardrone
8
+
9
+ def connect
10
+ require 'argus' unless defined?(::Argus)
11
+ @ardrone = Argus::NavStreamer.new(connect_to_udp, port.host, port.port.to_i)
12
+ @ardrone.start
13
+ super
14
+ end
15
+
16
+ def disconnect
17
+ ardrone.close
18
+ super
19
+ end
20
+
21
+ def method_missing(method_name, *arguments, &block)
22
+ ardrone.send(method_name, *arguments, &block)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require 'artoo/adaptors/adaptor'
2
+
3
+ module Artoo
4
+ module Adaptors
5
+ # Connect to a ARDrone 2.0 (http://ardrone2.parrot.com/) video data stream
6
+ class ArdroneVideo < Adaptor
7
+ attr_reader :ardrone, :video_parser
8
+
9
+ def connect
10
+ require 'argus' unless defined?(::Argus)
11
+ @ardrone = Argus::TcpVideoStreamer.new(connect_to_tcp, port.host, port.port)
12
+ @video_parser = Argus::PaVEParser.new(@ardrone)
13
+ @ardrone.start_stream(connect_to_udp)
14
+ super
15
+ end
16
+
17
+ def disconnect
18
+ ardrone.close
19
+ super
20
+ end
21
+
22
+ def method_missing(method_name, *arguments, &block)
23
+ ardrone.send(method_name, *arguments, &block)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'artoo/adaptors/adaptor'
2
+
3
+ module Artoo
4
+ module Adaptors
5
+ class Firmata < Adaptor
6
+ attr_reader :firmata
7
+
8
+ def connect
9
+ require 'firmata' unless defined?(::Firmata)
10
+ @firmata = ::Firmata::Board.new(connect_to)
11
+ @firmata.connect
12
+ super
13
+ return true
14
+ end
15
+
16
+ def disconnect
17
+ super
18
+ end
19
+
20
+ def method_missing(method_name, *arguments, &block)
21
+ firmata.send(method_name, *arguments, &block)
22
+ end
23
+ end
24
+ end
25
+ end