96#ifndef SAMPLE_APPS_HELPER
97#define SAMPLE_APPS_HELPER
133 std::ostringstream message;
134 message <<
"You must implement the " << __func__ <<
" function (found in " << __FILE__ <<
" line " << __LINE__ <<
") to use hardware.";
135 throw std::runtime_error(message.str().c_str());
196 bool hasErrors =
false;
197 std::string errorStrings(
"");
202 errorStrings += err->
what();
203 errorStrings +=
"\n";
213 throw std::runtime_error(errorStrings.c_str());
228 if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateOPERATIONAL)
230 std::cout <<
"Starting Network.." << std::endl;
234 if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateOPERATIONAL)
238 for (
int i = 0; i < messagesToRead; i++)
242 throw std::runtime_error(
"Expected OPERATIONAL state but the network did not get there.");
246 std::cout <<
"Network Started" << std::endl << std::endl;
261 if (controller->
NetworkStateGet() == RSINetworkState::RSINetworkStateUNINITIALIZED ||
262 controller->
NetworkStateGet() == RSINetworkState::RSINetworkStateSHUTDOWN)
268 std::cout <<
"Shutting down the network.." << std::endl;
271 if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateUNINITIALIZED &&
272 controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateSHUTDOWN)
276 for (
int i = 0; i < messagesToRead; i++)
280 throw std::runtime_error(
"Expected SHUTDOWN state but the network did not get there.");
284 std::cout <<
"Network Shutdown" << std::endl << std::endl;
315 const double positionToleranceMax =
316 std::numeric_limits<double>::max() /
341 else if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateUNINITIALIZED &&
342 controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateSHUTDOWN)
344 std::ostringstream message;
345 message <<
"The Sample Apps are configured to use Phantom Axes, but the network is not in the UNINITIALIZED or SHUTDOWN state.\n"
346 <<
"If you intended to run with hardware, then follow the steps in README.md and /include/SampleAppsHelper.h\n"
347 <<
"Otherwise, shutdown the network before running the sample apps with phantom axes.";
349 throw std::runtime_error(message.str().c_str());
360 if (axisCount < numAxes)
362 std::ostringstream message;
363 message <<
"Error! Not enough axes configured. Expected " << numAxes <<
" axes but only found " << axisCount <<
" axes."
364 <<
"Please configure the axes in the SampleAppsConfig::ConfigureHardwareAxes function.";
365 throw std::runtime_error(message.str().c_str());
380 for (
int i = 0; i < numAxes; i++)
449 for (
auto axisNum : axisNums)
463 std::cout <<
"----------------------------------------------------------------------------------------------------\n";
464 std::cout <<
"Running " << sampleAppName <<
" Sample App\n";
465 std::cout <<
"----------------------------------------------------------------------------------------------------\n" << std::endl;
477 std::cout <<
"\n----------------------------------------------------------------------------------------------------\n";
480 std::cout << sampleAppName <<
" Sample App Completed Successfully\n";
484 std::cout << sampleAppName <<
" Sample App Failed with Exit Code: " << exitCode <<
"\n";
486 std::cout <<
"----------------------------------------------------------------------------------------------------\n" << std::endl;
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
void HardwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Positive Limit Event triggers.
void PositionToleranceCoarseSet(double tolerance)
Set the Coarse Position Tolerance for Axis settling.
void SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
void AmpFaultActionSet(RSIAction action)
Set the Amp Fault action.
void AmpFaultTriggerStateSet(bool state)
Set the trigger state of the Amp Fault input.
void HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
void PositionToleranceFineSet(double tolerance)
Set the Fine Position Tolerance for Axis settling.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void MotorTypeSet(RSIMotorType type)
Set the motor type.
void PositionSet(double position)
Set the Command and Actual positions.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSINetworkState NetworkStateGet()
void Reset()
Reset the controller which stops and restarts the RMP firmware.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
const char *const NetworkLogMessageGet(int32_t messageIndex)
int32_t AxisCountGet()
Get the number of axes processing.
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.
int32_t NetworkLogMessageCountGet()
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
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...
void NetworkShutdown()
Shutdown the network. For EtherCAT, this will kill the RMPNetwork process.
void NetworkStart()
Start the network with RSINetworkStartupMethodNORMAL.
const RsiError *const ErrorLogGet()
Get the next RsiError in the log.
int32_t ErrorLogCountGet()
Get the number of software errors in the error log.
The RapidCode base class. All non-error objects are derived from this class.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
bool isWarning
Whether the error is or is not a warning.
const char * what() const noexcept
Returns a null terminated character sequence that may be used to identify the exception.
static void SetupControllerForHardware(MotionController *controller)
Sets up the controller for hardware use by resetting it and starting the network.
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void ConfigurePhantomAxis(MotionController *controller, int axisNumber)
Configures a specified axis as a phantom axis with custom settings.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static void ShutdownTheNetwork(MotionController *controller)
Shuts down the network communication for the given MotionController.
static void SetupControllerForPhantoms(MotionController *controller, int axisCount, std::vector< int > axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.
static void ClearControllerCounts(MotionController *controller)
Clears count settings for axes, motion, and user limits on the controller.
static void StartTheNetwork(MotionController *controller)
Starts the network communication for the given MotionController.
static void Cleanup(MotionController *controller)
Cleanup the controller and restore the object counts to the original values.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
static void SetupController(MotionController *controller, int numAxes=0)
Setup the controller with user defined axis counts and configuration.
SampleAppsHelper namespace provides static methods for common tasks in RMP applications.
static int initialAxisCount
Initial axis count to restore later (-1 indicates it has not been set)
static int initialMotionCount
Initial motion count to restore later (-1 indicates it has not been set)
char NodeName[PathLengthMaximum]
[Windows/INtime] Indicate the INtime node on which the RMP and RMPNetwork processes run.
char RmpPath[PathLengthMaximum]
Location of the RMP firmware executable, license, and associated binaries and resources.
int32_t CpuAffinity
[Linux] Indicate the CPU core on which the RMP and RMPNetwork processes run.
char NicPrimary[PathLengthMaximum]
Primary EtherCAT Network Interface (NIC) name.
static constexpr uint32_t PathLengthMaximum
MotionController::CreationParameters Maximum string buffer length.
CreationParameters for MotionController::Create.
static void ConfigureHardwareAxes(MotionController *controller)
Configures the hardware axes according to user specified implementation.
This struct provides static methods and constants for user configuration in RMP applications....
static constexpr int CPU_AFFINITY
(Linux only) CPU core to use. This should be an isolated core.
static constexpr char NIC_PRIMARY[]
Name of the NIC to use for the EtherCAT network (not needed for running on phantom axes)
static constexpr bool USE_HARDWARE
Flag for whether to use hardware or phantom axes.
static constexpr char RMP_PATH[]
Path to the RMP.rta file (usually the RapidSetup folder).
static constexpr char NODE_NAME[]
(Windows only) INtime node name. Use "" for default node.