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: Allow a Lua script to return to a previous mission track #27759

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

timtuxworth
Copy link
Contributor

@timtuxworth timtuxworth commented Aug 5, 2024

As discussed in #27639 on the dev call on 29 Aug 2024, added a way to get the previous WP location prior to switching out of AUTO mode and then restore it again after (in my case) doing some terrain object avoidance. This allows a plane to resume cross tracking mid mission which is required for magnetic field measurements in wilderness areas.

I changed the names proposed by @tridge in the call because:

  1. getting the previous WP could conceivably be used for other purposes not just cross tracking, so I'm proposing vehicle:get_previous_location() - REMOVED based on the dev call on 12 Aug 2024
  2. Restoring the previous location for crosstracking also requires setting the internal crosstrack boolean to true, so proposing to call this vehicle:set_crosstrack_start() which both sets the prev_WP_loc and also sets auto_state.crosstrack = true to resume cross tracking for the current mission item.

The sample script includes a LocationTracker() class which can be used to save previous target locations that can be passed to set_crosstrack_start()

Includes a sample lua script which requires you to be running a mission. A switch will save the previous location (high) and switch to loiter, then resume the mission and restore crosstracking (low). This screen shot shows a loiter being triggered, then switching back to crosstracking and resuming the path by crosstracking to the mission track rather than just heading direct for the next WP (WP 10).

Screenshot 2024-08-05 100641

ArduPlane/ArduPlane.cpp Outdated Show resolved Hide resolved
@timtuxworth
Copy link
Contributor Author

Tested on SITL and by Overhead Intelligence on a MFE Fighter VTOL

libraries/AP_Scripting/examples/crosstrack_restore.lua Outdated Show resolved Hide resolved
ArduPlane/ArduPlane.cpp Outdated Show resolved Hide resolved
ArduPlane/ArduPlane.cpp Outdated Show resolved Hide resolved
ArduPlane/ArduPlane.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/examples/crosstrack_restore.lua Outdated Show resolved Hide resolved
libraries/AP_Scripting/docs/docs.lua Outdated Show resolved Hide resolved
@timtuxworth timtuxworth force-pushed the pr-crosstrack-lua branch 3 times, most recently from f6490b8 to fa64426 Compare August 12, 2024 22:06
@CraigElder CraigElder changed the title Allow a Lua script to return to a previous mission track Plane: Allow a Lua script to return to a previous mission track Aug 12, 2024
ArduPlane/ArduPlane.cpp Outdated Show resolved Hide resolved
@@ -908,6 +908,50 @@ bool Plane::set_land_descent_rate(float descent_rate)
#endif
return false;
}

// allow scripts to find access prev_WP_loc
bool Plane::get_previous_location(Location &previous_location)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Pete is right that this functionality can be done in the script without a binding

@timtuxworth timtuxworth marked this pull request as draft August 13, 2024 01:31
@timtuxworth timtuxworth force-pushed the pr-crosstrack-lua branch 2 times, most recently from c82b5f3 to def8b77 Compare August 14, 2024 18:55
@timtuxworth timtuxworth marked this pull request as ready for review August 14, 2024 18:58
@timtuxworth
Copy link
Contributor Author

timtuxworth commented Aug 16, 2024

I got a CI fail on sitltest-plane. I downloaded the log but can't see the problem. Can you help @IamPete1 ? Oh found it - I'm pretty sure my code shouldn't affect this:

Failure Summary:
2024-08-14T19:53:35.4094916Z   test.Plane:
2024-08-14T19:53:35.4096328Z     DeadreckoningNoAirSpeed (Test deadreckoning support with no airspeed sensor) (GLOBAL_POSITION_INT diverged from simstate by 300.611553m (max=300.000000m) (see /tmp/buildlogs/ArduPlane-DeadreckoningNoAirSpeed.txt) (duration 7.538629055023193 s)
2024-08-14T19:53:35.4097532Z FAILED 1 tests: ['test.Plane']

@IamPete1
Copy link
Member

I got a CI fail on sitltest-plane. I downloaded the log but can't see the problem. Can you help @IamPete1 ?

I have restarted it, that test has been failing occasionally.

@timtuxworth
Copy link
Contributor Author

I got a CI fail on sitltest-plane. I downloaded the log but can't see the problem. Can you help @IamPete1 ?

I have restarted it, that test has been failing occasionally.

Is that something I can do myself?

@IamPete1
Copy link
Member

Is that something I can do myself?

Not directly, maintainers only. However, whenever you push it will restart all of CI, so you can always rebase to re-trigger everything.

@timtuxworth
Copy link
Contributor Author

Is that something I can do myself?

Not directly, maintainers only. However, whenever you push it will restart all of CI, so you can always rebase to re-trigger everything.

Thanks - looks like I need to do a rebase anyway. Are you good with the changes?

@timtuxworth
Copy link
Contributor Author

Rebased on master

@tridge tridge merged commit c2a5554 into ArduPilot:master Aug 19, 2024
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants