Copter v3.5 crash due to altitude out of control

After I moved from ardupilot v3.3 to v3.5, I found the altitude is not stable when optical flow is turned on. I got a few crashes when the copter thinks its estimated altitude is higher than the actual one. I also got rapid flying upward when the opposite happens. I was able to reproduce the issue a couple of times when I removed the propellers, but it seems random. I attached one case below for reference. copter_v35_ooc.log (194.4 KB)

I also found that the altitude in v3.5 would change a lot if I shake the copter, but it does not happen in v3.3. Please see the v3.5 logs here:
copter_v35_bad_alt.log (1.1 MB)

I really appreciate if someone can look into this issue.

Here is the v3.3 log for the same copter:
copter_v33_good_alt.log (285.6 KB)

I could not post this one in the previous message due to the two attachment limit

Although the Vibes don’t look too bad, the IMUacc shows vibrations, which will definitely cause altitude fluctuations.

However the RCout shows motors 2, 3 & 4 at nearly maximum output while 1 is barely above idle.
Under powered?
Out of balance?

Your Baro readings just appear to be noise and don’t seem to relate to altitude at all.
Do you have your Baro covered?
is it operational?
There is no GPS in the log, do you have one?

There just seems to be a lot of noise in the logs.
Here is your Amps showing large spikes.
Have you autotuned this copter?
Do the motors ‘pulse’ in flight?

Hi, Mike,

Thanks for looking into the issue. The imu acc vibrations were caused by me shaking the copter. What I wanted to show was that the altitude was ok with v3.3, but jumps out of control with v3.5 under the same test condition (by shaking the copter).

If I turned off optical flow, v3.5 works fine (altitude will not jump around by shaking the copter). I’m using ekf2 and suspect it’s the root cause, but I cannot pin down the specific line of code in the optical flow fusion cpp file.