Task 任务执行

对应目录:demo/task/,展示如何通过 YAML 配置编排动作序列并完成任务验收,无需编写控制代码。

示例一览

目录重点配置文件
01_pick_and_placePick-and-place 完整流程simple_scene.yaml / complex_scene.yaml

01:Pick-and-Place(01_pick_and_place)

运行

bash
# 执行任务,任务完成后仿真继续运行
fastsim launch_simulation --config simple_scene.yaml --run_task

# 执行任务,完成后自动终止仿真
fastsim launch_simulation --config simple_scene.yaml --run_task --stop_sim_on_task_end

或在 Python 中:

python
from fastsim.app import FastSim

sim = FastSim("simple_scene.yaml")
sim.start_with_task(stop_sim_on_task_end=True)

任务配置结构

simple_scene.yaml 中的任务块示例:

yaml
task:
  name: pick_and_place
  description: Pick the target object and place it on the table

  actions:
    - stereotype: release          # 先张开夹爪
      robot_name: franka_panda
      name: release
      description: Release gripper
      wait_robot_stopped: false
      wait_robot_stopped_timeout: 3.0
      visualization_config:
        enable_ee_pose_visualization: false
        enable_target_bounding_box_visualization: false
        ee_pose_type: coordinate

    - stereotype: pick             # 抓取目标物体
      robot_name: franka_panda
      name: pick_target
      description: Pick up the target
      wait_robot_stopped: true
      wait_robot_stopped_timeout: 5.0
      extra_parameters:
        pose_source: local
        pose_data: ./grasp_pose_ball_020.json   # 从文件加载候选抓取位姿
      visualization_config:
        enable_target_bounding_box_visualization: true
        ee_pose_type: coordinate

    - stereotype: place            # 放置到目标位置
      robot_name: franka_panda
      name: place_on_table
      description: Place on the target table
      wait_robot_stopped: true
      wait_robot_stopped_timeout: 5.0
      extra_parameters:
        target_name: table
      visualization_config:
        enable_target_bounding_box_visualization: true
        ee_pose_type: coordinate

  goals:
    - stereotype: on_top
      name: object_on_table
      description: Target object is on the table
      extra_parameters:
        object_name: target
        target_name: table
        tolerance: 0.02

两种场景配置

配置文件说明
simple_scene.yaml单机器人、单物体,grasp pose 从本地 JSON 文件加载
complex_scene.yaml多相机(wrist cam + watch cam)、更复杂的场景布局

complex_scene.yaml 中的相机配置示例:

yaml
sensor_cfg_dict:
  wrist_cam:
    stereotype: camera
    attach_to: franka_panda   # 绑定到机器人,随末端运动
    data_types: [rgb, depth]
    width: 640
    height: 480

  watch_gripper_cam:
    stereotype: camera
    look_at: panda_hand       # 始终朝向夹爪 link
    position: [1.0, 0.5, 0.8]
    data_types: [rgb]
    width: 1280
    height: 720

pose_source 的两种写法

yaml
# 方式一:从本地 JSON 文件加载候选抓取位姿(推荐,便于复用)
extra_parameters:
  pose_source: local
  pose_data: ./grasp_pose_ball_020.json

# 方式二:在配置中内联定义位姿
extra_parameters:
  pose_source: inline
  pose_data:
    grasp_0:
      position: [0.0, 0.0, 0.05]
      quaternion: [1.0, 0.0, 0.0, 0.0]

常见问题

现象原因处理方式
任务线程结束、仿真仍运行stop_sim_on_task_end 未设置添加 --stop_sim_on_task_end 或在代码中传入该参数