Skip to content

Commit

Permalink
mc_pos_control: added separate velocity control setpoint slewrate for…
Browse files Browse the repository at this point in the history
… deceleration

to improve the smooth user experience while accelerating
but not have any delay when braking
  • Loading branch information
MaEtUgR committed Mar 21, 2017
1 parent 8f1e851 commit d3847c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/modules/mc_pos_control/mc_pos_control_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class MulticopterPositionControl : public control::SuperBlock
control::BlockParamFloat _manual_thr_min;
control::BlockParamFloat _manual_thr_max;
control::BlockParamFloat _manual_land_alt;
control::BlockParamFloat _deceleration_hor_max;

control::BlockDerivative _vel_x_deriv;
control::BlockDerivative _vel_y_deriv;
Expand Down Expand Up @@ -434,6 +435,7 @@ MulticopterPositionControl::MulticopterPositionControl() :
_manual_thr_min(this, "MANTHR_MIN"),
_manual_thr_max(this, "MANTHR_MAX"),
_manual_land_alt(this, "MIS_LTRMIN_ALT", false),
_deceleration_hor_max(this, "DEC_HOR_MAX", true),
_vel_x_deriv(this, "VELD"),
_vel_y_deriv(this, "VELD"),
_vel_z_deriv(this, "VELD"),
Expand Down Expand Up @@ -608,14 +610,18 @@ MulticopterPositionControl::parameters_update(bool force)
_params.vel_d(1) = v;
param_get(_params_handles.z_vel_d, &v);
_params.vel_d(2) = v;
param_get(_params_handles.xy_vel_max, &v);
_params.vel_max_xy = v;
param_get(_params_handles.z_vel_max_up, &v);
_params.vel_max_up = v;
param_get(_params_handles.z_vel_max_down, &v);
_params.vel_max_down = v;
param_get(_params_handles.xy_vel_max, &v);
_params.vel_max_xy = v;
param_get(_params_handles.xy_vel_cruise, &v);
_params.vel_cruise_xy = v;

/* make sure that vel_cruise_xy is always smaller than vel_max */
_params.vel_cruise_xy = math::min(_params.vel_cruise_xy, _params.vel_max_xy);

param_get(_params_handles.xy_ff, &v);
v = math::constrain(v, 0.0f, 1.0f);
_params.vel_ff(0) = v;
Expand All @@ -641,16 +647,6 @@ MulticopterPositionControl::parameters_update(bool force)
_params.acc_down_max = v;
param_get(_params_handles.xy_vel_man_expo, &v);
_params.xy_vel_man_expo = v;


/* make sure that vel_cruise_xy is always smaller than vel_max */
_params.vel_cruise_xy = math::min(_params.vel_cruise_xy, _params.vel_max_xy);

/*
* increase the maximum horizontal acceleration such that stopping
* within 1 s from full speed is feasible
*/
_params.acc_hor_max = math::max(_params.vel_cruise_xy, _params.acc_hor_max);
param_get(_params_handles.alt_mode, &v_i);
_params.alt_mode = v_i;

Expand Down Expand Up @@ -1348,10 +1344,17 @@ MulticopterPositionControl::vel_sp_slewrate(float dt)
math::Vector<3> acc = (_vel_sp - _vel_sp_prev) / dt;
float acc_xy_mag = sqrtf(acc(0) * acc(0) + acc(1) * acc(1));

float acc_limit = _params.acc_hor_max;

/* adapt slew rate if we are decelerating */
if (_vel * acc < 0) {
acc_limit = _deceleration_hor_max.get();
}

/* limit total horizontal acceleration */
if (acc_xy_mag > _params.acc_hor_max) {
_vel_sp(0) = _params.acc_hor_max * acc(0) / acc_xy_mag * dt + _vel_sp_prev(0);
_vel_sp(1) = _params.acc_hor_max * acc(1) / acc_xy_mag * dt + _vel_sp_prev(1);
if (acc_xy_mag > acc_limit) {
_vel_sp(0) = acc_limit * acc(0) / acc_xy_mag * dt + _vel_sp_prev(0);
_vel_sp(1) = acc_limit * acc(1) / acc_xy_mag * dt + _vel_sp_prev(1);
}

/* limit vertical acceleration */
Expand Down
12 changes: 12 additions & 0 deletions src/modules/mc_pos_control/mc_pos_control_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,18 @@ PARAM_DEFINE_FLOAT(MPC_VELD_LP, 5.0f);
*/
PARAM_DEFINE_FLOAT(MPC_ACC_HOR_MAX, 5.0f);

/**
* Maximum horizonal braking deceleration in velocity controlled modes
*
* @unit m/s/s
* @min 2.0
* @max 15.0
* @increment 1
* @decimal 2
* @group Multicopter Position Control
*/
PARAM_DEFINE_FLOAT(MPC_DEC_HOR_MAX, 10.0f);

/**
* Maximum vertical acceleration in velocity controlled modes upward
*
Expand Down

0 comments on commit d3847c0

Please sign in to comment.