---
title: "Get the current position of a robot in C# and Python"
description: "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."
---

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

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](/robotics/documentation/get-started-net) or [Get started with Python](/robotics/documentation/get-started-python).
- The connection settings of each controller. See [Connect to your robot](/robotics/documentation/connect).
- The license of each brand you connect, or the 30 day trial. See [Licensing](/robotics/documentation/license).
- 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.

Routes of each method in the default order. The first route is used, the next ones are fallbacks. (manual) marks a route that you enable yourself.

| 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`.

**C# : MotionReadPoseAllBrands**
```csharp
using UnderAutomation.Robotics.Controllers;

public class MotionReadPoseAllBrands
{
    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();
        }
        /**/
    }
}
```

**Python : MotionReadPoseAllBrands**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters
from underautomation.robotics.controllers.motion_feature import MotionFeature

##
# One line per controller: only the brand and the address change
cell = [
    ("fanuc", "192.168.0.1"),
    ("yaskawa", "192.168.0.2"),
    ("universalrobots", "192.168.0.3"),
    ("abb", "192.168.125.1"),
    ("staubli", "192.168.0.254"),
]

for brand, address in cell:
    # The same code for each controller of this cell
    robot = RobotController()
    robot.connect(RobotConnectionParameters.create(brand, address, ""))

    # Cartesian position of the motion group 1, in mm and degrees
    position = robot.motion.read_pose()
    print(f"{robot.brand.name}: 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.is_available(MotionFeature.ReadJoints):
        print(", ".join(str(value) for value in robot.motion.read_joints().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](/robotics/documentation/info).

A position that you read can be given back to a move as it is. See [Move a robot from a PC](/robotics/documentation/how-to-move-robot).

## 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](/fanuc/documentation/get-current-position) |
| Yaskawa | No joint values in the common API: `HasJoints` is false. The Yaskawa SDK reads them through `robot.Native`. | [Get the position](/yaskawa/documentation/how-to-get-position) |
| Universal Robots | The library converts the metres and radians of the controller to mm and degrees. | [Get the position](/universal-robots/documentation/how-to-get-position) |
| ABB | | [Get the robot position](/abb/documentation/get-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](/staubli/documentation/how-to-get-position) |

The page [Motion](/robotics/documentation/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](/robotics/documentation/errors) explains each exception.

## What to read next

- [Motion](/robotics/documentation/motion): kinematics, frames, tools and the kinematic model.
- [Move a robot from a PC](/robotics/documentation/how-to-move-robot): give a position back as a target.
- [Monitor the state of a robot controller](/robotics/documentation/how-to-monitor-state): follow the controllers of a cell.