Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plane: move quadplane arming checks to own function and add angle max… #19178

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 69 additions & 35 deletions ArduPlane/AP_Arming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,7 @@ bool AP_Arming_Plane::pre_arm_checks(bool display_failure)
}

#if HAL_QUADPLANE_ENABLED
if (plane.quadplane.enabled() && !plane.quadplane.available()) {
check_failed(display_failure, "Quadplane enabled but not running");
ret = false;
}

if (plane.quadplane.available() && plane.scheduler.get_loop_rate_hz() < 100) {
check_failed(display_failure, "quadplane needs SCHED_LOOP_RATE >= 100");
ret = false;
}

if (plane.quadplane.available() && !plane.quadplane.motors->initialised_ok()) {
check_failed(display_failure, "Quadplane: check motor setup");
ret = false;
}

if (plane.quadplane.enabled() && plane.quadplane.available()) {
// ensure controllers are OK with us arming:
char failure_msg[50];
if (!plane.quadplane.pos_control->pre_arm_checks("PSC", failure_msg, ARRAY_SIZE(failure_msg))) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Bad parameter: %s", failure_msg);
return false;
}
if (!plane.quadplane.attitude_control->pre_arm_checks("ATC", failure_msg, ARRAY_SIZE(failure_msg))) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Bad parameter: %s", failure_msg);
return false;
}
}
ret &= quadplane_checks(display_failure);
#endif

if (plane.control_mode == &plane.mode_auto && plane.mission.num_commands() <= 1) {
Expand All @@ -120,14 +94,6 @@ bool AP_Arming_Plane::pre_arm_checks(bool display_failure)
ret = false;
}

#if HAL_QUADPLANE_ENABLED
if (plane.quadplane.enabled() && ((plane.quadplane.options & QuadPlane::OPTION_ONLY_ARM_IN_QMODE_OR_AUTO) != 0) &&
!plane.control_mode->is_vtol_mode() && (plane.control_mode != &plane.mode_auto) && (plane.control_mode != &plane.mode_guided)) {
check_failed(display_failure,"not in Q mode");
ret = false;
}
#endif

if (plane.g2.flight_options & FlightOptions::CENTER_THROTTLE_TRIM){
int16_t trim = plane.channel_throttle->get_radio_trim();
if (trim < 1250 || trim > 1750) {
Expand All @@ -139,6 +105,74 @@ bool AP_Arming_Plane::pre_arm_checks(bool display_failure)
return ret;
}

#if HAL_QUADPLANE_ENABLED
bool AP_Arming_Plane::quadplane_checks(bool display_failure)
{
if (!plane.quadplane.enabled()) {
return true;
}

if (!plane.quadplane.available()) {
check_failed(display_failure, "Quadplane enabled but not running");
return false;
}

bool ret = true;

if (plane.scheduler.get_loop_rate_hz() < 100) {
check_failed(display_failure, "quadplane needs SCHED_LOOP_RATE >= 100");
ret = false;
}

if (!plane.quadplane.motors->initialised_ok()) {
check_failed(display_failure, "Quadplane: check motor setup");
ret = false;
}

// lean angle parameter check
if (plane.quadplane.aparm.angle_max < 1000 || plane.quadplane.aparm.angle_max > 8000) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Check Q_ANGLE_MAX");
ret = false;
}

if ((plane.quadplane.tailsitter.enable > 0) && (plane.quadplane.tiltrotor.enable > 0)) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "set TAILSIT_ENABLE 0 or TILT_ENABLE 0");
ret = false;

} else {

if ((plane.quadplane.tailsitter.enable > 0) && !plane.quadplane.tailsitter.enabled()) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "tailsitter setup not complete, reboot");
ret = false;
}

if ((plane.quadplane.tiltrotor.enable > 0) && !plane.quadplane.tiltrotor.enabled()) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "tiltrotor setup not complete, reboot");
ret = false;
}
}

// ensure controllers are OK with us arming:
char failure_msg[50];
if (!plane.quadplane.pos_control->pre_arm_checks("PSC", failure_msg, ARRAY_SIZE(failure_msg))) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Bad parameter: %s", failure_msg);
ret = false;
}
if (!plane.quadplane.attitude_control->pre_arm_checks("ATC", failure_msg, ARRAY_SIZE(failure_msg))) {
check_failed(ARMING_CHECK_PARAMETERS, display_failure, "Bad parameter: %s", failure_msg);
ret = false;
}

if (((plane.quadplane.options & QuadPlane::OPTION_ONLY_ARM_IN_QMODE_OR_AUTO) != 0) &&
!plane.control_mode->is_vtol_mode() && (plane.control_mode != &plane.mode_auto) && (plane.control_mode != &plane.mode_guided)) {
check_failed(display_failure,"not in Q mode");
ret = false;
}

return ret;
}
#endif // HAL_QUADPLANE_ENABLED

bool AP_Arming_Plane::ins_checks(bool display_failure)
{
// call parent class checks
Expand Down
2 changes: 2 additions & 0 deletions ArduPlane/AP_Arming.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class AP_Arming_Plane : public AP_Arming
protected:
bool ins_checks(bool report) override;

bool quadplane_checks(bool display_failure);

private:
void change_arm_state(void);

Expand Down