Robot simulator#

We will use Universal Robots ursim_e-series simulator. To run the simulator image, we need to install Docker.

Docker installation & first start#

  1. Download the corresponding package dependent on which kind of processor you have (Apple or Intel).

  2. Install

  1. Start Microsoft Store.

  2. Search for Docker Desktop and start installation.

    A new window will pop up after download is complete.

  3. Leave default settings during installation.

  4. After the installation click Close and Restart.

Troubleshooting

Mac: Symptom: You cannot install or after installation, you cannot start Docker Desktop. Solution: You may have an older Mac which is not supported by the latest version. Try installing an older version of Docker Desktop. You find older installations on Releases.

After the installation:

  1. If a terms screen pops up, then accept it.

  2. Docker Desktop GUI with welcome screen should pop up. You don’t need to provide any data. Just click Skip.

Downloading simulation image#

../_images/docker-desktop-containers.png

Fig. 5 Docker Desktop containers screen.#

After the welcome screen, you will arrive at the main page of Docker Desktop similar to Fig. 5.

  1. In the search bar, search for universalrobots.

    In the search results, you will see universalrobots/ursim_e-series.

  2. Click Pull on the universalrobots/ursim_e-series.

    After downloading, you can close the search window.

Creating a new container from the simulation image#

We have to create a container using the image to run the robot simulator.

  1. Click Images on the left bar.

  2. Click ▶️ on the universalrobots/ursim_e-series you downloaded.

    You will be shown a window titled Run a new container.

  3. Do not click Run. Click icon to configure the container.

    You will see Optional Settings.

  4. Set Container name to robot-simulator.

  5. Fill the Ports as follows:

    • search for :29999/tcp (you see on the right of the fields) and fill with 29999.

    • :30002/tcp with 30002.

    • :6080/tcp (on the bottom) with 6080.

  6. Fill Environment variables as follows:

    • Variable: ROBOT_MODEL

    • Value: UR3

  7. Click Run.

    The Run a new container window will be closed. Run creates a new container using the image we have downloaded and runs it.

  8. Exit the search window.

    You should be back on the Containers view. You will see information about the container robot-simulation. The ️▶️ icon will be grayed out, which shows that the container is running in the background. You should also see some logs similar to:

    Universal Robots simulator for e-Series:...
    
    IP address of the simulator
    
         172.17.0.2
    
    Access the robots user interface through this URL:
    
         http://172.17.0.2:6080/vnc.html?host=172.17.0.2&port=6080
         
    ...
    
    Troubleshooting

    Mac: If you get errors about Xvfb before the messages above: We had this error with a Mac Sonoma 14, but could not find a solution. We tried installing an older version of Docker Desktop and an older version of the image.

    Unfortunately we cannot access the IP address given above using Docker Desktop and we will use another way in the next step.

  9. Go to http://localhost:6080/vnc.html?autoconnect=true

    You should see a remote interface similar to Fig. 6.

    ../_images/universal-robots-ursim.png

    Fig. 6 Remote interface through URSim.#

  10. Confirm Safety Configuration.

    You will be confronted with Getting Started window.

  11. On the simulator window, locate the round icon on the bottom left corner. If it is not 🟢, then the robot is not operational.

  12. Click the red icon, then click On and then Start.

    The icon in the corner should be 🟢 now.

    Note

    We will typically activate the robot from the C# code, so you don’t require this step every time. This step is only needed to make the robot visible in the next steps before we send a program to the robot.

  13. Click on the Move icon above.

    You should see robot’s current pose.

    Tip

    To change the perspective to the robot, click Feature drop-down menu and select View. Then drag the robot. The robot will be rotated around its base, or in other words z-axis.

    The other Features change the perspective to the robot’s base and tool, but these views can only be zoomed in or out.

We will use our own C# code to load a robot program instead of loading the program using PolyScope.

Adding a plane to visualize a workbench#

Later, we will have exercises with the robot, where we will simulate pick-and-place movements. We will assume that there is a workbench right at the base of the robot. To add it to the visualization:

  1. Click Installation

  2. Click Features

  3. Click Plane

    A green plane named Plane_1 will be placed at the origin of the robot (called Feature Base)and will be visible right under the base of the robot.

Sending a program to the robot#

To test the simulator, we will use a short program written in URScript – the programming language for robots manufactured by Universal Robots and send it to the robot.

The program below automatically powers on the robot and releases the brakes.

Create a new console project with the name, e.g., URScriptTest or use your scratchpad project and run the following code:

using System.Net.Sockets;
using System.Text;

const string program = @"
def f():
  p1 = p[.3, -.3, .1, 0, -3.1415, 0]
  p2 = p[.2, -.3, .1, 0, -3.1415, 0]
  times = 0
  while (times < 3):
    movej(get_inverse_kin(p1))
    movej(get_inverse_kin(p2))
    times = times + 1
  end
end
";

const int urscriptPort = 30002, dashboardPort = 29999;
const string IpAddress = "localhost";

void SendString(string host, int port, string message)
{
    using var client = new TcpClient(host, port);
    using var stream = client.GetStream();
    stream.Write(Encoding.ASCII.GetBytes(message));
}

SendString(IpAddress, dashboardPort, "brake release\n");
SendString(IpAddress, urscriptPort, program);
// To stop:
// SendString(IpAddress, dashboardPort, "stop\n");

Warning

Pay attention that the program you send include a newline after the last end keyword. Otherwise PolyScope can silently ignore your program.

The robot in the simulator should move for a while and then stop.

Every time you run the program the new robot program will overwrite the last robot program you have sent before.

Shutting down & running the container again#

When you finished your work, stop the container. If you want to start the simulation again, Run again.

Editor for writing URScript programs#

If you will write longer URScript programs, then I recommend the following workflow:

  1. Writing the program on the VS Codium editor with URScript extension

  2. Optional, especially in the beginning: Copying the program to the Script code editor and checking for further errors.

  3. Copying the program to the C# code to run it on the robot.

VS Codium + URScript extension#

  1. Install VSCodium

  2. Install URScript extension on top.

  3. Open settings with Ctrl,, activate Format On Save.

../_images/vscodium-with-urscript-extension-code-completion.png

Fig. 7 Code completion using VS Codium with URScript extension.#

Warning

Currently you have to manually download and install the URScript extension.

The URScript extension provides:

  • Syntax highlighting

  • Code completion like in Fig. 7

  • Autoformatting which helps with syntax errors like in Fig. 8

  • Show tips when you hover over code with your mouse

../_images/vscodium-with-urscript-helps-to-find-syntax-errors.png

Fig. 8 URScript extension can help with syntax errors when you use Format on Save feature. Even we have a function, the code is not intended. Moreover, the code is only blue instead of having many colors, so there must be an error. Do you spot the error? Solution is in Fig. 9.#

../_images/vscodium-with-urscript-helps-to-find-syntax-errors_errors-fixed.png

Fig. 9 Fig. 8 after the errors are fixed. The indentation is correct and code is correctly highlighted.#

PolyScope script editor#

../_images/vnc-viewer-clipboard.png

Fig. 10 VNC viewer clipboard#

  1. Click Program tab

  2. Click Advanced drop-down menu from the menu on the left

  3. Click Script

  4. Select File from the drop-down menu on the right

    It will show <No File Selected> if you did not edit any file before.

  5. Click Edit.

Now we will copy our code to the editor

Copy-paste using Ctrlv won’t work directly. First we have to copy into the special field of the web software that acts as a remote desktop software (VNC viewer):

../_images/polyscope-script-code-error.png

Fig. 11 Syntax error shown on the script code window#

  1. Click the arrow button on the left border of the window which will show the control bar, then on the clipboard icon as shown in Fig. 10.

  2. Close the control bar

  3. Use Ctrlv to paste your code

  4. Click Save As and give a name.

  5. Click Exit.

    You will be back on the Script code window

  6. Click ️▶️ on the bottom of the window.

  7. Click Play from selection or Play from beginning. It does not make a difference as our program only consists of the script.

    If you have errors in your code, a pop up window will show them like in Fig. 11.

Used resources#