Tutorial 4-5: Absolute encoders
When using absolute encoders, after the homing operation is completed once, it is not necessary to search for the home position again.
Using Absolute Encoder Parameters
The easiest way of configuring an absolute encoder is to use the absolute encoder paramters of WMX3. These parameters assume that the range of positions that the axis occupies stays within the range between -(2^31) and 2^31-1 pulses (before applying the gear ratio). If the axis would move beyond -(2^31) pulses or 2^31-1 pulses, the absolute encoder parameters will be unable to correctly apply the home position. By setting the position where the encoder value is 0x00000000 to around the center of the range of positions that the axis can occupy, the position range that the absolute encoder can support is maximized.
There are two absolute encoder parameters: Absolute Encoder Mode and Absolute Encoder Home Offset. The Absolute Encoder Mode parameter determines whether absolute encoder mode is enabled or disabled for an axis. This parameter should be set to TRUE.
The Absolute Encoder Home Offset parameter stores the home offset of for the absolute encoder. While the Absolute Encoder Mode parameter is set to TRUE, this parameter determines the home position of the axis. In addition, while the Absolute Encoder Mode parameter is set to TRUE, this parameter is updated with the current home offset whenever a homing operation is completed. By storing this parameter when the engine is closed and reapplying it when the engine is started again, the home position can be preserved while the machine is powered off.
Important
When using the Gear Ratio Numerator, Gear Ratio Denominator, Single Turn Mode, Single Turn Encoder Count, or Axis Polarity parameter with absolute encoder mode, the parameters must be set before first starting communication. Otherwise, the correct home position will not be stored or restored.
To set the absolute encoder home position, follow these steps:
Set the Absolute Encoder Mode parameter to TRUE. This can be done using the SetAbsoluteEncoderMode function, or any other function that also sets AxisParam parameters, such as SetAxisParam or Import (with an AxisParam parameter).
Execute homing using the StartHome function. As with regular homing, HomeParam parameters can be set to modify the homing routine. When the homing routine is completed, the Absolute Encoder Home Offset parameter applied to the engine will automatically be updated.
To store the absolute encoder home position during the closing routine of the user application, follow these steps:
Option 1
Get the currently applied AxisParam parameters using the GetAxisParam function. The Absolute Encoder Mode and Absolute Encoder Home Offset parameters settings are included in this class. If homing was executed, the Absolute Encoder Home Offset parameter will contain the home offset that was obtained by homing.
Export the obtained parameters to file using an Export function with an AxisParam parameter.
Option 2
Call the GetAndExportAll function to get all parameters, including AxisParam parameters, and export them to file.
To load the absolute encoder home position during the initialization routine of the user application, follow these steps:
Option 1
Import the parameters saved to file (which includes the Absolute Encoder Mode and Absolute Encoder Home Offset parameters) using an Import function with an AxisParam parameter.
Apply the imported parameters to the engine using the SetAxisParam function. The Absolute Encoder Mode and Absolute Encoder Home Offset parameters can also be individually set using the SetAbsoluteEncoderMode and SetAbsoluteEncoderHomeOffset functions (the order in which these functions are called does not matter).
Option 2
Call the ImportAndSetAll function to import all parameters from file, including AxisParam parameters, and apply them to the engine.
Absolute Encoders for Single Turn Axes
Absolute encoder parameters are also compatible with Single Turn Mode axes. Compared to regular axes, single turn axes have the following differences:
There is no limitation that the axis position must stay within the range between -(2^31) and 2^31-1 pulses. The axis may be moved in either direction for any distance, and the correct position will be retained.
If the axis moves by more than 0.25 * 2^32 pulses (one quarter of 32-bit) between saving the Absolute Encoder Home Offset parameter and loading it (e.g. if the axis moves by more than this amount while the WMX3 engine is closed), and the Single Turn Encoder Count does not evenly divide into 2^32, then the saved position may become incorrect when the Absolute Encoder Home Offset parameter is loaded.
Changing the Single Turn Mode or Single Turn Encoder Count parameter may cause the position to become incorrect. After changing these parameters, the axis must be homed again.
The Absolute Encoder Home Offset can change while the axis moves (in addition to changing when the axis is homed). This parameter must be re-read from the engine using functions such as GetAndExportAll or GetAbsoluteEncoderHomeOffset in the closing routine, when the axis no longer will move. If the axis moves by more than 0.25 * 2^32 pulses after re-reading the parameter from the engine (and the Single Turn Encoder Count does not evenly divide into 2^32), then the position may become incorrect.
Manually Handling the Absolute Encoder
The absolute encoder contains a position between -(2^31) and 2^31-1 pulses. If the axis could potentially move beyond this range and wrap around, it will also be necessary to read the multiple turn data (the number of times the axis wrapped around this range) from the servo. If possible, the absolute encoder position should be adjusted so that the axis position will always stay in this range, in which case the multiple turn data could be ignored.
To convert from absolute encoder coordinates to axis coordinates, an offset and a factor must be obtained.
The factor is equal to the Gear Ratio Numerator divided by the Gear Ratio Denominator, and is required to convert from the pulse units of the absolute encoder coordinates to the user units of the axis coordinates.
To obtain the offset, execute an actual homing operation using StartHome or another method. The absolute encoder position at the home position (where the axis position is 0) is the offset.
After obtaining the offset and the factor, the following equation can convert between the absolute encoder coordinates to the axis coordinates.
[Axis Coordinate Position] = ([Absolute Encoder Position] - [Offset]) / [Factor]
If the multiple turn data must also be considered, add 2^32 times the multiple turn data for each of [Absolute Encoder Position] and [Offset].
The above coordinate change should be executed after starting the engine, in place of the homing routine. Call the SetCommandPos function to change the coordinates. The Home Done signal should also be manually set with the SetHomeDone function.
The following code sets the axis coordinates for an absolute encoder. The absolute encoder position at the home position is set to 10000.
CoreMotionStatus st;
double offset, factor, gearRatioNumerator, gearRatioDenominator;
//Get the gear ratio numerator and denominator
err = wmxlib_cm.config->GetGearRatio(0, &gearRatioNumerator, &gearRatioDenominator);
if (err != ErrorCode::None) {
wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
printf("Failed to get gear ratio. Error=%d (%s)\n", err, errString);
goto exit;
}
//The factor is the gear ratio
factor = gearRatioNumerator / gearRatioDenominator;
//The offset is the absolute encoder position at the home position
offset = 10000;
//Get the current absolute encoder position
err = wmxlib_cm.GetStatus(&st);
if (err != ErrorCode::None) {
wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
printf("Failed to get absolute encoder position. Error=%d (%s)\n", err, errString);
goto exit;
}
//Set the axis coordinates
err = wmxlib_cm.home->SetCommandPos(0, (st.axesStatus[0].encoderCommand - offset)/factor);
if (err != ErrorCode::None) {
wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
printf("Failed to set axis coordinates. Error=%d (%s)\n", err, errString);
goto exit;
}
//Set home done status
err = wmxlib_cm.home->SetHomeDone(0, 1);
if (err != ErrorCode::None) {
wmxlib_cm.ErrorToString(err, errString, sizeof(errString));
printf("Failed to set home done. Error=%d (%s)\n", err, errString);
goto exit;
}