artoo-arduino 1.0.5.pre → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +25 -20
- data/README.md +63 -3
- data/artoo-arduino.gemspec +3 -1
- data/examples/firmata_blink_led.rb +1 -1
- data/examples/firmata_blink_led_with_toggle.rb +2 -2
- data/examples/firmata_dc_motor_speed.rb +1 -1
- data/examples/firmata_dc_motor_speed_h-bridge_2_pins.rb +1 -1
- data/examples/firmata_dc_motor_switch.rb +1 -1
- data/examples/firmata_dc_motor_switch_h-bridge_2_pins.rb +1 -1
- data/examples/firmata_led_brightness.rb +1 -1
- data/examples/firmata_led_with_button_toggle.rb +21 -0
- data/examples/firmata_maxbotix.rb +2 -3
- data/examples/firmata_motor.rb +1 -1
- data/examples/firmata_servo.rb +1 -1
- data/examples/littlewire_blink_led_with_toggle.rb +17 -0
- data/examples/littlewire_button_and_led.rb +16 -0
- data/examples/littlewire_dc_motor_speed.rb +31 -0
- data/examples/littlewire_maxbotix.rb +19 -0
- data/lib/artoo-arduino.rb +4 -3
- data/lib/artoo-arduino/version.rb +1 -1
- data/lib/artoo/adaptors/firmata.rb +63 -0
- data/lib/artoo/adaptors/littlewire.rb +63 -0
- data/lib/artoo/drivers/{firmata_board.rb → board.rb} +2 -2
- data/lib/artoo/drivers/button.rb +14 -31
- data/lib/artoo/drivers/led.rb +5 -7
- data/lib/artoo/drivers/maxbotix.rb +6 -29
- data/lib/artoo/drivers/motor.rb +16 -28
- data/lib/artoo/drivers/servo.rb +1 -11
- data/test/adaptors/littlewire_test.rb +25 -0
- data/test/drivers/firmata_board_test.rb +5 -5
- data/test/drivers/led_test.rb +3 -11
- data/test/drivers/motor_test.rb +6 -14
- data/test/drivers/servo_test.rb +1 -3
- metadata +30 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e99b8d72a5ef6f50399e41d98bdb430ac6c389e
|
4
|
+
data.tar.gz: 70b8875c3af5a261715c2e407d4c2ace7f498740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8809c09890418839551d643e735b2ad89397357712b8ba0310cda7e3ec76e5def5facd9179c731afc5a461305d620a768296ae4450a7297472b855472361c142
|
7
|
+
data.tar.gz: 0ae662eeeb16b7bc0a51d7855c750a5eb5985435bdab553b9882905ba0624f913590cc62486d12492db63416ffa42e69dc5440c18e798e87d3501f87665772d0
|
data/Gemfile.lock
CHANGED
@@ -1,35 +1,41 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artoo-arduino (1.0
|
5
|
-
artoo (~> 1.1.0
|
4
|
+
artoo-arduino (1.1.0)
|
5
|
+
artoo (~> 1.1.0)
|
6
6
|
hybridgroup-firmata (~> 0.4.5)
|
7
|
+
littlewire (~> 0.9.7)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
10
11
|
specs:
|
11
|
-
artoo (1.1.0
|
12
|
-
celluloid (~> 0.15.0
|
13
|
-
celluloid-io (~> 0.15.0
|
12
|
+
artoo (1.1.0)
|
13
|
+
celluloid (~> 0.15.0)
|
14
|
+
celluloid-io (~> 0.15.0)
|
14
15
|
multi_json (~> 1.6)
|
15
16
|
pry (~> 0.9)
|
16
17
|
rake (~> 10.0)
|
17
18
|
reel (~> 0.4.0.pre)
|
18
19
|
thor (~> 0.18.1)
|
19
|
-
celluloid (0.15.
|
20
|
-
timers (
|
21
|
-
celluloid-io (0.15.0
|
22
|
-
celluloid (>= 0.15.0
|
20
|
+
celluloid (0.15.1)
|
21
|
+
timers (~> 1.1.0)
|
22
|
+
celluloid-io (0.15.0)
|
23
|
+
celluloid (>= 0.15.0)
|
23
24
|
nio4r (>= 0.5.0)
|
24
|
-
certified (0.1.1)
|
25
25
|
coderay (1.0.9)
|
26
|
+
colorist (0.0.2)
|
26
27
|
event_emitter (0.2.5)
|
27
|
-
|
28
|
-
|
28
|
+
ffi (1.9.0)
|
29
|
+
http (0.5.0.pre)
|
29
30
|
http_parser.rb
|
30
|
-
http_parser.rb (0.
|
31
|
+
http_parser.rb (0.6.0.beta.2)
|
31
32
|
hybridgroup-firmata (0.4.5)
|
32
33
|
event_emitter
|
34
|
+
libusb (0.3.4)
|
35
|
+
ffi (>= 1.0)
|
36
|
+
littlewire (0.9.7)
|
37
|
+
colorist (>= 0.0.2)
|
38
|
+
libusb (>= 0.2.0)
|
33
39
|
metaclass (0.0.1)
|
34
40
|
method_source (0.8.2)
|
35
41
|
minitest (5.0.1)
|
@@ -42,14 +48,13 @@ GEM
|
|
42
48
|
coderay (~> 1.0.5)
|
43
49
|
method_source (~> 0.8)
|
44
50
|
slop (~> 3.4)
|
45
|
-
rack (1.5.2)
|
46
51
|
rake (10.1.0)
|
47
|
-
reel (0.4.0.
|
48
|
-
celluloid
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
websocket_parser (>= 0.1.
|
52
|
+
reel (0.4.0.pre4)
|
53
|
+
celluloid (>= 0.15.0)
|
54
|
+
celluloid-io (>= 0.15.0)
|
55
|
+
http (>= 0.5.0.pre)
|
56
|
+
http_parser.rb (>= 0.6.0.beta.2)
|
57
|
+
websocket_parser (>= 0.1.4)
|
53
58
|
slop (3.4.6)
|
54
59
|
thor (0.18.1)
|
55
60
|
timers (1.1.0)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Artoo Adaptor For Arduino
|
2
2
|
|
3
|
-
This repository contains the Artoo (http://artoo.io/) adaptor and drivers for
|
3
|
+
This repository contains the Artoo (http://artoo.io/) adaptor and drivers for Arduino and Arduino-compatible microcontrollers (http://arduino.cc/) using either the Firmata protocol (http://firmata.org) or the Little Wire protocol (http://littlewire.cc).
|
4
4
|
|
5
5
|
Artoo is a open source micro-framework for robotics using Ruby.
|
6
6
|
|
@@ -8,6 +8,10 @@ For more information abut Artoo, check out our repo at https://github.com/hybrid
|
|
8
8
|
|
9
9
|
[![Code Climate](https://codeclimate.com/github/hybridgroup/artoo-arduino.png)](https://codeclimate.com/github/hybridgroup/artoo-arduino) [![Build Status](https://travis-ci.org/hybridgroup/artoo-arduino.png?branch=master)](https://travis-ci.org/hybridgroup/artoo-arduino)
|
10
10
|
|
11
|
+
This gem makes extensive use of the hybridgroup fork of the firmata gem (https://github.com/hybridgroup/firmata) thanks to [@hardbap](https://github.com/hardbap) with code borrrowed from the arduino_firmata gem (https://github.com/shokai/arduino_firmata) thanks to [@shokai](https://github.com/shokai)
|
12
|
+
|
13
|
+
It also makes extensive use of the littlewire.rb gem (https://github.com/Bluebie/littlewire.rb) thanks to [@Bluebie](https://github.com/Bluebie)
|
14
|
+
|
11
15
|
## Installing
|
12
16
|
|
13
17
|
```
|
@@ -63,7 +67,7 @@ $ artoo connect scan
|
|
63
67
|
Now you are ready to connect to the Arduino using a socket, such as in this example port 4567:
|
64
68
|
|
65
69
|
```
|
66
|
-
artoo connect
|
70
|
+
artoo connect serial ttyACM0
|
67
71
|
```
|
68
72
|
|
69
73
|
### Ubuntu
|
@@ -85,9 +89,65 @@ $ ls /dev/ttyACM*
|
|
85
89
|
Now you are ready to connect to the Arduino using the socket, in this example port 4567:
|
86
90
|
|
87
91
|
```
|
88
|
-
artoo connect
|
92
|
+
artoo connect serial ttyACM0 4567
|
93
|
+
```
|
94
|
+
|
95
|
+
### Windows
|
96
|
+
|
97
|
+
Someone please fill in the blanks here...
|
98
|
+
|
99
|
+
## Connecting to Digispark
|
100
|
+
|
101
|
+
You can use Artoo with a Digispark (http://www.kickstarter.com/projects/digistump/digispark-the-tiny-arduino-enabled-usb-dev-board) ATTiny-based USB development board, that has the Little Wire (http://littlewire.cc/) protocol firmware installed. For instructions on how to install Little Wire on a Digispark check out http://digistump.com/board/index.php/topic,160.0.html
|
102
|
+
|
103
|
+
### OSX
|
104
|
+
|
105
|
+
The main steps are:
|
106
|
+
- Plug in the Digispark to the USB port
|
107
|
+
- Connect to the device via Artoo
|
108
|
+
|
109
|
+
First plug the Digispark into your computer via the USB port. Then... (directions go here)
|
110
|
+
|
111
|
+
### Ubuntu
|
112
|
+
|
113
|
+
The main steps are:
|
114
|
+
- Add a udev rule to allow access to the Digispark device
|
115
|
+
- Plug in the Digispark to the USB port
|
116
|
+
- Connect to the device via Artoo
|
117
|
+
|
118
|
+
First, you must add a udev rule, so that Artoo can communicate with the USB device. Ubuntu and other modern Linux distibutions use udev to manage device files when USB devices are added and removed. By default, udev will create a device with read-only permission which will not allow to you download code. You must place the udev rules below into a file named /etc/udev/rules.d/49-micronucleus.rules.
|
119
|
+
|
120
|
+
```
|
121
|
+
# UDEV Rules for Micronucleus boards including the Digispark.
|
122
|
+
# This file must be placed at:
|
123
|
+
#
|
124
|
+
# /etc/udev/rules.d/49-micronucleus.rules (preferred location)
|
125
|
+
# or
|
126
|
+
# /lib/udev/rules.d/49-micronucleus.rules (req'd on some broken systems)
|
127
|
+
#
|
128
|
+
# After this file is copied, physically unplug and reconnect the board.
|
129
|
+
#
|
130
|
+
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", MODE:="0666"
|
131
|
+
KERNEL=="ttyACM*", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", MODE:="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
|
132
|
+
#
|
133
|
+
# If you share your linux system with other users, or just don't like the
|
134
|
+
# idea of write permission for everybody, you can replace MODE:="0666" with
|
135
|
+
# OWNER:="yourusername" to create the device owned by you, or with
|
136
|
+
# GROUP:="somegroupname" and mange access using standard unix groups.
|
89
137
|
```
|
90
138
|
|
139
|
+
Thanks to [@bluebie](https://github.com/Bluebie) for these instructions! (https://github.com/Bluebie/micronucleus-t85/wiki/Ubuntu-Linux)
|
140
|
+
|
141
|
+
Now plug the Digispark into your computer via the USB port.
|
142
|
+
|
143
|
+
Once plugged in, use the `artoo connect scan` command with the `-t usb` option to verify your connection info:
|
144
|
+
|
145
|
+
```
|
146
|
+
$ artoo connect scan -t usb
|
147
|
+
```
|
148
|
+
|
149
|
+
Now use the `ID` info returned to find the `product` and `vendor` ID's for the connection info Digispark in your Artoo code.
|
150
|
+
|
91
151
|
### Windows
|
92
152
|
|
93
153
|
Someone please fill in the blanks here...
|
data/artoo-arduino.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "https://github.com/hybridgroup/artoo-arduino"
|
12
12
|
s.summary = %q{Artoo adaptor and driver for Arduino}
|
13
13
|
s.description = %q{Artoo adaptor and driver for Arduino}
|
14
|
+
s.license = 'Apache 2.0'
|
14
15
|
|
15
16
|
s.rubyforge_project = "artoo-arduino"
|
16
17
|
|
@@ -19,8 +20,9 @@ Gem::Specification.new do |s|
|
|
19
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
21
|
s.require_paths = ["lib"]
|
21
22
|
|
22
|
-
s.add_runtime_dependency 'artoo', '~> 1.1.0
|
23
|
+
s.add_runtime_dependency 'artoo', '~> 1.1.0'
|
23
24
|
s.add_runtime_dependency 'hybridgroup-firmata', '~> 0.4.5'
|
25
|
+
s.add_runtime_dependency 'littlewire', '~> 0.9.7'
|
24
26
|
s.add_development_dependency 'minitest', '~> 5.0'
|
25
27
|
s.add_development_dependency 'minitest-happy'
|
26
28
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
@@ -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:4567'
|
7
|
-
device :board, :driver => :
|
7
|
+
device :board, :driver => :board
|
8
8
|
device :led, :driver => :led, :pin => 13
|
9
9
|
|
10
10
|
work do
|
@@ -4,12 +4,12 @@ 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, :driver => :
|
7
|
+
device :board, :driver => :board
|
8
8
|
device :led, :driver => :led, :pin => 13
|
9
9
|
|
10
10
|
work do
|
11
11
|
puts "Firmware name: #{board.firmware_name}"
|
12
|
-
puts "
|
12
|
+
puts "Firmware version: #{board.version}"
|
13
13
|
|
14
14
|
every 1.second do
|
15
15
|
led.toggle
|
@@ -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:4567'
|
7
|
-
device :board, :driver => :
|
7
|
+
device :board, :driver => :board
|
8
8
|
device :motor, :driver => :motor, :speed_pin => 3 # Use a PWM pin
|
9
9
|
|
10
10
|
work do
|
@@ -5,7 +5,7 @@ require 'artoo'
|
|
5
5
|
|
6
6
|
#connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
|
7
7
|
connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
|
8
|
-
device :board, :driver => :
|
8
|
+
device :board, :driver => :board
|
9
9
|
device :motor, :driver => :motor,
|
10
10
|
:forward_pin => 4, # Digital or PWM pin
|
11
11
|
:backward_pin => 2, # Digital or PWM pin
|
@@ -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, :driver => :
|
7
|
+
device :board, :driver => :board
|
8
8
|
device :motor, :driver => :motor, :switch_pin => 3 # Use a digital or PWM pin
|
9
9
|
|
10
10
|
work do
|
@@ -6,7 +6,7 @@ require 'artoo'
|
|
6
6
|
|
7
7
|
#connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
|
8
8
|
connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
|
9
|
-
device :board, :driver => :
|
9
|
+
device :board, :driver => :board
|
10
10
|
device :motor, :driver => :motor, :forward_pin => 4, :backward_pin => 2
|
11
11
|
|
12
12
|
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, :driver => :
|
7
|
+
device :board, :driver => :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://arduino.cc/en/tutorial/button
|
4
|
+
|
5
|
+
#connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
|
6
|
+
connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
|
7
|
+
device :led, :driver => :led, :pin => 13
|
8
|
+
device :button, :driver => :button, :pin => 2, :interval => 0.01
|
9
|
+
|
10
|
+
work do
|
11
|
+
puts
|
12
|
+
puts "Press the button connected on pin #{button.pin}..."
|
13
|
+
|
14
|
+
on button, :push => proc {
|
15
|
+
if led.on?
|
16
|
+
led.off
|
17
|
+
else
|
18
|
+
led.on
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
@@ -5,14 +5,13 @@ require 'artoo'
|
|
5
5
|
#connection :firmata, :adaptor => :firmata, :port => '/dev/ttyACM0'
|
6
6
|
connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:4567'
|
7
7
|
device :sonar, :driver => :maxbotix, :pin => 14, :interval => 0.5
|
8
|
-
device :board, :driver => :
|
8
|
+
device :board, :driver => :board
|
9
9
|
|
10
10
|
work do
|
11
11
|
on sonar, :range => :sonar_reading
|
12
|
+
|
12
13
|
puts "Firmware name: #{board.firmware_name}"
|
13
14
|
puts "Firmata version: #{board.version}"
|
14
|
-
puts "Analog pins: #{board.analog_pins}"
|
15
|
-
|
16
15
|
puts "starting sonar..."
|
17
16
|
end
|
18
17
|
|
data/examples/firmata_motor.rb
CHANGED
@@ -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, :driver => :
|
12
|
+
device :board, :driver => :board
|
13
13
|
device :motor, :driver => :motor, :pin => [leg1_pin, leg2_pin, speed_pin]
|
14
14
|
|
15
15
|
work do
|
data/examples/firmata_servo.rb
CHANGED
@@ -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 => :board
|
8
8
|
device :servo, :driver => :servo, :pin => 3 # pin must be a PWM pin
|
9
9
|
|
10
10
|
work do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
# Uses Digispark USB board (http://digistump.com/products/1)
|
4
|
+
# with Little Wire protocol (http://littlewire.cc)
|
5
|
+
|
6
|
+
connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
|
7
|
+
device :board, :driver => :board
|
8
|
+
device :led, :driver => :led, :pin => 1
|
9
|
+
|
10
|
+
work do
|
11
|
+
puts "Firmware name: #{board.firmware_name}"
|
12
|
+
puts "Firmware version: #{board.version}"
|
13
|
+
|
14
|
+
every 1.second do
|
15
|
+
led.toggle
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
# Circuit and schematic here: http://arduino.cc/en/tutorial/button
|
4
|
+
|
5
|
+
connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
|
6
|
+
device :board, :driver => :board
|
7
|
+
device :led, :driver => :led, :pin => 1
|
8
|
+
device :button, :driver => :button, :pin => 0, :interval => 0.01
|
9
|
+
|
10
|
+
work do
|
11
|
+
puts "Firmware name: #{board.firmware_name}"
|
12
|
+
puts "Firmware version: #{board.version}"
|
13
|
+
puts "Press the button connected on pin #{button.pin}..."
|
14
|
+
|
15
|
+
on button, :push => proc { led.toggle }
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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 :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
|
6
|
+
device :board, :driver => :board
|
7
|
+
device :motor, :driver => :motor, :speed_pin => 1 # Use a PWM pin
|
8
|
+
|
9
|
+
work do
|
10
|
+
puts "Firmware name: #{board.firmware_name}"
|
11
|
+
puts "Firmata version: #{board.version}"
|
12
|
+
puts "Stopping motor..."
|
13
|
+
motor.min # same as 'motor.stop' or 'motor.speed(0)'
|
14
|
+
sleep 3
|
15
|
+
puts "Setting to maximum speed..."
|
16
|
+
motor.max # same as 'motor.start'
|
17
|
+
sleep 3
|
18
|
+
|
19
|
+
speed = 0
|
20
|
+
step = 50
|
21
|
+
|
22
|
+
every 3.seconds do
|
23
|
+
motor.speed(speed)
|
24
|
+
puts "Current speed: #{motor.current_speed}"
|
25
|
+
speed += step
|
26
|
+
if [0, 250].include?(speed)
|
27
|
+
step = -step
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'artoo'
|
2
|
+
|
3
|
+
# Circuit and schematic here: http://www.electrojoystick.com/tutorial/?page_id=285
|
4
|
+
|
5
|
+
connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
|
6
|
+
device :sonar, :driver => :maxbotix, :pin => 0, :interval => 0.5
|
7
|
+
device :board, :driver => :board
|
8
|
+
|
9
|
+
work do
|
10
|
+
on sonar, :range => :sonar_reading
|
11
|
+
|
12
|
+
puts "Firmware name: #{board.firmware_name}"
|
13
|
+
puts "Firmata version: #{board.version}"
|
14
|
+
puts "starting sonar..."
|
15
|
+
end
|
16
|
+
|
17
|
+
def sonar_reading(*args)
|
18
|
+
puts args[1] * 1000
|
19
|
+
end
|
data/lib/artoo-arduino.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'lib/artoo/adaptors/firmata'
|
2
|
+
require 'lib/artoo/adaptors/littlewire'
|
2
3
|
|
3
|
-
|
4
|
-
require
|
5
|
-
|
4
|
+
%w{ button led motor servo wiichuck wiiclassic wiidriver }.each do |f|
|
5
|
+
require "lib/artoo/drivers/#{f}")
|
6
|
+
end
|
6
7
|
|
7
8
|
require 'lib/artoo-arduino/version'
|
@@ -24,11 +24,74 @@ module Artoo
|
|
24
24
|
super
|
25
25
|
end
|
26
26
|
|
27
|
+
def digital_write(pin, level)
|
28
|
+
firmata.set_pin_mode(pin, ::Firmata::PinModes::OUTPUT)
|
29
|
+
firmata.digital_write(pin, convert_level(level))
|
30
|
+
end
|
31
|
+
|
32
|
+
def digital_read(pin)
|
33
|
+
firmata.set_pin_mode(pin, ::Firmata::PinModes::INPUT)
|
34
|
+
firmata.toggle_pin_reporting(pin)
|
35
|
+
firmata.read_and_process
|
36
|
+
|
37
|
+
value = nil
|
38
|
+
while i = find_event("digital_read_#{pin}")
|
39
|
+
event = events.slice!(i)
|
40
|
+
value = event.data.first if !event.nil?
|
41
|
+
end
|
42
|
+
value
|
43
|
+
end
|
44
|
+
|
45
|
+
def pwm_write(pin, level)
|
46
|
+
firmata.set_pin_mode(pin, ::Firmata::PinModes::PWM)
|
47
|
+
firmata.analog_write(pin, level)
|
48
|
+
end
|
49
|
+
|
50
|
+
def servo_write(pin, angle)
|
51
|
+
firmata.set_pin_mode(pin, ::Firmata::PinModes::SERVO)
|
52
|
+
firmata.analog_write(pin, angle)
|
53
|
+
end
|
54
|
+
|
55
|
+
def analog_read(pin)
|
56
|
+
firmata.set_pin_mode(pin, ::Firmata::PinModes::ANALOG)
|
57
|
+
firmata.toggle_pin_reporting(pin)
|
58
|
+
firmata.read_and_process
|
59
|
+
|
60
|
+
value = 0
|
61
|
+
while i = find_event("analog_read_#{to_analog_pin(pin)}") do
|
62
|
+
event = events.slice!(i)
|
63
|
+
value = event.data.first if !event.nil?
|
64
|
+
end
|
65
|
+
value
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_analog_pin(pin)
|
69
|
+
pin - 14
|
70
|
+
end
|
71
|
+
|
72
|
+
def find_event(name)
|
73
|
+
events.index {|e| e.name == name.to_sym }
|
74
|
+
end
|
75
|
+
|
76
|
+
def events
|
77
|
+
firmata.async_events
|
78
|
+
end
|
79
|
+
|
27
80
|
# Uses method missing to call Firmata Board methods
|
28
81
|
# @see http://rubydoc.info/gems/hybridgroup-firmata/0.3.0/Firmata/Board Firmata Board Documentation
|
29
82
|
def method_missing(method_name, *arguments, &block)
|
30
83
|
firmata.send(method_name, *arguments, &block)
|
31
84
|
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
def convert_level(level)
|
88
|
+
case level
|
89
|
+
when :low
|
90
|
+
::Firmata::PinLevels::LOW
|
91
|
+
when :high
|
92
|
+
::Firmata::PinLevels::HIGH
|
93
|
+
end
|
94
|
+
end
|
32
95
|
end
|
33
96
|
end
|
34
97
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'artoo/adaptors/adaptor'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Adaptors
|
5
|
+
# Connect to Digispark or Littlewire device using Little Wire protocol
|
6
|
+
# @see http://littlewire.cc/
|
7
|
+
class Littlewire < Adaptor
|
8
|
+
attr_reader :littlewire, :vendor, :product, :usb
|
9
|
+
|
10
|
+
def initialize(params={})
|
11
|
+
super
|
12
|
+
|
13
|
+
params[:additional_params] ||= {}
|
14
|
+
@vendor = params[:additional_params][:vendor] || 0x1781
|
15
|
+
@product = params[:additional_params][:product] || 0x0c9f
|
16
|
+
end
|
17
|
+
|
18
|
+
# Creates connection with littlewire board
|
19
|
+
# @return [Boolean]
|
20
|
+
def connect
|
21
|
+
require 'littlewire' unless defined?(::LittleWire)
|
22
|
+
@littlewire = ::LittleWire.new(connect_to_usb)
|
23
|
+
super
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Closes connection with littlewire board
|
28
|
+
# @return [Boolean]
|
29
|
+
def disconnect
|
30
|
+
littlewire.finished
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns firmware name of littlewire board
|
35
|
+
# @return [String]
|
36
|
+
def firmware_name
|
37
|
+
"Little Wire"
|
38
|
+
end
|
39
|
+
|
40
|
+
def digital_read(pin)
|
41
|
+
littlewire.digital_write(pin, true)
|
42
|
+
littlewire.digital_read(pin)
|
43
|
+
end
|
44
|
+
|
45
|
+
def pwm_write(pin, level)
|
46
|
+
littlewire.software_pwm_write(pin, level)
|
47
|
+
end
|
48
|
+
|
49
|
+
def connect_to_usb
|
50
|
+
@usb = LIBUSB::Context.new.devices(
|
51
|
+
:idVendor => vendor,
|
52
|
+
:idProduct => product
|
53
|
+
).first
|
54
|
+
end
|
55
|
+
|
56
|
+
# Uses method missing to call Littlewire methods
|
57
|
+
# @see https://github.com/Bluebie/littlewire.rb
|
58
|
+
def method_missing(method_name, *arguments, &block)
|
59
|
+
littlewire.send(method_name, *arguments, &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/artoo/drivers/button.rb
CHANGED
@@ -2,7 +2,7 @@ require 'artoo/drivers/driver'
|
|
2
2
|
|
3
3
|
module Artoo
|
4
4
|
module Drivers
|
5
|
-
# Button driver behaviors
|
5
|
+
# Button driver behaviors
|
6
6
|
class Button < Driver
|
7
7
|
COMMANDS = [:is_pressed?].freeze
|
8
8
|
|
@@ -11,48 +11,31 @@ module Artoo
|
|
11
11
|
|
12
12
|
# @return [Boolean] True if pressed
|
13
13
|
def is_pressed?
|
14
|
-
(@
|
14
|
+
(@pressed_val == 1) ? true : false
|
15
15
|
end
|
16
16
|
|
17
|
-
# Sets values to read and write from button
|
18
|
-
# and starts driver
|
19
17
|
def start_driver
|
20
|
-
|
21
|
-
connection.toggle_pin_reporting(pin)
|
18
|
+
@pressed_val = 0
|
22
19
|
|
23
20
|
every(interval) do
|
24
|
-
connection.
|
25
|
-
|
21
|
+
new_value = connection.digital_read(pin)
|
22
|
+
update(new_value) if !new_value.nil? && new_value != is_pressed?
|
26
23
|
end
|
27
24
|
|
28
25
|
super
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
|
-
while i = find_event("digital_read_#{pin}") do
|
33
|
-
event = events.slice!(i)
|
34
|
-
update(event.data.first) if !event.nil?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def find_event(name)
|
39
|
-
events.index {|e| e.name == name.to_sym}
|
40
|
-
end
|
41
|
-
|
42
|
-
def events
|
43
|
-
connection.async_events
|
44
|
-
end
|
45
|
-
|
28
|
+
private
|
46
29
|
# Publishes events according to the button feedback
|
47
|
-
def update(
|
48
|
-
if
|
49
|
-
@
|
50
|
-
publish(event_topic_name("update"), "push",
|
51
|
-
publish(event_topic_name("push"),
|
30
|
+
def update(new_val)
|
31
|
+
if new_val == 1
|
32
|
+
@pressed_val = 1
|
33
|
+
publish(event_topic_name("update"), "push", new_val)
|
34
|
+
publish(event_topic_name("push"), new_val)
|
52
35
|
else
|
53
|
-
@
|
54
|
-
publish(event_topic_name("update"), "release",
|
55
|
-
publish(event_topic_name("release"),
|
36
|
+
@pressed_val = 0
|
37
|
+
publish(event_topic_name("update"), "release", new_val)
|
38
|
+
publish(event_topic_name("release"), new_val)
|
56
39
|
end
|
57
40
|
end
|
58
41
|
end
|
data/lib/artoo/drivers/led.rb
CHANGED
@@ -5,8 +5,7 @@ module Artoo
|
|
5
5
|
# The LED driver behaviors
|
6
6
|
class Led < Driver
|
7
7
|
|
8
|
-
COMMANDS = [:
|
9
|
-
:on, :off, :toggle,
|
8
|
+
COMMANDS = [:on, :off, :toggle,
|
10
9
|
:brightness,
|
11
10
|
:on?, :off?].freeze
|
12
11
|
|
@@ -14,6 +13,7 @@ module Artoo
|
|
14
13
|
@is_on = false
|
15
14
|
super
|
16
15
|
end
|
16
|
+
|
17
17
|
# @return [Boolean] True if on
|
18
18
|
def on?
|
19
19
|
@is_on
|
@@ -26,14 +26,14 @@ module Artoo
|
|
26
26
|
|
27
27
|
# Sets led to level HIGH
|
28
28
|
def on
|
29
|
-
change_state(pin,
|
29
|
+
change_state(pin, :high)
|
30
30
|
@is_on = true
|
31
31
|
true
|
32
32
|
end
|
33
33
|
|
34
34
|
# Sets led to level LOW
|
35
35
|
def off
|
36
|
-
change_state(pin,
|
36
|
+
change_state(pin, :low)
|
37
37
|
@is_on = false
|
38
38
|
true
|
39
39
|
end
|
@@ -47,13 +47,11 @@ module Artoo
|
|
47
47
|
# Change brightness level
|
48
48
|
# @param [Integer] level
|
49
49
|
def brightness(level=0)
|
50
|
-
connection.
|
51
|
-
connection.analog_write(pin, level)
|
50
|
+
connection.pwm_write(pin, level)
|
52
51
|
end
|
53
52
|
|
54
53
|
private
|
55
54
|
def change_state(pin, level)
|
56
|
-
connection.set_pin_mode(pin, Firmata::PinModes::OUTPUT)
|
57
55
|
connection.digital_write(pin, level)
|
58
56
|
end
|
59
57
|
end
|
@@ -4,10 +4,10 @@ module Artoo
|
|
4
4
|
module Drivers
|
5
5
|
# Maxbotix ultrasonic range finder driver behaviors for Firmata
|
6
6
|
class Maxbotix < Driver
|
7
|
-
attr_accessor :last_reading
|
8
|
-
|
9
7
|
COMMANDS = [:range].freeze
|
10
8
|
|
9
|
+
attr_accessor :last_reading
|
10
|
+
|
11
11
|
def initialize(params={})
|
12
12
|
@last_reading = 0.0
|
13
13
|
super
|
@@ -15,53 +15,30 @@ module Artoo
|
|
15
15
|
|
16
16
|
# @return [float] last range reading in inches
|
17
17
|
def range
|
18
|
-
return (
|
18
|
+
return ( 254.0 / 1024.0 ) * 2.0 * last_reading
|
19
19
|
end
|
20
20
|
|
21
21
|
# @return [float] last range reading in cm
|
22
22
|
def range_cm
|
23
|
-
return (
|
23
|
+
return (last_reading / 2.0) * 2.54
|
24
24
|
end
|
25
25
|
|
26
26
|
# Sets values to read from ultrasonic range finder
|
27
27
|
# and starts driver
|
28
28
|
def start_driver
|
29
|
-
connection.set_pin_mode(pin, Firmata::PinModes::ANALOG)
|
30
|
-
connection.toggle_pin_reporting(pin)
|
31
|
-
|
32
29
|
every(interval) do
|
33
|
-
connection.
|
34
|
-
handle_events
|
30
|
+
update(connection.analog_read(pin))
|
35
31
|
end
|
36
32
|
|
37
33
|
super
|
38
34
|
end
|
39
35
|
|
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
36
|
# Publishes events according to the ultrasonic rangefinder value
|
56
37
|
def update(value)
|
57
|
-
|
38
|
+
last_reading = value
|
58
39
|
publish(event_topic_name("update"), "range", range)
|
59
40
|
publish(event_topic_name("range"), range)
|
60
41
|
end
|
61
|
-
|
62
|
-
def analog_pin
|
63
|
-
pin - 14
|
64
|
-
end
|
65
42
|
end
|
66
43
|
end
|
67
44
|
end
|
data/lib/artoo/drivers/motor.rb
CHANGED
@@ -13,12 +13,12 @@ module Artoo
|
|
13
13
|
|
14
14
|
additional_params = params[:additional_params]
|
15
15
|
@speed_pin = additional_params[:speed_pin]
|
16
|
-
@
|
16
|
+
@switch_pin = additional_params[:switch_pin] if additional_params[:switch_pin]
|
17
17
|
|
18
18
|
@forward_pin = additional_params[:forward_pin]
|
19
19
|
@backward_pin = additional_params[:backward_pin]
|
20
20
|
|
21
|
-
@current_state =
|
21
|
+
@current_state = :low
|
22
22
|
@current_speed = 0
|
23
23
|
|
24
24
|
# digital: just to switch the motor on or off, no speed control
|
@@ -37,15 +37,6 @@ module Artoo
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
# Starts connection to read and process and driver
|
41
|
-
def start_driver
|
42
|
-
every(interval) do
|
43
|
-
connection.read_and_process
|
44
|
-
end
|
45
|
-
|
46
|
-
super
|
47
|
-
end
|
48
|
-
|
49
40
|
def digital?
|
50
41
|
@current_mode == :digital
|
51
42
|
end
|
@@ -56,7 +47,7 @@ module Artoo
|
|
56
47
|
|
57
48
|
def stop
|
58
49
|
if digital?
|
59
|
-
change_state(
|
50
|
+
change_state(:low)
|
60
51
|
else
|
61
52
|
speed(0)
|
62
53
|
end
|
@@ -64,7 +55,7 @@ module Artoo
|
|
64
55
|
|
65
56
|
def start
|
66
57
|
if digital?
|
67
|
-
change_state(
|
58
|
+
change_state(:high)
|
68
59
|
else
|
69
60
|
speed(@current_speed.zero? ? 255 : @current_speed)
|
70
61
|
end
|
@@ -80,7 +71,7 @@ module Artoo
|
|
80
71
|
|
81
72
|
def on?
|
82
73
|
if digital?
|
83
|
-
@current_state ==
|
74
|
+
@current_state == :high
|
84
75
|
else
|
85
76
|
@current_speed > 0
|
86
77
|
end
|
@@ -96,8 +87,7 @@ module Artoo
|
|
96
87
|
|
97
88
|
def change_state(state)
|
98
89
|
@current_state = state
|
99
|
-
@current_speed = state
|
100
|
-
connection.set_pin_mode(@speed_pin, Firmata::PinModes::OUTPUT)
|
90
|
+
@current_speed = state == :low ? 0 : 255
|
101
91
|
connection.digital_write(@speed_pin, state)
|
102
92
|
end
|
103
93
|
|
@@ -107,8 +97,7 @@ module Artoo
|
|
107
97
|
@current_mode = :analog
|
108
98
|
raise "Motor speed must be an integer between 0-255" unless (value.is_a?(Numeric) && value >= 0 && value <= 255)
|
109
99
|
@current_speed = value
|
110
|
-
connection.
|
111
|
-
connection.analog_write(speed_pin, value)
|
100
|
+
connection.pwm_write(speed_pin, value)
|
112
101
|
end
|
113
102
|
|
114
103
|
private
|
@@ -147,10 +136,10 @@ module Artoo
|
|
147
136
|
def change_state(state)
|
148
137
|
@current_state = state
|
149
138
|
@current_speed = state.zero? ? 0 : 255
|
150
|
-
if state ==
|
139
|
+
if state == :high
|
151
140
|
direction(@current_direction)
|
152
141
|
speed(@current_speed) if speed_pin
|
153
|
-
elsif state ==
|
142
|
+
elsif state == :low
|
154
143
|
direction(:none)
|
155
144
|
end
|
156
145
|
end
|
@@ -159,18 +148,17 @@ module Artoo
|
|
159
148
|
@current_direction = direction
|
160
149
|
case direction
|
161
150
|
when :forward
|
162
|
-
forward_pin_level =
|
163
|
-
backward_pin_level =
|
151
|
+
forward_pin_level = :high
|
152
|
+
backward_pin_level = :low
|
164
153
|
when :backward
|
165
|
-
forward_pin_level =
|
166
|
-
backward_pin_level =
|
154
|
+
forward_pin_level = :low
|
155
|
+
backward_pin_level = :high
|
167
156
|
when :none
|
168
|
-
forward_pin_level =
|
169
|
-
backward_pin_level =
|
157
|
+
forward_pin_level = :low
|
158
|
+
backward_pin_level = :low
|
170
159
|
end
|
171
|
-
|
160
|
+
|
172
161
|
connection.digital_write(@forward_pin, forward_pin_level)
|
173
|
-
connection.set_pin_mode(@backward_pin, Firmata::PinModes::OUTPUT)
|
174
162
|
connection.digital_write(@backward_pin, backward_pin_level)
|
175
163
|
end
|
176
164
|
|
data/lib/artoo/drivers/servo.rb
CHANGED
@@ -15,23 +15,13 @@ module Artoo
|
|
15
15
|
@current_angle = 0
|
16
16
|
end
|
17
17
|
|
18
|
-
# Starts connection to read and process and driver
|
19
|
-
def start_driver
|
20
|
-
every(interval) do
|
21
|
-
connection.read_and_process
|
22
|
-
end
|
23
|
-
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
18
|
# Moves to specified angle
|
28
19
|
# @param [Integer] angle must be between 0-180
|
29
20
|
def move(angle)
|
30
21
|
raise "Servo angle must be an integer between 0-180" unless (angle.is_a?(Numeric) && angle >= 0 && angle <= 180)
|
31
22
|
|
32
23
|
@current_angle = angle
|
33
|
-
connection.
|
34
|
-
connection.analog_write(pin, angle_to_span(angle))
|
24
|
+
connection.servo_write(pin, angle_to_span(angle))
|
35
25
|
end
|
36
26
|
|
37
27
|
# Moves to min position
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
require 'artoo/adaptors/littlewire'
|
3
|
+
require 'littlewire'
|
4
|
+
|
5
|
+
describe Artoo::Adaptors::Littlewire do
|
6
|
+
before do
|
7
|
+
@port = Artoo::Port.new('/dev/awesome')
|
8
|
+
@adaptor = Artoo::Adaptors::Littlewire.new(:port => @port)
|
9
|
+
@adaptor.expects(:connect_to_usb)
|
10
|
+
@littlewire = mock('littlewire')
|
11
|
+
LittleWire.expects(:new).returns(@littlewire)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Artoo::Adaptors::Littlewire#connect' do
|
15
|
+
@adaptor.connect.must_equal true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'Artoo::Adaptors::Littlewire#disconnect' do
|
19
|
+
@littlewire.expects(:finished)
|
20
|
+
@adaptor.connect
|
21
|
+
@adaptor.disconnect
|
22
|
+
|
23
|
+
@adaptor.connected?.must_equal false
|
24
|
+
end
|
25
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
-
require 'artoo/drivers/
|
2
|
+
require 'artoo/drivers/board'
|
3
3
|
|
4
|
-
describe Artoo::Drivers::
|
4
|
+
describe Artoo::Drivers::Board do
|
5
5
|
before do
|
6
6
|
@device = mock('device')
|
7
|
-
@board = Artoo::Drivers::
|
7
|
+
@board = Artoo::Drivers::Board.new(:parent => @device)
|
8
8
|
@connection = mock('connection')
|
9
9
|
@device.stubs(:connection).returns(@connection)
|
10
10
|
end
|
11
11
|
|
12
|
-
it '
|
12
|
+
it 'Board#firmware_name' do
|
13
13
|
@connection.expects(:firmware_name).returns("awesomenessware")
|
14
14
|
@board.firmware_name.must_equal "awesomenessware"
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
17
|
+
it 'Board#version' do
|
18
18
|
@connection.expects(:version).returns("1.2.3")
|
19
19
|
@board.version.must_equal "1.2.3"
|
20
20
|
end
|
data/test/drivers/led_test.rb
CHANGED
@@ -12,21 +12,16 @@ describe Artoo::Drivers::Led do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'state switching' do
|
15
|
-
|
16
|
-
before do
|
17
|
-
@connection.expects(:set_pin_mode).with(@pin, Firmata::PinModes::OUTPUT)
|
18
|
-
end
|
19
|
-
|
20
15
|
describe '#on' do
|
21
16
|
it 'must turn the led on' do
|
22
|
-
@connection.expects(:digital_write).with(@pin,
|
17
|
+
@connection.expects(:digital_write).with(@pin, :high)
|
23
18
|
@led.on
|
24
19
|
end
|
25
20
|
end
|
26
21
|
|
27
22
|
describe '#off' do
|
28
23
|
it 'must turn the led off' do
|
29
|
-
@connection.expects(:digital_write).with(@pin,
|
24
|
+
@connection.expects(:digital_write).with(@pin, :low)
|
30
25
|
@led.off
|
31
26
|
end
|
32
27
|
end
|
@@ -79,16 +74,13 @@ describe Artoo::Drivers::Led do
|
|
79
74
|
describe '#brightness' do
|
80
75
|
it 'must change the brightness of the led' do
|
81
76
|
val = 100
|
82
|
-
@connection.expects(:
|
83
|
-
@connection.expects(:analog_write).with(@pin, val)
|
77
|
+
@connection.expects(:pwm_write).with(@pin, val)
|
84
78
|
@led.brightness(val)
|
85
79
|
end
|
86
80
|
end
|
87
81
|
|
88
82
|
describe '#commands' do
|
89
83
|
it 'must contain all the necessary commands' do
|
90
|
-
@led.commands.must_include :firmware_name
|
91
|
-
@led.commands.must_include :version
|
92
84
|
@led.commands.must_include :on
|
93
85
|
@led.commands.must_include :off
|
94
86
|
@led.commands.must_include :toggle
|
data/test/drivers/motor_test.rb
CHANGED
@@ -7,8 +7,7 @@ describe Artoo::Drivers::Motor do
|
|
7
7
|
|
8
8
|
before do
|
9
9
|
@device = mock('device')
|
10
|
-
connection.stubs(:
|
11
|
-
connection.stubs(:analog_write)
|
10
|
+
connection.stubs(:pwm_write)
|
12
11
|
connection.stubs(:digital_write)
|
13
12
|
@device.stubs(:connection).returns(connection)
|
14
13
|
end
|
@@ -76,8 +75,7 @@ describe Artoo::Drivers::Motor do
|
|
76
75
|
let(:motor) { Artoo::Drivers::Motor.new(:parent => @device, :additional_params => {speed_pin: 3}) }
|
77
76
|
|
78
77
|
it '#speed' do
|
79
|
-
connection.expects(:
|
80
|
-
connection.expects(:analog_write).with(3, 255)
|
78
|
+
connection.expects(:pwm_write).with(3, 255)
|
81
79
|
motor.speed(255)
|
82
80
|
end
|
83
81
|
|
@@ -123,12 +121,6 @@ describe Artoo::Drivers::Motor do
|
|
123
121
|
end
|
124
122
|
|
125
123
|
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
124
|
let(:motor) { Artoo::Drivers::Motor.new(:parent => @device,
|
133
125
|
:additional_params =>
|
134
126
|
{:forward_pin => 1,
|
@@ -137,8 +129,8 @@ describe Artoo::Drivers::Motor do
|
|
137
129
|
describe '#forward' do
|
138
130
|
|
139
131
|
before do
|
140
|
-
connection.expects(:digital_write).with(1,
|
141
|
-
connection.expects(:digital_write).with(2,
|
132
|
+
connection.expects(:digital_write).with(1, :high)
|
133
|
+
connection.expects(:digital_write).with(2, :low)
|
142
134
|
end
|
143
135
|
|
144
136
|
describe 'when no parameter' do
|
@@ -164,8 +156,8 @@ describe Artoo::Drivers::Motor do
|
|
164
156
|
describe '#backward' do
|
165
157
|
|
166
158
|
before do
|
167
|
-
connection.expects(:digital_write).with(1,
|
168
|
-
connection.expects(:digital_write).with(2,
|
159
|
+
connection.expects(:digital_write).with(1, :low)
|
160
|
+
connection.expects(:digital_write).with(2, :high)
|
169
161
|
end
|
170
162
|
|
171
163
|
describe 'when no parameter' do
|
data/test/drivers/servo_test.rb
CHANGED
@@ -8,9 +8,7 @@ describe Artoo::Drivers::Servo do
|
|
8
8
|
@servo = Artoo::Drivers::Servo.new(:parent => @device)
|
9
9
|
|
10
10
|
@connection = mock('connection')
|
11
|
-
@connection.stubs(:
|
12
|
-
@connection.stubs(:analog_write)
|
13
|
-
# @connection.stubs(:digital_write)
|
11
|
+
@connection.stubs(:servo_write)
|
14
12
|
@device.stubs(:connection).returns(@connection)
|
15
13
|
end
|
16
14
|
|
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
|
+
version: 1.1.0
|
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-
|
13
|
+
date: 2013-09-07 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.1.0
|
21
|
+
version: 1.1.0
|
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.1.0
|
28
|
+
version: 1.1.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: hybridgroup-firmata
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 0.4.5
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: littlewire
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.9.7
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.9.7
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: minitest
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,15 +120,21 @@ files:
|
|
106
120
|
- examples/firmata_dc_motor_switch.rb
|
107
121
|
- examples/firmata_dc_motor_switch_h-bridge_2_pins.rb
|
108
122
|
- examples/firmata_led_brightness.rb
|
123
|
+
- examples/firmata_led_with_button_toggle.rb
|
109
124
|
- examples/firmata_maxbotix.rb
|
110
125
|
- examples/firmata_motor.rb
|
111
126
|
- examples/firmata_servo.rb
|
112
127
|
- examples/firmata_wiichuck.rb
|
128
|
+
- examples/littlewire_blink_led_with_toggle.rb
|
129
|
+
- examples/littlewire_button_and_led.rb
|
130
|
+
- examples/littlewire_dc_motor_speed.rb
|
131
|
+
- examples/littlewire_maxbotix.rb
|
113
132
|
- lib/artoo-arduino.rb
|
114
133
|
- lib/artoo-arduino/version.rb
|
115
134
|
- lib/artoo/adaptors/firmata.rb
|
135
|
+
- lib/artoo/adaptors/littlewire.rb
|
136
|
+
- lib/artoo/drivers/board.rb
|
116
137
|
- lib/artoo/drivers/button.rb
|
117
|
-
- lib/artoo/drivers/firmata_board.rb
|
118
138
|
- lib/artoo/drivers/led.rb
|
119
139
|
- lib/artoo/drivers/maxbotix.rb
|
120
140
|
- lib/artoo/drivers/motor.rb
|
@@ -123,6 +143,7 @@ files:
|
|
123
143
|
- lib/artoo/drivers/wiiclassic.rb
|
124
144
|
- lib/artoo/drivers/wiidriver.rb
|
125
145
|
- test/adaptors/firmata_test.rb
|
146
|
+
- test/adaptors/littlewire_test.rb
|
126
147
|
- test/drivers/firmata_board_test.rb
|
127
148
|
- test/drivers/led_test.rb
|
128
149
|
- test/drivers/maxbotix_test.rb
|
@@ -133,7 +154,8 @@ files:
|
|
133
154
|
- test/drivers/wiidriver_test.rb
|
134
155
|
- test/test_helper.rb
|
135
156
|
homepage: https://github.com/hybridgroup/artoo-arduino
|
136
|
-
licenses:
|
157
|
+
licenses:
|
158
|
+
- Apache 2.0
|
137
159
|
metadata: {}
|
138
160
|
post_install_message:
|
139
161
|
rdoc_options: []
|
@@ -146,9 +168,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
168
|
version: '0'
|
147
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
170
|
requirements:
|
149
|
-
- - '
|
171
|
+
- - '>='
|
150
172
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
173
|
+
version: '0'
|
152
174
|
requirements: []
|
153
175
|
rubyforge_project: artoo-arduino
|
154
176
|
rubygems_version: 2.0.3
|