Hi all, I have enabled optical flow and range finder (downward facing distance sensor) on my drone and disabled the GNSS (EKF2_GPS_CTRL = 0), but I get a strange behavior and the drone seems to be “swinging”. I am attaching a log and a video showing this, do you have any takes on why that is?
I guess that the altitude instability can be fixed with some PID tuning, but I am not sure about the horizontal instability - any ideas on that?
Thanks,
~ Nick
Hi Nick
I haven’t looked at your log but some starting points for you.
- Have you correctly set the relative position of the optical flow sensor (EKF2_OF_POS_X/Y/Z)? If not set correctly, the angular-velocity correction will be faulty which will degrade the OF quality and degrade overall performance.
- Have you done some investigation if the delay is set correctly? You can start logging in a bench-setup and move the system abruptly, then compare the OF and IMU data.
- 1./2. often improve the oscillations massively. Further you can increaese EKF2_OF_N_MIN to trust the sensor a bit less and decrease MPC_XY_P to make the controller slightly less aggressive.
Hope this helps, Marco
Thanks for the tip. Will try it out and let you know
~ Nick
Hi @haumarco, I did this bench test (quite short as you see) and tried turning the drone along the z axis abruptly. This is the result I get and I interpret it like there is no delay between OF and IMU - does it make sense?
~ Nick
yes, possible. you can check sensor_combined, which is the imu topic but at a much higher rate. you can also compare the timestamps with a python script or similar. also make sure to do the other steps i mentioned
Hi @haumarco, sorry if I am coming back to you only now. I am getting back to some of these issues and I want to understand if the altitude instability is really caused by the PID tuning or by the EKF2 tuning.
I disabled OF for now and even when the drone is hovering, the altitude is not stable (there are some slow oscillations up and down). This brings me to the question: how can I tune the delay of different sensors? Is there some guidelines? I saw there is the repo for ECL replay: GitHub - PX4/PX4-ECL: Estimation & Control Library for Guidance, Navigation and Control Applications · GitHub (not maintained anymore but maybe useful).
Any takes on this?
Thannks,
Nick
Since you’re only using an optical flow sensor for positioning, measurement errors are easily propagated into the state estimate. By tuning the EKF noise parameters, you can smooth this out, although that will generally make the estimator less reactive. That’s why there is usually a tradeoff between tuning the controller and tuning the estimator.
Since you’re also seeing oscillations in altitude, you should check whether you are fusing barometer measurements or not. Additionally, are you flying high enough above the ground for ground effects to be negligible?
For delay tuning, there is unfortunately no proper guide. As I already mentioned, I would recommend performing specific “unit-test motions” (pure linear/rotational, high jerk) while recording logs, and then comparing the timestamps between measurements.
If you create some logs, I’m quite confident that an AI coding assistant of your choice could help you write a Python script for repeated analysis afterwards.
@haumarco
So, there have been some small changes on the setup:
- the OF oscillations were fixed by adding an IMU to the board as I was subscribing to it but there was none…
- I am now focusing on fixing the altitude oscillations and my understanding is that the sensors that contribute to this are: range finder, GNSS, baro. IMU and gyro used by EKF2 instances to predict the position (?)
I have 3 EKF2 instances running and the vehicle_local_position/altitude agrees with one of them (the one that is considered to be valid). But the issues are two:
- In the telemetry (on the RC) I see that the altitude reported is quite different than the real one - happens both at 3/4m altitude, but also at about 30m and the reported altitude is -20m…
- The drone oscillates in the z direction as I explained before, even while hovering (to answer you question, all tests were made at least at 2m altitude, so I can exclude ground effects I think)
Probably I do not understand everything correctly, but I thought that if a measurement gets fused it does not necessarily mean that it is used by the EKF for estimation, it still needs to pass the innovation test check (?).
My main concern now is fixing the height stability and at this point I am not sure it is related to tuning EKF2 params (delay, noise, gate) or something else - like PID.
Sorry for the long message, but I am running out of options and would really appreciate some advice.
Nick