APIs, concepts, guides, and more
axis-homing-ds402-drive.cs
/* 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(Constants.AXIS_0_INDEX);
// 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
axis.AmpEnableSet(false);
axis.ClearFaults();
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
}
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
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:5900
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5870
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void NetworkOutputOverrideValueSet(int32_t index, uint64_t outputValue)
Sets a PDO output directly.
RSINetworkState NetworkStateGet()
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void NetworkOutputOverrideSet(int32_t index, bool outputOverride)
Set NetworkOutputValue to override RMP cyclic value.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
void Delete(void)
Delete the MotionController and all its objects.
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.
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
MotionController * rsiControl
Gets the parent MotionController object.
Definition rsi.h:4330
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