rumba 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/rumba.rb +1 -1
- data/lib/rumba/constants.rb +1 -1
- data/lib/rumba/dsl.rb +48 -33
- data/lib/rumba/sensors.rb +25 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfa29def9523b31571bf2081b0428dac3c4804ce
|
4
|
+
data.tar.gz: e238032a3be080bae5b265ed7b3df1a5c6e9606f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c09e420f4645064408470c33493e805bb255b08198525f46870a8e172fb0f692294629ad18d1c3ab3f7d6e1f2cfc790ff7c707e921bdcc7f8e1a9513b9eb79b3
|
7
|
+
data.tar.gz: 41110e7769d55452e58e4bcfa94aedf0586e7777edad55686a4b3b7fd139afd01d85121cc11da0550301c3f95fa75c798755202113d6f6c469591be88f7f127c
|
data/README.md
CHANGED
@@ -20,6 +20,14 @@ Happy hacking!
|
|
20
20
|
### Dependencies
|
21
21
|
* [serialport](http://ruby-serialport.rubyforge.org/)
|
22
22
|
|
23
|
+
### Installation
|
24
|
+
|
25
|
+
Easy!
|
26
|
+
|
27
|
+
```bash
|
28
|
+
gem install rumba
|
29
|
+
```
|
30
|
+
|
23
31
|
### Usage
|
24
32
|
|
25
33
|
Here's an example program:
|
@@ -31,13 +39,13 @@ require 'rumba'
|
|
31
39
|
|
32
40
|
Roomba.new('/dev/tty.usbserial') do
|
33
41
|
safe_mode
|
34
|
-
forward meter
|
42
|
+
forward 1.meter
|
35
43
|
rotate :left
|
36
44
|
rotate -90 # degrees
|
37
45
|
|
38
46
|
rotate :right
|
39
47
|
rotate 90
|
40
|
-
backward meter
|
48
|
+
backward 1.meter
|
41
49
|
|
42
50
|
# access to any methods in the Roomba class here!
|
43
51
|
end
|
data/lib/rumba.rb
CHANGED
data/lib/rumba/constants.rb
CHANGED
data/lib/rumba/dsl.rb
CHANGED
@@ -8,61 +8,57 @@ class Rumba
|
|
8
8
|
|
9
9
|
# Radius of an average Roomba, used for calculating rotation
|
10
10
|
RADIUS = 165.1 # 6.5 inches
|
11
|
+
|
12
|
+
# move both wheels at the same speed in a certain direction!
|
13
|
+
# NOTE THAT THIS BLOCKS UNTIL COMPLETE
|
14
|
+
def straight_distance(distance, speed: DEFAULT_SPEED)
|
15
|
+
total = 0
|
16
|
+
straight(speed)
|
17
|
+
loop do
|
18
|
+
total += get_sensor(:distance).abs
|
19
|
+
break if total >= distance
|
20
|
+
end
|
21
|
+
|
22
|
+
halt
|
23
|
+
end
|
11
24
|
|
12
25
|
# distance is in mm!
|
13
26
|
def forward(distance, speed: DEFAULT_SPEED)
|
14
|
-
|
15
|
-
straight(speed)
|
16
|
-
sleep(duration)
|
17
|
-
halt
|
27
|
+
straight_distance(distance, speed: speed)
|
18
28
|
end
|
19
29
|
|
20
30
|
# distance is in mm!
|
21
31
|
def backward(distance, speed: DEFAULT_SPEED)
|
22
|
-
|
23
|
-
straight(-speed)
|
24
|
-
sleep(duration)
|
25
|
-
halt
|
32
|
+
straight_distance(distance, speed: -speed)
|
26
33
|
end
|
27
34
|
|
28
35
|
# Direction can either be a Fixnum for number of degrees,
|
29
36
|
# or a symbol for the direction (:left, :right)
|
30
37
|
def rotate(direction, speed: DEFAULT_SPEED)
|
31
38
|
# handle symbols...
|
39
|
+
# note that counter-clockwise is positive
|
32
40
|
case direction
|
33
41
|
when :left
|
34
|
-
direction = -90
|
35
|
-
when :right
|
36
42
|
direction = 90
|
43
|
+
when :right
|
44
|
+
direction = -90
|
37
45
|
end
|
38
46
|
|
39
|
-
|
47
|
+
direction > 0 ? spin_right(speed) : spin_left(speed)
|
40
48
|
|
41
|
-
|
42
|
-
|
49
|
+
total = 0
|
50
|
+
goal = direction.abs / 2
|
51
|
+
loop do
|
52
|
+
raw_angle = get_sensor(:angle)
|
43
53
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# MEASUREMENT HELPERS
|
51
|
-
# TODO: break these out into separate helpers file?
|
52
|
-
def inches(num)
|
53
|
-
25.4 * num
|
54
|
-
end
|
55
|
-
alias_method :inch, :inches
|
56
|
-
|
57
|
-
def feet(num)
|
58
|
-
inches(num) * 12
|
59
|
-
end
|
60
|
-
alias_method :foot, :feet
|
54
|
+
# taken from the official docs to convert output to degrees...
|
55
|
+
degrees = (360 * raw_angle)/(258 * Math::PI)
|
56
|
+
total += degrees.abs
|
57
|
+
break if total >= goal
|
58
|
+
end
|
61
59
|
|
62
|
-
|
63
|
-
num * 1000
|
60
|
+
halt
|
64
61
|
end
|
65
|
-
alias_method :meter, :meters
|
66
62
|
|
67
63
|
# eh, why not?
|
68
64
|
alias_method :forwards, :forward
|
@@ -70,3 +66,22 @@ class Rumba
|
|
70
66
|
alias_method :turn, :rotate
|
71
67
|
end
|
72
68
|
end
|
69
|
+
|
70
|
+
# MEASUREMENT HELPERS
|
71
|
+
class Fixnum
|
72
|
+
def inches
|
73
|
+
25.4 * self
|
74
|
+
end
|
75
|
+
alias_method :inch, :inches
|
76
|
+
|
77
|
+
def feet
|
78
|
+
self.inches * 12
|
79
|
+
end
|
80
|
+
alias_method :foot, :feet
|
81
|
+
|
82
|
+
def meters
|
83
|
+
self * 1000
|
84
|
+
end
|
85
|
+
alias_method :meter, :meters
|
86
|
+
end
|
87
|
+
|
data/lib/rumba/sensors.rb
CHANGED
@@ -4,7 +4,7 @@ class Rumba
|
|
4
4
|
module Sensor
|
5
5
|
class Boolean
|
6
6
|
def self.convert(v)
|
7
|
-
v == 1
|
7
|
+
v == 1
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -45,8 +45,8 @@ class Rumba
|
|
45
45
|
class ChargingSourceAvailable
|
46
46
|
def self.convert(v)
|
47
47
|
h = {}
|
48
|
-
h[:internal_charger] = v & 0b1 > 0
|
49
|
-
h[:home_base] = v & 0b10 > 0
|
48
|
+
h[:internal_charger] = v & 0b1 > 0
|
49
|
+
h[:home_base] = v & 0b10 > 0
|
50
50
|
h
|
51
51
|
end
|
52
52
|
end
|
@@ -54,12 +54,12 @@ class Rumba
|
|
54
54
|
class LightBumper
|
55
55
|
def self.convert(v)
|
56
56
|
h = {}
|
57
|
-
h[:light_bumper_left] = v & 0b1 > 0
|
58
|
-
h[:light_bumper_front_left] = v & 0b10 > 0
|
59
|
-
h[:light_bumper_center_left] = v & 0b100 > 0
|
60
|
-
h[:light_bumper_center_right] = v & 0b1000 > 0
|
61
|
-
h[:light_bumper_front_right] = v & 0b10000 > 0
|
62
|
-
h[:light_bumper_right] = v & 0b100000 > 0
|
57
|
+
h[:light_bumper_left] = v & 0b1 > 0
|
58
|
+
h[:light_bumper_front_left] = v & 0b10 > 0
|
59
|
+
h[:light_bumper_center_left] = v & 0b100 > 0
|
60
|
+
h[:light_bumper_center_right] = v & 0b1000 > 0
|
61
|
+
h[:light_bumper_front_right] = v & 0b10000 > 0
|
62
|
+
h[:light_bumper_right] = v & 0b100000 > 0
|
63
63
|
h
|
64
64
|
end
|
65
65
|
end
|
@@ -67,10 +67,10 @@ class Rumba
|
|
67
67
|
class WheelOvercurrents
|
68
68
|
def self.convert(v)
|
69
69
|
h = {}
|
70
|
-
h[:side_brush] = v & 0b1 > 0
|
71
|
-
h[:main_brush] = v & 0b100 > 0
|
72
|
-
h[:right_wheel] = v & 0b1000 > 0
|
73
|
-
h[:left_wheel] = v & 0b10000 > 0
|
70
|
+
h[:side_brush] = v & 0b1 > 0
|
71
|
+
h[:main_brush] = v & 0b100 > 0
|
72
|
+
h[:right_wheel] = v & 0b1000 > 0
|
73
|
+
h[:left_wheel] = v & 0b10000 > 0
|
74
74
|
h
|
75
75
|
end
|
76
76
|
end
|
@@ -78,10 +78,10 @@ class Rumba
|
|
78
78
|
class BumpsAndWheelDrops
|
79
79
|
def self.convert(v)
|
80
80
|
h = {}
|
81
|
-
h[:bump_right] = v & 0b1 > 0
|
82
|
-
h[:bump_left] = v & 0b10 > 0
|
83
|
-
h[:wheel_drop_right] = v & 0b100 > 0
|
84
|
-
h[:wheel_drop_left] = v & 0b1000 > 0
|
81
|
+
h[:bump_right] = v & 0b1 > 0
|
82
|
+
h[:bump_left] = v & 0b10 > 0
|
83
|
+
h[:wheel_drop_right] = v & 0b100 > 0
|
84
|
+
h[:wheel_drop_left] = v & 0b1000 > 0
|
85
85
|
h
|
86
86
|
end
|
87
87
|
|
@@ -282,15 +282,20 @@ class Rumba
|
|
282
282
|
# Get sensors by list
|
283
283
|
# Array entry can be packet ID or symbol
|
284
284
|
def get_sensors_list(list)
|
285
|
-
ids_list=
|
285
|
+
ids_list = list.map { |l|
|
286
286
|
if l.class == Symbol
|
287
287
|
SENSORS_PACKETS_SYMBOL.find_index(l)
|
288
288
|
else
|
289
289
|
l
|
290
290
|
end
|
291
|
-
|
291
|
+
}
|
292
292
|
|
293
|
-
sensors_bytes_to_packets(write_chars_with_read([QUERY_LIST,ids_list.length]+ids_list),ids_list)
|
293
|
+
sensors_bytes_to_packets(write_chars_with_read([Constants::QUERY_LIST,ids_list.length]+ids_list),ids_list)
|
294
|
+
end
|
295
|
+
|
296
|
+
# convenience method for grabbing a single sensor
|
297
|
+
def get_sensor(sensor)
|
298
|
+
get_sensors_list([sensor])[sensor]
|
294
299
|
end
|
295
300
|
end
|
296
301
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Wood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: serialport
|