mpc: add possibility to generate tilt using full 3D accel

Using full 3D acceleration provides better horizontal acceleration
tracking but also creates a sometimes unwanted behavior because the tilt
is directly coupled with the vertical acceleration setpoint.
This commit is contained in:
bresch
2024-03-19 12:29:34 -04:00
committed by Daniel Agar
parent 32aa3263a6
commit 2e6dd243af
5 changed files with 30 additions and 5 deletions
@@ -204,13 +204,20 @@ void PositionControl::_velocityControl(const float dt)
void PositionControl::_accelerationControl()
{
// Assume standard acceleration due to gravity in vertical direction for attitude generation
Vector3f body_z = Vector3f(-_acc_sp(0), -_acc_sp(1), CONSTANTS_ONE_G).normalized();
float z_specific_force = -CONSTANTS_ONE_G;
if (!_decouple_horizontal_and_vertical_acceleration) {
// Include vertical acceleration setpoint for better horizontal acceleration tracking
z_specific_force += _acc_sp(2);
}
Vector3f body_z = Vector3f(-_acc_sp(0), -_acc_sp(1), -z_specific_force).normalized();
ControlMath::limitTilt(body_z, Vector3f(0, 0, 1), _lim_tilt);
// Scale thrust assuming hover thrust produces standard gravity
float collective_thrust = _acc_sp(2) * (_hover_thrust / CONSTANTS_ONE_G) - _hover_thrust;
// Convert to thrust assuming hover thrust produces standard gravity
const float thrust_ned_z = _acc_sp(2) * (_hover_thrust / CONSTANTS_ONE_G) - _hover_thrust;
// Project thrust to planned body attitude
collective_thrust /= (Vector3f(0, 0, 1).dot(body_z));
collective_thrust = math::min(collective_thrust, -_lim_thr_min);
const float cos_ned_body = (Vector3f(0, 0, 1).dot(body_z));
const float collective_thrust = math::min(thrust_ned_z / cos_ned_body, -_lim_thr_min);
_thr_sp = body_z * collective_thrust;
}
@@ -163,6 +163,11 @@ public:
*/
void resetIntegral() { _vel_int.setZero(); }
/**
* If set, the tilt setpoint is computed by assuming no vertical acceleration
*/
void decoupleHorizontalAndVecticalAcceleration(bool val) { _decouple_horizontal_and_vertical_acceleration = val; }
/**
* Get the controllers output local position setpoint
* These setpoints are the ones which were executed on including PID output and feed-forward.
@@ -211,6 +216,7 @@ private:
float _lim_tilt{}; ///< Maximum tilt from level the output attitude is allowed to have
float _hover_thrust{}; ///< Thrust [HOVER_THRUST_MIN, HOVER_THRUST_MAX] with which the vehicle hovers not accelerating down or up with level orientation
bool _decouple_horizontal_and_vertical_acceleration{false}; ///< Ignore vertical acceleration setpoint to remove its effect on the tilt setpoint
// States
matrix::Vector3f _pos; /**< current position */