APIs, concepts, guides, and more
AxisConfiguration.cpp
1
11#include <cmath>
12
13#include "SampleAppsHelper.h" // Import our helper functions.
14#include "rsi.h" // Import our RapidCode Library.
15
16using namespace RSI::RapidCode; // Import the RapidCode namespace
17
18int main()
19{
20 const std::string SAMPLE_APP_NAME = "Axis Configuration";
21
22 // Print a start message to indicate that the sample app has started
23 SampleAppsHelper::PrintHeader(SAMPLE_APP_NAME);
24
25 /* RAPIDCODE INITIALIZATION */
26
27 // Create the controller
29 MotionController *controller = MotionController::Create(&params);
30
31 int exitCode = -1; // Set the exit code to an error value.
32 try // Ensure that the controller is deleted if an error occurs.
33 {
35
36 // Prepare the controller and axes as defined in SampleAppsHelper.h
38
39 /* SAMPLE APP BODY */
40
41 // Get the axes
42 Axis *axis = controller->AxisGet(SampleAppsConfig::AXIS_X_INDEX);
44
45 /* Amp Fault Configuration */
46 std::cout << "Configuring Amp Fault parameters\n" << std::endl;
47
48 // Parameters
49 const double AMP_FAULT_DURATION_TIME = 1; // How long the axis must be in the trigger state to be considered an amp fault.
50 const RSIAction AMP_FAULT_ACTION = RSIAction::RSIActionABORT; // The action to take when an amp fault occurs.
51 const int AMP_FAULT_TRIGGER_STATE = 1; // The state that triggers the amp fault, active high = 1, active low = 0.
52
53 // SET
54 axis->AmpEnableSet(false); // Disable the axis
55 axis->AmpFaultDurationSet(AMP_FAULT_DURATION_TIME);
56 axis->AmpFaultActionSet(AMP_FAULT_ACTION);
57 axis->AmpFaultTriggerStateSet(AMP_FAULT_TRIGGER_STATE);
58
59 // GET
60 double durationTime = axis->AmpFaultDurationGet();
61 RSIAction action = axis->AmpFaultActionGet();
62 int triggerState = axis->AmpFaultTriggerStateGet();
63
64 std::cout << "Axis Amp Fault parameters have been set" << std::endl;
65
66 /* Hardware Limits Configuration */
67 std::cout << "Configuring Hardware Limits parameters\n" << std::endl;
68
70 // Parameters
71 const int TRIGGER_STATE = 1; // The state that triggers the positive software limit, active high = 1, active low = 0.
72 const double DURATION = 0.01; // How long the hardware limit must be in the trigger state to be considered triggered.
73 const RSIAction ACTION = RSIAction::RSIActionABORT; // The action to take when the positive hardware limit is triggered.
74
75 // SET
76 axis->HardwarePosLimitTriggerStateSet(TRIGGER_STATE);
77 axis->HardwarePosLimitDurationSet(DURATION);
78 axis->HardwarePosLimitActionSet(ACTION);
79
80 axis->HardwareNegLimitTriggerStateSet(TRIGGER_STATE);
81 axis->HardwareNegLimitDurationSet(DURATION);
82 axis->HardwareNegLimitActionSet(ACTION);
83
84 // GET
85 int posTriggerState = axis->HardwarePosLimitTriggerStateGet();
86 double posDuration = axis->HardwarePosLimitDurationGet();
87 RSIAction posAction = axis->HardwarePosLimitActionGet();
88
89 int negTriggerState = axis->HardwareNegLimitTriggerStateGet();
90 double negDuration = axis->HardwareNegLimitDurationGet();
91 RSIAction negAction = axis->HardwareNegLimitActionGet();
93
94 std::cout << "Axis Hardware Limits have been set" << std::endl;
95
96 /* Settling Configuration */
97 std::cout << "Configuring Settling parameters\n" << std::endl;
98
100 // Parameters
101 const double POSITION_TOLERANCE_FINE = 200; // Tolerance for when a move is considered complete.
102 const double POSITION_TOLERANCE_COARSE = 300; // Tolerance for when a move is considered "near" complete.
103 const double VELOCITY_TOLERANCE = 12000; // Tolerance for when a velocity move is considered complete.
104 const double SETTLING_TIME = 5; // How long the axis must be within tolerance to be considered settled.
105
106 // SET
107 axis->PositionToleranceFineSet(POSITION_TOLERANCE_FINE);
108 axis->PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE);
109 axis->VelocityToleranceSet(VELOCITY_TOLERANCE);
110 axis->SettlingTimeSet(SETTLING_TIME);
111
112 // GET
113 double posTolFine = axis->PositionToleranceFineGet();
114 double posTolCoarse = axis->PositionToleranceCoarseGet();
115 double velTol = axis->VelocityToleranceGet();
116 double setTime = axis->SettlingTimeGet();
118
119 std::cout << "Axis Settling parameters have been set" << std::endl;
120
121 /* Stop Rate Configuration */
122 std::cout << "Configuring Stop Rate parameters\n" << std::endl;
123
125 // Parameters
126 const double STOP_RATE_DEFAULT = 1.0; // Specify the default STOP rate in seconds.
127 const double ESTOP_RATE_DEFAULT = 0.05; // Specify the default ESTOP rate in seconds.
128 const double ESTOP_DECELERATION_RATE = 1000; // Specify the default ESTOP deceleration rate in seconds.
129
130 // SET
131 axis->StopTimeSet(STOP_RATE_DEFAULT);
132 axis->EStopTimeSet(ESTOP_RATE_DEFAULT);
133 axis->EStopDecelerationSet(ESTOP_DECELERATION_RATE);
134
135 // GET
136 double stopRate = axis->StopTimeGet();
137 double eStopRate = axis->EStopTimeGet();
138 double eStopDeceleration = axis->EStopDecelerationGet();
140
141 std::cout << "Axis Stop Rate parameters have been set" << std::endl;
142
143 /* User Units Configuration */
144 std::cout << "Configuring User Units parameters\n" << std::endl;
145
147 // Parameters
148 const int ENCODER_RESOLUTION_BITS = 20; // The number of bits defining the encoder resolution
149 const double USER_UNITS = std::pow(2, ENCODER_RESOLUTION_BITS); // The number of user units per revolution
150 // (2^20 = 1,048,576 user units per revolution)
151
152 // SET
153 axis->UserUnitsSet(USER_UNITS);
154
155 // GET
156 double userUnits = axis->UserUnitsGet();
158
159 std::cout << "Axis User Units have been set" << std::endl;
160
161 exitCode = 0; // Set the exit code to success.
162 }
163 catch (const std::exception &ex)
164 {
165 std::cerr << ex.what() << std::endl;
166 exitCode = -1;
167 }
168 // Delete the controller as the program exits to ensure memory is deallocated in the correct order
169 controller->Delete();
170
171 // Print a message to indicate the sample app has finished and if it was successful or not
172 SampleAppsHelper::PrintFooter(SAMPLE_APP_NAME, exitCode);
173
174 return exitCode;
175}
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
RSIAction AmpFaultActionGet()
Get the Amp Fault action.
double SettlingTimeGet()
Get the Settling time.
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.
void PositionToleranceCoarseSet(double tolerance)
Set the Coarse Position Tolerance for Axis settling.
double UserUnitsGet()
Get the number of counts per User Unit.
double PositionToleranceFineGet()
Get the Fine Position Tolerance for axis settling.
RSIAction HardwarePosLimitActionGet()
Get the action that will occur when the Hardware Positive Limit Event triggers.
void HardwarePosLimitTriggerStateSet(bool state)
sets the trigger state.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void AmpFaultActionSet(RSIAction action)
Set the Amp Fault action.
void AmpFaultTriggerStateSet(bool state)
Set the trigger state of the Amp Fault input.
void PositionToleranceFineSet(double tolerance)
Set the Fine Position Tolerance for Axis settling.
double AmpFaultDurationGet()
Get the duration required before the Amp Fault event triggers.
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.
void VelocityToleranceSet(double tolerance)
Set the Velocity Tolerance used for settling.
double PositionToleranceCoarseGet()
Get the Coarse Position Tolerance for axis settling.
double EStopDecelerationGet()
Get the deceleration rate for an E-Stop, Modify Event.
bool AmpFaultTriggerStateGet()
Get the Amp Fault trigger state.
double VelocityToleranceGet()
Get the velocity tolerance used for settling.
void EStopDecelerationSet(double decel)
Set the deceleration rate for an E-Stop, Modify Event.
bool HardwareNegLimitTriggerStateGet()
Trigger state return.
double HardwarePosLimitDurationGet()
Get the duration required before the Hardware Positive Limit event triggers.
void AmpFaultDurationSet(double seconds)
Set the duration required before the Amp Fault 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.
void SettlingTimeSet(double time)
Set the settling time.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5513
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * Create()
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:794
void AmpEnableSet(bool enable)
Enable all amplifiers.
void StopTimeSet(double seconds)
Set the deceleration time for a Stop Event.
double EStopTimeGet()
Get E-Stop Event deceleration time.
void EStopTimeSet(double seconds)
Set the deceleration time for an E-Stop Event.
double StopTimeGet()
Get Stop Event deceleration time.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1061
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 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 SetupController(MotionController *controller)
Setup the controller with user defined axis counts and configuration.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
CreationParameters for MotionController::Create.
Definition rsi.h:855
static constexpr int AXIS_X_INDEX
Index of the first axis to use in the sample apps.