预计完成时间:6 分钟
在开始本节之前,请先使用 Gazebo Sim 启动 shapes 世界,并让仿真运行起来。
在 Web Shell 1 中执行
gz sim -r shapes.sdf
命令中的 -r 表示启动 Gazebo Sim 时直接让仿真开始运行。
现在,请在一个新的 web shell 中执行下面的命令。
在 Web Shell 2 中执行
gz model --list
Requesting state for world [shapes]...
Available models:
- ground_plane
- box
- cylinder
- sphere
- capsule
- ellipsoid
gz model --model box --pose
你的输出应与下图类似。
Requesting state for world [shapes]...
Model: [8]
- Name: box
- Pose [ XYZ (m) ] [ RPY (rad) ]:
[-0.000000 -0.000000 0.500000]
[0.000000 0.000000 -0.000000]
为仿真中的已有模型设置一个新的位姿。
gz service --service /world/shapes/set_pose \
--reqtype gz.msgs.Pose \
--reptype gz.msgs.Boolean \
--timeout 500 \
--req 'name:"box",position:{x:1.0,y:0.0,z:0.5},orientation:{x:0.0,y:0.0,z:0.383,w:0.924}'
你的输出应为:
data: true
暂停仿真。仿真画面中的实体会停在原地不动,仿真时间也会停止。
gz service --service /world/shapes/control \
--reqtype gz.msgs.WorldControl \
--reptype gz.msgs.Boolean \
--timeout 1000 \
--req 'pause:true'
预期输出为:
data: true
运行仿真,或在暂停后继续仿真。被冻结的实体会重新开始运动,仿真时间也会从暂停处继续。
gz service --service /world/shapes/control \
--reqtype gz.msgs.WorldControl \
--reptype gz.msgs.Boolean \
--timeout 1000 \
--req 'pause:false'
你的输出应为:
data: true
将所有实体重置回初始位置,并且把仿真从 0.0 秒重新开始。
gz service --service /world/shapes/control \
--reqtype gz.msgs.WorldControl \
--reptype gz.msgs.Boolean \
--timeout 1000 \
--req 'reset:{all:true}'
你的输出应如下所示:
data: true
将所有实体重置回初始位置,但不会重新启动仿真。
gz service --service /world/shapes/control \
--reqtype gz.msgs.WorldControl \
--reptype gz.msgs.Boolean \
--timeout 1000 \
--req 'reset:{model_only:true}'
将仿真时间重置回 0.0 秒,但不会重新启动仿真。
gz service --service /world/shapes/control \
--reqtype gz.msgs.WorldControl \
--reptype gz.msgs.Boolean \
--timeout 1000 \
--req 'reset:{time_only:true}'
在空场景中添加一些简单物体,并调用你刚学到的这些服务,观察它们的效果。
