Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AC_PrecLand/AC_PrecLand_MAVLink.cpp
4182 views
1
#include "AC_PrecLand_config.h"
2
3
#if AC_PRECLAND_MAVLINK_ENABLED
4
5
#include "AC_PrecLand_MAVLink.h"
6
#include <AP_HAL/AP_HAL.h>
7
#include <GCS_MAVLink/GCS.h>
8
9
// perform any required initialisation of backend
10
void AC_PrecLand_MAVLink::init()
11
{
12
// set healthy
13
_state.healthy = true;
14
}
15
16
// retrieve updates from sensor
17
void AC_PrecLand_MAVLink::update()
18
{
19
_los_meas.valid = _los_meas.valid && AP_HAL::millis() - _los_meas.time_ms <= 1000;
20
}
21
22
void AC_PrecLand_MAVLink::handle_msg(const mavlink_landing_target_t &packet, uint32_t timestamp_ms)
23
{
24
// check frame is supported
25
if (packet.frame != MAV_FRAME_BODY_FRD && packet.frame != MAV_FRAME_LOCAL_FRD) {
26
if (!_wrong_frame_msg_sent) {
27
_wrong_frame_msg_sent = true;
28
GCS_SEND_TEXT(MAV_SEVERITY_INFO,"Plnd: Frame not supported");
29
}
30
return;
31
}
32
33
if (packet.position_valid == 1) {
34
if (packet.distance > 0) {
35
_los_meas.vec_unit = Vector3f{packet.x, packet.y, packet.z};
36
_los_meas.vec_unit /= packet.distance;
37
_los_meas.frame = (packet.frame == MAV_FRAME_BODY_FRD) ? AC_PrecLand::VectorFrame::BODY_FRD : AC_PrecLand::VectorFrame::LOCAL_FRD;
38
} else {
39
// distance to target must be positive
40
return;
41
}
42
} else {
43
// compute unit vector towards target
44
_los_meas.vec_unit = Vector3f{-tanf(packet.angle_y), tanf(packet.angle_x), 1.0f};
45
_los_meas.vec_unit /= _los_meas.vec_unit.length();
46
_los_meas.frame = (packet.frame == MAV_FRAME_BODY_FRD) ? AC_PrecLand::VectorFrame::BODY_FRD : AC_PrecLand::VectorFrame::LOCAL_FRD;
47
}
48
49
_distance_to_target = MAX(0, packet.distance);
50
_los_meas.time_ms = timestamp_ms;
51
_los_meas.valid = true;
52
}
53
54
#endif // AC_PRECLAND_MAVLINK_ENABLED
55
56