Get the robot position
Read the position of a Staubli robot from C# or Python: joints, flange or tool position, and which method to choose. Complete program included.
This article shows how to read the current position of a Staubli robot from a PC, in C# or Python, on a CS8 or CS9 controller. It compares the three ways that the SDK offers, then gives a complete program that prints the position of a tool 10 times per second.
Prerequisites
- The PC reaches the controller, and the SDK is connected: see Connect to your robot.
- Nothing else: reading the position does not need the remote mode, the power or a VAL 3 program.
Which method to choose
| You need | Method | Requests |
|---|---|---|
| The joint values only | GetCurrentJointPosition(robot) | 1 |
| The joints and the flange or tool position | GetCurrentCartesianJointPosition(robot, tool, frame) | 1 |
| The Cartesian position of joint values that you have | ForwardKinematics(robot, joints) | 1 |
- For a Cartesian position,
GetCurrentCartesianJointPositionis the right choice: it gives the joints too, in the same request. - Pass a
toolto get the position of the tool center point instead of the flange, and aframeto get it in the frame of your part instead of the world frame. ForwardKinematicsreturns a full frame with its rotation matrix, and the configuration of the arm. Use it for positions that are not the current one.
Example
using UnderAutomation.Staubli;using UnderAutomation.Staubli.Soap.Data;public class HowToGetPosition{static void Main(){var controller = new StaubliController();controller.Connect("192.168.0.254");// Tool center point, 150 mm along Z of the flangevar tool = new CartesianPosition { Z = 0.150 };// Read the position 10 times per second, for 5 secondsfor (int i = 0; i < 50; i++){CartesianJointPosition position = controller.Soap.GetCurrentCartesianJointPosition(robot: 0, tool, frame: null);CartesianPosition tcp = position.CartesianPosition;// Meters to millimeters, radians to degreesConsole.WriteLine($"X={tcp.X * 1000:F1} Y={tcp.Y * 1000:F1} Z={tcp.Z * 1000:F1} mm, " +$"J1={position.JointsPosition[0] * 180 / Math.PI:F2} deg");Thread.Sleep(100);}controller.Disconnect();}}
The SDK gives meters and radians. The program converts them to millimeters and degrees to print them.
Polling period
Each read is one request to the controller. Its duration depends on the network and on the load of the controller: measure it on your cell (with a Stopwatch in C#, time.perf_counter() in Python) before you choose the period of your loop. Do not read faster than you need.
Troubleshooting
- The Cartesian position does not match the pendant: the pendant shows the position of the current tool in the current frame. Pass the same tool and frame to
GetCurrentCartesianJointPosition. InvalidRobotIdCode: therobotargument does not match an arm of the controller. Use0for the first arm, and seeGetRobots().- Values look too small: they are in meters and radians. Multiply by 1000 for millimeters, and by 180/π for degrees.
What to read next
- Position: the reference of the position methods.
- Kinematics: forward and inverse kinematics.
- Move the robot from a PC.