Class: Player::Ranger
- Includes:
- Enumerable
- Defined in:
- lib/ruby-player/ranger.rb
Overview
The ranger proxy provides an interface to the ranger sensors built into robots TODO Implement PLAYER_RANGER_DATA_RANGESTAMPED and PLAYER_RANGER_DATA_INTNSTAMPED TODO Implement state attr => { ranges: [0.0, 0.0], intensity: [0.0, 0.0] }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Configuration of ranger.
-
#geom ⇒ Hash
readonly
Device geometry.
Attributes inherited from Device
Instance Method Summary collapse
-
#[](index) ⇒ Object
Get sensor.
- #each ⇒ Object
- #fill(hdr, msg) ⇒ Object
- #handle_response(hdr, msg) ⇒ Object
-
#initialize(addr, client) ⇒ Ranger
constructor
A new instance of Ranger.
-
#intensity_disable! ⇒ Ranger
Self.
-
#intensity_enable! ⇒ Ranger
Self.
-
#power_off! ⇒ Ranger
Turn off ranger.
-
#power_on! ⇒ Ranger
Turn on ranger.
-
#query_config ⇒ Ranger
Query ranger configuration.
-
#query_geom ⇒ Ranger
Query ranger geometry.
-
#set_config(config = {}) ⇒ Ranger
Set config of ranger.
Methods inherited from Device
Constructor Details
#initialize(addr, client) ⇒ Ranger
Returns a new instance of Ranger.
33 34 35 36 37 38 |
# File 'lib/ruby-player/ranger.rb', line 33 def initialize(addr, client) super @sensors = [] @geom = {px: 0.0, py: 0.0, pz: 0.0, proll: 0.0, ppitch: 0.0, pyaw: 0.0, sw: 0.0, sl: 0.0, sh: 0.0 } @config = { min_angle: 0.0, max_angle: 0.0, angular_res: 0.0, min_range: 0.0, max_range: 0.0, range_res: 0.0, frequecy: 0.0 } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Configuration of ranger
27 28 29 |
# File 'lib/ruby-player/ranger.rb', line 27 def config @config end |
#geom ⇒ Hash (readonly)
Device geometry
31 32 33 |
# File 'lib/ruby-player/ranger.rb', line 31 def geom @geom end |
Instance Method Details
#[](index) ⇒ Object
Get sensor
137 138 139 |
# File 'lib/ruby-player/ranger.rb', line 137 def [](index) @sensors[index] ||= Sensor.new(index, self) end |
#each ⇒ Object
141 142 143 |
# File 'lib/ruby-player/ranger.rb', line 141 def each @sensors.each { |s| yield s } end |
#fill(hdr, msg) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ruby-player/ranger.rb', line 96 def fill(hdr, msg) case hdr.subtype when PLAYER_RANGER_DATA_RANGE # TODO: remove to separate method read_range data = msg.unpack("NNG*") data[2..-1].each_with_index do |r, i| self[i].state[:range] = r end debug "Got rangers #{@sensors.collect { |s| s.state[:range] }}" when PLAYER_RANGER_DATA_INTNS # TODO: remove to separate method read_intns data = msg.unpack("NNG*") data[2..-1].each_with_index do |ints, i| self[i].state[:intensity] = ints end debug "Got intensities #{@sensors.collect { |s| s.state[:intensity]}}" when PLAYER_RANGER_DATA_GEOM read_geom(msg) else hdr end end |
#handle_response(hdr, msg) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ruby-player/ranger.rb', line 121 def handle_response(hdr, msg) case hdr.subtype when PLAYER_RANGER_REQ_GET_GEOM read_geom(msg) when 2..4 nil when PLAYER_RANGER_REQ_GET_CONFIG read_config(msg) else hdr end end |
#intensity_disable! ⇒ Ranger
Returns self.
68 69 70 71 |
# File 'lib/ruby-player/ranger.rb', line 68 def intensity_disable! (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_INTNS, [0].pack("N")) self end |
#intensity_enable! ⇒ Ranger
Returns self.
62 63 64 65 |
# File 'lib/ruby-player/ranger.rb', line 62 def intensity_enable! (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_INTNS, [1].pack("N")) self end |
#power_off! ⇒ Ranger
Turn off ranger
56 57 58 59 |
# File 'lib/ruby-player/ranger.rb', line 56 def power_off! (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [0].pack("N")) self end |
#power_on! ⇒ Ranger
Turn on ranger
49 50 51 52 |
# File 'lib/ruby-player/ranger.rb', line 49 def power_on! (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [1].pack("N")) self end |
#query_config ⇒ Ranger
Query ranger configuration
75 76 77 78 |
# File 'lib/ruby-player/ranger.rb', line 75 def query_config (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_GET_CONFIG) self end |
#query_geom ⇒ Ranger
Query ranger geometry
42 43 44 45 |
# File 'lib/ruby-player/ranger.rb', line 42 def query_geom (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_GET_GEOM) self end |
#set_config(config = {}) ⇒ Ranger
Set config of ranger
90 91 92 93 94 |
# File 'lib/ruby-player/ranger.rb', line 90 def set_config(config={}) data = to_a_by_default(config, @config) (PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_SET_CONFIG, data.pack("G*")) self end |