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 = controller.AxisGet(axisNumber: i);
Helpers.CheckErrors(currentAxis);
// set userunits
currentAxis.UserUnitsSet(countsPerUserUnit: 1);
// print axis info
if (currentAxis != null)
{
Console.WriteLine($" Axis {i}: Motor Type = {currentAxis.MotorTypeGet()}");
Console.WriteLine($" Axis {i}: UserUnits = {currentAxis.UserUnitsGet()}");
}
}
/*
┌────────────────┐
│ HELPER METHODS │
└────────────────┘
*/
{
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)
{
Helpers.ControllerSetup(controller);
}
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++)
{
Axis phantomAxis = controller.AxisGet(i);
Helpers.CheckErrors(phantomAxis);
Helpers.PhantomAxisReset(phantomAxis);
}
}
}
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.
Definition _constants.cs:3
const bool USE_HARDWARE
Default: false.
Definition _constants.cs:9
const int AXIS_COUNT
Default: 6.
Definition _constants.cs:10
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.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5863
static MotionController * Get()
Get an already running RMP EtherCAT controller.
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
RSINetworkState
State of network.
Definition rsienums.h:568
void SetupController(MotionController *controller, int numAxes=0)
Setup the controller and check if the network is in the correct state for the configuration.
Definition config.h:134
MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
Definition config.h:68
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21
CreationParameters for MotionController::Create.
Definition rsi.h:866