Class: Artoo::Drivers::Maxbotix
- Inherits:
-
Driver
- Object
- Driver
- Artoo::Drivers::Maxbotix
- Defined in:
- lib/artoo/drivers/maxbotix.rb
Overview
Maxbotix ultrasonic range finder driver behaviors for Firmata
Constant Summary collapse
- COMMANDS =
[:range].freeze
Instance Attribute Summary collapse
-
#last_reading ⇒ Object
Returns the value of attribute last_reading.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Maxbotix
constructor
A new instance of Maxbotix.
-
#range ⇒ float
Last range reading in inches.
-
#range_cm ⇒ float
Last range reading in cm.
-
#start_driver ⇒ Object
Sets values to read from ultrasonic range finder and starts driver.
-
#update(value) ⇒ Object
Publishes events according to the ultrasonic rangefinder value.
Constructor Details
#initialize(params = {}) ⇒ Maxbotix
Returns a new instance of Maxbotix.
11 12 13 14 |
# File 'lib/artoo/drivers/maxbotix.rb', line 11 def initialize(params={}) @last_reading = 0.0 super end |
Instance Attribute Details
#last_reading ⇒ Object
Returns the value of attribute last_reading.
9 10 11 |
# File 'lib/artoo/drivers/maxbotix.rb', line 9 def last_reading @last_reading end |
Instance Method Details
#range ⇒ float
Returns last range reading in inches.
17 18 19 |
# File 'lib/artoo/drivers/maxbotix.rb', line 17 def range return ( 254.0 / 1024.0 ) * 2.0 * last_reading end |
#range_cm ⇒ float
Returns last range reading in cm.
22 23 24 |
# File 'lib/artoo/drivers/maxbotix.rb', line 22 def range_cm return (last_reading / 2.0) * 2.54 end |
#start_driver ⇒ Object
Sets values to read from ultrasonic range finder and starts driver
28 29 30 31 32 33 34 |
# File 'lib/artoo/drivers/maxbotix.rb', line 28 def start_driver every(interval) do update(connection.analog_read(pin)) end super end |
#update(value) ⇒ Object
Publishes events according to the ultrasonic rangefinder value
37 38 39 40 41 |
# 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 |