This video shows automated Hover-In-Place (HIP) using the PyQuadSim Python Quadrotor Simulator with OpenCV for optical flow. This setup allows us to prototype HIP and other optical-flow-based algorithms for use with an actual optical-flow sensor like the PX4Flow.
The quadrotor is being flown over a simulated concrete floor using a FrSky R/C transmitter, allowing us to switch position-hold (HIP) on/off. The small black window shows the pitch/roll/yaw/climb demands from the transmitter. The small gray window shows the optical flow computed by OpenCV from a downward-facing 128x128-pixel vision sensor created in V-REP. (If you look carefully, you'll see that the side-to-side flow is backwards in the video. I have since corrected this problem in the online code.)
The position-hold signal is computed as the average X,Y pixel flow sampled every 16 pixels, converted to meters-per-second using trigonometry. The second part of the video shows HIP facing a "breeze" from a blower. Even without Kalman filtering or other smoothing, the optical-flow signal is sufficient to keep the vehicle more or less stationary.
This project is open source and available at
http://home.wlu.edu/~levys/software/pyquadsim/
You need to be a member of diydrones to add comments!
Comments
Thanks, Gary. Yes, the optical flow calculator I wrote takes account of altitude (a.k.a. distance):
def _velocity_meters_per_second(self, velocity_pixels_per_second, dimsize_pixels, distance_meters):
distance_pixels = (dimsize_pixels/2) / math.tan(self.perspective_angle/2)
pixels_per_meter = distance_pixels / distance_meters
return velocity_pixels_per_second / pixels_per_meter
In the video example, the perspective angle of the vision sensor is 45 degrees, and dimsize_pixels is 128. I'm hoping that someone can check my calculation here, because I derived it from my memory of high-school trig, and I could very well be wrong!
Hi Simon,
Great project.
Is your simulator also calculating relative altitude using the Optical flow and compensating according to that as well?
Best Regards,
Gary