Class: Player::Actuator

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/ruby-player/actuator.rb

Overview

The actuator of actarray

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(joint, actarray) ⇒ Actuator

Returns a new instance of Actuator.



41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby-player/actuator.rb', line 41

def initialize(joint, actarray)
  @joint, @actarray = joint, actarray
  @state  = { position: 0.0, speed: 0.0, acceleration: 0.0, current: 0.0, state: 0 }
  @geom   = { type: 0, length: 0.0, 
    proll: 0.0, ppitch: 0.0, pyaw: 0.0, 
    px: 0.0, py: 0.0, pz: 0.0,
    min: 0.0, centre: 0.0, max: 0.0, home: 0.0,
    config_speed: 0.0, hasbreaks: 0
  }
end

Instance Attribute Details

#geomObject (readonly)

Geometry of actuator



39
40
41
# File 'lib/ruby-player/actuator.rb', line 39

def geom
  @geom
end

#jointInteger (readonly)

Number in actarray

Returns:

  • (Integer)


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

def joint
  @joint
end

#stateObject (readonly)

State of actuator

:position - The position of the actuator in m or rad depending on the type.

:speed - The speed of the actuator in m/s or rad/s depending on the type.

:acceleration - The acceleration of the actuator in m/s^2 or rad/s^2 depending on the type.

:current - The current of the actuator in A.

:state - The current state of the actuator. @see #idle?, #moving?, #braked?, #stalled?



36
37
38
# File 'lib/ruby-player/actuator.rb', line 36

def state
  @state
end

Instance Method Details

#accelerationFloat

The acceleration of the actuator in m/s^2 or rad/s^2 depending on the type.

Returns:

  • (Float)

See Also:



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

def acceleration
  state[:acceleration]
end

#braked?Boolean

Check braked state

Returns:

  • (Boolean)


141
142
143
# File 'lib/ruby-player/actuator.rb', line 141

def braked?
  state[:state] & PLAYER_ACTARRAY_ACTSTATE_BRAKED > 0
end

#currentFloat

The current of the actuator in A.

Returns:

  • (Float)

See Also:



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

def current
  state[:current]
end

#go_home!Actuator

Command to go to home position

Returns:



114
115
116
117
# File 'lib/ruby-player/actuator.rb', line 114

def go_home!
  @actarray.send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_HOME, [@joint].pack("N"))
  self
end

#idle?Boolean

Check idle state

Returns:

  • (Boolean)


129
130
131
# File 'lib/ruby-player/actuator.rb', line 129

def idle?
  state[:state] & PLAYER_ACTARRAY_ACTSTATE_IDLE > 0
end

#moving?Boolean

Check moving state

Returns:

  • (Boolean)


135
136
137
# File 'lib/ruby-player/actuator.rb', line 135

def moving?
  state[:state] & PLAYER_ACTARRAY_ACTSTATE_MOVING > 0
end

#positionFloat

The position of the actuator in m or rad depending on the type.

Returns:

  • (Float)

See Also:



55
56
57
# File 'lib/ruby-player/actuator.rb', line 55

def position
  state[:position]
end

#read_geom(msg) ⇒ Object



156
157
158
159
# File 'lib/ruby-player/actuator.rb', line 156

def read_geom(msg)
  data = msg.unpack("NgG6g5N")
  fill_hash!(@geom, data)
end

#read_state(msg) ⇒ Object



151
152
153
154
# File 'lib/ruby-player/actuator.rb', line 151

def read_state(msg)
  data = msg.unpack("g4N")
  fill_hash!(@state, data)
end

#set_accel_config(accel) ⇒ Actuator

Set accelelarion for a joint for all subsequent movements

Parameters:

  • accel
    • accelelarion setting in rad/s^2 or m/s^2

Returns:



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

def set_accel_config(accel)
  @actarray.send_message(PLAYER_MSGTYPE_REQ, PLAYER_ACTARRAY_REQ_ACCEL, [@joint, accel].pack("Ng"))
  self
end

#set_current(curr) ⇒ Actuator

Command a joint to attempt to move with the given current

Parameters:

  • curr

    -current to move with

Returns:



122
123
124
125
# File 'lib/ruby-player/actuator.rb', line 122

def set_current(curr)
  @actarray.send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_CURRENT, [@joint, curr].pack("Ng"))
  self
end

#set_position(pos) ⇒ Actuator

Set position for a joint

Parameters:

  • pos
    • position setting in rad or m

Returns:



99
100
101
102
# File 'lib/ruby-player/actuator.rb', line 99

def set_position(pos)
  @actarray.send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_POS, [@joint, pos].pack("Ng"))
  self
end

#set_speed(speed) ⇒ Actuator

Set speed for a joint

Parameters:

  • seepd
    • speed setting in rad/s or m/s

Returns:



107
108
109
110
# File 'lib/ruby-player/actuator.rb', line 107

def set_speed(speed)
  @actarray.send_message(PLAYER_MSGTYPE_CMD, PLAYER_ACTARRAY_CMD_SPEED, [@joint, speed].pack("Ng"))
  self
end

#set_speed_config(speed) ⇒ Actuator

Set speed for a joint for all subsequent movements

Parameters:

  • speed
    • speed setting in rad/s or m/s

Returns:



83
84
85
86
# File 'lib/ruby-player/actuator.rb', line 83

def set_speed_config(speed)
  @actarray.send_message(PLAYER_MSGTYPE_REQ, PLAYER_ACTARRAY_REQ_SPEED, [@joint, speed].pack("Ng"))
  self
end

#speedFloat

The speed of the actuator in m/s or rad/s depending on the type.

Returns:

  • (Float)

See Also:



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

def speed
  state[:speed]
end

#stalled?Boolean

Check braked state

Returns:

  • (Boolean)


147
148
149
# File 'lib/ruby-player/actuator.rb', line 147

def stalled?
  state[:state] & PLAYER_ACTARRAY_ACTSTATE_STALLED > 0
end