Skip to content

Commit

Permalink
format lint test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Apr 30, 2024
1 parent c3fbd2a commit 070ad67
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 67 deletions.
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"installDir": "${sourceDir}/dist-sensor",
"binaryDir": "${sourceDir}/build-cross-sensor",
"cacheVariables": {
"USE_PRESSURE_MOVE": true
"USE_SENSOR_MOVE": true
},
"inherits": "cross"
},
Expand Down
3 changes: 2 additions & 1 deletion gripper/firmware/interfaces_z_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ static tmc2130::configs::TMC2130DriverConfig MotorDriverConfigurations{
* The pending move queue
*/
#ifdef USE_SENSOR_MOVE
static freertos_message_queue::FreeRTOSMessageQueue<motor_messages::SensorSyncMove>
static freertos_message_queue::FreeRTOSMessageQueue<
motor_messages::SensorSyncMove>
motor_queue("Motor Queue");
#else
static freertos_message_queue::FreeRTOSMessageQueue<motor_messages::Move>
Expand Down
4 changes: 2 additions & 2 deletions include/can/core/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions include/common/core/sensor_buffer.hpp
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion include/gripper/core/can_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<z_tasks::QueueClient>,
Expand Down
8 changes: 5 additions & 3 deletions include/gripper/core/tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class SensorClient>
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<Empty> {
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;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -447,10 +455,13 @@ class MotorInterruptHandler {
if (buffered_move.sensor_id != can::ids::SensorId::UNUSED) {
auto binding = static_cast<uint8_t>(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
Expand Down Expand Up @@ -546,10 +557,13 @@ class MotorInterruptHandler {
auto binding =
static_cast<uint8_t>(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
Expand Down Expand Up @@ -698,21 +712,27 @@ class MotorInterruptHandler {
#ifdef USE_SENSOR_MOVE
void send_to_pressure_sensor_queue_rear(
can::messages::BindSensorOutputRequest& m) {
SensorClientHelper<SensorClient>::send_to_pressure_sensor_queue_rear(sensor_client, m);
SensorClientHelper<SensorClient>::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<SensorClient>::send_to_pressure_sensor_queue_front(sensor_client, m);
// send to both queues, they will handle their own gating based on
// sensor id
SensorClientHelper<SensorClient>::send_to_pressure_sensor_queue_front(
sensor_client, m);
}
void send_to_capacitive_sensor_queue_rear(
can::messages::BindSensorOutputRequest& m) {
SensorClientHelper<SensorClient>::send_to_capacitive_sensor_queue_rear(sensor_client, m);
SensorClientHelper<SensorClient>::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<SensorClient>::send_to_capacitive_sensor_queue_front(sensor_client, m);
// send to both queues, they will handle their own gating based on
// sensor id
SensorClientHelper<SensorClient>::send_to_capacitive_sensor_queue_front(
sensor_client, m);
}
#endif
uint64_t tick_count = 0x0;
Expand Down
6 changes: 4 additions & 2 deletions include/pipettes/core/sensor_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions include/sensors/core/message_handlers/sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 4 additions & 9 deletions include/sensors/core/tasks/capacitive_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions include/sensors/core/tasks/capacitive_sensor_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, SENSOR_BUFFER_SIZE> *p_buff)
: driver{i2c_writer, i2c_poller, can_client,
own_queue, hardware, shared_task, p_buff} {}
OwnQueue &own_queue, bool shared_task,
std::array<float, SENSOR_BUFFER_SIZE> *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 &)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -212,12 +213,14 @@ class CapacitiveSensorTask {
i2c::writer::Writer<QueueImpl> *writer,
i2c::poller::Poller<QueueImpl> *poller,
sensors::hardware::SensorHardwareBase *hardware, CanClient *can_client,
std::array<float, SENSOR_BUFFER_SIZE> *p_buff, bool shared_task = false) {
std::array<float, SENSOR_BUFFER_SIZE> *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 (;;) {
Expand Down
3 changes: 2 additions & 1 deletion include/sensors/core/tasks/environmental_sensor_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 1 addition & 8 deletions include/sensors/core/tasks/pressure_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 1 addition & 3 deletions motor-control/core/motor_interrupt_handler.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
auto motor_handler::Empty::get_default() -> Empty& { return empty; }
10 changes: 6 additions & 4 deletions sensors/tests/test_capacitive_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, SENSOR_BUFFER_SIZE> p_buff;

SCENARIO("read capacitance sensor values without shared CINs") {
test_mocks::MockSensorHardware mock_hw{};
test_mocks::MockMessageQueue<i2c::writer::TaskMessage> i2c_queue{};
Expand All @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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{};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 070ad67

Please sign in to comment.