artoo-arduino 1.0.4 → 1.0.5.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 263138985ee324070ab6a1cee971d216d3c803f8
4
- data.tar.gz: 67bd79ab8c8532f535f1b7570c23d0764918f88d
3
+ metadata.gz: ed4e1ede3ad4610f0d80b300a09561e4690caadc
4
+ data.tar.gz: 8ae924e30cea83c570ff06a022bfead5d2f4800a
5
5
  SHA512:
6
- metadata.gz: bbfa986c0bca2d94bfac331e15cf9cfcd92001b66f9f959cf3d5325278ea5ed88ce161e321532527c336c64413d923cf08881e76fb326c6ca45e050bae5abb1b
7
- data.tar.gz: 3014802fc3a1604c06c65745b609f86e60bb5eddf7a21d3c08b77319707a672f320df264821bc80a98057cbcd62c63b02ef1f310bebd41ef5f6205b8ea4302f7
6
+ metadata.gz: fedd0abf925bac7214ed62d2659bc9ba867698214685b688138f5755a160c6bc6922d84d583113768ee4a20d5b81dc3b1d09f2ea9e2baa566d44495e8a27d41d
7
+ data.tar.gz: 8eeff60911d1541fa1d7f221a36d063d60d1afd4c28613360f85e1726ec5977db4585a093b9aafa9421b88e49335b1a279cc67378da2c9880b6ca23f8ed9de9c
data/Gemfile.lock CHANGED
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo-arduino (1.0.4)
5
- artoo (~> 1.0.0)
4
+ artoo-arduino (1.0.5.pre)
5
+ artoo (~> 1.1.0.pre)
6
6
  hybridgroup-firmata (~> 0.4.5)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- artoo (1.0.0)
12
- celluloid (~> 0.14.1)
13
- celluloid-io (~> 0.14.1)
11
+ artoo (1.1.0.pre)
12
+ celluloid (~> 0.15.0.pre2)
13
+ celluloid-io (~> 0.15.0.pre2)
14
14
  multi_json (~> 1.6)
15
15
  pry (~> 0.9)
16
16
  rake (~> 10.0)
17
17
  reel (~> 0.4.0.pre)
18
18
  thor (~> 0.18.1)
19
- celluloid (0.14.1)
19
+ celluloid (0.15.0.pre2)
20
20
  timers (>= 1.0.0)
21
- celluloid-io (0.14.1)
22
- celluloid (>= 0.14.1)
23
- nio4r (>= 0.4.5)
21
+ celluloid-io (0.15.0.pre2)
22
+ celluloid (>= 0.15.0.pre)
23
+ nio4r (>= 0.5.0)
24
24
  certified (0.1.1)
25
25
  coderay (1.0.9)
26
26
  event_emitter (0.2.5)
data/README.md CHANGED
@@ -32,6 +32,17 @@ work do
32
32
  end
33
33
  ```
34
34
 
35
+ ## Devices supported
36
+
37
+ The following hardware devices have driver support:
38
+ - Button
39
+ - LED
40
+ - Maxbotix ultrasonic range finder
41
+ - Motor (DC)
42
+ - Servo
43
+ - Wiichuck controller (via i2c)
44
+ - Wiiclassic controller (via i2c)
45
+
35
46
  ## Connecting to Arduino
36
47
 
37
48
  ### OSX
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency 'artoo', '~> 1.0.0'
22
+ s.add_runtime_dependency 'artoo', '~> 1.1.0.pre'
23
23
  s.add_runtime_dependency 'hybridgroup-firmata', '~> 0.4.5'
24
24
  s.add_development_dependency 'minitest', '~> 5.0'
25
25
  s.add_development_dependency 'minitest-happy'
@@ -3,8 +3,8 @@ require 'artoo'
3
3
  # Circuit and schematic here: http://arduino.cc/en/Tutorial/Blink
4
4
 
5
5
  #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
6
- connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
7
- device :board
6
+ connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:4567'
7
+ device :board, :driver => :firmata_board
8
8
  device :led, :driver => :led, :pin => 13
9
9
 
10
10
  work do
@@ -4,7 +4,7 @@ require 'artoo'
4
4
 
5
5
  #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
6
6
  connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
7
- device :board
7
+ device :board, :driver => :firmata_board
8
8
  device :led, :driver => :led, :pin => 13
9
9
 
10
10
  work do
@@ -3,22 +3,26 @@ require 'artoo'
3
3
  #Circuit's breadboard layout here: http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/breadboard-layout
4
4
 
5
5
  #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
6
- connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
7
- device :board
8
- device :motor, :driver => :motor, :pin => [nil, nil, 3] # Needs a PWM pin
6
+ connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:4567'
7
+ device :board, :driver => :firmata_board
8
+ device :motor, :driver => :motor, :speed_pin => 3 # Use a PWM pin
9
9
 
10
10
  work do
11
- board.connect
12
11
  puts "Firmware name: #{board.firmware_name}"
13
12
  puts "Firmata version: #{board.version}"
13
+ puts "Stopping motor..."
14
+ motor.min # same as 'motor.stop' or 'motor.speed(0)'
15
+ sleep 3
16
+ puts "Setting to maximum speed..."
17
+ motor.max # same as 'motor.start'
18
+ sleep 3
14
19
 
15
- motor.stop
16
20
  speed = 0
17
21
  step = 50
18
22
 
19
- every 4.seconds do
20
- puts "Current speed: #{speed}"
21
- motor.speed speed
23
+ every 3.seconds do
24
+ motor.speed(speed)
25
+ puts "Current speed: #{motor.current_speed}"
22
26
  speed += step
23
27
  if [0, 250].include?(speed)
24
28
  step = -step
@@ -0,0 +1,38 @@
1
+ require 'artoo'
2
+
3
+ #Circuit's breadboard layout for the L293D: http://www.electrojoystick.com/tutorial/?p=759
4
+ #For the L239DNE: http://bit.ly/14QdjD5
5
+
6
+ #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
7
+ connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
8
+ device :board, :driver => :firmata_board
9
+ device :motor, :driver => :motor,
10
+ :forward_pin => 4, # Digital or PWM pin
11
+ :backward_pin => 2, # Digital or PWM pin
12
+ :speed_pin => 9 # PWM pin only
13
+
14
+ work do
15
+ puts "Firmware name: #{board.firmware_name}"
16
+ puts "Firmata version: #{board.version}"
17
+ puts "Stopping motor..."
18
+ motor.stop
19
+ sleep 2
20
+
21
+ loop do
22
+ motor.forward # if no speed set, spins at max speed
23
+ puts "Going forward, Speed: #{motor.current_speed}"
24
+ sleep 3
25
+ motor.forward 180
26
+ puts "Going forward, Speed: #{motor.current_speed}"
27
+ sleep 3
28
+ puts "Stopping..."
29
+ motor.stop
30
+ sleep 2
31
+ motor.backward(150) # spins at speed 150
32
+ puts "Going backward, Speed: #{motor.current_speed}"
33
+ sleep 3
34
+ motor.backward(255)
35
+ puts "Going backward, Speed: #{motor.current_speed}"
36
+ sleep 3
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ require 'artoo'
2
+
3
+ #Circuit's breadboard layout here: http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/breadboard-layout
4
+
5
+ #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
6
+ connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
7
+ device :board, :driver => :firmata_board
8
+ device :motor, :driver => :motor, :switch_pin => 3 # Use a digital or PWM pin
9
+
10
+ work do
11
+ puts "Firmware name: #{board.firmware_name}"
12
+ puts "Firmata version: #{board.version}"
13
+ puts "Stopping motor..." #just in case
14
+ motor.stop
15
+ sleep 3
16
+
17
+ every 3.seconds do
18
+ motor.toggle
19
+ puts "Motor is #{motor.on? ? 'on' : 'off'}"
20
+ end
21
+
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'artoo'
2
+
3
+ #Circuit's breadboard layout for the L293D here: http://www.electrojoystick.com/tutorial/?p=759
4
+ #For the L239DNE: http://bit.ly/14QdjD5,
5
+ # L293DNE's pin 1 should go to 5V instead of to Arduino's pin 9
6
+
7
+ #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
8
+ connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
9
+ device :board, :driver => :firmata_board
10
+ device :motor, :driver => :motor, :forward_pin => 4, :backward_pin => 2
11
+
12
+ work do
13
+ puts "Firmware name: #{board.firmware_name}"
14
+ puts "Firmata version: #{board.version}"
15
+ puts "Stopping motor..."
16
+ motor.stop
17
+ sleep 1
18
+
19
+ loop do
20
+ puts "Going forward..."
21
+ motor.forward
22
+ sleep 3
23
+ puts "Stopping..."
24
+ motor.stop
25
+ sleep 2
26
+ puts "Going backward..."
27
+ motor.backward
28
+ sleep 3
29
+ end
30
+
31
+ end
@@ -4,7 +4,7 @@ require 'artoo'
4
4
 
5
5
  #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
6
6
  connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
7
- device :board
7
+ device :board, :driver => :firmata_board
8
8
  device :led, :driver => :led, :pin => 3
9
9
 
10
10
  brightness = 0
@@ -0,0 +1,21 @@
1
+ require 'artoo'
2
+
3
+ # Circuit and schematic here: http://www.electrojoystick.com/tutorial/?page_id=285
4
+
5
+ #connection :firmata, :adaptor => :firmata, :port => '/dev/ttyACM0'
6
+ connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:4567'
7
+ device :sonar, :driver => :maxbotix, :pin => 14, :interval => 0.5
8
+ device :board, :driver => :firmata_board
9
+
10
+ work do
11
+ on sonar, :range => :sonar_reading
12
+ puts "Firmware name: #{board.firmware_name}"
13
+ puts "Firmata version: #{board.version}"
14
+ puts "Analog pins: #{board.analog_pins}"
15
+
16
+ puts "starting sonar..."
17
+ end
18
+
19
+ def sonar_reading(*args)
20
+ puts args
21
+ end
@@ -9,7 +9,7 @@ forward = true
9
9
 
10
10
  #connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
11
11
  connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
12
- device :board
12
+ device :board, :driver => :firmata_board
13
13
  device :motor, :driver => :motor, :pin => [leg1_pin, leg2_pin, speed_pin]
14
14
 
15
15
  work do
@@ -0,0 +1,10 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # Board driver behaviors for Firmata
6
+ class FirmataBoard < Driver
7
+ COMMANDS = [:firmware_name, :version, :connect].freeze
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,67 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # Maxbotix ultrasonic range finder driver behaviors for Firmata
6
+ class Maxbotix < Driver
7
+ attr_accessor :last_reading
8
+
9
+ COMMANDS = [:range].freeze
10
+
11
+ def initialize(params={})
12
+ @last_reading = 0.0
13
+ super
14
+ end
15
+
16
+ # @return [float] last range reading in inches
17
+ def range
18
+ return (( 254.0 / 1024.0 ) * 2.0 * last_reading).to_f
19
+ end
20
+
21
+ # @return [float] last range reading in cm
22
+ def range_cm
23
+ return ((last_reading / 2.0) * 2.54).to_f
24
+ end
25
+
26
+ # Sets values to read from ultrasonic range finder
27
+ # and starts driver
28
+ def start_driver
29
+ connection.set_pin_mode(pin, Firmata::PinModes::ANALOG)
30
+ connection.toggle_pin_reporting(pin)
31
+
32
+ every(interval) do
33
+ connection.read_and_process
34
+ handle_events
35
+ end
36
+
37
+ super
38
+ end
39
+
40
+ def handle_events
41
+ while i = find_event("analog_read_#{analog_pin}") do
42
+ event = events.slice!(i)
43
+ update(event.data.first) if !event.nil?
44
+ end
45
+ end
46
+
47
+ def find_event(name)
48
+ events.index {|e| e.name == name.to_sym}
49
+ end
50
+
51
+ def events
52
+ connection.async_events
53
+ end
54
+
55
+ # Publishes events according to the ultrasonic rangefinder value
56
+ def update(value)
57
+ @last_reading = value
58
+ publish(event_topic_name("update"), "range", range)
59
+ publish(event_topic_name("range"), range)
60
+ end
61
+
62
+ def analog_pin
63
+ pin - 14
64
+ end
65
+ end
66
+ end
67
+ end
@@ -2,21 +2,39 @@ require 'artoo/drivers/driver'
2
2
 
3
3
  module Artoo
4
4
  module Drivers
5
- # L293 or other H-bridge style motor driver behaviors for Firmata
6
5
  class Motor < Driver
7
- COMMANDS = [:forward, :backward, :stop, :speed, :current_speed].freeze
8
6
 
9
- attr_reader :leg1_pin, :leg2_pin, :speed_pin, :current_speed
7
+ COMMANDS = [:stop, :start, :on?, :off?, :toggle, :speed, :min, :max, :forward, :backward, :current_speed].freeze
8
+
9
+ attr_reader :speed_pin, :switch_pin, :current_speed
10
10
 
11
- # Create new Motor
12
11
  def initialize(params={})
13
12
  super
13
+
14
+ additional_params = params[:additional_params]
15
+ @speed_pin = additional_params[:speed_pin]
16
+ @speed_pin = additional_params[:switch_pin] if additional_params[:switch_pin]
17
+
18
+ @forward_pin = additional_params[:forward_pin]
19
+ @backward_pin = additional_params[:backward_pin]
14
20
 
15
- raise "Invalid pins, please pass an array in format [leg1, leg2, speed]" unless (pin && pin.is_a?(Array) && pin.size == 3)
16
- @leg1_pin = pin[0]
17
- @leg2_pin = pin[1]
18
- @speed_pin = pin[2]
21
+ @current_state = 0
19
22
  @current_speed = 0
23
+
24
+ # digital: just to switch the motor on or off, no speed control
25
+ # analog: speed control
26
+ @current_mode = :digital
27
+
28
+ @current_direction = :forward
29
+
30
+ @@modules_to_include = modules_to_include
31
+
32
+ class << self
33
+ @@modules_to_include.each do |m|
34
+ include m
35
+ end if @@modules_to_include
36
+ end
37
+
20
38
  end
21
39
 
22
40
  # Starts connection to read and process and driver
@@ -28,42 +46,134 @@ module Artoo
28
46
  super
29
47
  end
30
48
 
31
- # Sets movement forward
32
- # @param [Integer] s speed
33
- def forward(s)
34
- set_legs(Firmata::PinLevels::LOW, Firmata::PinLevels::HIGH)
35
- speed(s)
49
+ def digital?
50
+ @current_mode == :digital
36
51
  end
37
-
38
- # Sets movement backward
39
- # @param [Integer] s speed
40
- def backward(s)
41
- set_legs(Firmata::PinLevels::HIGH, Firmata::PinLevels::LOW)
42
- speed(s)
52
+
53
+ def analog?
54
+ @current_mode == :analog
43
55
  end
44
56
 
45
- # Stops
46
57
  def stop
47
- speed(0)
58
+ if digital?
59
+ change_state(Firmata::PinLevels::LOW)
60
+ else
61
+ speed(0)
62
+ end
63
+ end
64
+
65
+ def start
66
+ if digital?
67
+ change_state(Firmata::PinLevels::HIGH)
68
+ else
69
+ speed(@current_speed.zero? ? 255 : @current_speed)
70
+ end
71
+ end
72
+
73
+ def min
74
+ stop
75
+ end
76
+
77
+ def max
78
+ speed(255)
79
+ end
80
+
81
+ def on?
82
+ if digital?
83
+ @current_state == Firmata::PinLevels::HIGH
84
+ else
85
+ @current_speed > 0
86
+ end
87
+ end
88
+
89
+ def off?
90
+ !on?
91
+ end
92
+
93
+ def toggle
94
+ on? ? stop : start
95
+ end
96
+
97
+ def change_state(state)
98
+ @current_state = state
99
+ @current_speed = state.zero? ? 0 : 255
100
+ connection.set_pin_mode(@speed_pin, Firmata::PinModes::OUTPUT)
101
+ connection.digital_write(@speed_pin, state)
48
102
  end
49
103
 
50
104
  # Set motor speed
51
- # @param [Integer] s speed (must be an integer between 0-255)
52
- def speed(s)
53
- raise "Motor speed must be an integer between 0-255" unless (s.is_a?(Numeric) && s >= 0 && s <= 255)
54
- @current_speed = s
105
+ # @param [Integer] value (must be an integer between 0-255)
106
+ def speed(value)
107
+ @current_mode = :analog
108
+ raise "Motor speed must be an integer between 0-255" unless (value.is_a?(Numeric) && value >= 0 && value <= 255)
109
+ @current_speed = value
55
110
  connection.set_pin_mode(speed_pin, Firmata::PinModes::PWM)
56
- connection.analog_write(speed_pin, s)
111
+ connection.analog_write(speed_pin, value)
112
+ end
113
+
114
+ private
115
+ def modules_to_include
116
+ if @forward_pin and @backward_pin
117
+ [BidirectionalWithForwardBackwardPins]
118
+ end
119
+ end
120
+ end
121
+
122
+ module BidirectionalWithForwardBackwardPins
123
+
124
+ # Sets movement forward
125
+ # @param [Integer] speed
126
+ def forward(speed = nil)
127
+ direction(:forward)
128
+ speed ? self.speed(speed) : start
129
+ end
130
+
131
+ # Sets movement backward
132
+ # @param [Integer] speed
133
+ def backward(speed = nil)
134
+ direction(:backward)
135
+ speed ? self.speed(speed) : start
136
+ end
137
+
138
+ def forward?
139
+ @current_direction == :forward
140
+ end
141
+
142
+ def backward?
143
+ (not forward?)
57
144
  end
58
145
 
59
146
  private
147
+ def change_state(state)
148
+ @current_state = state
149
+ @current_speed = state.zero? ? 0 : 255
150
+ if state == Firmata::PinLevels::HIGH
151
+ direction(@current_direction)
152
+ speed(@current_speed) if speed_pin
153
+ elsif state == Firmata::PinLevels::LOW
154
+ direction(:none)
155
+ end
156
+ end
60
157
 
61
- def set_legs(l1, l2)
62
- connection.set_pin_mode(leg1_pin, Firmata::PinModes::OUTPUT)
63
- connection.digital_write(leg1_pin, l1)
64
- connection.set_pin_mode(leg2_pin, Firmata::PinModes::OUTPUT)
65
- connection.digital_write(leg2_pin, l2)
158
+ def direction(direction)
159
+ @current_direction = direction
160
+ case direction
161
+ when :forward
162
+ forward_pin_level = Firmata::PinLevels::HIGH
163
+ backward_pin_level = Firmata::PinLevels::LOW
164
+ when :backward
165
+ forward_pin_level = Firmata::PinLevels::LOW
166
+ backward_pin_level = Firmata::PinLevels::HIGH
167
+ when :none
168
+ forward_pin_level = Firmata::PinLevels::LOW
169
+ backward_pin_level = Firmata::PinLevels::LOW
170
+ end
171
+ connection.set_pin_mode(@forward_pin, Firmata::PinModes::OUTPUT)
172
+ connection.digital_write(@forward_pin, forward_pin_level)
173
+ connection.set_pin_mode(@backward_pin, Firmata::PinModes::OUTPUT)
174
+ connection.digital_write(@backward_pin, backward_pin_level)
66
175
  end
176
+
67
177
  end
68
178
  end
69
179
  end
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  module Arduino
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.5.pre'
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/drivers/firmata_board'
3
+
4
+ describe Artoo::Drivers::FirmataBoard do
5
+ before do
6
+ @device = mock('device')
7
+ @board = Artoo::Drivers::FirmataBoard.new(:parent => @device)
8
+ @connection = mock('connection')
9
+ @device.stubs(:connection).returns(@connection)
10
+ end
11
+
12
+ it 'FirmataBoard#firmware_name' do
13
+ @connection.expects(:firmware_name).returns("awesomenessware")
14
+ @board.firmware_name.must_equal "awesomenessware"
15
+ end
16
+
17
+ it 'FirmataBoard#version' do
18
+ @connection.expects(:version).returns("1.2.3")
19
+ @board.version.must_equal "1.2.3"
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
+ require 'artoo/drivers/maxbotix'
3
+
4
+ describe Artoo::Drivers::Maxbotix do
5
+ before do
6
+ @device = mock('device')
7
+ @pin = 0
8
+ @device.stubs(:pin).returns(@pin)
9
+ @maxbotix = Artoo::Drivers::Maxbotix.new(:parent => @device)
10
+ @connection = mock('connection')
11
+ @device.stubs(:connection).returns(@connection)
12
+ end
13
+
14
+ describe '#range' do
15
+ it 'must have initial value' do
16
+ @maxbotix.range.must_equal 0.0
17
+ end
18
+
19
+ it 'must adjust based on last_reading' do
20
+ @maxbotix.last_reading = 13.5
21
+ @maxbotix.range.must_equal 6.697265625
22
+ @maxbotix.range_cm.must_equal 17.145
23
+ end
24
+ end
25
+ end
@@ -2,39 +2,211 @@ require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
2
  require 'artoo/drivers/motor'
3
3
 
4
4
  describe Artoo::Drivers::Motor do
5
+
6
+ let(:connection) { mock('connection') }
7
+
5
8
  before do
6
9
  @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)
10
+ connection.stubs(:set_pin_mode)
11
+ connection.stubs(:analog_write)
12
+ connection.stubs(:digital_write)
13
+ @device.stubs(:connection).returns(connection)
15
14
  end
16
15
 
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
16
+ describe 'mode predicate methods' do
17
+
18
+ let(:motor) { Artoo::Drivers::Motor.new(:parent => @device, :additional_params => {}) }
19
+
20
+ it '#digital?' do
21
+ motor.digital?.must_equal true #initial state
22
+ motor.speed(1)
23
+ motor.digital?.must_equal false
24
+ end
25
+
26
+ it '#analog?' do
27
+ motor.analog?.must_equal false
28
+ motor.speed(1)
29
+ motor.analog?.must_equal true
30
+ end
23
31
 
24
- it 'Motor#forward' do
25
- @motor.wrapped_object.expects(:set_legs)
26
- @motor.forward(100)
27
- @motor.current_speed.must_equal 100
28
32
  end
29
33
 
30
- it 'Motor#backward' do
31
- @motor.wrapped_object.expects(:set_legs)
32
- @motor.backward(100)
33
- @motor.current_speed.must_equal 100
34
+ describe 'when unidirectional' do
35
+
36
+ describe 'when switching states (digital)' do
37
+
38
+ let(:motor) { Artoo::Drivers::Motor.new(:parent => @device, :additional_params => {switch_pin: 1}) }
39
+
40
+ it '#start' do
41
+ motor.start
42
+ motor.on?.must_equal true
43
+ end
44
+
45
+ it '#stop' do
46
+ motor.stop
47
+ motor.off?.must_equal true
48
+ end
49
+
50
+ it '#max' do
51
+ motor.expects(:speed).with(255)
52
+ motor.max
53
+ end
54
+
55
+ it '#min' do
56
+ motor.min
57
+ end
58
+
59
+ describe '#toggle' do
60
+ it 'toggles to on when off' do
61
+ motor.start
62
+ motor.toggle
63
+ motor.off?.must_equal true
64
+ end
65
+
66
+ it 'toggles to off when on' do
67
+ motor.stop
68
+ motor.toggle
69
+ motor.on?.must_equal true
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'when changing speed (analog)' do
75
+
76
+ let(:motor) { Artoo::Drivers::Motor.new(:parent => @device, :additional_params => {speed_pin: 3}) }
77
+
78
+ it '#speed' do
79
+ connection.expects(:set_pin_mode).with(3, 3)
80
+ connection.expects(:analog_write).with(3, 255)
81
+ motor.speed(255)
82
+ end
83
+
84
+ it '#start' do
85
+ motor.speed(0)
86
+ motor.start
87
+ motor.current_speed.must_equal 255
88
+ end
89
+
90
+ it '#stop' do
91
+ motor.speed(255)
92
+ motor.stop
93
+ motor.current_speed.must_equal 0
94
+ end
95
+
96
+ it '#max' do
97
+ motor.speed(0)
98
+ motor.max
99
+ motor.current_speed.must_equal 255
100
+ end
101
+
102
+ it '#min' do
103
+ motor.speed(255)
104
+ motor.min
105
+ motor.current_speed.must_equal 0
106
+ end
107
+
108
+ it '#on?' do
109
+ motor.speed(1)
110
+ motor.on?.must_equal true
111
+ motor.speed(0)
112
+ motor.on?.must_equal false
113
+ end
114
+
115
+ it '#off?' do
116
+ motor.speed(1)
117
+ motor.off?.must_equal false
118
+ motor.speed(0)
119
+ motor.off?.must_equal true
120
+ end
121
+ end
122
+
34
123
  end
35
124
 
36
- it 'Motor#stop' do
37
- @motor.stop
38
- @motor.current_speed.must_equal 0
125
+ describe 'bididirectional' do
126
+
127
+ before do
128
+ connection.expects(:set_pin_mode).with(1, 1)
129
+ connection.expects(:set_pin_mode).with(2, 1)
130
+ end
131
+
132
+ let(:motor) { Artoo::Drivers::Motor.new(:parent => @device,
133
+ :additional_params =>
134
+ {:forward_pin => 1,
135
+ :backward_pin => 2}) }
136
+
137
+ describe '#forward' do
138
+
139
+ before do
140
+ connection.expects(:digital_write).with(1, 1)
141
+ connection.expects(:digital_write).with(2, 0)
142
+ end
143
+
144
+ describe 'when no parameter' do
145
+
146
+ it '#forward' do
147
+ motor.expects(:start)
148
+ motor.forward
149
+ end
150
+
151
+ end
152
+
153
+ describe 'when speed parameter' do
154
+
155
+ it '#forward' do
156
+ motor.expects(:speed).with(255)
157
+ motor.forward(255)
158
+ end
159
+
160
+ end
161
+
162
+ end
163
+
164
+ describe '#backward' do
165
+
166
+ before do
167
+ connection.expects(:digital_write).with(1, 0)
168
+ connection.expects(:digital_write).with(2, 1)
169
+ end
170
+
171
+ describe 'when no parameter' do
172
+
173
+ it '#backward' do
174
+ motor.expects(:start)
175
+ motor.backward
176
+ end
177
+
178
+ end
179
+
180
+ describe 'when speed parameter' do
181
+
182
+ it '#backward' do
183
+ motor.expects(:speed).with(255)
184
+ motor.backward(255)
185
+ end
186
+
187
+ end
188
+
189
+ end
39
190
  end
191
+
192
+
193
+ #it 'Motor#speed must be valid' do
194
+ #invalid_speed = lambda { @motor2 = Artoo::Drivers::Motor.new(:parent => @device, :additional_params => {}); @motor2.speed("ads") }
195
+ #invalid_speed.must_raise RuntimeError
196
+ #error = invalid_speed.call rescue $!
197
+ #error.message.must_equal 'Motor speed must be an integer between 0-255'
198
+ #end
199
+
200
+ #it 'Motor#forward' do
201
+ #@motor.expects(:set_legs)
202
+ #@motor.forward(100)
203
+ #@motor.current_speed.must_equal 100
204
+ #end
205
+
206
+ #it 'Motor#backward' do
207
+ #@motor.expects(:set_legs)
208
+ #@motor.backward(100)
209
+ #@motor.current_speed.must_equal 100
210
+ #end
211
+
40
212
  end
data/test/test_helper.rb CHANGED
@@ -4,3 +4,8 @@ require 'firmata'
4
4
  require 'artoo/robot'
5
5
 
6
6
  Celluloid.logger = nil
7
+
8
+ MiniTest::Spec.before do
9
+ Celluloid.shutdown
10
+ Celluloid.boot
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artoo-arduino
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Evans
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-24 00:00:00.000000000 Z
13
+ date: 2013-08-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: artoo
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.0
21
+ version: 1.1.0.pre
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- version: 1.0.0
28
+ version: 1.1.0.pre
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: hybridgroup-firmata
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +102,11 @@ files:
102
102
  - examples/firmata_blink_led_with_toggle.rb
103
103
  - examples/firmata_button_and_led.rb
104
104
  - examples/firmata_dc_motor_speed.rb
105
+ - examples/firmata_dc_motor_speed_h-bridge_2_pins.rb
106
+ - examples/firmata_dc_motor_switch.rb
107
+ - examples/firmata_dc_motor_switch_h-bridge_2_pins.rb
105
108
  - examples/firmata_led_brightness.rb
109
+ - examples/firmata_maxbotix.rb
106
110
  - examples/firmata_motor.rb
107
111
  - examples/firmata_servo.rb
108
112
  - examples/firmata_wiichuck.rb
@@ -110,14 +114,18 @@ files:
110
114
  - lib/artoo-arduino/version.rb
111
115
  - lib/artoo/adaptors/firmata.rb
112
116
  - lib/artoo/drivers/button.rb
117
+ - lib/artoo/drivers/firmata_board.rb
113
118
  - lib/artoo/drivers/led.rb
119
+ - lib/artoo/drivers/maxbotix.rb
114
120
  - lib/artoo/drivers/motor.rb
115
121
  - lib/artoo/drivers/servo.rb
116
122
  - lib/artoo/drivers/wiichuck.rb
117
123
  - lib/artoo/drivers/wiiclassic.rb
118
124
  - lib/artoo/drivers/wiidriver.rb
119
125
  - test/adaptors/firmata_test.rb
126
+ - test/drivers/firmata_board_test.rb
120
127
  - test/drivers/led_test.rb
128
+ - test/drivers/maxbotix_test.rb
121
129
  - test/drivers/motor_test.rb
122
130
  - test/drivers/servo_test.rb
123
131
  - test/drivers/wiichuck_test.rb
@@ -138,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
146
  version: '0'
139
147
  required_rubygems_version: !ruby/object:Gem::Requirement
140
148
  requirements:
141
- - - '>='
149
+ - - '>'
142
150
  - !ruby/object:Gem::Version
143
- version: '0'
151
+ version: 1.3.1
144
152
  requirements: []
145
153
  rubyforge_project: artoo-arduino
146
154
  rubygems_version: 2.0.3