Run a program
Power on a UR cobot, release the brakes, load a program and play it from a PC in C# or Python, then follow it until its end.
This article shows how to start a program of a Universal Robots cobot from a PC, in C# or Python, and follow it until its end. It gives a complete program: check the remote control, power on, release the brakes, load the program, play it.
Which way to choose
| Way | Robots | What it runs | Follow it with |
|---|---|---|---|
| Dashboard Server | CB-Series, e-Series | A .urp program saved on the robot | GetProgramState(), IsProgramRunning() |
| REST API | PolyScope X | A program saved on the robot | GetProgramState() |
| URScript | All | URScript sent by the PC, without a .urp file | RobotModeData.ProgramRunning |
The Dashboard Server and the REST API run the programs made in PolyScope: the operator sees them and can stop them. URScript suits a short sequence generated by the PC. See Send URScript.
Prerequisites
- The service
Dashboard Serveris enabled (PolyScope 5), or the robot runs PolyScope X: see Prepare the robot. - The robot is in remote control.
- The program exists on the robot. To send it from the PC, see Transfer files and backups.
Steps
| Step | Dashboard Server | REST API (PolyScope X) |
|---|---|---|
| Check the remote control | IsInRemoteControl() | |
| Power on | PowerOn(), wait for Idle | PowerOn() |
| Release the brakes | ReleaseBrake(), wait for Running | BrakeRelease() |
| Load the program | LoadProgram("name.urp") | LoadProgram("name") |
| Play | Play() | Play() |
| Follow | GetProgramState() | GetProgramState() |
| Pause, stop | Pause(), Stop() | Pause(), Resume(), Stop() |
Example
The program uses the Dashboard Server. For PolyScope X, the same steps are in REST API.
using UnderAutomation.UniversalRobots;using UnderAutomation.UniversalRobots.Common;using UnderAutomation.UniversalRobots.Dashboard;class HowToRunProgram{static void Main(string[] args){var robot = new UR();// Primary Interface and Dashboard Serverrobot.Connect("192.168.0.1");// e-Series: the robot must be in remote controlif (!robot.Dashboard.IsInRemoteControl().Value){Console.WriteLine("Switch the robot to remote control on the teach pendant");return;}// Power on, then release the brakesrobot.Dashboard.PowerOn();WaitForMode(robot, RobotModes.Idle);robot.Dashboard.ReleaseBrake();WaitForMode(robot, RobotModes.Running);// Load the program: a path relative to the programs folder, or absolutevar load = robot.Dashboard.LoadProgram("pick_and_place.urp");if (!load.Succeed){Console.WriteLine(load.Message);return;}robot.Dashboard.Play();// Follow the program until it stopswhile (true){ProgramState state = robot.Dashboard.GetProgramState().Value;Console.WriteLine(state.Name + ": " + state.State);if (state.State == ProgramStates.Stopped) break;Thread.Sleep(500);}robot.Disconnect();}static void WaitForMode(UR robot, RobotModes mode){var timeout = DateTime.Now.AddSeconds(30);while (robot.Dashboard.GetRobotMode().Value != mode){if (DateTime.Now > timeout) throw new TimeoutException("Robot mode is not " + mode);Thread.Sleep(250);}}}
GetRobotMode() is polled until the arm is powered (Idle), then until the brakes are released (Running). The program state is polled every 500 ms until Stopped.
Troubleshooting
LoadProgramfails: the path is wrong. A relative path starts in the programs folder of the robot (/programs).- The commands fail with a message about the remote control: switch the robot to remote control on the teach pendant.
ReleaseBrakedoes nothing: the arm is not powered, or a protective stop is active. See Read and reset alarms.- The program stops at once: the installation of the program is not the loaded installation, or a popup waits on the teach pendant.
What to read next
- Dashboard Server: the list of the commands.
- Monitor the state of the robot.