2023-03-22 05:45:41 -03:00
|
|
|
#include "AC_PrecLand_config.h"
|
|
|
|
|
|
|
|
#if AC_PRECLAND_IRLOCK_ENABLED
|
|
|
|
|
2015-08-28 05:11:52 -03:00
|
|
|
#include "AC_PrecLand_IRLock.h"
|
2023-03-22 05:45:41 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-02-16 00:37:13 -04:00
|
|
|
|
|
|
|
// Constructor
|
|
|
|
AC_PrecLand_IRLock::AC_PrecLand_IRLock(const AC_PrecLand& frontend, AC_PrecLand::precland_state& state)
|
|
|
|
: AC_PrecLand_Backend(frontend, state),
|
2018-07-15 21:29:20 -03:00
|
|
|
irlock()
|
2015-02-16 00:37:13 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// init - perform initialisation of this backend
|
|
|
|
void AC_PrecLand_IRLock::init()
|
|
|
|
{
|
2017-04-11 21:19:21 -03:00
|
|
|
irlock.init(get_bus());
|
2015-02-16 00:37:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// update - give chance to driver to get updates from sensor
|
2016-07-05 16:37:17 -03:00
|
|
|
void AC_PrecLand_IRLock::update()
|
2015-02-16 00:37:13 -04:00
|
|
|
{
|
2016-07-05 16:37:17 -03:00
|
|
|
// update health
|
|
|
|
_state.healthy = irlock.healthy();
|
|
|
|
|
2015-02-16 00:37:13 -04:00
|
|
|
// get new sensor data
|
2016-07-05 16:37:17 -03:00
|
|
|
irlock.update();
|
|
|
|
|
|
|
|
if (irlock.num_targets() > 0 && irlock.last_update_ms() != _los_meas_time_ms) {
|
|
|
|
irlock.get_unit_vector_body(_los_meas_body);
|
|
|
|
_have_los_meas = true;
|
|
|
|
_los_meas_time_ms = irlock.last_update_ms();
|
|
|
|
}
|
|
|
|
_have_los_meas = _have_los_meas && AP_HAL::millis()-_los_meas_time_ms <= 1000;
|
2015-02-16 00:37:13 -04:00
|
|
|
}
|
|
|
|
|
2016-07-05 16:37:17 -03:00
|
|
|
// provides a unit vector towards the target in body frame
|
|
|
|
// returns same as have_los_meas()
|
|
|
|
bool AC_PrecLand_IRLock::get_los_body(Vector3f& ret) {
|
|
|
|
if (have_los_meas()) {
|
|
|
|
ret = _los_meas_body;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-22 05:45:41 -03:00
|
|
|
#endif // AC_PRECLAND_IRLOCK_ENABLED
|