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