@ -18,9 +18,9 @@ AP_OpticalFlow* AP_OpticalFlow::_sensor = NULL; // pointer to the last instanti
@@ -18,9 +18,9 @@ AP_OpticalFlow* AP_OpticalFlow::_sensor = NULL; // pointer to the last instanti
bool
AP_OpticalFlow::init(boolinitCommAPI)
{
_orientation=ROTATION_NONE;
update_conversion_factors();
returntrue;// just return true by default
_orientation=ROTATION_NONE;
update_conversion_factors();
returntrue;// just return true by default
}
// set_orientation - Rotation vector to transform sensor readings to the body frame.
// add rotated values to totals (perhaps this is pointless as we need to take into account yaw, roll, pitch)
x+=dx;
y+=dy;
// add rotated values to totals (perhaps this is pointless as we need to take into account yaw, roll, pitch)
x+=dx;
y+=dy;
}
// updatse conversion factors that are dependent upon field_of_view
void
AP_OpticalFlow::update_conversion_factors()
{
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)
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
// convert x/y movements into lon/lat movement
vlon=x_cm*sin_yaw_y+y_cm*cos_yaw_x;
vlat=y_cm*sin_yaw_y-x_cm*cos_yaw_x;
}
_last_altitude=altitude;
_last_roll=roll;
_last_pitch=pitch;
floatdiff_roll=roll-_last_roll;
floatdiff_pitch=pitch-_last_pitch;
// only update position if surface quality is good and angle is not over 45 degrees
// 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