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.
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.
| Method | Fanuc | Yaskawa | Universal Robots | ABB | Stäubli |
|---|---|---|---|---|---|
| Motion.ReadPose | SNPX, CGTP (Cgtp), RMI (manual), FTP | High Speed Ethernet Server, Ethernet Server | RTDE, Primary Interface (Primary) | Robot Web Services | SOAP |
| Motion.ReadJoints | SNPX, CGTP (Cgtp), RMI (manual), FTP | Not available | RTDE, Primary Interface (Primary) | Robot Web Services | SOAP |
| Methods of this article | 2 of 2 | 1 of 2 | 2 of 2 | 2 of 2 | 2 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 changevar 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 cellRobotController robot = new RobotController();robot.Connect(RobotConnectionParameters.Create(controller.Brand, controller.Address));// Cartesian position of the motion group 1, in mm and degreesRobotPosition 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.Nativeif (robot.Motion.IsAvailable(MotionFeature.ReadJoints))Console.WriteLine(string.Join(", ", robot.Motion.ReadJoints().Values));robot.Disconnect();}}}
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.
| Brand | Notes | Brand article |
|---|---|---|
| Fanuc | Get the current position | |
| Yaskawa | No joint values in the common API: HasJoints is false. The Yaskawa SDK reads them through robot.Native. | Get the position |
| Universal Robots | The library converts the metres and radians of the controller to mm and degrees. | Get the position |
| ABB | Get the robot position | |
| Stäubli | The 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 exampleReadJointson 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.