Class: Artoo::Drivers::Maxbotix

Inherits:
Driver
  • Object
show all
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

Instance Method Summary collapse

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_readingObject

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

#rangefloat

Returns last range reading in inches.

Returns:

  • (float)

    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_cmfloat

Returns last range reading in cm.

Returns:

  • (float)

    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_driverObject

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