APIs, concepts, guides, and more
🧩 Template

Basic template for getting started with RapidCode.

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.


In this page:


📜 Basic Template

This template demonstrates basic Controller and Axis initialization, configuration, and how to enable an axis and prepare it for motion. Use this as a starting point for RapidCode applications.

/* This is a basic template you can use to get up and running quickly with RapidCode.
It demonstrates simple controller and axis initialization, basic axis configuration,
and how to enable an axis and prepare it for motion.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Basic Template");
// create rmp controller
var createParams = new MotionController.CreationParameters();
#if WINDOWS
createParams.RmpPath = Constants.RMP_WINDOWS_PATH; // default is "C:\RSI\X.X.X"
createParams.NodeName = Constants.RMP_NODE_NAME; // default is "NodeA"
#elif LINUX
createParams.RmpPath = Constants.RMP_LINUX_PATH; // default is root folder "/rsi/"
createParams.NicPrimary = Constants.RMP_NIC_PRIMARY; // default is empty since we do not have a network by default
createParams.CpuAffinity = Constants.RMP_CPU_AFFINITY; // default is 0 since this is what our tests use
#endif
MotionController controller = MotionController.Create(createParams);
try
{
Helpers.CheckErrors(controller); // ALWAYS check for errors after creating a RapidCode object
// start the ethercat network
//Helpers.NetworkStart(controller); // uncomment if using real (not phantom) axis. samples use phantoms by default
// get your axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis); // ALWAYS check for errors after creating a RapidCode object
// specify the counts per unit/user units
const int ENCODER_RESOLUTION_BITS = 0; // set this to your encoder resolution in bits (e.g., 20 bits = 1,048,576 counts/rev)
double userUnits = Math.Pow(2, ENCODER_RESOLUTION_BITS); // turn your encoder resolution into something more meaningful than raw counts.
axis.UserUnitsSet(userUnits); // they are often used to change counts to distance (cm, inch, etc), degree, full rotation, etc.
// configure axis limits and error handling
axis.ErrorLimitTriggerValueSet(1); // set position error limit trigger
axis.PositionSet(0); // make sure motor starts at position 0
axis.Abort(); // abort any motion
axis.ClearFaults(); // clear faults, resets to IDLE state
axis.AmpEnableSet(true); // enable the motor
Console.WriteLine("Axis initialized and ready");
Console.WriteLine($"User Units: {userUnits}");
Console.WriteLine($"Current Position: {axis.CommandPositionGet()}");
Console.WriteLine($"Amp Enabled: {axis.AmpEnableGet()}");
//-----INSERT YOUR CODE HERE-----
//-----INSERT YOUR CODE HERE-----
axis.AmpEnableSet(false); // disable the motor
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
finally
{
controller.Delete(); // delete the controller as the program exits to ensure memory is deallocated in the correct order
}
Constants used in the C# sample apps.
Definition _constants.cs:3
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:11
const int RMP_CPU_AFFINITY
Default: 0.
Definition _constants.cs:8
const string RMP_LINUX_PATH
Default: /rsi.
Definition _constants.cs:5
const string RMP_NIC_PRIMARY
Default: "".
Definition _constants.cs:7
const string RMP_NODE_NAME
Default: NodeA.
Definition _constants.cs:6
const string RMP_WINDOWS_PATH
Default: .....
Definition _constants.cs:4
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
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:5863
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
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 AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21
CreationParameters for MotionController::Create.
Definition rsi.h:866