|
| 1 | +/**************************************************************************** |
| 2 | + * |
| 3 | + * Copyright (c) 2021 Autonomous Systems Lab, ETH Zurich. All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions |
| 7 | + * are met: |
| 8 | + * |
| 9 | + * 1. Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer in |
| 13 | + * the documentation and/or other materials provided with the |
| 14 | + * distribution. |
| 15 | + * 3. Neither the name PX4 nor the names of its contributors may be |
| 16 | + * used to endorse or promote products derived from this software |
| 17 | + * without specific prior written permission. |
| 18 | + * |
| 19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 22 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 23 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 25 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 26 | + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 27 | + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 29 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | + * POSSIBILITY OF SUCH DAMAGE. |
| 31 | + * |
| 32 | + ****************************************************************************/ |
| 33 | + |
| 34 | +#ifndef NPFG_STATUS_HPP |
| 35 | +#define NPFG_STATUS_HPP |
| 36 | + |
| 37 | +#include <uORB/topics/npfg_status.h> |
| 38 | + |
| 39 | +class MavlinkStreamNPFGStatus : public MavlinkStream |
| 40 | +{ |
| 41 | +public: |
| 42 | + static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamNPFGStatus(mavlink); } |
| 43 | + |
| 44 | + static constexpr const char *get_name_static() { return "NPFG_STATUS"; } |
| 45 | + static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_NPFG_STATUS; } |
| 46 | + |
| 47 | + const char *get_name() const override { return get_name_static(); } |
| 48 | + uint16_t get_id() override { return get_id_static(); } |
| 49 | + |
| 50 | + unsigned get_size() override |
| 51 | + { |
| 52 | + if (_npfg_status_sub.advertised()) { |
| 53 | + return MAVLINK_MSG_ID_NPFG_STATUS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; |
| 54 | + } |
| 55 | + |
| 56 | + return 0; |
| 57 | + } |
| 58 | + |
| 59 | +private: |
| 60 | + explicit MavlinkStreamNPFGStatus(Mavlink *mavlink) : MavlinkStream(mavlink) {} |
| 61 | + |
| 62 | + uORB::Subscription _npfg_status_sub{ORB_ID(npfg_status)}; |
| 63 | + |
| 64 | + bool send() override |
| 65 | + { |
| 66 | + struct npfg_status_s npfg_status; |
| 67 | + |
| 68 | + if (_npfg_status_sub.update(&npfg_status)) { |
| 69 | + mavlink_npfg_status_t msg{}; |
| 70 | + |
| 71 | + msg.timestamp = npfg_status.timestamp; |
| 72 | + msg.lat_accel = npfg_status.lat_accel; |
| 73 | + msg.lat_accel_ff = npfg_status.lat_accel_ff; |
| 74 | + msg.bearing_feas = npfg_status.bearing_feas; |
| 75 | + msg.bearing_feas_on_track = npfg_status.bearing_feas_on_track; |
| 76 | + msg.signed_track_error = npfg_status.signed_track_error; |
| 77 | + msg.track_error_bound = npfg_status.track_error_bound; |
| 78 | + msg.airspeed_ref = npfg_status.airspeed_ref; |
| 79 | + msg.bearing = math::degrees(npfg_status.bearing); |
| 80 | + msg.heading_ref = math::degrees(npfg_status.heading_ref); |
| 81 | + msg.min_ground_speed_ref = npfg_status.min_ground_speed_ref; |
| 82 | + msg.adapted_period = npfg_status.adapted_period; |
| 83 | + msg.p_gain = npfg_status.p_gain; |
| 84 | + msg.time_const = npfg_status.time_const; |
| 85 | + |
| 86 | + mavlink_msg_npfg_status_send_struct(_mavlink->get_channel(), &msg); |
| 87 | + |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + return false; |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +#endif // NPFG_STATUS |
0 commit comments