MCS to PCS

To transform Machine Coordinate System (MCS) to Product Coordinate System (PCS), we use SetCartesianTransform, to which we apply values for coordinate transformation. To retrieve the values for transformation, we use GetCartesianTransform.

You must transform an ACS position into MCS first, and then transform the MCS position into PCS, because an MCS position is created from ACS. If you transform MCS into PCS independently, the transformation will fail.

NOTE:  This feature requires Kinematic Package.

Functions

SetCartesianTransform: sets a Cartesian transformation between the MCS and PCS.

GetCartesianTransform: gets the parameters of the Cartesian transformation that is active between the MCS and PCS. If more than one transformation is active, the resulting Cartesian transformation is given.

Code

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

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

Copy
VOID MCSToPCS(int Group)
{
    RtPrintf("transform the coordinates of Group %d from MCS to PCS.\n\n", Group);
}
Transform MCS to PCS
  1. Before we transform anything, we need to declare some values for the coordinates to use. We declare two arrays to contain MCS and PCS positions. The Positions array is optional. If you want to set an MCS position to zero or other values (change zeros to other number), you need to use this array, otherwise the MCS position will use the values transformed from ACS.
  2. NOTE:  If you didn't transform an ACS position to MCS first but want to transform an MCS position into PCS, the transformation will fail.

    Copy
    //You must transform the ACS positions into MCS first, and then transform MCS into PCS.

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

    double MCSPositions[3] = { 0, 0, 0 };   //MCS positions.
    double PCSPositions[3] = { 0, 0, 0 };   //PCS positions.
    //double Positions[3] = { 0, 0, 0 };    //Set MCS positions to zero.
  3. After the values are set, use SetCartesianTransform to transform the MCS position into PCS, and then we use Done and ErrorID to check whether the transformation is done.
  4. We comment out SetGroupPositionOffset because we want to use the MCS position transformed from ACS instead of setting the MCS position to zero. If you want to transform a specified MCS position, such as (0, 0, 0), you can uncomment the line of SetGroupPositionOffset and the Positions array code.

    Copy
    /*KsCommandStatus Position = WaitForCommand(3, FALSE, SetGroupPositionOffset(Group, 3, Positions,
      FALSE, mcMachineCoordSystem, mcImmediately));*/
    KsCommandStatus SetCartesian = SetCartesianTransform(Group, 10, 20, 15, -45, 30, 20, mcImmediately);
    RtPrintf("SetCartesianTransform: Done: %d, ErrorID: %d\n", SetCartesian.Done, SetCartesian.ErrorId);
Get the values for transformation
  1. Declare two arrays to store translation and rotation values of transformation.
  2. Copy
    /* Get the values for MCS-PCS transformation */

    double Trans[3] = { 0 };                //Points of translation.
    double Rotate[3] = { 0 };               //Angles of rotation.
  3. Use GetCartesianTransform to get the values for transformation, and then display it to see if the values are correct. Notice that the first value of rotation is the angle of Z-axis rotation.
  4. Copy
    KsError err = GetCartesianTransform(Group, &Trans[0], &Trans[1], &Trans[2], &Rotate[0], &Rotate[1], &Rotate[2]);
    Sleep(3);
    printf("CartesianTransform is: TransX: %f, TransY: %f, TransZ: %f, RotateZ: %f, RotateY: %f, RotateX: %f\n\n",
        Trans[0], Trans[1], Trans[2], Rotate[0], Rotate[1], Rotate[2]);
Display the MCS and PCS positions

After the transformation is done, we use GetGroupPosition to retrieve the MCS and PCS 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, mcMachineCoordSystem, mcSetValue, 3, MCSPositions);
GetGroupPosition(Group, mcProductCoordSystem, mcSetValue, 3, PCSPositions);
printf("MCS Positions: %f, %f, %f\n", MCSPositions[0], MCSPositions[1], MCSPositions[2]);
printf("PCS Positions: %f, %f, %f\n\n", PCSPositions[0], PCSPositions[1], PCSPositions[2]);

Complete code

The complete code should be as follows:

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

    //You must transform the ACS positions into MCS first, and then transform MCS into PCS.

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

    double MCSPositions[3] = { 0, 0, 0 };   //MCS positions.
    double PCSPositions[3] = { 0, 0, 0 };   //PCS positions.
    //double Positions[3] = { 0, 0, 0 };    //Set MCS positions to zero.

    /*KsCommandStatus Position = WaitForCommand(3, FALSE, SetGroupPositionOffset(Group, 3, Positions,
      FALSE, mcMachineCoordSystem, mcImmediately));*/
    KsCommandStatus SetCartesian = SetCartesianTransform(Group, 10, 20, 15, -45, 30, 20, mcImmediately);
    RtPrintf("SetCartesianTransform: Done: %d, ErrorID: %d\n", SetCartesian.Done, SetCartesian.ErrorId);

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

    double Trans[3] = { 0 };                //Points of translation.
    double Rotate[3] = { 0 };               //Angles of rotation.
    
    KsError err = GetCartesianTransform(Group, &Trans[0], &Trans[1], &Trans[2], &Rotate[0], &Rotate[1], &Rotate[2]);
    Sleep(3);
    printf("CartesianTransform is: TransX: %f, TransY: %f, TransZ: %f, RotateZ: %f, RotateY: %f, RotateX: %f\n\n",
        Trans[0], Trans[1], Trans[2], Rotate[0], Rotate[1], Rotate[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, mcMachineCoordSystem, mcSetValue, 3, MCSPositions);
    GetGroupPosition(Group, mcProductCoordSystem, mcSetValue, 3, PCSPositions);
    printf("MCS Positions: %f, %f, %f\n", MCSPositions[0], MCSPositions[1], MCSPositions[2]);
    printf("PCS Positions: %f, %f, %f\n\n", PCSPositions[0], PCSPositions[1], PCSPositions[2]);
}

 

Output: