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.


In this page:


📜 Homing: Drive-Based

This sample code performs Drive-Based Homing (DS402) 📖 assuming the drive follows the DS402 Standard. RSI encourages drive-based homing method over all others because it avoids network latencies.

/* This sample application demonstrates drive-based homing with a DS402-compliant drive using the RapidCode .NET API.
Drive-based homing avoids network latencies since the drive executes the homing routine.
Many drives follow the DS402 standard, making this a widely applicable homing method.
This sample configures SDO parameters, manages control word states, and monitors status word for completion.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Axis Homing: DS402 Drive");
// set sample config params
const int offsetIdx = 0x607C;
const int offsetSub = 0x0;
const int offsetSize = 4;
const int offsetVal = 0;
const int methodIdx = 0x6098;
const int methodSub = 0x0;
const int methodSize = 1;
const int methodVal = 24;
const int targetSpeedIdx = 0x6099;
const int targetSpeedSub = 0x1;
const int targetSpeedSize = 4;
const int targetSpeedVal = 2;
const int originSpeedIdx = 0x6099;
const int originSpeedSub = 0x2;
const int originSpeedSize = 4;
const int originSpeedVal = 10;
const int accelIdx = 0x609A;
const int accelSub = 0x0;
const int accelSize = 4;
const int accelVal = 100;
const int CTRL_WORD_PREP_HOMING = 15;
const int CTRL_WORD_START_HOMING = 31;
const int DELAY_MS = 20;
const int STATUS_TARGET_REACHED = 0x400; // bit 10: target reached (homing complete)
const int STATUS_HOMING_ATTAINED = 0x1000; // bit 12: homing attained (successful)
const int STATUS_HOMING_ERROR = 0x2000; // bit 13: homing error
// get rmp controller
try
{
Helpers.CheckErrors(controller);
// check is network is started
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network not started. Please start it before running this app.");
return;
}
// get axis
Axis axis = controller.AxisGet(axisNumber: 0);
Helpers.CheckErrors(axis);
// 1. configure homing parameters via SDOs writes
axis.NetworkNode.ServiceChannelWrite(offsetIdx, offsetSub, offsetSize, offsetVal); // home offset
axis.NetworkNode.ServiceChannelWrite(methodIdx, methodSub, methodSize, methodVal); // home method (home type)
axis.NetworkNode.ServiceChannelWrite(targetSpeedIdx, targetSpeedSub, targetSpeedSize, targetSpeedVal); // speed during search for switch
axis.NetworkNode.ServiceChannelWrite(originSpeedIdx, originSpeedSub, originSpeedSize, originSpeedVal); // speed during search for zero
axis.NetworkNode.ServiceChannelWrite(accelIdx, accelSub, accelSize, accelVal); // home acceleration
// 2. configure control word for homing
int axisCtrlWordIdx = (int)axis.NetworkIndexGet(RSINetworkIndexType.NetworkIndexTypeCONTROL_WORD_INDEX);
axis.rsiControl.NetworkOutputOverrideValueSet(axisCtrlWordIdx, CTRL_WORD_PREP_HOMING); // control word should be 15 before switching to homing mode
axis.rsiControl.NetworkOutputOverrideSet(axisCtrlWordIdx, true); // override control word
controller.SampleWait(DELAY_MS); // delay to give transitions time
// 3. configure operation mode to homing
axis.OperationModeSet(RSIOperationMode.RSIOperationModeHOMING_MODE);
controller.SampleWait(DELAY_MS);
// 4. home
axis.rsiControl.NetworkOutputOverrideValueSet(axisCtrlWordIdx, CTRL_WORD_START_HOMING); // start homing
controller.SampleWait(DELAY_MS);
bool cancelHome = false;
UInt16 statusWord = axis.NetworkNode.StatusWordGet(Constants.AXIS_0_INDEX);
while ((!cancelHome) && ((statusWord & STATUS_TARGET_REACHED) == 0)) // wait until target reached or cancel
{
// A timeout that sets cancelHome would be a good idea for this while loop
statusWord = axis.NetworkNode.StatusWordGet(Constants.AXIS_0_INDEX); // update status word
// A short sleep or wait is appropriate so you aren't spamming this call
}
// evaluate homing result
if ((statusWord & STATUS_HOMING_ATTAINED) == STATUS_HOMING_ATTAINED)
Console.WriteLine("Axis homed successfully");
else if ((statusWord & STATUS_HOMING_ERROR) == STATUS_HOMING_ERROR)
Console.WriteLine("Error occurred during homing");
// clean up
Helpers.AbortMotionObject(axis);
axis.rsiControl.NetworkOutputOverrideSet(axisCtrlWordIdx, false);
// restore mode of operation to your desired control mode (typically CSP mode)
axis.OperationModeSet(RSIOperationMode.RSIOperationModeCYCLIC_SYNCHRONOUS_POSITION_MODE);
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
Constants used in the C# sample apps.
Definition _constants.cs:3
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:11
uint32_t NetworkIndexGet(RSINetworkIndexType indexType)
Get the PDO array index for an axis signal mapping.
void OperationModeSet(RSIOperationMode mode)
Set the axis operation mode.
NetworkNode * NetworkNode
Gets the associated NetworkNode object.
Definition rsi.h:5893
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5863
void NetworkOutputOverrideValueSet(int32_t index, uint64_t outputValue)
Sets a PDO output directly.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void NetworkOutputOverrideSet(int32_t index, bool outputOverride)
Set NetworkOutputValue to override RMP cyclic value.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void ServiceChannelWrite(int32_t index, int32_t subIndex, int32_t byteCount, int32_t sdoValue)
Write a number in the SDO.
uint16_t StatusWordGet(int32_t axisIndex)
Get the DS402 status word.
MotionController * rsiControl
Gets the parent MotionController object.
Definition rsi.h:4325
RSINetworkState
State of network.
Definition rsienums.h:568
RSIOperationMode
DS402 modes of operation.
Definition rsienums.h:1331
RSINetworkIndexType
Network PDO index types for configuring axis input/output mappings.
Definition rsienums.h:1390
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21

Source: axis-homing-ds402-drive.cs


📜 Homing: Drive-Based (AKD drive via ASCII)

This sample code performs Drive-Based Homing (AKD ASCII) 📖 with a Kollmorgen AKD drive. RSI encourages drive-based homing method over all others because it avoids network latencies.

/* This sample application demonstrates drive-based homing with a Kollmorgen AKD drive using the RapidCode .NET API.
AKD Drive-based ASCII homing uses preloaded methods available on the drive.
This allows for homing to be performed entirely in the drive without network latencies producing more accurate results.
Drive homing is the recommended homing strategy since it avoids network latencies by having the drive execute the homing routine.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Axis Homing: AKD Drive");
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// check is network is started
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network not started. Please start it before running this app.");
return;
}
// get axis
Axis axis = controller.AxisGet(axisNumber: 0);
Helpers.CheckErrors(axis);
// check Axis type
if (axis.NetworkNode.TypeGet() != RSINodeType.RSINodeTypeKOLLMORGEN_AKD)
{
Console.WriteLine("Wrong Axis type. This sample requires an AKD Axis.");
return;
}
// 1. get the drive ready
axis.OperationModeSet(RSIOperationMode.RSIOperationModeHOMING_MODE); // set mode to homing mode
axis.NetworkNode.AKDASCIICommand("DRV.OPMODE 2"); // set drive operation mode (0=current, 1=velocity, 2=position)
axis.NetworkNode.AKDASCIICommand("HOME.AUTOMOVE 0"); // 0=disabled, 1=homing starts when drive enabled
// Make sure you know your motor's position, velocity, and acceleration units before you send any values
// 2. set limit switches
axis.NetworkNode.AKDASCIICommand("DIN5.MODE 18"); // set digital input modes - DI5 is now positive limit switch
axis.NetworkNode.AKDASCIICommand("DIN5.INV 1"); // set polarity - DI5 is now active when low
axis.NetworkNode.AKDASCIICommand("DIN6.MODE 19"); // set digital input modes - DI6 is now negative limit switch
axis.NetworkNode.AKDASCIICommand("DIN6.INV 1"); // set polarity - DI6 is now active when low
// 3. configure drive homing parameters
axis.NetworkNode.AKDASCIICommand("HOME.MODE 1"); // select homing method (MODE1 = find limit input)
axis.NetworkNode.AKDASCIICommand("HOME.V 20"); // set homing velocity
axis.NetworkNode.AKDASCIICommand("HOME.ACC 200"); // set homing acceleration
axis.NetworkNode.AKDASCIICommand("HOME.DEC 200"); // set homing deceleration
axis.NetworkNode.AKDASCIICommand("HOME.DIR 0"); // set homing direction (0=negative, 1=positive)
axis.NetworkNode.AKDASCIICommand("HOME.P 0"); // set home position
axis.NetworkNode.AKDASCIICommand("HOME.DIST 0"); // set homing distance
axis.NetworkNode.AKDASCIICommand("HOME.MAXDIST 0"); // set max homing distance
axis.NetworkNode.AKDASCIICommand("HOME.IPEAK"); // set peak current
// 4. get the axis ready
axis.ErrorLimitActionSet(RSIAction.RSIActionNONE); // set action to none so we don't get position error while 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"); // start homing procedure (active in opmode 2 only)
Console.WriteLine("HOME.MOVE command sent");
// 6. check is homing done
UInt16 statusWord;
int isHomed = 0;
int axisIdx = axis.NumberGet();
while (isHomed != 1) // when isHomed = 1, homing has finished
{
statusWord = axis.NetworkNode.StatusWordGet(axisIdx);
isHomed = statusWord >> 12; // get 12th bit only - tells us homing is done when it goes high
}
Console.WriteLine("Axis homed");
// 7. cleanup
axis.OriginPositionSet(0.0); // set origin to 0 (needed for repeated use)
axis.Abort(); // disable the axis
axis.OperationModeSet(RSIOperationMode.RSIOperationModeINTERPOLATED_POSITION_MODE); // restore mode of operation
axis.ErrorLimitActionSet(RSIAction.RSIActionABORT); // restore position error action
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
void OriginPositionSet(double position)
Set the origin position.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
char * AKDASCIICommand(const char *const command)
Send a Kollmorgen AKD ASCII command (NodeType must equal KOLLMORGEN_AKD).
RSINodeType TypeGet()
Get the node type, as determined by the Vendor ID and Product Code.
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
int32_t NumberGet()
Get the axis number.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115
RSINodeType
Valid Node types.
Definition rsienums.h:677

Source: axis-homing-akd-drive.cs


📜 Homing: Master-Based

This sample code performs a simple Master-Based Homing (DS402) 📖 routine where the RMP controller executes the homing.

/* This sample application demonstrates master-based homing using the RapidCode .NET API.
Master-based homing is when the RMP controller executes the homing routine instead of the drive.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Axis Homing: Master-Based");
// set sample config params
const RSIHomeMethod HOME_METHOD = RSIHomeMethod.RSIHomeMethodImprovedFALLING_HOME_NEGATIVE_START_POSITIVE_MOMENTUM;
// get rmp controller
try
{
Helpers.CheckErrors(controller);
// check is network is started
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network not started. Please start it before running this app.");
return;
}
// get axis
Axis axis = controller.AxisGet(axisNumber: 0);
Helpers.CheckErrors(axis);
// configure limit action
axis.HardwareNegLimitActionSet(RSIAction.RSIActionSTOP); // neg limit action set to STOP
// configure homing parameters
axis.HomeMethodSet(HOME_METHOD); // set the homing method
axis.HomeVelocitySet(10); // set the home velocity
axis.HomeSlowVelocitySet(1); // set the slow home velocity (used for final move if necessary)
axis.HomeAccelerationSet(100); // set the acceleration used for homing
axis.HomeDecelerationSet(100); // set the deceleration used for homing
axis.HomeOffsetSet(0.5); // set position offset from home (zero) position
// execute homing routine
axis.Home();
// check if homing was successful
if (axis.HomeStateGet() == true)
Console.WriteLine("Homing successful");
// clean up
Helpers.AbortMotionObject(axis);
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
void HomeSlowVelocitySet(double velocity)
Set the slow home velocity.
void HomeVelocitySet(double velocity)
Set the home velocity.
void Home()
Execute the homing routine.
void HomeDecelerationSet(double decel)
Set the decleration to be used for homing when using the switch is not detected before the HomeTravel...
void HomeAccelerationSet(double accel)
Set the deceleration used for homing.
void HomeMethodSet(RSIHomeMethod method)
Set the method to be used for homing.
bool HomeStateGet()
Get the home state.
void HomeOffsetSet(double offset)
Sets the user coordinate value assigned to the detected homing reference point.

Source: axis-homing-master-based.cs