UnderAutomation
¿Una pregunta?

[email protected]

Contactos
UnderAutomation
⌘Q
Esta página solo está disponible en inglés.

Get the current position of a robot in C# and Python

Read the Cartesian pose of Fanuc, Yaskawa, Universal Robots, ABB and Stäubli robots with one code, in mm and degrees, and the joints where the brand gives them. Brand support table, C# and Python examples.

  • Prerequisites
  • Brand support
  • Example
  • Read the position of each robot of a cell
  • Read another motion group
  • What changes from one brand to another
  • Errors
  • What to read next

This article shows how to read the current position of a robot from a PC on Fanuc, Yaskawa, Universal Robots, ABB and Stäubli controllers, with one code in C# or Python. The result is the same type on every brand, in mm and degrees: only the address of the controller changes in the code.

Prerequisites

  • UnderAutomation.Robotics in your project. See Get started with .NET or Get started with Python.
  • The connection settings of each controller. See Connect to your robot.
  • The license of each brand you connect, or the 30 day trial. See Licensing.
  • Reading the position does not move the robot and does not need the servo power.

Brand support

Each cell gives the protocol that the method uses on this brand, in the default order. The table is generated from the route data of the library. "Not available" means that the brand has no route for the method: the call throws FeatureNotSupportedException, and IsAvailable returns false before the call. (manual) marks a route that you enable yourself in the connection parameters.

Motion
MethodFanucYaskawaUniversal RobotsABBStäubli
Motion.ReadPoseSNPX, CGTP (Cgtp), RMI (manual), FTPHigh Speed Ethernet Server, Ethernet ServerRTDE, Primary Interface (Primary)Robot Web ServicesSOAP
Motion.ReadJointsSNPX, CGTP (Cgtp), RMI (manual), FTPNot availableRTDE, Primary Interface (Primary)Robot Web ServicesSOAP
Methods of this article2 of 21 of 22 of 22 of 22 of 2

Example

Read the position of each robot of a cell

The example connects to the controllers of a cell one after the other and reads the position of the motion group 1. ReadPose returns a RobotPosition: Pose is the Cartesian pose of the tool center point (X, Y, Z and the orientation), with the configuration, the frame and the tool. ReadJoints returns the joint values in degrees, mm for a linear axis.

A brand without ReadJoints returns false for IsAvailable(MotionFeature.ReadJoints). This is the case of Yaskawa: the common API gives no joint values on this brand, and HasJoints of the pose is false. The Yaskawa SDK reads them through robot.Native.

static void Main()
{
// One line per controller: only the brand and the address change
var cell = new[]
{
(Brand: "fanuc", Address: "192.168.0.1"),
(Brand: "yaskawa", Address: "192.168.0.2"),
(Brand: "universalrobots", Address: "192.168.0.3"),
(Brand: "abb", Address: "192.168.125.1"),
(Brand: "staubli", Address: "192.168.0.254"),
};
foreach (var controller in cell)
{
// The same code for each controller of this cell
RobotController robot = new RobotController();
robot.Connect(RobotConnectionParameters.Create(controller.Brand, controller.Address));
// Cartesian position of the motion group 1, in mm and degrees
RobotPosition position = robot.Motion.ReadPose();
Console.WriteLine($"{robot.Brand}: X {position.Pose.X}, Y {position.Pose.Y}, Z {position.Pose.Z}");
// False on Yaskawa: the common API gives no joint values on this brand, the Yaskawa SDK reads them through robot.Native
if (robot.Motion.IsAvailable(MotionFeature.ReadJoints))
Console.WriteLine(string.Join(", ", robot.Motion.ReadJoints().Values));
robot.Disconnect();
}
}
}
Click to see the full code

In Python, the names are in snake_case: robot.motion.read_pose(), robot.motion.read_joints(), position.has_joints.

Read another motion group

ReadPose(group) and ReadJoints(group) take the number of the motion group, from 1. A controller with two robots or a positioner has several groups. robot.Info.ReadGroups() lists them: see Info.

A position that you read can be given back to a move as it is. See Move a robot from a PC.

What changes from one brand to another

The code does not change. The frame and the tool of the pose are the ones that the controller gives. Frame and Tool of the result give them, and -1 means the frame or the tool active on the controller.

BrandNotesBrand article
FanucGet the current position
YaskawaNo joint values in the common API: HasJoints is false. The Yaskawa SDK reads them through robot.Native.Get the position
Universal RobotsThe library converts the metres and radians of the controller to mm and degrees.Get the position
ABBGet the robot position
StäubliThe pose is always the flange in the world frame, not the active tool and frame. Frame and Tool are -1. The library converts the metres and radians of the controller to mm and degrees.Get the position

The page Motion describes RobotPosition, the configuration and the kinematics.

Errors

  • FeatureNotSupportedException: the brand has no route for the method, for example ReadJoints on Yaskawa.
  • RouteUnavailableException: the method has routes, but none can be used, for example because the protocol did not answer at the connection.
  • RobotControllerException: the route failed. Its inner exception is the exception of the brand SDK.

The page Errors explains each exception.

What to read next

  • Motion: kinematics, frames, tools and the kinematic model.
  • Move a robot from a PC: give a position back as a target.
  • Monitor the state of a robot controller: follow the controllers of a cell.