The RMP Motion Controller APIs
PathMotion.cpp
1
23#include <iostream>
24#include <fstream>
25
26#include "rsi.h" // Import our RapidCode Library.
27#include "HelperFunctionsCpp.h" // Import our SampleApp helper functions.
28#include "SampleApps.h"
29
30using namespace RSI::RapidCode;
31
33int PathMotion::Run()
34{
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 = (2);
40 const int AXIS_X = 0;
41 const int AXIS_Y = 1;
42
43 const double USER_UNITS = 1048576;
44
45 // Default file path for recording the path followed by the axes
46 const char* const PATH_MOTION_FILEPATH = "PathMotion.csv";
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 /* SAMPLE APP BODY */
52
53 Axis* axisX;
54 Axis* axisY;
55 MultiAxis* multiAxisXY;
56
57 double running_x = 0;
58 double running_y = 0;
59
60 double line_A[2] = { running_x, running_y };
61 running_x += -0.5;
62 double line_B[2] = { running_x, running_y };
63 running_y += -0.5;
64 double line_C[2] = { running_x, running_y };
65
66 //curve down
67 running_y += (-0.25);
68 double arc_center_A[2] = { running_x,running_y };
69 running_x += (0.25);
70
71 //curve left
72 running_x += -0.25;
73 double arc_center_B[2] = { running_x,running_y };
74 running_y += -0.25;
75
76 //curve up
77 running_y += 0.25;
78 double arc_center_C[2] = { running_x,running_y };
79 running_x += -0.25;
80
81 //curve right
82 running_x += 0.25;
83 double arc_center_D[2] = { running_x,running_y };
84 running_y += 0.25;
85
86 running_x += -0.5;
87 running_y += 0.5;
88 double line_D[2] = { running_x, running_y };
89
90 // Create and initialize RsiController class
93
94 // Setup the controller for the appropriate hardware configuration.
95 if (USE_HARDWARE)
96 {
98 }
99 else
100 {
101 HelperFunctionsCpp::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_X, AXIS_Y });
102 }
103
104 try
105 {
106 // enable one MotionSupervisor for the MultiAxis
107 controller->MotionCountSet(controller->AxisCountGet() + 1);
108
109 // Get Axis X and Y respectively.
110 Axis* axisX = controller->AxisGet(AXIS_X);
112 axisX->PositionSet(0);
113 axisX->HomeMethodSet(RSIHomeMethod::RSIHomeMethodCURRENT_POSITION);
114 axisX->ErrorLimitActionSet(RSIAction::RSIActionNONE);
118 axisX->UserUnitsSet(USER_UNITS);
119 axisX->Abort();
120
121 Axis* axisY = controller->AxisGet(AXIS_Y);
123 axisY->PositionSet(0);
124 axisY->HomeMethodSet(RSIHomeMethod::RSIHomeMethodCURRENT_POSITION);
125 axisY->ErrorLimitActionSet(RSIAction::RSIActionNONE);
129 axisY->UserUnitsSet(USER_UNITS);
130 axisY->Abort();
131
132 // Initialize a MultiAxis, using the last MotionSupervisor.
133 MultiAxis* multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
135 multiAxisXY->AxisAdd(axisX);
136 multiAxisXY->AxisAdd(axisY);
137
138 // make sure all axes are enabled and ready
139 multiAxisXY->Abort();
140 multiAxisXY->ClearFaults();
141 multiAxisXY->AmpEnableSet(true);
142
143 axisX->Home();
144 axisY->Home();
145
146 multiAxisXY->AmpEnableSet(false);
147
148 // set the trajectory info
149 multiAxisXY->VectorVelocitySet(1.0 * USER_UNITS);
150 multiAxisXY->VectorAccelerationSet(10.0 * USER_UNITS);
151 multiAxisXY->VectorDecelerationSet(10.0 * USER_UNITS);
152
153 // start path list
154 double start_positions[2] = { axisX->CommandPositionGet(),axisY->CommandPositionGet() };
155 multiAxisXY->PathListStart(start_positions);
156
157 multiAxisXY->ClearFaults();
158
159 // turn on blending (smooth corners)
160 multiAxisXY->PathBlendSet(true);
161
162 // Lines and arcs
163 multiAxisXY->PathLineAdd(line_A);
164 multiAxisXY->PathLineAdd(line_B);
165 multiAxisXY->PathLineAdd(line_C);
166 multiAxisXY->PathArcAdd(arc_center_A, -90.0);
167 multiAxisXY->PathArcAdd(arc_center_B, -90.0);
168 multiAxisXY->PathArcAdd(arc_center_C, -90.0);
169 multiAxisXY->PathArcAdd(arc_center_D, -90.0);
170 multiAxisXY->PathLineAdd(line_D);
171
172 // end path list
173 multiAxisXY->PathListEnd();
174
175 // make sure all axes are enabled and ready
176 multiAxisXY->ClearFaults();
177 multiAxisXY->AmpEnableSet(true);
178 // execute the motion
179 multiAxisXY->PathMotionStart();
180
181 // log positions
182 std::ofstream myfile;
183 myfile.open(PATH_MOTION_FILEPATH);
184 myfile << "samples,x,y,\n";
185
186 while (!multiAxisXY->MotionDoneGet()) {
187
188 myfile << controller->SampleCounterGet() << "," << axisX->CommandPositionGet() << "," << axisY->CommandPositionGet() << "\n";
189 controller->SampleWait(10);
190 }
191 // wait for motion to complete
192 multiAxisXY->MotionDoneWait();
193 multiAxisXY->AmpEnableSet(false);
194 myfile.close();
195 printf("\n%s\n", PATH_MOTION_FILEPATH);
196 }
197 catch (RsiError const& err)
198 {
199 printf("\n%s\n", err.text);
200 return -1;
201 }
202 controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
203 return 0;
204}
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.
double CommandPositionGet()
Get the current command position.
void AmpDisableActionSet(RSIMotorDisableAction action)
Set the Amp Disable action.
void SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void Home()
Execute the homing routine.
void HomeMethodSet(RSIHomeMethod method)
Set the method to be used for homing.
void PositionSet(double position)
Set the Command and Actual positions.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5664
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
int32_t SampleCounterGet()
Get the current value of the controller's processor's sample counter.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
int32_t AxisCountGet()
Get the number of axes processing.
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:762
void PathListStart(const double *const startPosition)
Start a line and arc point list for path motion.
void PathMotionStart()
Start the path motion.
void PathArcAdd(const double *const center, double angle)
Add an arc segment to the path.
void VectorDecelerationSet(double deceleration)
Set the vector deceleration.
void PathLineAdd(const double *const position)
Add a line segment to the path.
void PathBlendSet(bool blend)
Set the blending attribute.
void VectorAccelerationSet(double acceleration)
Set the vector acceleration.
void PathListEnd()
End a line and arc point list for path motion.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
void VectorVelocitySet(double velocity)
Set the vector velocity.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
Definition rsi.h:10564
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
bool MotionDoneGet()
Check to see if motion is done and settled.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:105
@ RSIMotorDisableActionNONE
No action taken when disabled.
@ RSIActionNONE
None - do not perform any action.