Hi guys,
I have been playing with optical flow sensors these days and trying to integrate them into the current version of Copter 4.4.2. The optical flow sensor that I use is based on OpenMV Mavlink optical flow example code. OpenMV for Optical Flow — Copter documentation
I did conducted some tests with the optical flow at 100m with interesting results that I would like to share. However, by answering the questions below, I will be more confident that the result does make sense to anybody before they try to implement by themselves.
Short video showing the drone can hover with non-GPS condition https://photos.app.goo.gl/MYqRoCWYFAYsJ8PSA
Here are what I found and I need your support to answer some questions:
There are some inconsistencies between the unit and what it actually is described in the code:
Line #85
// handle optical flow msp messages
void handle_msp(const MSP::msp_opflow_data_message_t &pkt);
#endif
// quality - returns the surface quality as a measure from 0 ~ 255
uint8_t quality() const { return _state.surface_quality; }
// raw - returns the raw movement from the sensor
const Vector2f& flowRate() const { return _state.flowRate; }
// velocity - returns the velocity in m/s
const Vector2f& bodyRate() const { return _state.bodyRate; }
// last_update() - returns system time of last sensor update
uint32_t last_update() const { return _last_update_ms; }
// get_height_override() - returns the user-specified height of sensor above ground
float get_height_override() const { return _height_override; }
struct OpticalFlow_state {
uint8_t surface_quality; // image quality (below TBD you can't trust the dx,dy values returned)
the bodyReate is commented as m/s - translational velocity
However, it was rad/s in line #97
In the line #36 , the body seems to be rad/s because it captures the IMU gyro
AP_OpticalFlow_MAV *AP_OpticalFlow_MAV::detect(AP_OpticalFlow &_frontend)
{
// we assume mavlink messages will be sent into this driver
AP_OpticalFlow_MAV *sensor = new AP_OpticalFlow_MAV(_frontend);
return sensor;
}
// read latest values from sensor and fill in x,y and totals.
void AP_OpticalFlow_MAV::update(void)
{
// record gyro values as long as they are being used
// the sanity check of dt below ensures old gyro values are not used
if (gyro_sum_count < 1000) {
const Vector3f& gyro = AP::ahrs().get_gyro();
gyro_sum.x += gyro.x;
gyro_sum.y += gyro.y;
gyro_sum_count++;
}
// return without updating state if no readings
if (count == 0) {
Question #1: What is the unit of the “body rate”?
As we are trying to match the body rate flow rate, so I assume they should be the same unit. In the line #65 , the body rate is multiplied by dt:
Question #2: What the flow rate actually is: rad or rad/s
I hope @rmackay9 can have some time to take a look. Highly appreciated.