Monitor the state of a robot controller
Follow the operating mode, servo power, program execution and alarm state of Fanuc, Yaskawa, Universal Robots and ABB controllers with one code. C# and Python examples.
This article shows how to follow the operating mode, the servo power, the program execution and the alarm state of Fanuc, Yaskawa, Universal Robots and ABB controllers from a PC, with one code in C# or Python. The table at the end gives what each brand reads, and what to read instead on a Stäubli controller.
The state of a Stäubli controller is not in the common API: the support table below shows it.
Prerequisites
- UnderAutomation.Robotics in your project. See Get started with .NET or Get started with Python.
- The connection settings of each controller. See Connect to your robot.
- The license of each brand you connect, or the 30 day trial. See Licensing.
- Reading the state does not change the controller.
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.
| 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 |
Example
Follow the controllers of a cell
The example connects to each controller of a cell once, then reads the state of every controller once per second. Read returns a ControllerStateInfo: Mode is the operating mode, ServoOn the servo power, Running true when a program runs, and AlarmPresent true when an alarm is active. Keep the connections open between two reads: a connection takes more time than a read.
static void Main(){// Connect each controller of the cell once: only the brand and the address changevar cell = new[]{(Brand: "fanuc", Address: "192.168.0.1"),(Brand: "yaskawa", Address: "192.168.0.2"),(Brand: "universalrobots", Address: "192.168.0.3"),(Brand: "abb", Address: "192.168.125.1"),};var robots = new List<RobotController>();foreach (var controller in cell){RobotController robot = new RobotController();robot.Connect(RobotConnectionParameters.Create(controller.Brand, controller.Address));robots.Add(robot);}// Read the state of each controller once per second, with the same code for each controllerfor (int i = 0; i < 10; i++){foreach (RobotController robot in robots){ControllerStateInfo state = robot.State.Read();Console.WriteLine($"{robot.Brand}: {state.Mode}, servo on: {state.ServoOn}, running: {state.Running}, alarm: {state.AlarmPresent}");}Thread.Sleep(1000);}foreach (RobotController robot in robots)robot.Disconnect();}}
In Python, the names are in snake_case: robot.state.read(), state.servo_on, state.alarm_present, and state.mode.name gives the name of the mode.
Automatic is the mode where programs run without an operator at the pendant. Some controllers call it play or remote mode. Manual is the manual mode at reduced speed, and ManualFullSpeed the manual mode at full speed.
Switch the servo power
ServoOn and ServoOff switch the motors on and off, on the brands that have them. Ask IsAvailable before the call. They return when the controller accepted the command: call Read to know when the motors are on.
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();}
What changes from one brand to another
The code does not change. Each controller gives its state in its own way.
| Brand | Read | Servo power | Brand article |
|---|---|---|---|
| Fanuc | The mode is the one of the last mode change in the alarm history. It is Unknown when this change is no longer in the history. | ServoOn resets the controller: the servo power comes back when the safety chain is closed, and the alarms that can be cleared are cleared. No ServoOff. | Monitor the task execution |
| Yaskawa | The teach mode gives Manual, the play mode gives Automatic. | ServoOn and ServoOff need the remote mode. | Monitor the state |
| Universal Robots | The robot mode of the controller and the state of its program. | ServoOn powers the robot on and releases the brakes. On e-Series and PolyScope X, the robot is in remote control. | Monitor the state |
| ABB | Controller state (motors), operation mode and execution of RAPID. | ServoOn and ServoOff switch the motors on and off. | Controller |
| Stäubli | Not available. Read the execution of the programs with robot.Program.ReadExecution() and the position with robot.Motion.ReadPose(). | ServoOn and ServoOff need the remote mode. | Monitor the state |
Errors
FeatureNotSupportedException: the brand has no route for the method, for exampleReadon Stäubli orServoOffon Fanuc.RouteUnavailableException: the method has routes, but none can be used, for example because the protocol did not answer at the connection.ControllerRefusedException: the controller receivedServoOnorServoOffand refused it, for example because it is not in remote mode.RobotControllerException: the route failed. Its inner exception is the exception of the brand SDK.
The page Errors explains each exception.
What to read next
- State: the
ControllerStateInfotype. - Read and reset robot alarms: read the alarms when
AlarmPresentis true. - Get the current position of a robot: the position of the same controllers.