Class: Artoo::Drivers::Sphero
- Inherits:
-
Driver
- Object
- Driver
- Artoo::Drivers::Sphero
- Defined in:
- lib/artoo/drivers/sphero.rb
Overview
The Sphero driver behaviors
Constant Summary collapse
- RED =
[255, 0, 0]
- GREEN =
[0, 255, 0]
- YELLOW =
[255, 255, 0]
- BLUE =
[0, 0, 255]
- WHITE =
[255, 255, 255]
- COMMANDS =
[:roll, :stop, :detect_collisions, :messages, :set_color, :color].freeze
Instance Method Summary collapse
-
#color(*colors) ⇒ Object
Retrieves color.
-
#detect_collisions(params = {}) ⇒ Object
Detects collisions.
- #handle_message_events ⇒ Object
-
#set_color(*colors) ⇒ Object
Set color.
-
#start_driver ⇒ Object
Starts drives and required connections.
Instance Method Details
#color(*colors) ⇒ Object
Retrieves color
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/artoo/drivers/sphero.rb', line 61 def color(*colors) case colors.first when :red then RED when :green then GREEN when :yellow then YELLOW when :blue then BLUE when :white then WHITE else colors end end |
#detect_collisions(params = {}) ⇒ Object
Detects collisions
49 50 51 |
# File 'lib/artoo/drivers/sphero.rb', line 49 def detect_collisions(params={}) connection.configure_collision_detection 0x01, 0x20, 0x20, 0x20, 0x20, 0x50 end |
#handle_message_events ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/artoo/drivers/sphero.rb', line 33 def while not connection..empty? do evt = connection..pop case when evt.is_a?(::Sphero::Response::CollisionDetected) handle_collision_detected(evt) when evt.is_a?(::Sphero::Response::PowerNotification) handle_power_notification(evt) when evt.is_a?(::Sphero::Response::SensorData) handle_sensor_data(evt) end end end |
#set_color(*colors) ⇒ Object
Set color
55 56 57 |
# File 'lib/artoo/drivers/sphero.rb', line 55 def set_color(*colors) connection.rgb(*color(*colors)) end |
#start_driver ⇒ Object
Starts drives and required connections
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/artoo/drivers/sphero.rb', line 17 def start_driver begin detect_collisions every(interval) do end super rescue Exception => e Logger.error "Error starting Sphero driver!" Logger.error e. Logger.error e.backtrace.inspect end end |