ACS to MCS

To transform Axis Coordinate System (ACS) to Machine Coordinate System (MCS), we use SetKinTransform, to which we apply values for coordinate transformation. To retrieve the values for transformation, we use GetKinTransform.

NOTE:  This feature requires Kinematic Package.

Functions

McKinRef structure: the kinematics reference.

McKinType type: the type of a kinematic model. When you choose kinCartesian3D1, you must have three axes to for X, Y, Z translation.

SetKinTransform: sets a kinematic transformation between the ACS and MCS based on the predefined kinematic model.

GetKinTransform: gets the kinematic transformation that is active between the ACS and MCS.

Code

We introduce how to convert ACS into MCS first, and then talk about how to get the values for transformation. Finally, we display both ACS and MCS positions.

Before we start, in GroupConfiguration.cpp, add the ACSToMCS function. We are writing code in this function. The first line of code, RtPrintf("Transform the coordinates of Group %d from ACS to MCS.\n\n", Group);, displays the message that describes what this function is going to do.

Copy
VOID ACSToMCS(int Group)
{
    RtPrintf("Transform the coordinates of Group %d from ACS to MCS.\n\n", Group);
}
Transform ACS to MCS
  1. Before we transform anything, we need to declare some values for the coordinates to use. First, we declare two arrays to contain ACS and MCS positions, and we declare another array to contain the values for coordinate conversion. Next, we declare an instance of the McKinRef structure, which is going to be applied to SetKinTransform.
  2. Copy
    /* Set the values for ACS-MCS transformation */

    double ACSPositions[3] = { 0, 0, 0 };           //ACS positions.
    double MCSPositions[3] = { 0, 0, 0 };           //MCS positions.
    double kinParameters[3] = { -20, -40, -60 };    //Values for transformation.
    McKinRef Transform = { kinCartesian3D1, kinParameters };
  3. After all values are set, use SetKinTransform to transform the ACS positions into MCS, and then use Done and ErrorID to check whether the transformation is done.
  4. Copy
    //Use SetKinTransform to transform coordinates.
    KsCommandStatus SetKin = WaitForCommand(3, FALSE, SetKinTransform(Group, Transform, mcImmediately));
    RtPrintf("SetKinTransform: Done: %d, ErrorID: %d\n", SetKin.Done, SetKin.ErrorId);
Get the values for transformation

The use of GetKinTransform is a bit special. You need to allocate memory space for McKinRef.KinParameters first, and then load the values of transformation to this space.

  1. Declare an instance of the McKinRef structure, and then declare an array with three elements, because there are three positions we want to get. Next, assign this array to Transformout.KinParameters. When we get the values for transformation, each of them will be stored in the array we gave to KinParameters.
  2. Copy
    /* Get the values for ACS-MCS transformation */

    /*You need to assign space to the instance of the McKinRef structure first, and then the read data
      can be written into the space you assigned.*/
    McKinRef Transformout;
    double KinParameterBuffer[3] = { 0 };
    Transformout.KinParameters = KinParameterBuffer;
  3. Use GetKinTransform to get the values for transformation, and then display it to see if the values are correct.
  4. Copy
    KsError err = GetKinTransform(Group, &Transformout);
    Sleep(3);
    printf("KinTransform is: KinType: %d, KinParameters: %f, %f, %f\n\n", Transformout.KinType, 
        Transformout.KinParameters[0], Transformout.KinParameters[1], Transformout.KinParameters[2]);
Display the ACS and MCS positions

After the transformation is done, use GetGroupPosition to retrieve the ACS and MCS positions, and display them.

Copy
/* Display the transformed positions */

/*The transformation process is ACS->MCS->PCS. When we use mcMachineCoordSystem, it affects
  MCS and PCS, but doesn't affect ACS. If you use mcAxisCoordSystem, it affects ACS, MCS, and PCS.*/
GetGroupPosition(Group, mcAxisCoordSystem, mcSetValue, 3, ACSPositions);
GetGroupPosition(Group, mcMachineCoordSystem, mcSetValue, 3, MCSPositions);
printf("ACS Positions: %f, %f, %f\n", ACSPositions[0], ACSPositions[1], ACSPositions[2]);
printf("MCS Positions: %f, %f, %f\n\n", MCSPositions[0], MCSPositions[1], MCSPositions[2]);

Complete code

The complete code should be as follows:

Copy
ACS to MCS
VOID ACSToMCS(int Group)
{
    RtPrintf("Transform the coordinates of Group %d from ACS to MCS.\n\n", Group);

    /* Set the values for ACS-MCS transformation */

    double ACSPositions[3] = { 0, 0, 0 };           //ACS positions.
    double MCSPositions[3] = { 0, 0, 0 };           //MCS positions.
    double kinParameters[3] = { -20, -40, -60 };    //Values for transformation.
    McKinRef Transform = { kinCartesian3D1, kinParameters };

    //Use SetKinTransform to transform coordinates.
    KsCommandStatus SetKin = WaitForCommand(3, FALSE, SetKinTransform(Group, Transform, mcImmediately));
    RtPrintf("SetKinTransform: Done: %d, ErrorID: %d\n", SetKin.Done, SetKin.ErrorId);

    /* Get the values for ACS-MCS transformation */

    /*You need to assign space to the instance of the McKinRef structure first, and then the read data
      can be written into the space you assigned.*/
    McKinRef Transformout;
    double KinParameterBuffer[3] = { 0 };
    Transformout.KinParameters = KinParameterBuffer;

    KsError err = GetKinTransform(Group, &Transformout);
    Sleep(3);
    printf("KinTransform is: KinType: %d, KinParameters: %f, %f, %f\n\n", Transformout.KinType, 
        Transformout.KinParameters[0], Transformout.KinParameters[1], Transformout.KinParameters[2]);

    /* Display the transformed positions */

    /*The transformation process is ACS->MCS->PCS. When we use mcMachineCoordSystem, it affects
      MCS and PCS, but doesn't affect ACS. If you use mcAxisCoordSystem, it affects ACS, MCS, and PCS.*/
    GetGroupPosition(Group, mcAxisCoordSystem, mcSetValue, 3, ACSPositions);
    GetGroupPosition(Group, mcMachineCoordSystem, mcSetValue, 3, MCSPositions);
    printf("ACS Positions: %f, %f, %f\n", ACSPositions[0], ACSPositions[1], ACSPositions[2]);
    printf("MCS Positions: %f, %f, %f\n\n", MCSPositions[0], MCSPositions[1], MCSPositions[2]);
}

 

Output: