Skip to content

Commit

Permalink
TVC: fix unallocated torque calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch committed Jan 28, 2025
1 parent 80d98db commit 52b5d25
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class ActuatorEffectiveness
int matrix_index, ActuatorVector &actuator_sp, const matrix::Vector<float, NUM_ACTUATORS> &actuator_min,
const matrix::Vector<float, NUM_ACTUATORS> &actuator_max) {}

const ActuatorVector &getActuatorEffectivenessScale() { return _actuator_effectiveness_scale; }

/**
* Get a bitmask of motors to be stopped
*/
Expand All @@ -222,4 +224,6 @@ class ActuatorEffectiveness
protected:
FlightPhase _flight_phase{FlightPhase::HOVER_FLIGHT};
uint32_t _stopped_motors_mask{0};

ActuatorVector _actuator_effectiveness_scale;
};
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ControlAllocation
* @return Control vector
*/
matrix::Vector<float, NUM_AXES> getAllocatedControl() const
{ return (_effectiveness * (_actuator_sp - _actuator_trim)).emult(_control_allocation_scale); }
{ return (_effectiveness * (_actuator_sp - _actuator_trim).emult(_actuator_effectiveness_scale)).emult(_control_allocation_scale); }

/**
* Get the control effectiveness matrix
Expand Down Expand Up @@ -233,12 +233,15 @@ class ControlAllocation

matrix::Matrix<float, NUM_AXES, NUM_ACTUATORS> _effectiveness; ///< Effectiveness matrix
matrix::Vector<float, NUM_AXES> _control_allocation_scale; ///< Scaling applied during allocation
matrix::Vector<float, NUM_AXES> _actuator_sp_scale; ///< Scaling durectly applied to the actuator setpoint
matrix::Vector<float, NUM_ACTUATORS> _actuator_trim; ///< Neutral actuator values
matrix::Vector<float, NUM_ACTUATORS> _actuator_min; ///< Minimum actuator values
matrix::Vector<float, NUM_ACTUATORS> _actuator_max; ///< Maximum actuator values
matrix::Vector<float, NUM_ACTUATORS> _actuator_slew_rate_limit; ///< Slew rate limit
matrix::Vector<float, NUM_ACTUATORS> _prev_actuator_sp; ///< Previous actuator setpoint
matrix::Vector<float, NUM_ACTUATORS> _actuator_sp; ///< Actuator setpoint
matrix::Vector<float, NUM_ACTUATORS> _actuator_effectiveness_scale; ///< Scaling applied after inilial
///allocation (e.g.: when effectiveness changes due to airspeed or thrust)
matrix::Vector<float, NUM_AXES> _control_sp; ///< Control setpoint
matrix::Vector<float, NUM_AXES> _control_trim; ///< Control at trim actuator values
int _num_actuators{0};
Expand Down
1 change: 1 addition & 0 deletions src/modules/control_allocator/ControlAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ ControlAllocator::Run()
_actuator_effectiveness->allocateAuxilaryControls(dt, i, _control_allocation[i]->_actuator_sp); //flaps and spoilers
_actuator_effectiveness->updateSetpoint(c[i], i, _control_allocation[i]->_actuator_sp,
_control_allocation[i]->getActuatorMin(), _control_allocation[i]->getActuatorMax());
_control_allocation[i]->_actuator_effectiveness_scale = _actuator_effectiveness->getActuatorEffectivenessScale();

if (_has_slew_rate) {
_control_allocation[i]->applySlewRateLimit(dt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,17 @@ void ActuatorEffectivenessControlSurfaces::applySpoilers(float spoilers_control,
}
}

void ActuatorEffectivenessControlSurfaces::applyScale(float scale, int first_actuator_idx,
ActuatorVector &actuator_sp) const
void ActuatorEffectivenessControlSurfaces::applyEffectivenessScale(float effectiveness_scale, int first_actuator_idx,
ActuatorVector &actuator_sp, ActuatorVector &applied_effectiveness_scale) const
{
if (!PX4_ISFINITE(effectiveness_scale)) {
effectiveness_scale = 1.f;
}

const float actuator_scale = 1.f / fmaxf(effectiveness_scale, FLT_EPSILON);

for (int i = 0; i < _count; ++i) {
actuator_sp(i + first_actuator_idx) *= scale;
actuator_sp(i + first_actuator_idx) *= actuator_scale;
applied_effectiveness_scale(i + first_actuator_idx) = effectiveness_scale;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ActuatorEffectivenessControlSurfaces : public ModuleParams, public Actuato

void applyFlaps(float flaps_control, int first_actuator_idx, float dt, ActuatorVector &actuator_sp);
void applySpoilers(float spoilers_control, int first_actuator_idx, float dt, ActuatorVector &actuator_sp);
void applyScale(float scale, int first_actuator_idx, ActuatorVector &actuator_sp) const;
void applyEffectivenessScale(float scale, int first_actuator_idx, ActuatorVector &actuator_sp, ActuatorVector &applied_effectiveness_scale) const;

private:
void updateParams() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void ActuatorEffectivenessThrustVectoring::updateSetpoint(const matrix::Vector<f
}
}

constexpr float propeller_coefficient = 1.f / (20000.f * 20000.f); // scale down the thrust
float thrust = rpm * rpm * propeller_coefficient;
const float rpm_scaled = rpm / 20000.f; // scale down the thrust to keep values in a reasonable range
float thrust = rpm_scaled * rpm_scaled;

// Use thrust setpoint if there is no ESC telemetry available
if (thrust < FLT_EPSILON) {
Expand All @@ -95,6 +95,7 @@ void ActuatorEffectivenessThrustVectoring::updateSetpoint(const matrix::Vector<f
}
}

const float scale = 1.f / fmaxf(thrust, 0.2f);
_control_surfaces.applyScale(scale, _first_control_surface_idx, actuator_sp);
const float effectiveness_scale = fmaxf(thrust, 0.2f);
_control_surfaces.applyEffectivenessScale(effectiveness_scale, _first_control_surface_idx, actuator_sp,
_actuator_effectiveness_scale);
}

0 comments on commit 52b5d25

Please sign in to comment.