Plane: Quadplane: move modes fully to run function

This commit is contained in:
Iampete1 2023-05-02 02:05:00 +01:00 committed by Andrew Tridgell
parent b5617a9ff8
commit 0d6d16d4e4
7 changed files with 71 additions and 17 deletions

View File

@ -392,22 +392,6 @@ void Plane::stabilize()
} }
steering_control.rudder = rudder; steering_control.rudder = rudder;
} }
#endif
} else if (control_mode == &mode_acro ||
control_mode == &mode_stabilize) {
plane.control_mode->run();
#if HAL_QUADPLANE_ENABLED
} else if (control_mode->is_vtol_mode() && !quadplane.tailsitter.in_vtol_transition(now)) {
// run controlers specific to this mode
plane.control_mode->run();
// we also stabilize using fixed wing surfaces
if (plane.control_mode->mode_number() == Mode::Number::QACRO) {
plane.mode_acro.run();
} else {
stabilize_roll();
stabilize_pitch();
}
#endif #endif
} else { } else {
plane.control_mode->run(); plane.control_mode->run();

View File

@ -32,6 +32,13 @@ void ModeQAcro::update()
*/ */
void ModeQAcro::run() void ModeQAcro::run()
{ {
const uint32_t now = AP_HAL::millis();
if (quadplane.tailsitter.in_vtol_transition(now)) {
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
Mode::run();
return;
}
if (quadplane.throttle_wait) { if (quadplane.throttle_wait) {
quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE); quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
attitude_control->set_throttle_out(0, true, 0); attitude_control->set_throttle_out(0, true, 0);
@ -64,6 +71,9 @@ void ModeQAcro::run()
// output pilot's throttle without angle boost // output pilot's throttle without angle boost
attitude_control->set_throttle_out(throttle_out, false, 10.0f); attitude_control->set_throttle_out(throttle_out, false, 10.0f);
} }
// Stabilize with fixed wing surfaces
plane.mode_acro.run();
} }
#endif #endif

View File

@ -21,9 +21,20 @@ void ModeQAutotune::update()
void ModeQAutotune::run() void ModeQAutotune::run()
{ {
const uint32_t now = AP_HAL::millis();
if (quadplane.tailsitter.in_vtol_transition(now)) {
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
Mode::run();
return;
}
#if QAUTOTUNE_ENABLED #if QAUTOTUNE_ENABLED
quadplane.qautotune.run(); quadplane.qautotune.run();
#endif #endif
// Stabilize with fixed wing surfaces
plane.stabilize_roll();
plane.stabilize_pitch();
} }
void ModeQAutotune::_exit() void ModeQAutotune::_exit()

View File

@ -24,6 +24,13 @@ void ModeQHover::update()
*/ */
void ModeQHover::run() void ModeQHover::run()
{ {
const uint32_t now = AP_HAL::millis();
if (quadplane.tailsitter.in_vtol_transition(now)) {
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
Mode::run();
return;
}
if (quadplane.throttle_wait) { if (quadplane.throttle_wait) {
quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE); quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
attitude_control->set_throttle_out(0, true, 0); attitude_control->set_throttle_out(0, true, 0);
@ -32,6 +39,10 @@ void ModeQHover::run()
} else { } else {
quadplane.hold_hover(quadplane.get_pilot_desired_climb_rate_cms()); quadplane.hold_hover(quadplane.get_pilot_desired_climb_rate_cms());
} }
// Stabilize with fixed wing surfaces
plane.stabilize_roll();
plane.stabilize_pitch();
} }
#endif #endif

View File

@ -28,6 +28,13 @@ void ModeQLoiter::update()
// run quadplane loiter controller // run quadplane loiter controller
void ModeQLoiter::run() void ModeQLoiter::run()
{ {
const uint32_t now = AP_HAL::millis();
if (quadplane.tailsitter.in_vtol_transition(now)) {
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
Mode::run();
return;
}
if (quadplane.throttle_wait) { if (quadplane.throttle_wait) {
quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE); quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
attitude_control->set_throttle_out(0, true, 0); attitude_control->set_throttle_out(0, true, 0);
@ -35,6 +42,10 @@ void ModeQLoiter::run()
pos_control->relax_z_controller(0); pos_control->relax_z_controller(0);
loiter_nav->clear_pilot_desired_acceleration(); loiter_nav->clear_pilot_desired_acceleration();
loiter_nav->init_target(); loiter_nav->init_target();
// Stabilize with fixed wing surfaces
plane.stabilize_roll();
plane.stabilize_pitch();
return; return;
} }
if (!quadplane.motors->armed()) { if (!quadplane.motors->armed()) {
@ -45,7 +56,6 @@ void ModeQLoiter::run()
loiter_nav->soften_for_landing(); loiter_nav->soften_for_landing();
} }
const uint32_t now = AP_HAL::millis();
if (now - quadplane.last_loiter_ms > 500) { if (now - quadplane.last_loiter_ms > 500) {
loiter_nav->clear_pilot_desired_acceleration(); loiter_nav->clear_pilot_desired_acceleration();
loiter_nav->init_target(); loiter_nav->init_target();
@ -112,6 +122,10 @@ void ModeQLoiter::run()
quadplane.set_climb_rate_cms(quadplane.get_pilot_desired_climb_rate_cms()); quadplane.set_climb_rate_cms(quadplane.get_pilot_desired_climb_rate_cms());
} }
quadplane.run_z_controller(); quadplane.run_z_controller();
// Stabilize with fixed wing surfaces
plane.stabilize_roll();
plane.stabilize_pitch();
} }
#endif #endif

View File

@ -86,6 +86,13 @@ void ModeQRTL::update()
*/ */
void ModeQRTL::run() void ModeQRTL::run()
{ {
const uint32_t now = AP_HAL::millis();
if (quadplane.tailsitter.in_vtol_transition(now)) {
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
Mode::run();
return;
}
switch (submode) { switch (submode) {
case SubMode::climb: { case SubMode::climb: {
// request zero velocity // request zero velocity
@ -165,6 +172,10 @@ void ModeQRTL::run()
break; break;
} }
} }
// Stabilize with fixed wing surfaces
plane.stabilize_roll();
plane.stabilize_pitch();
} }
/* /*

View File

@ -40,15 +40,28 @@ void ModeQStabilize::update()
// quadplane stabilize mode // quadplane stabilize mode
void ModeQStabilize::run() void ModeQStabilize::run()
{ {
const uint32_t now = AP_HAL::millis();
if (quadplane.tailsitter.in_vtol_transition(now)) {
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
Mode::run();
return;
}
// special check for ESC calibration in QSTABILIZE // special check for ESC calibration in QSTABILIZE
if (quadplane.esc_calibration != 0) { if (quadplane.esc_calibration != 0) {
quadplane.run_esc_calibration(); quadplane.run_esc_calibration();
plane.stabilize_roll();
plane.stabilize_pitch();
return; return;
} }
// normal QSTABILIZE mode // normal QSTABILIZE mode
float pilot_throttle_scaled = quadplane.get_pilot_throttle(); float pilot_throttle_scaled = quadplane.get_pilot_throttle();
quadplane.hold_stabilize(pilot_throttle_scaled); quadplane.hold_stabilize(pilot_throttle_scaled);
// Stabilize with fixed wing surfaces
plane.stabilize_roll();
plane.stabilize_pitch();
} }
// set the desired roll and pitch for a tailsitter // set the desired roll and pitch for a tailsitter