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
// 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)
conv_factor=(1.0/(float)(num_pixels*scaler))*2.0*tan(field_of_view/2.0);// multiply this number by altitude and pixel change to get horizontal move (in same units as altitude)
// calculate expected x,y diff due to roll and pitch change
exp_change_x=diff_roll*radians_to_pixels;
exp_change_y=-diff_pitch*radians_to_pixels;
// real estimated raw change from mouse
change_x=dx-exp_change_x;
change_y=dy-exp_change_y;
floatavg_altitude=(altitude+_last_altitude)*0.5;
// convert raw change to horizontal movement in cm
x_cm=-change_x*avg_altitude*conv_factor;// perhaps this altitude should actually be the distance to the ground? i.e. if we are very rolled over it should be longer?
y_cm=-change_y*avg_altitude*conv_factor;// for example if you are leaned over at 45 deg the ground will appear farther away and motion from opt flow sensor will be less