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
|
|
|
* ADC.cpp - Analog Digital Converter Base Class for Ardupilot Mega
|
|
|
|
* Code by James Goppert. DIYDrones.com
|
|
|
|
*
|
|
|
|
*/
|
2012-03-09 22:51:28 -04:00
|
|
|
|
|
|
|
#include "AP_OpticalFlow.h"
|
|
|
|
|
2013-01-10 14:42:24 -04:00
|
|
|
#define FORTYFIVE_DEGREES 0.78539816f
|
2012-03-09 22:51:28 -04:00
|
|
|
|
2012-11-28 14:32:38 -04:00
|
|
|
// set_orientation - Rotation vector to transform sensor readings to the body
|
|
|
|
// frame.
|
|
|
|
void AP_OpticalFlow::set_orientation(enum Rotation rotation)
|
2012-03-09 22:51:28 -04:00
|
|
|
{
|
2012-03-09 22:57:06 -04:00
|
|
|
_orientation = rotation;
|
2012-03-09 22:51:28 -04:00
|
|
|
}
|
|
|
|
|
2014-02-07 22:51:49 -04:00
|
|
|
void AP_OpticalFlow::update()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AP_OpticalFlow::init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-09 22:51:28 -04:00
|
|
|
// updates internal lon and lat with estimation based on optical flow
|
2014-01-08 23:26:55 -04:00
|
|
|
void AP_OpticalFlow::update_position(float roll, float pitch, float sin_yaw, float cos_yaw, float altitude)
|
2012-03-09 22:51:28 -04:00
|
|
|
{
|
2012-08-17 03:20:51 -03:00
|
|
|
float diff_roll = roll - _last_roll;
|
|
|
|
float diff_pitch = pitch - _last_pitch;
|
2014-02-10 00:53:01 -04:00
|
|
|
float change_x, change_y; // actual change in x, y coordinates
|
2012-08-17 03:20:51 -03:00
|
|
|
|
2012-11-28 14:32:38 -04:00
|
|
|
// only update position if surface quality is good and angle is not
|
|
|
|
// over 45 degrees
|
2013-01-10 14:42:24 -04:00
|
|
|
if( surface_quality >= 10 && fabsf(roll) <= FORTYFIVE_DEGREES
|
|
|
|
&& fabsf(pitch) <= FORTYFIVE_DEGREES ) {
|
2014-02-10 00:53:01 -04:00
|
|
|
altitude = max(altitude, 0);
|
2012-08-17 03:20:51 -03:00
|
|
|
|
2014-02-10 00:53:01 -04:00
|
|
|
// change in position is actual change measured by sensor (i.e. dx, dy) minus expected change due to change in roll, pitch
|
|
|
|
change_x = dx - (diff_roll * radians_to_pixels);
|
|
|
|
change_y = dy - (-diff_pitch * radians_to_pixels);
|
2012-08-17 03:20:51 -03:00
|
|
|
|
2013-01-10 14:42:24 -04:00
|
|
|
float avg_altitude = (altitude + _last_altitude)*0.5f;
|
2012-08-17 03:20:51 -03:00
|
|
|
|
|
|
|
// convert raw change to horizontal movement in cm
|
2012-11-28 14:32:38 -04:00
|
|
|
// perhaps this altitude should actually be the distance to the
|
|
|
|
// ground? i.e. if we are very rolled over it should be longer?
|
|
|
|
x_cm = -change_x * 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
|
|
|
|
y_cm = -change_y * avg_altitude * conv_factor;
|
2012-08-17 03:20:51 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
_last_altitude = altitude;
|
|
|
|
_last_roll = roll;
|
|
|
|
_last_pitch = pitch;
|
2012-03-09 22:57:06 -04:00
|
|
|
}
|