UMRT Arm Firmware Library
|
Describes the commands which are available to send MKS SERVO57D/42D/35D/28D stepper motor driver modules. More...
#include <cstdint>
Go to the source code of this file.
Describes the commands which are available to send MKS SERVO57D/42D/35D/28D stepper motor driver modules.
enum MksCommands : uint8_t |
CAN commands for the MKS SERVO57D/42D/35D/28D stepper motor driver modules.
Each message must have its checksum appended. Uses big-endian encoding.
The checksum function is a simple 8-bit sum-of-bytes. A sample Python implementation is:
When used, "nominal conditions" refers to a stepper driver configured to be in 16-microstepping mode along with a 200 step/rev motor. These are the conditions the manual authors assumed, and thus many hard-coded computations are based on it. Particularly, the manual documents the motor speed units to be "RPM". This is only true for these conditions; a speed of "1 RPM" actually corresponds to 3200 steps per minute. If a 200 step/rev motor is being used in full-step mode, a speed command of "1 RPM" will instead move the motor at \(v = 1 * \left(\frac{3200\ steps}{min}\right) \left(\frac{1\ full-step}{step}\right) \left(\frac{1\ rev}{200\ full-steps}\right) = 16\ RPM\)
Enumerator | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ENCODER_SPLIT | Encoder value, split into number of turns and angle. The angle is a 14-bit unsigned integer (0-0x3FFF), and follows the formula: For example, a quarter turn CW would be (0, 0x1000), and a quarter turn CCW would be (-1, 0x3000). Note that the manual refers to number of turns as the "carry".
| |||||||||||||||||||||||||||||||||||
ENCODER_ADDITIVE | Encoder value, with the number of turns and angle combined into a single integer. The angle is a 48-bit signed integer (0-0x3FFF for one CW rotation), and follows the formula: For example, a quarter turn CW would be 0x1000, and a quarter turn CCW would be -(0x1000)=0xFFFF_FFFF_F000
| |||||||||||||||||||||||||||||||||||
MOTOR_SPEED | Motor speed, as determined by the encoder. Represented as a signed integer, where positive denotes CCW and negative denotes CW.
| |||||||||||||||||||||||||||||||||||
CURRENT_POS | The current position of the motor, in steps As an alternative to the encoder value, this command allows position tracking by step counting.
| |||||||||||||||||||||||||||||||||||
IO_STATUS | Status of the IO ports. Returns a byte, with each bit representing:
Note that if LIMIT_PORT_REMAP is enabled, IN_1 maps to En, and IN_2 maps to Dir
| |||||||||||||||||||||||||||||||||||
ENCODER_RAW | Encoder value, in the "raw" (?) format. The manual entry for this is identical to ENCODER_ADDITIVE.
| |||||||||||||||||||||||||||||||||||
TARGET_ANGLE_ERROR | Difference between the target angle (mod 1 turn) and the current angle. The error is a signed integer, where the range 0-0xC800 maps to 0-360°.
| |||||||||||||||||||||||||||||||||||
ENABLE_STATUS | Status of the En pin.
| |||||||||||||||||||||||||||||||||||
GO_HOME_STATUS | Whether the motor successfully went back to the zero point once powered on. There are three legal return values:
| |||||||||||||||||||||||||||||||||||
RELEASE_SHAFT_LOCK | Commands the driver to release a motor from the locked-rotor protection state.
| |||||||||||||||||||||||||||||||||||
SHAFT_LOCK_STATUS | Whether the motor is currently in the locked-rotor protection state. Note that the manual says "protected" vs. "no protected", should be confirmed before use.
| |||||||||||||||||||||||||||||||||||
CALIBRATION | Calibration status. The motor must be unloaded for calibration. There are three legal return values:
Accessible through the driver screen as "Cal".
| |||||||||||||||||||||||||||||||||||
SET_WORK_MODE | Sets the work mode of the motor driver. There are 6 possible options: (Default: CR_vFOC)
Accessible through the driver screen as "Mode"
| |||||||||||||||||||||||||||||||||||
SET_WORKING_CURRENT | Sets the maximum current the driver is allowed to push through the motor (working current). Should not exceed 3000mA for SERVO42D/35D/28D models, and should not exceed 5200mA for the SERVO57D model. Accessible through the driver screen as "Ma".
| |||||||||||||||||||||||||||||||||||
SET_HOLDING_CURRENT | Sets the percentage of the working current to use for as the maximum holding current. I am not entirely clear on what this means for a stepper motor, but that is what the manual says. This is set as a value from 0-8:
Note that this is not applicable to vFOC modes. Accessible through the driver screen as "HoldMa".
| |||||||||||||||||||||||||||||||||||
SET_MICROSTEP | Sets the microstepping division. Can be set to any division, not just powers of 2. Accessible through the driver screen as "MStep", though only 1, 2, 4, 8, 16, 32, 64, 128, and 256 are available.
| |||||||||||||||||||||||||||||||||||
SET_EN_MODE | Sets the En pin mode. There are three possible modes:
Accessible through the driver screen as "En".
| |||||||||||||||||||||||||||||||||||
SET_DIR_MODE | Sets the Dir pin mode. There are three possible modes: (These should be confirmed before being used, manual is somewhat ambiguous)
Only applicable when using the pulse interface. Accessible through the driver screen as "Dir".
| |||||||||||||||||||||||||||||||||||
ENABLE_DISPLAY_SLEEP | Enables automatic shutoff of the driver screen after ~15 seconds. The screen can be woken up by pressing any button. Accessible through the driver screen as "AutoSDD".
| |||||||||||||||||||||||||||||||||||
ENABLE_ROTOR_LOCK | Lock/unlock the rotor. Note that the motor can be unlocked by sending RELEASE_SHAFT_LOCK, pressing "Enter" on the driver screen, or pulsing the En pin if in pulse interface mode. Accessible through the driver screen as "Protect".
| |||||||||||||||||||||||||||||||||||
ENABLE_MICROSTEP_INTERPOLATION | Enable microstep "interpolation", which internally uses 256-microstepping for smoother movement. Works by internally setting the motor microstep subdivisions to 256 instead of the division x set by SET_MICROSTEP, and converting each x-microstep into the equivalent number of 256-microsteps each time the motor is stepped. For example, if this is used with quarter-stepping, the motor will actually move 64 256-microsteps each time. This allegedly reduces the vibration and noise when the motor moves at low speed. Accessible through the driver screen as "Mplyer".
| |||||||||||||||||||||||||||||||||||
CAN_BAUD_RATE | Sets the CAN bus baud rate. There are four possible options:
Accessible through the driver screen as "CanRate".
| |||||||||||||||||||||||||||||||||||
CAN_ID | Sets the CAN bus ID for this driver. Eligible IDs are 0x001-0x7FF. Must not be set to 0 as that is the broadcast address. Accessible through the driver screen as "CanID".
| |||||||||||||||||||||||||||||||||||
RESPONSE_MODE | Change response mode. There are three possible response modes:
Some commands are capable of sending multiple responses. For example, SEND_STEP could send one response with 0x01 indicating the motor has begun moving, followed by another response with 0x02 indicating the motor has reached the target. Alternatively, it may only respond with 0x00 indicating that the command has been rejected. In this case, in active mode all of these responses could be sent, whereas in passive mode only the first response would be.
| |||||||||||||||||||||||||||||||||||
DISABLE_BUTTONS | Disables the buttons on the driver.
| |||||||||||||||||||||||||||||||||||
SET_GROUP_ID | Sets the group ID of this driver. Commands sent to the group ID will apply to every driver with that group ID. The group ID acts as an alternative CAN bus ID. However, no drivers will send responses to messages sent to their group ID. For example, could be used to link the left-side front and rear motors of differential drive car. Must not be set to 0 as that is the broadcast address. Eligible IDs are 0x001-0x7FF.
| |||||||||||||||||||||||||||||||||||
WRITE_IO | Write values to the IO ports. Input is a byte, with each bit representing:
There are 3 possible modes for OUT_2 and OUT_1:
| |||||||||||||||||||||||||||||||||||
HOME_SETTINGS | Sets parameters for the return-to-home sequence. Allows the following parameters to be changed:
The manual states that it is necessary to issue a homing command after the settings have been changed.
| |||||||||||||||||||||||||||||||||||
GO_HOME | Start the homing sequence. Note that if the limit switch is already triggered, the motor will move in the opposite direction of home until the limit switch releases, at which point to will restart the homing sequence. There are three legal return values:
| |||||||||||||||||||||||||||||||||||
SET_ZERO | Set the zero position. Sets the motor's current position to 0.
| |||||||||||||||||||||||||||||||||||
SET_BLIND_LIMIT | Blindly finds the axis limit by turning until the motor hits an obstacle. This is an alternative to a physical limit switch for the homing procedure. The maximum distance to rotate is specified in increments of 1/2^14 of a rotation, the same as described in ENCODER_SPLIT. Therefore, to move at most 360°, a distance of 0x4000 should be used An alternate maximum current is set here to use when homing so the motor stalls before inflicting damage. It would be a good idea to set the current limit at the minimum current required to move the motor, since it is going to hit something with whatever torque that current corresponds to.
| |||||||||||||||||||||||||||||||||||
SET_LIMIT_PORT_REMAP | Remap ports for an additional limit or to facilitate wiring. When used with the SERVO42D/35D/28D models, this converts the DIR port becomes the IN_2 port which is used as another end stop. Without this, these models can only have one end stop. Note that since there is no longer a DIR port, the pulse interface cannot be used. For the SERVO52D model, this switches the EN port with the IN_1 port, and the DIR port with the IN_2 port. This may be helpful to facilitate wiring.
| |||||||||||||||||||||||||||||||||||
POWER_ON_HOMING_MODE | Set how the motor homes upon startup. Allows the following parameters to be changed:
Home mode is accessible through the driver screen as "0_Mode", Enable as "Set 0", Speed as "0_Speed", and Direction as "0_Dir". Note that the motor will not move beyond 359°.
| |||||||||||||||||||||||||||||||||||
FACTORY_RESET | Restores the default settings. After restoring factory settings, the driver will reboot and the motor will need to be calibrated. The "Next" button on the driver screen may need to be pressed after sending this command. TODO: Confirm.
| |||||||||||||||||||||||||||||||||||
REBOOT_DRIVER | Reboots the motor driver.
| |||||||||||||||||||||||||||||||||||
SET_MISC_SETTINGS | Modifies motor protection settings and allows delayed homing when using the pulse interface. This command allows two distinct functions to be enabled. The first affects the driver's zeroing behaviour. POWER_ON_HOMING_MODE can be used to automatically home the motor when power is restored, however in some applications this may not be safe. When using the pulse interface, a GO_HOME command cannot be sent to trigger the homing sequence. Through the The second affects the driver's motor protection system. If the If the position protection system is triggered, the driver screen displays "Wrong2". Note that "Wrong" is displayed on the screen when the stall protection system triggered. The flags are encoded into a byte according to:
| |||||||||||||||||||||||||||||||||||
READ_PARAM | Reads the current setting for a parameter. Parameters are returned in the same format as they are set. If a parameter does not support reading, the payload 0xFF_FF is returned. From my interpretation of the manual, I suspect the only parameters which support reading are:
For example, when used with SET_WORK_MODE the response would be a uint8 that could be compared to the table described in SET_WORK_MODE to determine which mode the driver has been put in.
| |||||||||||||||||||||||||||||||||||
QUERY_STATUS | Get current motor status Retrieves a status code describing the current state of the motor:
| |||||||||||||||||||||||||||||||||||
ENABLE_MOTOR | Enable the motor Not entirely sure when this is needed.
| |||||||||||||||||||||||||||||||||||
EMERGENCY_STOP | Immediately stop the motor. Does not decelerate, attempts to immediately stops. According to the manual, if a motor is moving at greater than 1000 RPM it is not advisable to immediately stop it.
| |||||||||||||||||||||||||||||||||||
SET_SPEED | Run the motor at a target speed. Sets the motor to spin at a specific speed with a fixed acceleration. The speed properties are encoded into a 16-bit integer according to:
The speed value is a 12-bit unsigned integer, split so that the low nibble of the word contains the high nibble of the speed, and the high byte of the word contains the low byte of the speed. It can be reconstructed according to: For why the speed is encoded this way, note that this can be alternatively expressed as:
For example, 0x81_40 indicates moving CW at v = 0x40 | (0x01 << 8) = 320 * (160/3 steps/s) = 51 200 steps/s [320 nominal RPM]. Note that the motor can be stopped by sending a speed of 0. If an acceleration of 0 is used, the motor will stop, or more generally reach the target speed, immediately. Dir: 1 indicates CW, and 0 CCW
| |||||||||||||||||||||||||||||||||||
SET_POWER_ON_SPEED | Set the driver to engage at the current speed upon startup. Saves the current speed and direction into memory. When the driver starts up, it will begin spinning at this speed.
| |||||||||||||||||||||||||||||||||||
SEND_STEP | Run the motor a specific number of steps. The manual refers to this as "Position mode1: relative motion by pulses". Commands the motor to move a certain number of steps at a target speed with a fixed acceleration. See SEND_ANGLE for a variation of this command which moves by an angle instead of a number of steps. The speed properties are encoded into a 16-bit integer according to:
The speed value is a 12-bit unsigned integer, split so that the low nibble of the word contains the high nibble of the speed, and the high byte of the word contains the low byte of the speed. It can be reconstructed according to: Dir: 1 indicates CW, and 0 CCW The motor can be stopped by sending another command with zero packed_properties and steps. Note that this is different then simply sending another SEND_STEP command, as usually the commands are queued so that the first command would finish and then the second would be executed. The stop variation behaves differently, in that it is not queued and the motor immediately starts slowing. If an acceleration of 0 is used, the motor will stop, or more generally reach the target speed, immediately. Note as well that this may cause the motor to overshoot the original target if the acceleration is too slow. There are four legal return values:
| |||||||||||||||||||||||||||||||||||
SEEK_POS_BY_STEPS | Run the motor to a specific position in steps. The manual refers to this as "Position mode2: absolute motion by pulses". Commands the motor to a particular position at a target speed with a fixed acceleration. As with ENCODER_ADDITIVE, a positive position indicates CW of zero, and negative CCW of zero. See SEEK_POS_BY_ANGLE for a variation of this command which takes the position as an angle instead of a number of steps. The motor can be stopped by sending another command with zero speed and steps. Note that this is different from simply sending another SEEK_POS_BY_STEPS command, as usually the commands are queued so that the first command would finish and then the second would be executed. The stop variation behaves differently, in that it is not queued and the motor immediately starts slowing. If an acceleration of 0 is used, the motor will stop, or more generally reach the target speed, immediately. Note as well that this may cause the motor to overshoot the original target if the acceleration is too slow. There are four legal return values:
| |||||||||||||||||||||||||||||||||||
SEND_ANGLE | Run the motor CW or CCW by a specific angle. Commands the motor to a particular position at a target speed with a fixed acceleration. The manual refers to this as "Position mode3: relative motion by axis [angle]". Angles are represented in the same fashion as ENCODER_ADDITIVE, where a positive position indicates CW of zero, and negative CCW of zero. For example, if the motor is currently at 0x4000 (1 turn CW of zero), and 0xFFFF_FFFF_F000 (90° CCW) is sent, the motor will move to 0x3000 (270° CW of zero). See SEND_STEP for a variation of this command which moves by a number of steps instead of an angle. The motor can be stopped by sending another command with zero speed and angle. Note that this is different from simply sending another SEND_ANGLE command, as usually the commands are queued so that the first command would finish and then the second would be executed. The stop variation behaves differently, in that it is not queued and the motor immediately starts slowing. If an acceleration of 0 is used, the motor will stop, or more generally reach the target speed, immediately. Note as well that this may cause the motor to overshoot the original target if the acceleration is too slow. There are four legal return values:
| |||||||||||||||||||||||||||||||||||
SEEK_POS_BY_ANGLE | Run the motor to a specific angular position. The manual refers to this as "Position mode4: absolute motion by axis [angle]". Commands the motor to a particular position at a target speed with a fixed acceleration. Angles are represented in the same fashion as ENCODER_ADDITIVE, where a positive position indicates CW of zero, and negative CCW of zero. For example, an angular position of 0x4000 corresponds to 360° CW, and an angular position of 0xFFFF_FFFF_B000 corresponds to 450° CCW. See SEEK_POS_BY_STEPS for a variation of this command which takes the position as number of steps instead of an angle. Note this command behaves uniquely in that if another SEEK_POS_BY_ANGLE command is sent while this is executing, the first command will be dropped and the motor will seek the second position instead. For other commands, the requests are queued so that the first command finishes before the second is executed. The motor can be stopped by sending another command with zero speed and angle. If an acceleration of 0 is used, the motor will stop, or more generally reach the target speed, immediately. Note that this may cause the motor to overshoot the original target if the acceleration is too slow. There are four legal return values:
|