APIs, concepts, guides, and more
UserLimitDigitalInputAction.cpp
Attention
See the following Concept pages for a detailed explanation of this sample: User Limits.
Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
#include "rsi.h" // Import our RapidCode Library.
#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
#include "SampleApps.h"
using namespace RSI::RapidCode; // Import the RapidCode namespace
int UserLimitDigialInputAction::Run()
{
/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
// Axis configuration parameters
const int AXIS_COUNT = 1; // Specify how many axes we will be using in this sample.
const int AXIS_NUMBER = 0; // Specify which axis/motor we will be controlling.
const double USER_UNITS = 1048576; // Specify your counts per unit / user units. (the motor used in this example has 1048576 encoder pulses per revolution)
const int IO_NODE_NUMBER = 0; // which SqNode to use for I/O?
const int USER_LIMIT = 0; // which user limit to use?
const int CONDITION = 0; // which condition to use (0 or 1)
const int INPUT_BIT_NUMBER = 0; // which input bit?
// To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
USE_HARDWARE = false;
/* SAMPLE APP BODY */
// Initialize MotionController class.
MotionController* controller = MotionController::CreateFromSoftware();
// Setup the controller for the appropriate hardware configuration.
if (USE_HARDWARE)
{
}
else
{
std::cout << "This sample app cannot be run without hardware." << std::endl;
return 0;
}
// RapidCode interface classes
IO* io;
IOPoint* digitalInput;
try
{
// Create a new User Limit
controller->UserLimitCountSet(1);
// initialize the I/O class
io = controller->IOGet(IO_NODE_NUMBER);
digitalInput = IOPoint::CreateDigitalInput(io, INPUT_BIT_NUMBER);
auto addr = digitalInput->AddressGet();
auto mask1 = digitalInput->MaskGet();
auto mask2 = digitalInput->MaskGet();
// configure user limit to evaluate input bit
controller->UserLimitConditionSet(USER_LIMIT,
CONDITION,
RSIUserLimitLogic::RSIUserLimitLogicEQ,
digitalInput->AddressGet(),
digitalInput->MaskGet(),
digitalInput->MaskGet());
// enable the user limit, generate ESTOP_ABORT action when input is turned on
controller->UserLimitConfigSet(USER_LIMIT, RSIUserLimitTriggerType::RSIUserLimitTriggerTypeSINGLE_CONDITION, RSIAction::RSIActionE_STOP_ABORT, AXIS_NUMBER, 0.0);
printf("Waiting for the input bit to go high...\n");
printf("\nPress Any Key To Exit.\n");
// wait for user limit to trigger
while (controller->OS->KeyGet((int32_t)RSIWait::RSIWaitPOLL) < 0)
{
printf("User Limit state is %d\r", controller->UserLimitStateGet(USER_LIMIT));
controller->OS->Sleep(1);
}
// disable User Limit
controller->UserLimitDisable(USER_LIMIT);
}
catch (RsiError const& rsiError)
{
printf("Text: %s\n", rsiError.text);
return -1;
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return 0;
}
uint64_t AddressGet()
Get the Host Address for the I/O point.
int32_t MaskGet()
Get the bit mask for the I/O point.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:10964
void UserLimitDisable(int32_t number)
Disable the processing of a User Limit.
void UserLimitConditionSet(int32_t number, int32_t conditionNumber, RSIUserLimitLogic logic, uint64_t addressOfUInt32, uint32_t userLimitMask, uint32_t limitValueUInt32)
Set the conditions for a User Limit with a 32-bit integer trigger value.
void UserLimitConfigSet(int32_t number, RSIUserLimitTriggerType triggerType, RSIAction action, int32_t actionAxis, double duration, bool singleShot)
Configure a User Limit.
void Delete(void)
Delete the MotionController and all its objects.
IO * IOGet(int32_t nodeNumber)
IOGet returns a pointer to an IO object using its node number and initializes its internals.
bool UserLimitStateGet(int32_t number)
Get the state of a User Limit.
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:796
RapidCodeOS * OS
Provides access to operating system (Windows) features.
Definition rsi.h:3698
void Sleep(int32_t milliseconds)
Put the current thread to sleep.
int32_t KeyGet(int32_t milliseconds)
Wait for a key to be pressed and return its value.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:107
static void SetupControllerForHardware(MotionController *controller)
Sets up the controller for hardware use by resetting it and starting the network.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...