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: add examples #20656

Merged
merged 1 commit into from Jul 1, 2022
Merged

Conversation

yuri-rage
Copy link
Contributor

@yuri-rage yuri-rage commented Apr 28, 2022

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

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.

All looks good.

break
end
end
return tonumber(param:get('MODE' .. mode_num))
Copy link
Member

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)

Copy link
Contributor Author

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()
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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?

#20618

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@rmackay9
Copy link
Contributor

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?

@yuri-rage
Copy link
Contributor Author

yuri-rage commented May 2, 2022

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.

@yuri-rage
Copy link
Contributor Author

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?

Done!

@rmackay9 rmackay9 merged commit f155c1b into ArduPilot:master Jul 1, 2022
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

3 participants