Initial Cannode PWM Support (#19748)

* Add uavcannode esc/servo pwm control pipeline
* Remove cannode rc.interface with mixer purge
* Cannode add Kconfig options to reduce flash usage
This commit is contained in:
Alex Klimaj
2023-03-15 11:20:07 -04:00
committed by GitHub
parent f0a95f9572
commit ea97a38b2b
24 changed files with 891 additions and 19 deletions
+2
View File
@@ -142,6 +142,8 @@ px4_add_module(
${LIBUAVCAN_DIR}/libuavcan_drivers/posix/include
${LIBUAVCAN_DIR_DRIVERS}/${UAVCAN_DRIVER}/driver/include
SRCS
arming_status.cpp
arming_status.hpp
beep.cpp
beep.hpp
rgbled.cpp
+1 -1
View File
@@ -50,7 +50,7 @@ UavcanEscController::UavcanEscController(uavcan::INode &node) :
_uavcan_pub_raw_cmd(node),
_uavcan_sub_status(node)
{
_uavcan_pub_raw_cmd.setPriority(UAVCAN_COMMAND_TRANSFER_PRIORITY);
_uavcan_pub_raw_cmd.setPriority(uavcan::TransferPriority::NumericallyMin); // Highest priority
}
int
-2
View File
@@ -91,8 +91,6 @@ private:
*/
uint8_t check_escs_status();
static constexpr unsigned UAVCAN_COMMAND_TRANSFER_PRIORITY = 5; ///< 0..31, inclusive, 0 - highest, 31 - lowest
typedef uavcan::MethodBinder<UavcanEscController *,
void (UavcanEscController::*)(const uavcan::ReceivedDataStructure<uavcan::equipment::esc::Status>&)> StatusCbBinder;
+81
View File
@@ -0,0 +1,81 @@
/****************************************************************************
*
* Copyright (c) 2022 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.
*
****************************************************************************/
/**
* @file arming_status.cpp
*
* @author Alex Klimaj <alex@arkelectron.com>
*/
#include "arming_status.hpp"
UavcanArmingStatus::UavcanArmingStatus(uavcan::INode &node) :
_arming_status_pub(node),
_timer(node)
{
_arming_status_pub.setPriority(uavcan::TransferPriority::Default);
}
int UavcanArmingStatus::init()
{
/*
* Setup timer and call back function for periodic updates
*/
if (!_timer.isRunning()) {
_timer.setCallback(TimerCbBinder(this, &UavcanArmingStatus::periodic_update));
_timer.startPeriodic(uavcan::MonotonicDuration::fromMSec(1000 / MAX_RATE_HZ));
}
return 0;
}
void UavcanArmingStatus::periodic_update(const uavcan::TimerEvent &)
{
actuator_armed_s actuator_armed;
if (_actuator_armed_sub.update(&actuator_armed)) {
uavcan::equipment::safety::ArmingStatus cmd;
if (actuator_armed.lockdown || actuator_armed.manual_lockdown) {
cmd.status = cmd.STATUS_DISARMED;
} else if (actuator_armed.armed || actuator_armed.prearmed) {
cmd.status = cmd.STATUS_FULLY_ARMED;
} else {
cmd.status = cmd.STATUS_DISARMED;
}
(void)_arming_status_pub.broadcast(cmd);
}
}
+83
View File
@@ -0,0 +1,83 @@
/****************************************************************************
*
* Copyright (c) 2022 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.
*
****************************************************************************/
/**
* @file arming_status.hpp
*
* @author Alex Klimaj <alex@arkelectron.com>
*
* @brief Publish actuator_armed to CAN ArmingStatus message
*/
#pragma once
#include <uavcan/uavcan.hpp>
#include <uavcan/equipment/safety/ArmingStatus.hpp>
#include <uORB/Subscription.hpp>
#include <uORB/topics/actuator_armed.h>
class UavcanArmingStatus
{
public:
UavcanArmingStatus(uavcan::INode &node);
/*
* setup periodic updater
*/
int init();
private:
/*
* Max update rate to avoid exessive bus traffic
*/
static constexpr unsigned MAX_RATE_HZ = 10;
/*
* Setup timer and call back function for periodic updates
*/
void periodic_update(const uavcan::TimerEvent &);
typedef uavcan::MethodBinder<UavcanArmingStatus *, void (UavcanArmingStatus::*)(const uavcan::TimerEvent &)>
TimerCbBinder;
/*
* Publish CAN ArmingState
*/
uavcan::Publisher<uavcan::equipment::safety::ArmingStatus> _arming_status_pub;
uavcan::TimerEventForwarder<TimerCbBinder> _timer;
uORB::Subscription _actuator_armed_sub{ORB_ID(actuator_armed)};
};
+16 -1
View File
@@ -80,6 +80,7 @@ UavcanNode::UavcanNode(uavcan::ICanDriver &can_driver, uavcan::ISystemClock &sys
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::uavcan),
ModuleParams(nullptr),
_node(can_driver, system_clock, _pool_allocator),
_arming_status_controller(_node),
_beep_controller(_node),
_esc_controller(_node),
_servo_controller(_node),
@@ -478,7 +479,21 @@ UavcanNode::init(uavcan::NodeID node_id, UAVCAN_DRIVER::BusEvent &bus_events)
fill_node_info();
int ret = _beep_controller.init();
int ret;
// UAVCAN_PUB_ARM
int32_t uavcan_pub_arm = 0;
param_get(param_find("UAVCAN_PUB_ARM"), &uavcan_pub_arm);
if (uavcan_pub_arm == 1) {
ret = _arming_status_controller.init();
if (ret < 0) {
return ret;
}
}
ret = _beep_controller.init();
if (ret < 0) {
return ret;
+2
View File
@@ -50,6 +50,7 @@
#include "actuators/hardpoint.hpp"
#include "actuators/servo.hpp"
#include "allocator.hpp"
#include "arming_status.hpp"
#include "beep.hpp"
#include "logmessage.hpp"
#include "rgbled.hpp"
@@ -224,6 +225,7 @@ private:
uavcan::Node<> _node; ///< library instance
pthread_mutex_t _node_mutex;
UavcanArmingStatus _arming_status_controller;
UavcanBeepController _beep_controller;
UavcanEscController _esc_controller;
UavcanServoController _servo_controller;
+12
View File
@@ -185,6 +185,18 @@ PARAM_DEFINE_INT32(UAVCAN_LGT_NAV, 3);
*/
PARAM_DEFINE_INT32(UAVCAN_LGT_LAND, 0);
/**
* publish Arming Status stream
*
* Enable UAVCAN Arming Status stream publication
* uavcan::equipment::safety::ArmingStatus
*
* @boolean
* @reboot_required true
* @group UAVCAN
*/
PARAM_DEFINE_INT32(UAVCAN_PUB_ARM, 0);
/**
* publish RTCM stream
*