Webots Advanced Topics
Use this skill to implement and troubleshoot advanced Webots workflows involving ROS 2 integration, simulator-to-hardware transfer, external process orchestration, optimization loops, runtime scaling, plugin-based extensibility, and source builds.
Do not use this skill for basic controller coding patterns; refer to webots-controller-programming.
Do not use this skill for physics plugin internals; refer to webots-physics.
Apply This Skill When
- Integrating Webots with ROS 2 (
webots_ros2) including launch, URDF/Xacro, and topic wiring.
- Running controllers outside Webots (
<extern>) for IDE debugging, distributed systems, or external middleware.
- Bridging Webots with third-party applications through TCP/IP.
- Performing optimization-in-the-loop and simulation-driven parameter tuning.
- Coordinating multi-robot systems and Supervisor-managed orchestration.
- Building custom Robot Window or remote-control plugin workflows.
- Diagnosing platform-specific bugs and applying known workarounds.
- Building Webots from source for patching, profiling, or advanced customization.
ROS 2 Integration (webots_ros2)
Treat webots_ros2 as the official ROS 2 interface.
- Install from packages when available:
apt install ros-humble-webots-ros2
- Build from source when custom patches or unreleased features are required.
Core Components
webots_ros2_driver: main interface node between Webots devices and ROS 2 graph.
Ros2Supervisor: exposes Supervisor functionality through ROS 2 for runtime world and robot control.
- Plugin system: add custom translation logic for specific Webots devices or domain-specific message flows.
Launch Pattern
Use the canonical launcher + driver composition:
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from webots_ros2_driver.webots_launcher import WebotsLauncher
def generate_launch_description():
webots = WebotsLauncher(world='my_world.wbt')
robot_driver = Node(
package='webots_ros2_driver',
executable='driver',
parameters=[{'robot_description': robot_description}]
)
return LaunchDescription([webots, robot_driver])
Robot Description and Topics
- Generate
robot_description from URDF/Xacro for frame consistency and reuse across simulation and real robots.
- Map Webots sensors to standard ROS 2 topics and message types (for example image, laser scan, IMU, joint state).
- Keep namespace and TF conventions aligned with downstream navigation, perception, and control stacks.
Transfer to Real Robots
Use one of three transfer approaches:
- Remote Control Plugin: keep controller on PC and send commands to the real robot.
- Cross-Compilation: compile C/C++ controller for the robot CPU and deploy binary.
- Interpreted Transfer: deploy Python controller script directly when runtime supports it.
Remote Control Plugin Notes
- Implement plugin bridge in C/C++.
- Preserve command timing and actuator update cadence between simulation and hardware loop.
- Synchronize units, saturation limits, encoder scaling, and coordinate frames.
Sim-to-Real Calibration
- Match motor limits, friction, inertial values, latency, sensor noise, and control rate.
- Validate against recorded real telemetry and iterate on model parameters.
- Prefer domain randomization and tolerance bands over single-point fitting.
Extern Robot Controllers
Run controller process outside Webots when debugging with full IDE tooling, integrating ROS 2 stacks, or splitting workloads across hosts.
- Set Robot
controller field to <extern>.
- Define
WEBOTS_CONTROLLER_URL for transport endpoint.
export WEBOTS_CONTROLLER_URL=ipc:///tmp/local_url/ROBOT_NAME
python3 my_controller.py
Common endpoint styles:
ipc:// for local low-latency process communication.
tcp:// for remote/distributed execution.
TCP/IP Interfacing
Use controller-side sockets to connect Webots with MATLAB, LabVIEW, custom C++/Python tools, and external supervisory software.
- Implement robot controller as TCP server or client.
- Define compact command protocol (binary or line-based) with explicit versioning.
- Include timeout, reconnect, heartbeat, and command acknowledgment semantics.
- Decouple network IO thread from control loop to protect simulation step determinism.
Numerical Optimization
Use Webots as an evaluation backend for optimization algorithms.
- Supervisor applies candidate parameters.
- Reset simulation per trial.
- Run until termination criterion.
- Compute fitness and feed optimizer.
Supported patterns include genetic algorithms, gradient-based tuning, Bayesian optimization, and multi-objective workflows.
# Optimization loop pattern
supervisor = Supervisor()
for generation in range(N_GENERATIONS):
for individual in population:
# Apply parameters to robot
supervisor.simulationReset()
# Run simulation
while supervisor.step(timestep) != -1:
if simulation_complete():
break
fitness = evaluate()
For multi-objective workloads, distribute candidates across parallel worlds/processes and aggregate Pareto metrics offline.
Performance Optimization
Tune simulation cost before scaling experiments.
- Choose
basicTimeStep in practical range (typically 8-64 ms).
- Set
WorldInfo.optimalThreadCount to exploit multi-core physics execution.
- Disable unused high-cost sensors (Camera, Lidar, RangeFinder).
- Simplify
boundingObject geometry.
- Reduce rendering overhead via batch/fast mode.
webots --batch --mode=fast my_world.wbt # headless fast mode
Known Bugs and Workarounds
General:
- Saving while simulation is running may accumulate pose error; pause and reset before saving.
- High-speed bodies may tunnel through thin geometry; increase collision thickness or reduce
basicTimeStep.
- macOS Metal renderer may show transparency artifacts; validate with alternate visual settings or fallback testing workflows.
Linux-specific:
- Some NVIDIA driver versions cause rendering artifacts; verify OpenGL path with
glxinfo.
- Wayland compositor may cause window/input instability; use X11 session when issues appear.
- AppImage execution may require
--no-sandbox in constrained environments.
Multi-Robot Coordination
- Run one controller process per robot for clear fault isolation.
- Use Emitter/Receiver channels for in-sim communication.
- Use Supervisor for global coordination, reset sequencing, and scoring.
- Use extern controllers plus shared-memory/message-bus patterns for high-throughput coordination.
Plugin System
Controller Plugin (Remote Control)
- Use to connect simulated control interfaces to real robot communication stacks.
- Keep serialization and transport framing deterministic.
Robot Window Plugin
- Place HTML/JS assets in
plugins/robot_windows/.
- Use JavaScript bridge API for controller-window communication.
- Build dashboards for telemetry, debugging tools, and command panels.
Build Webots from Source
Use source builds for deep debugging, patching, profiling, or unreleased functionality testing.
- Requirements:
git, cmake, gcc/clang, and platform dependencies.
- Clone:
git clone https://github.com/cyberbotics/webots.git
make -j$(nproc)
make -j$(sysctl -n hw.ncpu)
Execution Checklist
- Confirm requested scope is advanced-topic only (no basic controller primer, no physics plugin deep-dive).
- Select integration path (ROS 2, extern, TCP/IP, plugin, optimization, or multi-robot).
- Apply platform-appropriate bug workarounds early.
- Benchmark and tune performance before large experiment runs.
- Capture reproducible configs in launch files, world files, and reference notes.
For detailed APIs, environment variables, build dependencies, CLI flags, and expanded troubleshooting matrices, use references/advanced_reference.md.
1---2name: webots-advanced3description: Use this skill for advanced Webots topics: ROS/ROS2 integration, transfer to real robots, numerical optimization, extern robot controllers, TCP/IP interfacing, performance optimization, known bugs/workarounds, plugin development (controller/robot window), building Webots from source, and multi-robot coordination. Triggers on: webots ROS, ROS2, webots_ros2, transfer to robot, extern controller, TCP/IP, optimization, known bugs, plugin, multi-robot, numerical optimization.4---56# Webots Advanced Topics78Use this skill to implement and troubleshoot advanced Webots workflows involving ROS 2 integration, simulator-to-hardware transfer, external process orchestration, optimization loops, runtime scaling, plugin-based extensibility, and source builds.910Do not use this skill for basic controller coding patterns; refer to `webots-controller-programming`.11Do not use this skill for physics plugin internals; refer to `webots-physics`.1213## Apply This Skill When1415- Integrating Webots with ROS 2 (`webots_ros2`) including launch, URDF/Xacro, and topic wiring.16- Running controllers outside Webots (`<extern>`) for IDE debugging, distributed systems, or external middleware.17- Bridging Webots with third-party applications through TCP/IP.18- Performing optimization-in-the-loop and simulation-driven parameter tuning.19- Coordinating multi-robot systems and Supervisor-managed orchestration.20- Building custom Robot Window or remote-control plugin workflows.21- Diagnosing platform-specific bugs and applying known workarounds.22- Building Webots from source for patching, profiling, or advanced customization.2324## ROS 2 Integration (`webots_ros2`)2526Treat `webots_ros2` as the official ROS 2 interface.2728- Install from packages when available:29 - `apt install ros-humble-webots-ros2`30- Build from source when custom patches or unreleased features are required.3132### Core Components3334- `webots_ros2_driver`: main interface node between Webots devices and ROS 2 graph.35- `Ros2Supervisor`: exposes Supervisor functionality through ROS 2 for runtime world and robot control.36- Plugin system: add custom translation logic for specific Webots devices or domain-specific message flows.3738### Launch Pattern3940Use the canonical launcher + driver composition:4142```python43from launch import LaunchDescription44from launch.substitutions import LaunchConfiguration45from webots_ros2_driver.webots_launcher import WebotsLauncher4647def generate_launch_description():48 webots = WebotsLauncher(world='my_world.wbt')49 robot_driver = Node(50 package='webots_ros2_driver',51 executable='driver',52 parameters=[{'robot_description': robot_description}]53 )54 return LaunchDescription([webots, robot_driver])55```5657### Robot Description and Topics5859- Generate `robot_description` from URDF/Xacro for frame consistency and reuse across simulation and real robots.60- Map Webots sensors to standard ROS 2 topics and message types (for example image, laser scan, IMU, joint state).61- Keep namespace and TF conventions aligned with downstream navigation, perception, and control stacks.6263## Transfer to Real Robots6465Use one of three transfer approaches:66671. Remote Control Plugin: keep controller on PC and send commands to the real robot.682. Cross-Compilation: compile C/C++ controller for the robot CPU and deploy binary.693. Interpreted Transfer: deploy Python controller script directly when runtime supports it.7071### Remote Control Plugin Notes7273- Implement plugin bridge in C/C++.74- Preserve command timing and actuator update cadence between simulation and hardware loop.75- Synchronize units, saturation limits, encoder scaling, and coordinate frames.7677### Sim-to-Real Calibration7879- Match motor limits, friction, inertial values, latency, sensor noise, and control rate.80- Validate against recorded real telemetry and iterate on model parameters.81- Prefer domain randomization and tolerance bands over single-point fitting.8283## Extern Robot Controllers8485Run controller process outside Webots when debugging with full IDE tooling, integrating ROS 2 stacks, or splitting workloads across hosts.8687- Set Robot `controller` field to `<extern>`.88- Define `WEBOTS_CONTROLLER_URL` for transport endpoint.8990```bash91export WEBOTS_CONTROLLER_URL=ipc:///tmp/local_url/ROBOT_NAME92python3 my_controller.py93```9495Common endpoint styles:9697- `ipc://` for local low-latency process communication.98- `tcp://` for remote/distributed execution.99100## TCP/IP Interfacing101102Use controller-side sockets to connect Webots with MATLAB, LabVIEW, custom C++/Python tools, and external supervisory software.103104- Implement robot controller as TCP server or client.105- Define compact command protocol (binary or line-based) with explicit versioning.106- Include timeout, reconnect, heartbeat, and command acknowledgment semantics.107- Decouple network IO thread from control loop to protect simulation step determinism.108109## Numerical Optimization110111Use Webots as an evaluation backend for optimization algorithms.112113- Supervisor applies candidate parameters.114- Reset simulation per trial.115- Run until termination criterion.116- Compute fitness and feed optimizer.117118Supported patterns include genetic algorithms, gradient-based tuning, Bayesian optimization, and multi-objective workflows.119120```python121# Optimization loop pattern122supervisor = Supervisor()123for generation in range(N_GENERATIONS):124 for individual in population:125 # Apply parameters to robot126 supervisor.simulationReset()127 # Run simulation128 while supervisor.step(timestep) != -1:129 if simulation_complete():130 break131 fitness = evaluate()132```133134For multi-objective workloads, distribute candidates across parallel worlds/processes and aggregate Pareto metrics offline.135136## Performance Optimization137138Tune simulation cost before scaling experiments.139140- Choose `basicTimeStep` in practical range (typically 8-64 ms).141- Set `WorldInfo.optimalThreadCount` to exploit multi-core physics execution.142- Disable unused high-cost sensors (Camera, Lidar, RangeFinder).143- Simplify `boundingObject` geometry.144- Reduce rendering overhead via batch/fast mode.145146```bash147webots --batch --mode=fast my_world.wbt # headless fast mode148```149150## Known Bugs and Workarounds151152General:153154- Saving while simulation is running may accumulate pose error; pause and reset before saving.155- High-speed bodies may tunnel through thin geometry; increase collision thickness or reduce `basicTimeStep`.156- macOS Metal renderer may show transparency artifacts; validate with alternate visual settings or fallback testing workflows.157158Linux-specific:159160- Some NVIDIA driver versions cause rendering artifacts; verify OpenGL path with `glxinfo`.161- Wayland compositor may cause window/input instability; use X11 session when issues appear.162- AppImage execution may require `--no-sandbox` in constrained environments.163164## Multi-Robot Coordination165166- Run one controller process per robot for clear fault isolation.167- Use Emitter/Receiver channels for in-sim communication.168- Use Supervisor for global coordination, reset sequencing, and scoring.169- Use extern controllers plus shared-memory/message-bus patterns for high-throughput coordination.170171## Plugin System172173### Controller Plugin (Remote Control)174175- Use to connect simulated control interfaces to real robot communication stacks.176- Keep serialization and transport framing deterministic.177178### Robot Window Plugin179180- Place HTML/JS assets in `plugins/robot_windows/`.181- Use JavaScript bridge API for controller-window communication.182- Build dashboards for telemetry, debugging tools, and command panels.183184## Build Webots from Source185186Use source builds for deep debugging, patching, profiling, or unreleased functionality testing.187188- Requirements: `git`, `cmake`, `gcc`/`clang`, and platform dependencies.189- Clone:190191```bash192git clone https://github.com/cyberbotics/webots.git193```194195- Build on Linux:196197```bash198make -j$(nproc)199```200201- Build on macOS:202203```bash204make -j$(sysctl -n hw.ncpu)205```206207## Execution Checklist208209- Confirm requested scope is advanced-topic only (no basic controller primer, no physics plugin deep-dive).210- Select integration path (ROS 2, extern, TCP/IP, plugin, optimization, or multi-robot).211- Apply platform-appropriate bug workarounds early.212- Benchmark and tune performance before large experiment runs.213- Capture reproducible configs in launch files, world files, and reference notes.214215For detailed APIs, environment variables, build dependencies, CLI flags, and expanded troubleshooting matrices, use `references/advanced_reference.md`.