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 // Print a start message to indicate that the sample app has started
21 const std::string SAMPLE_APP_NAME = "Axis Configuration";
22 SampleAppsHelper::PrintHeader(SAMPLE_APP_NAME);
23
24 /* CONSTANTS */
25 // *NOTICE* The following constants must be configured before attempting to run with hardware.
26 const int NUM_AXES = 1; // The number of axes to configure, default is 0 for this template
27 const int AXIS_INDEX = 0; // The index of the axis to configure
28
29 /* RAPIDCODE INITIALIZATION */
30
31 // Create the controller
33 MotionController *controller = MotionController::Create(&params);
34
35 // Set the exit code to an error value.
36 int exitCode = -1;
37 try // Ensure that the controller is deleted if an error occurs.
38 {
39 // Prepare the controller as defined in SampleAppsHelper.h depending on the configuration
41 SampleAppsHelper::SetupController(controller, NUM_AXES);
42
43 /* SAMPLE APP BODY */
44
45 /* SET CONTROLLER OBJECT COUNTS HERE*/
46 // Normally you would set the number of axes here, but for samples that is handled in the SampleAppsHelper::SetupController function
47 // controller->AxisCountSet(NUM_AXES);
48
49 // Get the axes
50 Axis *axis = controller->AxisGet(AXIS_INDEX);
52
53 /* Amp Fault Configuration */
54 std::cout << "Configuring Amp Fault parameters\n" << std::endl;
55
56 // Parameters
57 const double AMP_FAULT_DURATION_TIME = 1; // How long the axis must be in the trigger state to be considered an amp fault.
58 const RSIAction AMP_FAULT_ACTION = RSIAction::RSIActionABORT; // The action to take when an amp fault occurs.
59 const int AMP_FAULT_TRIGGER_STATE = 1; // The state that triggers the amp fault, active high = 1, active low = 0.
60
61 // SET
62 axis->AmpEnableSet(false); // Disable the axis
63 axis->AmpFaultDurationSet(AMP_FAULT_DURATION_TIME);
64 axis->AmpFaultActionSet(AMP_FAULT_ACTION);
65 axis->AmpFaultTriggerStateSet(AMP_FAULT_TRIGGER_STATE);
66
67 // GET
68 double durationTime = axis->AmpFaultDurationGet();
69 RSIAction action = axis->AmpFaultActionGet();
70 int triggerState = axis->AmpFaultTriggerStateGet();
71
72 std::cout << "Axis Amp Fault parameters have been set" << std::endl;
73
74 /* Hardware Limits Configuration */
75 std::cout << "Configuring Hardware Limits parameters\n" << std::endl;
76
78 // Parameters
79 const int TRIGGER_STATE = 1; // The state that triggers the positive software limit, active high = 1, active low = 0.
80 const double DURATION = 0.01; // How long the hardware limit must be in the trigger state to be considered triggered.
81 const RSIAction ACTION = RSIAction::RSIActionABORT; // The action to take when the positive hardware limit is triggered.
82
83 // SET
84 axis->HardwarePosLimitTriggerStateSet(TRIGGER_STATE);
85 axis->HardwarePosLimitDurationSet(DURATION);
86 axis->HardwarePosLimitActionSet(ACTION);
87
88 axis->HardwareNegLimitTriggerStateSet(TRIGGER_STATE);
89 axis->HardwareNegLimitDurationSet(DURATION);
90 axis->HardwareNegLimitActionSet(ACTION);
91
92 // GET
93 int posTriggerState = axis->HardwarePosLimitTriggerStateGet();
94 double posDuration = axis->HardwarePosLimitDurationGet();
95 RSIAction posAction = axis->HardwarePosLimitActionGet();
96
97 int negTriggerState = axis->HardwareNegLimitTriggerStateGet();
98 double negDuration = axis->HardwareNegLimitDurationGet();
99 RSIAction negAction = axis->HardwareNegLimitActionGet();
101
102 std::cout << "Axis Hardware Limits have been set" << std::endl;
103
104 /* Settling Configuration */
105 std::cout << "Configuring Settling parameters\n" << std::endl;
106
108 // Parameters
109 const double POSITION_TOLERANCE_FINE = 200; // Tolerance for when a move is considered complete.
110 const double POSITION_TOLERANCE_COARSE = 300; // Tolerance for when a move is considered "near" complete.
111 const double VELOCITY_TOLERANCE = 12000; // Tolerance for when a velocity move is considered complete.
112 const double SETTLING_TIME = 5; // How long the axis must be within tolerance to be considered settled.
113
114 // SET
115 axis->PositionToleranceFineSet(POSITION_TOLERANCE_FINE);
116 axis->PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE);
117 axis->VelocityToleranceSet(VELOCITY_TOLERANCE);
118 axis->SettlingTimeSet(SETTLING_TIME);
119
120 // GET
121 double posTolFine = axis->PositionToleranceFineGet();
122 double posTolCoarse = axis->PositionToleranceCoarseGet();
123 double velTol = axis->VelocityToleranceGet();
124 double setTime = axis->SettlingTimeGet();
126
127 std::cout << "Axis Settling parameters have been set" << std::endl;
128
129 /* Stop Rate Configuration */
130 std::cout << "Configuring Stop Rate parameters\n" << std::endl;
131
133 // Parameters
134 const double STOP_RATE_DEFAULT = 1.0; // Specify the default STOP rate in seconds.
135 const double ESTOP_RATE_DEFAULT = 0.05; // Specify the default ESTOP rate in seconds.
136 const double ESTOP_DECELERATION_RATE = 1000; // Specify the default ESTOP deceleration rate in seconds.
137
138 // SET
139 axis->StopTimeSet(STOP_RATE_DEFAULT);
140 axis->EStopTimeSet(ESTOP_RATE_DEFAULT);
141 axis->EStopDecelerationSet(ESTOP_DECELERATION_RATE);
142
143 // GET
144 double stopRate = axis->StopTimeGet();
145 double eStopRate = axis->EStopTimeGet();
146 double eStopDeceleration = axis->EStopDecelerationGet();
148
149 std::cout << "Axis Stop Rate parameters have been set" << std::endl;
150
151 /* User Units Configuration */
152 std::cout << "Configuring User Units parameters\n" << std::endl;
153
155 // Parameters
156 const int ENCODER_RESOLUTION_BITS = 20; // The number of bits defining the encoder resolution
157 const double USER_UNITS = std::pow(2, ENCODER_RESOLUTION_BITS); // The number of user units per revolution
158 // (2^20 = 1,048,576 user units per revolution)
159
160 // SET
161 axis->UserUnitsSet(USER_UNITS);
162
163 // GET
164 double userUnits = axis->UserUnitsGet();
166
167 std::cout << "Axis User Units have been set" << std::endl;
168
169 exitCode = 0; // Set the exit code to success.
170 }
171 catch (const std::exception &ex)
172 {
173 std::cerr << ex.what() << std::endl;
174 exitCode = -1;
175 }
176 // Clean up the controller and any other objects as needed
177 SampleAppsHelper::Cleanup(controller);
178
179 // Delete the controller as the program exits to ensure memory is deallocated in the correct order
180 controller->Delete();
181
182 // Print a message to indicate the sample app has finished and if it was successful or not
183 SampleAppsHelper::PrintFooter(SAMPLE_APP_NAME, exitCode);
184
185 return exitCode;
186}
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:5549
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:796
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:1072
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 Cleanup(MotionController *controller)
Cleanup the controller and restore the object counts to the original values.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
static void SetupController(MotionController *controller, int numAxes=0)
Setup the controller with user defined axis counts and configuration.
CreationParameters for MotionController::Create.
Definition rsi.h:857