RobotStudio event

How to align target using API?

I have created a wire on a face and an RsRobTarget at a point P on the wire.
I have created an RsTarget from the RsRobtarget and have set its transform so that it is correctly located at P.
I have calculated the Vector3 normal to the face at P, and the Vector3 tangent to the wire at P.

I would appreciate advice on how to align the target Z axis with the normal and the Y axis with the tangent.

Thanks,

Kevin


Comments

  • Hi Kevin,

    The x/y/z members of Matrix4 correspond to the axes of the coordinate system. So basically you set z = normal, y = tangent, and calculate x so you get a right-handed system.

    [code]            RsTarget target = ...
                Vector3 normal = ...
                Vector3 tangent = ...

                // Axes must be perpendicular
                System.Diagnostics.Debug.Assert(normal.Dot(tangent) == 0);
                Vector3 z = normal;
                z.Normalize();
                Vector3 y = tangent;
                y.Normalize();
                Vector3 x = y.Cross(z); // Matrix must be right-handed

                Matrix4 mat = target.Transform.GlobalMatrix;
                mat.UpperLeft = new Matrix3(x, y, z);
                target.Transform.GlobalMatrix = mat;
    [/code]

    /Johannes

    Johannes Weiman
    Software Engineer
    ABB Robotics

  • Many thanks Johannes,

    That positioned the target at the world origin, so I repositioned it to the selected 'point' using:[CODE]trg.Transform.X = point.x;
    trg.Transform.Y = point.y;
    trg.Transform.Z = point.z;[/CODE]
    The alignment appears not quite perfect. You can see that the Y and Z axes are deviating from the black normal and tangent lines. Do you have any idea why this might be?

    image

    Edit: If I create the target at the other end of the face the deviation from the normal is even greater ...

    image

    Regards,

    Kevin

    Kevin2010-01-20 11:28:58

  • Johannes explained via PM that Normals and Tangents have no position, only a direction.
    The normal is found using:
    [CODE]Bool = Face.GetNormalToSurface(testPoint, out hitPoint, out hitPointNormal);[/CODE] ... where hitPointNormal is a Vector3 position representing the end point of the unit normal with the normal translated so that its start point is at the world origin.
    To draw the normal correctly located at hitPoint it is necessary to use: [CODE]myNormal = Body.CreateLine(hitPoint, hitPoint + hitPointNormal);[/CODE] instead of [CODE]myNormal = Body.CreateLine(hitPoint, hitPointNormal);[/CODE]

    Kevin

    Kevin2010-01-26 10:25:33