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: add examples #20656
AP_Scripting: add examples #20656
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good.
break | ||
end | ||
end | ||
return tonumber(param:get('MODE' .. mode_num)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we would cache these params, either there values or param handles. Just saves doing the lookup by string at 5hz.
Did you find you needed the tonumber
? It should always return a number (so long as it finds the param)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that's a better method for this particular script where those params are unlikely to change during runtime.
I think tonumber
was a workaround at some point but probably overcome by events and unnecessary at this point.
Can modify to suit.
return monitor, RUN_INTERVAL_MS | ||
end | ||
|
||
function mission_paused() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add pause and continue support to rover so you don't need to change mode, we just got it in copter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that the binding would be very useful!
In this particular use case, the mode switch to manual (or acro or steering mode) is very intentional, since the vehicle may be under tree cover or near a building, which can cause a poor fix, so you can drive away from the obstruction and the vehicle automatically resumes nav when the fix improves (it's pretty cool to watch!).
end | ||
end | ||
|
||
local function do_change_speed(speed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be tempted to wait for a direct binding for this one, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be value in the interim to showing this example with waypoint insertion and manipulation. I do intend to update the script when the binding is added.
I'll leave it up to you whether to include the rather "hacky" example or wait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the TerrainDetector example in favor of an upcoming PR to add the binding as suggested
Great to see these example scripts, thanks! If possible could you rename the scripts to start with "rover" if they are only to be used with Rovers? |
I will do so and re-submit with a couple of changes as requested by @IamPete1 above. |
Done! |
Adding 2 examples per discussion with @IamPete1 and relevant topic here: https://discuss.ardupilot.org/t/lua-scripting-live-stream-recording-available-on-youtube/81407
rover-MinFixType.lua changes mode to manual or hold from auto if GPS fix state is worse than RTK fixed.
rover-SaveTurns.lua adds waypoints to the current mission when activated, dropping "breadcrumbs" as vehicle position changes