diff --git a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp index c8205a6bb..f79bd79c5 100644 --- a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp +++ b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp @@ -411,8 +411,9 @@ class MotorInterruptHandler { auto binding = static_cast(can::ids::SensorOutputBinding::sync) | static_cast( - can::ids::SensorOutputBinding::report); // sync and - // report + can::ids::SensorOutputBinding::report) | + static_cast( + can::ids::SensorOutputBinding::auto_baseline_report); if (buffered_move.sensor_id == can::ids::SensorId::BOTH) { send_bind_message(buffered_move.sensor_type, can::ids::SensorId::S0, binding); diff --git a/include/sensors/core/tasks/pressure_driver.hpp b/include/sensors/core/tasks/pressure_driver.hpp index 4cabb5519..69690d91e 100644 --- a/include/sensors/core/tasks/pressure_driver.hpp +++ b/include/sensors/core/tasks/pressure_driver.hpp @@ -76,10 +76,16 @@ class MMR920 { sensor_buffer_index = 0; // reset buffer index crossed_buffer_index = false; sensor_buffer->fill(0.0); - current_moving_pressure_baseline_pa = 0.0; } } + void set_auto_baseline_report(bool should_auto) { + enable_auto_baseline = should_auto; + // Always set this to 0, we want to clear it if disabled and + // reset if if we haven't baselined yet + current_moving_pressure_baseline_pa = 0.0; + } + void set_bind_sync(bool should_bind) { bind_sync = should_bind; hardware.reset_sync(); @@ -400,7 +406,8 @@ class MMR920 { sensor_buffer_log(response_pressure); - if (sensor_buffer_index == AUTO_BASELINE_END && + if (enable_auto_baseline && + sensor_buffer_index == AUTO_BASELINE_END && !crossed_buffer_index) { // this is the auto-base lining during a move. It requires that // a BaselineSensorRequest is sent prior to a move using the @@ -414,12 +421,12 @@ class MMR920 { sensor_buffer->begin() + AUTO_BASELINE_START, sensor_buffer->begin() + AUTO_BASELINE_END, 0) / (AUTO_BASELINE_END - AUTO_BASELINE_START); - for (auto i = sensor_buffer_index - AUTO_BASELINE_SAMPLES; + for (auto i = sensor_buffer_index - AUTO_BASELINE_SAMPLES; i < sensor_buffer_index; i++) { - // apply the moving baseline to older samples to so that - // data is in the same format as later samples, don't apply - // the current_pressure_baseline_pa since it has already - // been applied + // apply the moving baseline to older samples to so that + // data is in the same format as later samples, don't apply + // the current_pressure_baseline_pa since it has already + // been applied sensor_buffer->at(sensor_buffer_index) = sensor_buffer->at(sensor_buffer_index) - current_moving_pressure_baseline_pa; @@ -566,6 +573,7 @@ class MMR920 { bool _initialized = false; bool echoing = false; + bool enable_auto_baseline = false; bool bind_sync = false; bool max_pressure_sync = false; diff --git a/include/sensors/core/tasks/pressure_sensor_task.hpp b/include/sensors/core/tasks/pressure_sensor_task.hpp index 60b0f45a2..83f4294a8 100644 --- a/include/sensors/core/tasks/pressure_sensor_task.hpp +++ b/include/sensors/core/tasks/pressure_sensor_task.hpp @@ -136,6 +136,10 @@ class PressureMessageHandler { driver.set_max_bind_sync( m.binding & static_cast( can::ids::SensorOutputBinding::max_threshold_sync)); + driver.set_auto_baseline_report( + m.binding & + static_cast( + can::ids::SensorOutputBinding::auto_baseline_report)); std::array tags{utils::ResponseTag::IS_PART_OF_POLL, utils::ResponseTag::POLL_IS_CONTINUOUS}; auto tags_as_int = utils::byte_from_tags(tags);