using NUnit.Framework;
using System;
[TestFixture]
[Category("Software")]
class Compensator : StaticMemoryTestBase
{
[Test]
public void Compensator1D()
{
controller.CompensatorCountSet(2);
const int MIN = 0;
const int MAX = 200;
const int DELTA = 10;
const int POINTS = ((MAX - MIN) / DELTA) + 1;
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 };
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 };
controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE0.Length);
controller.CompensatorPointCountSet(Constants.COMP_NUM_ONE, TABLE1.Length);
controller.AxisCountSet(2);
Axis moving_axis = CreateAndReadyAxis(Constants.MAIN_AXIS_NUMBER);
Axis follower_axis = CreateAndReadyAxis(Constants.DRIVEN_AXIS_NUMBER);
if (controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO) == TABLE0.Length && POINTS == TABLE0.Length)
{
controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, moving_axis,
RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, MIN, MAX, DELTA, follower_axis,
RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE0);
controller.CompensatorConfigSet(Constants.COMP_NUM_ONE, moving_axis,
RSIAxisMasterType.RSIAxisMasterTypeAXIS_ACTUAL_POSITION, MIN, MAX, DELTA, follower_axis,
RSICompensatorOutputType.RSICompensatorOutputTypeADDITIVE, TABLE1);
}
Assert.That(controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO), Is.EqualTo(TABLE0.Length));
Assert.That(POINTS, Is.EqualTo(TABLE0.Length));
moving_axis.PositionSet(DELTA);
Assert.That(follower_axis.CompensationPositionGet(), Is.EqualTo(TABLE0[1] + TABLE1[1]));
}
[Test]
public void Compensator2D()
{
const int X_MIN = 0;
const int X_MAX = 500;
const int X_DELTA = 100;
const int Y_MIN = 0;
const int Y_MAX = 500;
const int Y_DELTA = 100;
const int COMPENSATOR_X_POINTS = ((X_MAX - X_MIN) / X_DELTA) + 1;
const int COMPENSATOR_Y_POINTS = ((Y_MAX - Y_MIN) / Y_DELTA) + 1;
const int POINTS = (COMPENSATOR_X_POINTS) * (COMPENSATOR_Y_POINTS);
double[] TABLE = new double[POINTS] {
0, 0, 0, 0, 0, 0,
100, 200, -200, 10, 300, 0,
100, 200, -500, 400, 500, 0,
0, 0, 0, 0, 0, 0,
-300, 300, -300, -300, -300, 0,
0, 0, 0, 0, 0, 0,
};
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE.Length);
controller.AxisCountSet(3);
Axis x = CreateAndReadyAxis(Constants.X_AXIS_NUMBER);
Axis y = CreateAndReadyAxis(Constants.Y_AXIS_NUMBER);
Axis z = CreateAndReadyAxis(Constants.Z_AXIS_NUMBER);
z.ErrorLimitTriggerValueSet(1);
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);
x.PositionSet(0);
y.PositionSet(0);
Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[0]));
x.PositionSet(X_DELTA);
y.PositionSet(Y_DELTA);
Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[7]));
x.PositionSet(X_DELTA * 2);
y.PositionSet(Y_DELTA * 2);
Assert.That(z.CompensationPositionGet(), Is.EqualTo(TABLE[14]));
}
[Test]
public void CompensatorSingleAxis()
{
Console.WriteLine("Start SompensatorSingleAxis");
const int MIN = 10;
const int MAX = 210;
const int DELTA = 10;
const int POINTS = ((MAX - MIN) / DELTA) + 1;
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 };
controller.CompensatorCountSet(1);
controller.CompensatorPointCountSet(Constants.COMP_NUM_ZERO, TABLE.Length);
controller.AxisCountSet(1);
Axis axis = CreateAndReadyAxis(Constants.AXIS_NUMBER);
if (controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO) == TABLE.Length && POINTS == TABLE.Length)
{
controller.CompensatorConfigSet(Constants.COMP_NUM_ZERO, axis,
RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMAND_POSITION, MIN, MAX, DELTA, axis,
RSICompensatorOutputType.RSICompensatorOutputTypeSINGLE, TABLE);
axis.MoveSCurve(DELTA * 2);
axis.MotionDoneWait();
controller.SampleWait(Constants.SAMPLES);
}
Assert.That(controller.CompensatorPointCountGet(Constants.COMP_NUM_ZERO), Is.EqualTo(TABLE.Length));
Assert.That(POINTS, Is.EqualTo(TABLE.Length));
Assert.That(axis.CompensationPositionGet(), Is.EqualTo(TABLE[1]));
Console.WriteLine("End SompensatorSingleAxis");
}
}