This article shows how to read the position of a Yaskawa Motoman robot from a PC, in C# or Python. It gives a complete program that reads the Cartesian position and the joint pulses, then polls the position 10 times per second.

## Prerequisites

- The SDK is connected to the controller: see [Connect to your robot](/yaskawa/documentation/connect).
- Nothing else: reading the position works in teach mode and in play mode, without the remote mode.

## Which method to choose

| Need                                       | Method                              | Unit                           |
| ------------------------------------------ | ----------------------------------- | ------------------------------ |
| Where the tool is, to log it or to compute | `GetRobotCartesianPosition()`       | mm and degrees, robot frame    |
| A position to send back with `MoveJoints`  | `GetRobotJointPosition()`           | Encoder pulses per axis        |
| The load of the axes during a move         | `GetTorque()`, `GetPositionError()` | Percent, pulses                |
| A position taught in a job                 | `ReadPositionVariable(n, 1)`        | Raw units of the `P` variable  |
| A second robot, base axes                  | `GetRobotPosition(group)`           | Pulses or raw Cartesian values |

## Example

**C# : HowToGetPosition**
```csharp
using UnderAutomation.Yaskawa;
using UnderAutomation.Yaskawa.HighSpeedEServer;

public class HowToGetPosition
{
    static void Main()
    {
        /**/
        var robot = new YaskawaRobot();
        robot.Connect("192.168.0.1");

        // Tool center point in the robot frame: mm and degrees
        RobotPositionCartesianData tcp = robot.HighSpeedEServer.GetRobotCartesianPosition();
        Console.WriteLine($"X={tcp.X:F3} Y={tcp.Y:F3} Z={tcp.Z:F3} Rx={tcp.Rx:F4} Ry={tcp.Ry:F4} Rz={tcp.Rz:F4}");
        Console.WriteLine($"Tool {tcp.ToolNumber}, posture {tcp.Form}");

        // Joints: encoder pulses, one value per axis
        RobotPositionIntData joints = robot.HighSpeedEServer.GetRobotJointPosition();
        Console.WriteLine("Pulses: " + string.Join(", ", joints.Axes));

        // Poll the position 10 times per second for 5 seconds
        for (int i = 0; i < 50; i++)
        {
            tcp = robot.HighSpeedEServer.GetRobotCartesianPosition();
            Console.WriteLine($"{DateTime.Now:HH:mm:ss.fff} X={tcp.X:F1} Y={tcp.Y:F1} Z={tcp.Z:F1}");
            Thread.Sleep(100);
        }

        robot.Disconnect();
        /**/
    }
}
```

**Python : HowToGetPosition**
```python
import time
from datetime import datetime
from underautomation.yaskawa.yaskawa_robot import YaskawaRobot
from underautomation.yaskawa.connect_parameters import ConnectParameters

##
robot = YaskawaRobot()
robot.connect(ConnectParameters("192.168.0.1"))

# Tool center point in the robot frame: mm and degrees
tcp = robot.high_speed_e_server.get_robot_cartesian_position()
print(f"X={tcp.x:.3f} Y={tcp.y:.3f} Z={tcp.z:.3f} Rx={tcp.rx:.4f} Ry={tcp.ry:.4f} Rz={tcp.rz:.4f}")
print(f"Tool {tcp.tool_number}, posture {tcp.form}")

# Joints: encoder pulses, one value per axis
joints = robot.high_speed_e_server.get_robot_joint_position()
print("Pulses:", list(joints.axes))

# Poll the position 10 times per second for 5 seconds
for _ in range(50):
    tcp = robot.high_speed_e_server.get_robot_cartesian_position()
    print(f"{datetime.now():%H:%M:%S.%f} X={tcp.x:.1f} Y={tcp.y:.1f} Z={tcp.z:.1f}")
    time.sleep(0.1)

robot.disconnect()
##
```

The program:

1. reads the Cartesian position of the tool, with its tool number and its posture;
2. reads the pulses of each axis;
3. reads the Cartesian position every 100 ms for 5 seconds.

## Polling period

Each read is one request and one answer over the network. On a local network, a request takes a few milliseconds: measure it on your cell before you choose the period. Read only what you need in a loop: the Cartesian position alone is one request, the position and the joints are two.

## Troubleshooting

- **The values are all `0`:** check the control group and the number of axes with [GetConfigurationInformation](/yaskawa/documentation/hses-system#axis_names).
- **The Cartesian position differs from the pendant:** compare the frame and the tool. `DataType` and `ToolNumber` give the ones of the answer.
- **The first call fails after a pause:** a `SocketException` means that the controller did not answer before `DataTimeoutMilliseconds`. Check the network, then call again.

## What to read next

- [Positions](/yaskawa/documentation/hses-positions): the reference of the position methods.
- [Move the robot from a PC](/yaskawa/documentation/how-to-move-robot).