From ac09f4e2d2762adda60fa3a9c0b9b9704fe238dd Mon Sep 17 00:00:00 2001 From: caila-marashaj Date: Mon, 29 Jan 2024 10:12:18 -0500 Subject: [PATCH] send report message on start sensor move --- include/motor-control/core/motor_messages.hpp | 20 ++++ .../core/stepper_motor/motion_controller.hpp | 20 ++++ .../stepper_motor/motor_interrupt_handler.hpp | 43 +++---- .../pipettes/core/motor_interrupt_handler.hpp | 108 +++++++++++++----- 4 files changed, 143 insertions(+), 48 deletions(-) diff --git a/include/motor-control/core/motor_messages.hpp b/include/motor-control/core/motor_messages.hpp index bfe573397..48545cfce 100644 --- a/include/motor-control/core/motor_messages.hpp +++ b/include/motor-control/core/motor_messages.hpp @@ -79,6 +79,26 @@ struct Move { // NOLINT(cppcoreguidelines-pro-type-member-init) } }; +struct SensorSyncMove // NOLINT(cppcoreguidelines-pro-type-member-init) + : public Move { + 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, + .seq_id = seq_id, + .current_position_steps = 0, + .encoder_position = pulses, + .position_flags = flags, + .ack_id = _id, + .start_encoder_position = start_encoder_position, + .usage_key = usage_key, + }; + } +}; + struct GearMotorMove // NOLINT(cppcoreguidelines-pro-type-member-init) : public Move { uint32_t start_step_position; diff --git a/include/motor-control/core/stepper_motor/motion_controller.hpp b/include/motor-control/core/stepper_motor/motion_controller.hpp index 3a4b71c57..3cdd3ffdc 100644 --- a/include/motor-control/core/stepper_motor/motion_controller.hpp +++ b/include/motor-control/core/stepper_motor/motion_controller.hpp @@ -59,6 +59,26 @@ class MotionController { return linear_motion_sys_config; } + void move(const can::messages::AddSensorMoveRequest& can_msg) { + steps_per_tick velocity_steps = + fixed_point_multiply(steps_per_mm, can_msg.velocity); + 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()}; + if (!enabled) { + enable_motor(); + } + queue.try_write(msg); + } + void move(const can::messages::AddLinearMoveRequest& can_msg) { steps_per_tick velocity_steps = fixed_point_multiply(steps_per_mm, can_msg.velocity); 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 ee57dbd3d..cc8307ac1 100644 --- a/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp +++ b/include/motor-control/core/stepper_motor/motor_interrupt_handler.hpp @@ -594,26 +594,27 @@ class MotorInterruptHandler { return has_active_move() && buffered_move.velocity != 0; } - private: - void update_hardware_step_tracker() { - hardware.set_step_tracker( - static_cast(position_tracker >> 31)); - } - - uint64_t tick_count = 0x0; - static constexpr const q31_31 tick_flag = 0x80000000; - static constexpr const uint64_t overflow_flag = 0x8000000000000000; - // Tracks position with sub-microstep accuracy - q31_31 position_tracker{0}; - MoveQueue& move_queue; - StatusClient& status_queue_client; - MotorHardware& hardware; - stall_check::StallCheck& stall_checker; - UpdatePositionQueue& update_position_queue; - MotorMoveMessage buffered_move = MotorMoveMessage{}; - bool clear_queue_until_empty = false; - bool stall_handled = false; - bool in_estop = false; - std::atomic_bool _has_active_move = false; +// private: +protected: +void update_hardware_step_tracker() { + hardware.set_step_tracker( + static_cast(position_tracker >> 31)); +} + +uint64_t tick_count = 0x0; +static constexpr const q31_31 tick_flag = 0x80000000; +static constexpr const uint64_t overflow_flag = 0x8000000000000000; +// Tracks position with sub-microstep accuracy +q31_31 position_tracker{0}; +MoveQueue& move_queue; +StatusClient& status_queue_client; +MotorHardware& hardware; +stall_check::StallCheck& stall_checker; +UpdatePositionQueue& update_position_queue; +MotorMoveMessage buffered_move = MotorMoveMessage{}; +bool clear_queue_until_empty = false; +bool stall_handled = false; +bool in_estop = false; +std::atomic_bool _has_active_move = false; }; } // namespace motor_handler diff --git a/include/pipettes/core/motor_interrupt_handler.hpp b/include/pipettes/core/motor_interrupt_handler.hpp index 6dec18f00..989589703 100644 --- a/include/pipettes/core/motor_interrupt_handler.hpp +++ b/include/pipettes/core/motor_interrupt_handler.hpp @@ -5,19 +5,20 @@ 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