State: operating mode and servo power
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.
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. - The license of the brand of the controller, or the 30 day trial. See Licensing.
- For
ServoOnandServoOff: the controller can need its remote mode. A controller that refuses the command throwsControllerRefusedException(see Errors).
Brand support
Each cell gives the protocol that the method uses on this brand, in the default order. The page 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.
| 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). 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.
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();}
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.
RobotController robot = new RobotController();robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));// ServoOff is not supported by every brand: ask before callingif (robot.State.IsAvailable(StateFeature.ServoOff)){robot.State.ServoOff();}robot.State.ServoOn();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
State service of a robot controller: operating mode, servo power, execution and alarm state. The library implements this interface. A minor version of the library can add members to it: a class of the application that implements it, for example a test double, then needs the new methods. Errors of the methods other than IsAvailable: FeatureNotSupportedException when the brand has no route for the method, RouteUnavailableException when the method has routes but none of them can be used, ControllerRefusedException when the controller received the command and refused it, RobotControllerException when the route failed (the inner exception is the exception of the brand SDK), and ArgumentException or a derived exception for an invalid argument. IsAvailable only throws ArgumentOutOfRangeException, for a value that is not in the enum. Results: a text and an array are empty when there is no value, never null. The only null values are the Native properties when there is no object of the brand SDK, and Position when the variable is not a position.
| Member | Type | Description |
|---|---|---|
IsAvailable(StateFeature) Method | bool | 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.
|
Read() Method | ControllerStateInfo | Reads the state of the controller |
ServoOff() Method | void | Switches the servo power (motors) off. This stops any motion. Returns when the controller accepted the command, without waiting for the servo power: Read gives it. |
ServoOn() Method | void | 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: Read gives it. The controller can need its remote mode. |
ControllerStateInfo
State of a controller: operating mode, servo power, program execution and alarms. The library creates a new object at each call and does not read it back. The setters are public so that tests and serializers can build the object.
| Member | Type | Description |
|---|---|---|
ControllerStateInfo() Constructor | Creates a state with the default value of each property | |
AlarmPresent Property | bool | True when at least one alarm is active |
Held Property | bool | True when a program is paused (held) |
Mode Property | OperatingMode | Operating mode |
Native Property | object | Object of the brand SDK this state comes from. Null when there is none. |
RemoteControlEnabled Property | bool | True when the controller accepts commands from a remote client |
Running Property | bool | True when a program is running |
ServoOn Property | bool | True when the servo power (motors) is on |
ToString() Method | string |
Operating mode of a controller
| Name | Value | Description |
|---|---|---|
Automatic | 1 | Automatic mode: programs run without an operator at the pendant (also called play or remote mode by some controllers) |
Manual | 2 | Manual mode at reduced speed (also called teach mode by some controllers) |
ManualFullSpeed | 3 | Manual mode at full speed |
Unknown | 0 | The controller does not give the mode |
Errors
The page 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: follow the controllers of a cell with the same code.
- Alarm: read the alarms when
AlarmPresentis true, and reset them. - Program: start and stop a program.
- Info: read the model and the serial number.