Day 1: Webots Environment Setup

Today’s Learning Goals

Morning Session: Environment & Fundamentals

  1. Understanding Webots scene graph structure

WorldInfo Node Explained

First impressions: Zoom and navigating in Webots is not very intuitive on Mac. It feels like free software often does, minimally functional UI. Built by developers for developers.

The WorldInfo node is the root configuration node for any Webots world. It defines fundamental simulation properties:

WorldInfo {
  basicTimeStep 32            # Simulation step in milliseconds
  FPS 60                      # Frames per second for rendering
  gravity 0 -9.81 0          # Gravity vector (x y z)
  coordinateSystem "NUE"     # North-Up-East coordinate system
  physics "ODE"              # Open Dynamics Engine physics
}

Key WorldInfo Parameters

  1. Physics Parameters

    • basicTimeStep: Controls simulation speed (ms)
      • Lower values (16-32ms) = more accurate but slower
      • Higher values (64ms+) = faster but less accurate
    • gravity: Vector defining gravity direction and magnitude
    • cfm: Constraint Force Mixing (default: 1e-5)
      • Lower = more rigid constraints
      • Higher = softer, more elastic behavior
    • erp: Error Reduction Parameter (default: 0.2)
      • Controls how aggressively joints maintain positions
      • Range 0.1-0.8 (0.2 is good starting point)
  2. Rendering Parameters

    • FPS: Maximum frames per second
    • lineScale: Line thickness for rendering
    • contactProperties: Define material interactions
  3. Coordinate System

    • coordinateSystem: Defines axis orientation
      • “NUE” = North-Up-East (Webots default)
      • X = North (red axis)
      • Y = Up (green axis)
      • Z = East (blue axis)

Mouse Controls

  • Left Click + Drag: Rotate camera
  • Right Click + Drag: Pan camera
  • Scroll Wheel: Zoom in/out
  • Shift + Left Click + Drag: Pan camera (alternative)
  • Alt + Left Click + Drag: Tilt camera
  • Middle Click: Reset view to selected object

Keyboard Shortcuts

  1. View Controls
Ctrl + 1-9       : Save viewpoint
1-9              : Restore saved viewpoint
Ctrl + Shift + F : Full screen
Ctrl + 0         : Reset viewpoint
  1. Navigation
Up Arrow    : Tilt up
Down Arrow  : Tilt down
Left Arrow  : Rotate left
Right Arrow : Rotate right
Page Up     : Zoom in
Page Down   : Zoom out
  1. Simulation Controls
Ctrl + P    : Play/pause simulation
Ctrl + T    : Run one step
Ctrl + R    : Reset simulation
Ctrl + Shift + R : Reset simulation and reload world

Pro Navigation Tips

  1. Object Selection

    • Double-click object: Select and center view
    • Shift + double-click: Select without centering
    • Esc: Deselect all objects
  2. View Modes

    Ctrl + F1: Plain rendering
    Ctrl + F2: Wireframe mode
    Ctrl + F3: Normal vectors display
    Ctrl + F4: Physics visualization
    
  3. Quick Scene Tree Navigation

    • Use the Scene Tree panel (typically on left)
    • Press Tab to quickly find nodes
    • Use arrow keys to expand/collapse nodes
    • Press Enter to edit selected field

Common Navigation Problems & Solutions

  1. Camera Getting Lost

    • Press Ctrl + 0 to reset view
    • Double-click an object to center it
    • Use Scene Tree to right-click object → Look At
  2. Zoom Sensitivity Issues

    # Adjust in Preferences → General → Navigation
    Translation multiply factor: 0.4 (default)
    Rotation multiply factor: 0.5 (default)
    
  3. Scene Tree Organization

    # Recommended hierarchy
    WorldInfo
    ├── Viewpoint
    ├── Background
    ├── DirectionalLight
    ├── Ground
    └── Robots/Objects
    

Best Practices

  1. Camera Setup

    • Save frequently used viewpoints (Ctrl + 1-9)
    • Set up multiple viewpoints for different tasks
    • Keep one overhead view for navigation
  2. Scene Organization

    • Group related objects under DEF nodes
    • Use meaningful names for nodes
    • Keep physics-heavy objects closer to root
  3. Performance Tips

    • Use wireframe mode for complex scenes
    • Toggle physics visualization only when needed
    • Adjust basicTimeStep based on scene complexity
  4. Configuring basic world parameters

  5. Setting up a simple simulation environment

Afternoon Session: Physics & Configuration

  1. Exploring physics engine parameters
  2. Setting up lighting and camera perspectives
  3. Creating a basic supervisor node

What is a Supervisor Node? A Supervisor node is a special robot node in Webots with privileged access to the simulation. Think of it as a “god mode” controller that can:

Modify the simulation while it’s running Access and modify any object’s position/rotation Create/delete objects dynamically Record simulation data Reset simulation states

Creating a Supervisor Node Basic Setup pythonCopy# In your .wbt world file Robot { controller “my_supervisor” supervisor TRUE # This is the key line … } Python Controller Example pythonCopyfrom controller import Supervisor

Initialize the Supervisor

supervisor = Supervisor() timestep = int(supervisor.getBasicTimeStep())

Get access to objects in the world

robot = supervisor.getFromDef(“ROBOT”) if robot is not None: # Get position of robot position = robot.getPosition() print(f"Robot position: {position}")

# Move robot to new position
translation_field = robot.getField("translation")
translation_field.setSFVec3f([0, 0.5, 0])

while supervisor.step(timestep) != -1: # Main control loop pass Key Supervisor Capabilities

  1. Object Manipulation pythonCopy# Get object by DEF name object = supervisor.getFromDef(“OBJECT_NAME”)

Move object

trans_field = object.getField(“translation”) trans_field.setSFVec3f([x, y, z])

Rotate object

rot_field = object.getField(“rotation”) rot_field.setSFRotation([axis_x, axis_y, axis_z, angle]) 2. Simulation Control pythonCopy# Reset simulation supervisor.simulationReset()

Reset physics

supervisor.simulationResetPhysics()

Get/Set simulation mode

mode = supervisor.simulationGetMode() supervisor.simulationSetMode(Supervisor.SIMULATION_MODE_PAUSE) 3. Dynamic Object Creation pythonCopy# Import node from file root = supervisor.getRoot() children = root.getField(“children”) children.importMFNode(-1, “path/to/object.wbo”)

Create node programmatically

box_string = """ Solid { translation 0 0.5 0 children [ Shape { appearance PBRAppearance { baseColor 1 0 0 } geometry Box { size 0.1 0.1 0.1 } } ] } """ children.importMFNodeFromString(-1, box_string) 4. Data Recording pythonCopy# Record to animation file supervisor.animationStartRecording(“recording.html”)

… simulation runs …

supervisor.animationStopRecording()

Save world state

supervisor.worldSave(“saved_state.wbt”) Common Use Cases

  1. Training Data Generation pythonCopydef collect_training_data(): robot = supervisor.getFromDef(“ROBOT”) object = supervisor.getFromDef(“TARGET”)

    while supervisor.step(timestep) != -1: robot_pos = robot.getPosition() object_pos = object.getPosition()

     # Save to dataset
     with open('training_data.csv', 'a') as f:
         f.write(f"{robot_pos},{object_pos}\n")
    
  2. Reinforcement Learning Setup pythonCopydef reset_episode():

    Reset robot position

    robot = supervisor.getFromDef(“ROBOT”) trans_field = robot.getField(“translation”) trans_field.setSFVec3f([0, 0, 0])

    Randomize object position

    object = supervisor.getFromDef(“TARGET”) object_trans = object.getField(“translation”) random_pos = [random.uniform(-1, 1), 0.5, random.uniform(-1, 1)] object_trans.setSFVec3f(random_pos)

    supervisor.simulationResetPhysics()

  3. Automated Testing pythonCopydef run_test_scenario(): robot = supervisor.getFromDef(“ROBOT”) initial_pos = robot.getPosition()

    Run simulation for 1000 steps

    for _ in range(1000): if supervisor.step(timestep) == -1: break

    final_pos = robot.getPosition() distance = compute_distance(initial_pos, final_pos)

    return distance < 0.1 # Test pass/fail criteria Best Practices

Error Handling

pythonCopydef safe_get_node(supervisor, def_name): node = supervisor.getFromDef(def_name) if node is None: raise ValueError(f"Node ‘{def_name}’ not found in simulation") return node

Resource Management

pythonCopydef cleanup_simulation(): # Stop any recordings supervisor.animationStopRecording()

# Save final state
supervisor.worldSave("final_state.wbt")

# Reset physics
supervisor.simulationResetPhysics()

Performance Considerations

Cache node references instead of getting them repeatedly Minimize physics resets Use batch operations when possible Consider timestep implications when moving objects

Common Pitfalls

Node Access

Always check if nodes exist before accessing Use DEF names consistently Handle None returns from getFromDef()

Physics Interactions

Reset physics after teleporting objects Consider stability when changing object positions Maintain realistic velocities and accelerations

Resource Usage

Close file handles properly Stop recordings when done Clean up created objects when no longer needed

What I Learned Today

Core Concepts

  • Scene graph hierarchy in Webots
    • WorldInfo node structure
    • Physics parameters (CFM, ERP)
    • Object relationships and inheritance

Technical Setup

# Key configuration locations on MacOS
~/Library/Webots/worlds/  # World files
~/Library/Webots/projects/  # Project directory

Critical Parameters

  1. Basic Physics Settings:

    • Gravity: 9.81 m/s²
    • Basic timestep: 32ms (adjustable)
    • Physics engine: ODE
  2. Environment Configuration:

    • Lighting setup (ambient & directional)
    • Camera viewpoints
    • Background settings

What I Wish I Knew Before Starting

Common Pitfalls

  1. Physics Engine Sensitivity

    • Start with default physics parameters
    • Make small, incremental changes
    • Document each modification
  2. Resource Management

    • Keep world files organized in project-specific directories
    • Use relative paths for resources
    • Maintain a consistent naming convention
  3. Version Compatibility

    • Webots version: [Your installed version]
    • ROS2 version: [Your ROS2 version]
    • Document any compatibility issues

Today’s Exercises

  1. Basic World Creation

    • Create new .wbt file
    • Add basic ground plane
    • Configure lighting
    • Add simple geometric objects
  2. Physics Experimentation

    • Test different physics parameters
    • Document effects on simulation
    • Find optimal settings for laundry simulation
  3. Environment Documentation

    • Screenshot key configurations
    • Document parameter settings
    • Create backup of working configurations

Questions to Explore Tomorrow

  1. How do material properties affect physics simulation?
  2. What’s the optimal camera setup for laundry manipulation?
  3. How to implement basic cloth physics?

Resources Used Today

  1. Documentation

    • Webots User Guide: Chapter 1
    • ROS2 Integration Guide
    • Physics Parameters Reference
  2. Tutorials

    • Official Webots tutorials #1-3
    • Community examples for physics setup
  3. Tools

    • Webots IDE
    • ROS2 VM
    • Visual Studio Code for configuration files

Progress Tracking

Completed

  • Basic environment setup
  • World file creation
  • Initial physics configuration

In Progress

  • Physics parameter optimization
  • Camera setup refinement
  • Supervisor node implementation

Blocked

  • None currently

Tomorrow’s Goals

  1. Dive deeper into physics parameters
  2. Begin implementing basic robot control
  3. Set up ROS2 bridge configuration

Notes for Future Reference

  • Keep physics timestep between 16ms and 32ms for stability
  • Back up working configurations regularly
  • Document all parameter changes in version control
  • Test changes incrementally

Mood and Motivation

  • Today’s Challenges: [Fill in at end of day]
  • Victories: [Fill in at end of day]
  • Energy Level: [1-10]
  • Understanding: [1-10]
  • Next Steps: [Fill in at end of day]

links: https://www.reddit.com/r/3Dprinting/comments/1brgped/parol6_3d_printed_robotic_arm_vaccum_gripper/

https://github.com/PCrnjak/PAROL6-Desktop-robot-arm