mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-22 16:47:35 +08:00
drivers/uavcannode: add GNSS Auxiliary publisher
This commit is contained in:
@@ -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 <cmath>
|
||||
|
||||
#include "UavcanPublisherBase.hpp"
|
||||
|
||||
#include <uavcan/equipment/gnss/Auxiliary.hpp>
|
||||
|
||||
#include <uORB/SubscriptionCallback.hpp>
|
||||
#include <uORB/topics/sensor_gps.h>
|
||||
|
||||
namespace uavcannode
|
||||
{
|
||||
|
||||
class GnssAuxiliary :
|
||||
public UavcanPublisherBase,
|
||||
public uORB::SubscriptionCallbackWorkItem,
|
||||
private uavcan::Publisher<uavcan::equipment::gnss::Auxiliary>
|
||||
{
|
||||
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<uavcan::equipment::gnss::Auxiliary>(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<uavcan::equipment::gnss::Auxiliary>::broadcast(auxiliary);
|
||||
|
||||
// ensure callback is registered
|
||||
uORB::SubscriptionCallbackWorkItem::registerCallback();
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace uavcannode
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user