I made a ballistic launch flight mode and it’s “working” as in my first tests indicate it is at least willing to do what I tell it, I think. When I shake my copter it begins to try to spin the motors to try to stabilize. I would like it to stop doing that after lets say 6 seconds OR even better after I flip an AUX switch and then resets back to checking for ballistic launch - kind of a show-proof-of-concept-mode.
This code works
So in other words I am looking for a way to execute a certain function within the run() function of a flight mode for only a certain amount of time. Trying AP_HAL::millis() and hal.scheduler->delay(300); both didn’t work for me.
Inside my flight mode definition in mode.h I privately declare the variable static uint32_t now_ms;
In the run() function in my mode_launch.cpp once a launch has been detected the variable is initialized with now_ms = AP_HAL::millis()
Later I want to use a logical check if 2000 ms have elapsed since launch if(launchDetected && AP_HAL::millis() - now_ms >= 2000)
However it never enters the loop. I think I am misunderstanding the values AP_HAL::millis() outputs and how to work with them then.
Have you tried without static declaration? Not sure about needing it…
You can use SITL simulation and add some callings to GCS_SEND_TEXT function to check if you are not entering in this loop. If it is being called by run(), it should enter (at least if you are not returning from it earlier by any condition).