We are trying to evolve a machine learning model to perform collision avoidance on a companion computer, using PX4’s offboard mode along with mission mode. To evolve efficiently, or even feasibly, we need to minimize the time each agent’s simulation takes to start gathering useful data. In the normal case, we have to cold start PX4, wait for preflight checks, takeoff, switch to mission mode, execute the mission, and only after all that we are able to start collecting data for the purpose of evolving the collision avoidance algorithm.
Ideally, we could start Gazebo, spawn the X500 drone in midair at takeoff altitude, and have the PX4 process start with the correct state (already in mission mode and executing). Additionally, since the first agents will crash very often, for efficiency we want to reuse the running PX4 instance and reset PX4’s state along with the pose of the X500 in Gazebo simultaneously.
We have faced a couple of problems with this approach so far. When trying to reset the pose of the X500 after a crash, PX4 cannot recover back to a loitering state on its own. Teleporting the drone back to spawn with the right orientation results in the drone crashing immediately. Also, I see some failsafes activating, specifically to do with the compass, that require the drone to land and recalibrate.
The question is, is there any feasible way to programmatically set PX4 to an arbitrary stable state at runtime without traversing the state machines fully to get there? More specifically in this case, is it possible to programmatically set PX4 to loiter or mission mode, given that I know the pose of the drone in simulation, while simultaneously setting the drone to that pose in Gazebo? Additionally, whether this is possible or not, is it more recommended to use PX4 in tight simulation loops like this, or to find a way to run high speed simulations without PX4 in the loop, and only using PX4 for validation and deployment?