APIs, concepts, guides, and more
compensator-single-axis.cs
Note
See Motion: Compensator 📜 for a detailed explanation of this sample code.
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.
/* 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