Unit conversion
To facilitate developers in programming applications using familiar units during development, KINGSTAR provides the unit conversion function that can be used to convert the units used by the drives into user units. The default units used in the KINGSTAR Subsystem are the standard CAN units, which include the following.
- Position/Distance: pulse (encoder count)
- Velocity: pulse/second
- Acceleration/Deceleration: pulse/second2
- Jerk: pulse/second3
- Jolt: pulse/second4
With the KINGSTAR unit conversion function, you can convert the units described above to your preferred units during programming, such as to convert the position unit of an axis from pulse (encoder count) to angle; or convert the acceleration and jerk units to seconds. For example, let's say your axis is configured with 1000 pulses per revolution. If you use the unit conversion function to convert the unit from pulses to angles, considering that a full revolution is 360 degrees, then when a command is given for 360 degrees, the axis would actually move 1000 pulses. Similarly, when a command is given for 180 degrees, the axis would actually move 500 pulses.
Since the KINGSTAR unit conversion function is designed to facilitate developers in programming using their preferred units, it does not alter the drives original configuration. In the example mentioned above, when the position unit is converted from pulses to angles, the position unit used for the drive remains fixed in pulses.
The following diagram illustrates the partial architecture of the drive system in Cyclic Synchronous Position (CSP) mode, where the axis control mode is direct position mode. The diagram is divided into three sections from left to right: the controller, the drive, and the motor. After the controller issues commands to the drive, the drive is responsible for motion planning and motor control. The KINGSTAR unit conversion function occurs solely within the controller section and only affects the commands issued by the controller itself. It does not impact the internal settings of the drive, such as “Position factor”, which can be configured using SDO (Service Data Object).
To convert the unit of an axis, you can either use the APIs or KINGSTAR Configuration Tool.
Converting the unit to the user unit by using the APIs:
- Use the SetAxisCountsPerUnit or SetAxisSecondEncoderCountsPerUnit to replace the count unit of the axis with a user unit.
- SetAxisCountsPerUnit: Sets the conversion ratio of the user-defined position unit to the count (pulse) unit used by an axis.
- SetAxisSecondEncoderCountsPerUnit: Sets the conversion ratio of the user-defined position unit to the count (pulse) unit used by an axis for the secondary encoder.
- Use EnableAxisUnitConversion to enable the conversion ratio set up by using the SetAxisCountsPerUnit or SetAxisSecondEncoderCountsPerUnit.
- Update the PID and motion parameters to match the user-defined unit. This can only be done when the axis is disabled.
- Use SetAxisVelocityPid to update the PID if the axis is in the velocity mode.
- Use SetAxisTorquePid to update the PID if the axis is in the torque mode.
- Use SetAxisMotionProfile to configure the motion setting of an axis.
Example
Below is an example of setting up the position unit from pulses to degrees and then enabling the unit conversion function.
SetAxisCountsPerUnit(TargetAxis, 1000, 360, FALSE); EnableAxisUnitConversion(TargetAxis, TRUE);
NOTE: You can also refer to the KINGSTAR samples for unit conversion, please refer to “Motion parameters, unit conversion, and simulated I/O modules" in the Motion Sample; or “Convert the axis unit”, “Enable the unit conversion” and “Update the PID and motion parameters” in the User Interpolation Sample.
Converting the unit to the user unit by using the KINGSTAR Configuration Tool:
- Start the KINGSTAR Configuration Tool, select an Axis device by clicking on it in the Project Configuration pane.
- In the right-side pane, click Configure and check the “Unit conversion” checkbox to enable unit conversion.
- Input the value in the Numerator and Denominator to convert the drive unit to the user unit.
- Numerator: For example, if the device is an encoder, typically the numerator is the resolution of the encoder.
- Denominator: If you're using degree, the value will be 360 because there are 360 degrees in one revolution.
- Update the PID and motion (Configure > Motion) parameters to match the user-defined unit. This can only be done when the axis is disabled.