本页面仅提供英文版本。
Get the robot position
Read the position of a Yaskawa robot from C# or Python: Cartesian position or joint pulses, which method to choose, and a polling loop. Complete program included.
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.
- 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
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 degreesRobotPositionCartesianData 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 axisRobotPositionIntData joints = robot.HighSpeedEServer.GetRobotJointPosition();Console.WriteLine("Pulses: " + string.Join(", ", joints.Axes));// Poll the position 10 times per second for 5 secondsfor (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();}}
The program:
- reads the Cartesian position of the tool, with its tool number and its posture;
- reads the pulses of each axis;
- 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. - The Cartesian position differs from the pendant: compare the frame and the tool.
DataTypeandToolNumbergive the ones of the answer. - The first call fails after a pause: a
SocketExceptionmeans that the controller did not answer beforeDataTimeoutMilliseconds. Check the network, then call again.
What to read next
- Positions: the reference of the position methods.
- Move the robot from a PC.