lib/artoo/drivers/sphero.rb in artoo-sphero-1.4.0 vs lib/artoo/drivers/sphero.rb in artoo-sphero-1.5.0
- old
+ new
@@ -14,20 +14,27 @@
COMMANDS = [:ping, :version, :bluetooth_info, :auto_reconnect,
:disable_auto_reconnect, :power_state, :sphero_sleep, :roll,
:stop, :heading, :stabilization, :color, :rgb, :set_color,
:back_led_output, :rotation_rate, :set_power_notification,
:set_data_streaming, :detect_collisions,
- :handle_message_events, :get_rgb].freeze
+ :handle_message_events, :get_rgb, :start_calibration,
+ :finish_calibration].freeze
+ def initialize(params={})
+ super
+ require_interface(:sphero)
+ end
+
# Starts drives and required connections
# Public: Starts the driver.
#
# Returns null.
def start_driver
begin
detect_collisions
+ enable_stop_on_disconnect
every(interval) do
handle_message_events
end
@@ -113,9 +120,24 @@
# Returns array of rgb values
def get_rgb
rgb = connection.user_led
[rgb.r, rgb.g, rgb.b] if rgb
+ end
+
+ # Starts calibration process by turning on back LED and turning off
+ # auto-stabilization
+ def start_calibration
+ connection.back_led_output = 127
+ connection.stabilization = false
+ end
+
+ # Finishes calibration process by setting the new heading, turning off back LED,
+ # and turning back on auto-stabilization
+ def finish_calibration
+ connection.heading = 0
+ connection.back_led_output = 0
+ connection.stabilization = true
end
private
# Publish collision events