using NUnit.Framework;
using System;
class Homing : SampleAppTestBase
{
public void MasterBasedHoming()
{
axis.HardwareNegLimitActionSet(
RSIAction.RSIActionSTOP);
axis.HomeMethodSet(
RSIHomeMethod.RSIHomeMethodImprovedFALLING_HOME_NEGATIVE_START_POSITIVE_MOMENTUM);
axis.HomeVelocitySet(Constants.VELOCITY);
axis.HomeSlowVelocitySet(Constants.VELOCITY / 10);
axis.HomeAccelerationSet(Constants.ACCELERATION);
axis.HomeDecelerationSet(Constants.DECELERATION);
axis.HomeOffsetSet(0.5);
axis.Home();
if (axis.HomeStateGet() == true)
{
Console.WriteLine("Homing successful\n");
}
axis.ClearFaults();
axis.AmpEnableSet(false);
}
public void HomingWithAKDdrive()
{
axis.NetworkNode.AKDASCIICommand("HOME.AUTOMOVE 0");
axis.NetworkNode.AKDASCIICommand("DIN5.MODE 18");
axis.NetworkNode.AKDASCIICommand("DIN5.INV 1");
axis.NetworkNode.AKDASCIICommand("DIN6.MODE 19");
axis.NetworkNode.AKDASCIICommand("DIN6.INV 1");
axis.NetworkNode.AKDASCIICommand("HOME.MODE 1");
axis.NetworkNode.AKDASCIICommand("HOME.V 20");
axis.NetworkNode.AKDASCIICommand("HOME.ACC 200");
axis.NetworkNode.AKDASCIICommand("HOME.DEC 200");
axis.NetworkNode.AKDASCIICommand("HOME.DIR 0");
axis.NetworkNode.AKDASCIICommand("HOME.P 0");
axis.NetworkNode.AKDASCIICommand("HOME.DIST 0");
axis.NetworkNode.AKDASCIICommand("HOME.MAXDIST 0");
axis.NetworkNode.AKDASCIICommand("HOME.IPEAK");
axis.ErrorLimitActionSet(
RSIAction.RSIActionNONE);
axis.Abort();
axis.ClearFaults();
axis.AmpEnableSet(true);
System.Threading.Thread.Sleep(100);
axis.NetworkNode.AKDASCIICommand("HOME.MOVE");
Console.WriteLine("HOME.MOVE");
UInt16 statusWordValue;
int isHomedvalue = 0;
int axisIndex = axis.NumberGet();
while (isHomedvalue != 1)
{
statusWordValue = axis.NetworkNode.StatusWordGet(axisIndex);
isHomedvalue = statusWordValue >> 12;
}
Console.WriteLine("Axis homed.");
axis.OriginPositionSet(0.0);
axis.Abort();
axis.OperationModeSet(
RSIOperationMode.RSIOperationModeINTERPOLATED_POSITION_MODE);
axis.ErrorLimitActionSet(
RSIAction.RSIActionABORT);
}
public void HomingWithDS402drive()
{
const int AXIS_NUMBER = 0;
const int offsetIndex = 0x607C;
const int offsetSubindex = 0x0;
const int offsetByteSize = 4;
const int offsetValue = 0;
const int methodIndex = 0x6098;
const int methodSubindex = 0x0;
const int methodByteSize = 1;
const int methodValue = 24;
const int targetSpeedIndex = 0x6099;
const int targetSpeedSubindex = 0x1;
const int targetSpeedByteSize = 4;
const int targetSpeedValue = 2;
const int originSpeedIndex = 0x6099;
const int originSpeedSubindex = 0x2;
const int orignSpeedByteSize = 4;
const int originSpeedValue = 10;
const int accelerationIndex = 0x609A;
const int accelerationSubindex = 0x0;
const int accelerationByteSize = 4;
const int accelerationValue = 100;
const int CONTROL_WORD_TO_PREP_HOMING = 15;
const int CONTROL_WORD_TO_START_HOMING = 31;
const int ACCEPTABLE_DELAY_IN_MS = 20;
const int STATUS_WORD_TARGET_REACHED_BIT = 0x400;
const int STATUS_WORD_HOMING_ATTAINED_BIT = 0x1000;
const int STATUS_WORD_HOMING_ERROR_BIT = 0x2000;
MotionController controller = MotionController.CreateFromSoftware();
Axis axis = controller.AxisGet(AXIS_NUMBER);
int axisControlWordIndex = (int)axis.NetworkIndexGet(
RSINetworkIndexType.NetworkIndexTypeCONTROL_WORD_INDEX);
axis.NetworkNode.ServiceChannelWrite(offsetIndex, offsetSubindex, offsetByteSize, offsetValue);
axis.NetworkNode.ServiceChannelWrite(methodIndex, methodSubindex, methodByteSize, methodValue);
axis.NetworkNode.ServiceChannelWrite(targetSpeedIndex, targetSpeedSubindex, targetSpeedByteSize, targetSpeedValue);
axis.NetworkNode.ServiceChannelWrite(originSpeedIndex, originSpeedSubindex, orignSpeedByteSize, originSpeedValue);
axis.NetworkNode.ServiceChannelWrite(accelerationIndex, accelerationSubindex, accelerationByteSize, accelerationValue);
axis.rsiControl.NetworkOutputOverrideValueSet(axisControlWordIndex, CONTROL_WORD_TO_PREP_HOMING);
axis.rsiControl.NetworkOutputOverrideSet(axisControlWordIndex, true);
controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
axis.rsiControl.NetworkOutputOverrideValueSet(axisControlWordIndex, CONTROL_WORD_TO_START_HOMING);
controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
UInt16 statusWordValue;
bool cancelHome = false;
statusWordValue = axis.NetworkNode.StatusWordGet(AXIS_NUMBER);
while ((!cancelHome) && ((statusWordValue & STATUS_WORD_TARGET_REACHED_BIT) == 0))
{
statusWordValue = axis.NetworkNode.StatusWordGet(AXIS_NUMBER);
}
if ((statusWordValue & STATUS_WORD_HOMING_ATTAINED_BIT) == 1)
{
Console.WriteLine("Axis homed.");
}
else if ((statusWordValue & STATUS_WORD_HOMING_ERROR_BIT) == 1)
{
Console.WriteLine("Error Occured during homing.");
}
axis.AmpEnableSet(false);
axis.ClearFaults();
axis.rsiControl.NetworkOutputOverrideSet(axisControlWordIndex, false);
axis.OperationModeSet(
RSIOperationMode.RSIOperationModeCYCLIC_SYNCHRONOUS_POSITION_MODE);
}
public void CustomHome()
{
const int HOME_LIMIT_NETWORK_INDEX = 99;
const int HOME_LIMIT_SIG_BIT = 0;
const int LongTime = 15000;
var homeLimitAddress = controller.NetworkInputAddressGet(HOME_LIMIT_NETWORK_INDEX);
axis.HomeLimitCustomConfigSet(homeLimitAddress, HOME_LIMIT_SIG_BIT);
axis.Abort();
axis.ClearFaults();
axis.AmpEnableSet(true);
axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
Boolean done = false;
while (!done)
{
RSIEventType eventType = controller.InterruptWait(LongTime);
switch (eventType)
{
done = true;
break;
done = true;
break;
default:
break;
}
}
if ((controller.NetworkInputValueGet(HOME_LIMIT_NETWORK_INDEX) & HOME_LIMIT_SIG_BIT) > 0)
{
axis.HomeStateSet(true);
}
else
{
}
axis.ClearFaults();
axis.AmpEnableSet(false);
}
}