APIs, concepts, guides, and more
compensator-2d.cs
/* 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(Constants.AXIS_0_INDEX);
Axis y = controller.AxisGet(Constants.AXIS_1_INDEX);
Axis z = controller.AxisGet(Constants.AXIS_2_INDEX);
// set position error limit trigger
// init the 2D compensator
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);
// get results
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.");
}
// handle errors as needed
finally
{
controller.CompensatorCountSet(0); // restore
controller.Delete(); // dispose
}
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
double CompensationPositionGet()
Get the compensator position.
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.
void PositionSet(double position)
Set the Command and Actual positions.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5870
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void CompensatorPointCountSet(int32_t compensatorNumber, int32_t pointCount)
Set the number of points for use with a Compensator.
void Delete(void)
Delete the MotionController and all its objects.
void CompensatorCountSet(int32_t compensatorCount)
Set the number of Compensators available in the firmware.
void CompensatorConfigSet(int32_t compensatorNumber, int32_t firstInputAxisNumber, RSIAxisMasterType firstInputAxisType, double firstInputAxisMinimum, double firstInputAxisMaximum, double firstInputAxisDelta, int32_t secondInputAxisNumber, RSIAxisMasterType secondInputAxisType, double secondInputAxisMinimum, double secondInputAxisMaximum, double secondInputAxisDelta, int32_t outputAxisNumber, RSICompensatorOutputType outputType, const double *const table)
Configure a 2D compensator.
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
@ RSICompensatorOutputTypeSINGLE
Compensator output will overwrite any other compensation values.
RSIAxisMasterType
Sources available to a slave Axis for electronic gearing & camming.
Definition rsienums.h:1218
@ RSIAxisMasterTypeAXIS_ACTUAL_POSITION
Use actual position from master.