Transforming Target
This example provides information on reassociating targets with respect to another workobject without repositioning. This example expects targets are already created and a workobject with the name "WorkObject1" exists in RobotStudio.
You need to pass objects of RsTargetCollection and RsWorkObject to this tutorial. When the code example is executed the targets would be now part of the new workobject (in this case it would be "WorkObject1").
Use this procedure to reassociate targets with the different work object:
Get global matrix of newWorkobject.
Inverse the global matrix of newWorkobject.
Get target frame global matrix.
Get new matrix value for target with respect to newWorkobject.
Change the workobject of target.
Assign final matrix to target local matrix.
Solution
Get global matrix of newWorkobject.
Matrix4 woObjectFrameGlobalMatrix = newWorkObject.ObjectFrame.GlobalMatrix;
Inverse the global matrix of newWorkobject.
woObjectFrameGlobalMatrix.InvertRigid();
Get target frame global matrix.
Matrix4 targetFramMatrix = target.RobTarget.Frame.GlobalMatrix;
Get new matrix value for target with respect to newWorkobject.
Matrix4 finalMatrix = woObjectFrameGlobalMatrix * targetFramMatrix;
Change the workobject of target.
target.WorkObject = newWorkObject;
Assign final matrix to target local matrix.
target.RobTarget.Frame.Matrix = finalMatrix;
Example
This example provides information on reassociating targets with respect to another workobject without repositioning.
private static void TransformTargetBasedOnNewWorkObject(RsTargetCollection targets,
RsWorkObject newWorkObject)
{
try
{
foreach (RsTarget target in targets)
{
//Check associated workobject with target is equal to the newWorkobject
//if both are equal then the further steps will not execute
if (!target.WorkObject.Equals(newWorkObject))
{
//Get global matrix of newWorkobject
Matrix4 woObjectFrameGlobalMatrix = newWorkObject.ObjectFrame.GlobalMatrix;
//Inverse the global matrix of newWorkobject
woObjectFrameGlobalMatrix.InvertRigid();
//Get target frame global matrix
Matrix4 targetFramMatrix = target.RobTarget.Frame.GlobalMatrix;
//Get new matrix value for target with respect to newWorkobject
Matrix4 finalMatrix = woObjectFrameGlobalMatrix * targetFramMatrix;
//Change the workobject of target
target.WorkObject = newWorkObject;
//Assign final matrix to target local matrix
target.RobTarget.Frame.Matrix = finalMatrix;
}
}
}
catch (Exception exception)
{
Logger.AddMessage(new LogMessage(exception.Message.ToString()));
}
}
Required Namespaces
ABB.Robotics.RobotStudio.Stations