Simulate Ned with Webots

What is Webots?

“Webots is an open source and multi-platform desktop application used to simulate robots. It provides a complete development environment to model, program and simulate robots. It has been designed for a professional use, and it is widely used in industry, education and research. Cyberbotics Ltd. maintains Webots as its main product continuously since 1998” (source).

You can download Webots for free on their website.

Note

To do this tutorial we used Ubuntu 18.04 and Webots R2021a.

Introduction

  • On July 2021, Ned was added on Webots. You can have more information on Cyberbotics’ website.

  • By downloading Webots and running Ned’s sample World, you will be able to control its joints and its gripper with your keyboard, and also run a demo.

  • Here is how the sample looks like on Webots:

    Ned

Objectives

  • As Ned is based on open-source technologies, it was important for us to explain you how we added Ned on Webots.

  • If you are curious, want to learn more about Webots, and create your own project with Ned, this tutorial is for you.

  • You don’t need any particular knowledge about Webots but we advise you to follow the different tutorials on Webots’ website which are quick and clear.

Note

You can find all the source code of this project in the folder YOUR_PATH/webots/projects/robots/ned. You can also find it on webots github: https://github.com/cyberbotics/webots/tree/released/projects/robots/niryo/ned

Explanation of Webots’ User interface

Webots is composed of four different windows. After having ran Ned’s sample world you should have this screen:

Ned
  1. The 3D window

  2. The Text editor

  3. The Scene Tree

  4. The console

In this tutorial we will explain the goal of these windows and how to use them for Ned.

Note

You can find all the information about these windows in Cyberbotics’ documentation.

The 3D window

Description

This is the main window that shows you the entire scene and where you can control the robot. To describe a scene on Webots, we call it the “world”. If you want to control Ned with your keyboard, you just have to click on this window with your mouse and then use your keyboard.

You can find the world we created in /webots/projects/robots/niryo/ned/protos.

To control Ned you can use these commands:

Launch demo --> D
Move joint_1 --> A and Z
Move joint_2 --> Q and S
Move joint_3 --> W and X
Move joint_4 --> Y and U
Move joint_5 --> H and J
Move joint_6 --> B and N
Open Close Gripper --> L or M
Launch Pick and Place --> P

Note

Do not hesitate to try all the different commands to control Ned. You also have a “joints demo” and a “pick and place” demo.

You can see that, so far, Ned’s sample world is a classroom with different table, chairs and two blackboards. All of the objects despite Ned come from Webots. Cyberbotics provides a library with various types of objects to let you create your own world easily.

Warning

On Webots, all the objects are called “PROTO node”. We highly advise you to follow this link to understand what is a PROTO node.

Add a new PROTO node in the world

If you want to modify Ned’s environment and add for example an “apple” you can do it following these steps:

Click on the button “Add a node”:

Ned

Then select “PROTO node (Webots Projects)” and search for the apple:

Ned

You should now see an apple in the 3D view, feel free to put it where you want.

Add your own PROTO node in the world

Webots has many different PROTO nodes, but how to add your own? This question is crucial as we do not use such format for our product.

If you are looking for a solution to implement your own models in Webots, you can use Cyberbotics’ urdf2webots package.

Note

In our case, for Ned, we use URDF, DAE, STL and XACRO files. You can find all the information concerning the XACRO files on the ROS Wiki, and about URDF here.

To use this package, open a terminal and follow these commands:

pip install urdf2webots

cd /YOUR_FOLDER_WITH_YOUR_FILE.xacro

python3 -m urdf2webots.importer --input=YOUR_FILE.xacro --disable-mesh-optimization

You should have your PROTO node generated in the same directory as your XACRO file.

The next step consists in adding this PROTO node in Webots’ directory: /webots/projects/robots/niryo/ned/protos

Now you can click on the “add a proto” button again and this time select PROTO node (Current Project):

Ned

Then, you should see your PROTO file in the list. Just select it and add it.

Ned

Note

In our case, we created two PROTO nodes, one called “Ned” and the other one “NedWithoutGripper”.

Now that we have seen the 3D window and how to add a model, or your own model, in Webots, let’s dive into the controls.

The Text editor

Description

The text editor allows you to edit the source code and create your own controller for the robot. On Webots, the major part of the controllers are edited with C. At Niryo, our robots can also be controlled in Python so we created a Python controller as well as a C controller.

You can find the controllers’ files of Ned’s sample here: /webots/projects/robots/niryo/ned/controllers.

Note

We highly recommend you to have a look at Webots’ documentation to learn how to edit your own controllers. If you want to create a new controller, on the toolbar you should click on “Wizards” and then on “New Robot_Controller…”. You can then select the editing language you want.

The Scene Tree

Description

The Scene Tree is a hierarchical representation of the current world. You will find all the PROTO nodes you included in your world. If you select a PROTO node, you can see all its caracteristics.

For example, if you select Ned’s PROTO node, you will be able to see its:

  • Position

  • Rotation

  • Name

  • Controller (very important, it’s here that you can change the controller you want to use)

Ned

The console

Description

The console window aims to display both compilation and controller outputs. If you want to debug your code or display a message for the user, you can do it here.

For example, when you run Ned’s sample, you get this on the console:

Ned

Going through Ned PROTO node file

The last important section before finishing this tutorial is to learn a bit more about how the PROTO node file of Ned is made.

In Ned’s PROTO node file, you will find all the characteristics of the robot that Webots requires. You will find the name, the controller used, the coordonates…

This can be found here:

Ned

But on this file you can also find all the modelisation caracteristics that Webots will need to simulate Ned’s movements. For example, which joints, which jaws… And thanks to the URDF, the PROTO file contains the “physics” that Webots will use to make the robot move.

If we focus on Ned’s Joint 1, you can find that in the file:

Ned

Note

It is here that Webots can understand that the joint_1 can be considered as a rotational_motor which means it can turn around an axis. It is this way that Webots manages to simulate with perfection the physics of robotics.

Let’s go

You are now ready to run Ned’s demo on Webots and play with it as much as you want. You can move all the joints and the gripper.

Feel free to share you work on social medias with #niryo!