diff --git a/docs/en/dronecan/escs.md b/docs/en/dronecan/escs.md index 630fce9e640..050122de26e 100644 --- a/docs/en/dronecan/escs.md +++ b/docs/en/dronecan/escs.md @@ -49,6 +49,8 @@ These workarounds are disabled by default and can be enabled with the [UAVCAN_QU - **Hobbywing ESCs:** some Hobbywing DroneCAN ESCs report `uavcan.equipment.esc.Status.esc_index` starting at 1 for the first ESC instead of 0 as required by the specification, while still expecting `RawCommand.cmd[0]` to command the first ESC. This causes ESC status feedback (e.g. RPM, voltage, current) to be matched to the wrong motor. Set bit 0 of `UAVCAN_QUIRKS` to correct for this off-by-one indexing. +- **Scaled RPM telemetry:** some ESCs report `uavcan.equipment.esc.Status.rpm` off by a fixed factor (for example electrical instead of mechanical RPM). + Set [UAVCAN_ESC_RPMSC](../advanced_config/parameter_reference.md#UAVCAN_ESC_RPMSC) to the factor that converts the reported value to mechanical RPM. ## Reversible Motors {#reversible-motors} diff --git a/src/drivers/uavcan/actuators/esc.cpp b/src/drivers/uavcan/actuators/esc.cpp index c1897bf927c..ef6b9e1e330 100644 --- a/src/drivers/uavcan/actuators/esc.cpp +++ b/src/drivers/uavcan/actuators/esc.cpp @@ -87,6 +87,7 @@ int UavcanEscController::init() } param_get(param_find("UAVCAN_QUIRKS"), &_param_uavcan_quirks); + param_get(param_find("UAVCAN_ESC_RPMSC"), &_param_esc_rpm_scale); _initialized = true; @@ -138,7 +139,7 @@ void UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructure< esc_report.esc_current = msg.current; esc_report.esc_temperature = msg.temperature + atmosphere::kAbsoluteNullCelsius; // Kelvin to Celsius // esc_report.motor_temperature is filled in the extended status callback - esc_report.esc_rpm = msg.rpm; + esc_report.esc_rpm = static_cast(lroundf(msg.rpm * _param_esc_rpm_scale)); esc_report.esc_errorcount = msg.error_count; esc_report.failures = get_failures(msg.getSrcNodeID().get()); diff --git a/src/drivers/uavcan/actuators/esc.hpp b/src/drivers/uavcan/actuators/esc.hpp index 15867fd1bcb..215a142cd08 100644 --- a/src/drivers/uavcan/actuators/esc.hpp +++ b/src/drivers/uavcan/actuators/esc.hpp @@ -130,6 +130,8 @@ private: failure_injection::Config _failure_config; + float _param_esc_rpm_scale{1.f}; + int32_t _param_uavcan_quirks{0}; enum class Quirk : int32_t { HobbywingEscIdx1 = (1 << 0), ///< ESCs reporting a 1-based esc_index instead of 0-based diff --git a/src/drivers/uavcan/module.yaml b/src/drivers/uavcan/module.yaml index f4ae52a7237..ba39fd90896 100644 --- a/src/drivers/uavcan/module.yaml +++ b/src/drivers/uavcan/module.yaml @@ -47,6 +47,19 @@ parameters: 0: Hobbywing 1-based esc_index default: 0 reboot_required: true + UAVCAN_ESC_RPMSC: + description: + short: ESC RPM telemetry scale + long: Multiplies the RPM reported in uavcan.equipment.esc.Status by this factor + before publishing, for ESCs that report RPM off by a fixed factor (e.g. electrical + instead of mechanical RPM). Applies to all DroneCAN ESCs. + type: float + default: 1.0 + min: 0.001 + max: 100.0 + decimal: 4 + increment: 0.01 + reboot_required: true UAVCAN_EC_SIGNED: description: short: Signed command for non-motor ESC channels