Class: Player::ActArray

Inherits:
Device
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ruby-player/actarray.rb

Overview

The actuator array interface provides access to an array of actuators.

Instance Attribute Summary collapse

Attributes inherited from Device

#addr

Instance Method Summary collapse

Methods inherited from Device

#send_message

Constructor Details

#initialize(dev, client) ⇒ ActArray

Returns a new instance of ActArray.



25
26
27
28
29
30
# File 'lib/ruby-player/actarray.rb', line 25

def initialize(dev, client)
  super
  @actuators = []
  @state  = { motor_state: 0 }
  @geom   = { px: 0.0, py: 0.0, pz: 0.0, proll: 0.0, ppitch: 0.0, pyaw: 0.0 }
end

Instance Attribute Details

#geomObject (readonly)

Geometry of base actarray



23
24
25
# File 'lib/ruby-player/actarray.rb', line 23

def geom
  @geom
end

#stateObject (readonly)

Returns the value of attribute state.



20
21
22
# File 'lib/ruby-player/actarray.rb', line 20

def state
  @state
end

Instance Method Details

#[](joint) ⇒ Actuator

Get single actuator

Parameters:

  • joint
    • number of actuator

Returns:



80
81
82
# File 'lib/ruby-player/actarray.rb', line 80

def [](joint)
  @actuators[joint] ||= Actuator.new(joint, self)
end

#brakes_off!ActArray

Turn off brakes all actuators

Returns:



65
66
67
68
# File 'lib/ruby-player/actarray.rb', line 65

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

#brakes_on!ActArray

Turn on brakes all actuators

Returns:



58
59
60
61
# File 'lib/ruby-player/actarray.rb', line 58

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

#eachObject



132
133
134
# File 'lib/ruby-player/actarray.rb', line 132

def each
  @actuators.each { |a| yield a }
end

#fill(hdr, msg) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/ruby-player/actarray.rb', line 136

def fill(hdr, msg)
  case hdr.subtype
  when PLAYER_ACTARRAY_DATA_STATE
    read_state(msg)
  else
    unexpected_message hdr
  end
end

#go_home!ActArray

Command to go to home position for all joints

Returns:



108
109
110
111
# File 'lib/ruby-player/actarray.rb', line 108

def go_home!
  send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_HOME, [-1].pack("N"))
  self
end

#handle_response(hdr, msg) ⇒ Object



145
146
147
148
149
150
151
152
# File 'lib/ruby-player/actarray.rb', line 145

def handle_response(hdr, msg)
  case hdr.subtype
  when PLAYER_ACTARRAY_REQ_GET_GEOM
    read_geom(msg)
  else
    unexpected_message hdr
  end
end

#power?Boolean

Check common power

Returns:

  • (Boolean)


34
35
36
# File 'lib/ruby-player/actarray.rb', line 34

def power?
  state[:motor_state] != 0
end

#power_off!ActArray

Turn off power all actuators Be careful when turning power on that the array is not obstructed from its home position in case it moves to it (common behaviour)

Returns:



51
52
53
54
# File 'lib/ruby-player/actarray.rb', line 51

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

#power_on!ActArray

Turn on power all actuators Be careful when turning power on that the array is not obstructed from its home position in case it moves to it (common behaviour)

Returns:



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

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

#query_geomActArray

Query actarray geometry

Returns:



72
73
74
75
# File 'lib/ruby-player/actarray.rb', line 72

def query_geom
  send_message(PLAYER_MSGTYPE_REQ, PLAYER_ACTARRAY_REQ_GET_GEOM)
  self
end

#set_current_all(curr) ⇒ ActArray

Command all joints to attempt to move with the given current

Parameters:

  • curr

    -current to move with

Returns:



116
117
118
119
# File 'lib/ruby-player/actarray.rb', line 116

def set_current_all(curr)
  send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_CURRENT, [-1, curr].pack("Ng"))
  self
end

#set_currents(currents) ⇒ ActArray

Tells all joints/actuators to attempt to move with the given current.

Parameters:

  • currents (Array)

Returns:



124
125
126
127
128
129
130
# File 'lib/ruby-player/actarray.rb', line 124

def set_currents(currents)
  send_message(
    PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_MULTI_CURRENT,
    ([currents.size] + currents).pack("Ng*")
  )
  self
end

#set_positions(poses) ⇒ ActArray

Tells all joints/actuators to attempt to move to the given positions.

Parameters:

  • poses (Array)

Returns:



87
88
89
90
91
92
93
# File 'lib/ruby-player/actarray.rb', line 87

def set_positions(poses)
  send_message(
    PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_MULTI_POS,
    ([poses.size] + poses).pack("Ng*")
  )
  self
end

#set_speeds(speeds) ⇒ ActArray

Tells all joints/actuators to attempt to move with the given speed.

Parameters:

  • speeds (Array)

Returns:



98
99
100
101
102
103
104
# File 'lib/ruby-player/actarray.rb', line 98

def set_speeds(speeds)
  send_message(
    PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_MULTI_SPEED,
    ([speeds.size] + speeds).pack("Ng*")
  )
  self
end