2016-11-11 01:10:35 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include "AC_PrecLand_SITL.h"
|
|
|
|
|
2023-03-22 05:45:41 -03:00
|
|
|
#if AC_PRECLAND_SITL_ENABLED
|
2016-11-11 01:10:35 -04:00
|
|
|
|
2018-08-03 07:52:48 -03:00
|
|
|
#include "AP_AHRS/AP_AHRS.h"
|
2016-11-11 01:10:35 -04:00
|
|
|
// init - perform initialisation of this backend
|
|
|
|
void AC_PrecLand_SITL::init()
|
|
|
|
{
|
2018-08-03 07:52:48 -03:00
|
|
|
_sitl = AP::sitl();
|
2016-11-11 01:10:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// update - give chance to driver to get updates from sensor
|
|
|
|
void AC_PrecLand_SITL::update()
|
|
|
|
{
|
2018-08-03 07:52:48 -03:00
|
|
|
_state.healthy = _sitl->precland_sim.healthy();
|
|
|
|
|
|
|
|
if (_state.healthy && _sitl->precland_sim.last_update_ms() != _los_meas_time_ms) {
|
2021-06-20 23:59:46 -03:00
|
|
|
const Vector3d position = _sitl->precland_sim.get_target_position();
|
|
|
|
const Matrix3d body_to_ned = AP::ahrs().get_rotation_body_to_ned().todouble();
|
|
|
|
_los_meas_body = body_to_ned.mul_transpose(-position).tofloat();
|
2022-06-24 10:07:34 -03:00
|
|
|
_distance_to_target = _sitl->precland_sim.option_enabled(SITL::SIM_Precland::Option::ENABLE_TARGET_DISTANCE) ? _los_meas_body.length() : 0.0f;
|
2018-08-03 07:52:48 -03:00
|
|
|
_los_meas_body /= _los_meas_body.length();
|
2022-06-24 10:03:39 -03:00
|
|
|
|
|
|
|
if (_frontend._orient != Rotation::ROTATION_PITCH_270) {
|
|
|
|
// rotate body frame vector based on orientation
|
|
|
|
// this is done to have homogeneity among backends
|
|
|
|
// frontend rotates it back to get correct body frame vector
|
|
|
|
_los_meas_body.rotate_inverse(_frontend._orient);
|
|
|
|
_los_meas_body.rotate_inverse(ROTATION_PITCH_90);
|
|
|
|
}
|
|
|
|
|
2018-08-03 07:52:48 -03:00
|
|
|
_have_los_meas = true;
|
|
|
|
_los_meas_time_ms = _sitl->precland_sim.last_update_ms();
|
|
|
|
} else {
|
|
|
|
_have_los_meas = false;
|
2016-11-11 01:10:35 -04:00
|
|
|
}
|
|
|
|
|
2018-08-03 07:52:48 -03:00
|
|
|
_have_los_meas = _have_los_meas && AP_HAL::millis() - _los_meas_time_ms <= 1000;
|
2016-11-11 01:10:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AC_PrecLand_SITL::have_los_meas() {
|
|
|
|
return AP_HAL::millis() - _los_meas_time_ms < 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
// provides a unit vector towards the target in body frame
|
|
|
|
// returns same as have_los_meas()
|
|
|
|
bool AC_PrecLand_SITL::get_los_body(Vector3f& ret) {
|
|
|
|
if (AP_HAL::millis() - _los_meas_time_ms > 1000) {
|
|
|
|
// no measurement for a full second; no vector available
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ret = _los_meas_body;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-22 05:45:41 -03:00
|
|
|
#endif // AC_PRECLAND_SITL_ENABLED
|