Show / Hide Table of Contents

Rotating Target around axis

This example provides information on rotating target by an angle (in degree) around x/y/z axis. This example expects targets are already created in RobotStudio.

You need to pass objects of RsTarget , RotateAxis type to this tutorial.

Use this procedure to rotate target's global matrix:

  1. Create Vector3 object which stores the target's global matrix translation value.

    Note

    This object will be used as a relative point required to rotate the target.

  2. Create rotation axis (say rotationAxis1) which is required to rotate the target around rotationAxis1.

  3. Create temporary Matrix4 object (say tempMatrix1). Rotate tempMatrix1 by angleInDegree, relative to point1, around rotationAxis1.

  4. Re-assign tempMatrix1 to RobTarget's frame local matrix.

Solution

This examples provides information on rotating target's global matrix. It uses the overloaded Rotate function of Matrix4 which accepts 3 parameters.

  1. Create Vector3 object which stores the target's global matrix translation value.

    Vector3 point1 = target.Transform.GlobalMatrix.Translation;
    
  2. Create rotation axis (say rotationAxis1) which is required to rotate the target around rotationAxis1.

    Vector3 rotationAxis1 = new Vector3();
    switch (Convert.ToInt32(value))
    {
        case 0:
            rotationAxis1 = new Vector3(target.Transform.GlobalMatrix.x.x ,
                target.Transform.GlobalMatrix.x.y ,
                target.Transform.GlobalMatrix.x.z);
            break;
        case 1:
            rotationAxis1 = new Vector3(target.Transform.GlobalMatrix.y.x ,
                target.Transform.GlobalMatrix.y.y ,
                target.Transform.GlobalMatrix.y .z);
            break;
        case 2:
            rotationAxis1 = new Vector3(target.Transform.GlobalMatrix.z.x ,
                target.Transform.GlobalMatrix.z.y ,
                target.Transform.GlobalMatrix.z.z);
            break;
    }
    
  3. Create temporary Matrix4 object (say tempMatrix1). Rotate tempMatrix1 by angleInDegree, relative to point1, around rotationAxis1.

    Matrix4 tempMatrix1 = target.Transform.GlobalMatrix;
    tempMatrix1.Rotate(point1 ,rotationAxis1 ,
    ABB.Robotics.Math.Globals.DegToRad(angleInDegree));
    
  4. Re-assign tempMatrix1 to RobTarget's frame local matrix.

    target.RobTarget.Frame.Matrix = tempMatrix1;
    

Example

This example shows how to rotate target with some angle around axis.

/// <summary>
/// Axis of rotation
/// </summary>
enum RotateAxis : int
{ X = 0 , Y = 1 , Z = 2 } ;  

/// <summary>
/// Rotate target with angle around "RotateAxis" value 
/// </summary>
/// <param name="target">Target which will rotate</param>
/// <param name="value">Around rotation axis</param>
/// <param name="angleInDegree">Angle in degree</param>
private static void Rotate(RsTarget target, RotateAxis value,double angleInDegree)
{
    //Create Vector3 object which stores the target's global matrix translation value.   
    Vector3 point1 = target.Transform.GlobalMatrix.Translation;

    //Create rotation axis (say rotationAxis1) which is required to rotate 
    //the target around rotationAxis1. 
    Vector3 rotationAxis1 = new Vector3();
    switch (Convert.ToInt32(value))
    {
        case 0:
            rotationAxis1 = new Vector3(target.Transform.GlobalMatrix.x.x ,
                target.Transform.GlobalMatrix.x.y ,
                target.Transform.GlobalMatrix.x.z);
            break;
        case 1:
            rotationAxis1 = new Vector3(target.Transform.GlobalMatrix.y.x ,
                target.Transform.GlobalMatrix.y.y ,
                target.Transform.GlobalMatrix.y .z);
            break;
        case 2:
            rotationAxis1 = new Vector3(target.Transform.GlobalMatrix.z.x ,
                target.Transform.GlobalMatrix.z.y ,
                target.Transform.GlobalMatrix.z.z);
            break;
    }

    //Create temporary Matrix4 object (say tempMatrix1). 
    //Rotate tempMatrix1 by angleInDegree, relative to point1, around rotationAxis1. 
    Matrix4 tempMatrix1 = target.Transform.GlobalMatrix;
    tempMatrix1.Rotate(point1 ,rotationAxis1 ,
    ABB.Robotics.Math.Globals.DegToRad(angleInDegree));

    //Re-assign tempMatrix1 to RobTarget's frame local matrix. 
    target.RobTarget.Frame.Matrix = tempMatrix1;
}

Required Namespaces

ABB.Robotics.Math

ABB.Robotics.RobotStudio.Stations

See Also

  • Rotate with respect to axis
In this article
Back to top Copyright © 2024 ABB