From 232c31053ef261056d3d1f45324b995d2f179bd3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 12 Sep 2022 13:31:04 +1000 Subject: [PATCH] AP_UAVCAN: support sending pulses as PWM for DroneCAN actuators --- libraries/AP_UAVCAN/AP_UAVCAN.cpp | 12 +++++++----- libraries/AP_UAVCAN/AP_UAVCAN.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/AP_UAVCAN/AP_UAVCAN.cpp b/libraries/AP_UAVCAN/AP_UAVCAN.cpp index 2dcffedd82..baeabe9557 100644 --- a/libraries/AP_UAVCAN/AP_UAVCAN.cpp +++ b/libraries/AP_UAVCAN/AP_UAVCAN.cpp @@ -528,11 +528,13 @@ void AP_UAVCAN::SRV_send_actuator(void) if (_SRV_conf[starting_servo].servo_pending && ((((uint32_t) 1) << starting_servo) & _servo_bm)) { cmd.actuator_id = starting_servo + 1; - // TODO: other types - cmd.command_type = uavcan::equipment::actuator::Command::COMMAND_TYPE_UNITLESS; - - // TODO: failsafe, safety - cmd.command_value = constrain_float(((float) _SRV_conf[starting_servo].pulse - 1000.0) / 500.0 - 1.0, -1.0, 1.0); + if (option_is_set(Options::USE_ACTUATOR_PWM)) { + cmd.command_type = uavcan::equipment::actuator::Command::COMMAND_TYPE_PWM; + cmd.command_value = _SRV_conf[starting_servo].pulse; + } else { + cmd.command_type = uavcan::equipment::actuator::Command::COMMAND_TYPE_UNITLESS; + cmd.command_value = constrain_float(((float) _SRV_conf[starting_servo].pulse - 1000.0) / 500.0 - 1.0, -1.0, 1.0); + } msg.commands.push_back(cmd); diff --git a/libraries/AP_UAVCAN/AP_UAVCAN.h b/libraries/AP_UAVCAN/AP_UAVCAN.h index 2523bc54ed..9085a76c5a 100644 --- a/libraries/AP_UAVCAN/AP_UAVCAN.h +++ b/libraries/AP_UAVCAN/AP_UAVCAN.h @@ -203,6 +203,7 @@ public: DNA_IGNORE_DUPLICATE_NODE = (1U<<1), CANFD_ENABLED = (1U<<2), DNA_IGNORE_UNHEALTHY_NODE = (1U<<3), + USE_ACTUATOR_PWM = (1U<<4), }; // check if a option is set