APIs, concepts, guides, and more
MultiAxisMotion.cs
1
37using RSI.RapidCode.dotNET; // Import our RapidCode Library.
38using NUnit.Framework;
39using System;
40
41#if DOXYGEN // RSI internal documentation use only
42using RSI.RapidCode;
43#endif
44
46[TestFixture]
47[Category("Software")]
48class MultiAxisMotion : StaticMemoryTestBase
49 {
50 [Test]
51 public void MultiAxisVelocityMotion()
52 {
54 // RapidCode Objects
55 MultiAxis multi; // Declare what multi is.
56
57 // Constants
58 const int cycles = 2; // Specify how many times you want to update the velocity.
59 const int NUM_OF_AXES = 6;
60
61 controller.AxisCountSet(NUM_OF_AXES);
62 controller.MotionCountSet(NUM_OF_AXES + 1); // We will need a motion supervisor for every Axis object and MultiAxis object
63
64 int i;
65 double[] accelerations = new double[6] { 1000, 1000, 1000, 1000, 1000, 1000 }; // Specify the acceleration for all 6 axes.
66 double[] velocities = new double[6]; // Initialize the array that will contain the velocities of all 6 axes.
67 Random rnd = new Random(); // Initialize the Random object that we will use to generate random velocities.
68
69 Axis x_axis = controller.AxisGet(Constants.X_AXIS_NUMBER); // Initialize axis. (You can use RapidSetup to see what axes you are using.)
70 Axis y_axis = controller.AxisGet(Constants.Y_AXIS_NUMBER); // Initialize axis.
71 Axis z_axis = controller.AxisGet(Constants.Z_AXIS_NUMBER); // Initialize axis.
72 Axis a_axis = controller.AxisGet(Constants.A_AXIS_NUMBER); // Initialize axis.
73 Axis b_axis = controller.AxisGet(Constants.B_AXIS_NUMBER); // Initialize axis.
74 Axis c_axis = controller.AxisGet(Constants.C_AXIS_NUMBER); // Initialize axis.
75
76 HelperFunctions.CheckErrors(x_axis); // Check that the axis has been initialize correctly.
77 HelperFunctions.CheckErrors(y_axis); // Check that the axis has been initialize correctly.
78 HelperFunctions.CheckErrors(z_axis); // Check that the axis has been initialize correctly.
79 HelperFunctions.CheckErrors(a_axis); // Check that the axis has been initialize correctly.
80 HelperFunctions.CheckErrors(b_axis); // Check that the axis has been initialize correctly.
81 HelperFunctions.CheckErrors(c_axis); // Check that the axis has been initialize correctly.
82
83 multi = controller.MultiAxisGet(NUM_OF_AXES); // Configure your MultiAxis on RapidSetup (Make sure MotionCount is 1 higher than AxisCount)
84 HelperFunctions.CheckErrors(multi); // Check that multi has been initialized correctly.
85
86 multi.AxisRemoveAll(); // If there are any current axes on multi, remove them.
87
88 multi.AxisAdd(x_axis); // Add axis to your Multi-Axis controller.
89 multi.AxisAdd(y_axis); // Add axis to your Multi-Axis controller.
90 multi.AxisAdd(z_axis); // Add axis to your Multi-Axis controller.
91 multi.AxisAdd(a_axis); // Add axis to your Multi-Axis controller.
92 multi.AxisAdd(b_axis); // Add axis to your Multi-Axis controller.
93 multi.AxisAdd(c_axis); // Add axis to your Multi-Axis controller.
94
95 multi.Abort(); // If there is any motion happening, abort it.
96 multi.ClearFaults(); // Clear faults and enable all axes.
97 multi.AmpEnableSet(true); // Enable the motor.
98
99 for (i = 0; i < cycles; i++) // This loop will iterate 5 times based on the value of "cycles"
100 {
101 int random_vel1 = rnd.Next(1, 100); // random_vel1 is a number [ >= 1 and < 100 ]
102 int random_vel2 = rnd.Next(1, 100);
103 int random_vel3 = rnd.Next(1, 100);
104 int random_vel4 = rnd.Next(1, 100);
105 int random_vel5 = rnd.Next(1, 100);
106 int random_vel6 = rnd.Next(1, 100);
107
108 velocities = new double[6] {random_vel1, // Update axis's velocity.
109 random_vel2, // Update axis's velocity.
110 random_vel3, // Update axis's velocity.
111 random_vel4, // Update axis's velocity.
112 random_vel5, // Update axis's velocity.
113 random_vel6 }; // Update axis's velocity.
114
115 multi.MoveVelocity(velocities, accelerations); // Move your Multi-Axis. (this will also update the move on the fly)
116
117 System.Threading.Thread.Sleep(100); // Sleep for 100ms before iterating again.
118 }
119
120 multi.Abort(); // Stop motion on all axes.
122 }
123
124 [Test]
125 public void PointToPointMultiAxisMotion()
126 {
128 // Constants
129 const int NUM_OF_AXES = 2; // Specify the number of axes (Make sure your axis count in RapidSetup is 2!)
130
131 // Parameters
132 double[] positions1 = new double[NUM_OF_AXES] { 5, 10 }; // The first set of positions to be moved to
133 double[] positions2 = new double[NUM_OF_AXES] { 15, 15 }; // The second set of positions to be moved to
134 double[] velocities1 = new double[NUM_OF_AXES] { 1000, 1000 }; // The velocity for the two axes for the first move- Units: units/sec (driver will execute 10 rotations per second)
135 double[] velocities2 = new double[NUM_OF_AXES] { 1000, 1000 }; // The velocity for the two axes for the second move
136 double[] accelerations = new double[NUM_OF_AXES] { 500, 500 }; // The acceleration for the two axes
137 double[] decelerations = new double[NUM_OF_AXES] { 500, 500 }; // The deceleration for the two axes
138 double[] jerkPercent = new double[NUM_OF_AXES] { 50, 50 }; // The jerk percent for the two axes
139
140 controller.AxisCountSet(NUM_OF_AXES);
141 controller.MotionCountSet(NUM_OF_AXES + 1);
142
143 Axis axis0 = controller.AxisGet(Constants.X_AXIS_NUMBER); // Initialize axis0
144 Axis axis1 = controller.AxisGet(Constants.Y_AXIS_NUMBER); // Initialize axis1
145
146 HelperFunctions.CheckErrors(axis0); // [Helper Function] Check that 'axis0' has been initialized correctly
147 HelperFunctions.CheckErrors(axis1); // [Helper Function] Check that 'axis1' has been initialized correctly
148
149 // In this application, we have two Axis objects and one MultiAxis object, so three motion supervisors are required
150 MultiAxis multi = controller.MultiAxisGet(NUM_OF_AXES); // Initialize a new MultiAxis object. MultiAxisGet takes a motion supervisor number as its argument.
151 // This number is equal to the number of axes since motion supervisors are zero indexed (i.e., motion supervisors
152 // 0 and 1 are used for axis0 and axis1, so motion supervisor 2 is available for our MultiAxis object).
153
154 HelperFunctions.CheckErrors(multi); // [Helper Function] Check that 'multi' has been initialized correctly
155 controller.AxisCountSet(NUM_OF_AXES); // Set the number of axis being used. A phantom axis will be created if for any axis not on the network. You may need to refresh rapid setup to see the phantom axis.
156
157 multi.AxisRemoveAll(); // Remove all current axis if any. So we can add new ones
158
159 multi.AxisAdd(axis0); // Add axis0 to the MultiAxis object
160 multi.AxisAdd(axis1); // Add axis1 to the MultiAxis object
161
162 multi.Abort(); // If there is any motion happening, abort it
163 multi.ClearFaults(); // Clear any faults
164 multi.AmpEnableSet(true); // Enable the motor
165
166 axis0.ErrorLimitActionSet(RSIAction.RSIActionNONE); // Disable poistion error for Phantom Axes.
167 axis1.ErrorLimitActionSet(RSIAction.RSIActionNONE); // Disable poistion error for Phantom Axes.
168
169 multi.MoveSCurve(positions1, velocities1, accelerations, decelerations, jerkPercent); // Move to the positions specified in positions1 using a trapezoidal motion profile
170 multi.MotionDoneWait(); // Wait for motion to finish
171
173 Assert.That(axis0.CommandPositionGet(), Is.EqualTo(positions1[0]), "The first axis in the multi axis object should be commanded to move to the firt element of the array");
174 Assert.That(axis1.CommandPositionGet(), Is.EqualTo(positions1[1]), "The second axis in the multi axis object should be commanded to move to the second element of the array");
175
176 multi.MoveTrapezoidal(positions2, velocities2, accelerations, decelerations); // Move to the positions specified in positions2 using a SCurve motion profile
177 multi.MotionDoneWait(); // Wait for the motion to finish
178
180 Assert.That(axis0.CommandPositionGet(), Is.EqualTo(positions2[0]), "The first axis in the multi axis object should be commanded to move to the firt element of the array");
181 Assert.That(axis1.CommandPositionGet(), Is.EqualTo(positions2[1]), "The second axis in the multi axis object should be commanded to move to the second element of the array");
182
183 multi.AmpEnableSet(false); // Disable the axes
184
185 // /@[PointToPointMultiAxisMotion]
186 }
187 }
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCodeObject has any errors.
Helper Functions for checking logged creation errors, starting the network, etc.
double CommandPositionGet()
Get the current command position.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
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.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
void MoveTrapezoidal(const double *const position, const double *const vel, const double *const accel, const double *const decel)
Point-to-point trapezoidal move.
void AxisRemoveAll()
Remove all axes from a MultiAxis group.s.
void MoveSCurve(const double *const position, const double *const vel, const double *const accel, const double *const decel, const double *const jerkPct)
Point-to-point S-Curve Move.
void MoveVelocity(const double *const velocity, const double *const accel)
Velocity move.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
Definition rsi.h:10208
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.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1061