APIs, concepts, guides, and more

◆ ServiceChannelWrite() [3/5]

void ServiceChannelWrite ( int32_t index,
int32_t subIndex,
int32_t byteCount,
int32_t sdoValue )
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

Axis: Homing

// 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);
Examples
Homing.cs.