Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eeprom): Store overpressure count #822

Merged
merged 8 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/bootloader/core/ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ typedef enum {
can_messageid_write_motor_current_request = 0x33,
can_messageid_read_motor_current_request = 0x34,
can_messageid_read_motor_current_response = 0x35,
can_messageid_read_motor_driver_error_status_request = 0x36,
can_messageid_read_motor_driver_error_status_response = 0x37,
can_messageid_set_brushed_motor_vref_request = 0x40,
can_messageid_set_brushed_motor_pwm_request = 0x41,
can_messageid_gripper_grip_request = 0x42,
Expand Down Expand Up @@ -103,6 +105,7 @@ typedef enum {
can_messageid_gear_read_motor_driver_request = 0x507,
can_messageid_max_sensor_value_request = 0x70,
can_messageid_max_sensor_value_response = 0x71,
can_messageid_batch_read_sensor_response = 0x81,
can_messageid_read_sensor_request = 0x82,
can_messageid_write_sensor_request = 0x83,
can_messageid_baseline_sensor_request = 0x84,
Expand Down Expand Up @@ -167,6 +170,7 @@ typedef enum {
can_errorcode_over_pressure = 0xd,
can_errorcode_door_open = 0xe,
can_errorcode_reed_open = 0xf,
can_errorcode_motor_driver_error_detected = 0x10,
can_errorcode_safety_relay_inactive = 0x11,
} CANErrorCode;

Expand All @@ -187,6 +191,7 @@ typedef enum {
can_sensortype_pressure_temperature = 0x4,
can_sensortype_humidity = 0x5,
can_sensortype_temperature = 0x6,
can_sensortype_unused = 0x7,
} CANSensorType;

/** Sensor IDs available.
Expand All @@ -208,6 +213,7 @@ typedef enum {
can_sensoroutputbinding_report = 0x2,
can_sensoroutputbinding_max_threshold_sync = 0x4,
can_sensoroutputbinding_auto_baseline_report = 0x8,
can_sensoroutputbinding_multi_sensor_sync = 0x10,
} CANSensorOutputBinding;

/** How a sensor's threshold should be interpreted. */
Expand Down Expand Up @@ -270,5 +276,6 @@ typedef enum {
can_motorusagevaluetype_right_gear_motor_distance = 0x2,
can_motorusagevaluetype_force_application_time = 0x3,
can_motorusagevaluetype_total_error_count = 0x4,
can_motorusagevaluetype_overpressure_error_count = 0x5,
} CANMotorUsageValueType;

3 changes: 2 additions & 1 deletion include/can/core/ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ enum class SensorOutputBinding {
sync = 0x1,
report = 0x2,
max_threshold_sync = 0x4,
auto_baseline_report = 0x08,
auto_baseline_report = 0x8,
multi_sensor_sync = 0x10,
};

Expand Down Expand Up @@ -277,6 +277,7 @@ enum class MotorUsageValueType {
right_gear_motor_distance = 0x2,
force_application_time = 0x3,
total_error_count = 0x4,
overpressure_error_count = 0x5,
};

} // namespace can::ids
46 changes: 27 additions & 19 deletions include/pipettes/core/sensor_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,6 @@ using I2CClient =
using I2CPollerClient =
i2c::poller::Poller<freertos_message_queue::FreeRTOSMessageQueue>;

void start_tasks(
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
I2CPollerClient& i2c1_poller_client,
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
can::ids::NodeId id,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware);

void start_tasks(
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
I2CPollerClient& i2c1_poller_client,
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
sensors::hardware::SensorHardwareBase& sensor_hardware_secondary,
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
can::ids::NodeId id,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware);

/**
* Access to all sensor/eeprom tasks. This will be a singleton.
*/
Expand Down Expand Up @@ -84,6 +65,9 @@ struct Tasks {
sensors::tasks::ReadSensorBoardTask<
freertos_message_queue::FreeRTOSMessageQueue>* read_sensor_board_task{
nullptr};
usage_storage_task::UsageStorageTask<
freertos_message_queue::FreeRTOSMessageQueue>* usage_storage_task{
nullptr};
};

/**
Expand Down Expand Up @@ -123,6 +107,7 @@ struct QueueClient : can::message_writer::MessageWriter {

void send_tip_notification_queue_front(
const sensors::tip_presence::TaskMessage& m);
void send_usage_storage_queue(const usage_storage_task::TaskMessage& m);

freertos_message_queue::FreeRTOSMessageQueue<eeprom::task::TaskMessage>*
eeprom_queue{nullptr};
Expand All @@ -142,8 +127,31 @@ struct QueueClient : can::message_writer::MessageWriter {
freertos_message_queue::FreeRTOSMessageQueue<
sensors::tip_presence::TaskMessage>* tip_notification_queue_front{
nullptr};
freertos_message_queue::FreeRTOSMessageQueue<
usage_storage_task::TaskMessage>* usage_storage_queue{nullptr};
};

void start_tasks(
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
I2CPollerClient& i2c1_poller_client,
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
can::ids::NodeId id,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware,
eeprom::dev_data::DevDataTailAccessor<QueueClient>& tail_accessor);

void start_tasks(
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
I2CPollerClient& i2c1_poller_client,
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
sensors::hardware::SensorHardwareBase& sensor_hardware_secondary,
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
can::ids::NodeId id,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware,
eeprom::dev_data::DevDataTailAccessor<QueueClient>& tail_accessor);

/**
* Access to the sensor tasks singleton
* @return
Expand Down
11 changes: 9 additions & 2 deletions include/pipettes/firmware/eeprom_keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
#include "eeprom/core/update_data_rev_task.hpp"

static constexpr uint16_t PLUNGER_MOTOR_STEP_KEY = 0;

static constexpr uint16_t P_SM_ERROR_COUNT_KEY = 1;
static constexpr uint16_t OVERPRESSURE_COUNT_KEY_SM = 2;

static constexpr uint16_t GEAR_LEFT_MOTOR_KEY = 1;
static constexpr uint16_t GEAR_RIGHT_MOTOR_KEY = 2;
static constexpr uint16_t P_96_ERROR_COUNT_KEY = 3;
static constexpr uint16_t P_SM_ERROR_COUNT_KEY = 1;
static constexpr uint16_t L_ERROR_COUNT_KEY = 4;
static constexpr uint16_t R_ERROR_COUNT_KEY = 5;
static constexpr uint16_t OVERPRESSURE_COUNT_KEY_96 = 6;

extern const eeprom::data_rev_task::DataTableUpdateMessage
data_table_rev1_sing_mult;
extern const eeprom::data_rev_task::DataTableUpdateMessage
data_table_rev2_sing_mult;
extern const eeprom::data_rev_task::DataTableUpdateMessage
data_table_rev3_sing_mult;
extern const eeprom::data_rev_task::DataTableUpdateMessage data_table_rev1_96ch;
extern const eeprom::data_rev_task::DataTableUpdateMessage data_table_rev2_96ch;
extern const eeprom::data_rev_task::DataTableUpdateMessage data_table_rev3_96ch;

extern const std::vector<eeprom::data_rev_task::DataTableUpdateMessage>
table_updater;
table_updater;
20 changes: 17 additions & 3 deletions include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "common/core/message_queue.hpp"
#include "common/core/sensor_buffer.hpp"
#include "i2c/core/messages.hpp"
#include "motor-control/core/tasks/usage_storage_task.hpp"
#include "sensors/core/mmr920.hpp"
#include "sensors/core/sensor_hardware_interface.hpp"
#include "sensors/core/sensors.hpp"
Expand All @@ -35,21 +36,25 @@ constexpr auto AUTO_BASELINE_START = 10;
constexpr auto AUTO_BASELINE_END = 20;

template <class I2CQueueWriter, class I2CQueuePoller,
can::message_writer_task::TaskClient CanClient, class OwnQueue>
can::message_writer_task::TaskClient CanClient, class OwnQueue,
usage_storage_task::TaskClient UsageClient>
class MMR920 {
public:
MMR920(I2CQueueWriter &writer, I2CQueuePoller &poller,
CanClient &can_client, OwnQueue &own_queue,
sensors::hardware::SensorHardwareBase &hardware,
const can::ids::SensorId &id,
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer)
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer,
UsageClient &usage_client, uint16_t pres_err_key)
: writer(writer),
poller(poller),
can_client(can_client),
own_queue(own_queue),
hardware(hardware),
sensor_id(id),
sensor_buffer(sensor_buffer) {}
sensor_buffer(sensor_buffer),
usage_client(usage_client),
pressure_error_key(pres_err_key) {}

/**
* @brief Check if the MMR92 has been initialized.
Expand Down Expand Up @@ -447,6 +452,7 @@ class MMR920 {
.message_index = m.message_index,
.severity = can::ids::ErrorSeverity::unrecoverable,
.error_code = can::ids::ErrorCode::over_pressure});
increase_overpressure_count();
} else if (!bind_sync) {
// if we're not using bind sync turn off the sync line
// we don't do this during bind sync because if it's triggering
Expand Down Expand Up @@ -599,6 +605,12 @@ class MMR920 {
}
}

void increase_overpressure_count() {
auto message =
usage_messages::IncreaseErrorCount{.key = pressure_error_key};
usage_client.send_usage_storage_queue(message);
}

private:
I2CQueueWriter &writer;
I2CQueuePoller &poller;
Expand Down Expand Up @@ -670,6 +682,8 @@ class MMR920 {
uint16_t sensor_buffer_index_start = 0;
uint16_t sensor_buffer_index_end = 0;
bool crossed_buffer_index = false;
UsageClient &usage_client;
uint16_t pressure_error_key;
};

} // namespace tasks
Expand Down
29 changes: 18 additions & 11 deletions include/sensors/core/tasks/pressure_sensor_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "i2c/core/messages.hpp"
#include "i2c/core/poller.hpp"
#include "i2c/core/writer.hpp"
#include "motor-control/core/tasks/usage_storage_task.hpp"
#include "sensors/core/mmr920.hpp"
#include "sensors/core/tasks/pressure_driver.hpp"
#include "sensors/core/utils.hpp"
Expand All @@ -15,17 +16,19 @@ namespace sensors {
namespace tasks {

template <class I2CQueueWriter, class I2CQueuePoller,
can::message_writer_task::TaskClient CanClient, class OwnQueue>
can::message_writer_task::TaskClient CanClient, class OwnQueue,
usage_storage_task::TaskClient UsageClient>
class PressureMessageHandler {
public:
explicit PressureMessageHandler(
I2CQueueWriter &i2c_writer, I2CQueuePoller &i2c_poller,
CanClient &can_client, OwnQueue &own_queue,
sensors::hardware::SensorHardwareBase &hardware,
const can::ids::SensorId &id,
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer)
: driver{i2c_writer, i2c_poller, can_client, own_queue,
hardware, id, sensor_buffer},
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer,
UsageClient &usage_client, uint16_t pres_err_key)
: driver{i2c_writer, i2c_poller, can_client, own_queue, hardware,
id, sensor_buffer, usage_client, pres_err_key},
sensor_id{id} {}
PressureMessageHandler(const PressureMessageHandler &) = delete;
PressureMessageHandler(const PressureMessageHandler &&) = delete;
Expand Down Expand Up @@ -192,7 +195,8 @@ class PressureMessageHandler {
static_cast<void>(m);
}

MMR920<I2CQueueWriter, I2CQueuePoller, CanClient, OwnQueue> driver;
MMR920<I2CQueueWriter, I2CQueuePoller, CanClient, OwnQueue, UsageClient>
driver;
can::ids::SensorId sensor_id;
};

Expand All @@ -205,8 +209,8 @@ class PressureSensorTask {
public:
using Messages = utils::TaskMessage;
using QueueType = QueueImpl<utils::TaskMessage>;
PressureSensorTask(QueueType &queue, can::ids::SensorId id)
: queue{queue}, sensor_id{id} {}
PressureSensorTask(QueueType &queue, can::ids::SensorId id, uint16_t key)
: queue{queue}, sensor_id{id}, key{key} {}
PressureSensorTask(const PressureSensorTask &c) = delete;
PressureSensorTask(const PressureSensorTask &&c) = delete;
auto operator=(const PressureSensorTask &c) = delete;
Expand All @@ -216,15 +220,17 @@ class PressureSensorTask {
/**
* Task entry point.
*/
template <can::message_writer_task::TaskClient CanClient>
template <can::message_writer_task::TaskClient CanClient,
usage_storage_task::TaskClient UsageClient>
[[noreturn]] void operator()(
i2c::writer::Writer<QueueImpl> *writer,
i2c::poller::Poller<QueueImpl> *poller, CanClient *can_client,
sensors::hardware::SensorHardwareBase *hardware,
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer) {
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer,
UsageClient *usage_client) {
auto handler = PressureMessageHandler{
*writer, *poller, *can_client, get_queue(),
*hardware, sensor_id, sensor_buffer};
*writer, *poller, *can_client, get_queue(), *hardware,
sensor_id, sensor_buffer, *usage_client, key};
handler.initialize();
utils::TaskMessage message{};
for (;;) {
Expand All @@ -239,6 +245,7 @@ class PressureSensorTask {
private:
QueueType &queue;
can::ids::SensorId sensor_id;
uint16_t key;
};
}; // namespace tasks
}; // namespace sensors
Loading
Loading