1#ifndef SAMPLE_APPS_HELPER
2#define SAMPLE_APPS_HELPER
38 std::ostringstream message;
39 message <<
"You must implement the " << __func__ <<
" function (found in " << __FILE__ <<
" line " << __LINE__ <<
") to use hardware.";
40 throw std::runtime_error(message.str().c_str());
101 bool hasErrors =
false;
102 std::string errorStrings(
"");
107 errorStrings += err->
what();
108 errorStrings +=
"\n";
118 throw std::runtime_error(errorStrings.c_str());
135 std::cout <<
"Starting Network.." << std::endl;
136 controller->NetworkStart();
141 int messagesToRead = controller->NetworkLogMessageCountGet();
143 for (
int i = 0; i < messagesToRead; i++)
145 std::cout << controller->NetworkLogMessageGet(i) << std::endl;
147 throw std::runtime_error(
"Expected OPERATIONAL state but the network did not get there.");
151 std::cout <<
"Network Started" << std::endl << std::endl;
173 std::cout <<
"Shutting down the network.." << std::endl;
174 controller->NetworkShutdown();
179 int messagesToRead = controller->NetworkLogMessageCountGet();
181 for (
int i = 0; i < messagesToRead; i++)
183 std::cout << controller->NetworkLogMessageGet(i) << std::endl;
185 throw std::runtime_error(
"Expected SHUTDOWN state but the network did not get there.");
189 std::cout <<
"Network Shutdown" << std::endl << std::endl;
205 Axis *axis = controller->AxisGet(axisNumber);
220 const double positionToleranceMax =
221 std::numeric_limits<double>::max() /
249 std::ostringstream message;
250 message <<
"The Sample Apps are configured to use Phantom Axes, but the network is not in the UNINITIALIZED or SHUTDOWN state.\n"
251 <<
"If you intended to run with hardware, then follow the steps in README.md and /src/SampleAppsHelper.h\n"
252 <<
"Otherwise, shutdown the network before running the sample apps with phantom axes.";
254 throw std::runtime_error(message.str().c_str());
264 int axisCount = controller->AxisCountGet();
265 if (axisCount < numAxes)
267 std::ostringstream message;
268 message <<
"Error! Not enough axes configured. Expected " << numAxes <<
" axes but only found " << axisCount <<
" axes."
269 <<
"Please configure the axes in the SampleAppsConfig::ConfigureHardwareAxes function.";
270 throw std::runtime_error(message.str().c_str());
282 controller->AxisCountSet(numAxes);
285 for (
int i = 0; i < numAxes; i++)
333 controller->AxisCountSet(0);
334 controller->MotionCountSet(0);
335 controller->UserLimitCountSet(0);
353 controller->AxisCountSet(axisCount);
354 for (
auto axisNum : axisNums)
368 std::cout <<
"----------------------------------------------------------------------------------------------------\n";
369 std::cout <<
"Running " << sampleAppName <<
" Sample App\n";
370 std::cout <<
"----------------------------------------------------------------------------------------------------\n" << std::endl;
382 std::cout <<
"\n----------------------------------------------------------------------------------------------------\n";
385 std::cout << sampleAppName <<
" Sample App Completed Successfully\n";
389 std::cout << sampleAppName <<
" Sample App Failed with Exit Code: " << exitCode <<
"\n";
391 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,...
Represents the RMP soft motion controller. This class provides an interface to general controller con...
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.
@ RSINetworkStateSHUTDOWN
EtherCAT was shutdown or stopped, must restart.
@ RSINetworkStateOPERATIONAL
EtherCAT operational, good state.
@ RSINetworkStateUNINITIALIZED
EtherCAT not yet started.
@ RSIActionNONE
None - do not perform any action.
@ RSIMotorTypePHANTOM
Phantom motor (nothing physically connected).
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.