APIs, concepts, guides, and more
Axis: Homing

Examples of various ways to home a drive.

Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.


📜 Hardware Limits
Learn how to get and set hardware limits.

const bool ACTIVE_HIGH = true; // Constant for active high.
const bool ACTIVE_LOW = false; // Constant for active low.
const double HW_POS_DURATION_TIME = 0.01; // Positive limit duration. (in seconds)
const double HW_NEG_DURATION_TIME = 0.01; // Negative limit duration. (in seconds)
// SET (Hardware POSITIVE (+) Limit characteristics)
axis.HardwarePosLimitActionSet(RSIAction.RSIActionE_STOP); // Set the positive limit action to E_STOP.
axis.HardwarePosLimitTriggerStateSet(ACTIVE_HIGH); // Set the positive limit trigger state to ACTIVE_HIGH.
axis.HardwarePosLimitDurationSet(HW_POS_DURATION_TIME); // Set the positive limit duration to 0.01 seconds.
// GET
var hPosLimAct = axis.HardwarePosLimitActionGet();
var hPosLimTrigState = axis.HardwarePosLimitTriggerStateGet();
var hPosLimDur = axis.HardwarePosLimitDurationGet();
// SET (Hardware NEGATIVE (-) Limit charateristics)
axis.HardwareNegLimitActionSet(RSIAction.RSIActionE_STOP); // Set the negative limit action to E_STOP.
axis.HardwareNegLimitTriggerStateSet(ACTIVE_LOW); // Set the negative limit trigger state to ACTIVE_LOW.
axis.HardwareNegLimitDurationSet(HW_NEG_DURATION_TIME); // Set the negative limit duration to 0.01 seconds.
// GET
var hNegLimAct = axis.HardwareNegLimitActionGet();
var hNegLimTrigState = axis.HardwareNegLimitTriggerStateGet();
var hNegLimDur = axis.HardwareNegLimitDurationGet();

Learn more in the concept page.


📜 Master-Based Homing
This sample code performs a simple homing. Diagrams of the homing routines are available in our topic page.

axis.HardwareNegLimitActionSet(RSIAction.RSIActionSTOP); // Neg Limit action set to STOP.
axis.HomeMethodSet(RSIHomeMethod.RSIHomeMethodImprovedFALLING_HOME_NEGATIVE_START_POSITIVE_MOMENTUM); // Set the method to be used for homing.
axis.HomeVelocitySet(Constants.VELOCITY); // Set the home velocity.
axis.HomeSlowVelocitySet(Constants.VELOCITY / 10); // Set the slow home velocity. (used for final move, if necessary)
axis.HomeAccelerationSet(Constants.ACCELERATION); // Set the acceleration used for homing.
axis.HomeDecelerationSet(Constants.DECELERATION); // Set the deceleration used for homing.
axis.HomeOffsetSet(0.5); // HomeOffsetSet sets the position offset from the home (zero) position.
axis.Home(); // Execute the homing routine.
if (axis.HomeStateGet() == true) // HomeStateGet returns true if the Axis is homed.
{
Console.WriteLine("Homing successful\n");
}
axis.ClearFaults(); // Clear faults created by homing.
axis.AmpEnableSet(false); // Disable the motor.

Learn more in the concept page.


📜 AKD Drive Homing
This sample code performs a simple homing with a Kollmorgen AKD drive. Drive based homing is one of many methods that exist to home a servo motor. RSI encourages this homing method over all others because it avoids network latencies. Since the AKD drive does not follow the DS402 standard completely, we created this sample application to help you home your servo motor with an AKD drive. This sample application is meant to be used by AKD drives only.

// 1. READY DRIVE
axis.OperationModeSet(RSIOperationMode.RSIOperationModeHOMING_MODE); // Mode of Operation set to Homing Mode.
axis.NetworkNode.AKDASCIICommand("DRV.OPMODE 2"); // Sets the drive operation mode (0 - current | 1 = velocity | 2 = position).
axis.NetworkNode.AKDASCIICommand("HOME.AUTOMOVE 0"); // 0 = Disabled | 1 = Homing starts when drive is enabled.
// Make sure you know your motor's position, velocity, and acceleration units before you send any values.
// 2. SET YOUR LIMIT SWITCHES
axis.NetworkNode.AKDASCIICommand("DIN5.MODE 18"); // Sets the digital input modes. - DI5 is now our Positive Limit Switch.
axis.NetworkNode.AKDASCIICommand("DIN5.INV 1"); // Sets the indicated polarity of a digital input mode. - DI5 is now active when Low.
axis.NetworkNode.AKDASCIICommand("DIN6.MODE 19"); // Sets the digital input modes. - DI6 is now our Negative Limit Switch.
axis.NetworkNode.AKDASCIICommand("DIN6.INV 1"); // Sets the indicated polarity of a digital input mode. - DI6 is now active when Low.
// 3. CONFIGURE DRIVE HOMING PARAMETERS
axis.NetworkNode.AKDASCIICommand("HOME.MODE 1"); // Selects the homing method. MODE1 = Find limit input
axis.NetworkNode.AKDASCIICommand("HOME.V 20");
axis.NetworkNode.AKDASCIICommand("HOME.ACC 200");
axis.NetworkNode.AKDASCIICommand("HOME.DEC 200");
axis.NetworkNode.AKDASCIICommand("HOME.DIR 0"); // Sets homing direction (0 = negative | 1 = positive)
axis.NetworkNode.AKDASCIICommand("HOME.P 0");
axis.NetworkNode.AKDASCIICommand("HOME.DIST 0");
axis.NetworkNode.AKDASCIICommand("HOME.MAXDIST 0");
axis.NetworkNode.AKDASCIICommand("HOME.IPEAK");
// 4. READY AXIS
axis.ErrorLimitActionSet(RSIAction.RSIActionNONE); //Set the action to none so we don't get a position error while the drive is in control.
axis.Abort(); // Disable axis.
axis.ClearFaults(); // Clear any faults.
axis.AmpEnableSet(true); // Enable the axis.
System.Threading.Thread.Sleep(100); // Allow time for amp enable
// 5. START HOMING
axis.NetworkNode.AKDASCIICommand("HOME.MOVE"); // Starts a homing procedure; active in opmode 2 (position) only.
Console.WriteLine("HOME.MOVE");
// 6. CHECK IF HOMING IS DONE
UInt16 statusWordValue;
int isHomedvalue = 0;
int axisIndex = axis.NumberGet();
while (isHomedvalue != 1) // When isHomedValue = 1, homing has finished.
{
statusWordValue = axis.NetworkNode.StatusWordGet(axisIndex);
isHomedvalue = statusWordValue >> 12; // Get the 12th bit only. This bit tells us homing is done when it goes HIGH.
}
Console.WriteLine("Axis homed.");
// 7. CLEAN UP
axis.OriginPositionSet(0.0);//Set the origin to 0, otherwise repeated use will not result in Rapidcode reporting 0 at the found home position.
axis.Abort(); // Disable the axis.
axis.OperationModeSet(RSIOperationMode.RSIOperationModeINTERPOLATED_POSITION_MODE); // Mode of Operation Restore
axis.ErrorLimitActionSet(RSIAction.RSIActionABORT);// Restore the position error action to whatever you want it to be.

Learn more in the concept page.


📜 DS402 Drive Homing
This sample code performs a simple homing with assuming the drive follows the DS402 Standard. Drive based homing is one of many methods that exist to home a servo motor. RSI encourages this homing method over all others because it avoids network latencies. Many drives follow the DS402 standard. Therefore, we have created a sample app to help you home your servo motor with your DS402 drive.

// Constants
const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
// Homing Offset.
const int offsetIndex = 0x607C;
const int offsetSubindex = 0x0;
const int offsetByteSize = 4;
const int offsetValue = 0;
// Home Method
const int methodIndex = 0x6098;
const int methodSubindex = 0x0;
const int methodByteSize = 1;
const int methodValue = 24;
// Speed To Switch
const int targetSpeedIndex = 0x6099;
const int targetSpeedSubindex = 0x1;
const int targetSpeedByteSize = 4;
const int targetSpeedValue = 2;
// Speed to Zero
const int originSpeedIndex = 0x6099;
const int originSpeedSubindex = 0x2;
const int orignSpeedByteSize = 4;
const int originSpeedValue = 10;
// Homing Acceleration
const int accelerationIndex = 0x609A;
const int accelerationSubindex = 0x0;
const int accelerationByteSize = 4;
const int accelerationValue = 100;
//Desired DS402 Enabled Output.
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; // Status Bit 10 (0x400) indicates Target Reached (Homing is Complete).
const int STATUS_WORD_HOMING_ATTAINED_BIT = 0x1000; // Status Bit 12 (0x1000) indicates Homing Attained (Homing is Successful).
const int STATUS_WORD_HOMING_ERROR_BIT = 0x2000; // Status Bit 13 (0x2000) indicates Homing Error (Homing ran into a problem).
int axisControlWordIndex = (int)axis.NetworkIndexGet(RSINetworkIndexType.NetworkIndexTypeCONTROL_WORD_INDEX);
// CONFIGURE (Writing to SDOs)
axis.NetworkNode.ServiceChannelWrite(offsetIndex, offsetSubindex, offsetByteSize, offsetValue); // Home Offset
axis.NetworkNode.ServiceChannelWrite(methodIndex, methodSubindex, methodByteSize, methodValue); // Home Method (Home type)
axis.NetworkNode.ServiceChannelWrite(targetSpeedIndex, targetSpeedSubindex, targetSpeedByteSize, targetSpeedValue); // Home Speed during search for switch
axis.NetworkNode.ServiceChannelWrite(originSpeedIndex, originSpeedSubindex, orignSpeedByteSize, originSpeedValue); // Home Speed during search for zero
axis.NetworkNode.ServiceChannelWrite(accelerationIndex, accelerationSubindex, accelerationByteSize, accelerationValue); // Home acceleration
axis.rsiControl.NetworkOutputOverrideValueSet(axisControlWordIndex, CONTROL_WORD_TO_PREP_HOMING); // Control Word should be 15 before Switching to Homing Mode.
axis.rsiControl.NetworkOutputOverrideSet(axisControlWordIndex, true); // Override Control Word.
controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
// Delay to give transitions time -or- setup something more complex to ensure drive is in the appropriate state.
axis.OperationModeSet(RSIOperationMode.RSIOperationModeHOMING_MODE);
controller.SampleWait(ACCEPTABLE_DELAY_IN_MS);
// HOME
axis.rsiControl.NetworkOutputOverrideValueSet(axisControlWordIndex, CONTROL_WORD_TO_START_HOMING); // Start Homing.
controller.SampleWait(ACCEPTABLE_DELAY_IN_MS); // Delay to give transitions time -or- setup something more complex to ensure drive is in the appropriate state.
UInt16 statusWordValue; // Takes the axis index. This will return the status word value.
bool cancelHome = false;
statusWordValue = axis.NetworkNode.StatusWordGet(AXIS_NUMBER);
while ((!cancelHome) && ((statusWordValue & STATUS_WORD_TARGET_REACHED_BIT) == 0)) // When Status Word Indicates Target Reached (Success or Fail) or external evaluator (cancelHome)
{
//A timeout that sets cancelHome would be a good idea for this while loop.
statusWordValue = axis.NetworkNode.StatusWordGet(AXIS_NUMBER); //Update.
//A short sleep or wait is appropriate so you can't spamming this call.
}
// 4. EVALUATE HOMING SUCCESS
if ((statusWordValue & STATUS_WORD_HOMING_ATTAINED_BIT) == STATUS_WORD_HOMING_ATTAINED_BIT)
{
Console.WriteLine("Axis homed.");
}
else if ((statusWordValue & STATUS_WORD_HOMING_ERROR_BIT) == STATUS_WORD_HOMING_ATTAINED_BIT)
{
Console.WriteLine("Error Occured during homing.");
}
//5. CLEAN UP
axis.AmpEnableSet(false); // Disable the axis.
axis.ClearFaults();
axis.rsiControl.NetworkOutputOverrideSet(axisControlWordIndex, false);
// Restore the mode of operation to the control mode you want to run in. For most, this will be RSIOperationModeCYCLIC_SYNCHRONOUS_POSITION_MODE.
axis.OperationModeSet(RSIOperationMode.RSIOperationModeCYCLIC_SYNCHRONOUS_POSITION_MODE);

Learn more in the concept page.