How to align target using API?
Kevin
✭✭
in RobotStudio
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
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
0
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 Robotics0 -
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?
Edit: If I create the target at the other end of the face the deviation from the normal is even greater ...
Regards,
Kevin
Kevin2010-01-20 11:28:580 -
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:330
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 786 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings