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

Added functionality to prevent activating smartrtl even for disarmed … #28284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion ArduCopter/mode_smart_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

bool ModeSmartRTL::init(bool ignore_checks)
{
// Add check to prevent SmartRTL activation when disarmed
if (!motors->armed()) {
Copy link
Contributor

@rmackay9 rmackay9 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In copter we always allow users to switch to any mode while the vehicle is disarmed. We do not allow users to arm in SmartRTL though so users are forced to be in a different mode when it comes time to arm.

// Send a warning message to the GCS
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Cannot engage SmartRTL while disarmed");
return false; // Prevent initialization
}

if (g2.smart_rtl.is_active()) {
// initialise waypoint and spline controller
wp_nav->wp_and_spline_init();
Expand Down Expand Up @@ -174,8 +181,12 @@ void ModeSmartRTL::pre_land_position_run()
// save current position for use by the smart_rtl flight mode
void ModeSmartRTL::save_position()
{
const bool should_save_position = motors->armed() && (copter.flightmode->mode_number() != Mode::Number::SMART_RTL);
// Prevent saving positions when the drone is disarmed
if (!motors->armed()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've already got a "should_save_position" below so I don't think we need this extra armed check.

I suspect the issue is not that a point is being saved but that home is being saved while the vehicle is disarmed. This means that if the user moves the vehicle after arming SmartRTL may move to the original position. Could you confirm this is the issue you're seeing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is the issue i was seeing so that it should not go to smartrtl mode before arming the copter that's why i added that thanks for reviewing!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @harsh839,

OK thanks for that. I think a better solution then would be to modify the AP_SmartRTL::update() function so that it takes a "save_home" argument that is set to true if the vehicle is disarmed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually after looking at the code a bit more, I see that when the vehicle arms it calls copter.g2.smart_rtl.set_home(copter.position_ok()) so there shouldn't be any need to do what I've mentioned above.

I'm sorry @harsh839, I don't see the problem. Are you sure that you've reproduced a problem and shown that this PR fixes it? Could you please share some logs or screen shots showing the before and after?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohk i will be posting here just check my another PR which fixes #17419

return;
}

const bool should_save_position = motors->armed() && (copter.flightmode->mode_number() != Mode::Number::SMART_RTL);
copter.g2.smart_rtl.update(copter.position_ok(), should_save_position);
}

Expand Down
Loading