datetime:2025/12/21 16:00
author:nzb

创建环境

本节内容

  • Python 脚本与 YAML 配置文件
  • 重要参数说明
  • 基础仿真循环
  • 环境控制与状态
  • 配置环境标题

Python 脚本与 YAML 配置文件

import irsim

env = irsim.make('empty_world.yaml')

# Set custom title
env.set_title("Multi-Robot Navigation Simulation")

# Check current status
print(f"Current status: {env.status}")
print(f"Current time: {env.time}")

# Control simulation state
env.pause()    # Pause the simulation
env.resume()   # Resume the simulation

# Main simulation loop
for i in range(50):
    env.step()  # Update simulation state
    env.render(0.05)  # Render with 0.05 second interval (20Hz)

    # Simulation loop with status checking
    if i < 10:
        env.pause()
    elif i > 20 and i < 30:
        env.resume()

    if env.status == "Pause":
        print("Environment is paused")

    # Update title every 10 steps
    if i % 10 == 0:
        env.set_title(f"Simulation Step: {i}")

    if env.done():  # Check if simulation should end
        print("Simulation completed successfully")
        break

env.end()  # Clean up resources
world:
  height: 10  # the height of the world (meters)
  width: 10   # the width of the world (meters)
  step_time: 0.1  # simulation time step (seconds) - 10Hz
  sample_time: 0.1  # rendering frequency (seconds) - 10Hz
  offset: [0, 0] # the offset of the world origin [x, y]
  control_mode: 'auto' # control mode: 'auto', 'keyboard'
  collision_mode: 'stop' # collision behavior: 'stop', 'unobstructed', 'unobstructed_obstacles'
  obstacle_map: null # path to obstacle map file (optional)

results matching ""

    No results matching ""