homingLatch
homingLatch uses a servo drive's touch probe feature to get the home position, and uses probe ID 0 in KINGSTAR as the trigger.
Process of using homingLatch
The following process shows how homingLatch is done:
Enable touch probe before start the KINGSTAR Subsystem -> Create an McProbeTrigger instance (define a touch probe) -> SetAxisTouchProbe (record a position and use it as the home position) -> HomeAxis (select homingLatch and home an axis)
Functions
EnableTouchProbe: adds the TouchProbeControl and TouchProbeStatus variables to PDO.
McProbeTrigger instance: selects which signal will trigger touch probe.
SetAxisTouchProbe: records the position of an axis at a trigger event.
HomeAxis: commands an axis to perform the "search home" sequence.
WaitForCommand: waits for a command to be finished.
Code
To use touch probe to home your axis, you have two steps to do:
Step 1: enable touch probe
To use touch probe, you need to enable it before the KINGSTAR Subsystem is started.
- In
SystemInitialization.h
, add the following code: - Use EnableTouchProbe to enable touch probe. In
SystemInitialization.cpp
, in the StartKingstar function, under the code block of EnableRedundancy, add the following code:
#pragma once
//Map the TouchProbeControl and TouchProbeStatus variables to the PDO.
#define TOUCHPROBE TRUE
//TOUCHPROBE is TRUE.
nRet = EnableTouchProbe(TOUCHPROBE);
if (nRet != errNoError)
{
RtPrintf("EnableTouchProbe failed: %x\n", nRet);
WaitForCommand(5, FALSE, Stop());
Destroy();
return FALSE;
}
Step 2: configure the probe settings and home your axis
In Homing.cpp
, add the following code:
- Declare a variable that will be used in SetAxisTouchProbe.
- Create an instance of the McProbeTrigger structure and then apply the instance to SetAxisTouchProbe, which records the position of an axis at a trigger event. For McProbeTrigger, you should set the parameters depending on your hardware environment. In this guide, we use a Z-phase signal from a servo drive and set TouchProbeID,
IndexPulse
, andEdge
. - After setting the touch probe, use HomeAxis to home your axis. We use WaitForCommand to give it some time to finish.
VOID HomingLatch(int Index)
{
RtPrintf("Home an axis using homingLatch.\n\n");
double PosRecord = 0;
//Configure the probe to use for position latching.
/*The axis moves in the preset homing direction at the high velocity until the probe is triggered.
The axis will then move back to the latched position using the low velocity.*/
//We use the phase Z signal from a servo drive.
McProbeTrigger ProbeTrigger = { 0 };
ProbeTrigger.TouchProbeId = 0; //Use TouchProbe Zero.
ProbeTrigger.IndexPulse = TRUE; /*TRUE: Use a Z signal to trigger.
FALSE: Use a DI from a servo drive to trigger.*/
ProbeTrigger.Edge = TRUE; //TRUE: Rising edge. FALSE: Falling edge.
KsCommandStatus probe = SetAxisTouchProbe(Index, ProbeTrigger, FALSE, 0, 0, &PosRecord);
if (probe.Error)
RtPrintf("SetAxisTouchProbe failed: %d\n", probe.ErrorId);
//Start homing.
KsCommandStatus home = WaitForCommand(30, TRUE, HomeAxis(Index, 0, HOMING_HIGH_VELOCITY,
HOMING_LOW_VELOCITY, HOMING_ACCELERATION, HOMING_DECELERATION, MAXIMUM_JERK,
HOMING_DIRECTION, homingLatch));
if (home.Error)
RtPrintf("homingLatch failed: %d\n", home.ErrorId);
else if (home.Done)
RtPrintf("homingLatch is completed.\n");
}
Complete code
The complete code should be as follows:
VOID HomingLatch(int Index)
{
RtPrintf("Home an axis using homingLatch.\n\n");
double PosRecord = 0;
//Configure the probe to use for position latching.
/*The axis moves in the preset homing direction at the high velocity until the probe is triggered.
The axis will then move back to the latched position using the low velocity.*/
//We use the phase Z signal from a servo drive.
McProbeTrigger ProbeTrigger = { 0 };
ProbeTrigger.TouchProbeId = 0; //Use TouchProbe Zero.
ProbeTrigger.IndexPulse = TRUE; /*TRUE: Use a Z signal to trigger.
FALSE: Use a DI from a servo drive to trigger.*/
ProbeTrigger.Edge = TRUE; //TRUE: Rising edge. FALSE: Falling edge.
KsCommandStatus probe = SetAxisTouchProbe(Index, ProbeTrigger, FALSE, 0, 0, &PosRecord);
if (probe.Error)
RtPrintf("SetAxisTouchProbe failed: %d\n", probe.ErrorId);
//Start homing.
KsCommandStatus home = WaitForCommand(30, TRUE, HomeAxis(Index, 0, HOMING_HIGH_VELOCITY,
HOMING_LOW_VELOCITY, HOMING_ACCELERATION, HOMING_DECELERATION, MAXIMUM_JERK,
HOMING_DIRECTION, homingLatch));
if (home.Error)
RtPrintf("homingLatch failed: %d\n", home.ErrorId);
else if (home.Done)
RtPrintf("homingLatch is completed.\n\n");
}
Output:
We have two EtherCAT slaves connected to five motors. I/O modules are simulated.