|
|
|
@ -44,84 +44,20 @@
@@ -44,84 +44,20 @@
|
|
|
|
|
ActuatorEffectivenessMultirotor::ActuatorEffectivenessMultirotor(): |
|
|
|
|
ModuleParams(nullptr) |
|
|
|
|
{ |
|
|
|
|
parameters_updated(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
ActuatorEffectivenessMultirotor::update() |
|
|
|
|
ActuatorEffectivenessMultirotor::getEffectivenessMatrix(matrix::Matrix<float, NUM_AXES, NUM_ACTUATORS> &matrix) |
|
|
|
|
{ |
|
|
|
|
bool updated = false; |
|
|
|
|
|
|
|
|
|
// Check if parameters have changed
|
|
|
|
|
if (_parameter_update_sub.updated()) { |
|
|
|
|
if (_updated || _parameter_update_sub.updated()) { |
|
|
|
|
// clear update
|
|
|
|
|
parameter_update_s param_update; |
|
|
|
|
_parameter_update_sub.copy(¶m_update); |
|
|
|
|
|
|
|
|
|
updateParams(); |
|
|
|
|
parameters_updated(); |
|
|
|
|
|
|
|
|
|
updated = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return updated; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
matrix::Matrix<float, ActuatorEffectivenessMultirotor::NUM_AXES, ActuatorEffectivenessMultirotor::NUM_ACTUATORS> |
|
|
|
|
ActuatorEffectivenessMultirotor::computeEffectivenessMatrix(MultirotorGeometry geometry) |
|
|
|
|
{ |
|
|
|
|
matrix::Matrix<float, ActuatorEffectivenessMultirotor::NUM_AXES, ActuatorEffectivenessMultirotor::NUM_ACTUATORS> |
|
|
|
|
effectiveness; |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NUM_ROTORS_MAX; i++) { |
|
|
|
|
// Get rotor axis
|
|
|
|
|
matrix::Vector3f axis( |
|
|
|
|
geometry.rotors[i].axis_x, |
|
|
|
|
geometry.rotors[i].axis_y, |
|
|
|
|
geometry.rotors[i].axis_z |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Normalize axis
|
|
|
|
|
float axis_norm = axis.norm(); |
|
|
|
|
|
|
|
|
|
if (axis_norm > FLT_EPSILON) { |
|
|
|
|
axis /= axis_norm; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// Bad axis definition, ignore this rotor
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get rotor position
|
|
|
|
|
matrix::Vector3f position( |
|
|
|
|
geometry.rotors[i].position_x, |
|
|
|
|
geometry.rotors[i].position_y, |
|
|
|
|
geometry.rotors[i].position_z |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Get coefficients
|
|
|
|
|
float ct = geometry.rotors[i].thrust_coef; |
|
|
|
|
float km = geometry.rotors[i].moment_ratio; |
|
|
|
|
|
|
|
|
|
// Compute thrust generated by this rotor
|
|
|
|
|
matrix::Vector3f thrust = ct * axis; |
|
|
|
|
|
|
|
|
|
// Compute moment generated by this rotor
|
|
|
|
|
matrix::Vector3f moment = ct * position.cross(axis) - ct * km * axis; |
|
|
|
|
|
|
|
|
|
// Fill corresponding items in effectiveness matrix
|
|
|
|
|
for (size_t j = 0; j < 3; j++) { |
|
|
|
|
effectiveness(j, i) = moment(j); |
|
|
|
|
effectiveness(j + 3, i) = thrust(j); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return effectiveness; |
|
|
|
|
} |
|
|
|
|
_updated = false; |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
ActuatorEffectivenessMultirotor::parameters_updated() |
|
|
|
|
{ |
|
|
|
|
// Get multirotor geometry
|
|
|
|
|
MultirotorGeometry geometry = {}; |
|
|
|
|
geometry.rotors[0].position_x = _param_ca_mc_r0_px.get(); |
|
|
|
@ -196,6 +132,57 @@ ActuatorEffectivenessMultirotor::parameters_updated()
@@ -196,6 +132,57 @@ ActuatorEffectivenessMultirotor::parameters_updated()
|
|
|
|
|
geometry.rotors[7].thrust_coef = _param_ca_mc_r7_ct.get(); |
|
|
|
|
geometry.rotors[7].moment_ratio = _param_ca_mc_r7_km.get(); |
|
|
|
|
|
|
|
|
|
// Compute effectiveness matrix
|
|
|
|
|
_effectiveness = computeEffectivenessMatrix(geometry); |
|
|
|
|
computeEffectivenessMatrix(geometry, matrix); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
ActuatorEffectivenessMultirotor::computeEffectivenessMatrix(const MultirotorGeometry &geometry, |
|
|
|
|
matrix::Matrix<float, NUM_AXES, NUM_ACTUATORS> &effectiveness) |
|
|
|
|
{ |
|
|
|
|
for (size_t i = 0; i < NUM_ROTORS_MAX; i++) { |
|
|
|
|
// Get rotor axis
|
|
|
|
|
matrix::Vector3f axis( |
|
|
|
|
geometry.rotors[i].axis_x, |
|
|
|
|
geometry.rotors[i].axis_y, |
|
|
|
|
geometry.rotors[i].axis_z |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Normalize axis
|
|
|
|
|
float axis_norm = axis.norm(); |
|
|
|
|
|
|
|
|
|
if (axis_norm > FLT_EPSILON) { |
|
|
|
|
axis /= axis_norm; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// Bad axis definition, ignore this rotor
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get rotor position
|
|
|
|
|
matrix::Vector3f position( |
|
|
|
|
geometry.rotors[i].position_x, |
|
|
|
|
geometry.rotors[i].position_y, |
|
|
|
|
geometry.rotors[i].position_z |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Get coefficients
|
|
|
|
|
float ct = geometry.rotors[i].thrust_coef; |
|
|
|
|
float km = geometry.rotors[i].moment_ratio; |
|
|
|
|
|
|
|
|
|
// Compute thrust generated by this rotor
|
|
|
|
|
matrix::Vector3f thrust = ct * axis; |
|
|
|
|
|
|
|
|
|
// Compute moment generated by this rotor
|
|
|
|
|
matrix::Vector3f moment = ct * position.cross(axis) - ct * km * axis; |
|
|
|
|
|
|
|
|
|
// Fill corresponding items in effectiveness matrix
|
|
|
|
|
for (size_t j = 0; j < 3; j++) { |
|
|
|
|
effectiveness(j, i) = moment(j); |
|
|
|
|
effectiveness(j + 3, i) = thrust(j); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|