---
title: "State: operating mode and servo power"
description: "Read the operating mode, servo power, running and alarm state, and switch the servo power on and off with robot.State. Brand support table, C# and Python examples."
---

# State: operating mode and servo power

`robot.State` reads the state of a robot controller (operating mode, servo power, program execution, alarm) and switches the servo power on and off. The result types are the same for Fanuc, Yaskawa, Universal Robots, ABB and Stäubli controllers. The methods that you can call depend on the brand: see the table below.

## Prerequisites

- A connected `RobotController`. See [Connect to your robot](/robotics/documentation/connect).
- The license of the brand of the controller, or the 30 day trial. See [Licensing](/robotics/documentation/license).
- For `ServoOn` and `ServoOff`: the controller can need its remote mode. A controller that refuses the command throws `ControllerRefusedException` (see [Errors](/robotics/documentation/errors)).

## Brand support

Each cell gives the protocol that the method uses on this brand, in the default order. The page [Routing](/robotics/documentation/routing) explains how the library chooses it. The table is generated from the route data of the library. (manual) marks a route that you enable yourself. "n of m" is the number of methods of the service that have a route on this brand.

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 |
| --- | --- | --- | --- | --- | --- |
| State.Read | SNPX, FTP | High Speed Ethernet Server, Ethernet Server | Dashboard Server, Primary Interface (Primary) | Robot Web Services | Not available |
| State.ServoOn | CGTP (CgtpKcl), Telnet, SNPX, RMI (manual) | High Speed Ethernet Server, Ethernet Server | Dashboard Server, REST API, Primary Interface (Primary) | Robot Web Services | SOAP |
| State.ServoOff | Not available | High Speed Ethernet Server, Ethernet Server | Dashboard Server, REST API, Primary Interface (Primary) | Robot Web Services | SOAP |
| State | **2 of 3** | **3 of 3** | **3 of 3** | **3 of 3** | **2 of 3** |

A brand that has no route for a method throws `FeatureNotSupportedException` (see [Errors](/robotics/documentation/errors)). Ask `robot.State.IsAvailable(StateFeature.ServoOff)` before the call to hide the action in a user interface.

## Example

### Read the state

`Read` returns a `ControllerStateInfo`. Call it in a loop to follow the controller.

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

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

        /**/
        ControllerStateInfo state = robot.State.Read();
        Console.WriteLine($"Mode: {state.Mode}, servo on: {state.ServoOn}, running: {state.Running}, alarm: {state.AlarmPresent}");
        /**/

        robot.Disconnect();
    }
}
```

**Python : StateRead**
```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", ""))

##
state = robot.state.read()
print(f"Mode: {state.mode.name}, servo on: {state.servo_on}, running: {state.running}, alarm: {state.alarm_present}")
##

robot.disconnect()
```

### Switch the servo power

`ServoOn` and `ServoOff` return when the controller accepted the command, without waiting for the servo power. Call `Read` and check `ServoOn` to know when the motors are on. On some controllers, `ServoOn` also clears the alarms that can be cleared. `ServoOff` stops any motion.

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

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

        /**/
        // ServoOff is not supported by every brand: ask before calling
        if (robot.State.IsAvailable(StateFeature.ServoOff))
        {
            robot.State.ServoOff();
        }

        robot.State.ServoOn();
        /**/

        robot.Disconnect();
    }
}
```

**Python : StateServo**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters
from underautomation.robotics.controllers.state_feature import StateFeature

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

##
# servo_off is not supported by every brand: ask before calling
if robot.state.is_available(StateFeature.ServoOff):
    robot.state.servo_off()

robot.state.servo_on()
##

robot.disconnect()
```

## Reference

In Python, the names are in snake_case: `robot.state.read()`, `robot.state.servo_on()`, `robot.state.servo_off()`, `robot.state.is_available(...)`. The enum members keep their names, and `state.mode.name` gives the name of the mode.

### Methods of IStateService

**Members of Controllers.IStateService**
```csharp
public interface IStateService {
    // Returns true when the method can be called on the connected controller.
    // The answer depends on the brand, on the routing settings and on the protocols that answered at the connection, not on the state of the controller.
    bool IsAvailable(StateFeature feature)

    // Reads the state of the controller
    ControllerStateInfo Read()

    // Switches the servo power (motors) off. This stops any motion.
    // Returns when the controller accepted the command, without waiting for the servo power: <xref href="UnderAutomation.Robotics.Controllers.IStateService.Read" data-throw-if-not-resolved="false"></xref> gives it.
    void ServoOff()

    // Switches the servo power (motors) on, so that the robot can move. On some controllers this also clears the alarms that can be cleared.
    // Returns when the controller accepted the command, without waiting for the servo power: <xref href="UnderAutomation.Robotics.Controllers.IStateService.Read" data-throw-if-not-resolved="false"></xref> gives it.
    // The controller can need its remote mode.
    void ServoOn()
}
```

### ControllerStateInfo

**Members of Controllers.ControllerStateInfo**
```csharp
public sealed class ControllerStateInfo {
    // Creates a state with the default value of each property
    public ControllerStateInfo()

    // True when at least one alarm is active
    public bool AlarmPresent { get; set; }

    // True when a program is paused (held)
    public bool Held { get; set; }

    // Operating mode
    public OperatingMode Mode { get; set; }

    // Object of the brand SDK this state comes from. Null when there is none.
    public object Native { get; set; }

    // True when the controller accepts commands from a remote client
    public bool RemoteControlEnabled { get; set; }

    // True when a program is running
    public bool Running { get; set; }

    // True when the servo power (motors) is on
    public bool ServoOn { get; set; }

    public override string ToString()
}
```

**Members of Controllers.OperatingMode**
```csharp
public enum OperatingMode {
    // Automatic mode: programs run without an operator at the pendant (also called play or remote mode by some controllers)
    Automatic = 1

    // Manual mode at reduced speed (also called teach mode by some controllers)
    Manual = 2

    // Manual mode at full speed
    ManualFullSpeed = 3

    // The controller does not give the mode
    Unknown = 0
}
```

### Errors

The page [Errors](/robotics/documentation/errors) explains each exception and how to avoid it.

- `FeatureNotSupportedException`: the brand has no route for the method.
- `RouteUnavailableException`: the method has routes, but none of them can be used, for example because the protocol did not answer at the connection.
- `ControllerRefusedException`: the controller received the command and refused it.
- `RobotControllerException`: the route failed. Its inner exception is the exception of the brand SDK.

`IsAvailable` only throws `ArgumentOutOfRangeException`, for a value that is not in the enum.

## What to read next

- [Monitor the state of a robot controller](/robotics/documentation/how-to-monitor-state): follow the controllers of a cell with the same code.
- [Alarm](/robotics/documentation/alarm): read the alarms when `AlarmPresent` is true, and reset them.
- [Program](/robotics/documentation/program): start and stop a program.
- [Info](/robotics/documentation/info): read the model and the serial number.