Group Configuration complete code
This page contains the complete code of Group Configuration.
In GroupConfiguration.cpp
, your group configuration code should be like this:
Copy
#include "RT_Project_01.h"
#include "GroupConfiguration.h"
using namespace std;
VOID AssignAxis(int Group, int Axis, int IndexInGroup)
{
RtPrintf("Add Axis %d to Group %d.\n\n", Axis, Group);
//AddAxisToGroup can be used only in the GroupDisabled state.
/*Each IndexInGroup can be used only once. If you use the same IndexInGroup for two axes,
an error will occur when you add the third axis to a group.*/
KsError nRet = AddAxisToGroup(Group, Axis, IndexInGroup);
if (nRet != errNoError)
RtPrintf("AddAxisToGroup failed: %x\n\n", nRet);
}
VOID RemoveAxis(int Group, int IndexInGroup)
{
//Get the original index of an axis in a group.
int AxisIndex = 0;
KsError nRet = GetGroupConfiguration(Group, IndexInGroup, mcAxisCoordSystem, &AxisIndex);
if (nRet != errNoError)
RtPrintf("GetGroupConfiguration failed: %x\n", nRet);
//RemoveAxisFromGroup can be used only in the GroupDisabled state.
nRet = RemoveAxisFromGroup(Group, AxisIndex);
if (nRet != errNoError)
RtPrintf("RemoveAxisFromGroup failed: %x\n\n", nRet);
RtPrintf("Remove Axis %d from Group %d.\n\n", AxisIndex, Group);
}
VOID GroupEnable(int Group)
{
RtPrintf("Enable Group %d.\n\n", Group);
KsError nRet = EnableGroup(Group);
if (nRet != errNoError)
RtPrintf("EnableGroup failed: %x\n\n", nRet);
//ResetGroup can be used only after the group is enabled.
KsCommandStatus resetGroup = WaitForCommand(3, FALSE, ResetGroup(Group));
if (resetGroup.Error)
RtPrintf("ResetGroup failed: %d\n\n", resetGroup.ErrorId);
}
VOID GroupDisable(int Group)
{
RtPrintf("Disable Group %d.\n\n", Group);
KsError nRet = DisableGroup(Group);
if (nRet != errNoError)
RtPrintf("DisableGroup failed: %x\n\n", nRet);
}
VOID RemoveGroup(int Group)
{
RtPrintf("Remove all axes from Group %d.\n\n", Group);
KsError nRet = UngroupAllAxes(Group);
if (nRet != errNoError)
RtPrintf("UngroupAllAxes failed: %x\n\n", nRet);
}
VOID MotionProfileGroup(int Group)
{
RtPrintf("Create a motion profile for Group %d.\n", Group);
KsCommandStatus MotionProfile = SetGroupParameter(Group, mcMotionProfileTypeACS,
MOTION_GROUP_PROFILE_TYPE, mcImmediately);
if (MotionProfile.Error)
RtPrintf("SetGroupParameter failed: %d\n", MotionProfile.ErrorId);
KsCommandStatus Velocity = SetGroupParameter(Group, mcMaxVelocityACS,
MAXIMUM_GROUP_VELOCITY, mcImmediately);
if (Velocity.Error)
RtPrintf("SetGroupParameter failed: %d\n", Velocity.ErrorId);
KsCommandStatus Acceleration = SetGroupParameter(Group, mcMaxAccelerationACS,
MAXIMUM_GROUP_ACCELERATION, mcImmediately);
if (Acceleration.Error)
RtPrintf("SetGroupParameter failed: %d\n", Acceleration.ErrorId);
KsCommandStatus Deceleration = SetGroupParameter(Group, mcMaxDecelerationACS,
MAXIMUM_GROUP_DECELERATION, mcImmediately);
if (Deceleration.Error)
RtPrintf("SetGroupParameter failed: %d\n", Deceleration.ErrorId);
KsCommandStatus Jerk = SetGroupParameter(Group, mcMaxJerkACS, MAXIMUM_GROUP_JERK,
mcImmediately);
if (Jerk.Error)
RtPrintf("SetGroupParameter failed: %d\n", Jerk.ErrorId);
RtPrintf("\n");
}
VOID GetAGroupState(int Group)
{
//The group state's value starts from 2.
string groupState[8] = { "NULL", "NULL", "groupErrorStop", "groupDisabled",
"groupLocked", "groupStandStill", "groupHoming", "groupMoving" };
GroupState state = groupStandStill;
KsError nRet = GetGroupState(Group, &state);
if (nRet != errNoError)
RtPrintf("GetGroupState failed: %x\n\n", nRet);
else if (nRet == errNoError)
{
for (int i = 0; i < 8; i++)
{
if (state == i)
{
RtPrintf("Group %d is %s.\n\n", Group, groupState[i].c_str());
break;
}
}
}
}
VOID CheckAxisInGroup(int Group, int AxisInGroup)
{
//Group: the index of a group.
/*AxisInGroup: the index of an axis in the group. For example, if Axis 3 is the
first axis in a group, its AxisInGroup is zero.*/
//AxisIndex: the original index of an axis.
int AxisIndex = 0;
KsError nRet = GetGroupConfiguration(Group, AxisInGroup, mcAxisCoordSystem, &AxisIndex);
if (nRet != errNoError)
RtPrintf("GetGroupConfiguration failed: %x\n", nRet);
RtPrintf("Axis %d is in Group %d.\n\n", AxisIndex, Group);
}