MotionController Axis MultiAxis IO IOPoint NetworkNode RsiError
Sample Apps Changelog

RapidCode API

Compensator2D.cs
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using RSI.RapidCode.dotNET.Enums; // Import RapidCode enums
using System;
namespace SampleAppsCS
{
class Compensator2D
{
static void Main(string[] args)
{
try
{
// Constants
const int X_AXIS_NUM = 0; // Specify which axis/motor to control.
const int Y_AXIS_NUM = 1; // Specify which axis/motor to control.
const int Z_AXIS_NUM = 2;
const int COMPENSATOR_NUM = 0; // Specify The address number of your compensator
const int USER_UNITS = 1048576; // Specify your counts per unit / user units.
const int ACCELERATION = 2; // Specify your acceleration. - units: Units/Sec^2
const int DECELERATION = 2; // Specify your deceleration. - units: Units/Sec^2
const int X_MIN = 0;
const int X_MAX = 50;
const int X_DELTA = 10;
const int Y_MIN = 0;
const int Y_MAX = 50;
const int Y_DELTA = 10;
const int COMPENSATOR_X_POINTS = ((X_MAX - X_MIN) / X_DELTA) + 1;
const int COMPENSATOR_Y_POINTS = ((Y_MAX - Y_MIN) / Y_DELTA) + 1;
const int POINTS = (COMPENSATOR_X_POINTS) * (COMPENSATOR_Y_POINTS);
// Compensator uses Axis COUNTS NOT user units
double[] TABLE = new double[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,
};
// Initialize RapidCode Objects
MotionController controller = MotionController.CreateFromSoftware(/*@"C:\RSI\X.X.X\"*/);// Insert the path location of the RMP.rta (usually the RapidSetup folder)
SampleAppsCS.HelperFunctions.CheckErrors(controller); // [Helper Function] Check that the controller has been initialize correctly.
//Setup memory space for the compensator
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(COMPENSATOR_NUM, TABLE.Length);
SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network.
Axis x = controller.AxisGet(X_AXIS_NUM); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
Axis y = controller.AxisGet(Y_AXIS_NUM); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
Axis z = controller.AxisGet(Z_AXIS_NUM); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
SampleAppsCS.HelperFunctions.CheckErrors(x); // [Helper Function] Check that the axis has been initialize correctly.
SampleAppsCS.HelperFunctions.CheckErrors(y); // [Helper Function] Check that the axis has been initialize correctly.
SampleAppsCS.HelperFunctions.CheckErrors(z); // [Helper Function] Check that the axis has been initialize correctly.
// Prepair each axis
x.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
x.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
x.Abort(); // If there is any motion happening, abort it.
x.ClearFaults(); // Clear faults.
// Prepair each axis
y.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
y.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
y.Abort(); // If there is any motion happening, abort it.
// Home the axis so we are starting at 0
y.AmpEnableSet(false); // Enable the motor.
z.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
z.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
z.DefaultAccelerationSet(ACCELERATION);
z.DefaultDecelerationSet(DECELERATION);
z.Abort(); // If there is any motion happening, abort it.
z.ClearFaults(); // Clear faults.
z.AmpEnableSet(true); // Enable the motor.
// Initalize the Compensator
controller.CompensatorConfigSet(COMPENSATOR_NUM, x, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, X_MIN, X_MAX, X_DELTA, y, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, Y_MIN, Y_MAX, Y_DELTA, z, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE);
Console.WriteLine("\nCompensator Configured\n");
while (!Console.KeyAvailable)
{
Console.WriteLine("Compensator Output: " + z.CompensationPositionGet());
}
}
catch (Exception e)
{
Console.WriteLine(e.Message); // If there are any exceptions/issues this will be printed out.
}
Console.WriteLine("\nPress Any Key To Exit"); // Allow time to read Console.
Console.ReadKey();
}
}
}