The RMP Motion Controller APIs
Compensator.cs
1
40using RSI.RapidCode.dotNET; // Import our RapidCode Library.
41using NUnit.Framework;
42using System;
43
45[TestFixture]
46[Category("Software")]
47class Compensator : StaticMemoryTestBase
48 {
49 //[Test, Timeout(Constants.MAX_TEST_TIME)]
50 [Test]
51 public void Compensator1D()
52 {
55 // 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.
56 controller.CompensatorCountSet(2);
57
58 // 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.
59 const int MIN = 0; // The smallest value in counts on the input axis where a table will be applied to the output axis.
60 const int MAX = 200; // The largest value in counts on the input axis where a table will be applied to the output axis.
61 const int DELTA = 10; // The number of encoder counts on the input axis between values in the table.
62 const int POINTS = ((MAX - MIN) / DELTA) + 1; // The space required in memory for the table to be held. (21)
63
64 // Compensator table values use Axis COUNTS NOT user units to be applied to the output axis.
65 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 };
66 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 };
67
68 // Reserve space in memory for the compensator tables.
69 controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE0.Length);
70 controller.CompensatorPointCountSet(Constants.COMP_NUM_ONE, TABLE1.Length);
71
72 controller.AxisCountSet(2);
73
74 Axis moving_axis = CreateAndReadyAxis(Constants.MAIN_AXIS_NUMBER); // Helper function to setup an axis
75 Axis follower_axis = CreateAndReadyAxis(Constants.DRIVEN_AXIS_NUMBER); // Helper function to setup an axis
76
77 // 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.
78 if (controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO) == TABLE0.Length && POINTS == TABLE0.Length)
79 {
80 // Initalize the Compensator
81 controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, moving_axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, MIN, MAX, DELTA, follower_axis, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE0);
82
83 // You can also configure multiple overlaping compensation tables. Note the first compensator remains in SINGLE mode but the second is set to ADDITIVE
84 controller.CompensatorConfigSet(Constants.COMP_NUM_ONE, moving_axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, MIN, MAX, DELTA, follower_axis, RSICompensatorOutputType.RSICompensatorOutputTypeADDITIVE, TABLE1);
85 }
87
89 // 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.
90 Assert.That(controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO), Is.EqualTo(TABLE0.Length));
91 Assert.That(POINTS, Is.EqualTo(TABLE0.Length));
92
93 //---TEST ASSERT---
94 moving_axis.PositionSet(DELTA);//We move one index into the compensation table
95 Assert.That(follower_axis.CompensationPositionGet(), Is.EqualTo(TABLE0[1] + TABLE1[1]));
96 }
97
98 [Test]
99 public void Compensator2D()
100 {
102 // Constants
103 const int X_MIN = 0;
104 const int X_MAX = 500;
105 const int X_DELTA = 100;
106 const int Y_MIN = 0;
107 const int Y_MAX = 500;
108 const int Y_DELTA = 100;
109 const int COMPENSATOR_X_POINTS = ((X_MAX - X_MIN) / X_DELTA) + 1;
110 const int COMPENSATOR_Y_POINTS = ((Y_MAX - Y_MIN) / Y_DELTA) + 1;
111 const int POINTS = (COMPENSATOR_X_POINTS) * (COMPENSATOR_Y_POINTS);
112
113 // Compensator uses Axis COUNTS NOT user units
114 double[] TABLE = new double[POINTS] {
115 0, 0, 0, 0, 0, 0,
116 100, 200, -200, 10, 300, 0,
117 100, 200, -500, 400, 500, 0,
118 0, 0, 0, 0, 0, 0,
119 -300, 300, -300, -300, -300, 0,
120 0, 0, 0, 0, 0, 0,
121 };
122
123 // 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.
124 controller.CompensatorCountSet(1);
125 controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE.Length);
126
127 // Initialize Axes. (Use RapidSetup Tool to see what is your axis number)
128 controller.AxisCountSet(3);
129 Axis x = CreateAndReadyAxis(Constants.X_AXIS_NUMBER);
130 Axis y = CreateAndReadyAxis(Constants.Y_AXIS_NUMBER);
131 Axis z = CreateAndReadyAxis(Constants.Z_AXIS_NUMBER);
132
133 z.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
134
135 // Initalize the Compensator
136 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);
138
139 //---TEST ASSERT---
140 // Test first row first col
141 x.PositionSet(0);
142 y.PositionSet(0);
143 Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[0]));
144 // Test second row second col
145 x.PositionSet(X_DELTA);
146 y.PositionSet(Y_DELTA);
147 Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[7]));
148 // Test Third row third col
149 x.PositionSet(X_DELTA * 2);
150 y.PositionSet(Y_DELTA * 2);
151 Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[14]));
152 }
153
154 [Test]
155 public void CompensatorSingleAxis()
156 {
157 Console.WriteLine("Start SompensatorSingleAxis");
158
160 // Constants
161 const int MIN = 10;
162 const int MAX = 210;
163 const int DELTA = 10;
164 const int POINTS = ((MAX - MIN) / DELTA) + 1; //21
165
166 // Compensator uses Axis COUNTS NOT user units
167 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 };
168
169 // Setup memory space for the compensator
170 controller.CompensatorCountSet(1);
171 controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE.Length);
172
173 // Initialize Axes. (Use RapidSetup Tool to see what is your axis number)
174 controller.AxisCountSet(1);
175 Axis axis = CreateAndReadyAxis(Constants.AXIS_NUMBER);
176
177 // 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.
178 if (controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO) == TABLE.Length && POINTS == TABLE.Length)
179 {
180 controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, axis, RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION, MIN, MAX, DELTA, axis, RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE);
181
182 axis.MoveSCurve(DELTA * 2); // Note multiply by to to get to index because min=delta
183 axis.MotionDoneWait();
184 controller.SampleWait(Constants.SAMPLES);
185 }
187
189 // 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.
190 Assert.That(controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO), Is.EqualTo(TABLE.Length));
191 Assert.That(POINTS, Is.EqualTo(TABLE.Length));
192 Assert.That(axis.CompensationPositionGet(), Is.EqualTo(TABLE[1]));
193
194 Console.WriteLine("End SompensatorSingleAxis");
195 }
196 }
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:1328
RSIAxisMasterType
Sources available to a slave Axis for electronic gearing & camming.
Definition rsienums.h:1154