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

modify tip presence sensor task #713

Merged
merged 12 commits into from
Aug 14, 2023
4 changes: 3 additions & 1 deletion gripper/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ void gripper_tasks::QueueClient::send_pressure_sensor_queue_front(
void gripper_tasks::QueueClient::send_pressure_sensor_queue_rear(
const sensors::utils::TaskMessage&) {}

void gripper_tasks::QueueClient::send_tip_notification_queue(
void gripper_tasks::QueueClient::send_tip_notification_queue_rear(
const sensors::tip_presence::TaskMessage&) {}
void gripper_tasks::QueueClient::send_tip_notification_queue_front(
const sensors::tip_presence::TaskMessage&) {}

/**
Expand Down
3 changes: 3 additions & 0 deletions include/can/core/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,11 +1239,14 @@ struct PushTipPresenceNotification
: BaseMessage<MessageId::tip_presence_notification> {
uint32_t message_index;
uint8_t ejector_flag_status;
can::ids::SensorId sensor_id{};

template <bit_utils::ByteIterator Output, typename Limit>
auto serialize(Output body, Limit limit) const -> uint8_t {
auto iter = bit_utils::int_to_bytes(message_index, body, limit);
iter = bit_utils::int_to_bytes(ejector_flag_status, iter, limit);
iter = bit_utils::int_to_bytes(static_cast<uint8_t>(sensor_id), iter,
limit);
return iter - body;
}

Expand Down
4 changes: 3 additions & 1 deletion include/gripper/core/tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ struct QueueClient : can::message_writer::MessageWriter {
void send_pressure_sensor_queue_front(const sensors::utils::TaskMessage& m);
void send_pressure_sensor_queue_rear(const sensors::utils::TaskMessage& m);

void send_tip_notification_queue(
void send_tip_notification_queue_rear(
const sensors::tip_presence::TaskMessage& m);
void send_tip_notification_queue_front(
const sensors::tip_presence::TaskMessage& m);

freertos_message_queue::FreeRTOSMessageQueue<
Expand Down
18 changes: 14 additions & 4 deletions include/pipettes/core/sensor_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ struct Tasks {
freertos_message_queue::FreeRTOSMessageQueue>*
pressure_sensor_task_front{nullptr};
sensors::tasks::TipPresenceNotificationTask<
freertos_message_queue::FreeRTOSMessageQueue>* tip_notification_task{
nullptr};
freertos_message_queue::FreeRTOSMessageQueue>*
tip_notification_task_rear{nullptr};
sensors::tasks::TipPresenceNotificationTask<
freertos_message_queue::FreeRTOSMessageQueue>*
tip_notification_task_front{nullptr};
};

/**
Expand All @@ -96,7 +99,10 @@ struct QueueClient : can::message_writer::MessageWriter {

void send_pressure_sensor_queue_front(const sensors::utils::TaskMessage& m);

void send_tip_notification_queue(
void send_tip_notification_queue_rear(
const sensors::tip_presence::TaskMessage& m);

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

freertos_message_queue::FreeRTOSMessageQueue<eeprom::task::TaskMessage>*
Expand All @@ -112,7 +118,11 @@ struct QueueClient : can::message_writer::MessageWriter {
freertos_message_queue::FreeRTOSMessageQueue<sensors::utils::TaskMessage>*
pressure_sensor_queue_front{nullptr};
freertos_message_queue::FreeRTOSMessageQueue<
sensors::tip_presence::TaskMessage>* tip_notification_queue{nullptr};
sensors::tip_presence::TaskMessage>* tip_notification_queue_rear{
nullptr};
freertos_message_queue::FreeRTOSMessageQueue<
sensors::tip_presence::TaskMessage>* tip_notification_queue_front{
nullptr};
};

/**
Expand Down
3 changes: 2 additions & 1 deletion include/sensors/core/message_handlers/sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class SensorHandler {
}

void visit(const can::messages::TipStatusQueryRequest &m) {
client.send_tip_notification_queue(m);
client.send_tip_notification_queue_rear(m);
client.send_tip_notification_queue_front(m);
}

void send_to_queue(can::ids::SensorType type, can::ids::SensorId id,
Expand Down
20 changes: 14 additions & 6 deletions include/sensors/core/tasks/tip_presence_notification_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ template <can::message_writer_task::TaskClient CanClient>
class TipPresenceNotificationHandler {
public:
explicit TipPresenceNotificationHandler(
CanClient &can_client, sensors::hardware::SensorHardwareBase &hardware)
: can_client{can_client}, hardware{hardware} {}
CanClient &can_client, sensors::hardware::SensorHardwareBase &hardware,
const can::ids::SensorId &id)
: can_client{can_client}, hardware{hardware}, sensor_id{id} {}
TipPresenceNotificationHandler(const TipPresenceNotificationHandler &) =
delete;
TipPresenceNotificationHandler(const TipPresenceNotificationHandler &&) =
Expand All @@ -29,7 +30,9 @@ class TipPresenceNotificationHandler {
can::messages::PushTipPresenceNotification{
.message_index = 0,
.ejector_flag_status =
static_cast<uint8_t>(hardware.check_tip_presence())});
static_cast<uint8_t>(hardware.check_tip_presence()),
.sensor_id = sensor_id,
});
}

void visit(const can::messages::TipStatusQueryRequest &m) {
Expand All @@ -38,12 +41,14 @@ class TipPresenceNotificationHandler {
can::messages::PushTipPresenceNotification{
.message_index = m.message_index,
.ejector_flag_status =
static_cast<uint8_t>(hardware.check_tip_presence())});
static_cast<uint8_t>(hardware.check_tip_presence()),
.sensor_id = sensor_id});
}

private:
CanClient &can_client;
sensors::hardware::SensorHardwareBase &hardware;
can::ids::SensorId sensor_id;
};

/**
Expand All @@ -56,7 +61,8 @@ class TipPresenceNotificationTask {
public:
using Messages = tip_presence::TaskMessage;
using QueueType = QueueImpl<Messages>;
TipPresenceNotificationTask(QueueType &queue) : queue{queue} {}
TipPresenceNotificationTask(QueueType &queue, can::ids::SensorId id)
: queue{queue}, sensor_id{id} {}
TipPresenceNotificationTask(const TipPresenceNotificationTask &c) = delete;
TipPresenceNotificationTask(const TipPresenceNotificationTask &&c) = delete;
auto operator=(const TipPresenceNotificationTask &c) = delete;
Expand All @@ -70,7 +76,8 @@ class TipPresenceNotificationTask {
[[noreturn]] void operator()(
CanClient *can_client,
sensors::hardware::SensorHardwareBase *hardware) {
auto handler = TipPresenceNotificationHandler{*can_client, *hardware};
auto handler =
TipPresenceNotificationHandler{*can_client, *hardware, sensor_id};
Messages message{};
for (;;) {
if (queue.try_read(&message, queue.max_delay)) {
Expand All @@ -83,6 +90,7 @@ class TipPresenceNotificationTask {

private:
QueueType &queue;
can::ids::SensorId sensor_id;
};

} // namespace tasks
Expand Down
52 changes: 40 additions & 12 deletions pipettes/core/sensor_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ static auto pressure_sensor_task_builder_front =
freertos_task::TaskStarter<512, sensors::tasks::PressureSensorTask,
can::ids::SensorId>(can::ids::SensorId::S1);

static auto tip_notification_task_builder_rear =
freertos_task::TaskStarter<256, sensors::tasks::TipPresenceNotificationTask,
can::ids::SensorId>(can::ids::SensorId::S0);

static auto tip_notification_task_builder_front =
freertos_task::TaskStarter<256,
sensors::tasks::TipPresenceNotificationTask>{};
freertos_task::TaskStarter<256, sensors::tasks::TipPresenceNotificationTask,
can::ids::SensorId>(can::ids::SensorId::S1);

void sensor_tasks::start_tasks(
sensor_tasks::CanWriterTask& can_writer,
Expand Down Expand Up @@ -70,22 +74,23 @@ void sensor_tasks::start_tasks(
capacitive_sensor_task_builder_rear.start(
5, "capacitive sensor s0", i2c3_task_client, i2c3_poller_client,
sensor_hardware_primary, queues);
auto& tip_notification_task = tip_notification_task_builder_front.start(
5, "tip notification", queues, sensor_hardware_primary);
auto& tip_notification_task_rear = tip_notification_task_builder_rear.start(
5, "tip notification sensor s0", queues, sensor_hardware_primary);

tasks.eeprom_task = &eeprom_task;
tasks.environment_sensor_task = &environment_sensor_task;
tasks.capacitive_sensor_task_rear = &capacitive_sensor_task_rear;
tasks.pressure_sensor_task_rear = &pressure_sensor_task_rear;
tasks.tip_notification_task = &tip_notification_task;
tasks.tip_notification_task_rear = &tip_notification_task_rear;

queues.set_queue(&can_writer.get_queue());
queues.eeprom_queue = &eeprom_task.get_queue();
queues.environment_sensor_queue = &environment_sensor_task.get_queue();
queues.capacitive_sensor_queue_rear =
&capacitive_sensor_task_rear.get_queue();
queues.pressure_sensor_queue_rear = &pressure_sensor_task_rear.get_queue();
queues.tip_notification_queue = &tip_notification_task.get_queue();
queues.tip_notification_queue_rear =
&tip_notification_task_rear.get_queue();
}

void sensor_tasks::start_tasks(
Expand Down Expand Up @@ -119,6 +124,8 @@ void sensor_tasks::start_tasks(
? i2c3_task_client
: i2c2_task_client;
auto shared_cap_task = PIPETTE_TYPE == EIGHT_CHANNEL ? true : false;
auto front_tip_presence_sensor =
PIPETTE_TYPE == NINETY_SIX_CHANNEL ? true : false;

auto& eeprom_task = eeprom_task_builder.start(
5, "eeprom", eeprom_i2c_client, eeprom_hardware);
Expand All @@ -134,14 +141,14 @@ void sensor_tasks::start_tasks(
capacitive_sensor_task_builder_rear.start(
5, "capacitive sensor s0", i2c3_task_client, i2c3_poller_client,
sensor_hardware_primary, queues, shared_cap_task);
auto& tip_notification_task = tip_notification_task_builder_front.start(
5, "tip notification", queues, sensor_hardware_primary);
auto& tip_notification_task_rear = tip_notification_task_builder_rear.start(
5, "tip notification sensor s0", queues, sensor_hardware_primary);

tasks.eeprom_task = &eeprom_task;
tasks.environment_sensor_task = &environment_sensor_task;
tasks.pressure_sensor_task_rear = &pressure_sensor_task_rear;
tasks.pressure_sensor_task_front = &pressure_sensor_task_front;
tasks.tip_notification_task = &tip_notification_task;
tasks.tip_notification_task_rear = &tip_notification_task_rear;
tasks.capacitive_sensor_task_rear = &capacitive_sensor_task_rear;

queues.set_queue(&can_writer.get_queue());
Expand All @@ -152,7 +159,8 @@ void sensor_tasks::start_tasks(
queues.pressure_sensor_queue_rear = &pressure_sensor_task_rear.get_queue();
queues.pressure_sensor_queue_front =
&pressure_sensor_task_front.get_queue();
queues.tip_notification_queue = &tip_notification_task.get_queue();
queues.tip_notification_queue_rear =
&tip_notification_task_rear.get_queue();

if (shared_cap_task) {
// There is only one cap sensor on the eight channel and so the "front"
Expand All @@ -170,6 +178,17 @@ void sensor_tasks::start_tasks(
queues.capacitive_sensor_queue_front =
&capacitive_sensor_task_front.get_queue();
}
if (front_tip_presence_sensor) {
// the eight channel only has one tip presence sensor, so the front
// task should only be started if we have a 96 channel pipette
auto& tip_notification_task_front =
tip_notification_task_builder_front.start(
5, "tip notification sensor s1", queues,
sensor_hardware_secondary);
tasks.tip_notification_task_front = &tip_notification_task_front;
queues.tip_notification_queue_front =
&tip_notification_task_front.get_queue();
}
}

sensor_tasks::QueueClient::QueueClient()
Expand Down Expand Up @@ -216,9 +235,18 @@ void sensor_tasks::QueueClient::send_pressure_sensor_queue_front(
}
}

void sensor_tasks::QueueClient::send_tip_notification_queue(
void sensor_tasks::QueueClient::send_tip_notification_queue_rear(
const sensors::tip_presence::TaskMessage& m) {
tip_notification_queue->try_write(m);
if (tip_notification_queue_rear != nullptr) {
tip_notification_queue_rear->try_write(m);
}
}

void sensor_tasks::QueueClient::send_tip_notification_queue_front(
const sensors::tip_presence::TaskMessage& m) {
if (tip_notification_queue_front != nullptr) {
tip_notification_queue_front->try_write(m);
}
}

auto sensor_tasks::get_tasks() -> Tasks& { return tasks; }
Expand Down
16 changes: 10 additions & 6 deletions pipettes/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,19 @@ static auto tail_accessor =

extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == tip_sense_gpio_primary.pin) {
static_cast<void>(
sensor_queue_client.tip_notification_queue->try_write_isr(
sensors::tip_presence::TipStatusChangeDetected{}));
if (sensor_queue_client.tip_notification_queue_rear != nullptr) {
static_cast<void>(
sensor_queue_client.tip_notification_queue_rear->try_write_isr(
sensors::tip_presence::TipStatusChangeDetected{}));
}
} else if (ok_for_secondary &&
GPIO_Pin ==
pins_for_sensor.secondary.value().tip_sense.value().pin) {
static_cast<void>(
sensor_queue_client.tip_notification_queue->try_write_isr(
sensors::tip_presence::TipStatusChangeDetected{}));
if (sensor_queue_client.tip_notification_queue_front != nullptr) {
static_cast<void>(
sensor_queue_client.tip_notification_queue_front->try_write_isr(
sensors::tip_presence::TipStatusChangeDetected{}));
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions pipettes/firmware/utility_configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ auto utility_configs::sensor_configurations<PipetteType::NINETY_SIX_CHANNEL>()
gpio::PinConfig{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_12,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET}},
.secondary = sensors::hardware::SensorHardwareConfiguration{
.sync_out =
Expand All @@ -138,7 +138,7 @@ auto utility_configs::sensor_configurations<PipetteType::NINETY_SIX_CHANNEL>()
.tip_sense = gpio::PinConfig{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_7,
.pin = GPIO_PIN_12,
.active_setting = GPIO_PIN_RESET}}};
return pins;
}
Expand Down
Loading