This is my first time using optical flow for position hold and it’s mostly good, but the drone tends to move back and forth by ~20cm slowly. I’ve tried adjusting the MPC_XY_P setting but it doesn’t seem to affect it very much when I look at the logs.
With the usual disclaimer that more information would give better background, and that I am a fairly rusty control engineer when it comes to tuning, I can make some suggestions.
I see that the noise from what I would guess is the motors (running at roughly 3000 RPM) show as vibrations on the IMU data. This is 50 Hz, which I believe is not a problem filtering out, and default filters should be doing that already.
To address the oscillations: If you don’t have excessive vibrations, and if it responds quick and firm in stabilize/altitude mode, then you can experiment with increasing MPC_XY_VEL_I_ACC (fast oscillations may be reduced by MPC_XY_VEL_D_ACC.
I like the QGC tuning interface where you can test these if you have someone that can take over in a more manual mode if it goes wrong.
Also, if you change SDLOG_PROFILE to include the High rate data, you can see better vibration related logs.
Thank you for the suggestions @Thouge, I appreciate you taking the time to offer advice!
I was planning to look at the XY_VEL and XY_ACC settings if no one had other ideas. Unfortunately, I’m running this particular UAV over Herelink which doesn’t support the better in-air tuning controls that QGC often has. That means I have to land to change a setting which can be someone time consuming
The props are running around 15,000RPM, so that makes sense that there is some noise around there. The vibrations are very low (<1m/s2) and the tuning is almost perfect, so I suspect it’s an acceleration issue. Good idea to focus on the VEL_I setting or the VEL_D one, those are good places to start!
I’ll share my results when I have a chance to test it out properly so that knowledge can be preserved!
You should also set EKF2_OF_POS_Z accurately, otherwise any roll/pitch angular velocity messes up the velocity estimate.
This is my reasoning: in the plot below you can see that the fused velocity has a lower amplitude than the flow velocity, meaning that the IMU doesn’t fully agree with the flow sensor; most likely because the apparent flow isn’t correctly compensated.