AP_OpticalFlow*AP_OpticalFlow::_sensor=NULL;// pointer to the last instantiated optical flow sensor. Will be turned into a table if we ever add support for more than one sensor
uint8_tAP_OpticalFlow::_num_calls;// number of times we have been called by 1khz timer process. We use this to throttle read down to 20hz
// init - initCommAPI parameter controls whether I2C/SPI interface is initialised (set to false if other devices are on the I2C/SPI bus and have already initialised the interface)
#define AP_OPTICALFLOW_NUM_CALLS_FOR_10HZ 100 // timer process runs at 1khz. 100 iterations = 10hz
#define AP_OPTICALFLOW_NUM_CALLS_FOR_20HZ 50 // timer process runs at 1khz. 50 iterations = 20hz
#define AP_OPTICALFLOW_NUM_CALLS_FOR_50HZ 20 // timer process runs at 1khz. 20 iterations = 50hz
classAP_OpticalFlow
{
...
...
@@ -44,17 +49,13 @@ public:
~AP_OpticalFlow(){
_sensor=NULL;
};
virtualboolinit(boolinitCommAPI=true);// parameter controls whether I2C/SPI interface is initialised (set to false if other devices are on the I2C/SPI bus and have already initialised the interface)
virtualboolinit(boolinitCommAPI,AP_PeriodicProcess*scheduler);// parameter controls whether I2C/SPI interface is initialised (set to false if other devices are on the I2C/SPI bus and have already initialised the interface)
virtualbyteread_register(byteaddress);
virtualvoidwrite_register(byteaddress,bytevalue);
virtualvoidset_orientation(enumRotationrotation);// Rotation vector to transform sensor readings to the body frame.
virtualvoidset_field_of_view(constfloatfov){
field_of_view=fov;update_conversion_factors();
};// sets field of view of sensor
staticvoidread(uint32_t){
if(_sensor!=NULL)_sensor->update();
};// call to update all attached sensors
virtualboolupdate();// read latest values from sensor and fill in x,y and totals. returns true on success
virtualvoidset_field_of_view(constfloatfov){field_of_view=fov;update_conversion_factors();};// sets field of view of sensor
staticvoidread(uint32_tnow);// called by timer process to read sensor data from all attached sensors
virtualvoidupdate(uint32_tnow);// read latest values from sensor and fill in x,y and totals.
virtualvoidupdate_position(floatroll,floatpitch,floatcos_yaw_x,floatsin_yaw_y,floataltitude);// updates internal lon and lat with estimation based on optical flow
protected:
...
...
@@ -65,9 +66,11 @@ protected:
float_last_roll,_last_pitch,_last_altitude;
virtualvoidapply_orientation_matrix();// rotate raw values to arrive at final x,y,dx and dy values
virtualvoidupdate_conversion_factors();
private:
staticuint8_t_num_calls;// number of times we have been called by 1khz timer process. We use this to throttle read down to 20hz