Skip to content

Commit 2d10623

Browse files
authored
feat(eeprom): Store overpressure count (#822)
* first pass * correctly hook up templates * run update-headers * add overpressure errors to the plunger usage response * run update-headers again * fix sensor tests * hope this fixes simulators they won't compile on my computer * format
1 parent bc54b1d commit 2d10623

File tree

13 files changed

+182
-67
lines changed

13 files changed

+182
-67
lines changed

include/bootloader/core/ids.h

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ typedef enum {
6262
can_messageid_write_motor_current_request = 0x33,
6363
can_messageid_read_motor_current_request = 0x34,
6464
can_messageid_read_motor_current_response = 0x35,
65+
can_messageid_read_motor_driver_error_status_request = 0x36,
66+
can_messageid_read_motor_driver_error_status_response = 0x37,
6567
can_messageid_set_brushed_motor_vref_request = 0x40,
6668
can_messageid_set_brushed_motor_pwm_request = 0x41,
6769
can_messageid_gripper_grip_request = 0x42,
@@ -103,6 +105,7 @@ typedef enum {
103105
can_messageid_gear_read_motor_driver_request = 0x507,
104106
can_messageid_max_sensor_value_request = 0x70,
105107
can_messageid_max_sensor_value_response = 0x71,
108+
can_messageid_batch_read_sensor_response = 0x81,
106109
can_messageid_read_sensor_request = 0x82,
107110
can_messageid_write_sensor_request = 0x83,
108111
can_messageid_baseline_sensor_request = 0x84,
@@ -167,6 +170,7 @@ typedef enum {
167170
can_errorcode_over_pressure = 0xd,
168171
can_errorcode_door_open = 0xe,
169172
can_errorcode_reed_open = 0xf,
173+
can_errorcode_motor_driver_error_detected = 0x10,
170174
can_errorcode_safety_relay_inactive = 0x11,
171175
} CANErrorCode;
172176

@@ -187,6 +191,7 @@ typedef enum {
187191
can_sensortype_pressure_temperature = 0x4,
188192
can_sensortype_humidity = 0x5,
189193
can_sensortype_temperature = 0x6,
194+
can_sensortype_unused = 0x7,
190195
} CANSensorType;
191196

192197
/** Sensor IDs available.
@@ -208,6 +213,7 @@ typedef enum {
208213
can_sensoroutputbinding_report = 0x2,
209214
can_sensoroutputbinding_max_threshold_sync = 0x4,
210215
can_sensoroutputbinding_auto_baseline_report = 0x8,
216+
can_sensoroutputbinding_multi_sensor_sync = 0x10,
211217
} CANSensorOutputBinding;
212218

213219
/** How a sensor's threshold should be interpreted. */
@@ -270,5 +276,6 @@ typedef enum {
270276
can_motorusagevaluetype_right_gear_motor_distance = 0x2,
271277
can_motorusagevaluetype_force_application_time = 0x3,
272278
can_motorusagevaluetype_total_error_count = 0x4,
279+
can_motorusagevaluetype_overpressure_error_count = 0x5,
273280
} CANMotorUsageValueType;
274281

include/can/core/ids.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ enum class SensorOutputBinding {
222222
sync = 0x1,
223223
report = 0x2,
224224
max_threshold_sync = 0x4,
225-
auto_baseline_report = 0x08,
225+
auto_baseline_report = 0x8,
226226
multi_sensor_sync = 0x10,
227227
};
228228

@@ -277,6 +277,7 @@ enum class MotorUsageValueType {
277277
right_gear_motor_distance = 0x2,
278278
force_application_time = 0x3,
279279
total_error_count = 0x4,
280+
overpressure_error_count = 0x5,
280281
};
281282

282283
} // namespace can::ids

include/pipettes/core/sensor_tasks.hpp

+27-19
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@ using I2CClient =
3535
using I2CPollerClient =
3636
i2c::poller::Poller<freertos_message_queue::FreeRTOSMessageQueue>;
3737

38-
void start_tasks(
39-
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
40-
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
41-
I2CPollerClient& i2c1_poller_client,
42-
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
43-
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
44-
can::ids::NodeId id,
45-
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware);
46-
47-
void start_tasks(
48-
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
49-
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
50-
I2CPollerClient& i2c1_poller_client,
51-
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
52-
sensors::hardware::SensorHardwareBase& sensor_hardware_secondary,
53-
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
54-
can::ids::NodeId id,
55-
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware);
56-
5738
/**
5839
* Access to all sensor/eeprom tasks. This will be a singleton.
5940
*/
@@ -84,6 +65,9 @@ struct Tasks {
8465
sensors::tasks::ReadSensorBoardTask<
8566
freertos_message_queue::FreeRTOSMessageQueue>* read_sensor_board_task{
8667
nullptr};
68+
usage_storage_task::UsageStorageTask<
69+
freertos_message_queue::FreeRTOSMessageQueue>* usage_storage_task{
70+
nullptr};
8771
};
8872

8973
/**
@@ -123,6 +107,7 @@ struct QueueClient : can::message_writer::MessageWriter {
123107

124108
void send_tip_notification_queue_front(
125109
const sensors::tip_presence::TaskMessage& m);
110+
void send_usage_storage_queue(const usage_storage_task::TaskMessage& m);
126111

127112
freertos_message_queue::FreeRTOSMessageQueue<eeprom::task::TaskMessage>*
128113
eeprom_queue{nullptr};
@@ -142,8 +127,31 @@ struct QueueClient : can::message_writer::MessageWriter {
142127
freertos_message_queue::FreeRTOSMessageQueue<
143128
sensors::tip_presence::TaskMessage>* tip_notification_queue_front{
144129
nullptr};
130+
freertos_message_queue::FreeRTOSMessageQueue<
131+
usage_storage_task::TaskMessage>* usage_storage_queue{nullptr};
145132
};
146133

134+
void start_tasks(
135+
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
136+
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
137+
I2CPollerClient& i2c1_poller_client,
138+
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
139+
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
140+
can::ids::NodeId id,
141+
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware,
142+
eeprom::dev_data::DevDataTailAccessor<QueueClient>& tail_accessor);
143+
144+
void start_tasks(
145+
CanWriterTask& can_writer, I2CClient& i2c3_task_client,
146+
I2CPollerClient& i2c3_poller_client, I2CClient& i2c1_task_client,
147+
I2CPollerClient& i2c1_poller_client,
148+
sensors::hardware::SensorHardwareBase& sensor_hardware_primary,
149+
sensors::hardware::SensorHardwareBase& sensor_hardware_secondary,
150+
sensors::hardware::SensorHardwareVersionSingleton& version_wrapper,
151+
can::ids::NodeId id,
152+
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hardware,
153+
eeprom::dev_data::DevDataTailAccessor<QueueClient>& tail_accessor);
154+
147155
/**
148156
* Access to the sensor tasks singleton
149157
* @return

include/pipettes/firmware/eeprom_keys.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
#include "eeprom/core/update_data_rev_task.hpp"
44

55
static constexpr uint16_t PLUNGER_MOTOR_STEP_KEY = 0;
6+
7+
static constexpr uint16_t P_SM_ERROR_COUNT_KEY = 1;
8+
static constexpr uint16_t OVERPRESSURE_COUNT_KEY_SM = 2;
9+
610
static constexpr uint16_t GEAR_LEFT_MOTOR_KEY = 1;
711
static constexpr uint16_t GEAR_RIGHT_MOTOR_KEY = 2;
812
static constexpr uint16_t P_96_ERROR_COUNT_KEY = 3;
9-
static constexpr uint16_t P_SM_ERROR_COUNT_KEY = 1;
1013
static constexpr uint16_t L_ERROR_COUNT_KEY = 4;
1114
static constexpr uint16_t R_ERROR_COUNT_KEY = 5;
15+
static constexpr uint16_t OVERPRESSURE_COUNT_KEY_96 = 6;
1216

1317
extern const eeprom::data_rev_task::DataTableUpdateMessage
1418
data_table_rev1_sing_mult;
1519
extern const eeprom::data_rev_task::DataTableUpdateMessage
1620
data_table_rev2_sing_mult;
21+
extern const eeprom::data_rev_task::DataTableUpdateMessage
22+
data_table_rev3_sing_mult;
1723
extern const eeprom::data_rev_task::DataTableUpdateMessage data_table_rev1_96ch;
1824
extern const eeprom::data_rev_task::DataTableUpdateMessage data_table_rev2_96ch;
25+
extern const eeprom::data_rev_task::DataTableUpdateMessage data_table_rev3_96ch;
1926

2027
extern const std::vector<eeprom::data_rev_task::DataTableUpdateMessage>
21-
table_updater;
28+
table_updater;

include/sensors/core/tasks/pressure_driver.hpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "common/core/message_queue.hpp"
1313
#include "common/core/sensor_buffer.hpp"
1414
#include "i2c/core/messages.hpp"
15+
#include "motor-control/core/tasks/usage_storage_task.hpp"
1516
#include "sensors/core/mmr920.hpp"
1617
#include "sensors/core/sensor_hardware_interface.hpp"
1718
#include "sensors/core/sensors.hpp"
@@ -35,21 +36,25 @@ constexpr auto AUTO_BASELINE_START = 10;
3536
constexpr auto AUTO_BASELINE_END = 20;
3637

3738
template <class I2CQueueWriter, class I2CQueuePoller,
38-
can::message_writer_task::TaskClient CanClient, class OwnQueue>
39+
can::message_writer_task::TaskClient CanClient, class OwnQueue,
40+
usage_storage_task::TaskClient UsageClient>
3941
class MMR920 {
4042
public:
4143
MMR920(I2CQueueWriter &writer, I2CQueuePoller &poller,
4244
CanClient &can_client, OwnQueue &own_queue,
4345
sensors::hardware::SensorHardwareBase &hardware,
4446
const can::ids::SensorId &id,
45-
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer)
47+
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer,
48+
UsageClient &usage_client, uint16_t pres_err_key)
4649
: writer(writer),
4750
poller(poller),
4851
can_client(can_client),
4952
own_queue(own_queue),
5053
hardware(hardware),
5154
sensor_id(id),
52-
sensor_buffer(sensor_buffer) {}
55+
sensor_buffer(sensor_buffer),
56+
usage_client(usage_client),
57+
pressure_error_key(pres_err_key) {}
5358

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

608+
void increase_overpressure_count() {
609+
auto message =
610+
usage_messages::IncreaseErrorCount{.key = pressure_error_key};
611+
usage_client.send_usage_storage_queue(message);
612+
}
613+
602614
private:
603615
I2CQueueWriter &writer;
604616
I2CQueuePoller &poller;
@@ -670,6 +682,8 @@ class MMR920 {
670682
uint16_t sensor_buffer_index_start = 0;
671683
uint16_t sensor_buffer_index_end = 0;
672684
bool crossed_buffer_index = false;
685+
UsageClient &usage_client;
686+
uint16_t pressure_error_key;
673687
};
674688

675689
} // namespace tasks

include/sensors/core/tasks/pressure_sensor_task.hpp

+18-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "i2c/core/messages.hpp"
88
#include "i2c/core/poller.hpp"
99
#include "i2c/core/writer.hpp"
10+
#include "motor-control/core/tasks/usage_storage_task.hpp"
1011
#include "sensors/core/mmr920.hpp"
1112
#include "sensors/core/tasks/pressure_driver.hpp"
1213
#include "sensors/core/utils.hpp"
@@ -15,17 +16,19 @@ namespace sensors {
1516
namespace tasks {
1617

1718
template <class I2CQueueWriter, class I2CQueuePoller,
18-
can::message_writer_task::TaskClient CanClient, class OwnQueue>
19+
can::message_writer_task::TaskClient CanClient, class OwnQueue,
20+
usage_storage_task::TaskClient UsageClient>
1921
class PressureMessageHandler {
2022
public:
2123
explicit PressureMessageHandler(
2224
I2CQueueWriter &i2c_writer, I2CQueuePoller &i2c_poller,
2325
CanClient &can_client, OwnQueue &own_queue,
2426
sensors::hardware::SensorHardwareBase &hardware,
2527
const can::ids::SensorId &id,
26-
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer)
27-
: driver{i2c_writer, i2c_poller, can_client, own_queue,
28-
hardware, id, sensor_buffer},
28+
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer,
29+
UsageClient &usage_client, uint16_t pres_err_key)
30+
: driver{i2c_writer, i2c_poller, can_client, own_queue, hardware,
31+
id, sensor_buffer, usage_client, pres_err_key},
2932
sensor_id{id} {}
3033
PressureMessageHandler(const PressureMessageHandler &) = delete;
3134
PressureMessageHandler(const PressureMessageHandler &&) = delete;
@@ -192,7 +195,8 @@ class PressureMessageHandler {
192195
static_cast<void>(m);
193196
}
194197

195-
MMR920<I2CQueueWriter, I2CQueuePoller, CanClient, OwnQueue> driver;
198+
MMR920<I2CQueueWriter, I2CQueuePoller, CanClient, OwnQueue, UsageClient>
199+
driver;
196200
can::ids::SensorId sensor_id;
197201
};
198202

@@ -205,8 +209,8 @@ class PressureSensorTask {
205209
public:
206210
using Messages = utils::TaskMessage;
207211
using QueueType = QueueImpl<utils::TaskMessage>;
208-
PressureSensorTask(QueueType &queue, can::ids::SensorId id)
209-
: queue{queue}, sensor_id{id} {}
212+
PressureSensorTask(QueueType &queue, can::ids::SensorId id, uint16_t key)
213+
: queue{queue}, sensor_id{id}, key{key} {}
210214
PressureSensorTask(const PressureSensorTask &c) = delete;
211215
PressureSensorTask(const PressureSensorTask &&c) = delete;
212216
auto operator=(const PressureSensorTask &c) = delete;
@@ -216,15 +220,17 @@ class PressureSensorTask {
216220
/**
217221
* Task entry point.
218222
*/
219-
template <can::message_writer_task::TaskClient CanClient>
223+
template <can::message_writer_task::TaskClient CanClient,
224+
usage_storage_task::TaskClient UsageClient>
220225
[[noreturn]] void operator()(
221226
i2c::writer::Writer<QueueImpl> *writer,
222227
i2c::poller::Poller<QueueImpl> *poller, CanClient *can_client,
223228
sensors::hardware::SensorHardwareBase *hardware,
224-
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer) {
229+
std::array<float, SENSOR_BUFFER_SIZE> *sensor_buffer,
230+
UsageClient *usage_client) {
225231
auto handler = PressureMessageHandler{
226-
*writer, *poller, *can_client, get_queue(),
227-
*hardware, sensor_id, sensor_buffer};
232+
*writer, *poller, *can_client, get_queue(), *hardware,
233+
sensor_id, sensor_buffer, *usage_client, key};
228234
handler.initialize();
229235
utils::TaskMessage message{};
230236
for (;;) {
@@ -239,6 +245,7 @@ class PressureSensorTask {
239245
private:
240246
QueueType &queue;
241247
can::ids::SensorId sensor_id;
248+
uint16_t key;
242249
};
243250
}; // namespace tasks
244251
}; // namespace sensors

0 commit comments

Comments
 (0)