first of all, thanks very much for sharing and documenting your experience with px4flow! I sure appreciate it a lot!
Just two things I'd like to discuss a little bit here:
1) The sonar on the px4flow sensor.
The Maxbotix EZ4 sonar is not entirely unused since its readings is used by px4flow internally to convert the flow vectors of the images into real-world velocities. I tested the sonar using an Arduino and the readigs were actually quite accurate. It was however just a stationary test.
The test also confirmed that px4flow does output its sonar readings through i2c. It's just that those distance messages don't seem to be accepted by APM. However, there is a way for pixhawk to read the sonar outputs using this tutorial. The reading on APM seem less accurate than those of the Arduino, but I think I just need to adapt some of the parameters.
2) Optical flow
Following the hill contour has likely less to do with optical flow, but more with the sonar (extra sonar). As far as I am not mistaken, the way px4flow works is that it takes two consecutive images in a short time, tries to recognize similar features in both of them and then calculates the vectors of those features. These vectors, scaled with the distance readings, would represent your quadcopter's 2d movement in the horizontal plane, relative to the objects in the frame of the camera (which is the ground in most cases). The x and y velocity is then passed to APM, which makes control adjustments based on unwanted drift of your quad. Therefore, I think that only horizontal movements are compensated by px4flow.
Regarding the dips, maybe it was caused by some leaves flying around, blocking the sonar's direct view to the ground. Can you reproduce those dips? Be careful with your drone though, those sudden dips were quite dangerous. It is strange however that they happened exactly at 180° and 360°. Could be some software issues.
Cheers, thanks for reading and please keep updating your progress!