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.
Console.WriteLine("📜 Compensator: Single Axis");
int exitCode = 0;
const int INDEX_ZERO = 0;
const int MIN = 10;
const int MAX = 110;
const int DELTA = 10;
const int POINTS = ((MAX - MIN) / DELTA) + 1;
const double VELOCITY = 20.0;
const double ACCELERATION = 30.0;
const double DECELERATION = 30.0;
const double JERK = 50.0;
double[] table = new double[POINTS] { 0, 2, -3, -5, -3, 2, -3, 0, 2, -3, -5 };
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]}");
}
try
{
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(compensatorNumber: INDEX_ZERO, pointCount: table.Length);
if (controller.CompensatorPointCountGet(INDEX_ZERO) == table.Length && POINTS == table.Length)
{
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ZERO,
inputAxis: axis,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: axis,
table: table);
axis.PositionSet(MIN);
axis.MoveSCurve(position: MIN + DELTA, VELOCITY, ACCELERATION, DECELERATION, JERK);
axis.MotionDoneWait();
double compPos = axis.CompensationPositionGet();
Console.WriteLine($"Compensation position: {compPos} (expected: {table[1]})");
axis.AmpEnableSet(false);
axis.UserUnitsSet(originalUserUnits);
if (compPos != table[1])
throw new Exception("❌ Compensator compensation position does not match expected value.");
}
}
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
}
finally
{
controller.CompensatorCountSet(0);
controller.Delete();
}
return exitCode;
Constants used in the C# sample apps.
const bool USE_HARDWARE
Default: false.
const int EXIT_FAILURE
Exit code for failed execution.
const int AXIS_0_INDEX
Default: 0.
const int AMP_ENABLE_MS
Default: 750.
const int EXIT_SUCCESS
Exit code for successful execution.
double UserUnitsGet()
Get the number of counts per User Unit.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
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...
RSICompensatorOutputType
Compensator output types.
RSIAxisMasterType
Sources available to a slave Axis for electronic gearing & camming.
Helpers namespace provides utility functions for common tasks in RMP applications.
📜 Compensator: 1D
Learn how to configure a 1-dimensional Compensator 📖 with overlapping compensation tables to modify follower axis motion based on moving axis position.
Console.WriteLine("📜 Compensator: 1D");
int exitCode = 0;
const int INDEX_ZERO = 0;
const int INDEX_ONE = 1;
const int MIN = 0;
const int MAX = 100;
const int DELTA = 10;
const int POINTS = ((MAX - MIN) / DELTA) + 1;
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 };
Console.WriteLine($"Range: {MIN} to {MAX}, Delta: {DELTA}");
Console.WriteLine($"Points: {POINTS}");
try
{
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller, minRequiredSampleAxisCount: 2);
controller.CompensatorCountSet(2);
controller.CompensatorPointCountSet(INDEX_ZERO, table0.Length);
controller.CompensatorPointCountSet(INDEX_ONE, table1.Length);
Helpers.PhantomAxisReset(movingAxis);
Helpers.PhantomAxisReset(followerAxis);
if (controller.CompensatorPointCountGet(INDEX_ZERO) == table0.Length && POINTS == table0.Length)
{
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ZERO,
inputAxis: movingAxis,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: followerAxis,
table: table0);
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ONE,
inputAxis: movingAxis,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: followerAxis,
table: table1);
movingAxis.PositionSet(DELTA);
double compPos = followerAxis.CompensationPositionGet();
Console.WriteLine($"Compensation position: {compPos} (expected: {table0[1] + table1[1]})");
if (compPos != table0[1] + table1[1])
throw new Exception("❌ Compensator compensation position does not match expected value.");
Helpers.AbortMotionObject(followerAxis);
Helpers.AbortMotionObject(movingAxis);
}
}
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
}
finally
{
controller.CompensatorCountSet(0);
controller.Delete();
}
return exitCode;
const int AXIS_1_INDEX
Default: 1.
📜 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).
Console.WriteLine("📜 Compensator: 2D");
int exitCode = 0;
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;
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;
const int TOTAL_POINTS = X_POINTS * Y_POINTS;
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,
};
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();
}
try
{
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller, minRequiredSampleAxisCount: 3);
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(INDEX_ZERO, table.Length);
controller.CompensatorConfigSet(
compensatorNumber: INDEX_ZERO,
firstInputAxis: x,
firstInputAxisMinimum: X_MIN,
firstInputAxisMaximum: X_MAX,
firstInputAxisDelta: X_DELTA,
secondInputAxis: y,
secondInputAxisMinimum: Y_MIN,
secondInputAxisMaximum: Y_MAX,
secondInputAxisDelta: Y_DELTA,
outputAxis: z,
table: table);
x.PositionSet(0);
y.PositionSet(0);
double compPos1 = z.CompensationPositionGet();
x.PositionSet(X_DELTA);
y.PositionSet(Y_DELTA);
double compPos2 = z.CompensationPositionGet();
Console.WriteLine($"Compensation at (0,0): {compPos1} (expected: {table[0]})");
Console.WriteLine($"Compensation at ({X_DELTA},{Y_DELTA}): {compPos2} (expected: {table[7]})");
if (compPos1 != table[0] || compPos2 != table[7])
throw new Exception("❌ Compensator compensation position does not match expected value.");
}
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
}
finally
{
controller.CompensatorCountSet(0);
controller.Delete();
}
return exitCode;
const int AXIS_2_INDEX
Default: 2.
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.