class Artoo::Drivers::Maxbotix
Maxbotix
ultrasonic range finder driver behaviors for Firmata
Constants
- COMMANDS
Attributes
last_reading[RW]
Public Class Methods
new(params={})
click to toggle source
Calls superclass method
# File lib/artoo/drivers/maxbotix.rb, line 11 def initialize(params={}) @last_reading = 0.0 super end
Public Instance Methods
range()
click to toggle source
@return [float] last range reading in inches
# File lib/artoo/drivers/maxbotix.rb, line 17 def range return ( 254.0 / 1024.0 ) * 2.0 * last_reading end
range_cm()
click to toggle source
@return [float] last range reading in cm
# File lib/artoo/drivers/maxbotix.rb, line 22 def range_cm return (last_reading / 2.0) * 2.54 end
start_driver()
click to toggle source
Sets values to read from ultrasonic range finder and starts driver
Calls superclass method
# File lib/artoo/drivers/maxbotix.rb, line 28 def start_driver every(interval) do update(connection.analog_read(pin)) end super end
update(value)
click to toggle source
Publishes events according to the ultrasonic rangefinder value
# File lib/artoo/drivers/maxbotix.rb, line 37 def update(value) @last_reading = value publish(event_topic_name("update"), "range", range) publish(event_topic_name("range"), range) end