homingSoft and homingSensor

homingSoft and homingSensor are very similar. To know their difference, see the introduction page. The ways to use them are the same.

Process of using homingSoft and homingSensor

The following process show how homingSoft and homingSensor are done.

SetAxisHomeSwitch (configure a homing sensor) -> HomeAxis (select homingSoft or homingSensor and home an axis)

We use homingSoft for the tutorial, and we give you the code of homingSoft and homingSensor functions in homingSoft and homingSensor section.

Functions

SetAxisHomeSwitch: sets a digital sensor to use as a homing switch.

HomeAxis: commands an axis to perform the "search home" sequence.

Code

We divide the homingSoft code into steps to explain. In the last part, we combine all the code for you to see the completed one.

In Homing.cpp, add the following code:

  1. Use SetAxisHomeSwitch to set a home sensor. The sensor settings vary according to hardware environment.
  2. Copy
    VOID HomingSoft(int Index)
    {
        RtPrintf("Home an axis using homingSoft.\n\n");
        
        //Configure a homing sensor.
        KsError nRet = SetAxisHomeSwitch(Index, HOME_SENSOR_TYPE, HOME_SENSOR_INDEX,
            HOME_SENSOR_OFFSET, HOME_SENSOR_INVERT);
        if (nRet != errNoError)
            RtPrintf("SetAxisHomeSwitch failed: %x\n", nRet);
  3. Use HomeAxis to home your axis. We use WaitForCommand to give it some time to finish.
  4. Copy
        //Start homing.
        //An axis moves in the preset homing direction using high velocity.
        /*An axis reverses the direction every time it touches a sensor, because the sensor's signal changes
          whenever the sensor is touched.*/
        /*The velocity is divided by 10 every time the direction is reversed until it finds the sensor
          in the preset direction at the low velocity.*/
        KsCommandStatus home = WaitForCommand(30, TRUE, HomeAxis(Index, 0, HOMING_HIGH_VELOCITY,
            HOMING_LOW_VELOCITY, HOMING_ACCELERATION, HOMING_DECELERATION, MAXIMUM_JERK,
            HOMING_DIRECTION, homingSoft));
        
        if (home.Error)
            RtPrintf("homingSoft failed: %d\n", home.ErrorId);
        
        else if (home.Done)
            RtPrintf("homingSoft is completed.\n\n");
    }

Complete code

The complete code should be as follows:

Copy
homingSoft and homingSensor
VOID HomingSoft(int Index)
{
    RtPrintf("Home an axis using homingSoft.\n\n");
    
    //Configure a homing sensor.
    KsError nRet = SetAxisHomeSwitch(Index, HOME_SENSOR_TYPE, HOME_SENSOR_INDEX,
        HOME_SENSOR_OFFSET, HOME_SENSOR_INVERT);
    if (nRet != errNoError)
        RtPrintf("SetAxisHomeSwitch failed: %x\n", nRet);
    
    //Start homing.
    //An axis moves in the preset homing direction using high velocity.
    /*An axis reverses the direction every time it touches a sensor, because the sensor's signal changes
      whenever the sensor is touched.*/
    /*The velocity is divided by 10 every time the direction is reversed until it finds the sensor
      in the preset direction at the low velocity.*/
    KsCommandStatus home = WaitForCommand(30, TRUE, HomeAxis(Index, 0, HOMING_HIGH_VELOCITY,
        HOMING_LOW_VELOCITY, HOMING_ACCELERATION, HOMING_DECELERATION, MAXIMUM_JERK,
        HOMING_DIRECTION, homingSoft));
    
    if (home.Error)
        RtPrintf("homingSoft failed: %d\n", home.ErrorId);
    
    else if (home.Done)
        RtPrintf("homingSoft is completed.\n\n");
}

VOID HomingSensor(int Index)
{
    RtPrintf("Home an axis using homingSensor.\n\n");
    
    //Configure a homing sensor.
    KsError nRet = SetAxisHomeSwitch(Index, HOME_SENSOR_TYPE, HOME_SENSOR_INDEX,
         HOME_SENSOR_OFFSET, HOME_SENSOR_INVERT);
    if (nRet != errNoError)
        RtPrintf("SetAxisHomeSwitch failed: %x\n", nRet);
    
    //Start homing.
    //An axis moves in the preset homing direction using high velocity.
    /*The moving direction of an axis is determined by a sensor's signal. If the signal is zero,
      it moves forward; if the signal is one, it moves backward.*/
    /*The velocity is divided by 10 every time the direction is reversed until it finds the sensor
        in the preset direction at the low velocity.*/
    KsCommandStatus home = WaitForCommand(30, TRUE, HomeAxis(Index, 0, HOMING_HIGH_VELOCITY,
        HOMING_LOW_VELOCITY, HOMING_ACCELERATION, HOMING_DECELERATION, MAXIMUM_JERK,
        HOMING_DIRECTION, homingSensor));
    
    if (home.Error)
        RtPrintf("homingSensor failed: %d\n", home.ErrorId);
    
    else if (home.Done)
        RtPrintf("homingSensor is completed.\n\n");
}

 

Output:

homingSoft

homingSensor