-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
How to adapt your world or PROTO to Webots R2022b
PROTO nodes are a powerful way of describing complex objects or robots.
From R2022b, all PROTO files used by a world need to be declared using the EXTERNPROTO keyword. Similarly, every PROTO inserted during the execution of the simulation by a supervisor needs to be declared an Ephemeral EXTERNPROTO prior to import it.
When opening a world in R2022b, declared PROTO will look like:
#VRML_SIM R2022b utf8
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/objects/backgrounds/protos/TexturedBackground.proto"
WorldInfo {
basicTimeStep 16
}
Viewpoint {
}
TexturedBackground {
}
In this case, the PROTO TexturedBackground will be retrieved from the corresponding url. Similarly, a PROTO may reference another PROTO, in this case a declaration is also necessary:
#VRML_SIM R2022b utf8
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/appearances/protos/Plastic.proto"
PROTO MyProto [
field SFVec3f size 0.1 0.1 0.1 # Defines the size of the box.
]
{
Shape {
appearance Plastic {
}
geometry Box {
size IS size
}
}
}
In general, the url can be defined multiple ways:
# remote PROTO
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2022b/projects/objects/backgrounds/protos/TexturedBackground.proto"
# local PROTO (absolute path)
EXTERNPROTO "/home/user/Documents/my_project/protos/TexturedBackground.proto"
# local PROTO (relative path)
EXTERNPROTO "../protos/TexturedBackground.proto"
The location (url) for official PROTO can be found in the file: WEBOTS_HOME/resources/proto-list.xml
When inserting PROTO nodes using the add-node button, a declaration is added automatically.
Under the hood, EXTERNPROTO and Ephemeral EXTERNPROTO are treated in the same manner so the information provided above is valid for ephemeral EXTERNPROTO as well. What distinguishes the two is that, as the name implies, PROTO nodes that are ephemeral may not be present when the world is loaded but instead may appear later on during the execution of the simulation, typically when spawned by a supervisor.
Therefore, declared PROTO nodes that have no instances in the world at load-time will be shown under the Ephemeral EXTERNPROTO panel, which can be opened by clicking the similarly named button:

Doing so will open the panel:

Only PROTO included in this list can be inserted into the world using a Supervisor. Therefore if your controller spawns PROTO nodes, you need to declare them prior to doing so.
If your world was created before R2022a, generally speaking it should be sufficient for you to load it with Webots R2022b and click the save button. Doing so, the backwards compatibility mechanism will add the declaration for you by assuming you are using the official Webots PROTO nodes and therefore setting the url accordingly.
Unfortunately, PROTO files aren't (and cannot) be altered dynamically by webots since due to the fact that PROTO can be procedurally defined, a PROTO file may in principle represent anything. For these reason, the backwards compatibility mechanism will stop at the world and will not apply to locally defined PROTO. If the world uses a PROTO that you created yourself, the backwards compatibility mechanism will do the necessary change in the world file, but will not modify the PROTO itself. So if your PROTO depends on other PROTO, they need to declared manually