Skip to content

Commit

Permalink
RateControl: allow setting individual saturation flags
Browse files Browse the repository at this point in the history
This helps for more complicated cases where certain axes are controlled
through and get feedback from a different allocator.
  • Loading branch information
MaEtUgR authored and sfuhrer committed Jun 19, 2023
1 parent 957a06a commit 53b9e66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/lib/rate_control/rate_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@ void RateControl::setPidGains(const Vector3f &P, const Vector3f &I, const Vector
_gain_d = D;
}

void RateControl::setSaturationStatus(const Vector<bool, 3> &saturation_positive,
const Vector<bool, 3> &saturation_negative)
void RateControl::setSaturationStatus(const Vector3<bool> &saturation_positive,
const Vector3<bool> &saturation_negative)
{
_control_allocator_saturation_positive = saturation_positive;
_control_allocator_saturation_negative = saturation_negative;
}

void RateControl::setPositiveSaturationFlag(size_t axis, bool is_saturated)
{
if (axis < 3) {
_control_allocator_saturation_positive(axis) = is_saturated;
}
}

void RateControl::setNegativeSaturationFlag(size_t axis, bool is_saturated)
{
if (axis < 3) {
_control_allocator_saturation_negative(axis) = is_saturated;
}
}

Vector3f RateControl::update(const Vector3f &rate, const Vector3f &rate_sp, const Vector3f &angular_accel,
const float dt, const bool landed)
{
Expand Down
12 changes: 10 additions & 2 deletions src/lib/rate_control/rate_control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ class RateControl
* Set saturation status
* @param control saturation vector from control allocator
*/
void setSaturationStatus(const matrix::Vector<bool, 3> &saturation_positive,
const matrix::Vector<bool, 3> &saturation_negative);
void setSaturationStatus(const matrix::Vector3<bool> &saturation_positive,
const matrix::Vector3<bool> &saturation_negative);

/**
* Set individual saturation flags
* @param axis 0 roll, 1 pitch, 2 yaw
* @param is_saturated value to update the flag with
*/
void setPositiveSaturationFlag(size_t axis, bool is_saturated);
void setNegativeSaturationFlag(size_t axis, bool is_saturated);

/**
* Run one control loop cycle calculation
Expand Down

0 comments on commit 53b9e66

Please sign in to comment.