Skip to content

Commit

Permalink
test and simulator build changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Oct 25, 2023
1 parent d2307be commit f3f224b
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 51 deletions.
6 changes: 4 additions & 2 deletions gantry/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gantry::queues::get_queues(), motor_interface, stallcheck,
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(), motor_interface, stallcheck,
update_position_queue);

static motor_interrupt_driver::MotorInterruptDriver A(motor_queue,
motor_interrupt,
motor_interface,
update_position_queue);
void interfaces::initialize() {}
void interfaces::initialize(diag0_handler* call_diag0_handler) {
static_cast<void>(call_diag0_handler);
}

static po::variables_map options{};

Expand Down
6 changes: 4 additions & 2 deletions gantry/simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ void signal_handler(int signum) {
exit(signum);
}

static interfaces::diag0_handler call_diag0_handler = NULL;

int main(int argc, char** argv) {
signal(SIGINT, signal_handler);

Expand All @@ -21,10 +23,10 @@ int main(int argc, char** argv) {
return pcTaskGetName(xTaskGetCurrentTaskHandle());
});

interfaces::initialize();
interfaces::initialize(&call_diag0_handler);
interfaces::initialize_sim(argc, argv);

gantry::tasks::start_tasks(
call_diag0_handler = gantry::tasks::start_tasks(
interfaces::get_can_bus(), interfaces::get_motor().motion_controller,
interfaces::get_spi(), interfaces::get_driver_config(),
interfaces::get_motor_hardware_task(), *interfaces::get_sim_i2c2(),
Expand Down
2 changes: 1 addition & 1 deletion gripper/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gripper_tasks::z_tasks::get_queues(), motor_interface,
motor_queue, gripper_tasks::z_tasks::get_queues(), gripper_tasks::z_tasks::get_queues(), motor_interface,
stallcheck, update_position_queue);

static motor_interrupt_driver::MotorInterruptDriver A(motor_queue,
Expand Down
4 changes: 2 additions & 2 deletions head/simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static stall_check::StallCheck stallcheck_right(
linear_config.get_usteps_per_mm() / 1000.0F, utils::STALL_THRESHOLD_UM);

static motor_handler::MotorInterruptHandler motor_interrupt_right(
motor_queue_right, head_tasks::get_right_queues(), motor_interface_right,
motor_queue_right, head_tasks::get_right_queues(), head_tasks::get_right_queues(), motor_interface_right,
stallcheck_right, update_position_queue_right);

static stall_check::StallCheck stallcheck_left(
Expand All @@ -117,7 +117,7 @@ static motor_class::Motor motor_right{
motor_queue_right, update_position_queue_right};

static motor_handler::MotorInterruptHandler motor_interrupt_left(
motor_queue_left, head_tasks::get_left_queues(), motor_interface_left,
motor_queue_left, head_tasks::get_left_queues(), head_tasks::get_left_queues(), motor_interface_left,
stallcheck_left, update_position_queue_left);

static motor_class::Motor motor_left{
Expand Down
4 changes: 2 additions & 2 deletions include/motor-control/simulation/motor_interrupt_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

namespace motor_interrupt_driver {

template <class StatusClient, typename MotorMoveMessage, class MotorHardware>
template <class StatusClient, class DriverClient, typename MotorMoveMessage, class MotorHardware>
class MotorInterruptDriver {
using InterruptQueue =
freertos_message_queue::FreeRTOSMessageQueue<MotorMoveMessage>;
using MotorPositionUpdateQueue =
freertos_message_queue::FreeRTOSMessageQueue<
can::messages::UpdateMotorPositionEstimationRequest>;
using InterruptHandler = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, StatusClient,
freertos_message_queue::FreeRTOSMessageQueue, StatusClient, DriverClient,
MotorMoveMessage, MotorHardware>;

public:
Expand Down
24 changes: 12 additions & 12 deletions include/motor-control/simulation/sim_motor_hardware_iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class SimMotorHardwareIface : public motor_hardware::StepperMotorHardwareIface {
bool check_estop_in() final { return estop_detected; }

void set_estop(bool estop_pressed) { estop_detected = estop_pressed; }
auto has_cancel_request() -> bool final {
return cancel_request.exchange(false);
auto has_cancel_request() -> uint8_t final {
return cancel_request.exchange(0);
}
void request_cancel() final { cancel_request.store(true); }
void request_cancel(uint8_t error_severity) final { cancel_request.store(error_severity); }
auto get_usage_eeprom_config()
-> motor_hardware::UsageEEpromConfig & final {
return eeprom_config;
Expand All @@ -106,7 +106,7 @@ class SimMotorHardwareIface : public motor_hardware::StepperMotorHardwareIface {
Direction _direction = Direction::POSITIVE;
float _encoder_ticks_per_pulse = 0;
bool estop_detected = false;
std::atomic<bool> cancel_request = false;
std::atomic<uint8_t> cancel_request = 0;
motor_hardware::UsageEEpromConfig eeprom_config = {
std::array<UsageRequestSet, 1>{UsageRequestSet{
.eeprom_key = 0,
Expand Down Expand Up @@ -177,10 +177,10 @@ class SimBrushedMotorHardwareIface
return ret;
}

auto has_cancel_request() -> bool final {
return cancel_request.exchange(false);
auto has_cancel_request() -> uint8_t final {
return cancel_request.exchange(0);
}
void request_cancel() final { cancel_request.store(true); }
void request_cancel(uint8_t error_severity) final { cancel_request.store(error_severity); }

void disable_encoder() final {}
void enable_encoder() final {}
Expand All @@ -198,7 +198,7 @@ class SimBrushedMotorHardwareIface
StateManagerHandle _state_manager = nullptr;
MoveMessageHardware _id;
bool estop_detected = false;
std::atomic<bool> cancel_request = false;
std::atomic<uint8_t> cancel_request = 0;
motor_hardware::UsageEEpromConfig eeprom_config{
std::array<UsageRequestSet, 1>{UsageRequestSet{
.eeprom_key = 0,
Expand Down Expand Up @@ -263,10 +263,10 @@ class SimGearMotorHardwareIface
bool check_estop_in() final { return estop_detected; }

void set_estop(bool estop_pressed) { estop_detected = estop_pressed; }
auto has_cancel_request() -> bool final {
return cancel_request.exchange(false);
auto has_cancel_request() -> uint8_t final {
return cancel_request.exchange(0);
}
void request_cancel() final { cancel_request.store(true); }
void request_cancel(uint8_t error_severity) final { cancel_request.store(error_severity); }

auto get_usage_eeprom_config()
-> motor_hardware::UsageEEpromConfig & final {
Expand All @@ -283,7 +283,7 @@ class SimGearMotorHardwareIface
Direction _direction = Direction::POSITIVE;
float _encoder_ticks_per_pulse = 0;
bool estop_detected = false;
std::atomic<bool> cancel_request = false;
std::atomic<uint8_t> cancel_request = 0;
motor_hardware::UsageEEpromConfig eeprom_config = {
std::array<UsageRequestSet, 1>{UsageRequestSet{
.eeprom_key = 0,
Expand Down
37 changes: 25 additions & 12 deletions include/pipettes/simulator/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

namespace interfaces {

template <typename Client>
template <typename Client, typename DriverClient>
using MotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client, motor_messages::Move,
freertos_message_queue::FreeRTOSMessageQueue, Client, DriverClient, motor_messages::Move,
sim_motor_hardware_iface::SimMotorHardwareIface>;

template <typename Client>
using GearMotorInterruptHandlerType = motor_handler::MotorInterruptHandler<
freertos_message_queue::FreeRTOSMessageQueue, Client,
freertos_message_queue::FreeRTOSMessageQueue, Client, Client,
motor_messages::GearMotorMove,
sim_motor_hardware_iface::SimGearMotorHardwareIface>;

Expand Down Expand Up @@ -61,16 +61,29 @@ 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)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient>;
LowThroughputInterruptQueues& queues,
stall_check::StallCheck& stall)
-> MotorInterruptHandlerType<linear_motor_tasks::QueueClient, linear_motor_tasks::tmc2130_driver::QueueClient>;

auto 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>;

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

auto get_motor_hardware() -> sim_motor_hardware_iface::SimMotorHardwareIface;
Expand All @@ -93,11 +106,11 @@ struct GearInterruptHandlers {

struct GearInterruptDrivers {
motor_interrupt_driver::MotorInterruptDriver<
gear_motor_tasks::QueueClient, motor_messages::GearMotorMove,
gear_motor_tasks::QueueClient, gear_motor_tasks::QueueClient, motor_messages::GearMotorMove,
sim_motor_hardware_iface::SimGearMotorHardwareIface>
left;
motor_interrupt_driver::MotorInterruptDriver<
gear_motor_tasks::QueueClient, motor_messages::GearMotorMove,
gear_motor_tasks::QueueClient, gear_motor_tasks::QueueClient, motor_messages::GearMotorMove,
sim_motor_hardware_iface::SimGearMotorHardwareIface>
right;
};
Expand Down
47 changes: 34 additions & 13 deletions pipettes/simulator/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,44 @@ auto interfaces::get_interrupt_queues<PipetteType::THREE_EIGHTY_FOUR_CHANNEL>()
.left_update_queue = UpdatePositionQueue{"Left PUpdate Queue"}};
}

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

auto linear_motor::get_interrupt_driver(
sim_motor_hardware_iface::SimMotorHardwareIface& hw,
LowThroughputInterruptQueues& queues,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient, linear_motor_tasks::tmc2130_driver::QueueClient>& handler)
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient, linear_motor_tasks::tmc2130_driver::QueueClient, motor_messages::Move,
sim_motor_hardware_iface::SimMotorHardwareIface> {
return motor_interrupt_driver::MotorInterruptDriver(queues.plunger_queue, handler, hw,
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,
HighThroughputInterruptQueues& queues,
MotorInterruptHandlerType<linear_motor_tasks::QueueClient, linear_motor_tasks::tmc2160_driver::QueueClient>& handler)
-> motor_interrupt_driver::MotorInterruptDriver<
linear_motor_tasks::QueueClient, motor_messages::Move,
linear_motor_tasks::QueueClient, linear_motor_tasks::tmc2160_driver::QueueClient, motor_messages::Move,
sim_motor_hardware_iface::SimMotorHardwareIface> {
return motor_interrupt_driver::MotorInterruptDriver(queue, handler, hw,
update_queue);
return motor_interrupt_driver::MotorInterruptDriver(queues.plunger_queue, handler, hw,
queues.plunger_update_queue);
}

auto linear_motor::get_motor_hardware()
Expand Down Expand Up @@ -103,10 +124,10 @@ auto gear_motor::get_interrupts(gear_motor::GearHardware& hw,
return gear_motor::GearInterruptHandlers{
.left = motor_handler::MotorInterruptHandler(
queues.left_motor_queue, gear_motor_tasks::get_left_gear_queues(),
hw.left, stall.left, queues.left_update_queue),
gear_motor_tasks::get_left_gear_queues(), hw.left, stall.left, queues.left_update_queue),
.right = motor_handler::MotorInterruptHandler(
queues.right_motor_queue, gear_motor_tasks::get_right_gear_queues(),
hw.right, stall.right, queues.right_update_queue),
gear_motor_tasks::get_right_gear_queues(), hw.right, stall.right, queues.right_update_queue),
};
}

Expand Down
6 changes: 2 additions & 4 deletions pipettes/simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ static auto gear_stall_check = interfaces::gear_motor::GearStallCheck{
static auto linear_motor_hardware =
interfaces::linear_motor::get_motor_hardware();
static auto plunger_interrupt = interfaces::linear_motor::get_interrupt(
linear_motor_hardware, interrupt_queues.plunger_queue, linear_stall_check,
interrupt_queues.plunger_update_queue);
linear_motor_hardware, interrupt_queues, linear_stall_check);
static auto plunger_interrupt_driver =
interfaces::linear_motor::get_interrupt_driver(
linear_motor_hardware, interrupt_queues.plunger_queue,
plunger_interrupt, interrupt_queues.plunger_update_queue);
linear_motor_hardware, interrupt_queues, plunger_interrupt);
static auto linear_motion_control =
interfaces::linear_motor::get_motion_control(linear_motor_hardware,
interrupt_queues);
Expand Down
2 changes: 1 addition & 1 deletion sensors/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ target_compile_options(sensors
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)

target_link_libraries(sensors PUBLIC Catch2::Catch2 common-core motor-utils common-simulation)
target_link_libraries(sensors PUBLIC Catch2::Catch2 Boost::boost Boost::program_options Boost::date_time common-core motor-utils common-simulation)

target_i2c_simlib(sensors)

Expand Down

0 comments on commit f3f224b

Please sign in to comment.