2014-11-17 01:33:23 -04:00
|
|
|
/*
|
|
|
|
* IRLock.cpp
|
|
|
|
*
|
|
|
|
* Created on: Nov 12, 2014
|
|
|
|
* Author: MLandes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IRLock.h"
|
|
|
|
|
|
|
|
// default constructor
|
2015-02-18 01:47:33 -04:00
|
|
|
IRLock::IRLock() :
|
2016-07-05 16:20:35 -03:00
|
|
|
_last_update_ms(0),
|
2015-08-31 02:17:20 -03:00
|
|
|
_num_targets(0)
|
2014-11-17 01:33:23 -04:00
|
|
|
{
|
2015-08-31 02:17:20 -03:00
|
|
|
// clear target info
|
2015-08-30 00:36:55 -03:00
|
|
|
memset(_target_info, 0, sizeof(_target_info));
|
2014-11-17 01:33:23 -04:00
|
|
|
|
2015-08-31 02:17:20 -03:00
|
|
|
// will be adjusted when init is called
|
|
|
|
_flags.healthy = false;
|
2014-11-17 01:33:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
IRLock::~IRLock() {}
|
|
|
|
|
2016-07-05 16:20:35 -03:00
|
|
|
// retrieve body frame x and y angles (in radians) to target
|
|
|
|
// returns true if data is available
|
|
|
|
bool IRLock::get_angle_to_target_rad(float &x_angle_rad, float &y_angle_rad) const
|
2014-11-17 01:33:23 -04:00
|
|
|
{
|
2015-02-18 01:47:33 -04:00
|
|
|
// return false if we have no target
|
2015-08-30 00:36:55 -03:00
|
|
|
if (_num_targets == 0) {
|
2015-02-18 01:47:33 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-05 16:20:35 -03:00
|
|
|
// use data from first (largest) object
|
|
|
|
x_angle_rad = atanf(_target_info[0].pos_x);
|
|
|
|
y_angle_rad = atanf(_target_info[0].pos_y);
|
2015-02-18 01:47:33 -04:00
|
|
|
return true;
|
2014-11-17 01:33:23 -04:00
|
|
|
}
|
2016-07-05 16:20:35 -03:00
|
|
|
|
|
|
|
// retrieve body frame unit vector in direction of target
|
|
|
|
// returns true if data is available
|
|
|
|
bool IRLock::get_unit_vector_body(Vector3f& ret) const
|
|
|
|
{
|
|
|
|
// return false if we have no target
|
|
|
|
if (_num_targets == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use data from first (largest) object
|
|
|
|
ret.x = -_target_info[0].pos_y;
|
|
|
|
ret.y = _target_info[0].pos_x;
|
|
|
|
ret.z = 1.0f;
|
|
|
|
ret /= ret.length();
|
|
|
|
return true;
|
|
|
|
}
|