5 #ifndef UMRT_ARM_FIRMWARE_LIB_MKS_STEPPER_CONTROLLER_HPP
6 #define UMRT_ARM_FIRMWARE_LIB_MKS_STEPPER_CONTROLLER_HPP
8 #include <boost/signals2.hpp>
11 #include <unordered_set>
17 namespace drivers::socketcan {
18 class SocketCanReceiver;
19 class SocketCanSender;
49 const uint8_t norm_factor = 1
67 bool setSpeed(
const uint16_t motor,
const int16_t speed,
const uint8_t acceleration = 0);
80 bool sendStep(
const uint16_t motor,
const uint32_t num_steps,
const int16_t speed,
const uint8_t acceleration = 0);
92 bool seekPosition(
const uint16_t motor,
const int32_t position,
const int16_t speed,
const uint8_t acceleration = 0);
106 [[nodiscard]]
bool isSetup()
const;
127 boost::signals2::signal<void(uint16_t,
bool)>
ESetSpeed;
185 const uint8_t norm_factor;
191 bool setup_completed;
Abstracts CAN bus communication to MKS SERVO57D/42D/35D/28D stepper motor driver modules.
Definition: mks_stepper_controller.hpp:37
bool seekPosition(const uint16_t motor, const int32_t position, const int16_t speed, const uint8_t acceleration=0)
Sends a MksCommands::SEEK_POS_BY_STEPS command to move a motor to specific step position.
Definition: mks_stepper_controller.cpp:116
void update(const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero())
Polls for CAN messages.
Definition: mks_stepper_controller.cpp:169
bool sendStep(const uint16_t motor, const uint32_t num_steps, const int16_t speed, const uint8_t acceleration=0)
Sends a MksCommands::SEND_STEP command to move a motor a fixed number of steps.
Definition: mks_stepper_controller.cpp:85
boost::signals2::signal< void(uint16_t, int32_t)> EGetPosition
Boost signal triggered when getPosition responses are received.
Definition: mks_stepper_controller.hpp:154
boost::signals2::signal< void(uint16_t, bool)> ESetSpeed
Boost signal triggered when setSpeed responses are received.
Definition: mks_stepper_controller.hpp:127
boost::signals2::signal< void(uint16_t, MksMoveResponse)> ESeekPosition
Boost signal triggered when seekPosition responses are received.
Definition: mks_stepper_controller.hpp:145
~MksStepperController() noexcept
Destroys an MksStepperController.
Definition: mks_stepper_controller.cpp:37
MksStepperController(const std::string &can_interface, std::shared_ptr< const std::unordered_set< uint16_t >> motor_ids, const uint8_t norm_factor=1)
Initializes an MksStepperController.
Definition: mks_stepper_controller.cpp:20
bool setSpeed(const uint16_t motor, const int16_t speed, const uint8_t acceleration=0)
Sends a MksCommands::SET_SPEED command to set the speed of a motor.
Definition: mks_stepper_controller.cpp:39
boost::signals2::signal< void(uint16_t, MksMoveResponse)> ESendStep
Boost signal triggered when sendStep responses are received.
Definition: mks_stepper_controller.hpp:136
bool isSetup() const
Returns whether the CAN bus connection has been fully established.
Definition: mks_stepper_controller.cpp:167
void handleCanMessage(const std::vector< uint8_t > &message, drivers::socketcan::CanId &info)
Handles received CAN messages and sends out signals as appropriate.
Definition: mks_stepper_controller.cpp:221
bool getPosition(const uint16_t motor)
Sends a MksCommands::CURRENT_POS command to query the current position of a motor in steps.
Definition: mks_stepper_controller.cpp:151
Enums for interacting with commands described in MKS_COMMANDS.hpp.
MksMoveResponse
Status code for the response to move commands.
Definition: mks_enums.hpp:21