---
title: "Move a robot from a PC in C# and Python"
description: "Move Fanuc, Yaskawa, Universal Robots, ABB and Stäubli robots to a Cartesian target with one code: what each controller needs before a move, safety, C# and Python examples."
---

# Move a robot from a PC in C# and Python

This article shows how to move a Fanuc, Yaskawa, Universal Robots, ABB or Stäubli robot from a PC to a Cartesian target, with one code in C# or Python. The code of the move does not change from one brand to another. What changes is what each controller needs before it accepts a move from the network: the table at the end gives it.

## 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).
- The servo power on, see [State](/robotics/documentation/state), and the mode that accepts a move from the network on each controller. See the table at the end.
- The route of the moves enabled when it is marked (manual) in the table below. Until then, a move throws `RouteUnavailableException`, and its message says what to enable.

## Safety

The moves move the robot. A robot is dangerous machinery. Test your code on a simulator or an emulator first, then on the real robot with low speeds and a person at the emergency stop. The safety of the controller applies as for any remote command. `StopMotion` does not replace the emergency stop. The SDK does not replace a safety system: see the [Legal notice](/robotics/documentation/credits).

## 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.MoveJoint | RMI (manual) | Not available | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.MoveJointToPose | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.MoveLinear | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.MoveLinearToJoints | RMI (manual) | Not available | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.StopMotion | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Primary Interface (Script), Dashboard Server | Robot Web Services | SOAP |
| Motion.WaitForMotionEnd | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Dashboard Server, Primary Interface (Primary) | Robot Web Services | Not available |
| Methods of this article | **6 of 6** | **4 of 6** | **6 of 6** | **6 of 6** | **5 of 6** |

## Example

### Move each robot of a cell to a Cartesian target

The example connects to the controllers of a cell one after the other. It reads the current position, raises it by 50 mm and moves there with a joint interpolation at 10 % of the maximum speed. `MoveJointToPose` returns when the controller accepted the motion, without waiting for its end. `WaitForMotionEnd` waits for it on the brands that have it. On a brand without it, the example reads the position until it reaches the target.

The parameters of the brand give the settings of the moves. On Fanuc, the example enables RMI, the only route of the moves.

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

public class MotionMoveAllBrands
{
    static void Main()
    {
        /**/
        // Fanuc: RMI is the only route of the moves, and the library never opens it by itself
        UnderAutomation.Fanuc.ConnectionParameters fanuc = new UnderAutomation.Fanuc.ConnectionParameters("192.168.0.1");
        fanuc.Rmi.Enable = true;

        RobotConnectionParameters[] cell =
        {
            fanuc,
            new UnderAutomation.Yaskawa.ConnectParameters("192.168.0.2"),
            new UnderAutomation.UniversalRobots.ConnectParameters("192.168.0.3"),
            new UnderAutomation.ABB.ConnectionParameters("192.168.125.1"),
            new UnderAutomation.Staubli.ConnectionParameters("192.168.0.254"),
        };

        foreach (RobotConnectionParameters parameters in cell)
        {
            // The same code for each controller of this cell
            RobotController robot = new RobotController();
            robot.Connect(parameters);

            // ABB: take the RAPID mastership with the ABB SDK through robot.Native before the move
            // 50 mm up from the current position, joint interpolation at 10 % of the maximum speed
            RobotPosition target = robot.Motion.ReadPose();
            target.Pose.Z += 50;
            robot.Motion.MoveJointToPose(target, new MotionSpeed { Percent = 10 });

            if (robot.Motion.IsAvailable(MotionFeature.WaitForMotionEnd))
            {
                robot.Motion.WaitForMotionEnd(30000);
            }
            else
            {
                // No end of motion on this brand: wait until Z reaches the target, 30 s at most
                for (int i = 0; i < 300 && Math.Abs(robot.Motion.ReadPose().Pose.Z - target.Pose.Z) > 0.5; i++)
                    Thread.Sleep(100);
            }

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

**Python : MotionMoveAllBrands**
```python
import time

from underautomation.abb.connection_parameters import ConnectionParameters as AbbParameters
from underautomation.fanuc.connection_parameters import ConnectionParameters as FanucParameters
from underautomation.robotics.controllers.motion_feature import MotionFeature
from underautomation.robotics.controllers.motion_speed import MotionSpeed
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.staubli.connection_parameters import ConnectionParameters as StaubliParameters
from underautomation.universal_robots.connect_parameters import ConnectParameters as UrParameters
from underautomation.yaskawa.connect_parameters import ConnectParameters as YaskawaParameters

##
# Fanuc: RMI is the only route of the moves, and the library never opens it by itself
fanuc = FanucParameters("192.168.0.1")
fanuc.rmi.enable = True

cell = [
    fanuc,
    YaskawaParameters("192.168.0.2"),
    UrParameters("192.168.0.3"),
    AbbParameters("192.168.125.1"),
    StaubliParameters("192.168.0.254"),
]

for parameters in cell:
    # The same code for each controller of this cell
    robot = RobotController()
    robot.connect(parameters)

    # ABB: take the RAPID mastership with the ABB SDK through robot.native before the move
    # 50 mm up from the current position, joint interpolation at 10 % of the maximum speed
    target = robot.motion.read_pose()
    target.pose.z += 50
    speed = MotionSpeed()
    speed.percent = 10
    robot.motion.move_joint_to_pose(target, speed)

    if robot.motion.is_available(MotionFeature.WaitForMotionEnd):
        robot.motion.wait_for_motion_end(30000)
    else:
        # No end of motion on this brand: wait until Z reaches the target, 30 s at most
        for _ in range(300):
            if abs(robot.motion.read_pose().pose.z - target.pose.z) <= 0.5:
                break
            time.sleep(0.1)

    robot.disconnect()
##
```

In Python, the names are in snake_case: `robot.motion.move_joint_to_pose(target, speed)`, `robot.motion.wait_for_motion_end(30000)`, `robot.motion.is_available(...)`.

### Move along a line

`MoveLinear` moves the tool center point along a line to a Cartesian position. `Linear` of the `MotionSpeed` is the speed of the tool center point in mm/s. `MoveLinearToJoints` does it to a joint position, on the brands that have it.

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

public class MotionMoveLinear
{
    static void Main()
    {
        RobotController robot = new RobotController();
        robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));

        /**/
        RobotPosition target = robot.Motion.ReadPose();
        target.Pose.Z += 50;

        // Linear interpolation: tool center point at 100 mm/s
        MotionSpeed speed = new MotionSpeed { Linear = 100 };

        robot.Motion.MoveLinear(target, speed);
        robot.Motion.WaitForMotionEnd(30000);

        // Same move to joint values
        robot.Motion.MoveLinearToJoints(new JointValues(0, 0, 0, 0, -90, 0), speed);
        /**/

        robot.Disconnect();
    }
}
```

**Python : MotionMoveLinear**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters
from underautomation.robotics.controllers.motion_speed import MotionSpeed
from underautomation.robotics.geometry.joint_values import JointValues

robot = RobotController()
robot.connect(RobotConnectionParameters.create("fanuc", "192.168.0.1", ""))

##
target = robot.motion.read_pose()
target.pose.z += 50

# Linear interpolation: tool center point at 100 mm/s
speed = MotionSpeed()
speed.linear = 100

robot.motion.move_linear(target, speed)
robot.motion.wait_for_motion_end(30000)

# Same move to joint values
robot.motion.move_linear_to_joints(JointValues([0, 0, 0, 0, -90, 0]), speed)
##

robot.disconnect()
```

### Stop the motion

`StopMotion` stops a motion that was started by the moves of the library.

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

public class MotionStop
{
    static void Main()
    {
        RobotController robot = new RobotController();
        robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));

        /**/
        robot.Motion.StopMotion();
        /**/

        robot.Disconnect();
    }
}
```

**Python : MotionStop**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters

robot = RobotController()
robot.connect(RobotConnectionParameters.create("fanuc", "192.168.0.1", ""))

##
robot.motion.stop_motion()
##

robot.disconnect()
```

## What changes from one brand to another

The code does not change. Each controller has its own conditions for a move from the network. The moves that each brand has are in the support table above.

| Brand | Before a move | Brand article |
| --- | --- | --- |
| Fanuc | RMI, option R912 of the controller. The library never opens RMI by itself: set `Rmi.Enable` to true in the connection parameters. RMI takes the motion control of the controller. | [Move the robot remotely](/fanuc/documentation/move-robot-remotely) |
| Yaskawa | Servo power, remote mode and play mode. | [Move the robot](/yaskawa/documentation/how-to-move-robot) |
| Universal Robots | On e-Series and PolyScope X, the robot is in remote control. The default route sends a script: the program that runs on the robot stops. | [Move the robot](/universal-robots/documentation/how-to-move-robot) |
| ABB | One RAPID module, [UnderAutomationMotion.mod](https://github.com/underautomation/Robotics.NET/blob/main/Rapid/UnderAutomationMotion.mod), loaded once in the motion task of the robot, automatic mode, and the RAPID mastership taken with the ABB SDK through `robot.Native`. Without the module, `IsAvailable` returns true and a move throws `RouteUnavailableException`. See [Routing](/robotics/documentation/routing). | [Motion](/abb/documentation/rws-motion) |
| Stäubli | Remote mode, and no application that holds the arm. The moves use the flange as the tool and the world as the frame. | [Move the robot](/staubli/documentation/how-to-move-robot) |

The page [Motion](/robotics/documentation/motion) explains the targets, the configuration, the speeds and the joint moves.

## Errors

- `FeatureNotSupportedException`: the brand has no route for the method, for example `MoveJoint` on Yaskawa.
- `RouteUnavailableException`: the method has routes, but none can be used, for example RMI not enabled on Fanuc, or the RAPID module missing on ABB.
- `ControllerRefusedException`: the controller received the move and refused it, for example because it is not in the right mode.
- `RobotControllerException`: the route failed. Its inner exception is the exception of the brand SDK. `WaitForMotionEnd` throws it with an inner `TimeoutException` when the motion is not finished after the timeout.

The page [Errors](/robotics/documentation/errors) explains each exception.

## What to read next

- [Motion](/robotics/documentation/motion): every method of the Motion service.
- [Get the current position of a robot](/robotics/documentation/how-to-get-position): read a target before a move.
- [Routing settings](/robotics/documentation/routing-settings): enable a route that is off at start.