CaptureAndMove.cs
Capture a position from input, then move some offset.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using RSI.RapidCode.SynqNet.dotNET;
using RSI.RapidCode.SynqNet.dotNET.Enums;
namespace SampleApplications
{
[TestFixture]
public class CaptureAndMove
{
const double VELOCITY = 1000.0;
const double ACCEL = 10000.0;
const double JERK_PCT = 50.0;
const double INITIAL_TARGET = 5000;
const double TARGET_OFFSET = 400;
const int A_FEW_MILLISECONDS = 7;
MotionController controller;
Axis axis;
private void SetupDefaults()
{
axis.DefaultVelocitySet(VELOCITY);
axis.DefaultAccelerationSet(ACCEL);
axis.DefaultDecelerationSet(ACCEL);
axis.DefaultJerkPercentSet(JERK_PCT);
}
[Test]
public void Main()
{
try
{
controller = MotionController.Create();
axis = controller.AxisGet(0);
SetupDefaults();
axis.Abort();
axis.PositionSet(0);
axis.ClearFaults();
axis.AmpEnableSet(true);
axis.CaptureConfigSet(RSICaptureType.RSICaptureTypeTIME,
RSICaptureSource.RSICaptureSourceINDEX,
RSICaptureEdge.RSICaptureEdgeEITHER,
axis.NumberGet(),
RSIMotorEncoder.RSIMotorEncoderPRIMARY, false);
axis.CaptureArm(true);
axis.MoveSCurve(INITIAL_TARGET);
while (axis.CaptureStateGet() != RSICaptureState.RSICaptureStateCAPTURED)
{
controller.OS.Sleep(A_FEW_MILLISECONDS);
}
double capturedPosition = (axis.CapturePositionGet() - axis.OriginPositionGet());
Console.WriteLine("Captured Position: " + capturedPosition);
double targetPosition = capturedPosition + TARGET_OFFSET;
Console.WriteLine("Adjusting move to: " + targetPosition);
axis.MoveSCurve(targetPosition);
}
catch (RsiError e)
{
Console.WriteLine(e.Message);
}
}
}
}