Programmatically reset the EKF

I am working on a reinforcement learning algorithm using px4 stack 1.80 and gazebo SITL as a simulator. I want to reset the UAV location at the starting point while UAV hit something(collision count plus one). when I do so the quadrotor lose the attitude control drift and go far away due to the bad state estimation, I need to reset the EKF and the drone location at the same time. how can i do so ?

@doukhi_oualid I don’t understand why you need to reset the estimator. Resetting a estimator means you need to stop flying to reinitialize the estimator.

Can’t you just feed in the network with a different reference frame?

in the console, try “ekf2 stop”, “ekf2 start”

using the console its working fine , i need to do so using python code is it possible ?

im training the quadrotor to avoid obstacles using DRL algorithm , during the training process the drone needs to hit some obstacle , at that time i need to reset the drone position to the starting point (0,0,1) , when i do so the quad drift and crash it loss the attitude and position due to the bad measurement . in my application i need to control the velocity in the body frame " mavros/setpoint_raw/local " , i thought i must reset the ekf to get the position (0,0,1) .

@doukhi_oualid As far as I understand you need to reset the estimator to generate training datasets.

I am sure you made the decision to use SITL as you see this is differently. But in my opinion, doing this in SITL is not going to be effiicient as you will run into these problems such as resetting the estimator. The whole PX4 firmware behavior starts becoming part of your plant dynamics, which will make learning more complicated and unreliable. Moreover, in order for the network to generalize, you need to be able to add noise into your dynamics which will get even harder if you do it by interacting with the firmware.

I would try and train the network in a separate more simplified world where you can randomize the dynamics with a similar high level setpoint (such as sepoint_raw/local) and try to deploy it in SITL.

I have worked on something similar not for perception, but for trajectory tracking control. If you are interested, you can look at it here. Training is done in a more simplified IDEAL world and the network is deployed to work with SITL. The deployment part is not public yet