Skip to content

Commit

Permalink
Added a time requirement to pipette overpressure detection
Browse files Browse the repository at this point in the history
  • Loading branch information
fsinapi committed Sep 19, 2023
1 parent 6646fe3 commit 6f0695b
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ class MMR920C04 {
}

auto poll_continuous_pressure(uint8_t tags) -> void {
auto mode_delay_with_buffer =
// in milliseconds
uint16_t mode_delay_with_buffer =
MeasurementTimings[static_cast<int>(measurement_mode_rate)] +
DEFAULT_DELAY_BUFFER;
max_pressure_required_readings =
MAX_PRESSURE_TIME_MS / mode_delay_with_buffer;
max_pressure_consecutive_readings = 0;
auto command_data =
build_register_command(_registers.low_pass_pressure_command);
if (filter_setting == mmr920C04::FilterSetting::NO_FILTER) {
Expand Down Expand Up @@ -289,10 +293,22 @@ class MMR920C04 {
_registers.pressure_result.reading);

if (max_pressure_sync) {
if (std::fabs(pressure) - std::fabs(current_pressure_baseline_pa) >
mmr920C04::MAX_PRESSURE_READING) {
hardware.set_sync();
bool this_tick_over_threshold =
std::fabs(pressure - current_pressure_baseline_pa) >=
mmr920C04::MAX_PRESSURE_READING;
bool over_threshold = false;
if (this_tick_over_threshold) {
max_pressure_consecutive_readings =
std::min(max_pressure_consecutive_readings + 1,
max_pressure_required_readings);
over_threshold = (max_pressure_consecutive_readings ==
max_pressure_required_readings);
echo_this_time = true;
} else {
max_pressure_consecutive_readings = 0;
}
if (over_threshold) {
hardware.set_sync();
can_client.send_can_message(
can::ids::NodeId::host,
can::messages::ErrorMessage{
Expand Down Expand Up @@ -450,6 +466,13 @@ class MMR920C04 {
static constexpr float DEFAULT_DELAY_BUFFER =
1.0; // in msec (TODO might need to change to fit in uint16_t)
static constexpr uint16_t STOP_DELAY = 0;

/**
* Time required before raising a Max Pressure error. The pressure must
* exceed the threshold for the entirety of this period.
*/
static constexpr uint16_t MAX_PRESSURE_TIME_MS = 500;

mmr920C04::MeasurementRate measurement_mode_rate =
mmr920C04::MeasurementRate::MEASURE_4;

Expand All @@ -465,6 +488,9 @@ class MMR920C04 {
float current_pressure_baseline_pa = 0;
float current_temperature_baseline = 0;

size_t max_pressure_consecutive_readings = 0;
size_t max_pressure_required_readings = 0;

// TODO(fs, 2022-11-11): Need to figure out a realistic threshold. Pretty
// sure this is an arbitrarily large number to enable continuous reads.
float threshold_pascals = 100.0F;
Expand Down

0 comments on commit 6f0695b

Please sign in to comment.