Why no get_current_do_index() in AP_Mission?

I’m looking into a state-saving function in a Lua script. Is there a reason that there is not a function analogous to get_current_nav_index() for do commands? Adding a method to AP_Mission.h would be super trivial. (Essentially, I’m trying to find the most recently started command or waypoint read for the running mission — there doesn’t seem to be a direct index.)

Thanks!

I’m almost certain that all mission items are indexed the same way. The method you mentioned should work for DO commands just as well as waypoints.

They are indexed together monotonically, but AP_Mission.cpp tracks them separately (because you can miss do commands if you reach the next nav wp first, and you can’t run do commands after the next nav command until you’ve reached it). See set_current_cmd() and advance_current_do_cmd() for example.

Sounds like there isn’t a particular reason there isn’t such a command.

I don’t know what you’re trying to do that can’t be done already. Your examples are too abstract to follow.

Sorry… I’m testing a copter sprayer, and I need to know where the copter is stopped/paused so I can turn off the sprayer and know exactly where to return to.

It may be that I am misunderstanding or misreading the design of DO_PAUSE_CONTINUE — which seems close, but does not return to the exact point (from my reading of this thread). If I could “insert” commands in the mission here, this would be close — but I would need the most recently completed nav or do mission item so that already-completed do commands are not repeated.

Mission rewinding also looks very promising, but it does not appear to account for do items (the docs page only discusses navigation commands) — and it could not rerun any items turning on the sprayer — only navigation. I would also need to turn a sprayer back on at the right location on the track (perhaps with an inserted waypoint and subsequent do?)

In other words, the goal is to rewrite the mission so that the sprayer turns on at the same location as it was stopped upon resume. Perhaps I’m thinking about this wrong…

You are still being too abstract. Give an example mission. Show any script you’re using. Provide a concrete concept of operations.

I think this is entirely achievable, possibly without any scripting at all, but it’s hard to help when there’s so little to with which to work.