Class: Player::Ranger

Inherits:
Device
  • Object
show all
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] }

Examples:

ranger = robot.subscribe(:ranger, index: 0)
ranger[0].range #=> 0.2

Instance Attribute Summary collapse

Attributes inherited from Device

#addr

Instance Method Summary collapse

Methods inherited from Device

#send_message

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

#configObject (readonly)

Configuration of ranger

See Also:



27
28
29
# File 'lib/ruby-player/ranger.rb', line 27

def config
  @config
end

#geomHash (readonly)

Device geometry

Returns:

  • (Hash)

    geometry { :px, :py. :pz, :proll, :ppitch, :pyaw, :sw, :sl, :sh, :sensors => [geom of sensors] }



31
32
33
# File 'lib/ruby-player/ranger.rb', line 31

def geom
  @geom
end

Instance Method Details

#[](index) ⇒ Object

Get sensor

Parameters:

  • index (Integer)


137
138
139
# File 'lib/ruby-player/ranger.rb', line 137

def [](index)
  @sensors[index] ||= Sensor.new(index, self)
end

#eachObject



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
    unexpected_message 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
    unexpected_message hdr
  end
end

#intensity_disable!Ranger

Returns self.

Returns:



68
69
70
71
# File 'lib/ruby-player/ranger.rb', line 68

def intensity_disable!
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_INTNS, [0].pack("N"))
  self
end

#intensity_enable!Ranger

Returns self.

Returns:



62
63
64
65
# File 'lib/ruby-player/ranger.rb', line 62

def intensity_enable!
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_INTNS, [1].pack("N"))
  self
end

#power_off!Ranger

Turn off ranger

Returns:



56
57
58
59
# File 'lib/ruby-player/ranger.rb', line 56

def power_off!
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [0].pack("N")) 
  self
end

#power_on!Ranger

Turn on ranger

Returns:



49
50
51
52
# File 'lib/ruby-player/ranger.rb', line 49

def power_on!
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_POWER, [1].pack("N")) 
  self
end

#query_configRanger

Query ranger configuration

Returns:



75
76
77
78
# File 'lib/ruby-player/ranger.rb', line 75

def query_config
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_GET_CONFIG)
  self
end

#query_geomRanger

Query ranger geometry

Returns:



42
43
44
45
# File 'lib/ruby-player/ranger.rb', line 42

def query_geom
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_GET_GEOM)
  self
end

#set_config(config = {}) ⇒ Ranger

Set config of ranger

Parameters:

  • config (Hash) (defaults to: {})

    params for setup

Options Hash (config):

  • :min_angle (Object)

    start angle of scans [rad]

  • :max_angle (Object)

    end angle of scans

  • :angular_res (Object)

    scan resolution [rad]

  • :min_range (Object)

    maximum range [m]

  • :max_range (Object)

    minimum range [m]

  • :range_res (Object)

    range resolution [m]

  • :frequency (Object)

    scanning frequency [Hz]

Returns:



90
91
92
93
94
# File 'lib/ruby-player/ranger.rb', line 90

def set_config(config={})
  data = to_a_by_default(config, @config)
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_RANGER_REQ_SET_CONFIG, data.pack("G*"))
  self
end