Class: Artoo::Drivers::Roomba

Inherits:
Driver
  • Object
show all
Defined in:
lib/artoo/drivers/roomba.rb

Overview

The Roomba driver behaviors

Defined Under Namespace

Modules: Direction, Mode, Note, Song, Speed

Instance Attribute Summary

Attributes inherited from Driver

#parent

Instance Method Summary collapse

Methods inherited from Driver

#connection, #event_topic_name, #initialize, #interval, #method_missing, #pin, #start_driver

Methods included from Celluloid

#timers

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



73
74
75
76
# File 'lib/artoo/drivers/roomba.rb', line 73

def backwards(seconds)
  drive(Speed::NEG, Direction::STRAIGHT, seconds)
  stop if seconds > 0
end

#beepObject



126
127
128
# File 'lib/artoo/drivers/roomba.rb', line 126

def beep
  play_song([Note::G, Note::WHOLE])
end

#drive(v, r, s = 0) ⇒ Object



100
101
102
103
104
105
# File 'lib/artoo/drivers/roomba.rb', line 100

def drive(v, r, s = 0)
  vH,vL = split_bytes(v)
  rH,rL = split_bytes(r)
  send_bytes([137, vH, vL, rH, rL])
  sleep(s) if s > 0
end

#fast_forward(seconds) ⇒ Object



68
69
70
71
# File 'lib/artoo/drivers/roomba.rb', line 68

def fast_forward(seconds)
  drive(Speed::MAX, Direction::STRAIGHT, seconds)
  stop if seconds > 0
end

#forward(seconds, velocity = Speed::SLOW) ⇒ Object



59
60
61
62
# File 'lib/artoo/drivers/roomba.rb', line 59

def forward(seconds, velocity = Speed::SLOW)
  drive(velocity, Direction::STRAIGHT, seconds)
  stop if seconds > 0
end

#full_modeObject



53
54
55
56
57
# File 'lib/artoo/drivers/roomba.rb', line 53

def full_mode
  start
  send_bytes(Mode::FULL)
  sleep 0.1
end

#nudge_leftObject



78
79
80
# File 'lib/artoo/drivers/roomba.rb', line 78

def nudge_left
  turn_left(0.25)
end

#nudge_rightObject



92
93
94
# File 'lib/artoo/drivers/roomba.rb', line 92

def nudge_right
  turn_right(0.25)
end

#play(song_number = 0) ⇒ Object



111
112
113
# File 'lib/artoo/drivers/roomba.rb', line 111

def play(song_number = 0)
  send_bytes([Song::PLAY, song_number])
end

#play_song(notes, song_number = 0) ⇒ Object



121
122
123
124
# File 'lib/artoo/drivers/roomba.rb', line 121

def play_song(notes, song_number = 0)
  song(notes, song_number)
  play(song_number)
end

#safe_modeObject



47
48
49
50
51
# File 'lib/artoo/drivers/roomba.rb', line 47

def safe_mode
  start
  send_bytes(Mode::SAFE)
  sleep 0.1
end

#song(notes, song_number = 0) ⇒ Object



115
116
117
118
119
# File 'lib/artoo/drivers/roomba.rb', line 115

def song(notes, song_number = 0)
  note_group = notes.flatten.compact
  l = note_group.length / 2
  send_bytes([Song::SONG, song_number, l] + note_group)
end

#split_bytes(num) ⇒ Object



107
108
109
# File 'lib/artoo/drivers/roomba.rb', line 107

def split_bytes(num)
  [num >> 8, num & 255]
end

#startObject



42
43
44
45
# File 'lib/artoo/drivers/roomba.rb', line 42

def start
  send_bytes(Mode::START)
  sleep 0.2
end

#stopObject



64
65
66
# File 'lib/artoo/drivers/roomba.rb', line 64

def stop
  drive(Speed::ZERO, Direction::STRAIGHT)
end

#turn_aroundObject



96
97
98
# File 'lib/artoo/drivers/roomba.rb', line 96

def turn_around
  turn_left(1.6)
end

#turn_left(seconds = 1) ⇒ Object



82
83
84
85
# File 'lib/artoo/drivers/roomba.rb', line 82

def turn_left(seconds = 1)
  drive(Speed::SLOW, Direction::COUNTERCLOCKWISE, seconds)
  stop if seconds > 0
end

#turn_right(seconds = 1) ⇒ Object



87
88
89
90
# File 'lib/artoo/drivers/roomba.rb', line 87

def turn_right(seconds = 1)
  drive(Speed::SLOW, Direction::CLOCKWISE, seconds)
  stop if seconds > 0
end