@@ -151,7 +151,9 @@ class MulticopterPositionControl : public ModuleBase<MulticopterPositionControl>
151
151
(ParamInt<px4::params::MPC_AUTO_MODE>) _param_mpc_auto_mode,
152
152
(ParamInt<px4::params::MPC_ALT_MODE>) _param_mpc_alt_mode,
153
153
(ParamFloat<px4::params::MPC_SPOOLUP_TIME>) _param_mpc_spoolup_time, /* *< time to let motors spool up after arming */
154
- (ParamFloat<px4::params::MPC_TILTMAX_LND>) _param_mpc_tiltmax_lnd /* *< maximum tilt for landing and smooth takeoff */
154
+ (ParamFloat<px4::params::MPC_TILTMAX_LND>) _param_mpc_tiltmax_lnd, /* *< maximum tilt for landing and smooth takeoff */
155
+ (ParamFloat<px4::params::MPC_THR_HOVER>)_param_mpc_thr_hover,
156
+ (ParamFloat<px4::params::MPC_Z_VEL_P>)_param_mpc_z_vel_p
155
157
);
156
158
157
159
control::BlockDerivative _vel_x_deriv; /* *< velocity derivative in x */
@@ -358,6 +360,7 @@ MulticopterPositionControl::parameters_update(bool force)
358
360
// set trigger time for takeoff delay
359
361
_takeoff.setSpoolupTime (_param_mpc_spoolup_time.get ());
360
362
_takeoff.setTakeoffRampTime (_param_mpc_tko_ramp_t .get ());
363
+ _takeoff.generateInitialValue (_param_mpc_thr_hover.get (), _param_mpc_z_vel_p.get ());
361
364
362
365
if (_wv_controller != nullptr ) {
363
366
_wv_controller->update_parameters ();
@@ -582,7 +585,7 @@ MulticopterPositionControl::run()
582
585
}
583
586
584
587
// an update is necessary here because otherwise the takeoff state doesn't get skiped with non-altitude-controlled modes
585
- _takeoff.updateTakeoffState (_control_mode.flag_armed , _vehicle_land_detected.landed , false , - 1 .f , !_control_mode.flag_control_climb_rate_enabled );
588
+ _takeoff.updateTakeoffState (_control_mode.flag_armed , _vehicle_land_detected.landed , false , 10 .f , !_control_mode.flag_control_climb_rate_enabled );
586
589
587
590
// takeoff delay for motors to reach idle speed
588
591
if (_takeoff.getTakeoffState () >= TakeoffState::ready_for_takeoff) {
@@ -634,6 +637,30 @@ MulticopterPositionControl::run()
634
637
// check if all local states are valid and map accordingly
635
638
set_vehicle_states (setpoint.vz );
636
639
640
+ // handle smooth takeoff
641
+ _takeoff.updateTakeoffState (_control_mode.flag_armed , _vehicle_land_detected.landed , constraints.want_takeoff , constraints.speed_up , !_control_mode.flag_control_climb_rate_enabled );
642
+ constraints.speed_up = _takeoff.updateRamp (_dt, constraints.speed_up );
643
+
644
+ if (_takeoff.getTakeoffState () < TakeoffState::rampup && !PX4_ISFINITE (setpoint.thrust [2 ])) {
645
+ // we are not flying yet and need to avoid any corrections
646
+ reset_setpoint_to_nan (setpoint);
647
+ setpoint.thrust [0 ] = setpoint.thrust [1 ] = setpoint.thrust [2 ] = 0 .0f ;
648
+ // set yaw-sp to current yaw
649
+ // TODO: we need a clean way to disable yaw control
650
+ setpoint.yaw = _states.yaw ;
651
+ setpoint.yawspeed = 0 .f ;
652
+ // prevent any integrator windup
653
+ _control.resetIntegralXY ();
654
+ _control.resetIntegralZ ();
655
+ // reactivate the task which will reset the setpoint to current state
656
+ _flight_tasks.reActivate ();
657
+ }
658
+
659
+ if (_takeoff.getTakeoffState () < TakeoffState::flight && !PX4_ISFINITE (setpoint.thrust [2 ])) {
660
+ constraints.tilt = math::radians (_param_mpc_tiltmax_lnd.get ());
661
+ }
662
+
663
+
637
664
// limit altitude only if local position is valid
638
665
if (PX4_ISFINITE (_states.position (2 ))) {
639
666
limit_altitude (setpoint);
@@ -672,28 +699,6 @@ MulticopterPositionControl::run()
672
699
local_pos_sp.vz = PX4_ISFINITE (_control.getVelSp ()(2 )) ? _control.getVelSp ()(2 ) : setpoint.vz ;
673
700
_control.getThrustSetpoint ().copyTo (local_pos_sp.thrust );
674
701
675
- // handle smooth takeoff
676
- _takeoff.updateTakeoffState (_control_mode.flag_armed , _vehicle_land_detected.landed , constraints.want_takeoff , local_pos_sp.thrust [2 ], !_control_mode.flag_control_climb_rate_enabled );
677
- local_pos_sp.thrust [2 ] = _takeoff.updateThrustRamp (local_pos_sp.thrust [2 ], _dt);
678
-
679
- if (_takeoff.getTakeoffState () < TakeoffState::flight && !PX4_ISFINITE (setpoint.thrust [2 ])) {
680
- // we are not flying yet and need to avoid any corrections
681
- // set the horizontal thrust to zero
682
- local_pos_sp.thrust [0 ] = local_pos_sp.thrust [1 ] = 0 .0f ;
683
- // set yaw-sp to current yaw to avoid any corrections
684
- // TODO: we need a clean way to disable yaw control
685
- local_pos_sp.yaw = _states.yaw ;
686
- local_pos_sp.yawspeed = 0 .f ;
687
- // prevent any integrator windup
688
- _control.resetIntegralXY ();
689
- _control.resetIntegralZ ();
690
- }
691
-
692
- if (_takeoff.getTakeoffState () < TakeoffState::rampup && !PX4_ISFINITE (setpoint.thrust [2 ])) {
693
- // reactivate the task which will reset the setpoint to current state
694
- _flight_tasks.reActivate ();
695
- }
696
-
697
702
// Publish local position setpoint
698
703
// This message will be used by other modules (such as Landdetector) to determine
699
704
// vehicle intention.
0 commit comments