I’m wondering whether there is a function to return how long a do_repeat_servo command has been active. I seem to recall one existed, but cannot find it again.
The idea is to record how much time is left in a do_repeat_servo loop should the mission be paused or terminated while this mission command is active.
To answer my own question, the function is the free-standing mission_receive() function which returns the time (millis()) when the current DO_ command is pushed into the ring buffer for the AP to handle (in AP_Scripting.cpp).
mission_receive() also returns the up-to-four parameters passed to the command. An example appears in Mission_test.lua. So, something like this (I have “constants” defined elsewhere):
local time_left = 0
local started_ms, p1, p2, p3, p4 = mission_receive()
if started_ms then
local current_do = mission:get_current_do_cmd_id()
local item = mission:get_item( current_do )
if item:command() == MAV_CMD_DO_REPEAT_SERVO and p1 == SPRAY_SERVO then
-- ms_left = ( number of reps + 1 ) * delay_s * 1000 - ( ms since start )
time_left = ( p3 + 1 ) * p4 * 1000 - ( millis() - started_ms )
end
end