Skip to content

Commit

Permalink
rip out the unneeded templating of sensor hardware since that stuff i…
Browse files Browse the repository at this point in the history
…s behind ifdefs
  • Loading branch information
ryanthecoder committed Jun 4, 2024
1 parent 5f65a2b commit 77dce9e
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 120 deletions.
4 changes: 4 additions & 0 deletions gripper/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,7 @@ auto gripper_tasks::get_all_tasks() -> AllTask& { return tasks; }
* @return
*/
auto gripper_tasks::get_main_queues() -> QueueClient& { return queues; }

auto sensor_tasks::get_queues() -> gripper_tasks::QueueClient& {
return queues;
}
2 changes: 1 addition & 1 deletion gripper/firmware/interfaces_z_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static motor_class::Motor z_motor{
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gripper_tasks::z_tasks::get_queues(), motor_hardware_iface,
stallcheck, update_position_queue, gripper_tasks::get_main_queues());
stallcheck, update_position_queue);

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down
4 changes: 4 additions & 0 deletions include/gripper/core/tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,7 @@ struct QueueClient : can::message_writer::MessageWriter {
} // namespace g_tasks

} // namespace gripper_tasks

namespace sensor_tasks {
[[nodiscard]] auto get_queues() -> gripper_tasks::QueueClient&;
} // namespace sensor_tasks
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
#include "motor-control/core/motor_messages.hpp"
#include "motor-control/core/stall_check.hpp"
#include "motor-control/core/tasks/move_status_reporter_task.hpp"

#include "motor-control/core/tasks/tmc_motor_driver_common.hpp"
#ifdef USE_SENSOR_MOVE
#ifdef PIPETTE_TYPE_DEFINE
#include "pipettes/core/sensor_tasks.hpp"
#else
#include "gripper/core/tasks.hpp"
#endif // PIPETTE_TYPE_DEFINE
#endif // USE_SENSOR_MOVE
namespace motor_handler {

using namespace motor_messages;
Expand Down Expand Up @@ -41,61 +48,8 @@ using namespace motor_messages;
* Note: The position tracker should never be allowed to go below zero.
*/

struct Empty {
static auto get_default() -> Empty&;
};

template <class SensorClient>
struct SensorClientHelper {
inline static void send_to_pressure_sensor_queue_rear(
SensorClient& sensor_client,
can::messages::BindSensorOutputRequest& m) {
sensor_client.send_pressure_sensor_queue_rear_isr(m);
}
inline static void send_to_pressure_sensor_queue_front(
SensorClient& sensor_client,
can::messages::BindSensorOutputRequest& m) {
sensor_client.send_pressure_sensor_queue_front_isr(m);
}
inline static void send_to_capacitive_sensor_queue_rear(
SensorClient& sensor_client,
can::messages::BindSensorOutputRequest& m) {
sensor_client.send_capacitive_sensor_queue_rear_isr(m);
}
inline static void send_to_capacitive_sensor_queue_front(
SensorClient& sensor_client,
can::messages::BindSensorOutputRequest& m) {
sensor_client.send_capacitive_sensor_queue_front_isr(m);
}
};

template <>
struct SensorClientHelper<Empty> {
inline static void send_to_pressure_sensor_queue_rear(
Empty& sensor_client, can::messages::BindSensorOutputRequest& m) {
std::ignore = sensor_client;
std::ignore = m;
}
inline static void send_to_pressure_sensor_queue_front(
Empty& sensor_client, can::messages::BindSensorOutputRequest& m) {
std::ignore = sensor_client;
std::ignore = m;
}
inline static void send_to_capacitive_sensor_queue_rear(
Empty& sensor_client, can::messages::BindSensorOutputRequest& m) {
std::ignore = sensor_client;
std::ignore = m;
}
inline static void send_to_capacitive_sensor_queue_front(
Empty& sensor_client, can::messages::BindSensorOutputRequest& m) {
std::ignore = sensor_client;
std::ignore = m;
}
};

template <template <class> class QueueImpl, class StatusClient,
typename MotorMoveMessage, typename MotorHardware,
class SensorClient = Empty>
typename MotorMoveMessage, typename MotorHardware>
requires MessageQueue<QueueImpl<MotorMoveMessage>, MotorMoveMessage> &&
std::is_base_of_v<motor_hardware::MotorHardwareIface, MotorHardware>
class MotorInterruptHandler {
Expand All @@ -109,21 +63,11 @@ class MotorInterruptHandler {
MotorHardware& hardware_iface,
stall_check::StallCheck& stall,
UpdatePositionQueue& incoming_update_position_queue)
: MotorInterruptHandler(
incoming_move_queue, outgoing_queue, hardware_iface, stall,
incoming_update_position_queue, Empty::get_default()) {}
MotorInterruptHandler(MoveQueue& incoming_move_queue,
StatusClient& outgoing_queue,
MotorHardware& hardware_iface,
stall_check::StallCheck& stall,
UpdatePositionQueue& incoming_update_position_queue,
SensorClient& sensor_queue)
: move_queue(incoming_move_queue),
status_queue_client(outgoing_queue),
hardware(hardware_iface),
stall_checker{stall},
update_position_queue(incoming_update_position_queue),
sensor_client(sensor_queue) {
update_position_queue(incoming_update_position_queue) {
hardware.unstep();
}
~MotorInterruptHandler() = default;
Expand Down Expand Up @@ -718,27 +662,23 @@ 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);
sensor_tasks::get_queues().send_pressure_sensor_queue_rear_isr(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);
sensor_tasks::get_queues().send_pressure_sensor_queue_front_isr(m);
}
void send_to_capacitive_sensor_queue_rear(
can::messages::BindSensorOutputRequest& m) {
SensorClientHelper<SensorClient>::send_to_capacitive_sensor_queue_rear(
sensor_client, m);
sensor_tasks::get_queues().send_capacitive_sensor_queue_rear_isr(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);
sensor_tasks::get_queues().send_pressure_sensor_queue_front_isr(m);
}
#endif
uint64_t tick_count = 0x0;
Expand All @@ -751,7 +691,6 @@ class MotorInterruptHandler {
MotorHardware& hardware;
stall_check::StallCheck& stall_checker;
UpdatePositionQueue& update_position_queue;
SensorClient& sensor_client;
MotorMoveMessage buffered_move = MotorMoveMessage{};
bool clear_queue_until_empty = false;
bool stall_handled = false;
Expand Down
13 changes: 5 additions & 8 deletions include/pipettes/firmware/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ namespace interfaces {
#ifdef USE_SENSOR_MOVE
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue,
Client motor_messages::SensorSyncMove, motor_hardware::MotorHardware,
sensor_tasks::QueueClient>;
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::SensorSyncMove, motor_hardware::MotorHardware>;
#else
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client, motor_messages::Move,
motor_hardware::MotorHardware, sensor_tasks::QueueClient>;
motor_hardware::MotorHardware>;
#endif
template <typename Client>
using GearMotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
Expand Down Expand Up @@ -75,13 +74,11 @@ namespace linear_motor {

auto get_interrupt(motor_hardware::MotorHardware& hw,
LowThroughputInterruptQueues& queues,
stall_check::StallCheck& stall,
sensor_tasks::QueueClient& sensor_client)
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;
auto get_interrupt(motor_hardware::MotorHardware& hw,
HighThroughputInterruptQueues& queues,
stall_check::StallCheck& stall,
sensor_tasks::QueueClient& sensor_client)
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;
auto get_motor_hardware(motor_configs::LowThroughputPipetteMotorHardware pins)
-> motor_hardware::MotorHardware;
Expand Down
11 changes: 4 additions & 7 deletions include/pipettes/firmware/interfaces_g4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ namespace interfaces {
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
motor_messages::SensorSyncMove, motor_hardware::MotorHardware,
sensor_tasks::QueueClient>;
motor_messages::SensorSyncMove, motor_hardware::MotorHardware>;
#else
template <typename Client>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client, motor_messages::Move,
motor_hardware::MotorHardware, sensor_tasks::QueueClient>;
motor_hardware::MotorHardware>;
#endif
template <typename Client>
using GearMotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
Expand Down Expand Up @@ -84,13 +83,11 @@ namespace linear_motor {

auto get_interrupt(motor_hardware::MotorHardware& hw,
LowThroughputInterruptQueues& queues,
stall_check::StallCheck& stall,
sensor_tasks::QueueClient& sensor_client)
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;
auto get_interrupt(motor_hardware::MotorHardware& hw,
HighThroughputInterruptQueues& queues,
stall_check::StallCheck& stall,
sensor_tasks::QueueClient& sensor_client)
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;
auto get_motor_hardware(motor_hardware::HardwareConfig pins)
-> motor_hardware::MotorHardware;
Expand Down
24 changes: 19 additions & 5 deletions include/pipettes/simulator/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,28 @@ auto get_interrupt_queues<PipetteType::THREE_EIGHTY_FOUR_CHANNEL>()
namespace linear_motor {

auto get_interrupt(sim_motor_hardware_iface::SimMotorHardwareIface& hw,
MoveQueue& queue, stall_check::StallCheck& stall,
UpdatePositionQueue& update_queue)
LowThroughputInterruptQueues& queues,
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;

auto get_interrupt(sim_motor_hardware_iface::SimMotorHardwareIface& hw,
HighThroughputInterruptQueues& queues,
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;

auto get_interrupt_driver(
sim_motor_hardware_iface::SimMotorHardwareIface& hw,
LowThroughputInterruptQueues& queues,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient>& handler)
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient,
linear_motor_tasks::tmc2130_driver::QueueClient, motor_messages::Move,
sim_motor_hardware_iface::SimMotorHardwareIface>;

auto get_interrupt_driver(
sim_motor_hardware_iface::SimMotorHardwareIface& hw, MoveQueue& queue,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient>& handler,
UpdatePositionQueue& update_queue)
sim_motor_hardware_iface::SimMotorHardwareIface& hw,
HighThroughputInterruptQueues& queues,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient>& handler)
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient, motor_messages::Move,
sim_motor_hardware_iface::SimMotorHardwareIface>;
Expand Down
11 changes: 5 additions & 6 deletions motor-control/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
add_library(motor-utils STATIC
add_library(motor-utils STATIC
motor_hardware_interface.cpp
stall_check.cpp
types.cpp
utils.cpp
motor_interrupt_handler.cpp)
types.cpp
utils.cpp)

set_target_properties(motor-utils
PROPERTIES CXX_STANDARD 20
Expand All @@ -23,7 +22,7 @@ target_compile_options(motor-utils
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)

target_include_directories(motor-utils PUBLIC
target_include_directories(motor-utils PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../../include)

add_coverage(motor-utils)
add_coverage(motor-utils)
4 changes: 0 additions & 4 deletions motor-control/core/motor_interrupt_handler.cpp

This file was deleted.

10 changes: 4 additions & 6 deletions pipettes/firmware/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@ void linear_motor::encoder_interrupt(motor_hardware::MotorHardware& hw,

auto linear_motor::get_interrupt(motor_hardware::MotorHardware& hw,
LowThroughputInterruptQueues& queues,
stall_check::StallCheck& stall,
sensor_tasks::QueueClient& sensor_client)
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient> {
return motor_handler::MotorInterruptHandler(
queues.plunger_queue, linear_motor_tasks::get_queues(), hw, stall,
queues.plunger_update_queue, sensor_client);
queues.plunger_update_queue);
}

auto linear_motor::get_interrupt(motor_hardware::MotorHardware& hw,
HighThroughputInterruptQueues& queues,
stall_check::StallCheck& stall,
sensor_tasks::QueueClient& sensor_client)
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient> {
return motor_handler::MotorInterruptHandler(
queues.plunger_queue, linear_motor_tasks::get_queues(), hw, stall,
queues.plunger_update_queue, sensor_client);
queues.plunger_update_queue);
}

struct motor_hardware::UsageEEpromConfig plunger_usage_config {
Expand Down
3 changes: 1 addition & 2 deletions pipettes/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ static auto linear_motor_hardware =
interfaces::linear_motor::get_motor_hardware(
motor_config.hardware_pins.linear_motor);
static auto plunger_interrupt = interfaces::linear_motor::get_interrupt(
linear_motor_hardware, interrupt_queues, linear_stall_check,
sensor_queue_client);
linear_motor_hardware, interrupt_queues, linear_stall_check);
static auto linear_motion_control =
interfaces::linear_motor::get_motion_control(linear_motor_hardware,
interrupt_queues);
Expand Down
24 changes: 18 additions & 6 deletions pipettes/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ auto interfaces::get_interrupt_queues<PipetteType::THREE_EIGHTY_FOUR_CHANNEL>()
}

auto linear_motor::get_interrupt(
sim_motor_hardware_iface::SimMotorHardwareIface& hw, MoveQueue& queue,
stall_check::StallCheck& stall, UpdatePositionQueue& update_queue)
sim_motor_hardware_iface::SimMotorHardwareIface& hw,
LowThroughputInterruptQueues& queues, stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient> {
return motor_handler::MotorInterruptHandler(
queue, linear_motor_tasks::get_queues(), hw, stall, update_queue);
queues.plunger_queue, linear_motor_tasks::get_queues(), hw, stall,
queues.plunger_update_queue);
}

auto linear_motor::get_interrupt(
sim_motor_hardware_iface::SimMotorHardwareIface& hw,
HighThroughputInterruptQueues& queues, stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<
linear_motor_tasks::QueueClient,
linear_motor_tasks::tmc2160_driver::QueueClient> {
return motor_handler::MotorInterruptHandler(
queues.plunger_queue, linear_motor_tasks::get_queues(), hw, stall,
queues.plunger_update_queue);
}

auto linear_motor::get_interrupt_driver(
sim_motor_hardware_iface::SimMotorHardwareIface& hw, MoveQueue& queue,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient>& handler,
UpdatePositionQueue& update_queue)
sim_motor_hardware_iface::SimMotorHardwareIface& hw,
LowThroughputInterruptQueues& queues,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient>& handler)
#ifdef USE_SENSOR_MOVE
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient, motor_messages::SensorSyncMove,
Expand Down

0 comments on commit 77dce9e

Please sign in to comment.