APIs, concepts, guides, and more

◆ ServiceChannelWrite() [2/3]

void ServiceChannelWrite ( int32_t index,
int32_t subIndex,
int32_t byteCount,
int32_t sdoValue,
uint32_t timeoutMilliseconds = SDOTimeoutMillisecondsDefault )
Description:
Write a number to the SDO. The index, subIndex, byteCount, and valid numeric values are drive specific. Refer to the drive manual to determine these values.
Parameters
indexThe memory address to write to
subIndexThe sub index to write to
byteCountThe number of bytes to write
sdoValueThe numeric value to write
timeoutMillisecondsThe time in ms that the function will wait for a write response before generating a timeout error. (Default: SDOTimeoutMillisecondsDefault)

Axis: Homing

/* 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");
int exitCode = 0;
// 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);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
// check is network is started
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Network not started. Please start it before running this app.");
}
// get axis
Axis axis = controller.AxisGet(axisNumber: Constants.AXIS_0_INDEX);
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);
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
Constants used in the C# sample apps.
Definition _constants.cs:3
const int EXIT_FAILURE
Exit code for failed execution.
Definition _constants.cs:69
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:20
const int EXIT_SUCCESS
Exit code for successful execution.
Definition _constants.cs:68
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:5993
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5963
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:796
void ServiceChannelWrite(int32_t index, int32_t subIndex, int32_t byteCount, int32_t sdoValue, uint32_t timeoutMilliseconds=SDOTimeoutMillisecondsDefault)
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:4437
RSINetworkState
State of network.
Definition rsienums.h:609
RSIOperationMode
DS402 modes of operation.
Definition rsienums.h:1380
RSINetworkIndexType
Network PDO index types for configuring axis input/output mappings.
Definition rsienums.h:1478
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21
See also
SDOTimeoutMillisecondsDefault
Examples
axis-homing-ds402-drive.cs.