MotionController Axis MultiAxis IO IOPoint NetworkNode RsiError
Sample Apps Changelog

RapidCode API

CompensatorSingleAxis.cs

A 1D compensator with the same axis as the input and output

This sample application demonstrates how to use the compensator.

Precondition
This sample code presumes that the user has set the tuning paramters(PID, PIV, etc.) prior to running this program so that the motor can rotate in a stable manner.
Warning
This is a sample program to assist in the integration of your motion controller with your application. It may not contain all of the logic and safety features that your application requires.
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using RSI.RapidCode.dotNET.Enums; // Import RapidCode enums
using System;
namespace SampleAppsCS
{
class CompensatorSingleAxis
{
static void Main(string[] args)
{
try
{
// Constants
const int AXIS = 0; // Specify which axis/motor to control.
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 MIN = 0;
const int MAX = 20;
const int DELTA = 1;
const int POINTS = ((MAX - MIN) / DELTA) + 1; //22
// Compensator uses Axis COUNTS NOT user units
double[] TABLE0 = new double[POINTS] { 0, 1000, -5000, -10000, 10000, 5000, -5000, 2500, 0, 2500, 5000, 7500, 1000, 1250, 1000, 7500, 5000, 2500, 0, -2500, -1000 };
// 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, TABLE0.Length);
SampleAppsCS.HelperFunctions.StartTheNetwork(controller); // [Helper Function] Initialize the network.
Axis axis = controller.AxisGet(AXIS); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
SampleAppsCS.HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
// Prepair each axis
axis.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
axis.Abort(); // If there is any motion happening, abort it.
axis.ClearFaults(); // Clear faults.
axis.AmpEnableSet(false); // Enable the motor.
axis.UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
axis.DefaultAccelerationSet(ACCELERATION);
axis.DefaultDecelerationSet(DECELERATION);
axis.Abort(); // If there is any motion happening, abort it.
axis.ClearFaults(); // Clear faults.
axis.AmpEnableSet(true); // Enable the motor.
//NOTE the three following values must be equal. Otherwise an error will be thrown. See topic page for more info.
Console.WriteLine("Points in Compensator: " + controller.CompensatorPointCountGet(COMPENSATOR_NUM));
Console.WriteLine("Array length: " + TABLE0.Length);
int points = (int)((MAX - MIN) / DELTA) + 1;
Console.WriteLine("Equation points: " + points);
// Initalize the Compensator
controller.CompensatorConfigSet(COMPENSATOR_NUM, axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION, MIN, MAX, DELTA, axis, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE0);
Console.WriteLine("\nCompensator Configured\n");
while (!Console.KeyAvailable)
{
controller.SampleWait(1000);
Console.WriteLine("Compensator Output: " + axis.CompensationPositionGet() + " User Units --- Compensator Output: " + axis.CompensationPositionGet()/USER_UNITS+" Counts");
}
}
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();
}
}
}