2023-03-22 05:45:41 -03:00
|
|
|
#include "AC_PrecLand_config.h"
|
|
|
|
|
|
|
|
#if AC_PRECLAND_COMPANION_ENABLED
|
|
|
|
|
|
|
|
#include "AC_PrecLand_Companion.h"
|
2015-08-28 05:11:52 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2022-07-30 06:54:25 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2015-02-16 00:37:13 -04:00
|
|
|
|
2016-07-05 16:37:17 -03:00
|
|
|
// perform any required initialisation of backend
|
2015-02-16 00:37:13 -04:00
|
|
|
void AC_PrecLand_Companion::init()
|
|
|
|
{
|
|
|
|
// set healthy
|
|
|
|
_state.healthy = true;
|
|
|
|
}
|
|
|
|
|
2016-07-05 16:37:17 -03:00
|
|
|
// retrieve updates from sensor
|
|
|
|
void AC_PrecLand_Companion::update()
|
2015-02-16 00:37:13 -04:00
|
|
|
{
|
2016-07-05 16:37:17 -03:00
|
|
|
_have_los_meas = _have_los_meas && AP_HAL::millis()-_los_meas_time_ms <= 1000;
|
2015-02-16 00:37:13 -04:00
|
|
|
}
|
|
|
|
|
2021-04-12 23:49:59 -03:00
|
|
|
void AC_PrecLand_Companion::handle_msg(const mavlink_landing_target_t &packet, uint32_t timestamp_ms)
|
2015-09-11 08:00:18 -03:00
|
|
|
{
|
|
|
|
_distance_to_target = packet.distance;
|
2017-02-03 03:01:03 -04:00
|
|
|
|
2022-07-30 06:54:25 -03:00
|
|
|
if (packet.position_valid == 1) {
|
|
|
|
if (packet.frame == MAV_FRAME_BODY_FRD) {
|
|
|
|
if (_distance_to_target > 0) {
|
|
|
|
_los_meas_body = Vector3f(packet.x, packet.y, packet.z);
|
|
|
|
_los_meas_body /= _distance_to_target;
|
|
|
|
} else {
|
|
|
|
// distance to target must be positive
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//we do not support this frame
|
|
|
|
if (!_wrong_frame_msg_sent) {
|
|
|
|
_wrong_frame_msg_sent = true;
|
2024-02-15 11:26:16 -04:00
|
|
|
GCS_SEND_TEXT(MAV_SEVERITY_INFO,"Plnd: Frame not supported ");
|
2022-07-30 06:54:25 -03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// compute unit vector towards target
|
|
|
|
_los_meas_body = Vector3f(-tanf(packet.angle_y), tanf(packet.angle_x), 1.0f);
|
|
|
|
_los_meas_body /= _los_meas_body.length();
|
|
|
|
}
|
2017-02-03 03:01:03 -04:00
|
|
|
|
2021-04-12 23:49:59 -03:00
|
|
|
_los_meas_time_ms = timestamp_ms;
|
2016-07-05 16:37:17 -03:00
|
|
|
_have_los_meas = true;
|
2015-09-11 08:00:18 -03:00
|
|
|
}
|
2023-03-22 05:45:41 -03:00
|
|
|
|
|
|
|
#endif // AC_PRECLAND_COMPANION_ENABLED
|