Class: Artoo::Drivers::Roomba
- Defined in:
- lib/artoo/drivers/roomba.rb
Overview
The Roomba driver behaviors
Defined Under Namespace
Modules: Modes
Constant Summary collapse
- STRAIGHT =
32768- CLOCKWISE =
65535- COUNTERCLOCKWISE =
1- MAX =
500- SLOW =
250- NEG =
(65536 - 250)
- ZERO =
0- B =
95- D =
98- G =
91- C =
96- A =
93- QUART =
16- HALF =
57- WHOLE =
114- START =
128
Instance Attribute Summary
Attributes inherited from Driver
Instance Method Summary collapse
- #backwards(seconds) ⇒ Object
- #beep ⇒ Object
- #drive(v, r, s = 0) ⇒ Object
- #fast_forward(seconds) ⇒ Object
- #forward(seconds, velocity = SLOW) ⇒ Object
- #full_mode ⇒ Object
- #nudge_left ⇒ Object
- #nudge_right ⇒ Object
- #safe_mode ⇒ Object
- #sing_jingle_bells ⇒ Object
- #split_bytes(num) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #turn_around ⇒ Object
- #turn_left(seconds = 1) ⇒ Object
- #turn_right(seconds = 1) ⇒ Object
Methods inherited from Driver
#connection, #event_topic_name, #initialize, #interval, #method_missing, #pin, #start_driver
Methods included from Celluloid
Constructor Details
This class inherits a constructor from Artoo::Drivers::Driver
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Artoo::Drivers::Driver
Instance Method Details
#backwards(seconds) ⇒ Object
62 63 64 65 |
# File 'lib/artoo/drivers/roomba.rb', line 62 def backwards(seconds) drive(NEG,STRAIGHT,seconds) stop if seconds > 0 end |
#beep ⇒ Object
89 90 91 92 93 |
# File 'lib/artoo/drivers/roomba.rb', line 89 def beep notes = [140,0,1,G,WHOLE] connection.send_bytes(notes) connection.send_bytes([141,0]) end |
#drive(v, r, s = 0) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/artoo/drivers/roomba.rb', line 142 def drive(v,r,s = 0) vH,vL = split_bytes(v) rH,rL = split_bytes(r) connection.send_bytes([137,vH,vL,rH,rL]) sleep(s) if s > 0 end |
#fast_forward(seconds) ⇒ Object
57 58 59 60 |
# File 'lib/artoo/drivers/roomba.rb', line 57 def fast_forward(seconds) drive(MAX,STRAIGHT,seconds) stop if seconds > 0 end |
#forward(seconds, velocity = SLOW) ⇒ Object
48 49 50 51 |
# File 'lib/artoo/drivers/roomba.rb', line 48 def forward(seconds, velocity = SLOW) drive(velocity,STRAIGHT,seconds) stop if seconds > 0 end |
#full_mode ⇒ Object
42 43 44 45 46 |
# File 'lib/artoo/drivers/roomba.rb', line 42 def full_mode start send_bytes(Modes::FULL) sleep 0.1 end |
#nudge_left ⇒ Object
67 68 69 |
# File 'lib/artoo/drivers/roomba.rb', line 67 def nudge_left turn_left(0.25) end |
#nudge_right ⇒ Object
81 82 83 |
# File 'lib/artoo/drivers/roomba.rb', line 81 def nudge_right turn_right(0.25) end |
#safe_mode ⇒ Object
36 37 38 39 40 |
# File 'lib/artoo/drivers/roomba.rb', line 36 def safe_mode start send_bytes(Modes::SAFE) sleep 0.1 end |
#sing_jingle_bells ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/artoo/drivers/roomba.rb', line 95 def sing_jingle_bells song0 = [[B,QUART],[B,QUART],[B,HALF], [B,QUART],[B,QUART],[B,HALF], [B,QUART],[D,QUART],[G,QUART],[A,QUART], [B,WHOLE]] song1 = [[C,QUART],[C,QUART],[C,QUART],[C,QUART], [C,QUART],[B,QUART],[B,HALF], [B,QUART],[A,QUART],[A,QUART],[B,QUART], [A,HALF],[D,HALF]] song2 = [[B,QUART],[B,QUART],[B,HALF], [B,QUART],[B,QUART],[B,HALF], [B,QUART],[D,QUART],[G,QUART],[A,QUART], [B,WHOLE]] song3 = [[C,QUART],[C,QUART],[C,QUART],[C,QUART], [C,QUART],[B,QUART],[B,QUART],[B,QUART], [D,QUART],[D,QUART],[C,QUART],[A,QUART], [G,WHOLE]] note_group = song0.flatten.compact l = note_group.length / 2 notes = [140,0,l] + note_group connection.send_bytes(notes) note_group = song1.flatten.compact l = note_group.length / 2 notes = [140,1,l] + note_group connection.send_bytes(notes) note_group = song2.flatten.compact l = note_group.length / 2 notes = [140,2,l] + note_group connection.send_bytes(notes) note_group = song3.flatten.compact l = note_group.length / 2 notes = [140,3,l] + note_group connection.send_bytes(notes) connection.send_bytes([141,0]) sleep(7) connection.send_bytes([141,1]) sleep(7) connection.send_bytes([141,2]) sleep(7) connection.send_bytes([141,3]) end |
#split_bytes(num) ⇒ Object
149 150 151 |
# File 'lib/artoo/drivers/roomba.rb', line 149 def split_bytes(num) [num >> 8, num & 255] end |
#start ⇒ Object
31 32 33 34 |
# File 'lib/artoo/drivers/roomba.rb', line 31 def start send_bytes(START) sleep 0.2 end |
#stop ⇒ Object
53 54 55 |
# File 'lib/artoo/drivers/roomba.rb', line 53 def stop drive(ZERO,STRAIGHT) end |
#turn_around ⇒ Object
85 86 87 |
# File 'lib/artoo/drivers/roomba.rb', line 85 def turn_around turn_left(1.6) end |
#turn_left(seconds = 1) ⇒ Object
71 72 73 74 |
# File 'lib/artoo/drivers/roomba.rb', line 71 def turn_left(seconds = 1) drive(SLOW,COUNTERCLOCKWISE,seconds) stop if seconds > 0 end |