YAML配置语法#

配置文件是用于初始化环境的 YAML 文件。它包含用于模拟和可视化世界、障碍物和机器人的配置参数。你只需通过这些参数即可自定义场景并定义对象的行为。


配置总览#

一个完整的 IR-SIM 场景由最多五个顶层键描述 —— worldrobotobstacleguicustomrobotobstacle 接受相同的对象级键,但工厂默认值会因对象类型和运动学而异,例如 role、颜色、状态维度和图像描述。展开下方的交互式树即可浏览每个键及其类型和默认值;除非默认值为 unset,否则所有键均为可选。点击各部分的 full docs › 链接可跳转到详细说明。

在多模拟器的组合配置中,这些键可以嵌套在可选的顶层 irsim 映射下。IR-SIM 读取并验证该映射,同时保持同级的其他模拟器部分不变。传递给 irsim.make() 并由 env.reload() 使用的文件名无需改变。

KeyTypeDefaultDescription
worlddictsimulation environmentfull docs ›
namestr"world"world name
heightfloat10world height (m, y-axis)
widthfloat10world width (m, x-axis)
step_timefloat0.1simulation step (s)
sample_timefloatstep_timerender / sample step (s)
offsetlist[0, 0]world origin offset [x, y]
step_modestr"internal"internal | external
control_modestr"auto"auto | keyboard
collision_modestr"stop"stop | unobstructed | unobstructed_obstacles
statusstr"None"initial display label
obstacle_mapstr/dict/nullnulloccupancy-grid source
mdownsampleint1obstacle-map downsample factor
fog_mapboolfalsefog-of-map overlay
fog_map_resolutionfloatmap resfog cell size (m)
plotdictglobal plot options
saved_figuredict{dpi:100, bbox_inches:'tight'}
figure_pixelslist[1000, 800]figure size in px
show_titlebooltrue
titlestrnullcustom title
no_axisboolfalse
tightbooltrue
viewpointnull/list/strnullcamera center or object to follow
robot / obstaclelistper-object schema (default role: robot / obstacle)full docs ›
namestr/listnullunique id, auto "<role>_<id>"
numberint1how many to create
statelist[1, 1, 0]manual initial [x, y, theta]
goallist[1, 9, 0]manual target [x, y, theta] (or list of)
velocitylist[0]·diminitial control vector
rolestrtop-level keyrobot | obstacle
colorstrrole/kinematicsmatplotlib color
staticboolfalseimmobile object
vel_minlist[-1]·dim
vel_maxlist[1]·dim
accelist[inf]·dimaccel limits
angle_rangelist[-pi, pi]
goal_thresholdfloat0.1arrival distance
arrive_modestr"position"position | state
descriptionstrnullimage label
groupint0
group_namestrnull
unobstructedboolfalseignore collisions
state_dimintnull
vel_dimintnull
fovfloatnullfield-of-view angle (rad)
fov_radiusfloatnull
distributiondictplacement when number > 1
namestr
No extra keys: set state / goal per object.
range_lowlistworld bounds +0.5lower [x, y, θ] bound
range_highlistworld bounds −0.5upper [x, y, θ] bound
min_distancefloat1.0min pairwise spacing
centerlistworld center[x, y, θ] of the circle
radiusfloatmin(w,h)/2−0.5circle radius
kinematicsdictmotion model
namestr
noiseboolfalseadd velocity noise (all variants)
alphalist[0.03, 0, 0, 0.03]noise params [α₁ … α₄]
alphalist[0.03, 0.03]noise params [α_fwd, α_lat]
alphalist[0.03, 0.03, 0.03]noise params [α_fwd, α_lat, α_yaw]
alphalist[0.03, 0, 0, 0.03]noise params
modestr"steer"steer | angular
wheelbase comes from shape.wheelbase.
shapedictgeometry
namestr
radiusfloat0.2circle radius
centerlist[0, 0]body-frame center
random_shapeboolfalserandomize radius
radius_rangelist[0.1, 1.0]when random_shape
wheelbasefloatnullrequired for acker
lengthfloat1.0x-axis length
widthfloat1.0y-axis width
wheelbasefloatnullrequired for acker
verticeslistunset[[x, y], …] body frame
random_shapeboolfalsegenerate random polygons
is_convexboolfalseforce convex when random
Random-gen extras: number, center_range, avg_radius_range, … (see full docs).
partslistunsetnon-empty list of circle, rectangle, or polygon shape dicts
parts[].poselist[0, 0, 0]fixed body-frame [x, y, theta] for each part
verticeslistunset[[x, y], …] body frame
random_shapeboolfalsegenerate random linestrings
is_convexbooltrueforce convex when random
behaviordictper-object motion logic
namestr
wanderboolfalseshared: new random goal on arrival
loopboolfalseshared: cycle waypoints
target_rolesstr"all"shared: all | robot | obstacle
range_lowlist[0,0,-pi]shared: wander bound
range_highlist[10,10,pi]shared: wander bound
angle_tolerancefloat0.1orientation tol. (diff/acker/omni_angular)
vxmaxfloat1.5max x velocity
vymaxfloat1.5max y velocity
accefloat1.0acceleration factor
factorfloat1.0RVO scaling
modestr"rvo"rvo | hrvo | vo
neighbor_thresholdfloat3.0neighbour filter distance
vmaxfloat1.5speed cap after force integration
neighbor_thresholdfloat10.0social interaction cutoff distance
relaxation_timefloat0.5goal-pull time constant tau
force_factor_desiredfloat1.0goal-pull weight
force_factor_socialfloat2.1inter-agent repulsion weight
force_factor_obstaclefloat10.0obstacle repulsion weight
sigma_obstaclefloat0.8obstacle force decay length
lambda_importancefloat2.0velocity vs. position weight in interaction direction
gammafloat0.35interaction range scale
n_angularfloat2.0sideways force angular sharpness
n_velocityfloat3.0slowdown force angular sharpness
safety_radiusfloat0.0personal-space buffer (m) shifting decay closer in
group_behaviordictgroup-level (ORCA)
namestrunsetorca
neighborDistfloat15.0
timeHorizonfloat20.0
safe_radiusfloat0.1
maxSpeedfloat/nullnullfalls back to vel_max
sensorslistlidar2d or fmcw_lidar2d
namestr
range_minfloat0
range_maxfloat10
numberint100beam count
scan_timefloat0.1
noiseboolfalseboth variants
stdfloat0.2
angle_stdfloat0.02
offsetlist[0, 0, 0]
has_velocityboolfalse
plotdictsensor visualization · flat keys also accepted
alphafloat0.3plot transparency
colorstr"r"
motion_compensateboolfalseremove ego-motion from radial velocity
velocity_noise_stdfloat0.0radial-velocity noise std
scan adds radial_velocity and valid arrays.
plotdictDoppler visualization · flat keys also accepted
plotdictper-object visualization
group
obj_colorstrobject's coloroutline / fill colour
obj_alphafloat1.0transparency 0–1
obj_linestylestr"-"outline line style
obj_zorderint3 / 1; image 2draw order (robot / obstacle / image)
show_goalboolfalsetruemaster switch: enables the keys below
goal_colorstrobject's color
goal_alphafloat0.5
show_textboolfalsetruemaster switch: enables the keys below
text_alphafloat1.0
text_positionlistradius offset[dx, dy] from center
show_arrowboolfalsetruemaster switch: enables the keys below
arrow_colorstr"gold"
arrow_lengthfloat0.4
arrow_widthfloat0.6
arrow_alphafloat1.0
show_trajectoryboolfalsetruemaster switch: enables the keys below
traj_colorstrobject's color
traj_widthfloatobject's width
traj_alphafloat0.5
keep_traj_lengthint00 = keep all
show_trailboolfalsetruemaster switch: enables the keys below
trail_freqint2plot every N steps
trail_typestrobject's shape
trail_edgecolorstrobject's color
trail_alphafloat0.7
trail_fillboolfalse
trail_colorstrobject's color
keep_trail_lengthint00 = keep all
show_sensorbooltrueshow sensor visualization
show_fovboolfalsetruemaster switch: enables the keys below
fov_colorstr"lightblue"
fov_alphafloat0.5
guidictoptional interactive controlsfull docs ›
keyboarddictactive when control_mode: keyboard
backendstr"pynput"pynput | mpl
global_hookboolfalse
key_lv_maxfloat3.0
key_ang_maxfloat1.0
key_lvfloat0.0
key_angfloat0.0
key_rotfloat0.0yaw rate (omni_angular)
key_idint0
mousedictinteractive zoom / pan
zoom_factorfloat1.1

小技巧

该树是一个快速导览 —— 点击任意键即可跳转到它的完整说明。完整的说明、示例和边界情况请参见下方各部分的文档。


快速上手示例#

配置文件主要分为三个部分:worldrobotobstacle。下面是一个可直接复制并修改的最小可用示例:

world:
  height: 10  # the height of the world
  width: 10   # the width of the world
  step_time: 0.1  # 10Hz 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 
  step_mode: 'internal'  # 'internal' or 'external'
  collision_mode: 'stop'  # 'stop', 'unobstructed', 'unobstructed_obstacles'
  plot:
    show_title: true
    figure_pixels: [1000, 800]

robot:
  - kinematics: {name: 'diff'}  # omni, diff, acker
    shape: {name: 'circle', radius: 0.2}  # radius
    # shape: {name: 'rectangle', length: 0.5, width: 0.2}  # radius
    state: [1, 1, 0]  
    goal: [9, 9, 0] 
    # acce: [3, .inf]   # acce of [linear, angular]  or [v_x, v_y] or [linear, steer]
    behavior: {name: 'dash'} # move toward to the goal directly 
  
obstacle:
  - number: 10
    distribution: {name: 'random'}
    shape: 
      - {name: 'circle', radius: 1.0}  # radius
      - {name: 'rectangle', length: 1.5, width: 1.2}  # radius
    state: 
      - [5, 5, 0]  
      - [4, 4, 0]
  
  - shape: {name: 'rectangle', length: 1.5, width: 1.2}  # radius
    state: [6, 5, 1] 

  - shape: {name: 'linestring', vertices: [[5, 5], [4, 0], [1, 6]] }  # vertices
    state: [0, 0, 0] 
    unobstructed: True

重要

关键内容配置指南

  • 要在配置文件中包含多个机器人或障碍物,请在 robot 和 obstacle 部分下添加单独的条目,并使用 - 标记每个添加的条目。

  • distribution、shape、behavior、group_behavior 和 kinematics 等参数必须写成 {key: value} 字典形式。请确保每个字典都包含 name 键;省略 name 会使该参数取值为 None。

  • 当处理多个对象(即数量大于 1)时,利用 distribution 参数来定义这些对象的摆放位置的分布方式。

  • 默认情况下,同一组内的所有对象共享相同的配置。要单独自定义组内的某个对象,可使用 - 添加子参数。未显式配置的其余对象会继承组中最后一个已指定对象的设置。

  • 对象级 name 是可选的,用于标识每个对象。若省略,默认值为 "<role>_<id>"(例如 robot_0obstacle_3)。名称在所有对象间必须唯一;重复会在环境初始化时报错。请勿将对象级 nameshapekinematicsbehavior 等字典内部的 name 键混淆(后者表示组件类型)。


World 配置#

本节介绍 world 区块可用的配置参数。

World 参数表#

参数

类型

默认值

说明

name

str

"world"

世界名称

height

float

10

长(米)

width

float

10

世界的宽

step_time

float

0.1

决定仿真每一步之间的时间间隔(秒)。

sample_time

float

step_time

渲染和数据提取的采样时间间隔(秒)。如未指定则默认为 step_time

offset

float 列表

[0, 0]

世界位置在 [x, y] 坐标上的偏移量

step_mode

str

"internal"

状态推进模式,支持 internalexternal

control_mode

str

"auto"

仿真控制模式,支持 autokeyboard

collision_mode

str

"stop"

碰撞处理模式(支持:"stop""unobstructed""unobstructed_obstacles"

status

str

"None"

初始显示标签;第一个完整仿真步后会被运行时状态替换

obstacle_map

strndarraydictnull

None

生成器配置 dict(例如 { name: image, path: '…' }{ name: perlin, resolution: 0.1, })。字符串路径是 image 生成器的简写形式。参见 配置栅格地图

mdownsample

int

1

障碍地图的降采样系数,用于降低分辨率并减少计算量。

fog_map

bool

false

启用地图迷雾叠加层:世界初始为灰色(未探索),随着机器人探索,由每个激光雷达的视线逐步揭示。详见下方 fog_map

fog_map_resolution

float

地图栅格尺寸

迷雾栅格的尺寸(米,仅在 fog_map: true 时生效)。默认与障碍地图的栅格尺寸一致,若无障碍地图则为 0.1。越细腻越平滑但开销越大,越粗糙则越快。

plot

dict

{}

初始化世界图形的绘制选项。

参数详解#

world 属性
namestr,默认: "world"

定义仿真使用的世界名称,便于区分不同环境。

heightfloat,默认 10

指定世界在屏幕 Y 轴方向的垂直尺寸(米)。

widthfloat,默认 10

指定世界在屏幕 X 轴方向的水平尺寸(米)。

step_timefloat,默认 0.1

决定仿真每一步之间的时间间隔。

性能影响step_time 越小仿真频率越高(如 0.1 秒即 10 Hz),但仿真耗时也更长。

sample_timefloat,默认与 step_time 相同)

定义渲染与数据采集的时间间隔,决定可视化更新与记录的频率。未指定时默认等于 step_time;与 step_time 的比值会向下取整为整数步数(至少为 1)。

offsetfloat 列表,默认 [0, 0]

设置世界在 X、Y 轴上的初始偏移,便于在更大坐标系中定位或相对放置。

world 模式
step_modestr,默认:"internal"

定义在 env.step() 期间由谁推进对象状态:

选项:

  • internal:IR-SIM 使用显式动作、键盘命令、群组行为或对象行为,通过自身运动学推进状态。

  • external:由外部系统负责更新状态。使用 set_state()set_velocity() 设置每个对象的状态和速度,然后调用不带动作的 env.step()。IR-SIM 会同步几何信息和传感器、重建碰撞数据、更新状态并推进世界时钟,但不运行自身的运动学或行为逻辑。

irsim.make("world.yaml", step_mode="...") 可以为特定运行覆盖 YAML 中的值;该覆盖在 env.reload()env.reset(random=True) 后仍然有效。

control_mode (str, 默认: "auto")

配置仿真中对象的被控方式:

选项:

  • auto:通过 Python 脚本中定义的输入速度或 YAML 文件中的行为进行自动控制。

  • keyboard:通过键盘输入进行手动控制。按键输入在文件中定义。

collision_mode (str, 默认: "stop")

定义仿真中对象碰撞的处理方式:

选项:

  • stop:发生碰撞时立即停止(默认)。

  • unobstructed:允许对象彼此穿过,不考虑任何碰撞。

  • unobstructed_obstacles:仅允许障碍物彼此穿过而不考虑碰撞;机器人与障碍物发生碰撞时仍会停止。

status (str, 默认值: "None")

设置第一个完整仿真步之前显示的标签。该字段接受任意字符串,默认使用 "None" 哨兵值。

每个完整仿真步结束后,IR-SIM 会用计算得到的运行时状态替换该标签,例如 "Running""Arrived""Collision"

注意:此设置不控制执行。尤其是,status: "Pause" 不会让仿真以暂停状态启动。请使用 env.pause()env.resume() 控制执行,并使用 env.done() 检查是否完成。

world 地图
obstacle_mapdictstrndarraynull,默认值:None

占据栅格来源。标准形式是带 name 的生成器配置字典;其他类型为便捷写法/向后兼容。

  • 生成器配置dict):name 标识生成器。name: image 配合 path(例如 'cave.png')从图像加载,栅格大小取自图像。name: perlin(及其他)需要 resolution;栅格大小 = 世界大小 / resolution。参见 配置栅格地图。要新增生成器,参见 新增地图生成器

  • 图像路径str):等价于 { name: image, path: obstacle_map }(向后兼容)。

  • 占据栅格ndarray):仅供编程方式使用。浮点值 0–100;世界大小必须与栅格形状匹配。

  • null:无障碍物地图(空世界)。

可用地图:我们在 irsim/world/map 文件夹中提供了一些示例地图,你也可以使用来自 HM3DMatterPort3DGibson 等 3D 数据集的自定义地图。更多细节见 此处

# Image path
obstacle_map: 'hm3d_2.png'

# Procedural generator (grid size = world size / resolution)
obstacle_map:
  name: perlin
  resolution: 0.1
  complexity: 0.12
  fill: 0.32
  seed: 48
mdownsample (int, 默认值: 1)

设置障碍物地图图像的降采样系数。

提示:更高的取值会降低障碍地图的分辨率,减小计算负载,从而提升仿真性能。

fog_map (bool, 默认值: false)

启用覆盖整个世界的地图迷雾叠加层(FogMap)。每个栅格初始为灰色(未探索)。每个机器人沿其激光雷达视线揭示栅格,若没有激光雷达,则在其视场扇形(fov / fov_radius)内揭示,因此随着机器人移动,已探索区域不断扩大;已揭示的栅格变为透明,露出底层地图(空闲为白色、障碍为黑色、未知为灰色)。即使无显示(headless),已探索掩码也会每步更新,可用作探索/覆盖率信号(env._world.fog_map.explored_ratio)。参见 usage/24fog_world 示例。

fog_map_resolution (float, 默认值:障碍地图栅格尺寸,否则为 0.1)

迷雾栅格的尺寸(米),仅在 fog_map: true 时使用。省略时与障碍地图的栅格尺寸一致,使迷雾栅格与地图对齐;若无障碍地图则回退为 0.1 米。取值越细腻揭示越平滑,但占用更多内存/时间;取值越粗糙则越快。

world 可视化
plot (dict, 默认值: {})

指定初始化世界绘图时可用的绘制选项。

可视化选项:

  • saved_figure:默认 dpi100;默认格式为 png;默认 bbox_inches 为 tight。更多细节参见 matplotlib.pyplot.savefig

  • figure_pixels: 图像的像素宽和高,默认值为[1000, 800]

  • show_title: 是否显示图表标题,默认是True.

  • title:自定义图表标题;若未指定,则显示仿真时间与当前状态。

  • no_axis: 是否显示坐标轴,默认是False

  • tight: 是否使用紧凑布局,默认是True.

  • viewpoint: 控制相机(视角)的中心位置,默认值为null.

    • null:使用初始的世界边界,不进行自动移动

    • [x, y]:视角始终以固定点[x, y]为中心

    • "<object_name>":跟随该名称的对象进行动态平移,例如"robot_0"

# Examples
plot:
  viewpoint: [3, 3]        # fixed center at (3, 3)
# or
plot:
  viewpoint: "robot_0"     # follow the object named robot_0

完整世界配置示例#

world:
  name: "world"                       # Name of the world
  height: 10                          # Height of the world
  width: 10                           # Width of the world
  step_time: 0.1                      # Time interval between steps (10 Hz)
  sample_time: 0.1                    # Time interval for rendering and data extraction (10 Hz)
  offset: [0, 0]                      # Positional offset of the world on the x and y axes
  step_mode: 'internal'               # State advancement mode ('internal' or 'external')
  control_mode: 'keyboard'            # Control mode ('auto' or 'keyboard')
  collision_mode: 'stop'              # Collision handling mode ('stop', 'unobstructed', 'unobstructed_obstacles')
  obstacle_map: "path/to/map.png"     # Path to the obstacle map image file
  mdownsample: 2                      # Downsampling factor for the obstacle map
  status: "Ready"                     # Initial display label (does not control execution)
  plot:                               # Plotting configuration
    show_title: true                  # Show plot title
    title: "Custom Simulation Title"  # Custom title (optional)
    figure_pixels: [1200, 800]        # Figure size in pixels
    viewpoint: "robot_0"              # Camera center: fixed [x, y], object name, or null
    saved_figure:                     # Figure saving options
      dpi: 150                        # Resolution for saved figures
      format: "png"                   # File format

警告

obstacle_map:将 "path/to/map.png" 替换为你的障碍物地图图像的实际文件路径。请确保图像为兼容格式(如 PNG、JPEG)并正确表示障碍物位置。


Object 配置#

仿真中的 robotobstacle 都作为对象进行配置,参数结构类似但默认值可能不同。本节介绍这些对象可用的配置项。

Object Parameters Table#

Parameter

类型

默认值

描述

name

str 或者 list of str

None

对象的唯一标识符;若省略,则会自动分配为"<role>_<id>"。当number > 1时支持参数列表。

number

int

1

要创建的对象数量。

distribution

dict

{name: manual}

定义多个对象的分布方式。支持的分布方式有:manual, random, circle

kinematics

dict

None

对象的运动学模型。支持 diffackeromniomni_angular。没有运动学模型的对象为静态对象。

shape

dict

None

对象的几何形状。省略时,IR-SIM 创建半径为 1 的圆;显式指定 {name: circle} 时使用半径 0.2。支持 circlerectanglepolygonlinestringcompound

state

float 列表

手动分布时为 [1, 1, 0]

对象的初始状态向量。

velocity

float 列表

[0] * action_dim

初始速度向量。长度与运动学动作维度匹配(diff/omni/acker 为 2,omni_angular 为 3)。

goal

float列表或float列表的列表

手动分布时为 [1, 9, 0]

目标状态向量。

behavior

dict

None

决定对象运动的行为配置,支持 dashrvosfm(可用性取决于 kinematics,详见配置行为)。

group_behavior

dict

None

同组对象的群体行为配置,支持 orca

role

str

从顶层键推断

对象在仿真中的角色(robot 下为 "robot"obstacle 下为 "obstacle")。

color

str

从角色和运动学推断

对象在仿真中的显示颜色。机器人使用运动学相关的默认颜色;障碍物默认使用黑色。

static

bool

派生值

存在运动学模型时为 False;否则对象始终为静态。将其设为 true 可冻结具有运动学模型的对象。

vel_min

float 列表

[-1] * action_dim

各控制维度的最小速度限制。长度与运动学动作维度匹配。

vel_max

float 列表

[1] * action_dim

各控制维度的最大速度限制。长度与运动学动作维度匹配。

acce

float 列表

[inf] * action_dim

加速度限制。长度与运动学动作维度匹配。

angle_range

float 列表

[-pi, pi]

朝向角的弧度范围。

goal_threshold

float

0.1

判定到达目标的距离阈值。

sensors

dict 列表

None

附加到该对象的传感器配置列表。支持的 name:lidar2dfmcw_lidar2d

arrive_mode

str

'position'

到达检测模式。

description

str

None

对象的图像描述或标签。

group

int

0

用于组织的分组 ID,使对象可以按组管理。

group_name

str

None

用于组织的分组名称,使对象能够按组名进行管理。

unobstructed

bool

False

指示对象是否忽略碰撞。

plot

dict

{}

对象可视化的绘图选项。

state_dim

int

None

状态向量维度。

vel_dim

int

None

速度向量维度。

fov

float

None

对象传感器的视场角(弧度),限制在 [0, 2*pi] 内。

fov_radius

float

None

对象传感器的视场半径。

参数详解#

object 属性
概述
  • number — 创建多少个对象

  • distribution — 对象摆放位置分布 (manual, random, circle)

  • state — 初始化位置 ([x, y, θ])

  • goal — 目标位姿 ([x, y, θ])

  • velocity — 初始化速度 ([v, ω], [forward, lateral], [v, φ])

  • state_dim — 状态向量维度 (auto: 3 或 4)

  • vel_dim — 速度向量维度 (auto: 2)

  • name — 对象的唯一标识符

  • role — 对象类型(robotobstacle

number (int, 默认值: 1)

指定使用该配置创建的对象数量。

# Example usage
robot:
  - number: 5
distributiondict,默认值:{name: manual})(源码

number大于1时,定义多个对象在空间中的分布方式。

选项:

  • 'manual':手动为每个对象指定初始状态和目标

    • 这种模式下必须为每个对象提供state(或目标)参数;如果提供的列表长度少于对象数量,则最后一个状态(或目标)会被重复使用。

    # Example usage
    distribution: {name: 'manual'}
    state: [[1, 1, 0], [2, 2, 0], [3, 3, 0]]
    goal: [[9, 9, 0], [8, 8, 0], [7, 7, 0]]
    
  • 'random': 在指定范围内随机分布对象。采样过程采用拒绝采样,保证任意两点在 xy 平面上的距离至少为 min_distance。可选参数:

    • range_low (list): 随机分布的下界 [x, y, theta]。默认值为世界边界向内缩进 0.5,即 [offset_x + 0.5, offset_y + 0.5, -pi]

    • range_high (list): 随机分布的上界 [x, y, theta]。默认值为 [offset_x + width - 0.5, offset_y + height - 0.5, pi]

    • min_distance (float): 采样点之间在 xy 平面上的最小两两距离。默认值为 1.0

    # Example usage
    distribution: {name: 'random', range_low: [0.5, 0.5, -3.14], range_high: [9.5, 9.5, 3.14], min_distance: 1.0}
    
  • 'circle':将对象以圆形阵列排布在指定中心周围。可选参数:

    • center (list): 圆心坐标 [x, y, theta]。默认值为世界中心 [offset_x + width / 2, offset_y + height / 2, 0]

    • radius (float): 圆的半径。默认值为 min(width, height) / 2 - 0.5,使圆形排布留有少量边距。

    # Example usage
    distribution: {name: 'circle', center: [5, 5, 0], radius: 4.0}
    
statefloat 列表,手动分布时默认:[1, 1, 0]

定义对象的初始状态,通常为 [x, y, theta] 格式,其中 theta 表示以弧度为单位的朝向。若提供的状态元素多于所需,多余的会被截断;若不足,缺失值以零补齐。随机分布和圆形分布会根据其分布参数生成状态。

# Example usage
state: [1.0, 1.0, 0.2]
velocityfloat 列表,默认:[0] * action_dim

指定对象的初始速度(列表)。长度须与运动学动作维度匹配。格式取决于运动学模型:

运动学模型的格式:

  • 'diff'模型参数由[v, omega]构成, 其中 v 线速度,omega角速度。

  • 'omni'模型参数由[forward, lateral]构成,为机体坐标系下的速度(相对于朝向的前进和横向速度)。

  • 'acker'模型参数通常由[v, phi]构成,其中 v 是线速度,phi是转向角。

# Example usage
velocity: [1.0, 0.5]
goalfloat 列表或 float 列表的列表,手动分布时默认:[1, 9, 0]

设置对象应移动到的目标状态或位置。与行为配合使用以引导对象导航。格式为 [x, y, theta],或多目标时为 [[x, y, theta], [x, y, theta], ...]。随机分布和圆形分布会根据其分布参数生成目标。

# Example usage - single goal
goal: [10.0, 10.0, 0.2]

注意:对于单个对象的多个目标(注意区分多个对象的单个目标与单个对象的多个目标):

# Example usage - multiple goals
goal: 
  - [[10.0, 10.0, 0.2], [5.0, 4.0, 1.0], [3.0, 3.0, 2.0]]
state_dim (int, 默认值: None)

显式定义状态向量的维度。若未指定,则自动从运动学模型推断。对于大多数使用场景,默认推断即可满足需求。

常用值:

  • 3: 2D的位置和朝向角 [x, y, theta]

  • 4:对于具有额外状态的车辆(例如 Ackermann 模型的[x, y, theta, steer_angle]

# Example usage
state_dim: 3
vel_dim (int, 默认值: None)

显式定义速度向量的维度。若未指定,则自动从运动学模型推断。速度维度取决于特定运动学模型的控制输入。

常用值:

  • 2:对于差速驱动[v, omega]或全向 [forward, lateral]

  • 3:对于带角速度控制的全向模型 [forward, lateral, yaw_rate]

# Example usage
vel_dim: 2
groupint,默认 0

指定用于组织目的的分组标识符,允许对象被分类和管理。具有相同分组 ID 的对象可作为一个整体用于某些操作。

# Example usage
group: 1
group_name (str, 默认值为: None)

用于组织目的指定分组名称,使对象能够被分类并统一管理。具有相同分组名称的对象在某些操作中可作为一个整体进行处理。

# Example usage
group_name: "robot_flow"
namestrstr 列表,默认 None

为对象设置唯一标识符。若未提供,名称默认为 "_"(例如 robot_0obstacle_3)。名称在环境中所有对象间必须唯一;重复会在初始化时抛出 ValueError

  • 创建多个对象(number > 1)时,可提供名称列表。若列表长度小于对象数量,则最后一个名称会被重复使用;请确保名称唯一性以避免错误。

# Example usage - single object
robot:
  - name: "r1"
    kinematics: {name: 'diff'}
    shape: {name: 'circle', radius: 0.2}
    state: [1, 1, 0]
    goal: [9, 9, 0]
# Example usage - multiple objects with explicit names
robot:
  - number: 3
    name: ["r1", "r2", "r3"]
    distribution: {name: 'circle', center: [5, 5, 0], radius: 4.0}
    kinematics: {name: 'diff'}
    shape: {name: 'circle', radius: 0.2}

备注

请勿将对象级 nameshapekinematicsbehavior 等字典内部的 name 键混淆。后者指定该组件的类型,而非对象的标识符。

rolestr,从顶层键推断)

定义对象在仿真中的角色。在 YAML 配置中,该值由对象所属的配置区块推断,通常无需手动设置:

  • 'robot':主动实体,通常由行为或输入命令控制。

  • 'obstacle':被动实体,可静止也可移动,但参与碰撞检测。

object 运动学
运动学模型
  • diff — 差速驱动,由线速度和角速度控制([v, omega]

  • omni — 全向移动,由机体坐标系下的前进和横向速度控制([forward, lateral]

  • omni_angular — 带角速度控制的全向移动,由机体坐标系下的速度和偏航角速度控制([forward, lateral, yaw_rate]

  • acker — 阿克曼转向,由线速度和转向角控制([v, phi]

速度指令在机器人自身坐标系下表示,而 [vx, vy] 描述的是世界坐标系下的刚体运动。RVO、SFM、ORCA 等全向规划器在世界坐标系下求解,因此其速度会在该边界处完成转换。在世界坐标系下规划的外部控制器同样按此转换:

env.step(env.robot.vel_world2body(world_vel))

omni[vx, vy] 旋转为 [forward, lateral]diff 则依据机器人的角速度上限与世界步长,将其映射为 [linear, angular]ackeromni_angular 由指令直接控制,世界坐标系下的平移速度无法确定其指令,因此该转换会抛出异常。


(p-o-kinematics)=
**`kinematics`** (`dict`, default: `None`)
: Sets the kinematic model governing the object's movement.

  **Options:**
  - `'diff'`: Differential drive robot, suitable for robots that can rotate in place (e.g., two-wheel robots). This type of robot is controlled by linear and angular velocity. Optional parameters:
    - `noise` (bool): whether to add noise to the velocity commands. Default is `False`.
    - `alpha` (list): noise parameters for velocity commands. Default is `[0.03, 0, 0, 0.03]`.    

    ```yaml
    # Example usage
    kinematics: {name: 'diff', noise: True, alpha: [0.03, 0, 0, 0.03]}
    ```

  - `'omni'`: Omnidirectional movement, allowing movement in any direction without changing orientation. This type of robot is controlled by body-frame velocities `[forward, lateral]`. Orientation (theta) is preserved but not updated. Optional parameters:
    - `noise` (bool): whether to add noise to the velocity commands. Default is `False`.
    - `alpha` (list): noise parameters for velocity commands `[alpha_forward, alpha_lateral]`. Default is `[0.03, 0.03]`.   

    ```yaml
    # Example usage
    kinematics: {name: 'omni', noise: True, alpha: [0.03, 0.03]}
    ```

  - `'omni_angular'`: Omnidirectional movement with angular velocity control. Extends `omni` by adding a yaw rate channel that integrates orientation (theta). This type of robot is controlled by body-frame velocities `[forward, lateral, yaw_rate]`. Optional parameters:
    - `noise` (bool): whether to add noise to the velocity commands. Default is `False`.
    - `alpha` (list): noise parameters for velocity commands `[alpha_forward, alpha_lateral, alpha_yaw]`. Default is `[0.03, 0.03, 0.03]`.

    ```yaml
    # Example usage
    kinematics: {name: 'omni_angular', noise: True, alpha: [0.03, 0.03, 0.03]}
    ```

  - `'acker'`: Ackermann steering, typical for car-like vehicles requiring a turning radius.
    - `noise` (bool): whether to add noise to the velocity commands. Default is `False`.
    - `alpha` (list): noise parameters for velocity commands. Default is `[0.03, 0, 0, 0.03]`.  
    - `mode` (str): steering mode, either `steer` or `angular`. Default is `steer`.
      - `steer`: the object is controlled by linear and steer angle.
      - `angular`: the object is controlled by linear and angular velocity. 

    ```yaml
    # Example usage
    kinematics: {name: 'acker', noise: True, alpha: [0.03, 0, 0, 0.03], mode: 'steer'}
    ```
  

  Any other key under `kinematics` is passed to the handler's constructor. This is how a model registered with `@register_kinematics` receives its own parameters, e.g. `kinematics: {name: 'lag', tau: 0.5}`.

(p-o-vel-min)=
**`vel_min`** (`list` of `float`, default: `[-1, -1]`) and **`vel_max`** (`list` of `float`, default: `[1, 1]`)
: Set the minimum and maximum velocity limits for each control dimension (e.g., linear and angular velocities). These constraints ensure the object's motion stays within feasible and safe bounds.

(p-o-acce)=
**`acce`** (`list` of `float`, default: `[inf, inf]`)
: Defines acceleration limits as the maximum change in velocity per time step for each control dimension. This parameter simulates the physical limitations of the object's motion capabilities.

(p-o-angle-range)=
**`angle_range`** (`list` of `float`, default: `[-pi, pi]`)
: Specifies the allowed range of orientation angles `[min, max]` in radians. The object's orientation angle `theta` is wrapped within this range to maintain consistency.

(p-o-goal-threshold)=
**`goal_threshold`** (`float`, default: `0.1`)
: Determines the proximity threshold to the goal at which the object is considered to have arrived. Once within this distance, arrival behaviors or state changes may be triggered.

  ```yaml
  # Example usage
  vel_min: [-1, -1]
  vel_max: [1, 1]
  acce: [0.5, 0.1]
  angle_range: [-pi, pi]
  goal_threshold: 0.1

警告

使用 acker 运动学模型时,请确保在 shape 配置中设置 wheelbase 参数;kinematics 下的 wheelbase 会覆盖它。

object 形状
概述
  • circle — 圆形(radiuscenter

  • rectangle — 矩形(lengthwidthwheelbase

  • polygon — 自定义多边形(verticesis_convex

  • compound — 固定实体部件的组合(partspose

  • linestring — 线段(vertices

shapedict,默认 {name: circle}

决定初始状态下用于碰撞检测和可视化的几何形状。如果完全省略 shape,对象将回退为以 [0, 0] 为中心、radius: 1 的圆;下面的 radius: 0.2 仅在给定 circle 形状但未显式指定 radius 时作为默认值。

支持的形状:

  • 'circle':圆形。

    • radiusfloat):圆半径,默认 0.2

    • centerlist):圆心在机体坐标系中的 [x, y] 偏移,会随对象朝向旋转。默认值为 [0, 0]。对于阿克曼圆形,实际圆心还会向前偏移 wheelbase / 2

    • random_shapebool):是否随机半径,默认 False

    • radius_rangelist):当 random_shapeTrue 时用于随机半径生成的范围 [min_radius, max_radius]。默认值为 [0.1, 1.0]

    • wheelbasefloat):阿克曼转向车辆的轴距,使用 'acker' 时必填,默认 None

    # Example usage
    shape: {name: 'circle', radius: 0.2, center: [0, 0]}
    
  • 'rectangle':矩形。

    • lengthfloat):x 轴方向长度,默认 1.0

    • widthfloat):y 轴方向宽度,默认 1.0

    • wheelbasefloat):阿克曼转向车辆的轴距,使用 'acker' 时必填,默认 None

    # Example usage
    shape: {name: 'rectangle', length: 1.0, width: 0.5}
    
  • 'polygon':由顶点列表定义的多边形。

    • vertices(列表):定义多边形的顶点列表,格式 [[x1, y1], ...]。若未提供则生成随机多边形。

    • random_shapebool):是否生成一系列随机多边形,默认 False

    • is_convexbool):是否生成一系列随机凸多边形,默认 False

    # Example usage
    shape:
      name: 'polygon'
      vertices: 
        - [4.5, 4.5]
        - [5.5, 4.5]
        - [5.5, 5.5]
        - [4.5, 5.5]
    
    # Example usage - random polygon
    shape:
      - {name: 'polygon', random_shape: true, center_range: [5, 10, 40, 30], avg_radius_range: [0.5, 2], irregularity_range: [0, 1], spikeyness_range: [0, 1], num_vertices_range: [4, 5]} 
    
  • 'compound':表示由固定实体部件组合而成的一个刚性形状。

    • partslist):由 circlerectanglepolygon 形状字典组成的非空列表。

    • poselist):部件相对于所属对象坐标系原点的可选 [x, y, theta] 位姿。默认值为 [0, 0, 0]theta 使用弧度。

    # Example usage - compound robot body
    shape:
      name: compound
      parts:
        - {name: rectangle, length: 0.8, width: 0.3}
        - {name: rectangle, length: 0.3, width: 0.8, pose: [-0.25, 0, 0]}
    
  • 'linestring':由顶点列表定义的折线,类似多边形但生成的是一串线。

    • vertices(列表):定义线串的顶点列表,格式 [[x1, y1], ...]

    • random_shapebool):是否生成随机线串(多边形),默认 False

    • is_convexbool):是否生成随机凸线串(多边形),默认 True

    # Example usage
    shape:
      name: 'linestring'
      vertices: 
        - [4.5, 4.5]
        - [5.5, 4.5]
        - [5.5, 5.5]
        - [4.5, 5.5]
    
    # Example usage - random linestring
    shape:
      - {name: 'linestring', random_shape: true, center_range: [5, 10, 40, 30], avg_radius_range: [0.5, 2], irregularity_range: [0, 1], spikeyness_range: [0, 1], num_vertices_range: [4, 5]} 
    
object 行为
行为系统
  • behaviordash(直接朝目标移动)、rvo(互惠速度障碍)、sfm(社会力模型)

  • group_behaviororca(最优互惠碰撞避免)

  • static — 静止对象(True/False

behaviordict,默认 None

配置对象的运动行为,可为简单或复杂策略,并可包含额外参数。

选项:

  • 'dash':以最大允许速度直接朝目标移动。

    • wander(bool/False):是否加入随机游走。若为 True,对象到达当前目标后会随机分配新目标。

    • loop(bool/False):是否循环导航路径点。若为 True,对象到达最后一个路径点后会从第一个路径点重新开始。

    • target_roles(str/all):仅对具有目标角色的对象应用该行为。当前可设为 robotobstacle

    • range_low(列表):随机游走下界,默认 [0, 0, -3.14]

    • range_high(列表):随机游走上界,默认 [10, 10, 3.14]

    • angle_tolerance(float):diffackeromni_angular 运动学的朝向校准容差,默认 0.1

    示例:

    behavior: {name: 'dash', wander: True, range_low: [0, 0, -3.14], range_high: [10, 10, 3.14], angle_tolerance: 0.1}
    
  • 'rvo':实现多动态体避碰的 RVO 算法,支持 diffomni 运动学。

    • wander(bool/False):是否加入随机游走。若为 True,对象到达当前目标后会随机分配新目标。

    • loop(bool/False):是否循环导航路径点。若为 True,对象到达最后一个路径点后会从第一个路径点重新开始。

    • target_roles(str/all):仅对具有目标角色的对象应用该行为。当前可设为 robotobstacle

    • range_low(列表):随机游走下界,默认 [0, 0, -3.14]

    • range_high(列表):随机游走上界,默认 [10, 10, 3.14]

    • vxmax(float):x 轴最大线速度,默认 1.5

    • vymax(float):y 轴最大线速度,默认 1.5

    • acce(float):最大加速度,默认 1.0

    • factor(float):RVO 算法因子,默认 1.0

    • mode(str):RVO 算法模式,可选 rvohrvovo,默认 rvo

      • rvo:互惠速度障碍法,用于多智能体避碰。

      • hrvo:混合 RVO,将 RVO 与 VO 结合以减少死锁。

      • vo:速度障碍,用于避障。

    • neighbor_threshold(float):筛选邻居的距离阈值,默认 3.0

    示例:

    behavior: {name: 'rvo', vxmax: 1.5, vymax: 1.5, acce: 1.0, factor: 1.0, mode: 'rvo', wander: False}
    
  • 'sfm':实现社会力模型,用于反应式行人风格避障。支持 diffomni 运动学。

group_behaviordict,默认 None

同组内所有对象的群体行为。对于协同行为(如群体或人群仿真)更高效,因为它在单步中为所有成员计算动作。必须包含 name 及行为特定参数。

选项:

  • 'orca':用于多智能体导航的最优互惠碰撞避免(ORCA)。需要 pyrvo 包(pip install pyrvo)。仅在使用该行为时仿真才会尝试导入它。

    • wander(bool/False):是否加入随机游走。若为 True,对象到达当前目标后会随机分配新目标。

    • range_low(列表):随机游走下界,默认 [0, 0, -3.14]

    • range_high(列表):随机游走上界,默认 [10, 10, 3.14]

    • neighborDist(float/15.0):搜索邻居的最大距离。

    • maxNeighbors(int/10):考虑的邻居数量上限。

    • timeHorizon(float/20.0):相对于其他智能体计算安全速度的时间范围。

    • timeHorizonObst(float/10.0):相对于静态障碍物计算安全速度的时间范围。

    • safe_radius(float/0.1):额外的安全半径填充。

    • maxSpeed(float/None):智能体最大速度。若为 None,使用对象的 vel_max

    示例:

    group_behavior: 
      name: 'orca'
      neighborDist: 10.0
      maxNeighbors: 10
      timeHorizon: 10.0
      timeHorizonObst: 10.0
      safe_radius: 0.1
    

static:布尔值,表示对象是否静止。静止对象忽略运动学与行为,保持初始状态。

示例:

static: True
object 传感器
概述
  • lidar2d — 2D 激光雷达(range_min/maxangle_rangenoise

  • fmcw_lidar2d —— 2D FMCW 激光雷达(range/radial_velocitymotion_compensate、多普勒可视化)

  • fov — 视场角(弧度)

  • fov_radius — 最大探测距离

sensors:为对象挂载传感器以感知环境。每个传感器以字典形式描述其类型与参数,目前支持:

  • lidar2d:用于距离测量的 2D LiDAR,参数包括:

    • range_min(float):最小探测距离,默认 0.0

    • range_max(float):最大探测距离,默认 10.0

    • angle_range(float):传感器覆盖角度,默认 pi,限制在 [0, 2*pi] 内(6.283185 为 360° 全向扫描)。

    • number(int):激光束数量,默认 100

    • scan_time(float):完成一次扫描的时间,默认 0.1

    • noise(bool):测量是否加入噪声,默认 False

    • std(float):当 noise=True 时距离噪声的标准差,默认 0.2

    • angle_std(float):noise=True 时的角度噪声标准差,默认 0.02

    • offset(列表):传感器相对对象位置 (x, y, theta) 的偏移,默认 [0, 0, 0]

    • has_velocity(bool):是否测量点速度,默认 False

    可视化选项位于传感器的 plot: 子字典下(为向后兼容,仍接受扁平的顶层键):

    • alpha(float):绘图透明度,默认 0.3

    • color(str):传感器颜色,默认 r

    示例:

    sensors:
      - name: 'lidar2d'
        range_min: 0
        range_max: 5
        angle_range: 3.14 
        number: 200
        noise: False
        std: 0.2
        angle_std: 0.2
        offset: [0, 0, 0]
        plot:
          alpha: 0.3
    
  • fmcw_lidar2d:用于距离和径向多普勒测量的简化 2D FMCW 激光雷达。它复用 lidar2d 的波束几何,并新增两个功能参数:

    • motion_compensate(bool/False):是否从测得的径向速度中消除自身运动。

    • velocity_noise_std(float/0.0):径向速度上高斯噪声的标准差。

    所有可视化选项位于传感器的 plot: 子字典下(与 lidar2d 和对象的 plot: 约定相同)。为向后兼容,仍接受扁平的顶层键。

    • velocity_color(bool/True):是否按径向速度为有效波束着色。

    • velocity_color_max(float/2.0):绘图颜色饱和时对应的速度大小。

    • velocity_linewidth(float/2.5):有效回波的绘图线宽。

    • no_hit_linewidth(float/0.8):无效波束的绘图线宽。

    • no_hit_alpha(float/0.03):无效波束的绘图透明度。

    • show_velocity_markers(bool/True):是否在有效端点处绘制彩色命中标记。

    • velocity_marker_size(float/36):有效端点的绘图标记大小。

    • velocity_marker_edge_color(str/black):端点标记的边缘颜色。

    • velocity_marker_edge_width(float/0.6):端点标记的边缘宽度。

    • zero_velocity_color(str/cyan):用于接近零径向速度的绘图颜色。

    • positive_velocity_color(str/crimson):用于正径向速度的绘图颜色。

    • negative_velocity_color(str/royalblue):用于负径向速度的绘图颜色。

    • no_hit_color(str/lightgray):用于无效波束的绘图颜色。

    扫描输出在标准激光雷达角度元数据的基础上,增加了 radial_velocityvalid 数组。

    示例:

    sensors:
      - type: 'fmcw_lidar2d'
        range_min: 0.0
        range_max: 8.0
        angle_range: 2.0944
        number: 121
        motion_compensate: False
        plot:
          velocity_color: True
          velocity_linewidth: 2.0
          velocity_marker_size: 45
    

fovfov_radius:定义对象传感器的视场(FOV)。FOV 是传感器可检测对象的角度范围。fov 参数以弧度指定角度范围,fov_radius 设置最大检测距离。

示例:

fov: 1.57
fov_radius: 5.0
object 模式
概述
  • arrive_mode — 目标判定方式(positionstate

  • unobstructed — 忽略碰撞(True/False

arrive_modestr,默认 'position'

选择判定对象是否到达目标的方法:

选项:

  • 'position':仅根据与目标位置 ([x, y]) 的距离判断。

  • 'state':同时考虑位置与朝向 ([x, y, theta])。

示例:

arrive_mode: 'position'
unobstructedbool,默认 False

当设为 True 时,该对象被视为无障碍,忽略与其他对象和障碍物的碰撞,适合测试或需要不被阻挡的对象。

示例:

unobstructed: True
object 可视化
概述
  • color — 对象颜色('r''blue''k' 等)

  • description — 图像文件(如 'car_blue.png''diff_robot0.png'

  • plot — 进阶显示选项

    • Object — 外观(obj_colorobj_alphaobj_linestyle

    • Goal — 目标标记(show_goalgoal_colorshow_goal_text

    • Trail — 轨迹点(show_trailkeep_trail_length

    • Trajectory — 路径线(show_trajectorykeep_traj_length

    • Sensors — 传感器显示(show_sensorshow_fov

colorstr,默认从角色和运动学推断)

指定对象在可视化中的颜色,便于识别。带有已注册运动学的机器人使用运动学处理器定义的颜色;障碍物默认使用黑色。详细颜色选项见 matplotlib color

示例:

color: 'r'
descriptionstr,默认 None

提供用于图形展示的图像,可使用 world/description 下的文件,或自定义绝对路径。

可用图像:

  • car_green.png:阿克曼车辆默认图。

  • car_blue.png

  • car_red.png

  • diff_robot0.png

  • diff_robot1.png

示例:

description: 'car_blue.png'

plot:包含控制对象显示的绘图选项。所有绘图元素初始创建在原点,并在动画更新时通过变换与数据更新定位。

对象可视化属性:

  • obj_linestyle(str):对象轮廓线型(如 '-', '--', ':', '-.'),默认 '-'.

  • obj_zorder(int):对象元素的绘制层级。机器人图形默认 3,障碍物图形默认 1,描述图片默认 2。

  • obj_color(str):对象颜色,默认沿用 color

  • obj_alpha(float):对象透明度(0.0-1.0),默认 1.0。

  • obj_linewidth(float/1.0):对象轮廓线宽,单位为 Matplotlib 点。

目标可视化:

  • show_goal(bool):是否显示目标位置,默认 False。

    • goal_color(str):目标标记颜色,默认与对象一致。

    • goal_alpha(float):目标透明度,默认 0.5。

    • goal_zorder(int):目标层级,默认 1。

  • show_goal_text(bool):是否显示目标位置的文本,默认 False。

文本标签可视化:

  • show_text(bool):是否显示文本信息,默认 False。默认显示对象缩写(如 r0o1)。可在运行时通过 object.set_text("自定义文本") 设置自定义文本。传入 None 可重置为默认缩写。

    • text_color(str):文本颜色,默认 'k'(黑)。

    • text_size(int):字体大小,默认 10。

    • text_alpha(float):文本透明度,默认 1.0。

    • text_zorder(int):文本层级,默认 2。

    • text_position(列表):相对对象中心的偏移 [dx, dy],默认 [-radius-0.1, radius+0.1]

同样,目标文本可通过 object.set_goal_text("自定义目标文本") 进行自定义。

速度箭头可视化:

  • show_arrow(bool):是否显示速度箭头,默认 False。

    • arrow_color(str):箭头颜色,默认 "gold"。

    • arrow_length(float):箭头长度,默认 0.4。

    • arrow_width(float):箭头宽度,默认 0.6。

    • arrow_alpha(float):箭头透明度,默认 1.0。

    • arrow_zorder(int/3):箭头的绘制层级。

轨迹线可视化:

  • show_trajectory(bool):是否显示路径线,默认 False。

    • traj_color(str):路径颜色,默认继承对象颜色。

    • traj_style(str):路径线型(如 '-', '--', ':', '-.'),默认 "-"。

    • traj_width(float/对象宽度):轨迹线宽,默认为对象宽度。

    • traj_alpha(float):路径透明度,默认 0.5。

    • traj_zorder(int):路径层级,默认 0。

    • keep_traj_length(int):保留的尾段步数,默认 0(保留全部)。

对象轨迹点可视化:

  • show_trail(bool):是否显示轨迹点,默认 False。

    • trail_freq(int):轨迹显示频率(每 N 步),默认 2。

    • trail_type(str):轨迹形状类型,默认与对象形状相同。

    • trail_edgecolor(str):轨迹边缘颜色,默认为对象颜色。

    • trail_linewidth(float):轨迹线宽,默认 0.8。

    • trail_alpha(float):轨迹透明度,默认 0.7。

    • trail_fill(bool):是否填充轨迹形状,默认 False。

    • trail_color(str):轨迹填充色,默认为对象颜色。

    • trail_zorder(int):轨迹层级,默认 0。

    • keep_trail_length(int):保留的轨迹尾段步数,默认 0(保留全部)。

传感器可视化:

  • show_sensor(bool):是否显示传感器,默认 True。

视场可视化:

  • show_fov(bool):是否显示视场,默认 False。

    • fov_color(str):视场填充色,默认 "lightblue"。

    • fov_edge_color(str):视场边缘色,默认 "blue"。

    • fov_alpha(float):视场透明度,默认 0.5。

    • fov_zorder(int):视场层级,默认 1。

注意: 所有可视化元素在初始化时创建于原点,并在动画期间通过 matplotlib 的变换(patch)与 set_data(线)定位。

示例:

plot:
  # Object appearance
  obj_linestyle: '--'
  obj_zorder: 3
  obj_color: 'blue'
  obj_alpha: 0.8
  obj_linewidth: 2.0
  
  # Goal visualization
  show_goal: True
  goal_color: 'red'
  goal_alpha: 0.7
  goal_zorder: 2
  
  # Text labels
  show_text: True
  text_color: 'black'
  text_size: 12
  text_alpha: 0.9
  text_zorder: 5
  
  # Velocity arrows
  show_arrow: True
  arrow_color: 'gold'
  arrow_length: 0.5
  arrow_width: 0.8
  arrow_alpha: 0.9
  arrow_zorder: 4
  
  # Trajectory path
  show_trajectory: True
  traj_color: 'green'
  traj_style: '-'
  traj_width: 0.6
  traj_alpha: 0.6
  traj_zorder: 1
  
  # Object trails
  show_trail: True
  trail_freq: 3
  trail_edgecolor: 'purple'
  trail_linewidth: 1.0
  trail_alpha: 0.5
  trail_fill: False
  trail_color: 'purple'
  trail_zorder: 0
  
  # Sensors and FOV
  show_sensor: True
  show_fov: True
  fov_color: 'lightblue'
  fov_edge_color: 'blue'
  fov_alpha: 0.3
  fov_zorder: 1

GUI 配置#

GUI 参数表#

Parameter

类型

默认值

描述

keyboard

dict

{}

键盘控制选项(当 world.control_mode: keyboard 时生效)。

mouse

dict

{}

鼠标控制选项。

键盘控制

keyboarddict,默认值:{})配置键盘控制。选项由 KeyboardControl 读取。默认后端为 pynput。若 pynput 不可用,IR‑SIM 会自动回退到 Matplotlib 后端。

  • backendstr):键盘后端。

    • "pynput"(默认):全局键盘hook,但需 Matplotlib 窗口聚焦(依赖 pynput 包)。

    • "mpl":Matplotlib 图窗按键事件,仅在窗口聚焦时生效;无额外依赖,但对象数量多时可能有延迟。

  • global_hookbool/False):当 backend: 'pynput' 时,即使 Matplotlib 窗口未获得焦点也捕获按键。(仅在窗口获得焦点时生效)。

  • key_lv_maxfloat):最大线速度,默认 3.0。

  • key_ang_maxfloat):最大角速度,默认 1.0。

  • key_lvfloat):初始线速度,默认 0.0

  • key_angfloat):初始角速度,默认 0.0

  • key_rotfloat):初始旋转速度(omni_angular 运动学下的偏航角速度),默认 0.0

  • key_idint):初始机器人控制 ID,默认 0

# Example: enable keyboard control with GUI settings
world:
  control_mode: 'keyboard'

gui:
  keyboard:
    backend: 'pynput'     # or 'mpl'
    global_hook: true     # if your want to capture keys globally. Default is False.
    key_id: 0
    key_lv_max: 3.0
    key_ang_max: 1.0

键盘控制按键:

  • w — 前进

  • s — 后退

  • a — 左转(diff/acker)或左侧平移(omni/omni_angular

  • d — 右转(diff/acker)或右侧平移(omni/omni_angular

  • q — 左旋转(omni_angular 的偏航角速度)

  • e — 右旋转(omni_angular 的偏航角速度)

  • z / c — 降低 / 提高最大角速度(key_ang_max

  • shift+z / shift+c — 降低 / 提高最大线速度(key_lv_max

  • alt+num — 更改当前控制的机器人ID

  • r — 重置环境

  • space — 切换暂停/恢复环境

  • esc — 退出环境(设置退出标志)

  • x — 切换键盘/自动控制

  • l — 重新加载环境

  • F5 — 调试环境(Mac上使用fn+f5)

  • v — 保存当前图像

  • y — 切换显示渲染窗口

小技巧

调试模式可逐帧推进仿真以便检查:

  • F5 在当前帧进入调试模式,再次按下 F5 进入单步。

  • space 退出调试模式并恢复正常执行。

注意:

  • 在 macOS 笔记本上可能需要配合 fn 键(如 fn+F5)。alt 键对应 option

鼠标控制

mousedict,默认 {}):配置鼠标控制,由 MouseControl 读取。

  • zoom_factorfloat):缩放因子,默认 1.1

gui:
  mouse:
    zoom_factor: 1.1

备注

鼠标操作:

  • 鼠标移动 — 跟踪鼠标位置并更新显示坐标

  • 中键点击 — 重置缩放到默认视图

  • 滚轮向上 — 放大(以鼠标位置为中心)

  • 滚轮向下 — 缩小(以鼠标位置为中心)

鼠标位置属性:

  • left_click_postuple):左键点击位置 (x, y)。

  • right_click_postuple):右键点击位置 (x, y)。

  • mouse_postuple):当前鼠标位置 (x, y)。


自定义配置#

自定义参数#

custom 会从 YAML 中读取并原样返回。IR-SIM 不会解析其内容,因此场景可以把自己代码所需的数值(容差、规划器权重等)与仿真器读取的参数放在同一个文件中,一并修改。

world:
  height: 20
  width: 20
  step_time: 0.1

robot:
  - kinematics: {name: 'diff'}
    shape: {name: 'circle', radius: 0.35}

custom:
  safe_margin: 0.15
  planner: {horizon: 20, weights: [1.0, 0.5]}

通过 config 读取,它返回全部已解析的配置段,因此与机器人半径写在一起的数值无需再次打开文件即可获得:

env = irsim.make("world.yaml")

margin = env.config["custom"]["safe_margin"] + env.robot.radius
horizon = env.config["custom"]["planner"]["horizon"]
step_time = env.config["world"]["step_time"]

custom 内部不做任何校验,可以自由嵌套;场景未提供该段时默认为 {}env.reload() 会连同文件其余部分一起重新读取。

配置示例#

下面通过多个配置示例展示 IR-SIM 的灵活性与能力:

robot:
  - number: 10
    distribution: {name: 'circle', radius: 4.0, center: [5, 5]}  
    kinematics: {name: 'diff'}
    shape: 
      - {name: 'circle', radius: 0.2}  
    behavior: {name: 'rvo', vxmax: 1.5, vymax: 1.5, acce: 1.0, factor: 1.0}
    vel_min: [-3, -3.0]
    vel_max: [3, 3.0]
    color: ['royalblue', 'red', 'green', 'orange', 'purple', 'yellow', 'cyan', 'magenta', 'lime', 'pink', 'brown'] 
    arrive_mode: position
    goal_threshold: 0.15
    plot:
      show_trail: true
      show_goal: true
      trail_fill: true
      trail_alpha: 0.2
      show_trajectory: false
robot:
  - number: 10
    distribution: {name: 'circle', radius: 4.0, center: [5, 5]}
    kinematics: {name: 'omni'}
    shape: {name: 'circle', radius: 0.2}
    group_behavior: 
      name: 'orca'
      neighborDist: 10.0
      maxNeighbors: 10
      timeHorizon: 10.0
      timeHorizonObst: 10.0
      safe_radius: 0.1
    vel_max: [2.0, 2.0]
    goal: [9, 9, 0]
    plot:
      show_trail: true
      trail_alpha: 0.5
obstacle:
  - shape: {name: 'circle', radius: 1.0}  # radius
    state: [5, 5, 0]  
  
  - shape: {name: 'rectangle', length: 1.5, width: 1.2}  # radius
    state: [6, 5, 1] 

  - shape: {name: 'linestring', vertices: [[5, 5], [4, 0], [1, 6]] }  # vertices
    state: [0, 0, 0] 
    unobstructed: True

  - shape:
      name: 'polygon'
      vertices: 
        - [4.5, 4.5]
        - [5.5, 4.5]
        - [5.5, 5.5]
        - [4.5, 5.5]
robot:  
  - kinematics: {name: 'acker'}  
    shape: {name: 'rectangle', length: 4.6, width: 1.6, wheelbase: 3}
    state: [1, 1, 0, 0]
    goal: [40, 40, 0]
    vel_max: [4, 1]
    behavior: {name: 'dash'}
    plot:
      show_trajectory: True
robot:
  - kinematics: {name: 'omni_angular'}
    shape: {name: 'circle', radius: 0.2}
    state: [2, 2, 0]
    goal: [8, 8, 0]
    velocity: [0, 0, 0]
    vel_min: [-1, -1, -1]
    vel_max: [1, 1, 1]
    behavior: {name: 'dash'}
    plot:
      show_trajectory: True
robot:
  - kinematics: {name: 'diff'}
    shape: {name: 'circle', radius: 0.3}
    state: [2, 2, 0]
    goal: [8, 8, 0]
    behavior: {name: 'rvo'}
    sensors:
      - name: 'lidar2d'
        range_min: 0.1
        range_max: 8.0
        angle_range: 6.28  # Full 360 degrees
        number: 360
        noise: True
        std: 0.1
        offset: [0, 0, 0]
        color: 'red'
    plot:
      show_sensor: True
      show_fov: True
      fov_color: 'lightgreen'
      fov_alpha: 0.3

小技巧

配置最佳实践:

  • 多个对象:配置多个对象时,使用 numberdistribution 参数可高效地生成它们。例如,设置 number: 10 并使用 'random'distribution,可快速在仿真中随机放置大量对象。

  • 字典参数:所有字典类型的参数(如 distributionshapekinematicsbehavior)都必须包含 'name' 键以指定其类型。省略 'name' 键会导致使用默认值或报错。

  • 分组配置:同组对象默认共享配置。若需定制,请使用 - 添加子参数;未显式配置的对象会继承组内最后一个配置。

  • 运动学与速度:确保 velocityvel_max 的格式与运动学模型匹配,例如差速 ('diff') 使用 [v, omega],全向 ('omni') 使用机体坐标系 [forward, lateral]'omni_angular' 使用 [forward, lateral, yaw_rate]

  • 绘图选项:若 plot 位于对象配置内部,可为单个对象定制可视化;若位于对象配置的根级,则应用于所有对象。