From 81ecd130fcd539c867e690139937ae129c98b026 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Tue, 11 Jan 2022 14:34:52 -0500 Subject: [PATCH] uavcan: ESC publish esc_status in callback instead of timer - this ensures every ESC status gets published with minimal latency - also prevents publishing ORB_ID(esc_status) when there's no actual data (bug) --- src/drivers/uavcan/actuators/esc.cpp | 39 +++++++--------------------- src/drivers/uavcan/actuators/esc.hpp | 9 +------ 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/drivers/uavcan/actuators/esc.cpp b/src/drivers/uavcan/actuators/esc.cpp index cd9ff51b70..e808c5d01e 100644 --- a/src/drivers/uavcan/actuators/esc.cpp +++ b/src/drivers/uavcan/actuators/esc.cpp @@ -48,16 +48,11 @@ using namespace time_literals; UavcanEscController::UavcanEscController(uavcan::INode &node) : _node(node), _uavcan_pub_raw_cmd(node), - _uavcan_sub_status(node), - _orb_timer(node) + _uavcan_sub_status(node) { _uavcan_pub_raw_cmd.setPriority(UAVCAN_COMMAND_TRANSFER_PRIORITY); } -UavcanEscController::~UavcanEscController() -{ -} - int UavcanEscController::init() { @@ -69,11 +64,6 @@ UavcanEscController::init() return res; } - // ESC status will be relayed from UAVCAN bus into ORB at this rate - _orb_timer.setCallback(TimerCbBinder(this, &UavcanEscController::orb_pub_timer_cb)); - _orb_timer.startPeriodic(uavcan::MonotonicDuration::fromMSec(1000 / ESC_STATUS_UPDATE_RATE_HZ)); - _esc_status_pub.advertise(); - return res; } @@ -136,10 +126,6 @@ void UavcanEscController::set_rotor_count(uint8_t count) { _rotor_count = count; - - if (_rotor_count != 0u) { - _orb_timer.startPeriodic(uavcan::MonotonicDuration::fromMSec(1000 / ESC_STATUS_UPDATE_RATE_HZ)); - } } void @@ -148,29 +134,24 @@ UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructure &msg); - /** - * ESC status will be published to ORB from this callback (fixed rate). - */ - void orb_pub_timer_cb(const uavcan::TimerEvent &event); - /** * Checks all the ESCs freshness based on timestamp, if an ESC exceeds the timeout then is flagged offline. */ uint8_t check_escs_status(); - static constexpr unsigned ESC_STATUS_UPDATE_RATE_HZ = 10; static constexpr unsigned UAVCAN_COMMAND_TRANSFER_PRIORITY = 5; ///< 0..31, inclusive, 0 - highest, 31 - lowest typedef uavcan::MethodBinder _uavcan_pub_raw_cmd; uavcan::Subscriber _uavcan_sub_status; - uavcan::TimerEventForwarder _orb_timer; /* * ESC states