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: Add ability to run aero scripts from any mode #19811

Merged
merged 3 commits into from Feb 7, 2022

Conversation

Hwurzburg
Copy link
Collaborator

@Hwurzburg Hwurzburg commented Jan 16, 2022

Extends scripting nav_scripting aerobatics rate control to any mode. Current time stamped in nav_scripting structure and checked by attitude and servo(throttle) modules for age to prevent script death from retaining control.

Below is an example of a knife_edge lua script routine with angle programmed by SCR_USER5 and duration by SCR_USER6....SCR_USER1-4 should be set as 2,1,80,20 for height and pitch pid values as in plane_aerobatics.lua example.....set an rc channel to 300 to start and stop knife_edge....mode changes will exit....script stop will exit (25ms keep alive time...ie for 10ms scripts)...arming protection...( I am sure my LUA style is non-optimal...but it works to test this)

caution , do not activate trick while armed and on the ground....same as if you tried to do that manually....you wont be happy

knife_edge.lua.zip

tested along side the previous plane_aerobatics example to test co-existence...no problem (except rolling circles since USER5/6 have be co-opted for the knife-edge....easily fixed by using new local params, but I was lazy since this was just for testing)

open issue: exiting the knife-edge, the yaw jumps ~20 degrees in stabilized modes...haven't been able to figure out what I need to do in the script to fix that....resetting yaw I in C++ code does not fix...

@IamPete1
Copy link
Member

I think any mode is a bad idea. I would prefer to add support for guided only. The script can then switch to guided mode, do its stuff, and then switch back to your original mode.

@tridge
Copy link
Contributor

tridge commented Jan 16, 2022

I do want to make this possible in all modes that use the fixed wing rate controllers (but not Q modes). What I'd like to see is an API that enables this feature explicitly for the current mode. Something like this:

  • vehicle:nav_script_enable(MODE_ACRO)

this would enable the feature only for the mode specified, and it would be disabled again as soon as you change modes, so the script would have to enable it again.
The feature would always be enabled when in AUTO in a NAV_SCRIPT_TIME mission item, as per current master

@IamPete1
Copy link
Member

I really don't like the idea of breaking the rules on manual modes. In master if your in a manual mode you have control. The mode the vehicle is in tells the user what they can expect the vehicle do when they give inputs. With this change the vehicle can do whatever it likes in whatever mode and the user has no way to tell when scripting is taking control.

My preferred method would be the script looking for the user to switch into guided mode. The script then does its stuff and puts the vehicle back into the last mode when its done.

Second best would be the script looking for a aux switch, it then switches into guided itself, does its stuff and puts the mode back.

As implemented this breaks the basic assumptions of what flight modes can do.

Scripting should absolutely be allowed to do whatever it likes in guided mode, but unleashing it on all modes is asking for trouble. If the script author wants that behaviour they can switch modes from the script, we should not bake it into the API.

I see scripting as another forum of external control, just like a companion computer, I'm sure you would not suggest we allow "fly to here" from the GCS manual mode.

I do not see any advantage to allowing this in any mode vs switching to guided for a bit. Adding per mode enable bindings makes it more complex and costs more flash.

@Hwurzburg
Copy link
Collaborator Author

added the enable as requested....new lua without having to use mode checking for mode changes below:
knife_edge.lua.zip

@robustini
Copy link
Contributor

robustini commented Jan 17, 2022

@Hwurzburg thanks Henry for this implementation, I find it very useful to be able to run scripts from any mode, it would have been nice to be able to do it in MANUAL too, so the user who uses them will not be naive, this would be useful for those who use Ardupilot as a stunt aid but usually fly in MANUAL.
I am trying your script but I don't understand why it gets in the knife but doesn't do any corrections to yaw.
Am I forgetting something?
Yes, I had YAW_RATE_ENABLE at 0, it works!

@robustini
Copy link
Contributor

robustini commented Jan 17, 2022

@Hwurzburg
Copy link
Collaborator Author

Hwurzburg commented Jan 17, 2022

fyi, test script only holds heading not track

ArduPlane/Plane.h Outdated Show resolved Hide resolved
ArduPlane/commands_logic.cpp Outdated Show resolved Hide resolved
ArduPlane/Attitude.cpp Outdated Show resolved Hide resolved
ArduPlane/Attitude.cpp Outdated Show resolved Hide resolved
ArduPlane/servos.cpp Outdated Show resolved Hide resolved
@Hwurzburg
Copy link
Collaborator Author

Hwurzburg commented Jan 28, 2022

Updated C++ and added scripts for tricks on a switch....this provides a modular approach to having switch activated aerobatics tricks...arbitrarily limited selection range to 10 tricks max on the selection channel figuring one could not remember which is which with more than that...provided separate Aerobatics examples directories with README...tested extensively in SITL....can co-exist with AUTO nav_script_time missions....can easily change which modes allow scripting override...

will test in a real vehicle as soon as time permits....

@Hwurzburg Hwurzburg force-pushed the acro_tricks branch 4 times, most recently from 2238fdb to bb79526 Compare February 1, 2022 16:46
@Hwurzburg
Copy link
Collaborator Author

flight tested and video updated https://youtu.be/XD81TRRgDUM

@tridge
Copy link
Contributor

tridge commented Feb 7, 2022

I'm very happy to see this functionality, and I think the decision on what modes this should be done in should be made in the lua script, not in the C++ code. Once we have the ability to create new modes inside lua scripts I think we'll move to that, and create modes suitable for the action being performed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants