APIs, concepts, guides, and more
Motion: Compensator

Learn how to configure and use compensators for motion correction.

Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.


In this page:


📜 Compensator: Single Axis

Learn how to configure a Compensator 📖 that modifies the motion of itself, useful for correcting mechanical non-linearities or backlash on a single axis.

/* This sample demonstrates how to configure a compensator that modifies the motion of itself.
The axis command position is used as the input to apply compensation to the same axis,
useful for correcting mechanical non-linearities or backlash.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Compensator: Single Axis");
// set sample config params
const int INDEX_ZERO = 0;
const int MIN = 10;
const int MAX = 110;
const int DELTA = 10;
const int POINTS = ((MAX - MIN) / DELTA) + 1; // 11 points
// compensator table (values are in raw counts not user units)
// at position: 10 20 30 40 50 ... ... 110
// adjust by: ↓ ↓ ↓ ↓ ↓ ... ... ↓
double[] table = new double[POINTS] { 0, 2, -3, -5, -3, 2, -3, 0, 2, -3, -5 };
// print compensator info
Console.WriteLine($"Range: {MIN} to {MAX}, Delta: {DELTA}");
Console.WriteLine($"Points: {POINTS}");
Console.WriteLine("Compensator Table:");
for (int i = 0; i < POINTS; i++)
{
int inputPos = MIN + (i * DELTA);
Console.WriteLine($"@ Pos: {inputPos}, Compensate by: {table[i]}");
}
// get rmp controller
try
{
Helpers.CheckErrors(controller);
// set compensator count before any RapidCodeObject get/create other than the controller
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(compensatorNumber: INDEX_ZERO, pointCount: table.Length);
// get & configure axis
Axis axis = controller.AxisGet(axisNumber: 0);
Helpers.CheckErrors(axis);
Helpers.PhantomAxisReset(axis);
// verify the three values are equal before configuring compensator
if (controller.CompensatorPointCountGet(INDEX_ZERO) == table.Length && POINTS == table.Length)
{
// configure compensator using AXIS_COMMAND_POSITION as input to modify same axis
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ZERO,
inputAxis: axis,
inputAxisType: RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: axis,
outputType: RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE,
table: table);
// command motion
axis.AmpEnableSet(true);
axis.MoveSCurve(position: MIN + DELTA); // move to 2nd point
axis.MotionDoneWait();
// get results
double compPos = axis.CompensationPositionGet();
// print results
Console.WriteLine($"Compensation position: {compPos} (expected: {table[1]})");
// verify compensation
if (compPos != table[1])
throw new Exception("❌ Compensator compensation position does not match expected value.");
// cleanup
Helpers.AbortMotionObject(axis);
}
}
// handle errors as needed
finally
{
controller.CompensatorCountSet(0); // restore
controller.Delete(); // dispose
}
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5863
static MotionController * Get()
Get an already running RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
RSICompensatorOutputType
Compensator output types.
Definition rsienums.h:1419
RSIAxisMasterType
Sources available to a slave Axis for electronic gearing & camming.
Definition rsienums.h:1218
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21


📜 Compensator: 1D

Learn how to configure a 1-dimensional Compensator 📖 with overlapping compensation tables to modify follower axis motion based on moving axis position.

/* This sample demonstrates how to configure and use a 1-dimensional compensator.
Two overlapping compensation tables are applied to modify the follower axis motion
based on the moving axis position.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Compensator: 1D");
// set sample config params
const int INDEX_ZERO = 0;
const int INDEX_ONE = 1;
const int MIN = 0; // smallest value in counts on input axis where table is applied
const int MAX = 100; // largest value in counts on input axis where table is applied
const int DELTA = 10; // number of encoder counts on input axis between values in table
const int POINTS = ((MAX - MIN) / DELTA) + 1; // 11 points
// compensator tables (values are in raw counts not user units)
double[] table0 = new double[POINTS] { 0, 1000, -5000, -10000, 10000, 5000, -5000, 2500, 0, 2500, 5000 };
double[] table1 = new double[POINTS] { 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, 1000 };
// print compensator info
Console.WriteLine($"Range: {MIN} to {MAX}, Delta: {DELTA}");
Console.WriteLine($"Points: {POINTS}");
// get rmp controller
try
{
Helpers.CheckErrors(controller);
// set compensator count before any RapidCodeObject get/create other than the controller
controller.CompensatorCountSet(2);
// reserve space in memory for the compensator tables
controller.CompensatorPointCountSet(INDEX_ZERO, table0.Length);
controller.CompensatorPointCountSet(INDEX_ONE, table1.Length);
// get & configure axes
Axis movingAxis = controller.AxisGet(axisNumber: 0);
Helpers.CheckErrors(movingAxis);
Helpers.PhantomAxisReset(movingAxis);
Axis followerAxis = controller.AxisGet(axisNumber: 1);
Helpers.CheckErrors(followerAxis);
Helpers.PhantomAxisReset(followerAxis);
// Verify the three following values are equal before configuring compensator
if (controller.CompensatorPointCountGet(INDEX_ZERO) == table0.Length && POINTS == table0.Length)
{
// set compensator0
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ZERO,
inputAxis: movingAxis,
inputAxisType: RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: followerAxis,
outputType: RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE,
table: table0);
// set compensator1
// configure multiple overlapping compensation tables
// note: first compensator remains in SINGLE mode, second is set to ADDITIVE
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ONE,
inputAxis: movingAxis,
inputAxisType: RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: followerAxis,
outputType: RSICompensatorOutputType.RSICompensatorOutputTypeADDITIVE,
table: table1);
// move one index into the compensation table to test
movingAxis.PositionSet(DELTA);
// get results
double compPos = followerAxis.CompensationPositionGet();
// print results
Console.WriteLine($"Compensation position: {compPos} (expected: {table0[1] + table1[1]})");
// verify compensation
if (compPos != table0[1] + table1[1])
throw new Exception("❌ Compensator compensation position does not match expected value.");
// cleanup
Helpers.AbortMotionObject(followerAxis);
Helpers.AbortMotionObject(movingAxis);
}
}
// handle errors as needed
finally
{
controller.CompensatorCountSet(0); // restore
controller.Delete(); // dispose
}


📜 Compensator: 2D

Learn how to configure a 2-dimensional Compensator 📖 to apply flatness compensation or surface mapping based on two input axes (X and Y) to an output axis (Z).

/* This sample demonstrates how to configure and use a 2-dimensional compensator.
A 2D compensation table is applied to a Z axis based on the positions of X and Y axes,
useful for flatness compensation or surface mapping applications.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Compensator: 2D");
// set sample config params
const int INDEX_ZERO = 0;
const int X_MIN = 0;
const int X_MAX = 500;
const int X_DELTA = 100;
const int X_POINTS = ((X_MAX - X_MIN) / X_DELTA) + 1; // 6 points
const int Y_MIN = 0;
const int Y_MAX = 500;
const int Y_DELTA = 100;
const int Y_POINTS = ((Y_MAX - Y_MIN) / Y_DELTA) + 1; // 6 points
const int TOTAL_POINTS = X_POINTS * Y_POINTS; // 36 points total
// compensator table values use axis COUNTS (not user units)
// table is organized as rows (X) & columns (Y)
double[] table = new double[TOTAL_POINTS] {
0, 0, 0, 0, 0, 0,
100, 200, -200, 10, 300, 0,
100, 200, -500, 400, 500, 0,
0, 0, 0, 0, 0, 0,
-300, 300, -300, -300, -300, 0,
0, 0, 0, 0, 0, 0,
};
// print compensator info
Console.WriteLine($"X Range: {X_MIN} to {X_MAX}, Delta: {X_DELTA}");
Console.WriteLine($"Y Range: {Y_MIN} to {Y_MAX}, Delta: {Y_DELTA}");
Console.WriteLine($"Points: {TOTAL_POINTS}");
Console.WriteLine($"2D Compensator Table ({X_POINTS}x{Y_POINTS}):");
for (int i = 0; i < Y_POINTS; i++)
{
for (int j = 0; j < X_POINTS; j++)
{
Console.Write($"{table[i * X_POINTS + j],6}");
}
Console.WriteLine();
}
// get rmp controller
try
{
Helpers.CheckErrors(controller);
// set compensator count before any RapidCodeObject get/create other than the controller
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(INDEX_ZERO, table.Length); // set number points allocated on the controller
// get & configure axes
Axis x = controller.AxisGet(axisNumber: 0);
Helpers.CheckErrors(x);
Axis y = controller.AxisGet(axisNumber: 1);
Helpers.CheckErrors(y);
Axis z = controller.AxisGet(axisNumber: 2);
Helpers.CheckErrors(z);
// set position error limit trigger
// init the 2D compensator
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ZERO,
firstInputAxis: x,
firstInputAxisType: RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION,
firstInputAxisMinimum: X_MIN,
firstInputAxisMaximum: X_MAX,
firstInputAxisDelta: X_DELTA,
secondInputAxis: y,
secondInputAxisType: RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION,
secondInputAxisMinimum: Y_MIN,
secondInputAxisMaximum: Y_MAX,
secondInputAxisDelta: Y_DELTA,
outputAxis: z,
outputType: RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE,
table: table);
// get results
x.PositionSet(0);
y.PositionSet(0);
double compPos1 = z.CompensationPositionGet();
x.PositionSet(X_DELTA);
y.PositionSet(Y_DELTA);
double compPos2 = z.CompensationPositionGet();
// print results
Console.WriteLine($"Compensation at (0,0): {compPos1} (expected: {table[0]})");
Console.WriteLine($"Compensation at ({X_DELTA},{Y_DELTA}): {compPos2} (expected: {table[7]})");
// verify accuracy
if (compPos1 != table[0] || compPos2 != table[7])
throw new Exception("❌ Compensator compensation position does not match expected value.");
// cleanup
Helpers.AbortMotionObject(x);
Helpers.AbortMotionObject(y);
Helpers.AbortMotionObject(z);
}
// handle errors as needed
finally
{
controller.CompensatorCountSet(0); // restore
controller.Delete(); // dispose
}
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.