APIs, concepts, guides, and more
Compensator.cs
1
45using RSI.RapidCode.dotNET; // Import our RapidCode Library.
46using NUnit.Framework;
47using System;
48
50[TestFixture]
51[Category("Software")]
52class Compensator : StaticMemoryTestBase
53 {
54 //[Test, Timeout(Constants.MAX_TEST_TIME)]
55 [Test]
56 public void Compensator1D()
57 {
60 // To use a compensator space in memory must be reserved before creating axis objects. For this sample app we will create two overlapping compensation tables.
61 controller.CompensatorCountSet(2);
62
63 // To know how much memory will be required for the compensator table you must first know your MIN, MAX, and DELTA. See our compensator topic page for more information.
64 const int MIN = 0; // The smallest value in counts on the input axis where a table will be applied to the output axis.
65 const int MAX = 200; // The largest value in counts on the input axis where a table will be applied to the output axis.
66 const int DELTA = 10; // The number of encoder counts on the input axis between values in the table.
67 const int POINTS = ((MAX - MIN) / DELTA) + 1; // The space required in memory for the table to be held. (21)
68
69 // Compensator table values use Axis COUNTS NOT user units to be applied to the output axis.
70 double[] TABLE0 = new double[POINTS] { 0, 1000, -5000, -10000, 10000, 5000, -5000, 2500, 0, 2500, 5000, 7500, 1000, 1250, 1000, 7500, 5000, 2500, 0, -2500, -1000 };
71 double[] TABLE1 = new double[POINTS] { 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, 1000, -5000, -1000, 1000, 5000, -5000, 2500, 0, -1000, 0, 0 };
72
73 // Reserve space in memory for the compensator tables.
74 controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE0.Length);
75 controller.CompensatorPointCountSet(Constants.COMP_NUM_ONE, TABLE1.Length);
76
77 controller.AxisCountSet(2);
78
79 Axis moving_axis = CreateAndReadyAxis(Constants.MAIN_AXIS_NUMBER); // Helper function to setup an axis
80 Axis follower_axis = CreateAndReadyAxis(Constants.DRIVEN_AXIS_NUMBER); // Helper function to setup an axis
81
82 // NOTE the three following values must be equal before a compensator can be configured. Otherwise an error will be thrown. See topic page for more info.
83 if (controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO) == TABLE0.Length && POINTS == TABLE0.Length)
84 {
85 // Initalize the Compensator
86 controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, moving_axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, MIN, MAX, DELTA, follower_axis, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE0);
87
88 // You can also configure multiple overlaping compensation tables. Note the first compensator remains in SINGLE mode but the second is set to ADDITIVE
89 controller.CompensatorConfigSet(Constants.COMP_NUM_ONE, moving_axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, MIN, MAX, DELTA, follower_axis, RSICompensatorOutputType.RSICompensatorOutputTypeADDITIVE, TABLE1);
90 }
92
94 // NOTE the three following values must be equal before a compensator can be configured. Otherwise an error will be thrown. See topic page for more info.
95 Assert.That(controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO), Is.EqualTo(TABLE0.Length));
96 Assert.That(TABLE0.Length, Is.EqualTo(POINTS));
97
98 //---TEST ASSERT---
99 moving_axis.PositionSet(DELTA);//We move one index into the compensation table
100 Assert.That(follower_axis.CompensationPositionGet(), Is.EqualTo(TABLE0[1] + TABLE1[1]));
101 }
102
103 [Test]
104 public void Compensator2D()
105 {
107 // Constants
108 const int X_MIN = 0;
109 const int X_MAX = 500;
110 const int X_DELTA = 100;
111 const int Y_MIN = 0;
112 const int Y_MAX = 500;
113 const int Y_DELTA = 100;
114 const int COMPENSATOR_X_POINTS = ((X_MAX - X_MIN) / X_DELTA) + 1;
115 const int COMPENSATOR_Y_POINTS = ((Y_MAX - Y_MIN) / Y_DELTA) + 1;
116 const int POINTS = (COMPENSATOR_X_POINTS) * (COMPENSATOR_Y_POINTS);
117
118 // Compensator uses Axis COUNTS NOT user units
119 double[] TABLE = new double[POINTS] {
120 0, 0, 0, 0, 0, 0,
121 100, 200, -200, 10, 300, 0,
122 100, 200, -500, 400, 500, 0,
123 0, 0, 0, 0, 0, 0,
124 -300, 300, -300, -300, -300, 0,
125 0, 0, 0, 0, 0, 0,
126 };
127
128 // To use a compensator space in memory must be reserved before creating axis objects. For this sample app we will create two overlapping compensation tables.
129 controller.CompensatorCountSet(1);
130 controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE.Length);
131
132 // Initialize Axes. (Use RapidSetup Tool to see what is your axis number)
133 controller.AxisCountSet(3);
134 Axis x = CreateAndReadyAxis(Constants.X_AXIS_NUMBER);
135 Axis y = CreateAndReadyAxis(Constants.Y_AXIS_NUMBER);
136 Axis z = CreateAndReadyAxis(Constants.Z_AXIS_NUMBER);
137
138 z.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
139
140 // Initalize the Compensator
141 controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, x, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, X_MIN, X_MAX, X_DELTA, y, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, Y_MIN, Y_MAX, Y_DELTA, z, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE);
143
144 //---TEST ASSERT---
145 // Test first row first col
146 x.PositionSet(0);
147 y.PositionSet(0);
148 Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[0]));
149 // Test second row second col
150 x.PositionSet(X_DELTA);
151 y.PositionSet(Y_DELTA);
152 Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[7]));
153 // Test Third row third col
154 x.PositionSet(X_DELTA * 2);
155 y.PositionSet(Y_DELTA * 2);
156 Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[14]));
157 }
158
159 [Test]
160 public void CompensatorSingleAxis()
161 {
162 Console.WriteLine("Start SompensatorSingleAxis");
163
165 // Constants
166 const int MIN = 10;
167 const int MAX = 210;
168 const int DELTA = 10;
169 const int POINTS = ((MAX - MIN) / DELTA) + 1; //21
170
171 // Compensator uses Axis COUNTS NOT user units
172 double[] TABLE = new double[POINTS] { 0, 2, -3, -5, -3, 2, -3, 0, 2, -3, -5, -3, 2, -3, 0, 2, -3, -5, -3, 2, -3 };
173
174 // Setup memory space for the compensator
175 controller.CompensatorCountSet(1);
176 controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE.Length);
177
178 // Initialize Axes. (Use RapidSetup Tool to see what is your axis number)
179 controller.AxisCountSet(1);
180 Axis axis = CreateAndReadyAxis(Constants.AXIS_NUMBER);
181
182 // NOTE the three following values must be equal before a compensator can be configured. Otherwise an error will be thrown. See topic page for more info.
183 if (controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO) == TABLE.Length && POINTS == TABLE.Length)
184 {
185 controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION, MIN, MAX, DELTA, axis, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE);
186
187 axis.MoveSCurve(DELTA * 2); // Note multiply by to to get to index because min=delta
188 axis.MotionDoneWait();
189 controller.SampleWait(Constants.SAMPLES);
190 }
192
194 // NOTE the three following values must be equal before a compensator can be configured. Otherwise an error will be thrown. See topic page for more info.
195 Assert.That(controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO), Is.EqualTo(TABLE.Length));
196 Assert.That(TABLE.Length, Is.EqualTo(POINTS));
197 Assert.That(axis.CompensationPositionGet(), Is.EqualTo(TABLE[1]));
198
199 Console.WriteLine("End SompensatorSingleAxis");
200 }
201 }
int32_t CompensatorPointCountGet(int32_t compensatorNumber)
Get the number of points for use with a Compensator.
void CompensatorPointCountSet(int32_t compensatorNumber, int32_t pointCount)
Set the number of points for use with a Compensator.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
void CompensatorCountSet(int32_t compensatorCount)
Set the number of Compensators available in the firmware.
void CompensatorConfigSet(int32_t compensatorNumber, int32_t firstInputAxisNumber, RSIAxisMasterType firstInputAxisType, double firstInputAxisMinimum, double firstInputAxisMaximum, double firstInputAxisDelta, int32_t secondInputAxisNumber, RSIAxisMasterType secondInputAxisType, double secondInputAxisMinimum, double secondInputAxisMaximum, double secondInputAxisDelta, int32_t outputAxisNumber, RSICompensatorOutputType outputType, const double *const table)
Configure a 2D compensator.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
RSICompensatorOutputType
Compensator output types.
Definition rsienums.h:1337
RSIAxisMasterType
Sources available to a slave Axis for electronic gearing & camming.
Definition rsienums.h:1163