Class: Player::Power
Overview
The power interface provides access to a robot’s power subsystem
Instance Attribute Summary collapse
-
#state ⇒ Hash
readonly
Power state.
Attributes inherited from Device
Instance Method Summary collapse
-
#charging_valid? ⇒ Boolean
Check charging valid.
- #fill(hdr, msg) ⇒ Object
- #handle_response(hdr, msg) ⇒ Object
-
#initialize(addr, client) ⇒ Power
constructor
A new instance of Power.
-
#joules ⇒ Object
Energy stored [J].
-
#joules_valid? ⇒ Boolean
Check joules valid.
-
#percent ⇒ Object
Percent of full charge [%].
-
#percent_valid? ⇒ Boolean
Check perecent valid.
-
#set_charging_policy(policy = {}) ⇒ Power
Request to change the charging policy.
-
#volts ⇒ Object
Battery voltage [V].
-
#volts_valid? ⇒ Boolean
Check volts valid.
-
#watts ⇒ Object
Estimated current energy consumption (negative values) or aquisition (positive values) [W].
-
#watts_valid? ⇒ Boolean
Check watts valid.
Methods inherited from Device
Constructor Details
#initialize(addr, client) ⇒ Power
Returns a new instance of Power.
36 37 38 39 |
# File 'lib/ruby-player/power.rb', line 36 def initialize(addr, client) super @state = { valid: 0, volts: 0.0, percent: 0.0, joules: 0.0, watts: 0.0, charging: 0 } end |
Instance Attribute Details
#state ⇒ Hash (readonly)
Power state
:valid status bits. The driver will set the bits to indicate which fields it is using. Bitwise-and with PLAYER_POWER_MASK_X values to see which fields are being set.
:volts Battery voltage [V].
:percent Percent of full charge [%].
:joules Energy stored [J].
:watts Estimated current energy consumption (negative values) or aquisition (positive values) [W].
:charging Charge exchange status: if 1, the device is currently receiving charge from another energy device
34 35 36 |
# File 'lib/ruby-player/power.rb', line 34 def state @state end |
Instance Method Details
#charging_valid? ⇒ Boolean
Check charging valid
104 105 106 |
# File 'lib/ruby-player/power.rb', line 104 def charging_valid? state[:valid].to_i & PLAYER_POWER_MASK_CHARGING > 0 end |
#fill(hdr, msg) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/ruby-player/power.rb', line 108 def fill(hdr, msg) case hdr.subtype when PLAYER_POWER_DATA_STATE read_state(msg) else hdr end end |
#handle_response(hdr, msg) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/ruby-player/power.rb', line 117 def handle_response(hdr, msg) case hdr.subtype when PLAYER_POWER_REQ_SET_CHARGING_POLICY nil else hdr end end |
#joules ⇒ Object
Energy stored [J].
58 59 60 |
# File 'lib/ruby-player/power.rb', line 58 def joules state[:joules] end |
#joules_valid? ⇒ Boolean
Check joules valid
94 95 96 |
# File 'lib/ruby-player/power.rb', line 94 def joules_valid? state[:valid].to_i & PLAYER_POWER_MASK_JOULES > 0 end |
#percent ⇒ Object
Percent of full charge [%].
51 52 53 |
# File 'lib/ruby-player/power.rb', line 51 def percent state[:percent] end |
#percent_valid? ⇒ Boolean
Check perecent valid
99 100 101 |
# File 'lib/ruby-player/power.rb', line 99 def percent_valid? state[:valid].to_i & PLAYER_POWER_MASK_PERCENT > 0 end |
#set_charging_policy(policy = {}) ⇒ Power
Request to change the charging policy
74 75 76 77 78 79 80 81 |
# File 'lib/ruby-player/power.rb', line 74 def set_charging_policy(policy={}) data = [ policy[:enable_input] ? 1 : 0, policy[:enable_output] ? 1 : 0 ] (PLAYER_MSGTYPE_REQ, PLAYER_POWER_REQ_SET_CHARGING_POLICY, data.pack("NN")) self end |
#volts ⇒ Object
Battery voltage [V].
44 45 46 |
# File 'lib/ruby-player/power.rb', line 44 def volts state[:volts] end |
#volts_valid? ⇒ Boolean
Check volts valid
84 85 86 |
# File 'lib/ruby-player/power.rb', line 84 def volts_valid? state[:valid].to_i & PLAYER_POWER_MASK_VOLTS > 0 end |
#watts ⇒ Object
Estimated current energy consumption (negative values) or aquisition (positive values) [W].
65 66 67 |
# File 'lib/ruby-player/power.rb', line 65 def watts state[:watts] end |
#watts_valid? ⇒ Boolean
Check watts valid
89 90 91 |
# File 'lib/ruby-player/power.rb', line 89 def watts_valid? state[:valid].to_i & PLAYER_POWER_MASK_WATTS > 0 end |