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

AP_Scripting: added SCR_THD_PRIORITY #25686

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

tridge
Copy link
Contributor

@tridge tridge commented Dec 3, 2023

this makes it possible to run lua scripts at higher priorities, which makes real time lua scripts (such as IMU drivers) possible
Tested with a 200Hz external AHRS driver over a UART

broken out from #25678

@tridge tridge requested a review from IamPete1 December 3, 2023 00:43
@tridge tridge changed the title AP_Scripting: AP_Scripting: added SCR_THR_PRIORITY Dec 3, 2023
@tridge tridge changed the title AP_Scripting: added SCR_THR_PRIORITY AP_Scripting: added SCR_THD_PRIORITY Dec 3, 2023
@tridge tridge force-pushed the pr-scripting-priority branch from 7e86001 to 8e05b41 Compare December 3, 2023 02:42
@IamPete1
Copy link
Member

IamPete1 commented Dec 3, 2023

This make me a little nervous in that people might change it without understanding properly. With increased priority it becomes possible for the script to prevent the flight code from doing its stuff.

Maybe once the current scripting priority is not sufficient that is a good sign that the functionality really should be in the C++.

I am a bit surprised this is needed, on H7 I have done lots of quite heavy things without issue, although in those cases I was not chasing timing.

@tridge
Copy link
Contributor Author

tridge commented Dec 3, 2023

This make me a little nervous in that people might change it without understanding properly.

thus the warnings in the parameter docs

Maybe once the current scripting priority is not sufficient that is a good sign that the functionality really should be in the C++.

that is why is did this particular driver, I did a C++ and a lua version of the same protocol. The C++ one is much faster and of course has no timing issues. The lua one works without this change, but we get frequent timing issues where the sensor data is delayed. With the SCR_THD_PRIORITY set to 5 I get no timing issues.
This is definitely an advanced option, but it does widen the scope of what you can do with scripting a lot. I think it is reasonable to offer the option for advanced users.

@Hwurzburg Hwurzburg added the WikiNeeded needs wiki update label Dec 5, 2023
@@ -132,6 +132,14 @@ const AP_Param::GroupInfo AP_Scripting::var_info[] = {
// @User: Advanced
AP_GROUPINFO("DIR_DISABLE", 9, AP_Scripting, _dir_disable, 0),

// @Param: THD_PRIORITY
// @DisplayName: Scripting thread priority
// @Description: This sets the priority of the scripting thread. This is normally set to a low priority to prevent scripts from interfering with other parts of the system. Advanced users can change this priority if scripting needs to be prioritised for realtime applications. WARNING: changing this parameter can impact the stability of your flight controller. The scipting thread priority in this parameter is chosen based on a set of system level priorities for other subsystems. It is strongly recommended that you use the lowest priority that is sufficient for your application. Note that all scripts run at the same priority, so if you raise this priority you must carefully audit all lua scripts for behaviour that does not interfere with the operation of the system.
Copy link
Contributor

@rmackay9 rmackay9 Dec 5, 2023

Choose a reason for hiding this comment

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

nitpick: normally we don't add "this sets" or "this controls" at the front of parameter descriptions because really all parameters "set" or "control" something. I'd shorten the first sentence to simply, "Priority of the scripting thread"

Copy link
Contributor

@rmackay9 rmackay9 left a comment

Choose a reason for hiding this comment

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

seems OK to me.

@tridge tridge force-pushed the pr-scripting-priority branch from 8e05b41 to 4498e51 Compare December 5, 2023 01:30
Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

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

Looks good.

this makes it possible to run lua scripts at higher priorities, which
makes real time lua scripts (such as IMU drivers) possible
@tridge tridge force-pushed the pr-scripting-priority branch from 4498e51 to 94d3e99 Compare December 14, 2023 20:26
@tridge tridge merged commit 61b3ad3 into ArduPilot:master Dec 14, 2023
88 checks passed
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.

5 participants