Webots Environment Setup

Helpful resources: https://github.com/mithi/robotics-coursework

##1.1 World Nodes

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

##1.2 Supervisor Nodes

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

Webots Environment Setup

Overview

Brief introduction to Webots Environment Setup and its importance in the context of robotic laundry folding.

Theory

Core concepts and theoretical foundations.

Implementation

Step-by-step implementation guide with code examples.

Exercises

  1. Exercise 1
  2. Exercise 2
  3. Exercise 3

Additional Resources

  • Related documentation
  • Research papers
  • External tutorials
  • Reference implementations

Project Work

Specific project tasks related to Webots Environment Setup.

Key Takeaways

Summary of main points and learning outcomes.