Skip to content

Commit

Permalink
drivers/uavcannode: add indicated airspeed
Browse files Browse the repository at this point in the history
Signed-off-by: dirksavage88 <[email protected]>
  • Loading branch information
dirksavage88 authored Feb 6, 2024
1 parent a6fcb8e commit bf52d8a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/drivers/uavcannode/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if DRIVERS_UAVCANNODE
bool "Include hygrometer measurement"
default n

config UAVCANNODE_INDICATED_AIR_SPEED
bool "Include Indicated Airspeed"
default n

config UAVCANNODE_LIGHTS_COMMAND
bool "Include lights command"
default n
Expand Down
91 changes: 91 additions & 0 deletions src/drivers/uavcannode/Publishers/IndicatedAirspeed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/****************************************************************************
*
* 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 "UavcanPublisherBase.hpp"

#include <uORB/SubscriptionCallback.hpp>
#include <uORB/topics/airspeed.h>
#include <uavcan/equipment/air_data/IndicatedAirspeed.hpp>

namespace uavcannode
{

class IndicatedAirspeed : public UavcanPublisherBase,
public uORB::SubscriptionCallbackWorkItem,
private uavcan::Publisher <
uavcan::equipment::air_data::IndicatedAirspeed >
{
public:
IndicatedAirspeed(px4::WorkItem *work_item, uavcan::INode &node)
: UavcanPublisherBase(
uavcan::equipment::air_data::IndicatedAirspeed::DefaultDataTypeID),
uORB::SubscriptionCallbackWorkItem(work_item, ORB_ID(airspeed)),
uavcan::Publisher<uavcan::equipment::air_data::IndicatedAirspeed>(
node)
{
this->setPriority(uavcan::TransferPriority::OneLowerThanHighest);
}

void PrintInfo() override
{
if (uORB::SubscriptionCallbackWorkItem::advertised()) {
printf(
"\t%s -> %s:%d\n",
uORB::SubscriptionCallbackWorkItem::get_topic()->o_name,
uavcan::equipment::air_data::IndicatedAirspeed::getDataTypeFullName(),
uavcan::equipment::air_data::IndicatedAirspeed::DefaultDataTypeID);
}
}

void BroadcastAnyUpdates() override
{

// airspeed -> uavcan::equipment::air_data::IndicatedAirspeed

airspeed_s airspeed_m;

if (uORB::SubscriptionCallbackWorkItem::update(&airspeed_m)) {
uavcan::equipment::air_data::IndicatedAirspeed indicated_as{};

indicated_as.indicated_airspeed = airspeed_m.indicated_airspeed_m_s;
uavcan::Publisher<uavcan::equipment::air_data::IndicatedAirspeed>::
broadcast(indicated_as);

// ensure callback is registered
uORB::SubscriptionCallbackWorkItem::registerCallback();
}
}
};
} // namespace uavcannode
4 changes: 4 additions & 0 deletions src/drivers/uavcannode/UavcanNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
#include "Publishers/GnssAuxiliary.hpp"
#endif // CONFIG_UAVCANNODE_GNSS_FIX

#if defined(CONFIG_UAVCANNODE_INDICATED_AIR_SPEED)
#include "Publishers/IndicatedAirspeed.hpp"
#endif // CONFIG_UAVCANNODE_INDICATED_AIR_SPEED

#if defined(CONFIG_UAVCANNODE_MAGNETIC_FIELD_STRENGTH)
#include "Publishers/MagneticFieldStrength2.hpp"
#endif // CONFIG_UAVCANNODE_MAGNETIC_FIELD_STRENGTH
Expand Down

0 comments on commit bf52d8a

Please sign in to comment.