快速开始#
若想快速启动仿真,可使用以下代码片段在世界中运行一个机器人。
创建一个 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
创建配置文件 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
后续步骤#
Make Environment —— 深入了解仿真循环、状态控制和动态对象。
Configure robots and obstacles —— 运动学、形状和多对象场景。
YAML Configuration —— 完整的配置参考,附带交互式 schema 浏览器。