diff --git a/include/can/core/message_handlers/move_group.hpp b/include/can/core/message_handlers/move_group.hpp index c3c4bf973..9cd589ad6 100644 --- a/include/can/core/message_handlers/move_group.hpp +++ b/include/can/core/message_handlers/move_group.hpp @@ -11,10 +11,18 @@ using namespace can::messages; template class MoveGroupHandler { public: +#ifdef PIPETTE_TYPE_DEFINE using MessageType = std::variant; +#else + using MessageType = + std::variant; +#endif + MoveGroupHandler(Client &task_client) : task_client{task_client} {} MoveGroupHandler(const MoveGroupHandler &) = delete; MoveGroupHandler(const MoveGroupHandler &&) = delete; diff --git a/include/motor-control/core/motor_messages.hpp b/include/motor-control/core/motor_messages.hpp index 48545cfce..27c47da2d 100644 --- a/include/motor-control/core/motor_messages.hpp +++ b/include/motor-control/core/motor_messages.hpp @@ -84,7 +84,6 @@ struct SensorSyncMove // NOLINT(cppcoreguidelines-pro-type-member-init) can::ids::SensorId sensor_id; auto build_ack(int32_t pulses, uint8_t flags, AckMessageId _id) -> Ack { - // not sure if we need to include sensor id in the ack return Ack{ .message_index = message_index, .group_id = group_id, diff --git a/include/motor-control/core/stepper_motor/motion_controller.hpp b/include/motor-control/core/stepper_motor/motion_controller.hpp index 3cdd3ffdc..dede8841b 100644 --- a/include/motor-control/core/stepper_motor/motion_controller.hpp +++ b/include/motor-control/core/stepper_motor/motion_controller.hpp @@ -65,14 +65,16 @@ class MotionController { steps_per_tick_sq acceleration_steps = fixed_point_multiply(steps_per_um, can_msg.acceleration); SensorSyncMove msg{ - .message_index = can_msg.message_index, - .duration = can_msg.duration, - .velocity = velocity_steps, - .acceleration = acceleration_steps, - .group_id = can_msg.group_id, - .seq_id = can_msg.seq_id, - .stop_condition = can_msg.request_stop_condition, - .usage_key = hardware.get_usage_eeprom_config().get_distance_key()}; + can_msg.message_index, + can_msg.duration, + velocity_steps, + acceleration_steps, + can_msg.group_id, + can_msg.seq_id, + can_msg.request_stop_condition, + 0, + hardware.get_usage_eeprom_config().get_distance_key(), + can_msg.sensor_id}; if (!enabled) { enable_motor(); } 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 cc8307ac1..4dc7763b9 100644 --- a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp +++ b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp @@ -594,7 +594,6 @@ class MotorInterruptHandler { return has_active_move() && buffered_move.velocity != 0; } -// private: protected: void update_hardware_step_tracker() { hardware.set_step_tracker( diff --git a/include/motor-control/core/tasks/messages.hpp b/include/motor-control/core/tasks/messages.hpp index 7376699f1..1e27fb529 100644 --- a/include/motor-control/core/tasks/messages.hpp +++ b/include/motor-control/core/tasks/messages.hpp @@ -6,6 +6,7 @@ namespace motor_control_task_messages { +#ifdef PIPETTE_TYPE_DEFINE using MotionControlTaskMessage = std::variant< std::monostate, can::messages::AddLinearMoveRequest, can::messages::DisableMotorRequest, can::messages::EnableMotorRequest, @@ -14,12 +15,7 @@ using MotionControlTaskMessage = std::variant< can::messages::MotorPositionRequest, can::messages::ReadLimitSwitchRequest, can::messages::HomeRequest, can::messages::UpdateMotorPositionEstimationRequest, - can::messages::GetMotorUsageRequest>; - -using MotorDriverTaskMessage = - std::variant; + can::messages::GetMotorUsageRequest, can::messages::AddSensorMoveRequest>; using MoveGroupTaskMessage = std::variant; +#else +using MotionControlTaskMessage = std::variant< + std::monostate, can::messages::AddLinearMoveRequest, + can::messages::DisableMotorRequest, can::messages::EnableMotorRequest, + can::messages::GetMotionConstraintsRequest, + can::messages::SetMotionConstraints, can::messages::StopRequest, + can::messages::MotorPositionRequest, can::messages::ReadLimitSwitchRequest, + can::messages::HomeRequest, + can::messages::UpdateMotorPositionEstimationRequest, + can::messages::GetMotorUsageRequest>; + + using MoveGroupTaskMessage = + std::variant; +#endif + + +using MotorDriverTaskMessage = + std::variant; using MoveStatusReporterTaskMessage = std::variant< std::monostate, motor_messages::Ack, motor_messages::UpdatePositionResponse, diff --git a/include/motor-control/core/tasks/motion_controller_task.hpp b/include/motor-control/core/tasks/motion_controller_task.hpp index a157ca8e0..6a0e3025d 100644 --- a/include/motor-control/core/tasks/motion_controller_task.hpp +++ b/include/motor-control/core/tasks/motion_controller_task.hpp @@ -95,6 +95,16 @@ class MotionControllerMessageHandler { controller.move(m); } +#ifdef PIPETTE_TYPE_DEFINE + void handle(const can::messages::AddSensorMoveRequest& m) { + LOG("Received add linear move request: velocity=%d, acceleration=%d, " + "groupid=%d, seqid=%d, duration=%d, stopcondition=%d", + m.velocity, m.acceleration, m.group_id, m.seq_id, m.duration, + m.request_stop_condition); + controller.move(m); + } +#endif + void handle(const can::messages::HomeRequest& m) { LOG("Motion Controller Received home request: velocity=%d, " "groupid=%d, seqid=%d\n", @@ -140,6 +150,7 @@ class MotionControllerMessageHandler { controller.send_usage_data(m.message_index, usage_client); } + MotorControllerType& controller; CanClient& can_client; UsageClient& usage_client; diff --git a/include/motor-control/core/tasks/move_group_task.hpp b/include/motor-control/core/tasks/move_group_task.hpp index 0ff826f1f..041fbe3d5 100644 --- a/include/motor-control/core/tasks/move_group_task.hpp +++ b/include/motor-control/core/tasks/move_group_task.hpp @@ -14,12 +14,18 @@ namespace move_group_task { constexpr std::size_t max_groups = 3; constexpr std::size_t max_moves_per_group = 12; - +#ifdef PIPETTE_TYPE_DEFINE using MoveGroupType = move_group::MoveGroupManager; +#else +using MoveGroupType = + move_group::MoveGroupManager; +#endif using TaskMessage = motor_control_task_messages::MoveGroupTaskMessage; @@ -122,7 +128,11 @@ class MoveGroupMessageHandler { mc_client.send_motion_controller_queue(m); } - void visit_move(const can::messages::AddSensorMoveRequest&) {} +#ifdef PIPETTE_TYPE_DEFINE + void visit_move(const can::messages::AddSensorMoveRequest& m) { + mc_client.send_motion_controller_queue(m); + } +#endif MoveGroupType& move_groups; MotionControllerClient& mc_client; diff --git a/include/pipettes/core/dispatch_builder.hpp b/include/pipettes/core/dispatch_builder.hpp index 33d17d8e9..00e60e019 100644 --- a/include/pipettes/core/dispatch_builder.hpp +++ b/include/pipettes/core/dispatch_builder.hpp @@ -39,6 +39,7 @@ using GearMotorDispatchTarget = can::dispatch::DispatchParseTarget< can::messages::GearWriteMotorDriverRegister, can::messages::GearWriteMotorCurrentRequest>; +#ifdef PIPETTE_TYPE_DEFINE using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::message_handlers::move_group::MoveGroupHandler< linear_motor_tasks::QueueClient>, @@ -46,6 +47,15 @@ using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< can::messages::ClearAllMoveGroupsRequest, can::messages::ExecuteMoveGroupRequest, can::messages::GetMoveGroupRequest, can::messages::HomeRequest, can::messages::StopRequest, can::messages::AddSensorMoveRequest>; +#else + using MoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< + can::message_handlers::move_group::MoveGroupHandler< + linear_motor_tasks::QueueClient>, + can::messages::AddLinearMoveRequest, + can::messages::ClearAllMoveGroupsRequest, + can::messages::ExecuteMoveGroupRequest, can::messages::GetMoveGroupRequest, + can::messages::HomeRequest, can::messages::StopRequest>; +#endif using GearMoveGroupDispatchTarget = can::dispatch::DispatchParseTarget< gear_move_group_handler::GearMoveGroupHandler< diff --git a/include/pipettes/core/motor_interrupt_handler.hpp b/include/pipettes/core/motor_interrupt_handler.hpp index 989589703..74597b759 100644 --- a/include/pipettes/core/motor_interrupt_handler.hpp +++ b/include/pipettes/core/motor_interrupt_handler.hpp @@ -5,10 +5,6 @@ namespace pipettes { using namespace motor_messages; -//using InterruptHandler = motor_handler::MotorInterruptHandler< -// freertos_message_queue::FreeRTOSMessageQueue, StatusClient, -// MotorMoveMessage, MotorHardware>; -// might need to change MotorMoveMessage to include sensormove template