From 9368a9826a0e4639f4eacfeb2b209bdedd7e32c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Sat, 17 Oct 2026 01:41:45 +0200 Subject: [PATCH] perf(sensors/flight_mode_manager): drop two per-cycle topic copies (#29263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VotedSensorsUpdate::imuPoll() copied the whole vehicle_imu_status of each IMU on every vehicle_imu sample (200 Hz or more) to read two error counters that are published at 10 Hz. Keep the latest counters and update them only when a new status arrives; the voter gets the same values as before. FlightTaskManualAcceleration::update() copied vehicle_local_position by value on every run, although it only reads it and the subscription only changes in updateInitialize(). Take it by reference. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Benjamin Cabé --- .../FlightTaskManualAcceleration.cpp | 2 +- src/modules/sensors/voted_sensors_update.cpp | 14 +++++++++----- src/modules/sensors/voted_sensors_update.h | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/flight_mode_manager/tasks/ManualAcceleration/FlightTaskManualAcceleration.cpp b/src/modules/flight_mode_manager/tasks/ManualAcceleration/FlightTaskManualAcceleration.cpp index 4c243dfcf27..25cef9c8d31 100644 --- a/src/modules/flight_mode_manager/tasks/ManualAcceleration/FlightTaskManualAcceleration.cpp +++ b/src/modules/flight_mode_manager/tasks/ManualAcceleration/FlightTaskManualAcceleration.cpp @@ -64,7 +64,7 @@ bool FlightTaskManualAcceleration::activate(const trajectory_setpoint_s &last_se bool FlightTaskManualAcceleration::update() { - const vehicle_local_position_s vehicle_local_pos = _sub_vehicle_local_position.get(); + const vehicle_local_position_s &vehicle_local_pos = _sub_vehicle_local_position.get(); setMaxDistanceToGround(vehicle_local_pos.hagl_max_xy); bool ret = FlightTaskManualAltitudeSmoothVel::update(); diff --git a/src/modules/sensors/voted_sensors_update.cpp b/src/modules/sensors/voted_sensors_update.cpp index 5fe164ddc44..106de95dac8 100644 --- a/src/modules/sensors/voted_sensors_update.cpp +++ b/src/modules/sensors/voted_sensors_update.cpp @@ -174,9 +174,13 @@ void VotedSensorsUpdate::imuPoll(struct sensor_combined_s &raw) if (_vehicle_imu_sub[uorb_index].update(&imu_report) && imuEnabled(uorb_index)) { - // copy corresponding vehicle_imu_status for accel & gyro error counts - vehicle_imu_status_s imu_status{}; - _vehicle_imu_status_subs[uorb_index].copy(&imu_status); + // update the accel & gyro error counts from the corresponding vehicle_imu_status + vehicle_imu_status_s imu_status; + + if (_vehicle_imu_status_subs[uorb_index].update(&imu_status)) { + _accel_error_count[uorb_index] = imu_status.accel_error_count; + _gyro_error_count[uorb_index] = imu_status.gyro_error_count; + } _accel_device_id[uorb_index] = imu_report.accel_device_id; _gyro_device_id[uorb_index] = imu_report.gyro_device_id; @@ -207,10 +211,10 @@ void VotedSensorsUpdate::imuPoll(struct sensor_combined_s &raw) _last_accel_timestamp[uorb_index] = imu_report.timestamp_sample; _accel.voter.put(uorb_index, imu_report.timestamp, _last_sensor_data[uorb_index].accelerometer_m_s2, - imu_status.accel_error_count, _accel.priority[uorb_index]); + _accel_error_count[uorb_index], _accel.priority[uorb_index]); _gyro.voter.put(uorb_index, imu_report.timestamp, _last_sensor_data[uorb_index].gyro_rad, - imu_status.gyro_error_count, _gyro.priority[uorb_index]); + _gyro_error_count[uorb_index], _gyro.priority[uorb_index]); } } diff --git a/src/modules/sensors/voted_sensors_update.h b/src/modules/sensors/voted_sensors_update.h index 599d91af4cb..641f0053bd6 100644 --- a/src/modules/sensors/voted_sensors_update.h +++ b/src/modules/sensors/voted_sensors_update.h @@ -173,6 +173,8 @@ private: uORB::SubscriptionCallbackWorkItem(&_vehicle_imu_sub)[MAX_SENSOR_COUNT]; uORB::SubscriptionMultiArray _vehicle_imu_status_subs{ORB_ID::vehicle_imu_status}; + uint32_t _accel_error_count[MAX_SENSOR_COUNT] {}; /**< latest vehicle_imu_status error counts */ + uint32_t _gyro_error_count[MAX_SENSOR_COUNT] {}; uORB::Subscription _sensor_selection_sub{ORB_ID(sensor_selection)};