Show / Hide Table of Contents

Creating and Configuring RsRobTarget

This example shows you how to create and configure an RsRobTarget. You need a station with an IRB140 for it to work.

The RsRobTarget created has the position and rotation of the home position of an IRB140. Since a target can have multiple configurations, we will select the first one. Given that we have a valid configuration, we set the ConfigurationStatus to defined, and print the configuration in the logger (the output window in RobotStudio).

Example

Project.UndoContext.BeginUndoStep("RsRobTargetExample");
try
{
    // NOTE: This example requires a station containing an IRB_140 and a running VC.
    Station station = Station.ActiveStation;

    // Create a RobTarget, corresponding to the home position of an IRB_140.
    RsRobTarget myRobTarget = new RsRobTarget();

    // Set the name of the RobTarget.
    myRobTarget.Name = station.ActiveTask.GetValidRapidName("Target", "_", 10);

    // Set the position and rotation of the RobTarget.
    myRobTarget.Frame.X = 0.50629;
    myRobTarget.Frame.Y = 0;
    myRobTarget.Frame.Z = 0.67950;
    myRobTarget.Frame.RX = Globals.DegToRad(180); // From ABB.Robotics.Math
    myRobTarget.Frame.RY = Globals.DegToRad(60);
    myRobTarget.Frame.RZ = Globals.DegToRad(180);

    // Add the RobTarget to the DataDeclarations of the ActiveTask.
    station.ActiveTask.DataDeclarations.Add(myRobTarget);

    // Set the RobTarget to not be an inline declaration.
    myRobTarget.IsInline = false;

    // Create an RsTarget for the RobTarget, to give it a graphical representation and use it to get configs.
    RsTarget myRsTarget = new RsTarget(station.ActiveTask.ActiveWorkObject, myRobTarget);
    myRsTarget.Name = myRobTarget.Name;

    // Add it to the ActiveTask.
    station.ActiveTask.Targets.Add(myRsTarget);

    bool includeTurns = true; // Include turns = all solutions

    // Get all the solutions for the RobTarget using the mechanism.
    ConfigurationData[] myConfs = await station.ActiveTask.Mechanism.GetAllConfigurationsAsync(myRsTarget, station.ActiveTask.ActiveTool, includeTurns);
    if (myConfs.Length > 0)
    {
        // Assign the first available configuration to the RobTarget.
        myRobTarget.ConfigurationData = myConfs[0];

        // Set the ConfigurationStatus as defined, since there is a valid config.
        myRobTarget.ConfigurationStatus = ConfigurationStatus.Defined;

        // Output the config.
        Logger.AddMessage(new LogMessage($"The configuration of RobTarget: '{myRobTarget.Name}' is: " +
            $"'[{myRobTarget.ConfigurationData.Cf1}, {myRobTarget.ConfigurationData.Cf4}," +
            $" {myRobTarget.ConfigurationData.Cf6}, {myRobTarget.ConfigurationData.Cfx}]'"));
    }
    else
    {
        // Could not find any valid configurations fo the RobTarget.
        // Set the configuration status to no solutions.
        myRobTarget.ConfigurationStatus = ConfigurationStatus.NoSolutions;

        // Output a message.
        Logger.AddMessage(new LogMessage($"There is no configuration for robtarget: '{ myRobTarget.Name }'"));
    }
}
catch
{
    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
    throw;
}
finally
{
    Project.UndoContext.EndUndoStep();
}

See Also

  • RsRobTarget
  • RsTarget
  • ConfigurationData
In this article
Back to top Copyright © 2025 ABB