APIs, concepts, guides, and more
UserLimitDigitalInputAction.cpp
1
25#include "rsi.h" // Import our RapidCode Library.
26#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
27#include "SampleApps.h"
28
29using namespace RSI::RapidCode; // Import the RapidCode namespace
30
32int UserLimitDigialInputAction::Run()
33{
35 /* CONSTANTS */
36 // *NOTICE* The following constants must be configured before attempting to run with hardware.
37
38 // Axis configuration parameters
39 const int AXIS_COUNT = 1; // Specify how many axes we will be using in this sample.
40 const int AXIS_NUMBER = 0; // Specify which axis/motor we will be controlling.
41
42 const double USER_UNITS = 1048576; // Specify your counts per unit / user units. (the motor used in this example has 1048576 encoder pulses per revolution)
43
44 const int IO_NODE_NUMBER = 0; // which SqNode to use for I/O?
45 const int USER_LIMIT = 0; // which user limit to use?
46 const int CONDITION = 0; // which condition to use (0 or 1)
47 const int INPUT_BIT_NUMBER = 0; // which input bit?
48
49 // To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
50 USE_HARDWARE = false;
51
52 /* SAMPLE APP BODY */
53
54 // Initialize MotionController class.
57
58 // Setup the controller for the appropriate hardware configuration.
59 if (USE_HARDWARE)
60 {
62 }
63 else
64 {
65 std::cout << "This sample app cannot be run without hardware." << std::endl;
66 return 0;
67 }
68
69 // RapidCode interface classes
70 IO* io;
71 IOPoint* digitalInput;
72 try
73 {
74 // Create a new User Limit
75 controller->UserLimitCountSet(1);
76
77 // initialize the I/O class
78 io = controller->IOGet(IO_NODE_NUMBER);
80
81 digitalInput = IOPoint::CreateDigitalInput(io, INPUT_BIT_NUMBER);
82
83 auto addr = digitalInput->AddressGet();
84 auto mask1 = digitalInput->MaskGet();
85 auto mask2 = digitalInput->MaskGet();
86
87 // configure user limit to evaluate input bit
88 controller->UserLimitConditionSet(USER_LIMIT,
89 CONDITION,
91 digitalInput->AddressGet(),
92 digitalInput->MaskGet(),
93 digitalInput->MaskGet());
94
95 // enable the user limit, generate ESTOP_ABORT action when input is turned on
97
98 printf("Waiting for the input bit to go high...\n");
99 printf("\nPress Any Key To Exit.\n");
100
101 // wait for user limit to trigger
102 while (controller->OS->KeyGet((int32_t)RSIWait::RSIWaitPOLL) < 0)
103 {
104 printf("User Limit state is %d\r", controller->UserLimitStateGet(USER_LIMIT));
105 controller->OS->Sleep(1);
106 }
107
108 // disable User Limit
109 controller->UserLimitDisable(USER_LIMIT);
110 }
111 catch (RsiError const& rsiError)
112 {
113 printf("Text: %s\n", rsiError.text);
114 return -1;
115 }
116 controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
117 return 0;
119}
120
The IO object provides an interface to the inputs and outputs of a network node.
Definition rsi.h:11420
uint64_t AddressGet()
Get the Host Address for the I/O point.
static IOPoint * CreateDigitalInput(Axis *axis, RSIMotorDedicatedIn motorDedicatedInNumber)
Create a Digital Input from an Axis' Dedicated Input bits.
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:10928
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.
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
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:794
RapidCodeOS * OS
Provides access to operating system (Windows) features.
Definition rsi.h:3664
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:105
@ RSIActionE_STOP_ABORT
E-Stop then Abort.
@ RSIWaitPOLL
return immediately, use polling
@ RSIUserLimitTriggerTypeSINGLE_CONDITION
Only one condition is evaluated.
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 ...