FlightTask - When switching task, pass the last setpoints of the previous task to the new task

This is done to allow proper initialization of the new FlightTask and
give it a chance to continue the setpoints without discontinuity. The
function checkSetpoints replaces the setpoints containing NANs with an
estimate of the state. The estimate is usually the current estimate of
the EKF or zero.
The transition FlightTask also provides an estimate of the current
acceleration to properly initialize the next FlightTask after
back-transition. This avoid having to initialize the accelerations to
zero knowing that the actual acceleration is usually far from zero.
This commit is contained in:
bresch
2019-07-02 16:11:44 +02:00
committed by Mathieu Bresciani
parent d24c415fd7
commit 1414f50cea
28 changed files with 151 additions and 99 deletions
@@ -38,11 +38,21 @@
using namespace matrix;
bool FlightTaskManualPositionSmoothVel::activate()
bool FlightTaskManualPositionSmoothVel::activate(vehicle_local_position_setpoint_s state_prev)
{
bool ret = FlightTaskManualPosition::activate();
bool ret = FlightTaskManualPosition::activate(state_prev);
reset(Axes::XYZ);
// Check if the previous FlightTask provided setpoints
checkSetpoints(last_setpoint);
const Vector3f accel_prev(last_setpoint.acc_x, last_setpoint.acc_y, last_setpoint.acc_z);
const Vector3f vel_prev(last_setpoint.vx, last_setpoint.vy, last_setpoint.vz);
const Vector3f pos_prev(last_setpoint.x, last_setpoint.y, last_setpoint.z);
for (int i = 0; i < 3; ++i) {
_smoothing[i].reset(accel_prev(i), vel_prev(i), pos_prev(i));
}
_resetPositionLock();
return ret;
}
@@ -51,37 +61,18 @@ void FlightTaskManualPositionSmoothVel::reActivate()
{
// The task is reacivated while the vehicle is on the ground. To detect takeoff in mc_pos_control_main properly
// using the generated jerk, reset the z derivatives to zero
reset(Axes::XYZ, true);
}
void FlightTaskManualPositionSmoothVel::reset(Axes axes, bool force_z_zero)
{
int count;
switch (axes) {
case Axes::XY:
count = 2;
break;
case Axes::XYZ:
count = 3;
break;
default:
count = 0;
break;
}
// TODO: get current accel
for (int i = 0; i < count; ++i) {
for (int i = 0; i < 2; ++i) {
_smoothing[i].reset(0.f, _velocity(i), _position(i));
}
// Set the z derivatives to zero
if (force_z_zero) {
_smoothing[2].reset(0.f, 0.f, _position(2));
}
_smoothing[2].reset(0.f, 0.f, _position(2));
_initEkfResetCounters();
_resetPositionLock();
}
void FlightTaskManualPositionSmoothVel::_resetPositionLock()
{
_position_lock_xy_active = false;
_position_lock_z_active = false;
_position_setpoint_xy_locked(0) = NAN;