AP_OpticalFlow : prevent divide by zero

This commit is contained in:
priseborough 2014-11-01 10:23:24 +11:00 committed by Andrew Tridgell
parent 9ea97c1a38
commit 92e9336fe1

View File

@ -63,10 +63,17 @@ void AP_OpticalFlow_PX4::update(void)
while (::read(_fd, &report, sizeof(optical_flow_s)) == sizeof(optical_flow_s) && report.timestamp != _last_timestamp) {
_device_id = report.sensor_id;
_surface_quality = report.quality;
if (report.integration_timespan > 0) {
_flowRate.x = report.pixel_flow_x_integral / (report.integration_timespan / 1e6f); // rad/sec measured optically about the X sensor axis
_flowRate.y = report.pixel_flow_y_integral / (report.integration_timespan / 1e6f); // rad/sec measured optically about the Y sensor axis
_bodyRate.x = report.gyro_x_rate_integral / (report.integration_timespan / 1e6f); // rad/sec measured inertially about the X sensor axis
_bodyRate.y = report.gyro_y_rate_integral / (report.integration_timespan / 1e6f); // rad/sec measured inertially about the Y sensor axis
} else {
_flowRate.x = 0.0f;
_flowRate.y = 0.0f;
_bodyRate.x = 0.0f;
_bodyRate.y = 0.0f;
}
_last_timestamp = report.timestamp;
_last_update = hal.scheduler->millis();
}