APIs, concepts, guides, and more
HardwareLimits.cpp
1
24#include "rsi.h" // Import our RapidCode Library.
25#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
26#include "SampleApps.h"
27
28using namespace RSI::RapidCode; // Import the RapidCode namespace
29
31int HardwareLimits::Run()
32{
33 /* CONSTANTS */
34 // *NOTICE* The following constants must be configured before attempting to run with hardware.
35
36 // Axis configuration parameters
37 const int AXIS_COUNT = 1; // Specify how many axes we will be using in this sample.
38 const int AXIS_NUMBER = 0; // Specify which axis/motor we will be controlling.
39
40 const double USER_UNITS = 1048576; // Specify your counts per unit / user units. (the motor used in this example has 1048576 encoder pulses per revolution)
41
42 // Hardware Limit configuration parameters
43 const bool ACTIVE_HIGH = true; // Constant for active high.
44 const bool ACTIVE_LOW = false; // Constant for active low.
45 const double HW_POS_DURATION_TIME = 0.01; // Positive limit duration. (in seconds)
46 const double HW_NEG_DURATION_TIME = 0.01; // Negative limit duration. (in seconds)
47
48 // To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
49 USE_HARDWARE = false;
50
51 // The rmpPath only needs to be set if the project directory is different than the rapid setup directory.
52 // *NOTICE* When setting the rmpPath, be sure to uncomment the rmpPath arguement in MotionController::CreateFromSoftware() in the Run() function.
53 const std::string rmpPath = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)
54
55 /* SAMPLE APP BODY */
56
57 // Initialize MotionController class.
58 MotionController* controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
59 SampleAppsHelper::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
60
61 // Setup the controller for the appropriate hardware configuration.
62 if (USE_HARDWARE)
63 {
65 }
66 else
67 {
68 SampleAppsHelper::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
69 }
70
71 try
72 {
73 Axis* axis = controller->AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
74 SampleAppsHelper::CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
75
76 printf("Hardware Limits Example\n");
77
78 // Change Hardware POSITIVE (+) Limit characteristicpp.
79 axis->HardwarePosLimitActionSet(RSIAction::RSIActionE_STOP); // Set the positive limit action to E_STOP.
80 printf("\nHardware Positive Limit Action set to %i", axis->HardwarePosLimitActionGet());
81
82 axis->HardwarePosLimitTriggerStateSet(ACTIVE_HIGH); // Set the positive limit trigger state to ACTIVE_HIGH.
83 printf("\nHardware Positive Limit TriggerState set to %i", axis->HardwarePosLimitTriggerStateGet());
84
85 axis->HardwarePosLimitDurationSet(HW_POS_DURATION_TIME); // Set the positive limit duration to 0.01 seconds.
86 printf("\nHardware Positive Limit Duration set to %f seconds", axis->HardwarePosLimitDurationGet());
87
88 // Change Hardware NEGATIVE (-) Limit charateristicpp.
89 axis->HardwareNegLimitActionSet(RSIAction::RSIActionE_STOP); // Set the negative limit action to E_STOP.
90 printf("\nHardware Negative Limit Action set to %i", axis->HardwareNegLimitActionGet());
91
92 axis->HardwareNegLimitTriggerStateSet(ACTIVE_LOW); // Set the negative limit trigger state to ACTIVE_LOW.
93 printf("\nHardware Negative Limit TriggerState set to %i", axis->HardwareNegLimitTriggerStateGet());
94
95 axis->HardwareNegLimitDurationSet(HW_NEG_DURATION_TIME); // Set the negative limit duration to 0.01 seconds.
96 printf("\nHardware Negative Limit Duration set to %f seconds", axis->HardwareNegLimitDurationGet());
97
98 printf("\nAll Hardware Limit characteristicpp set\n");
99 }
100 catch (RsiError const& err)
101 {
102 printf("\n%s\n", err.text);
103 return -1;
104 }
105 controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
106 return 0;
107}
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
void HardwareNegLimitDurationSet(double seconds)
Set the duration required before the Hardware Negative Limit event triggers.
void HardwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Positive Limit Event triggers.
RSIAction HardwarePosLimitActionGet()
Get the action that will occur when the Hardware Positive Limit Event triggers.
void HardwarePosLimitTriggerStateSet(bool state)
sets the trigger state.
double HardwareNegLimitDurationGet()
Get the duration required before the Hardware Negative Limit event triggers.
bool HardwarePosLimitTriggerStateGet()
trigger state return.
void HardwarePosLimitDurationSet(double seconds)
Set the duration required before the Hardware Positive Limit event triggers.
bool HardwareNegLimitTriggerStateGet()
Trigger state return.
double HardwarePosLimitDurationGet()
Get the duration required before the Hardware Positive Limit event triggers.
RSIAction HardwareNegLimitActionGet()
Get the action that will occur when the Hardware Negative Limit Event triggers.
void HardwareNegLimitTriggerStateSet(bool state)
Sets the trigger state.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5643
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:796
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:107
@ RSIActionE_STOP
E-Stop - decelerate in EStopTime and leave in error state.
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 ...
static void SetupControllerForPhantoms(MotionController *controller, int axisCount, std::vector< int > axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.