Skip to content

Commit

Permalink
[control_allocation] centralize the definition of minimum yaw margin
Browse files Browse the repository at this point in the history
  • Loading branch information
Master Chief committed Nov 20, 2024
1 parent 4817c06 commit 4ddbc87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ControlAllocationSequentialDesaturation::mixYaw()
// Change yaw acceleration to unsaturate the outputs if needed (do not change roll/pitch),
// and allow some yaw response at maximum thrust
ActuatorVector max_prev = _actuator_max;
_actuator_max += (_actuator_max - _actuator_min) * 0.15f;
_actuator_max += (_actuator_max - _actuator_min) * MINIMUM_YAW_MARGIN;
desaturateActuators(_actuator_sp, yaw);
_actuator_max = max_prev;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class ControlAllocationSequentialDesaturation: public ControlAllocationPseudoInv
void allocate() override;

void updateParameters() override;

// This is the minimum actuator yaw granted when the controller is saturated.
// In the yaw-only case where outputs are saturated, thrust is reduced by up to this amount.
static constexpr float MINIMUM_YAW_MARGIN{0.15f};
private:

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,18 @@ TEST(ControlAllocationSequentialDesaturationTest, AirmodeDisabledReducedThrustAn
allocator.allocate();

const auto &actuator_sp = allocator.getActuatorSetpoint();
// In the case of yaw saturation, thrust per motor will be reduced by the hard-coded
// magic-number yaw margin of 0.15f.
constexpr float YAW_MARGIN{0.15f}; // get this from a centralized source when available.
constexpr float YAW_DIFF_PER_MOTOR{1.0f + YAW_MARGIN - DESIRED_THRUST_Z_PER_MOTOR};
// In the case of yaw saturation, thrust per motor will be reduced by
// ControlAllocationSequentialDesaturation::MINIMUM_YAW_MARGIN.
constexpr float YAW_DIFF_PER_MOTOR{1.0f +
ControlAllocationSequentialDesaturation::MINIMUM_YAW_MARGIN - DESIRED_THRUST_Z_PER_MOTOR};
// At control set point, there will be 2 different actuator values.
constexpr float HIGH_THRUST_Z_PER_MOTOR{DESIRED_THRUST_Z_PER_MOTOR + YAW_DIFF_PER_MOTOR - YAW_MARGIN};
constexpr float LOW_THRUST_Z_PER_MOTOR{DESIRED_THRUST_Z_PER_MOTOR - YAW_DIFF_PER_MOTOR - YAW_MARGIN};
constexpr float HIGH_THRUST_Z_PER_MOTOR{
DESIRED_THRUST_Z_PER_MOTOR + YAW_DIFF_PER_MOTOR
- ControlAllocationSequentialDesaturation::MINIMUM_YAW_MARGIN};
constexpr float LOW_THRUST_Z_PER_MOTOR{
DESIRED_THRUST_Z_PER_MOTOR - YAW_DIFF_PER_MOTOR
- ControlAllocationSequentialDesaturation::MINIMUM_YAW_MARGIN};

EXPECT_NEAR(actuator_sp(0), HIGH_THRUST_Z_PER_MOTOR, EXPECT_NEAR_TOL);
EXPECT_NEAR(actuator_sp(1), HIGH_THRUST_Z_PER_MOTOR, EXPECT_NEAR_TOL);
EXPECT_NEAR(actuator_sp(2), LOW_THRUST_Z_PER_MOTOR, EXPECT_NEAR_TOL);
Expand Down

0 comments on commit 4ddbc87

Please sign in to comment.