artoo 0.5.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/.yardopts +1 -1
  4. data/CONTRIBUTORS.md +16 -0
  5. data/Gemfile +10 -9
  6. data/Gemfile.lock +31 -35
  7. data/README.md +110 -19
  8. data/Rakefile +0 -1
  9. data/api/assets/javascripts/artoo/controllers/robot.js.coffee +5 -8
  10. data/api/public/core.js +7 -12
  11. data/api/public/partials/robot-detail.html +1 -1
  12. data/bin/robi +1 -1
  13. data/examples/christmas_roomba.rb +16 -19
  14. data/examples/hello_api_multiple.rb +3 -2
  15. data/examples/notifications.rb +2 -2
  16. data/examples/sphero_messages.rb +9 -3
  17. data/lib/artoo/adaptors/test.rb +28 -0
  18. data/lib/artoo/connection.rb +5 -0
  19. data/lib/artoo/delegator.rb +1 -1
  20. data/lib/artoo/device.rb +13 -0
  21. data/lib/artoo/drivers/counter.rb +28 -0
  22. data/lib/artoo/drivers/pinger.rb +8 -11
  23. data/lib/artoo/drivers/random.rb +27 -0
  24. data/lib/artoo/drivers/test.rb +23 -0
  25. data/lib/artoo/master.rb +4 -2
  26. data/lib/artoo/robot.rb +11 -103
  27. data/lib/artoo/robot_class_methods.rb +147 -0
  28. data/lib/artoo/version.rb +1 -1
  29. data/test/robot_test.rb +3 -3
  30. data/test/test_helper.rb +1 -2
  31. metadata +10 -44
  32. data/bin/sphero.sh +0 -8
  33. data/bin/sphero_linux_bind.sh +0 -25
  34. data/bin/sphero_linux_socat.sh +0 -8
  35. data/examples/sphero2.rb +0 -26
  36. data/lib/artoo/adaptors/ardrone.rb +0 -41
  37. data/lib/artoo/adaptors/ardrone_navigation.rb +0 -33
  38. data/lib/artoo/adaptors/ardrone_video.rb +0 -35
  39. data/lib/artoo/adaptors/firmata.rb +0 -33
  40. data/lib/artoo/adaptors/roomba.rb +0 -51
  41. data/lib/artoo/adaptors/sphero.rb +0 -58
  42. data/lib/artoo/drivers/ardrone.rb +0 -15
  43. data/lib/artoo/drivers/ardrone_navigation.rb +0 -25
  44. data/lib/artoo/drivers/ardrone_video.rb +0 -27
  45. data/lib/artoo/drivers/button.rb +0 -59
  46. data/lib/artoo/drivers/led.rb +0 -48
  47. data/lib/artoo/drivers/motor.rb +0 -69
  48. data/lib/artoo/drivers/pinger2.rb +0 -27
  49. data/lib/artoo/drivers/roomba.rb +0 -179
  50. data/lib/artoo/drivers/servo.rb +0 -59
  51. data/lib/artoo/drivers/sphero.rb +0 -105
  52. data/lib/artoo/drivers/wiichuck.rb +0 -61
  53. data/lib/artoo/drivers/wiiclassic.rb +0 -139
  54. data/lib/artoo/drivers/wiidriver.rb +0 -102
  55. data/test/adaptors/ardrone_test.rb +0 -24
  56. data/test/adaptors/firmata_test.rb +0 -25
  57. data/test/adaptors/sphero_test.rb +0 -24
  58. data/test/drivers/ardrone_navigation_test.rb +0 -11
  59. data/test/drivers/ardrone_test.rb +0 -11
  60. data/test/drivers/ardrone_video_test.rb +0 -11
  61. data/test/drivers/led_test.rb +0 -56
  62. data/test/drivers/motor_test.rb +0 -40
  63. data/test/drivers/roomba_test.rb +0 -87
  64. data/test/drivers/servo_test.rb +0 -45
  65. data/test/drivers/sphero_test.rb +0 -54
  66. data/test/drivers/wiichuck_test.rb +0 -11
  67. data/test/drivers/wiiclassic_test.rb +0 -11
  68. data/test/drivers/wiidriver_test.rb +0 -54
@@ -1,102 +0,0 @@
1
- require 'artoo/drivers/driver'
2
-
3
- module Artoo
4
- module Drivers
5
- # Wii-based controller shared driver behaviors for Firmata
6
- class Wiidriver < Driver
7
- attr_reader :joystick, :data
8
-
9
- def address; 0x52; end
10
-
11
- # Create new Wiidriver
12
- def initialize(params={})
13
- @joystick = get_defaults
14
- @data = {}
15
- super
16
- end
17
-
18
- # Starts drives and required connections
19
- def start_driver
20
- begin
21
- connection.i2c_config(0)
22
- every(interval) do
23
- connection.i2c_write_request(address, 0x40, 0x00)
24
- connection.i2c_write_request(address, 0x00, 0x00)
25
- connection.i2c_read_request(address, 6)
26
-
27
- connection.read_and_process
28
- handle_events
29
- end
30
-
31
- super
32
- rescue Exception => e
33
- Logger.error "Error starting wii driver!"
34
- Logger.error e.message
35
- Logger.error e.backtrace.inspect
36
- end
37
- end
38
-
39
- # Get and update data
40
- def update(value)
41
- if encrypted?(value)
42
- Logger.error "Encrypted bytes from wii device!"
43
- raise "Encrypted bytes from wii device!"
44
- end
45
-
46
- @data = parse(value)
47
- end
48
-
49
- def handle_events
50
- while i = find_event("i2c_reply") do
51
- update(events.slice!(i).data.first)
52
- end
53
- end
54
-
55
- protected
56
-
57
- def find_event(name)
58
- events.index {|e| e.name == name}
59
- end
60
-
61
- def events
62
- connection.async_events
63
- end
64
-
65
- def get_defaults
66
- {}
67
- end
68
-
69
- def parse
70
- {}
71
- end
72
-
73
- def set_joystick_default_value(joystick_axis, default_value)
74
- joystick[joystick_axis] = default_value if joystick[joystick_axis].nil?
75
- end
76
-
77
- def calculate_joystick_value(axis, origin)
78
- data[axis] - joystick[origin]
79
- end
80
-
81
- def encrypted?(value)
82
- [[0, 1], [2, 3], [4, 5]].all? {|a| get_value(value, a[0]) == get_value(value, a[1]) }
83
- end
84
-
85
- def decode(x)
86
- return ( x ^ 0x17 ) + 0x17
87
- end
88
-
89
- def decode_value(value, index)
90
- decode(get_value(value, index))
91
- end
92
-
93
- def get_value(value, index)
94
- value[:data][index]
95
- end
96
-
97
- def generate_bool(value)
98
- value == 0 ? true : false
99
- end
100
- end
101
- end
102
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/adaptors/ardrone'
3
- require 'argus'
4
-
5
- describe Artoo::Adaptors::Ardrone do
6
- before do
7
- @port = Artoo::Port.new('/dev/awesome')
8
- @adaptor = Artoo::Adaptors::Ardrone.new(:port => @port)
9
- @ardrone = mock('ardrone')
10
- Argus::Drone.stubs(:new).returns(@ardrone)
11
- end
12
-
13
- it 'Artoo::Adaptors::Ardrone#connect' do
14
- @adaptor.connect.must_equal true
15
- end
16
-
17
- it 'Artoo::Adaptors::Ardrone#disconnect' do
18
- @adaptor.connect
19
-
20
- @ardrone.expects(:stop)
21
- @adaptor.disconnect
22
- @adaptor.connected?.must_equal false
23
- end
24
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/adaptors/firmata'
3
- require 'firmata'
4
-
5
- describe Artoo::Adaptors::Firmata do
6
- before do
7
- @port = Artoo::Port.new('/dev/awesome')
8
- @adaptor = Artoo::Adaptors::Firmata.new(:port => @port)
9
- @firmata = mock('firmata')
10
- Firmata::Board.stubs(:new).returns(@firmata)
11
- end
12
-
13
- it 'Artoo::Adaptors::Firmata#connect' do
14
- @firmata.expects(:connect)
15
- @adaptor.connect.must_equal true
16
- end
17
-
18
- it 'Artoo::Adaptors::Firmata#disconnect' do
19
- @firmata.stubs(:connect)
20
- @adaptor.connect
21
- @adaptor.disconnect
22
-
23
- @adaptor.connected?.must_equal false
24
- end
25
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/adaptors/sphero'
3
- require 'sphero'
4
-
5
- describe Artoo::Adaptors::Sphero do
6
- before do
7
- @port = Artoo::Port.new('/dev/awesome')
8
- @adaptor = Artoo::Adaptors::Sphero.new(:port => @port)
9
- @sphero = mock('sphero')
10
- Sphero.stubs(:new).returns(@sphero)
11
- end
12
-
13
- it 'Artoo::Adaptors::Sphero#connect' do
14
- @adaptor.connect.must_equal true
15
- end
16
-
17
- it 'Artoo::Adaptors::Sphero#disconnect' do
18
- @adaptor.connect
19
-
20
- @sphero.expects(:close)
21
- @adaptor.disconnect
22
- @adaptor.connected?.must_equal false
23
- end
24
- end
@@ -1,11 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/ardrone_navigation'
3
-
4
- describe Artoo::Drivers::ArdroneNavigation do
5
- before do
6
- @device = mock('device')
7
- @driver = Artoo::Drivers::ArdroneNavigation.new(:parent => @device)
8
- end
9
-
10
- it 'must do things'
11
- end
@@ -1,11 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/ardrone'
3
-
4
- describe Artoo::Drivers::Ardrone do
5
- before do
6
- @device = mock('device')
7
- @driver = Artoo::Drivers::Ardrone.new(:parent => @device)
8
- end
9
-
10
- it 'must do things'
11
- end
@@ -1,11 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/ardrone_video'
3
-
4
- describe Artoo::Drivers::ArdroneVideo do
5
- before do
6
- @device = mock('device')
7
- @driver = Artoo::Drivers::ArdroneVideo.new(:parent => @device)
8
- end
9
-
10
- it 'must do things'
11
- end
@@ -1,56 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/led'
3
-
4
- describe Artoo::Drivers::Led do
5
- before do
6
- @device = mock('device')
7
- @pin = 13
8
- @device.stubs(:pin).returns(@pin)
9
- @led = Artoo::Drivers::Led.new(:parent => @device)
10
- @connection = mock('connection')
11
- @device.stubs(:connection).returns(@connection)
12
- end
13
-
14
- it 'Led#is_on? default' do
15
- @led.is_on?.must_equal false
16
- end
17
-
18
- it 'Led#is_off? default' do
19
- @led.is_off?.must_equal true
20
- end
21
-
22
- it 'Led#on' do
23
- @connection.expects(:set_pin_mode).with(@pin, Firmata::Board::OUTPUT)
24
- @connection.expects(:digital_write).with(@pin, Firmata::Board::HIGH)
25
- @led.on
26
- @led.is_on?.must_equal true
27
- end
28
-
29
- it 'Led#off' do
30
- @connection.expects(:set_pin_mode).with(@pin, Firmata::Board::OUTPUT)
31
- @connection.expects(:digital_write).with(@pin, Firmata::Board::LOW)
32
- @led.off
33
- @led.is_off?.must_equal true
34
- end
35
-
36
- it 'Led#toggle' do
37
- @connection.stubs(:set_pin_mode)
38
- @connection.stubs(:digital_write)
39
- @led.is_off?.must_equal true
40
- @led.toggle
41
- @led.is_on?.must_equal true
42
- @led.toggle
43
- @led.is_off?.must_equal true
44
- end
45
-
46
- it 'Led#brightness' do
47
- val = 100
48
- @connection.expects(:set_pin_mode).with(@pin, Firmata::Board::PWM)
49
- @connection.expects(:analog_write).with(@pin, val)
50
- @led.brightness(val)
51
- end
52
-
53
- it 'Led#commands' do
54
- @led.commands.must_include :toggle
55
- end
56
- end
@@ -1,40 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/motor'
3
-
4
- describe Artoo::Drivers::Motor do
5
- before do
6
- @device = mock('device')
7
- @device.stubs(:pin).returns([2, 3, 4])
8
- @motor = Artoo::Drivers::Motor.new(:parent => @device)
9
-
10
- @connection = mock('connection')
11
- @connection.stubs(:set_pin_mode)
12
- @connection.stubs(:analog_write)
13
- @connection.stubs(:digital_write)
14
- @device.stubs(:connection).returns(@connection)
15
- end
16
-
17
- it 'Motor#speed must be valid' do
18
- invalid_speed = lambda { @motor2 = Artoo::Drivers::Motor.new(:parent => @device); @motor2.speed("ads") }
19
- invalid_speed.must_raise RuntimeError
20
- error = invalid_speed.call rescue $!
21
- error.message.must_equal 'Motor speed must be an integer between 0-255'
22
- end
23
-
24
- it 'Motor#forward' do
25
- @motor.wrapped_object.expects(:set_legs)
26
- @motor.forward(100)
27
- @motor.current_speed.must_equal 100
28
- end
29
-
30
- it 'Motor#backward' do
31
- @motor.wrapped_object.expects(:set_legs)
32
- @motor.backward(100)
33
- @motor.current_speed.must_equal 100
34
- end
35
-
36
- it 'Motor#stop' do
37
- @motor.stop
38
- @motor.current_speed.must_equal 0
39
- end
40
- end
@@ -1,87 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/roomba'
3
-
4
- describe Artoo::Drivers::Roomba do
5
- before do
6
- @connection = mock('connection')
7
- @device = mock('device')
8
- @device.stubs(:connection).returns(@connection)
9
- @roomba = Artoo::Drivers::Roomba.new(:parent => @device)
10
- @roomba.stubs(:sleep)
11
- @roomba_proxy = @roomba.wrapped_object
12
- end
13
-
14
- it 'Roomba#start' do
15
- @connection.expects(:send_bytes).with(Artoo::Drivers::Roomba::Mode::START)
16
- @roomba.start
17
- end
18
-
19
- it 'Roomba#safe_mode' do
20
- @roomba.stubs(:start)
21
- @connection.expects(:send_bytes).with(Artoo::Drivers::Roomba::Mode::SAFE)
22
- @roomba.safe_mode
23
- end
24
-
25
- it 'Roomba#full_mode' do
26
- @roomba.stubs(:start)
27
- @connection.expects(:send_bytes).with(Artoo::Drivers::Roomba::Mode::FULL)
28
- @roomba.full_mode
29
- end
30
-
31
- it 'Roomba#forward' do
32
- @roomba_proxy.expects(:drive).with(250, Artoo::Drivers::Roomba::Direction::STRAIGHT, 10)
33
- @roomba_proxy.expects(:stop)
34
- @roomba.forward(10, 250)
35
- end
36
-
37
- it 'Roomba#stop' do
38
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::ZERO, Artoo::Drivers::Roomba::Direction::STRAIGHT)
39
- @roomba.stop
40
- end
41
-
42
- it 'Roomba#fast_forward' do
43
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::MAX, Artoo::Drivers::Roomba::Direction::STRAIGHT, 10)
44
- @roomba_proxy.expects(:stop)
45
- @roomba.fast_forward(10)
46
- end
47
-
48
- it 'Roomba#backwards' do
49
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::NEG, Artoo::Drivers::Roomba::Direction::STRAIGHT, 10)
50
- @roomba_proxy.expects(:stop)
51
- @roomba.backwards(10)
52
- end
53
-
54
- it 'Roomba#turn_left' do
55
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::COUNTERCLOCKWISE, 10)
56
- @roomba_proxy.expects(:stop)
57
- @roomba.turn_left(10)
58
- end
59
-
60
- it 'Roomba#nudge_left' do
61
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::COUNTERCLOCKWISE, 0.25)
62
- @roomba_proxy.expects(:stop)
63
- @roomba.nudge_left
64
- end
65
-
66
- it 'Roomba#turn_right' do
67
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::CLOCKWISE, 10)
68
- @roomba_proxy.expects(:stop)
69
- @roomba.turn_right(10)
70
- end
71
-
72
- it 'Roomba#nudge_right' do
73
- @roomba_proxy.expects(:drive).with(Artoo::Drivers::Roomba::Speed::SLOW, Artoo::Drivers::Roomba::Direction::CLOCKWISE, 0.25)
74
- @roomba_proxy.expects(:stop)
75
- @roomba.nudge_right
76
- end
77
-
78
- it 'Roomba#play' do
79
- @connection.expects(:send_bytes).with([Artoo::Drivers::Roomba::Song::PLAY, 0])
80
- @roomba.play(0)
81
- end
82
-
83
- it 'Roomba#song' do
84
- @connection.expects(:send_bytes).with([Artoo::Drivers::Roomba::Song::SONG, 0, 3, Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER, Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER, Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::HALF])
85
- @roomba.song([[Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER], [Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::QUARTER], [Artoo::Drivers::Roomba::Note::B, Artoo::Drivers::Roomba::Note::HALF]], 0)
86
- end
87
- end
@@ -1,45 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
- require 'artoo/drivers/servo'
3
-
4
- describe Artoo::Drivers::Servo do
5
- before do
6
- @device = mock('device')
7
- @device.stubs(:pin).returns(3)
8
- @servo = Artoo::Drivers::Servo.new(:parent => @device)
9
-
10
- @connection = mock('connection')
11
- @connection.stubs(:set_pin_mode)
12
- @connection.stubs(:analog_write)
13
- # @connection.stubs(:digital_write)
14
- @device.stubs(:connection).returns(@connection)
15
- end
16
-
17
- it "Servo#angle_to_span" do
18
- @servo.angle_to_span(0).must_equal 0
19
- @servo.angle_to_span(30).must_equal 42
20
- @servo.angle_to_span(90).must_equal 127
21
- @servo.angle_to_span(180).must_equal 255
22
- end
23
-
24
- it 'Servo#move must be valid' do
25
- invalid_angle = lambda { @servo2 = Artoo::Drivers::Servo.new(:parent => @device); @servo2.move(360) }
26
- invalid_angle.must_raise RuntimeError
27
- error = invalid_angle.call rescue $!
28
- error.message.must_equal 'Servo angle must be an integer between 0-180'
29
- end
30
-
31
- it 'Servo#min' do
32
- @servo.min
33
- @servo.current_angle.must_equal 0
34
- end
35
-
36
- it 'Servo#center' do
37
- @servo.center
38
- @servo.current_angle.must_equal 90
39
- end
40
-
41
- it 'Servo#max' do
42
- @servo.max
43
- @servo.current_angle.must_equal 180
44
- end
45
- end