Show / Hide Table of Contents

Create RsMoveInstruction Example

This example loads a mechanism (a robot) to the current station, and sets it as the active task. It creates a work object for the active task and tool data for the robot. It creates a RsRobTarget and a RsTarget, which is the RsRobTargets graphical representation. It creates a path and adds some move instructions to it.

Compiling the Code

Note

You need to uncomment two lines in this example and change the path to your RobotStudio directory. There is also a comment in the code that you need to do this.

Example

Project.UndoContext.BeginUndoStep("RsMoveInstructionCreate");
try
{
    Station station = Station.ActiveStation;

    // First import a robot (a mechanism) and add it to the station.
    GraphicComponentLibrary mechLib = GraphicComponentLibrary.Load("IRB140_6_81_C_G_03.rslib", true);
    Mechanism mechGfx = (Mechanism)mechLib.RootComponent.CopyInstance();
    mechGfx.Name = "IRB140_6_81_C_G_03";
    station.GraphicComponents.Add(mechGfx);

    // Set the active task to the mechanism task.
    station.ActiveTask = mechGfx.Task;

    // Create a WorkObject and add it to the ActiveTask.
    RsWorkObject myWobj = new RsWorkObject();
    myWobj.Name = station.ActiveTask.GetValidRapidName("myWobj", "_", 1);
    station.ActiveTask.DataDeclarations.Add(myWobj);

    // Create a ToolData and add it to the ActiveTask.
    RsToolData myTool = new RsToolData();
    myTool.Name = station.ActiveTask.GetValidRapidName("myTool", "_", 1);
    station.ActiveTask.DataDeclarations.Add(myTool);

    // Create a new RobTarget and add it to the ActiveTask.
    RsRobTarget toPoint = new RsRobTarget();
    toPoint.Name = station.ActiveTask.GetValidRapidName("myRobTarget", "_", 1);
    station.ActiveTask.DataDeclarations.Add(toPoint);

    // Create a graphic representation of the RobTarget and RsTarget.
    RsTarget myRsTarget = new RsTarget(myWobj, toPoint);
    myRsTarget.Name = toPoint.Name;
    station.ActiveTask.Targets.Add(myRsTarget);

    // Create a PathProcedure.
    RsPathProcedure myPath = new RsPathProcedure("myPath");
    station.ActiveTask.PathProcedures.Add(myPath);

    // Create a linear move instruction using the move definition and the default template.
    RsMoveInstruction myMoveL = new RsMoveInstruction
        (station.ActiveTask, "Move", "Default",
        MotionType.Linear, myWobj.Name, toPoint.Name, myTool.Name);
    myPath.Instructions.Add(myMoveL);

    // Create a new RobTarget to use as cirPoint and add it to the ActiveTask.
    RsRobTarget cirPoint = new RsRobTarget();
    cirPoint.Name = station.ActiveTask.GetValidRapidName("myRobTarget", "_", 1);
    cirPoint.Frame.X = cirPoint.Frame.X + 0.10;
    cirPoint.Frame.Z = cirPoint.Frame.Z + 0.10;
    station.ActiveTask.DataDeclarations.Add(cirPoint);

    // Create a graphic representation of the RobTarget and RsTarget.
    RsTarget myRsTarget_2 = new RsTarget(myWobj, cirPoint);
    myRsTarget_2.Name = cirPoint.Name;
    station.ActiveTask.Targets.Add(myRsTarget_2);

    // Create a circular move instruction.
    RsMoveInstruction myMoveCirc = new RsMoveInstruction(station.ActiveTask,
        "Move", "Default", myWobj.Name, cirPoint.Name, toPoint.Name, myTool.Name);
    myPath.Instructions.Add(myMoveCirc);

    // Create a joint target to be able to create a MoveAbsJ move instruction.
    RsJointTarget myJointTarget = new RsJointTarget();
    myJointTarget.Name = station.ActiveTask.GetValidRapidName("myJointTarget", "_", 1);
    station.ActiveTask.DataDeclarations.Add(myJointTarget);

    // Set the robot axis values.
    RobotAxisValues rbAxis = new RobotAxisValues();
    rbAxis.Rax_1 = 70.0000000000001;
    rbAxis.Rax_2 = -30;
    rbAxis.Rax_3 = 30;
    rbAxis.Rax_4 = -55.0000000000001;
    rbAxis.Rax_5 = 40;
    rbAxis.Rax_6 = 10;
    myJointTarget.SetRobotAxes(rbAxis, false);

    // Create a MoveAbsJ move instruction (this only makes sense if there is a mechanism in the station).
    RsMoveInstruction myMoveAbsJ =
        new RsMoveInstruction(station.ActiveTask, "MoveAbs", "Default", myJointTarget.Name);
    myPath.Instructions.Add(myMoveAbsJ);

    // Create a MoveAbsL move instruction (this only makes sense if there is a mechanism in the station).
    RsMoveInstruction myMoveAbsL =
        new RsMoveInstruction(station.ActiveTask, "MoveAbs", "Default", myJointTarget.Name, MotionType.Linear);
    myPath.Instructions.Add(myMoveAbsL);
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

See Also

  • GraphicComponentLibrary
  • Mechanism
  • RsWorkObject
  • RsToolData
  • RsRobTarget
  • RsTarget
  • RsPathProcedure
  • RsMoveInstruction
  • RsJointTarget
  • RobotAxisValues
  • RobotStudio Community
In this article
Back to top Copyright © 2025 ABB