快速开始#

若想快速启动仿真,可使用以下代码片段在世界中运行一个机器人。

  1. 创建一个 Python 文件并复制下面的代码片段即可运行仿真。

import irsim

env = irsim.make('robot_world.yaml') # initialize the environment with the configuration file

for i in range(300): # run the simulation for 300 steps

    env.step()  # update the environment
    env.render() # render the environment

    if env.done(): 
        break # check if the simulation is done
        
env.end() # close the environment
  1. 创建配置文件 robot_world.yaml,并将以下配置复制到该文件中。

所有配置都写在该 YAML 文件中,你可以通过修改这些配置来自定义仿真。下面是 robot_world.yaml 的示例。

world:
  height: 10  # the height of the world
  width: 10   # the width of the world
  step_time: 0.1  # 10Hz to calculate each step
  sample_time: 0.1  # 10 Hz for render and data extraction 
  offset: [0, 0] # the offset of the world on x and y 

robot:
  kinematics: {name: 'diff'}  # kinematics of the robot, current name should be one of omni, omni_angular, diff, acker. If not set, this object will be static
  shape: {name: 'circle', radius: 0.2}  # radius for circle shape
  state: [1, 1, 0]  # x, y, theta, 2d position and orientation
  goal: [9, 9, 0]  # x, y, theta, 2d position and orientation
  behavior: {name: 'dash'} # move toward the goal directly 
  color: 'g' # green

后续步骤#