@@ -132,6 +132,25 @@ bool fastcat::Actuator::ConfigFromYaml(YAML::Node node)
132
132
if (!ParseValCheckRange (node, " smooth_factor" , smooth_factor_, -1 , 64 )) {
133
133
return false ;
134
134
}
135
+
136
+ if (ParseOptValCheckRange (node, " torque_constant" , torque_constant_, 0.0 , 999999.0 ) &&
137
+ ParseOptValCheckRange (node, " winding_resistance" , winding_resistance_, 0.0 , 999999.0 ) ) {
138
+
139
+ // Only compute power if we received both torque_constant and winding_resistance parameters
140
+ compute_power_ = true ;
141
+
142
+ // Read in brake power (if provided) to add to actuator power
143
+ if (!ParseOptValCheckRange (node, " brake_power" , brake_power_, 0.0 , 9999.0 )) {
144
+ // If not found then set to zero
145
+ brake_power_ = 0.0 ;
146
+ }
147
+
148
+ // Read in any gear ratio between the motor and encoder for power calculation
149
+ if (!ParseOptValCheckRange (node, " motor_encoder_gear_ratio" , motor_encoder_gear_ratio_, 0.0 , 9999.0 )) {
150
+ // If not found then set to 1.0
151
+ motor_encoder_gear_ratio_ = 1.0 ;
152
+ }
153
+ }
135
154
136
155
// overall_reduction must be set before using EuToCnts/CntsToEu
137
156
if (actuator_type_ == ACTUATOR_TYPE_REVOLUTE) {
@@ -221,6 +240,22 @@ bool fastcat::Actuator::Read()
221
240
state_->actuator_state .actuator_state_machine_state =
222
241
static_cast <int >(actuator_sms_);
223
242
243
+ if (compute_power_) {
244
+ double motor_velocity = fabs (state_->actuator_state .actual_velocity ) * motor_encoder_gear_ratio_;
245
+ double current = fabs (jsd_egd_state_.actual_current );
246
+
247
+ // P = R I^2 + K_T * I * \omega
248
+ state_->actuator_state .power = current *
249
+ (winding_resistance_ * current +
250
+ torque_constant_ * motor_velocity);
251
+
252
+ // Should checking, but assuming motor_on > 0 means brakes powered/disengaged
253
+ if (state_->actuator_state .motor_on )
254
+ state_->actuator_state .power += brake_power_;
255
+ }
256
+ // else
257
+ // state_->actuator_state.power = 0;
258
+
224
259
return true ;
225
260
}
226
261
0 commit comments