Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d5d09c

Browse files
MaEtUgRLorenzMeier
authored andcommitted
mc_pos_control: refactor smooth takeoff call
There were two rather confusing function calls one to check if smooth takeoff needs to be ran and one that updates it. I combined them and documented the interface correctly making the parameters non-reference const floats.
1 parent 3413df1 commit 6d5d09c

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/modules/mc_pos_control/mc_pos_control_main.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,13 @@ class MulticopterPositionControl : public ModuleBase<MulticopterPositionControl>
233233
void publish_trajectory_sp(const vehicle_local_position_setpoint_s &traj);
234234

235235
/**
236-
* Checks if smooth takeoff is initiated.
237-
* @param position_setpoint_z the position setpoint in the z-Direction
238-
* @param velocity setpoint_z the velocity setpoint in the z-Direction
236+
* Update smooth takeoff setpoint ramp to bring the vehicle off the ground without step.
237+
* @param z_sp position setpoint in the z-Direction
238+
* @param vz_sp velocity setpoint in the z-Direction
239+
* @param jz_sp jerk setpoint in the z-Direction
240+
* @param min_ground_clearance minimal distance to the ground in which e.g. optical flow works correctly
239241
*/
240-
void check_for_smooth_takeoff(const float &position_setpoint_z, const float &velocity_setpoint_z,
241-
const float &jerk_sp, const vehicle_constraints_s &constraints);
242-
243-
/**
244-
* Check if smooth takeoff has ended and updates accordingly.
245-
* @param position_setpoint_z the position setpoint in the z-Direction
246-
* @param velocity setpoint_z the velocity setpoint in the z-Direction
247-
*/
248-
void update_smooth_takeoff(const float &position_setpoint_z, const float &velocity_setpoint_z);
242+
void update_smooth_takeoff(const float z_sp, const float vz_sp, const float jz_sp, const float min_ground_clearance);
249243

250244
/**
251245
* Adjust the setpoint during landing.
@@ -655,8 +649,7 @@ MulticopterPositionControl::run()
655649

656650
// do smooth takeoff after delay if there's a valid vertical velocity or position
657651
if (_spoolup_time_hysteresis.get_state() && PX4_ISFINITE(_states.position(2)) && PX4_ISFINITE(_states.velocity(2))) {
658-
check_for_smooth_takeoff(setpoint.z, setpoint.vz, setpoint.jerk_z, constraints);
659-
update_smooth_takeoff(setpoint.z, setpoint.vz);
652+
update_smooth_takeoff(setpoint.z, setpoint.vz, setpoint.jerk_z, constraints.min_distance_to_ground);
660653
}
661654

662655
// disable horizontal / yaw control during smooth takeoff and limit maximum speed upwards
@@ -987,21 +980,20 @@ MulticopterPositionControl::start_flight_task()
987980
}
988981

989982
void
990-
MulticopterPositionControl::check_for_smooth_takeoff(const float &z_sp, const float &vz_sp,
991-
const float &jerk_sp, const vehicle_constraints_s &constraints)
983+
MulticopterPositionControl::update_smooth_takeoff(const float z_sp, const float vz_sp, const float jz_sp, const float min_ground_clearance)
992984
{
993985
// Check for smooth takeoff
994986
if (_vehicle_land_detected.landed && !_in_smooth_takeoff) {
995987
// Vehicle is still landed and no takeoff was initiated yet.
996988
// Adjust for different takeoff cases.
997989
// The minimum takeoff altitude needs to be at least 20cm above minimum distance or, if valid, above minimum distance
998990
// above ground.
999-
float min_altitude = PX4_ISFINITE(constraints.min_distance_to_ground) ? (constraints.min_distance_to_ground + 0.05f) :
991+
float min_altitude = PX4_ISFINITE(min_ground_clearance) ? (min_ground_clearance + 0.05f) :
1000992
0.2f;
1001993

1002994
// takeoff was initiated through velocity setpoint
1003995
_smooth_velocity_takeoff = PX4_ISFINITE(vz_sp) && vz_sp < -0.1f;
1004-
bool jerk_triggered_takeoff = PX4_ISFINITE(jerk_sp) && jerk_sp < -FLT_EPSILON;
996+
bool jerk_triggered_takeoff = PX4_ISFINITE(jz_sp) && jz_sp < -FLT_EPSILON;
1005997
_smooth_velocity_takeoff |= jerk_triggered_takeoff;
1006998

1007999
if ((PX4_ISFINITE(z_sp) && z_sp < _states.position(2) - min_altitude) || _smooth_velocity_takeoff) {
@@ -1013,11 +1005,7 @@ MulticopterPositionControl::check_for_smooth_takeoff(const float &z_sp, const fl
10131005

10141006
}
10151007
}
1016-
}
10171008

1018-
void
1019-
MulticopterPositionControl::update_smooth_takeoff(const float &z_sp, const float &vz_sp)
1020-
{
10211009
// If in smooth takeoff, adjust setpoints based on what is valid:
10221010
// 1. position setpoint is valid -> go with takeoffspeed to specific altitude
10231011
// 2. position setpoint not valid but velocity setpoint valid: ramp up velocity

0 commit comments

Comments
 (0)