APIs, concepts, guides, and more
compensator-single-axis.cs
/* 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(INDEX_ZERO, table.Length); // set number points allocated on the controller
// get & configure axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
axis.Abort();
axis.ClearFaults();
controller.SampleWait(10);
axis.PositionSet(0);
// 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
compensatorNumber: INDEX_ZERO,
inputAxis: axis,
inputAxisMinimum: MIN,
inputAxisMaximum: MAX,
inputAxisDelta: DELTA,
outputAxis: axis,
table: table);
// command motion
axis.AmpEnableSet(true);
axis.MoveSCurve(position: MIN + DELTA); // move to 2nd point
// 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.");
}
}
// 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 PositionSet(double position)
Set the Command and Actual positions.
void MoveSCurve(double position, double vel, double accel, double decel, double jerkPct)
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.
int32_t CompensatorPointCountGet(int32_t compensatorNumber)
Get the number of points for use with a Compensator.
void CompensatorPointCountSet(int32_t compensatorNumber, int32_t pointCount)
Set the number of points for use with a Compensator.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
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
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
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_COMMAND_POSITION
Use command position from master.