Path: blob/master/libraries/AC_PrecLand/AC_PrecLand_MAVLink.cpp
4182 views
#include "AC_PrecLand_config.h"12#if AC_PRECLAND_MAVLINK_ENABLED34#include "AC_PrecLand_MAVLink.h"5#include <AP_HAL/AP_HAL.h>6#include <GCS_MAVLink/GCS.h>78// perform any required initialisation of backend9void AC_PrecLand_MAVLink::init()10{11// set healthy12_state.healthy = true;13}1415// retrieve updates from sensor16void AC_PrecLand_MAVLink::update()17{18_los_meas.valid = _los_meas.valid && AP_HAL::millis() - _los_meas.time_ms <= 1000;19}2021void AC_PrecLand_MAVLink::handle_msg(const mavlink_landing_target_t &packet, uint32_t timestamp_ms)22{23// check frame is supported24if (packet.frame != MAV_FRAME_BODY_FRD && packet.frame != MAV_FRAME_LOCAL_FRD) {25if (!_wrong_frame_msg_sent) {26_wrong_frame_msg_sent = true;27GCS_SEND_TEXT(MAV_SEVERITY_INFO,"Plnd: Frame not supported");28}29return;30}3132if (packet.position_valid == 1) {33if (packet.distance > 0) {34_los_meas.vec_unit = Vector3f{packet.x, packet.y, packet.z};35_los_meas.vec_unit /= packet.distance;36_los_meas.frame = (packet.frame == MAV_FRAME_BODY_FRD) ? AC_PrecLand::VectorFrame::BODY_FRD : AC_PrecLand::VectorFrame::LOCAL_FRD;37} else {38// distance to target must be positive39return;40}41} else {42// compute unit vector towards target43_los_meas.vec_unit = Vector3f{-tanf(packet.angle_y), tanf(packet.angle_x), 1.0f};44_los_meas.vec_unit /= _los_meas.vec_unit.length();45_los_meas.frame = (packet.frame == MAV_FRAME_BODY_FRD) ? AC_PrecLand::VectorFrame::BODY_FRD : AC_PrecLand::VectorFrame::LOCAL_FRD;46}4748_distance_to_target = MAX(0, packet.distance);49_los_meas.time_ms = timestamp_ms;50_los_meas.valid = true;51}5253#endif // AC_PRECLAND_MAVLINK_ENABLED545556