Skip to content

Commit

Permalink
drivers/uavcannode: add GNSS Auxiliary publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlimaj authored May 25, 2023
1 parent 822d784 commit ee96d20
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
100 changes: 100 additions & 0 deletions src/drivers/uavcannode/Publishers/GnssAuxiliary.hpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/drivers/uavcannode/UavcanNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee96d20

Please sign in to comment.