Skip to content

Commit

Permalink
add new binding type for sensors and use the auto-baselineing during …
Browse files Browse the repository at this point in the history
…sensor moves
  • Loading branch information
ryanthecoder committed Jun 25, 2024
1 parent 3109317 commit 7a26107
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ class MotorInterruptHandler {
auto binding =
static_cast<uint8_t>(can::ids::SensorOutputBinding::sync) |
static_cast<uint8_t>(
can::ids::SensorOutputBinding::report); // sync and
// report
can::ids::SensorOutputBinding::report) |
static_cast<uint8_t>(
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);
Expand Down
22 changes: 15 additions & 7 deletions include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions include/sensors/core/tasks/pressure_sensor_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class PressureMessageHandler {
driver.set_max_bind_sync(
m.binding & static_cast<uint8_t>(
can::ids::SensorOutputBinding::max_threshold_sync));
driver.set_auto_baseline_report(
m.binding &
static_cast<uint8_t>(
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);
Expand Down

0 comments on commit 7a26107

Please sign in to comment.