APIs, concepts, guides, and more
Homing.cs
Attention
See the following Concept pages for a detailed explanation of this sample: Homing.
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.
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using NUnit.Framework;
using System;
class Homing : SampleAppTestBase
{
public void MasterBasedHoming()
{
//@[MasterBasedHoming]
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.
//@[MasterBasedHoming]
}
public void HomingWithAKDdrive()
{
//@[HomingWithAKDdrive]
// 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.
//@[HomingWithAKDdrive]
}
public void HomingWithDS402drive()
{
//@[HomingWithDS402drive]
// 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);
//@[HomingWithDS402drive]
}
public void CustomHome()
{
//@[CustomHome]
// user defined options
//const RSIMotorDedicatedIn CAPTURE_SOURCE = RSIMotorDedicatedIn.RSIMotorDedicatedInHOME;
const int HOME_LIMIT_NETWORK_INDEX = 99; //You may want to discover this rather than hard code it.
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.HomeActionSet(RSIAction.RSIActionSTOP);
// Ready Axis
axis.Abort();
axis.ClearFaults();
axis.AmpEnableSet(true);
// commanding a velocity move. This program assumes that the Custom Home will trigger at some point.
axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
//wait (sleep) until motion done interrupt occurs
Boolean done = false;
while (!done)
{
RSIEventType eventType = controller.InterruptWait(LongTime);
switch (eventType)
{
case RSIEventType.RSIEventTypeMOTION_DONE:
done = true;
break;
case RSIEventType.RSIEventTypeTIMEOUT:
done = true;
break;
default:
break;
}
}
if ((controller.NetworkInputValueGet(HOME_LIMIT_NETWORK_INDEX) & HOME_LIMIT_SIG_BIT) > 0) //On Home Limit
{
axis.HomeStateSet(true);
}
else
{
//Evaluate why we aren't on custom home.
}
// setup Home Action (the home action will not trigger)
axis.HomeActionSet(RSIAction.RSIActionNONE);
axis.ClearFaults();
axis.AmpEnableSet(false);
//@[CustomHome]
}
}
uint32_t NetworkIndexGet(RSINetworkIndexType indexType)
Get the Network Index associated with a DS402 Axis Feature.
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 OriginPositionSet(double position)
Set the origin position.
void OperationModeSet(RSIOperationMode mode)
Set the axis operation mode.
void HomeVelocitySet(double velocity)
Set the home velocity.
NetworkNode * NetworkNode
Gets the associated NetworkNode object.
Definition rsi.h:5586
void HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void MoveVelocity(double 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 HomeStateSet(bool homed)
Set the home state.
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 HomeLimitCustomConfigSet(uint64_t address, int32_t bitIndex)
void HomeOffsetSet(double offset)
Set the home offset.
void NetworkOutputOverrideValueSet(int32_t index, uint64_t outputValue)
Sets a PDO output directly.
void NetworkOutputOverrideSet(int32_t index, bool outputOverride)
Set NetworkOutputValue to override RMP cyclic value.
uint64_t NetworkInputValueGet(int32_t index)
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
uint64_t NetworkInputAddressGet(int32_t index)
char * AKDASCIICommand(const char *const command)
Send a Kollmorgen AKD ASCII command (NodeType must equal KOLLMORGEN_AKD)
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.
RSIEventType InterruptWait(int32_t milliseconds)
Suspend the current thread until an interrupt arrives from the controller.
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t NumberGet()
Get the axis number.
MotionController * rsiControl
Gets the parent MotionController object.
Definition rsi.h:4081