2012-11-28 14:32:38 -04:00
|
|
|
#ifndef __AP_OPTICALFLOW_H__
|
|
|
|
#define __AP_OPTICALFLOW_H__
|
2013-08-29 02:34:34 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-03-09 22:51:28 -04:00
|
|
|
|
|
|
|
/*
|
2012-08-17 03:20:51 -03:00
|
|
|
* AP_OpticalFlow.cpp - OpticalFlow Base Class for Ardupilot Mega
|
|
|
|
* Code by Randy Mackay. DIYDrones.com
|
|
|
|
*
|
|
|
|
* Methods:
|
2012-11-28 14:32:38 -04:00
|
|
|
* init() : initializate sensor and library.
|
|
|
|
* read : reads latest value from OpticalFlow and
|
|
|
|
* stores values in x,y, surface_quality parameter
|
|
|
|
* read_register() : reads a value from the sensor (will be
|
|
|
|
* sensor specific)
|
|
|
|
* write_register() : writes a value to one of the sensor's
|
|
|
|
* register (will be sensor specific)
|
2012-08-17 03:20:51 -03:00
|
|
|
*/
|
2012-03-09 22:51:28 -04:00
|
|
|
|
|
|
|
#include <AP_Math.h>
|
2012-09-14 08:33:08 -03:00
|
|
|
|
2012-03-09 22:51:28 -04:00
|
|
|
class AP_OpticalFlow
|
|
|
|
{
|
2012-08-17 03:20:51 -03:00
|
|
|
public:
|
2013-05-28 10:56:11 -03:00
|
|
|
// constructor
|
2012-08-17 03:20:51 -03:00
|
|
|
AP_OpticalFlow() {
|
2014-01-08 23:26:55 -04:00
|
|
|
_flags.healthy = false;
|
2012-08-17 03:20:51 -03:00
|
|
|
};
|
2013-05-28 10:56:11 -03:00
|
|
|
|
2014-01-08 23:26:55 -04:00
|
|
|
virtual void init();
|
2013-05-28 10:56:11 -03:00
|
|
|
|
2014-01-08 23:26:55 -04:00
|
|
|
// healthy - return true if the sensor is healthy
|
|
|
|
bool healthy() const { return _flags.healthy; }
|
2013-05-28 10:56:11 -03:00
|
|
|
|
2012-11-28 14:32:38 -04:00
|
|
|
// Rotation vector to transform sensor readings to the body frame.
|
2014-01-08 23:26:55 -04:00
|
|
|
void set_orientation(enum Rotation rotation);
|
2013-05-28 10:56:11 -03:00
|
|
|
|
2012-11-28 14:32:38 -04:00
|
|
|
// sets field of view of sensor
|
2014-01-08 23:26:55 -04:00
|
|
|
void set_field_of_view(const float fov) { field_of_view = fov; };
|
2013-05-28 10:56:11 -03:00
|
|
|
|
2012-11-28 14:32:38 -04:00
|
|
|
// read latest values from sensor and fill in x,y and totals.
|
2014-01-08 23:26:55 -04:00
|
|
|
virtual void update();
|
2013-05-28 10:56:11 -03:00
|
|
|
|
2012-11-28 14:32:38 -04:00
|
|
|
// updates internal lon and lat with estimation based on optical flow
|
2014-01-08 23:26:55 -04:00
|
|
|
void update_position(float roll, float pitch, float sin_yaw, float cos_yaw, float altitude);
|
2013-05-28 10:56:11 -03:00
|
|
|
|
|
|
|
// public variables
|
2014-01-08 23:26:55 -04:00
|
|
|
uint8_t surface_quality; // image quality (below 15 you can't trust the dx,dy values returned)
|
2013-05-28 10:56:11 -03:00
|
|
|
int16_t dx,dy; // rotated change in x and y position
|
|
|
|
uint32_t last_update; // millis() time of last update
|
|
|
|
float field_of_view; // field of view in Radians
|
|
|
|
|
|
|
|
// public variables for reporting purposes
|
|
|
|
float x_cm, y_cm; // x,y position in cm
|
2012-03-09 22:51:28 -04:00
|
|
|
|
|
|
|
protected:
|
2014-01-08 23:26:55 -04:00
|
|
|
|
|
|
|
struct AP_OpticalFlow_Flags {
|
|
|
|
uint8_t healthy : 1; // true if sensor is healthy
|
|
|
|
} _flags;
|
|
|
|
|
|
|
|
enum Rotation _orientation;
|
|
|
|
float conv_factor; // multiply this number by altitude and pixel change to get horizontal move (in same units as altitude)
|
2012-11-28 14:32:38 -04:00
|
|
|
float radians_to_pixels;
|
|
|
|
float _last_roll;
|
|
|
|
float _last_pitch;
|
|
|
|
float _last_altitude;
|
2012-03-09 22:51:28 -04:00
|
|
|
};
|
|
|
|
|
2011-09-17 00:38:18 -03:00
|
|
|
#include "AP_OpticalFlow_ADNS3080.h"
|
|
|
|
|
2012-03-09 22:51:28 -04:00
|
|
|
#endif
|