APIs, concepts, guides, and more
_setup.cs
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Sample Apps Setup");
// start fresh each time
KillExistingController();
// create new controller
var creationParams = GetCreationParameters();
MotionController controller = MotionController.Create(creationParams);
Helpers.CheckErrors(controller);
// setup controller
SetupController(controller, Constants.AXIS_COUNT, Constants.USE_HARDWARE);
// print setup
Console.WriteLine($"RMP path: {creationParams.RmpPath}");
Console.WriteLine($"Use hardware: {Constants.USE_HARDWARE}");
Console.WriteLine($"Axis count: {controller.AxisCountGet()}");
for (int i = 0; i < Constants.AXIS_COUNT; i++)
{
Axis? currentAxis = null;
// set userunits
if (i == 0)
{
currentAxis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(currentAxis);
}
else if (i == 1)
{
currentAxis = controller.AxisGet(Constants.AXIS_1_INDEX);
Helpers.CheckErrors(currentAxis);
}
// print axis info
if (currentAxis != null)
{
Console.WriteLine($" Axis {i}: Motor Type = {currentAxis.MotorTypeGet()}");
Console.WriteLine($" Axis {i}: UserUnits = {currentAxis.UserUnitsGet()}");
}
}
/*
┌────────────────┐
│ HELPER METHODS │
└────────────────┘
*/
MotionController.CreationParameters GetCreationParameters()
{
var createParams = new MotionController.CreationParameters();
#if WINDOWS
createParams.RmpPath = Constants.RMP_WINDOWS_PATH;
createParams.NodeName = Constants.RMP_NODE_NAME; // default is "NodeA"
#elif LINUX
createParams.RmpPath = Constants.RMP_LINUX_PATH;
createParams.NicPrimary = Constants.RMP_NIC_PRIMARY; // default is "" since we do not have network by default
createParams.CpuAffinity = Constants.RMP_CPU_AFFINITY; // default is 0 since this is what our tests use
#endif
return createParams;
}
static void SetupController(MotionController controller, int userAxisCount, bool useHardware)
{
// Start or shutdown the network depending on the configuration
if (useHardware)
{
}
else if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateUNINITIALIZED &&
controller.NetworkStateGet() != RSINetworkState.RSINetworkStateSHUTDOWN)
{
throw new Exception(
"The Sample Apps are configured to use Phantom Axes, but the network is not in the UNINITIALIZED or SHUTDOWN state.\n" +
"If you intended to run with hardware, then set USE_HARDWARE to true in config.json\n" +
"Otherwise, shutdown the network before running the sample apps with phantom axes.");
}
// Track initial counts for restoration later
int initialAxisCount = controller.AxisCountGet();
int initialMotionCount = controller.MotionCountGet();
// Check if we are using hardware or phantom axes
if (useHardware)
{
// Verify there are enough axes configured
int axisCount = controller.AxisCountGet();
if (axisCount < userAxisCount)
{
throw new Exception(
$"Error! Not enough axes configured. Expected {userAxisCount} axes but only found {axisCount} axes.\n" +
"Please configure the axes in your hardware setup.");
}
}
else
{
// Add phantom axes for the sample app if needed
if (userAxisCount != initialAxisCount)
{
controller.AxisCountSet(userAxisCount);
}
// Configure each phantom axis
for (int i = 0; i < userAxisCount; i++)
{
Helpers.ConfigurePhantomAxis(controller, i);
}
}
}
static void KillExistingController()
{
// try getting existing controller if any
try
{
// throws if there was no existing controller
Helpers.CheckErrors(controller);
// no errors thrown, so kill existing controller
controller.Shutdown();
}
catch
{
// ignore errors (no existing controller)
}
finally
{
controller.Delete(); // dispose
}
}
Constants used in the C# sample apps.
const bool USE_HARDWARE
Default: false.
Definition _constants.cs:10
const int AXIS_COUNT
Default: 2.
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:13
const int AXIS_1_USER_UNITS
Default: 1.
Definition _constants.cs:16
const int RMP_CPU_AFFINITY
Default: 0.
Definition _constants.cs:9
const string RMP_LINUX_PATH
Default: /rsi.
Definition _constants.cs:6
const int AXIS_0_USER_UNITS
Default: 1.
Definition _constants.cs:15
const string RMP_NIC_PRIMARY
Default: "".
Definition _constants.cs:8
const int AXIS_1_INDEX
Default: 1.
Definition _constants.cs:14
const string RMP_NODE_NAME
Default: NodeA.
Definition _constants.cs:7
static void SetupControllerForHardware(MotionController controller)
Sets up the controller for hardware use by resetting it and starting the network.
Definition _helpers.cs:126
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
static void ConfigurePhantomAxis(MotionController controller, int axisIndex)
Configures a phantom axis on the controller.
Definition _helpers.cs:160
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.
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.
RSINetworkState NetworkStateGet()
static MotionController * Get()
Get an already running RMP EtherCAT controller.
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
void Shutdown()
Shutdown the controller.
int32_t AxisCountGet()
Get the number of axes processing.
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
RSINetworkState
State of network.
Definition rsienums.h:568
CreationParameters for MotionController::Create.
Definition rsi.h:866