AxisSystem_CAPI_Init.cpp
Axis system initialization.The following examples shows how to lookup, initialize and enable an axis system and how to execute a homing move for all axes.
//===========================================================================
// INCLUDES
//===========================================================================
#include "labbCAN_Bus_API.h"
#include "labbCAN_MotionControl_API.h"
//===========================================================================
// STATIC DATA
//===========================================================================
//===========================================================================
// Axis system initialisation
//===========================================================================
TErrCode InitAxisSystem(void)
{
TErrCode Result;
//
// Get the axis system handle for the axis system that is registered with
// the name neMAXYS1
//
if (hAxisSystem <= 0)
{
// handle error properly here
}
//
// Now we enable the axis system. Enabling the axis system means, power
// will be applied to power stage of all motion control units of this
// axis system. If the axis system is in fault state, then this function
// clears the fault state first, and then enables the axis device.
//
Result = LCA_Enable(hAxisSystem);
{
// handle error properly here
return Result;
}
//
// We execute a homing move to bring all axes of the axis system into their
// home positions and to reset the internal device position counters to
// zero. We use the FindHome position ofthe axis system to ensure a proper
// order of axis initialisation.
//
Result = LCA_FindHome(hAxisSystem);
if (Result != ERR_NOERR)
{
// handle error properly here
return Result;
}
//
// Give drives some time to start their homing moves
//
Sleep(100);
//
// Now we wait, until the positioning system reaches its home position.
// The home position is reached, if all axes of this positioning system
// reached their home positions.
//
while (1)
{
Result = LCA_IsHomingPosAttained(hAxisSystem);
//
// If all axes reached their homing position stop the loop
// and continue
//
if (Result > 0)
{
break;
}
if (Result != ERR_NOERR)
{
// handle error properly here
return Result;
}
Sleep(50); // do not take all processor time with this loop
} // while (1)
// now the axis system is properly initialized and we can start positioning
return Result;
}