datetime:2025/12/22 19:15
author:nzb

渲染并保存动画

本节内容

  • 渲染并保存动画
    • 渲染环境
    • 将动画保存为 GIF
    • 将动画保存为视频
    • 3D 绘图

Python 脚本与 YAML 配置文件

import irsim

# 在 make() 函数中将 save_ani 设为 True,即可轻松把仿真动画保存为 GIF
env = irsim.make(save_ani=True) # 将动画保存为 GIF
env = irsim.make(projection='3d') # 3D 绘图

for i in range(300):

    env.step()
    env.render(0.05)

    if env.done():
        break

env.end(ending_time=3)
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 
  collision_mode: 'stop'  # 'stop', 'unobstructed', 'unobstructed_obstacles'
  control_mode: 'auto'  # 'keyboard', 'auto'
  plot:
    show_title: False
    no_axis: False

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, 4, 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 

  - kinematics: {name: 'diff'}  # omni, diff, acker
    shape: {name: 'circle', radius: 0.2}  # radius
    # shape: {name: 'rectangle', length: 0.5, width: 0.2}  # radius
    state: [5, 1, 0]  
    goal: [2, 6, 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 
    color: 'royalblue'
    plot: {show_trajectory: True, show_trail: True, trail_fill: True, trail_alpha: 0.2} 


obstacle:
  - number: 10
    distribution: {name: 'manual'}
    shape:
      - {name: 'circle', radius: 1.5}  # radius
      - {name: 'circle', radius: 1.0}  # radius

    state: [[20, 34], [31, 38], [10, 20], [41, 25], [20, 13], [16, 26], [10, 24], [18, 20], [16, 26], [19, 26], [10, 30]]
  • 3D 绘图

在 irsim.make 中将 projection 设为 3d,即可渲染仿真的 3D 图

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 
  plot:
    show_title: False

robot:
  kinematics: {name: 'diff'}  # omni, diff, acker
  shape: {name: 'circle', radius: 0.2}  # radius
  # shape: {name: 'rectangle', length: 0.3, width: 1.0} 
  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 
  color: 'g'
  plot:
    show_trajectory: True
    show_trail: True
  # description: 'diff_robot0.png'

  sensors:
      - name: 'lidar2d'
        range_min: 0
        range_max: 5
        angle_range: 3.14 #  4.7123
        number: 200
        noise: False
        std: 0.2
        angle_std: 0.2
        alpha: 0.3

results matching ""

    No results matching ""