APIs, concepts, guides, and more
basic-template.cs
/* 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
}
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
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:5862
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
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.
CreationParameters for MotionController::Create.
Definition rsi.h:866