From ee96d209d78510fe7bcc2c34e526648fa79c0135 Mon Sep 17 00:00:00 2001 From: Alex Klimaj Date: Wed, 24 May 2023 19:27:50 -0600 Subject: [PATCH] drivers/uavcannode: add GNSS Auxiliary publisher --- .../uavcannode/Publishers/GnssAuxiliary.hpp | 100 ++++++++++++++++++ src/drivers/uavcannode/UavcanNode.cpp | 2 + 2 files changed, 102 insertions(+) create mode 100644 src/drivers/uavcannode/Publishers/GnssAuxiliary.hpp diff --git a/src/drivers/uavcannode/Publishers/GnssAuxiliary.hpp b/src/drivers/uavcannode/Publishers/GnssAuxiliary.hpp new file mode 100644 index 0000000000..6a57cccdc7 --- /dev/null +++ b/src/drivers/uavcannode/Publishers/GnssAuxiliary.hpp @@ -0,0 +1,100 @@ +/**************************************************************************** + * + * Copyright (c) 2023 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#pragma once + +#include + +#include "UavcanPublisherBase.hpp" + +#include + +#include +#include + +namespace uavcannode +{ + +class GnssAuxiliary : + public UavcanPublisherBase, + public uORB::SubscriptionCallbackWorkItem, + private uavcan::Publisher +{ +public: + GnssAuxiliary(px4::WorkItem *work_item, uavcan::INode &node) : + UavcanPublisherBase(uavcan::equipment::gnss::Auxiliary::DefaultDataTypeID), + uORB::SubscriptionCallbackWorkItem(work_item, ORB_ID(sensor_gps)), + uavcan::Publisher(node) + { + this->setPriority(uavcan::TransferPriority::Default); + } + + void PrintInfo() override + { + if (uORB::SubscriptionCallbackWorkItem::advertised()) { + printf("\t%s -> %s:%d\n", + uORB::SubscriptionCallbackWorkItem::get_topic()->o_name, + uavcan::equipment::gnss::Auxiliary::getDataTypeFullName(), + id()); + } + } + + void BroadcastAnyUpdates() override + { + using uavcan::equipment::gnss::Auxiliary; + + // sensor_gps -> uavcan::equipment::gnss::Auxiliary + sensor_gps_s gps; + + if (uORB::SubscriptionCallbackWorkItem::update(&gps)) { + uavcan::equipment::gnss::Auxiliary auxiliary{}; + + //auxiliary.gdop = gps.gdop; + //auxiliary.pdop = gps.pdop; + auxiliary.hdop = gps.hdop; + auxiliary.vdop = gps.vdop; + //auxiliary.tdop = gps.tdop; + //auxiliary.ndop = gps.ndop; + //auxiliary.edop = gps.edop; + + auxiliary.sats_visible = gps.satellites_used; + auxiliary.sats_used = gps.satellites_used; + + uavcan::Publisher::broadcast(auxiliary); + + // ensure callback is registered + uORB::SubscriptionCallbackWorkItem::registerCallback(); + } + } +}; +} // namespace uavcannode diff --git a/src/drivers/uavcannode/UavcanNode.cpp b/src/drivers/uavcannode/UavcanNode.cpp index 8ac153380e..810a4fd0ca 100644 --- a/src/drivers/uavcannode/UavcanNode.cpp +++ b/src/drivers/uavcannode/UavcanNode.cpp @@ -58,6 +58,7 @@ #if defined(CONFIG_UAVCANNODE_GNSS_FIX) #include "Publishers/GnssFix2.hpp" +#include "Publishers/GnssAuxiliary.hpp" #endif // CONFIG_UAVCANNODE_GNSS_FIX #if defined(CONFIG_UAVCANNODE_MAGNETIC_FIELD_STRENGTH) @@ -366,6 +367,7 @@ int UavcanNode::init(uavcan::NodeID node_id, UAVCAN_DRIVER::BusEvent &bus_events #if defined(CONFIG_UAVCANNODE_GNSS_FIX) _publisher_list.add(new GnssFix2(this, _node)); + _publisher_list.add(new GnssAuxiliary(this, _node)); #endif // CONFIG_UAVCANNODE_GNSS_FIX #if defined(CONFIG_UAVCANNODE_MAGNETIC_FIELD_STRENGTH)