From 070ad67bb1c659a5d744df1e3d67b9984213cb61 Mon Sep 17 00:00:00 2001 From: pmoegenburg Date: Tue, 30 Apr 2024 13:57:56 -0400 Subject: [PATCH] format lint test --- CMakePresets.json | 2 +- gripper/firmware/interfaces_z_motor.cpp | 3 +- include/can/core/messages.hpp | 4 +- include/common/core/sensor_buffer.hpp | 7 ++ include/gripper/core/can_task.hpp | 3 +- include/gripper/core/tasks.hpp | 8 ++- .../stepper_motor/motor_interrupt_handler.hpp | 64 ++++++++++++------- include/pipettes/core/sensor_tasks.hpp | 6 +- .../sensors/core/message_handlers/sensors.hpp | 10 +-- .../sensors/core/tasks/capacitive_driver.hpp | 13 ++-- .../core/tasks/capacitive_sensor_task.hpp | 15 +++-- .../core/tasks/environmental_sensor_task.hpp | 3 +- .../sensors/core/tasks/pressure_driver.hpp | 9 +-- .../core/motor_interrupt_handler.cpp | 4 +- sensors/tests/test_capacitive_sensor.cpp | 10 +-- 15 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 include/common/core/sensor_buffer.hpp diff --git a/CMakePresets.json b/CMakePresets.json index 6dbf1c62d..44b3d417d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -42,7 +42,7 @@ "installDir": "${sourceDir}/dist-sensor", "binaryDir": "${sourceDir}/build-cross-sensor", "cacheVariables": { - "USE_PRESSURE_MOVE": true + "USE_SENSOR_MOVE": true }, "inherits": "cross" }, diff --git a/gripper/firmware/interfaces_z_motor.cpp b/gripper/firmware/interfaces_z_motor.cpp index df9fbaf9f..662c87246 100644 --- a/gripper/firmware/interfaces_z_motor.cpp +++ b/gripper/firmware/interfaces_z_motor.cpp @@ -158,7 +158,8 @@ static tmc2130::configs::TMC2130DriverConfig MotorDriverConfigurations{ * The pending move queue */ #ifdef USE_SENSOR_MOVE -static freertos_message_queue::FreeRTOSMessageQueue +static freertos_message_queue::FreeRTOSMessageQueue< + motor_messages::SensorSyncMove> motor_queue("Motor Queue"); #else static freertos_message_queue::FreeRTOSMessageQueue diff --git a/include/can/core/messages.hpp b/include/can/core/messages.hpp index 1e5d5d917..4f424b4d7 100644 --- a/include/can/core/messages.hpp +++ b/include/can/core/messages.hpp @@ -803,8 +803,8 @@ struct SendAccumulatedSensorDataRequest body = bit_utils::bytes_to_int(body, limit, sensor_id); body = bit_utils::bytes_to_int(body, limit, sensor_type); return SendAccumulatedSensorDataRequest{.message_index = msg_ind, - .sensor_id = sensor_id, - .sensor_type = sensor_type}; + .sensor_id = sensor_id, + .sensor_type = sensor_type}; } auto operator==(const SendAccumulatedSensorDataRequest& other) const diff --git a/include/common/core/sensor_buffer.hpp b/include/common/core/sensor_buffer.hpp new file mode 100644 index 000000000..b2e0c5bcc --- /dev/null +++ b/include/common/core/sensor_buffer.hpp @@ -0,0 +1,7 @@ +#pragma once + +#if defined(USE_SENSOR_MOVE) +constexpr size_t SENSOR_BUFFER_SIZE = P_BUFF_SIZE; +#else +constexpr size_t SENSOR_BUFFER_SIZE = 0; +#endif \ No newline at end of file diff --git a/include/gripper/core/can_task.hpp b/include/gripper/core/can_task.hpp index 8b627cdf9..334801bf6 100644 --- a/include/gripper/core/can_task.hpp +++ b/include/gripper/core/can_task.hpp @@ -26,7 +26,8 @@ using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::messages::AddLinearMoveRequest, can::messages::ClearAllMoveGroupsRequest, can::messages::ExecuteMoveGroupRequest, can::messages::GetMoveGroupRequest, - can::messages::HomeRequest, can::messages::StopRequest, can::messages::AddSensorMoveRequest>; + can::messages::HomeRequest, can::messages::StopRequest, + can::messages::AddSensorMoveRequest>; #else using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::move_group::MoveGroupHandler, diff --git a/include/gripper/core/tasks.hpp b/include/gripper/core/tasks.hpp index f67b3cef4..8e849547e 100644 --- a/include/gripper/core/tasks.hpp +++ b/include/gripper/core/tasks.hpp @@ -81,9 +81,11 @@ struct QueueClient : can::message_writer::MessageWriter { void send_pressure_sensor_queue_rear(const sensors::utils::TaskMessage& m); - void send_pressure_sensor_queue_front_isr(const sensors::utils::TaskMessage& m); - - void send_pressure_sensor_queue_rear_isr(const sensors::utils::TaskMessage& m); + void send_pressure_sensor_queue_front_isr( + const sensors::utils::TaskMessage& m); + + void send_pressure_sensor_queue_rear_isr( + const sensors::utils::TaskMessage& m); void send_tip_notification_queue_rear( const sensors::tip_presence::TaskMessage& m); diff --git a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp index ebf45ad6e..fc723e3b8 100644 --- a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp +++ b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp @@ -44,26 +44,32 @@ using namespace motor_messages; // take macros up a level to this? struct Empty { - static Empty& get_default(); + static auto get_default() -> Empty&; }; template struct SensorClientHelper { - inline static void send_to_pressure_sensor_queue(SensorClient& sensor_client, can::messages::BindSensorOutputRequest& m) { + inline static void send_to_pressure_sensor_queue( + SensorClient& sensor_client, + can::messages::BindSensorOutputRequest& m) { sensor_client.send_pressure_sensor_queue_rear_isr(m); } - inline static void send_to_capacitive_sensor_queue(SensorClient& sensor_client, can::messages::BindSensorOutputRequest& m) { + inline static void send_to_capacitive_sensor_queue( + SensorClient& sensor_client, + can::messages::BindSensorOutputRequest& m) { sensor_client.send_capacitive_sensor_queue_rear_isr(m); } }; -template<> +template <> struct SensorClientHelper { - inline static void send_to_pressure_sensor_queue(Empty& sensor_client, can::messages::BindSensorOutputRequest& m) { + inline static void send_to_pressure_sensor_queue( + Empty& sensor_client, can::messages::BindSensorOutputRequest& m) { std::ignore = sensor_client; std::ignore = m; } - inline static void send_to_capacitive_sensor_queue(Empty& sensor_client, can::messages::BindSensorOutputRequest& m) { + inline static void send_to_capacitive_sensor_queue( + Empty& sensor_client, can::messages::BindSensorOutputRequest& m) { std::ignore = sensor_client; std::ignore = m; } @@ -86,9 +92,9 @@ class MotorInterruptHandler { MotorHardware& hardware_iface, stall_check::StallCheck& stall, UpdatePositionQueue& incoming_update_position_queue) - : MotorInterruptHandler(incoming_move_queue, outgoing_queue, - driver_queue, hardware_iface, stall, incoming_update_position_queue, - Empty::get_default()) {} + : MotorInterruptHandler( + incoming_move_queue, outgoing_queue, driver_queue, hardware_iface, + stall, incoming_update_position_queue, Empty::get_default()) {} MotorInterruptHandler(MoveQueue& incoming_move_queue, StatusClient& outgoing_queue, DriverClient& driver_queue, @@ -416,7 +422,9 @@ class MotorInterruptHandler { return tick_count < buffered_move.duration; } #ifdef USE_SENSOR_MOVE - auto send_bind_message(can::ids::SensorType sensor_type, can::ids::SensorId sensor_id, uint8_t binding) -> void { + auto send_bind_message(can::ids::SensorType sensor_type, + can::ids::SensorId sensor_id, uint8_t binding) + -> void { auto msg = can::messages::BindSensorOutputRequest{ .message_index = buffered_move.message_index, .sensor = sensor_type, @@ -447,10 +455,13 @@ class MotorInterruptHandler { if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) { auto binding = static_cast(0x3); // sync and report if (buffered_move.sensor_id == can::ids::SensorId::BOTH) { - send_bind_message(buffered_move.sensor_type, can::ids::SensorId::S0, binding); - send_bind_message(buffered_move.sensor_type, can::ids::SensorId::S1, binding); + send_bind_message(buffered_move.sensor_type, + can::ids::SensorId::S0, binding); + send_bind_message(buffered_move.sensor_type, + can::ids::SensorId::S1, binding); } else { - send_bind_message(buffered_move.sensor_type, buffered_move.sensor_id, binding); + send_bind_message(buffered_move.sensor_type, + buffered_move.sensor_id, binding); } } #endif @@ -546,10 +557,13 @@ class MotorInterruptHandler { auto binding = static_cast(can::ids::SensorOutputBinding::sync); if (buffered_move.sensor_id == can::ids::SensorId::BOTH) { - send_bind_message(buffered_move.sensor_type, can::ids::SensorId::S0, binding); - send_bind_message(buffered_move.sensor_type, can::ids::SensorId::S1, binding); + send_bind_message(buffered_move.sensor_type, + can::ids::SensorId::S0, binding); + send_bind_message(buffered_move.sensor_type, + can::ids::SensorId::S1, binding); } else { - send_bind_message(buffered_move.sensor_type, buffered_move.sensor_id, binding); + send_bind_message(buffered_move.sensor_type, + buffered_move.sensor_id, binding); } } #endif @@ -698,21 +712,27 @@ class MotorInterruptHandler { #ifdef USE_SENSOR_MOVE void send_to_pressure_sensor_queue_rear( can::messages::BindSensorOutputRequest& m) { - SensorClientHelper::send_to_pressure_sensor_queue_rear(sensor_client, m); + SensorClientHelper::send_to_pressure_sensor_queue_rear( + sensor_client, m); } void send_to_pressure_sensor_queue_front( can::messages::BindSensorOutputRequest& m) { - // send to both queues, they will handle their own gating based on sensor id - SensorClientHelper::send_to_pressure_sensor_queue_front(sensor_client, m); + // send to both queues, they will handle their own gating based on + // sensor id + SensorClientHelper::send_to_pressure_sensor_queue_front( + sensor_client, m); } void send_to_capacitive_sensor_queue_rear( can::messages::BindSensorOutputRequest& m) { - SensorClientHelper::send_to_capacitive_sensor_queue_rear(sensor_client, m); + SensorClientHelper::send_to_capacitive_sensor_queue_rear( + sensor_client, m); } void send_to_capacitive_sensor_queue_front( can::messages::BindSensorOutputRequest& m) { - // send to both queues, they will handle their own gating based on sensor id - SensorClientHelper::send_to_capacitive_sensor_queue_front(sensor_client, m); + // send to both queues, they will handle their own gating based on + // sensor id + SensorClientHelper::send_to_capacitive_sensor_queue_front( + sensor_client, m); } #endif uint64_t tick_count = 0x0; diff --git a/include/pipettes/core/sensor_tasks.hpp b/include/pipettes/core/sensor_tasks.hpp index 5a177d945..0a4f575b3 100644 --- a/include/pipettes/core/sensor_tasks.hpp +++ b/include/pipettes/core/sensor_tasks.hpp @@ -108,9 +108,11 @@ struct QueueClient : can::message_writer::MessageWriter { void send_pressure_sensor_queue_front(const sensors::utils::TaskMessage& m); - void send_pressure_sensor_queue_rear_isr(const sensors::utils::TaskMessage& m); + void send_pressure_sensor_queue_rear_isr( + const sensors::utils::TaskMessage& m); - void send_pressure_sensor_queue_front_isr(const sensors::utils::TaskMessage& m); + void send_pressure_sensor_queue_front_isr( + const sensors::utils::TaskMessage& m); void send_tip_notification_queue_rear( const sensors::tip_presence::TaskMessage& m); diff --git a/include/sensors/core/message_handlers/sensors.hpp b/include/sensors/core/message_handlers/sensors.hpp index 1dd995330..533db997a 100644 --- a/include/sensors/core/message_handlers/sensors.hpp +++ b/include/sensors/core/message_handlers/sensors.hpp @@ -47,12 +47,14 @@ class SensorHandler { } void visit(const can::messages::SendAccumulatedSensorDataRequest &m) { - if (can::ids::SensorType(m.sensor_type) == can::ids::SensorType::pressure) { + if (can::ids::SensorType(m.sensor_type) == + can::ids::SensorType::pressure) { send_to_queue(can::ids::SensorType::pressure, - can::ids::SensorId(m.sensor_id), m); - } else if (can::ids::SensorType(m.sensor_type) == can::ids::SensorType::capacitive) { + can::ids::SensorId(m.sensor_id), m); + } else if (can::ids::SensorType(m.sensor_type) == + can::ids::SensorType::capacitive) { send_to_queue(can::ids::SensorType::capacitive, - can::ids::SensorId(m.sensor_id), m); + can::ids::SensorId(m.sensor_id), m); } } diff --git a/include/sensors/core/tasks/capacitive_driver.hpp b/include/sensors/core/tasks/capacitive_driver.hpp index 5d721960c..6581da146 100644 --- a/include/sensors/core/tasks/capacitive_driver.hpp +++ b/include/sensors/core/tasks/capacitive_driver.hpp @@ -27,12 +27,7 @@ #include "sensors/core/fdc1004.hpp" #include "sensors/core/sensor_hardware_interface.hpp" #include "sensors/core/utils.hpp" - -#if defined(USE_SENSOR_MOVE) -constexpr size_t SENSOR_BUFFER_SIZE = P_BUFF_SIZE; -#else -constexpr size_t SENSOR_BUFFER_SIZE = 0; -#endif +#include "common/core/sensor_buffer.hpp" namespace sensors { @@ -103,7 +98,7 @@ class FDC1004 { void set_echoing(bool should_echo) { echoing = should_echo; if (should_echo) { - sensor_buffer_index = 0; // reset buffer index + sensor_buffer_index = 0; // reset buffer index } } @@ -404,12 +399,12 @@ class FDC1004 { fdc1004::FDC1004RegisterMap _registers{}; bool _initialized = false; - static constexpr uint16_t DELAY = 20; // can we reduce? + static constexpr uint16_t DELAY = 20; // can we reduce? static constexpr uint16_t STOP_DELAY = 0; can::ids::SensorId sensor_id = can::ids::SensorId::S0; fdc1004::MeasureConfigMode measure_mode = fdc1004::MeasureConfigMode::ONE; fdc1004::MeasurementRate measurement_rate = - fdc1004::MeasurementRate::FOUR_HUNDRED_SAMPLES_PER_SECOND; + fdc1004::MeasurementRate::ONE_HUNDRED_SAMPLES_PER_SECOND; // make FOUR_HUNDRED_SAMPLES_PER_SECOND? bool shared_sensor = false; float current_offset_pf = 0; diff --git a/include/sensors/core/tasks/capacitive_sensor_task.hpp b/include/sensors/core/tasks/capacitive_sensor_task.hpp index ef4d1a5c8..15943bdc1 100644 --- a/include/sensors/core/tasks/capacitive_sensor_task.hpp +++ b/include/sensors/core/tasks/capacitive_sensor_task.hpp @@ -22,9 +22,10 @@ class CapacitiveMessageHandler { explicit CapacitiveMessageHandler( I2CQueueWriter &i2c_writer, I2CQueuePoller &i2c_poller, sensors::hardware::SensorHardwareBase &hardware, CanClient &can_client, - OwnQueue &own_queue, bool shared_task, std::array *p_buff) - : driver{i2c_writer, i2c_poller, can_client, - own_queue, hardware, shared_task, p_buff} {} + OwnQueue &own_queue, bool shared_task, + std::array *p_buff) + : driver{i2c_writer, i2c_poller, can_client, own_queue, + hardware, shared_task, p_buff} {} CapacitiveMessageHandler(const CapacitiveMessageHandler &) = delete; CapacitiveMessageHandler(const CapacitiveMessageHandler &&) = delete; auto operator=(const CapacitiveMessageHandler &) @@ -67,7 +68,7 @@ class CapacitiveMessageHandler { void visit(const can::messages::SendAccumulatedSensorDataRequest &m) { LOG("Received request to dump capacitive data buffer %d", m.sensor_id); - + driver.send_accumulated_sensor_data(m.message_index); } @@ -212,12 +213,14 @@ class CapacitiveSensorTask { i2c::writer::Writer *writer, i2c::poller::Poller *poller, sensors::hardware::SensorHardwareBase *hardware, CanClient *can_client, - std::array *p_buff, bool shared_task = false) { + std::array *p_buff, + bool shared_task = false) { // On the 8 channel, there is a singular cap sensor but we're using // multiple channels. We will thus rely on the sensor id in this case // to determine which CIN configuration the sensor should be in. auto handler = CapacitiveMessageHandler{ - *writer, *poller, *hardware, *can_client, get_queue(), shared_task, p_buff}; + *writer, *poller, *hardware, *can_client, + get_queue(), shared_task, p_buff}; handler.initialize(); utils::TaskMessage message{}; for (;;) { diff --git a/include/sensors/core/tasks/environmental_sensor_task.hpp b/include/sensors/core/tasks/environmental_sensor_task.hpp index 57b272a3e..e1694a80b 100644 --- a/include/sensors/core/tasks/environmental_sensor_task.hpp +++ b/include/sensors/core/tasks/environmental_sensor_task.hpp @@ -76,7 +76,8 @@ class EnvironmentSensorMessageHandler { } void visit(const can::messages::SendAccumulatedSensorDataRequest &m) { - LOG("Received request to dump environmental data buffer %d", m.sensor_id); + LOG("Received request to dump environmental data buffer %d", + m.sensor_id); std::ignore = m; } diff --git a/include/sensors/core/tasks/pressure_driver.hpp b/include/sensors/core/tasks/pressure_driver.hpp index 1ccf9db88..17883d1ef 100644 --- a/include/sensors/core/tasks/pressure_driver.hpp +++ b/include/sensors/core/tasks/pressure_driver.hpp @@ -13,14 +13,7 @@ #include "sensors/core/sensor_hardware_interface.hpp" #include "sensors/core/sensors.hpp" #include "sensors/core/utils.hpp" - -/* -#if defined(USE_SENSOR_MOVE) -constexpr size_t SENSOR_BUFFER_SIZE = P_BUFF_SIZE; -#else -constexpr size_t SENSOR_BUFFER_SIZE = 0; -#endif -*/ +#include "common/core/sensor_buffer.hpp" namespace sensors { diff --git a/motor-control/core/motor_interrupt_handler.cpp b/motor-control/core/motor_interrupt_handler.cpp index 30e3ea868..e9c8b29ba 100644 --- a/motor-control/core/motor_interrupt_handler.cpp +++ b/motor-control/core/motor_interrupt_handler.cpp @@ -1,6 +1,4 @@ #include "motor-control/core/stepper_motor/motor_interrupt_handler.hpp" motor_handler::Empty empty{}; -auto motor_handler::Empty::get_default() -> Empty& { - return empty; -} \ No newline at end of file +auto motor_handler::Empty::get_default() -> Empty& { return empty; } \ No newline at end of file diff --git a/sensors/tests/test_capacitive_sensor.cpp b/sensors/tests/test_capacitive_sensor.cpp index 97c139c7b..89b172d11 100644 --- a/sensors/tests/test_capacitive_sensor.cpp +++ b/sensors/tests/test_capacitive_sensor.cpp @@ -30,6 +30,8 @@ auto get_message_i2c(Queue& q) -> Message { auto sensor_id = can::ids::SensorId::S0; constexpr uint8_t sensor_id_int = 0x0; +static std::array p_buff; + SCENARIO("read capacitance sensor values without shared CINs") { test_mocks::MockSensorHardware mock_hw{}; test_mocks::MockMessageQueue i2c_queue{}; @@ -53,7 +55,7 @@ SCENARIO("read capacitance sensor values without shared CINs") { poller.set_queue(&poller_queue); auto sensor_not_shared = sensors::tasks::CapacitiveMessageHandler{ - writer, poller, mock_hw, queue_client, response_queue, false}; + writer, poller, mock_hw, queue_client, response_queue, false, &p_buff}; constexpr uint8_t capacitive_id = 0x1; GIVEN("a initialize sensor request") { @@ -381,7 +383,7 @@ SCENARIO("read capacitance sensor values supporting shared CINs") { poller.set_queue(&poller_queue); auto sensor_shared = sensors::tasks::CapacitiveMessageHandler{ - writer, poller, mock_hw, queue_client, response_queue, true}; + writer, poller, mock_hw, queue_client, response_queue, true, &p_buff}; constexpr uint8_t capacitive_id = 0x1; GIVEN("a initialize sensor request") { @@ -579,7 +581,7 @@ SCENARIO("capacitance driver tests no shared CINs") { queue_client.set_queue(&can_queue); writer.set_queue(&i2c_queue); sensors::tasks::FDC1004 callback_host(writer, poller, queue_client, - response_queue, mock_hw, false); + response_queue, mock_hw, false, &p_buff); can::message_writer_task::TaskMessage empty_msg{}; @@ -769,7 +771,7 @@ SCENARIO("threshold configuration") { poller.set_queue(&poller_queue); auto sensor = sensors::tasks::CapacitiveMessageHandler{ - writer, poller, mock_hw, queue_client, response_queue, false}; + writer, poller, mock_hw, queue_client, response_queue, false, &p_buff}; GIVEN("A request to set an autothreshold") { int NUM_READS = 10;