ros_gz_sim_demos
ros_gz_sim
Demos using Gazebo Sim simulation with ROS.
使用 Gazebo Sim 模擬和 ROS 的示範。
README 自述文件
ROS + Gazebo Sim demos
ROS + Gazebo Sim 示範
This package contains demos showing how to use Gazebo Sim with ROS.
該軟體包包含演示如何將 Gazebo Sim 與 ROS 結合使用的演示。
Run Gazebo Sim
運行 Gazebo Sim
There’s a convenient launch file, try for example:
有一個方便的啟動文件,例如嘗試:
ros2 launch ros_gz_sim gz_sim.launch.py gz_args:="shapes.sdf"
Air pressure
氣壓
Publishes fluid pressure readings.
發布流體壓力讀數。
ros2 launch ros_gz_sim_demos air_pressure.launch.xml
This demo also shows the use of custom QoS parameters. The sensor data is published as as “best-effort”, so trying to subscribe to “reliable” data won’t work. See the difference between:
此演示還展示了自訂 QoS 參數的使用。感測器數據以“盡力而為”的方式發布,因此嘗試訂閱“可靠”數據將無法正常工作。以下是兩者之間的差異:
ros2 topic echo /air_pressure --qos-reliability best_effort
And 和
ros2 topic echo /air_pressure --qos-reliability reliable
Battery 電池
Get the current state of a battery.
取得電池的目前狀態。
ros2 launch ros_gz_sim_demos battery.launch.py
Then send a command so the vehicle moves and drains the battery.
然後發送命令讓車輛移動並耗盡電池。
ros2 topic pub /model/vehicle_blue/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 5.0}, angular: {z: 0.5}}"
Camera 房間
Publishes RGB camera image and info.
發布 RGB 相機影像和資訊。
Images can be exposed to ROS through ros_gz_bridge
or ros_gz_image
.
影像可以透過 ros_gz_bridge
或 ros_gz_image
暴露給 ROS。
Using the image bridge (unidirectional, uses image_transport):
使用影像橋(單向,使用 image_transport ):
ros2 launch ros_gz_sim_demos image_bridge.launch.py
Using the regular bridge:
使用常規橋接:
ros2 launch ros_gz_sim_demos camera.launch.xml
To use a camera that only publishes information when triggered:
若要使用僅在觸發時發布資訊的相機:
ros2 launch ros_gz_sim_demos triggered_camera.launch.xml
Trigger the camera: 觸發相機:
ros2 topic pub /camera/trigger std_msgs/msg/Bool "{data: true}" --once
Diff drive 差速驅動
Send commands to a differential drive vehicle and listen to its odometry.
向差速驅動車輛發送命令並監聽其里程表。
ros2 launch ros_gz_sim_demos diff_drive.launch.xml
Then send a command
然後發送命令
ros2 topic pub /model/vehicle_blue/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 5.0}, angular: {z: 0.5}}"
This demo also shows the use of custom QoS parameters. The commands are subscribed to as “reliable”, so trying to publish “best-effort” commands won’t work. See the difference between:
此演示還展示了自訂 QoS 參數的使用。這些命令被訂閱為“可靠”,因此嘗試發布“盡力而為”的命令將不起作用。以下是兩者之間的差異:
ros2 topic pub /model/vehicle_blue/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 5.0}, angular: {z: 0.0}}" --qos-reliability reliable
And 和
ros2 topic pub /model/vehicle_blue/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 5.0}, angular: {z: 0.0}}" --qos-reliability best_effort
Depth camera
深度相機
Depth camera data can be obtained as:
深度相機數據可以透過以下方式取得:
sensor_msgs/msg/Image
, throughros_gz_bridge
orros_gz_image
sensor_msgs/msg/Image
,透過ros_gz_bridge
或ros_gz_image
sensor_msgs/msg/PointCloud2
, throughros_gz_point_cloud
sensor_msgs/msg/PointCloud2
,透過ros_gz_point_cloud
Using the image bridge (unidirectional, uses image_transport):
使用影像橋(單向,使用 image_transport ):
ros2 launch ros_gz_sim_demos image_bridge.launch.py image_topic:=/depth_camera
TODO: Blocked by ros_gz_point_cloud
issue.
TODO :被 ros_gz_point_cloud
問題阻止。
Using Gazebo Sim plugin:
使用 Gazebo Sim 外掛:
ros2 launch ros_gz_sim_demos depth_camera.launch.py
GPU lidar GPU 光達
GPU lidar data can be obtained as:
GPU 光達資料取得方式如下:
sensor_msgs/msg/LaserScan
, through theros_gz_bridge
sensor_msgs/msg/LaserScan
,透過ros_gz_bridge
sensor_msgs/msg/PointCloud2
, through theros_gz_bridge
orros_gz_point_cloud
sensor_msgs/msg/PointCloud2
,透過ros_gz_bridge
或ros_gz_point_cloud
Using the bridge: 使用橋接器:
ros2 launch ros_gz_sim_demos gpu_lidar_bridge.launch.xml
TODO: Blocked by ros_gz_point_cloud
issue.
TODO :被 ros_gz_point_cloud
問題阻止。
Using Gazebo Sim plugin:
使用 Gazebo Sim 外掛:
ros2 launch ros_gz_sim_demos gpu_lidar.launch.py
IMU 慣性測量單元
Publishes IMU readings. 發布 IMU 讀數。
ros2 launch ros_gz_sim_demos imu.launch.xml
TODO: IMU display missing for RViz2
TODO :RViz2 缺少 IMU 顯示
Magnetometer
磁力儀
Publishes magnetic field readings.
發布磁場讀數。
ros2 launch ros_gz_sim_demos magnetometer.launch.xml
GNSS 全球導航衛星系統
Publishes satellite navigation readings, only available in Fortress on.
發布衛星導航讀數,僅在 Fortress 上提供。
GNSS information can be obtained as:
GNSS 資訊可以透過以下方式取得:
# sensor_msgs/msg/NavSatFix
ros2 launch ros_gz_sim_demos navsat.launch.xml
# gps_msgs/msg/GPSFix
ros2 launch ros_gz_sim_demos navsat_gpsfix.launch.xml
RGBD camera RGBD 相機
RGBD camera data can be obtained as:
RGBD 相機數據可以透過以下方式取得:
sensor_msgs/msg/Image
, throughros_gz_bridge
orros_gz_image
sensor_msgs/msg/Image
,透過ros_gz_bridge
或ros_gz_image
sensor_msgs/msg/PointCloud2
, throughros_gz_bridge
orros_gz_point_cloud
sensor_msgs/msg/PointCloud2
,透過ros_gz_bridge
或ros_gz_point_cloud
Using the image bridge (unidirectional, uses image_transport):
使用影像橋(單向,使用 image_transport ):
# RGB image
ros2 launch ros_gz_sim_demos image_bridge.launch.py image_topic:=/rgbd_camera/image
# Depth image
ros2 launch ros_gz_sim_demos image_bridge.launch.py image_topic:=/rgbd_camera/depth_image
Using the regular bridge:
使用常規橋接:
ros2 launch ros_gz_sim_demos rgbd_camera_bridge.launch.xml
TODO: Blocked by ros_gz_point_cloud
issue.
TODO :被 ros_gz_point_cloud
問題阻止。
Using Gazebo Sim plugin:
使用 Gazebo Sim 外掛:
ros2 launch ros_gz_sim_demos rgbd_camera.launch.py
Robot description publisher
機器人描述發布者
Leverage the robot description publisher to spawn a new urdf model in gazebo and show it in rviz2. To try the demo launch:
利用機器人描述發佈器在 Gazebo 中產生一個新的 URDF 模型,並在 rviz2 中展示。若要試用演示版本,請啟動:
ros2 launch ros_gz_sim_demos robot_description_publisher.launch.py
Joint States Publisher
美國出版商
Publishes joint states of the robot.
發布機器人的關節狀態。
To try the demo launch:
若要嘗試示範啟動:
ros2 launch ros_gz_sim_demos joint_states.launch.py
Bridging joint state and pose publishers
連結聯合狀態與姿勢發布者
The launch file demonstrates bridging Gazebo poses to TFMessage to visualize the pose and transforms of a robot in rviz.
啟動檔案示範如何將 Gazebo 姿勢與 TFMessage 連接起來,以便在 rviz 中可視化機器人的姿勢和變換。
To try the demo launch:
若要嘗試示範啟動:
ros2 launch ros_gz_sim_demos tf_bridge.launch.xml
Managing Entities
管理實體
The ros_gz_sim
package provides a set of utilities for managing entities (models, lights, links, etc.) in Gazebo simulations through ROS 2. This package enables seamless communication between ROS 2 and Gazebo, allowing you to:ros_gz_sim
套件提供了一組實用程序,用於透過 ROS 2 管理 Gazebo 模擬中的實體(模型、燈光、連結等)。該包支援 ROS 2 和 Gazebo 之間的無縫通信,使您能夠:
Spawn entities: Add new models and objects to a running Gazebo simulation
生成實體 :在正在運行的 Gazebo 模擬中新增模型和對象Set entity poses: Dynamically adjust the position and orientation of existing entities
設定實體姿勢 :動態調整現有實體的位置與方向Delete entities: Remove entities from the simulation environment
刪除實體 :從模擬環境中刪除實體
Launching Gazebo
啟動 Gazebo
gz sim -v 4 ~/ros2_ws/src/ros_gz/ros_gz_sim_demos/worlds/default.sdf
1. Spawning Entities
1. 生成實體
Spawn new entities into the simulation:
在模擬中產生新的實體:
Run the ROS-Gazebo bridge for the spawn service:
為 spawn 服務運行 ROS-Gazebo 橋:
ros2 run ros_gz_bridge parameter_bridge /world/default/create@ros_gz_interfaces/srv/SpawnEntity
Spawn your entity: 產生你的實體:
ros2 run ros_gz_sim spawn_entity --name <model_name> --sdf_filename <path_to_sdf_file> [--pos x y z] [--quat x y z w | --euler roll pitch yaw]
Example: 例子:
ros2 run ros_gz_sim spawn_entity --name cardboard_box --sdf_filename $(ros2 pkg prefix ros_gz_sim_demos)/share/ros_gz_sim_demos/models/cardboard_box/model.sdf --pos 1.0 2.0 0.5 --euler 0.0 0.0 1.57
or 或者
ros2 run ros_gz_sim spawn_entity --name cardboard_box --sdf_filename /full/path/to/ros_gz_ws/src/ros_gz_sim_demos/models/cardboard_box/model.sdf --pos 1.0 2.0 0.5 --euler 0.0 0.0 1.57
2. Setting Entity Poses
2. 設定實體姿勢
Dynamically adjust the position and orientation of existing entities:
動態調整現有實體的位置和方向:
Run the ROS-Gazebo bridge for the set pose service:
運行 ROS-Gazebo 橋接器來設定姿勢服務:
ros2 run ros_gz_bridge parameter_bridge /world/default/set_pose@ros_gz_interfaces/srv/SetEntityPose
Set the entity’s pose: 設定實體的姿勢:
ros2 run ros_gz_sim set_entity_pose [--name NAME | --id ID] [--type TYPE] [--pos X Y Z] [--quat X Y Z W | --euler ROLL PITCH YAW]
Examples: 例子:
Using entity name with Euler angles for rotation:
使用帶有歐拉角的實體名稱進行旋轉:
ros2 run ros_gz_sim set_entity_pose --name cardboard_box --pos 3.0 4.0 1.0 --euler 0.0 0.0 1.57
Using entity ID with quaternion for rotation:
使用四元數的實體 ID 進行旋轉:
ros2 run ros_gz_sim set_entity_pose --id 8 --pos 3.0 4.0 1.0 --quat 0.0 0.0 0.7071 0.7071
3. Deleting Entities
3. 刪除實體
Remove entities from the simulation:
從模擬中刪除實體:
Run the ROS-Gazebo bridge for the delete service:
運行 ROS-Gazebo 橋接器以刪除服務:
ros2 run ros_gz_bridge parameter_bridge /world/default/remove@ros_gz_interfaces/srv/DeleteEntity
Delete the entity: 刪除實體:
ros2 run ros_gz_sim delete_entity [--name NAME | --id ID] [--type TYPE]
Examples: 例子:
Using entity name: 使用實體名稱:
ros2 run ros_gz_sim delete_entity --name cardboard_box
Using entity ID: 使用實體 ID:
ros2 run ros_gz_sim delete_entity --id 8
Using a specific entity type:
使用特定的實體類型:
ros2 run ros_gz_sim delete_entity --name cardboard_box --type 2
Entity Type Reference
實體類型參考
When using the set_entity_pose
and delete_entity
commands, you can specify the entity type using the --type
flag. The following type values are available:
使用 set_entity_pose
和 delete_entity
指令時,可以使用 --type
標誌指定實體類型。可用的類型值如下:
Value 價值 | Entity Type 實體類型 |
---|---|
0 | NONE |
1 | LIGHT |
2 | LINK |
3 | VISUAL |
4 | COLLISION |
5 | SENSOR |
6 | MODEL (default) 型號(預設) |
沒有留言:
張貼留言