使用PX4,gazebo,mavros为旋翼添加下视的相机(仿真采集openrealm数据集-第一步)

发布于:2025-04-09 ⋅ 阅读:(55) ⋅ 点赞:(0)

目录

一.方法一(没成功)

1.运行PX4 

2.运行mavros通讯

3.启动仿真世界和无人机

(1)单独测试相机

(2)make px4_sitl gazebo启动四旋翼iris无人机

二.方法二(成功)

1.通过 roslaunch 启动

2.运行rostopic list和rosnode list有gazebo节点和相关话题

3.如何修改iris.sdf,我应该在iris的哪里添加相机呢?

一、添加相机的位置

在哪里添加?

二、修改后的 iris.sdf

三、代码说明

四、总结

4.检查相机是否符合要求

三.解释和分析上述 iris.sdf 文件的内容,包括其结构、语法和每个部分的含义

一、SDF 文件总体结构与语法

1. 文件头

2. 模型定义

二、主要组成部分分析

1.

- 物理部件

示例:base_link(主体)

示例:rotor_0(旋翼)

示例:camera_link(相机)

2. - 关节

示例:rotor_0_joint

示例:camera_joint

3. - 插件

示例:motor_model(电机)

4. - 外部模型

三、语法规则

四、整体功能分析

五、总结

四.sdf模型坐标系是什么,gazebo仿真世界坐标系是什么

一、SDF 模型坐标系

定义

在 iris.sdf 中的体现

特点

二、Gazebo 仿真世界坐标系

定义

在仿真中的体现

特点

三、两者的关系

四、示例分析(基于 iris.sdf)

模型坐标系

世界坐标系

验证

五、语法与配置要点

五.如何知道世界坐标系的原点和xyz方向,如何知道模型坐标系的原点和xyz方向

一、确定 Gazebo 世界坐标系的原点和 XYZ 方向

1. 世界坐标系的定义

2. 如何确认原点和方向

方法 1:检查世界文件

方法 2:通过 Gazebo GUI 可视化

方法 3:检查 /gazebo/model_states

二、确定 SDF 模型坐标系的原点和 XYZ 方向

1. 模型坐标系的定义

2. 如何确认原点和方向

方法 1:分析 SDF 文件

方法 2:Gazebo GUI 可视化

方法 3:检查传感器数据

三、两者的关系与验证

四、总结

世界坐标系

模型坐标系

实用建议

六.依然是坐标系问题

一、解释 /gazebo/model_states 输出

命令与输出

输出内容

分析

总结

二、Gazebo GUI 中坐标轴颜色对应

操作

颜色与 XYZ 的对应

三、rotor_0 在右前方,模型坐标系的 XYZ 方向

rotor_0 的位置

模型坐标系的 XYZ 方向

验证

四、综合分析

五、建议


一.方法一(没成功)

1.运行PX4 

make px4_sitl gazebo

默认启动的是iris四旋翼模型

2.运行mavros通讯

roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"

“Gazebo ROS 插件未初始化”意味着 Gazebo 仿真器无法正确与 ROS(Robot Operating System)通信,导致 ROS 插件(如 libgazebo_ros_camera.so)无法加载或发布话题。这种情况通常会表现为你在 rostopic list 中看不到预期的传感器话题(如 /downward_camera/image_raw),或者 rosnode list 中缺少 /gazebo 节点。以下是问题的原因分析、排查步骤和解决方法。

3.启动仿真世界和无人机

(1)单独测试相机

~/test_camera/test_camera.sdf代码为: 

<sdf version="1.6">
  <world name="test_world">
    <model name="camera_test">
      <link name="camera_link">
        <pose>0 0 0 0 0 0</pose>
        <inertial>
          <mass>0.01</mass>
          <inertia>
            <ixx>1e-05</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>1e-05</iyy>
            <iyz>0</iyz>
            <izz>1e-05</izz>
          </inertia>
        </inertial>
        <sensor name="test_camera" type="camera">
          <always_on>true</always_on>
          <update_rate>10.0</update_rate>
          <camera>
            <horizontal_fov>1.047</horizontal_fov>
            <image>
              <width>640</width>
              <height>480</height>
              <format>R8G8B8</format>
            </image>
            <clip>
              <near>0.1</near>
              <far>1000</far>
            </clip>
          </camera>
          <plugin name="camera_plugin" filename="libgazebo_ros_camera.so">
            <ros>
              <namespace>/test_camera</namespace>
            </ros>
            <frame_name>camera_link</frame_name>
            <cameraName>test_camera</cameraName>
          </plugin>
        </sensor>
      </link>
    </model>
  </world>
</sdf>

不要直接用 gazebo 命令,而是通过 ROS 启动:

rosrun gazebo_ros gazebo ~/test_camera/test_camera.sdf
  • rosrun gazebo_ros gazebo = 启动 Gazebo + 启用 ROS 接口。

即可成功出现gazebo节点和相关话题 


中间的某一步export 

leaf@LAPTOP-NI05EP5K:~$ find /usr/lib /opt/ros -name "libCameraPlugin.so"
/usr/lib/x86_64-linux-gnu/gazebo-11/plugins/libCameraPlugin.so
leaf@LAPTOP-NI05EP5K:~$ ldd /opt/ros/noetic/lib/libgazebo_ros_camera.so | grep libCameraPlugin
        libCameraPlugin.so => not found
leaf@LAPTOP-NI05EP5K:~$ export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:$LD_LIBRARY_PATH
leaf@LAPTOP-NI05EP5K:~$ ldd /opt/ros/noetic/lib/libgazebo_ros_camera.so | grep libCameraPlugin
        libCameraPlugin.so => /usr/lib/x86_64-linux-gnu/gazebo-11/plugins/libCameraPlugin.so (0x00007fe3b6f25000)
leaf@LAPTOP-NI05EP5K:~$ cat gazebo_log.txt
WARNING: Package name "MSTC_Star_update" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "MSTC_Star_update" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
WARNING: Package name "MSTC_Star_update" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
leaf@LAPTOP-NI05EP5K:~$ ldd /opt/ros/noetic/lib/libgazebo_ros_camera.so | grep libCameraPlugin
        libCameraPlugin.so => /usr/lib/x86_64-linux-gnu/gazebo-11/plugins/libCameraPlugin.so (0x00007f77cf450000)

 


清理所有节点进程 

killall -9 gzserver gzclient roslaunch rosmaster
leaf@LAPTOP-NI05EP5K:~/test_camera$ killall -9 gzserver gzclient roslaunch rosmaster
gzserver: no process found
gzclient: no process found
roslaunch: no process found


(2)make px4_sitl gazebo启动四旋翼iris无人机

从你的反馈来看,问题已经非常清晰:rosrun gazebo_ros gazebo 可以成功启动 Gazebo 并与 ROS 集成,而 make px4_sitl gazebo 虽然启动了 Gazebo 和 PX4 仿真,但未能正确与 ROS 集成,导致 /gazebo 节点和话题未出现。以下是分析和最终解决方案。


二.方法二(成功)

1.通过 roslaunch 启动

PX4 提供了集成 ROS 的启动文件,可同时启动 Gazebo、PX4 SITL 和 MAVROS:

roslaunch px4 mavros_posix_sitl.launch

 

效果

  • 自动加载 Gazebo-ROS 插件,发布 /gazebo 话题。

  • 启动 MAVROS,连接 PX4 和 ROS。

2.运行rostopic list和rosnode list有gazebo节点和相关话题

leaf@LAPTOP-NI05EP5K:~$ rostopic list
/clock
/diagnostics
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/performance_metrics
/gazebo/set_link_state
/gazebo/set_model_state
/mavlink/from
/mavlink/gcs_ip
/mavlink/to
/mavros/actuator_control
/mavros/adsb/send
/mavros/adsb/vehicle
/mavros/altitude
/mavros/battery
/mavros/cam_imu_sync/cam_imu_stamp
/mavros/camera/image_captured
/mavros/cellular_status/status
/mavros/companion_process/status
/mavros/debug_value/debug
/mavros/debug_value/debug_float_array
/mavros/debug_value/debug_vector
/mavros/debug_value/named_value_float
/mavros/debug_value/named_value_int
/mavros/debug_value/send
/mavros/esc_info
/mavros/esc_status
/mavros/esc_telemetry
/mavros/estimator_status
/mavros/extended_state
/mavros/fake_gps/mocap/tf
/mavros/geofence/waypoints
/mavros/global_position/compass_hdg
/mavros/global_position/global
/mavros/global_position/gp_lp_offset
/mavros/global_position/gp_origin
/mavros/global_position/local
/mavros/global_position/raw/fix
/mavros/global_position/raw/gps_vel
/mavros/global_position/raw/satellites
/mavros/global_position/rel_alt
/mavros/global_position/set_gp_origin
/mavros/gps_input/gps_input
/mavros/gps_rtk/rtk_baseline
/mavros/gps_rtk/send_rtcm
/mavros/gpsstatus/gps1/raw
/mavros/gpsstatus/gps1/rtk
/mavros/gpsstatus/gps2/raw
/mavros/gpsstatus/gps2/rtk
/mavros/hil/actuator_controls
/mavros/hil/controls
/mavros/hil/gps
/mavros/hil/imu_ned
/mavros/hil/optical_flow
/mavros/hil/rc_inputs
/mavros/hil/state
/mavros/home_position/home
/mavros/home_position/set
/mavros/imu/data
/mavros/imu/data_raw
/mavros/imu/diff_pressure
/mavros/imu/mag
/mavros/imu/static_pressure
/mavros/imu/temperature_baro
/mavros/imu/temperature_imu
/mavros/landing_target/lt_marker
/mavros/landing_target/pose
/mavros/landing_target/pose_in
/mavros/local_position/accel
/mavros/local_position/odom
/mavros/local_position/pose
/mavros/local_position/pose_cov
/mavros/local_position/velocity_body
/mavros/local_position/velocity_body_cov
/mavros/local_position/velocity_local
/mavros/log_transfer/raw/log_data
/mavros/log_transfer/raw/log_entry
/mavros/mag_calibration/report
/mavros/mag_calibration/status
/mavros/manual_control/control
/mavros/manual_control/send
/mavros/mission/reached
/mavros/mission/waypoints
/mavros/mocap/pose
/mavros/mount_control/command
/mavros/mount_control/orientation
/mavros/mount_control/status
/mavros/nav_controller_output
/mavros/obstacle/send
/mavros/odometry/in
/mavros/odometry/out
/mavros/onboard_computer/status
/mavros/param/param_value
/mavros/play_tune
/mavros/px4flow/ground_distance
/mavros/px4flow/raw/optical_flow_rad
/mavros/px4flow/raw/send
/mavros/px4flow/temperature
/mavros/radio_status
/mavros/rallypoint/waypoints
/mavros/rc/in
/mavros/rc/out
/mavros/rc/override
/mavros/setpoint_accel/accel
/mavros/setpoint_attitude/cmd_vel
/mavros/setpoint_attitude/thrust
/mavros/setpoint_position/global
/mavros/setpoint_position/global_to_local
/mavros/setpoint_position/local
/mavros/setpoint_raw/attitude
/mavros/setpoint_raw/global
/mavros/setpoint_raw/local
/mavros/setpoint_raw/target_attitude
/mavros/setpoint_raw/target_global
/mavros/setpoint_raw/target_local
/mavros/setpoint_trajectory/desired
/mavros/setpoint_trajectory/local
/mavros/setpoint_velocity/cmd_vel
/mavros/setpoint_velocity/cmd_vel_unstamped
/mavros/state
/mavros/statustext/recv
/mavros/statustext/send
/mavros/sys_status
/mavros/target_actuator_control
/mavros/terrain/report
/mavros/time_reference
/mavros/timesync_status
/mavros/trajectory/desired
/mavros/trajectory/generated
/mavros/trajectory/path
/mavros/tunnel/in
/mavros/tunnel/out
/mavros/vfr_hud
/mavros/vision_pose/pose
/mavros/vision_pose/pose_cov
/mavros/vision_speed/speed_twist_cov
/mavros/wind_estimation
/move_base_simple/goal
/rosout
/rosout_agg
/test_camera/camera_info
/test_camera/image_raw
/test_camera/image_raw/compressed
/test_camera/image_raw/compressed/parameter_descriptions
/test_camera/image_raw/compressed/parameter_updates
/test_camera/image_raw/compressedDepth
/test_camera/image_raw/compressedDepth/parameter_descriptions
/test_camera/image_raw/compressedDepth/parameter_updates
/test_camera/image_raw/theora
/test_camera/image_raw/theora/parameter_descriptions
/test_camera/image_raw/theora/parameter_updates
/test_camera/parameter_descriptions
/test_camera/parameter_updates
/tf
/tf_static
leaf@LAPTOP-NI05EP5K:~$ rosnode list
/gazebo
/gazebo_gui
/mavros
/rosout
  • 结论
    • 该命令正确启动了 Gazebo、PX4 SITL 和 MAVROS,并完成了 ROS 集成。

优点

  • 官方支持:mavros_posix_sitl.launch 是 PX4 提供的标准 launch 文件,集成了 Gazebo、PX4 SITL 和 MAVROS。
  • 自动化:自动处理环境变量、符号链接和模型加载,无需手动配置。
  • 稳定性:避免了手动启动可能出现的路径或参数错误。

与之前方法的对比

  • 之前的手动方法和脚本需要手动管理 roscore、Gazebo 和 PX4 的启动顺序,而 roslaunch px4 mavros_posix_sitl.launch 一次性完成所有步骤。

3.如何修改iris.sdf,我应该在iris的哪里添加相机呢?

在 iris.sdf 中添加相机需要将其作为一个新的 <link> 和 <sensor>,并通过 <joint> 将其固定到 iris 的主体(通常是 base_link)。你的目标是添加一个下视相机,因此我们需要选择合适的位置和朝向。

以下是如何在 iris.sdf 中添加相机的详细步骤和代码:


一、添加相机的位置

  • 目标:下视相机,通常安装在机身底部。
  • 坐标系
    • base_link 是 iris 的主体坐标系,位于机身中心。
    • X 轴向前,Y 轴向右,Z 轴向上。
    • 下视相机应放在 base_link 下方(Z 负方向),朝下(绕 Y 轴旋转 90°,即俯仰角 -90°)。
  • 建议位置
    • <pose>0 0 -0.1 0 1.5708 0</pose> 表示相机位于机身下方 0.1 米,朝下。

在哪里添加?

  • 在 <model name='iris'> 内,添加新的 <link> 和 <joint>,通常放在现有 <link>(如 rotor_* 或 gps0)之后,但在 <plugin> 之前。

二、修改后的 iris.sdf

以下是将相机添加到你的 iris.sdf 的完整代码(在原始文件基础上添加相机部分):

<!-- DO NOT EDIT: Generated from iris.sdf.jinja -->
<sdf version='1.6'>
  <model name='iris'>
    <link name='base_link'>
      <pose>0 0 0 0 0 0</pose>
      <inertial>
        <pose>0 0 0 0 0 0</pose>
        <mass>1.5</mass>
        <inertia>
          <ixx>0.029125</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.029125</iyy>
          <iyz>0</iyz>
          <izz>0.055225</izz>
        </inertia>
      </inertial>
      <collision name='base_link_inertia_collision'>
        <pose>0 0 0 0 0 0</pose>
        <geometry>
          <box>
            <size>0.47 0.47 0.11</size>
          </box>
        </geometry>
        <surface>
          <contact>
            <ode>
              <min_depth>0.001</min_depth>
              <max_vel>0</max_vel>
            </ode>
          </contact>
          <friction>
            <ode/>
          </friction>
        </surface>
      </collision>
      <visual name='base_link_inertia_visual'>
        <pose>0 0 0 0 0 0</pose>
        <geometry>
          <mesh>
            <scale>1 1 1</scale>
            <uri>model://iris/meshes/iris.stl</uri>
          </mesh>
        </geometry>
        <material>
          <script>
            <name>Gazebo/DarkGrey</name>
            <uri>file://media/materials/scripts/gazebo.material</uri>
          </script>
        </material>
      </visual>
      <gravity>1</gravity>
      <velocity_decay/>
    </link>
    <!-- 其他现有 link 和 joint(如 imu_link, rotor_0 等)保持不变 -->
    <link name='/imu_link'>
      <!-- 原有内容 -->
    </link>
    <joint name='/imu_joint' type='revolute'>
      <!-- 原有内容 -->
    </joint>
    <link name='rotor_0'>
      <!-- 原有内容 -->
    </link>
    <joint name='rotor_0_joint' type='revolute'>
      <!-- 原有内容 -->
    </joint>
    <!-- rotor_1, rotor_2, rotor_3 等保持不变 -->

    <!-- 添加相机 link -->
    <link name="camera_link">
      <pose>0 0 -0.1 0 1.5708 0</pose> <!-- 下方 0.1 米,朝下 (绕 Y 轴旋转 90°) -->
      <inertial>
        <pose>0 0 0 0 0 0</pose>
        <mass>0.01</mass> <!-- 相机质量,通常很小 -->
        <inertia>
          <ixx>1e-05</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>1e-05</iyy>
          <iyz>0</iyz>
          <izz>1e-05</izz>
        </inertia>
      </inertial>
      <!-- 可选:添加可视化几何体 -->
      <visual name="camera_visual">
        <pose>0 0 0 0 0 0</pose>
        <geometry>
          <box>
            <size>0.02 0.02 0.02</size> <!-- 小盒子表示相机 -->
          </box>
        </geometry>
        <material>
          <script>
            <name>Gazebo/Red</name>
            <uri>file://media/materials/scripts/gazebo.material</uri>
          </script>
        </material>
      </visual>
      <!-- 相机传感器 -->
      <sensor name="test_camera" type="camera">
        <always_on>true</always_on>
        <update_rate>10.0</update_rate> <!-- 每秒 10 帧 -->
        <camera>
          <horizontal_fov>1.047</horizontal_fov> <!-- 视场角约 60° -->
          <image>
            <width>640</width>
            <height>480</height>
            <format>R8G8B8</format> <!-- RGB 格式 -->
          </image>
          <clip>
            <near>0.1</near>
            <far>1000</far>
          </clip>
        </camera>
        <plugin name="camera_plugin" filename="libgazebo_ros_camera.so">
          <ros>
            <namespace>/test_camera</namespace>
          </ros>
          <frame_name>camera_link</frame_name>
          <cameraName>test_camera</cameraName>
        </plugin>
      </sensor>
    </link>

    <!-- 将相机固定到 base_link -->
    <joint name="camera_joint" type="fixed">
      <parent>base_link</parent>
      <child>camera_link</child>
    </joint>

    <!-- 以下是原有插件部分,保持不变 -->
    <plugin name='rosbag' filename='libgazebo_multirotor_base_plugin.so'>
      <!-- 原有内容 -->
    </plugin>
    <!-- 其他插件如 motor_model, gps, groundtruth 等保持不变 -->
  </model>
</sdf>

三、代码说明

  1. 相机位置
    • <pose>0 0 -0.1 0 1.5708 0</pose>:
      • 0 0 -0.1:相机位于 base_link 下方 0.1 米。
      • 0 1.5708 0:绕 Y 轴旋转 90°(1.5708 弧度),使相机朝下。
  2. 惯性参数
    • <mass>0.01</mass> 和 <inertia>:相机质量和惯性矩阵,值较小以模拟轻型相机。
  3. 可视化(可选)
    • 添加了一个红色小盒子作为相机模型,便于在 Gazebo 中看到。
  4. 传感器
    • <sensor name="test_camera" type="camera"> 定义相机参数。
    • <plugin name="camera_plugin" filename="libgazebo_ros_camera.so"> 使用 ROS 插件发布图像到 /test_camera/image_raw。
  5. 关节
    • <joint name="camera_joint" type="fixed"> 将相机固定到 base_link。

四、总结

  • 添加位置:在 <model name='iris'> 内,rotor_* 和 gps0 之后,<plugin> 之前。
  • 效果:相机固定在 base_link 下方,朝下拍摄,图像通过 ROS 话题发布。

 


4.检查相机是否符合要求

话题列表

  • /test_camera/image_raw:原始图像数据。
  • /test_camera/camera_info:相机内参和畸变参数。
  • /test_camera/image_raw/compressed 等:压缩格式图像(由插件自动生成)。

运行仿真

roslaunch px4 mavros_posix_sitl.launch

检查相机话题

rostopic list | grep test_camera

查看图像

rosrun image_view image_view image:=/test_camera/image_raw

检查发布频率

rostopic hz /test_camera/image_raw
  • 输出话题的平均发布频率(单位:Hz)。
  • 预期:你在 iris.sdf 中设置了 <update_rate>10.0</update_rate>,应接近 10 Hz。
  • 调整:如果需要更高帧率,修改 iris.sdf 中的 <update_rate>(如 30.0),保存后重启仿真:

查看图像信息

rostopic echo /test_camera/image_raw -n 1

使用 camera_info

rostopic echo /test_camera/camera_info -n 1

三.解释和分析上述 iris.sdf 文件的内容,包括其结构、语法和每个部分的含义

我将详细解释和分析上述 iris.sdf 文件的内容,包括其结构、语法和每个部分的含义。SDF(Simulation Description Format)是 Gazebo 仿真器使用的 XML 格式文件,用于定义机器人模型的物理属性、可视化、传感器和插件等


一、SDF 文件总体结构与语法

1. 文件头
<sdf version='1.6'>
  • 含义:声明 SDF 文件的版本为 1.6,表明使用的语法和功能符合 SDF 1.6 规范。
  • 语法:<sdf> 是根标签,所有内容必须包裹在此标签内,version 属性指定版本号。
2. 模型定义
<model name='iris'>
  • 含义:定义一个名为 iris 的模型(四旋翼无人机)。
  • 语法:<model> 标签表示一个独立的物理实体,name 属性是模型的唯一标识符。
  • 嵌套内容:包含 <link>(物理部件)、<joint>(关节)和 <plugin>(插件)等。

二、主要组成部分分析

1. <link> - 物理部件

<link> 定义模型的刚体部件,每个部件有位置、质量、惯性、碰撞体和可视化属性。

示例:base_link(主体)
<link name='base_link'>
  <pose>0 0 0 0 0 0</pose>
  <inertial>
    <pose>0 0 0 0 0 0</pose>
    <mass>1.5</mass>
    <inertia>
      <ixx>0.029125</ixx>
      <ixy>0</ixy>
      <ixz>0</ixz>
      <iyy>0.029125</iyy>
      <iyz>0</iyz>
      <izz>0.055225</izz>
    </inertia>
  </inertial>
  <collision name='base_link_inertia_collision'>
    <pose>0 0 0 0 0 0</pose>
    <geometry>
      <box>
        <size>0.47 0.47 0.11</size>
      </box>
    </geometry>
    <surface>
      <contact>
        <ode>
          <min_depth>0.001</min_depth>
          <max_vel>0</max_vel>
        </ode>
      </contact>
      <friction>
        <ode/>
      </friction>
    </surface>
  </collision>
  <visual name='base_link_inertia_visual'>
    <pose>0 0 0 0 0 0</pose>
    <geometry>
      <mesh>
        <scale>1 1 1</scale>
        <uri>model://iris/meshes/iris.stl</uri>
      </mesh>
    </geometry>
    <material>
      <script>
        <name>Gazebo/DarkGrey</name>
        <uri>file://media/materials/scripts/gazebo.material</uri>
      </script>
    </material>
  </visual>
  <gravity>1</gravity>
  <velocity_decay/>
</link>
  • <pose>:x y z roll pitch yaw(单位:米和弧度),表示相对于模型坐标系的位置和姿态。
    • 0 0 0 0 0 0:位于原点,无旋转。
  • <inertial>:定义物理属性。
    • <mass>:1.5 kg,主体质量。
    • <inertia>:惯性张量(对角矩阵),描述质量分布,单位 kg·m²。
      • ixx, iyy, izz:主轴惯性,ixy, ixz, iyz:交叉项(这里为 0,表示对称)。
  • <collision>:碰撞体,用于物理计算。
    • <geometry><box><size>:0.47x0.47x0.11 m 的盒子。
    • <surface>:接触和摩擦属性,ode 表示使用 ODE 物理引擎。
      • <min_depth>:最小穿透深度。
      • <max_vel>:最大接触速度。
  • <visual>:可视化外观。
    • <geometry><mesh>:加载 iris.stl 网格文件。
    • <material>:颜色为深灰(Gazebo/DarkGrey)。
  • <gravity>:1,表示受重力影响。
  • <velocity_decay>:速度衰减(默认空值,无阻尼)。
示例:rotor_0(旋翼)
<link name='rotor_0'>
  <pose>0.13 -0.22 0.023 0 0 0</pose>
  <inertial>
    <mass>0.005</mass>
    <inertia>
      <ixx>9.75e-07</ixx>
      <iyy>0.000273104</iyy>
      <izz>0.000274004</izz>
    </inertia>
  </inertial>
  <collision name='rotor_0_collision'>
    <geometry>
      <cylinder>
        <length>0.005</length>
        <radius>0.128</radius>
      </cylinder>
    </geometry>
  </collision>
  <visual name='rotor_0_visual'>
    <geometry>
      <mesh>
        <uri>model://iris/meshes/iris_prop_ccw.dae</uri>
      </mesh>
    </geometry>
    <material>
      <script>
        <name>Gazebo/Blue</name>
      </script>
    </material>
  </visual>
  <gravity>1</gravity>
</link>
  • <pose>:旋翼位置 (0.13, -0.22, 0.023),相对于 base_link。
  • <inertial>:质量 0.005 kg,惯性较小。
  • <collision>:圆柱体(半径 0.128 m,厚度 0.005 m)。
  • <visual>:加载逆时针螺旋桨模型,颜色为蓝色。
示例:camera_link(相机)
<link name="camera_link">
  <pose>0 0 -0.1 0 1.5708 0</pose>
  <inertial>
    <mass>0.01</mass>
    <inertia>
      <ixx>1e-05</ixx>
      <iyy>1e-05</iyy>
      <izz>1e-05</izz>
    </inertia>
  </inertial>
  <visual name="camera_visual">
    <geometry>
      <box>
        <size>0.02 0.02 0.02</size>
      </box>
    </geometry>
    <material>
      <script>
        <name>Gazebo/Red</name>
      </script>
    </material>
  </visual>
  <sensor name="test_camera" type="camera">
    <always_on>true</always_on>
    <update_rate>10.0</update_rate>
    <camera>
      <horizontal_fov>1.047</horizontal_fov>
      <image>
        <width>640</width>
        <height>480</height>
        <format>R8G8B8</format>
      </image>
      <clip>
        <near>0.1</near>
        <far>1000</far>
      </clip>
    </camera>
    <plugin name="camera_plugin" filename="libgazebo_ros_camera.so">
      <ros>
        <namespace>/test_camera</namespace>
      </ros>
      <frame_name>camera_link</frame_name>
      <cameraName>test_camera</cameraName>
    </plugin>
  </sensor>
</link>
  • <pose>:下方 0.1 m,绕 Y 轴旋转 90°(朝下)。
  • <inertial>:质量 0.01 kg,惯性小。
  • <visual>:红色小盒子表示相机。
  • <sensor>:相机传感器。
    • <update_rate>:10 Hz。
    • <horizontal_fov>:约 60°。
    • <image>:分辨率 640x480,RGB 格式。
    • <clip>:近裁剪面 0.1 m,远裁剪面 1000 m。
    • <plugin>:libgazebo_ros_camera.so 将图像发布到 ROS 话题 /test_camera/image_raw。
2. <joint> - 关节

<joint> 定义部件之间的连接。

示例:rotor_0_joint
<joint name='rotor_0_joint' type='revolute'>
  <child>rotor_0</child>
  <parent>base_link</parent>
  <axis>
    <xyz>0 0 1</xyz>
    <limit>
      <lower>-1e+16</lower>
      <upper>1e+16</upper>
    </limit>
    <dynamics>
      <spring_reference>0</spring_reference>
      <spring_stiffness>0</spring_stiffness>
    </dynamics>
    <use_parent_model_frame>1</use_parent_model_frame>
  </axis>
</joint>
  • <type>:revolute(旋转关节)。
  • <child> 和 <parent>:连接 rotor_0 和 base_link。
  • <axis>:旋转轴。
    • <xyz>:Z 轴 (0 0 1)。
    • <limit>:旋转范围(几乎无限制)。
    • <dynamics>:无弹簧效应。
示例:camera_joint
<joint name="camera_joint" type="fixed">
  <parent>base_link</parent>
  <child>camera_link</child>
</joint>
  • <type>:fixed(固定关节),相机不可动。
  • 连接:将 camera_link 固定到 base_link。
3. <plugin> - 插件

<plugin> 添加仿真功能,如动力学或传感器数据发布。

示例:motor_model(电机)
<plugin name='front_right_motor_model' filename='libgazebo_motor_model.so'>
  <jointName>rotor_0_joint</jointName>
  <linkName>rotor_0</linkName>
  <turningDirection>ccw</turningDirection>
  <maxRotVelocity>1100</maxRotVelocity>
  <motorConstant>5.84e-06</motorConstant>
  <commandSubTopic>/gazebo/command/motor_speed</commandSubTopic>
  <motorNumber>0</motorNumber>
</plugin>
  • <filename>:加载 libgazebo_motor_model.so。
  • 参数
    • <jointName>:控制 rotor_0_joint。
    • <turningDirection>:逆时针旋转。
    • <maxRotVelocity>:最大转速 1100 rad/s。
    • <commandSubTopic>:订阅电机速度指令。
<plugin name='mavlink_interface' filename='libgazebo_mavlink_interface.so'>
  <imuSubTopic>/imu</imuSubTopic>
  <mavlink_tcp_port>4560</mavlink_tcp_port>
  <enable_lockstep>1</enable_lockstep>
</plugin>
  • 功能:连接 Gazebo 和 PX4,通过 MAVLink 协议通信。
  • 参数
    • <imuSubTopic>:订阅 IMU 数据。
    • <mavlink_tcp_port>:TCP 端口 4560。
    • <enable_lockstep>:同步仿真和 PX4 时间。
4. <include> - 外部模型
<include>
  <uri>model://gps</uri>
  <pose>0.1 0 0 0 0 0</pose>
  <name>gps0</name>
</include>
  • 含义:引入外部 GPS 模型,位置在前方 0.1 m。

三、语法规则

  1. XML 格式:层级结构,标签必须闭合。
  2. 单位
    • 长度:米 (m)。
    • 角度:弧度 (rad)。
    • 质量:千克 (kg)。
  3. 坐标系
    • 模型坐标系:base_link 为原点。
    • <pose>:x y z roll pitch yaw。
  4. 命名:name 属性必须唯一。

四、整体功能分析

  • 模型:iris 是一个四旋翼无人机。
  • 部件
    • base_link:机身。
    • rotor_*:四个旋翼。
    • imu_link:IMU 传感器。
    • camera_link:下视相机。
  • 关节:旋翼可旋转,IMU 和相机固定。
  • 插件:实现电机控制、传感器数据发布和 PX4 集成。

五、总结

这个 iris.sdf 文件定义了一个功能完整的四旋翼模型,包含物理属性、可视化、传感器(相机、IMU、GPS 等)和 PX4 仿真接口。语法符合 SDF 1.6 规范,结构清晰,便于扩展(如添加更多传感器)。如果有具体部分需要深入分析,请告诉我!


四.sdf模型坐标系是什么,gazebo仿真世界坐标系是什么

在 Gazebo 中,SDF(Simulation Description Format)模型坐标系和 Gazebo 仿真世界坐标系是两个相关但不同的概念。理解它们的定义和关系对于正确配置机器人模型(如 iris.sdf)以及在仿真中定位和控制非常重要。以下是详细解释。


一、SDF 模型坐标系

定义
  • SDF 模型坐标系 是指一个 SDF 文件中定义的模型(例如 iris)自身的局部坐标系。
  • 原点:由 <model> 标签内的第一个 <link>(通常是主体部件,如 base_link)的 <pose> 定义。如果未指定,默认位于模型的几何中心。
  • 方向
    • X 轴:向前(正方向)。
    • Y 轴:向右(正方向)。
    • Z 轴:向上(正方向)。
  • 单位:米(长度),弧度(角度)。
在 iris.sdf 中的体现
<model name='iris'>
  <link name='base_link'>
    <pose>0 0 0 0 0 0</pose>
    ...
  </link>
  <link name='rotor_0'>
    <pose>0.13 -0.22 0.023 0 0 0</pose>
    ...
  </link>
  <link name="camera_link">
    <pose>0 0 -0.1 0 1.5708 0</pose>
    ...
  </link>
</model>
  • 原点:base_link 的 <pose>0 0 0 0 0 0</pose> 定义了模型坐标系的原点(位于机身中心)
  • 相对位置
    • rotor_0 位于 (0.13, -0.22, 0.023),即相对于 base_link 前方 0.13 m,左侧 0.22 m,上方 0.023 m。
    • camera_link 位于 (0, 0, -0.1),下方 0.1 m,绕 Y 轴旋转 1.5708 弧度(90°,朝下)。
  • 特性所有 <link> 和 <joint> 的 <pose> 都是相对于模型坐标系的局部偏移
特点
  • 独立性:模型坐标系是模型内部的参考系,与外部世界无关。
  • 移动性:当模型在仿真中移动时,整个模型坐标系随模型一起移动。

二、Gazebo 仿真世界坐标系

定义
  • Gazebo 仿真世界坐标系 是 Gazebo 仿真环境的全局参考系,固定不变。
  • 原点:通常位于仿真世界的 (0, 0, 0),对应于 Gazebo 窗口的中心地面。
  • 方向
    • X 轴:向东(正方向)。
    • Y 轴:向北(正方向)。
    • Z 轴:向上(正方向,与重力相反)。
  • 单位:与 SDF 一致,米和弧度。
在仿真中的体现
  • 模型放置:当你通过 roslaunch px4 mavros_posix_sitl.launch 启动仿真时,iris 模型会被放置到世界坐标系中的某个位置。
    • 默认位置通常由 launch 文件或 Gazebo 的世界文件(.world)指定,例如 (0, 0, 0)。
  • 话题数据
    • /gazebo/model_states 话题提供所有模型相对于世界坐标系的位置和姿态。
    • 示例:若 iris 的 base_link 在世界坐标系中位于 (1, 2, 0.5),则其模型坐标系原点也在此点。
特点
  • 固定性:世界坐标系是全局的,不随模型移动。
  • 参考性:所有模型、传感器数据和物理计算都以世界坐标系为基准。

三、两者的关系

  1. 层次关系
    • 模型坐标系是局部坐标系,嵌套在世界坐标系内。
    • 模型坐标系的原点位置和姿态由模型在世界坐标系中的 <pose> 决定。
  2. 变换
    • 从模型坐标系到世界坐标系需要应用模型的全局位姿(位置和旋转)。
    • 例如,若 iris 在世界坐标系中位于 (1, 0, 0),则 camera_link 的世界坐标为 (1, 0, -0.1)。
  3. 实际应用
    • 在 SDF 中配置时,使用模型坐标系(相对 base_link)。
    • 在仿真运行时,传感器数据(如相机图像的 frame_id)和运动控制基于世界坐标系。

四、示例分析(基于 iris.sdf)

模型坐标系
  • 原点:base_link 位于 (0, 0, 0)。
  • 旋翼:rotor_0 在 (0.13, -0.22, 0.023),表示相对于机身中心的偏移。
  • 相机:camera_link 在 (0, 0, -0.1),下方 0.1 m,朝下。
世界坐标系
  • 假设:iris 被放置在世界坐标系的 (0, 0, 1)(起飞高度 1 m)。
  • 计算
    • base_link 世界坐标:(0, 0, 1)。
    • rotor_0 世界坐标:(0.13, -0.22, 1.023)。
    • camera_link 世界坐标:(0, 0, 0.9)。
验证
  • 运行仿真:
roslaunch px4 mavros_posix_sitl.launch

检查模型位置:

rostopic echo /gazebo/model_states -n 1
    • 查找 iris 的 pose,确认其在世界坐标系中的位置。

五、语法与配置要点

  1. SDF 中的 <pose>
    • 格式:x y z roll pitch yaw。
    • 在 <link> 中定义相对于模型坐标系的位置。
  2. 世界坐标系的指定
    • 通过 Gazebo 的 .world 文件或 ROS launch 文件(如 mavros_posix_sitl.launch)设置模型初始位置。
    • 示例(在 .world 文件中):
<include>
  <uri>model://iris</uri>

五.如何知道世界坐标系的原点和xyz方向,如何知道模型坐标系的原点和xyz方向

在 Gazebo 中,确定世界坐标系和模型坐标系的原点及其 X、Y、Z 方向需要结合文件配置、仿真环境和可视化工具进行观察和验证。以下是详细的步骤和方法,帮助你明确这两者的原点和方向。


一、确定 Gazebo 世界坐标系的原点和 XYZ 方向

1. 世界坐标系的定义
  • 原点:默认情况下,Gazebo 世界坐标系的原点位于仿真环境的 (0, 0, 0),通常对应于地面中心。
  • 方向
    • X 轴:向东(正方向)。
    • Y 轴:向北(正方向)。
    • Z 轴:向上(正方向,与重力相反)。
2. 如何确认原点和方向
方法 1:检查世界文件
  • Gazebo 的世界坐标系由 .world 文件定义。
  • 示例:在你的 PX4 SITL 仿真中,可能是 ~/PX4_Firmware/Tools/sitl_gazebo/worlds/empty.world。
  • 查看文件
cat ~/PX4_Firmware/Tools/sitl_gazebo/worlds/empty.world

查找 <pose> 或 <origin>:

<world name="empty">
  <scene>
    <ambient>0.4 0.4 0.4 1</ambient>
    <background>0.7 0.7 0.7 1</background>
  </scene>
  <physics type="ode">
    ...
  </physics>
  <model name="ground_plane">
    <pose>0 0 0 0 0 0</pose>
    ...
  </model>
</world>
    • 分析
      • ground_plane 的 <pose>0 0 0 0 0 0</pose> 表示地面位于世界坐标系原点。
      • 原点默认在地面中心,Z=0 为地面高度。
方法 2:通过 Gazebo GUI 可视化
  • 启动仿真
roslaunch px4 mavros_posix_sitl.launch
  • 观察
    • Gazebo 窗口中,地面是一个灰色平面,其中心通常是世界坐标系原点 (0, 0, 0)。
    • XYZ 方向:
      • 在 Gazebo 中,右键点击空白处,选择 “View -> Wireframe” 或 “View -> Orbit”,观察坐标轴方向。
      • 默认情况下,X 轴向右(东),Y 轴向前(北),Z 轴向上。
  • 添加坐标轴(可选):
    • 在 .world 文件中手动添加一个坐标轴模型:
<include>
  <uri>model://coordinate_frame</uri>
  <pose>0 0 0 0 0 0</pose>
</include>
    • 重启仿真后,坐标轴模型会显示红(X)、绿(Y)、蓝(Z),直观确认方向。
方法 3:检查 /gazebo/model_states
  • 运行命令
rostopic echo /gazebo/model_states -n 1

输出示例

name: ['ground_plane', 'iris']
pose:
  -
    position:
      x: 0.0
      y: 0.0
      z: 0.0
    orientation:
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
  -
    position:
      x: 0.0
      y: 0.0
      z: 0.5
    orientation:
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
  • 分析
    • ground_plane 在 (0, 0, 0),确认世界原点在地面。
    • iris 在 (0, 0, 0.5),表示模型初始位于 Z=0.5 m。
    • 方向由四元数 orientation 表示,(0, 0, 0, 1) 表示无旋转,与世界坐标系对齐。

二、确定 SDF 模型坐标系的原点和 XYZ 方向

1. 模型坐标系的定义
  • 原点:由 <model> 内第一个 <link>(通常是 base_link)的 <pose> 定义,默认情况下是 (0, 0, 0)。
  • 方向
    • X 轴:向前(正方向)。
    • Y 轴:向右(正方向)。
    • Z 轴:向上(正方向)。
  • 局部性:所有其他 <link> 和 <joint> 的 <pose> 是相对于模型坐标系的偏移。
2. 如何确认原点和方向
方法 1:分析 SDF 文件
  • 查看 iris.sdf
<model name='iris'>
  <link name='base_link'>
    <pose>0 0 0 0 0 0</pose>
    ...
  </link>
  <link name='rotor_0'>
    <pose>0.13 -0.22 0.023 0 0 0</pose>
    ...
  </link>
  <link name="camera_link">
    <pose>0 0 -0.1 0 1.5708 0</pose>
    ...
  </link>
</model>
  • 分析
    • 原点:base_link 的 <pose>0 0 0 0 0 0</pose> 定义模型坐标系原点。
    • 方向
      • rotor_0 在 (0.13, -0.22, 0.023):
        • X 正方向(0.13):向前。
        • Y 负方向(-0.22):向左(相对于右为正)。
        • Z 正方向(0.023):向上。
      • camera_link 在 (0, 0, -0.1),Z 负方向为下方,pitch=1.5708(90°)使相机朝下。
    • 结论:模型坐标系的 X 向前,Y 向右,Z 向上,与惯例一致。
方法 2:Gazebo GUI 可视化
  • 启动仿真
roslaunch px4 mavros_posix_sitl.launch
  • 观察模型
    • 在 Gazebo 中选中 iris,右键选择 “View -> Transparent” 或 “Wireframe”,查看部件布局。
    • base_link 是机身中心,旋翼位置(如 rotor_0 在左前方)可确认方向:
      • X 轴:机头方向。
      • Y 轴:右侧方向。
      • Z 轴:顶部方向。
  • 添加坐标轴
    • 修改 iris.sdf,在 base_link 中添加可视化坐标轴:
<visual name="base_link_axes">
  <pose>0 0 0 0 0 0</pose>
  <geometry>
    <mesh>
      <uri>model://coordinate_frame/meshes/axes.dae</uri>
      <scale>0.1 0.1 0.1</scale>
    </mesh>
  </geometry>
</visual>
    • 重启仿真后,机身中心会显示坐标轴(红 X,绿 Y,蓝 Z)。
方法 3:检查传感器数据
  • 相机朝向
rosrun image_view image_view image:=/test_camera/image_raw
    • camera_link 的 <pose>0 0 -0.1 0 1.5708 0</pose> 表示朝下,图像应显示地面,确认 Z 负方向。
  • IMU 数据
rostopic echo /imu -n 1
    • IMU 的 <pose> 与 base_link 对齐,检查加速度(Z 轴应接近 -9.81 m/s²,表示向上为正)。

三、两者的关系与验证

  1. 模型坐标系到世界坐标系
    • 模型坐标系的原点和方向由 iris 在世界坐标系中的位姿决定。
    • 示例:若 iris 在世界坐标系的 (1, 0, 0),无旋转,则 rotor_0 的世界坐标为 (1.13, -0.22, 0.023)。
  2. 验证方法
    • 在 Gazebo 中移动 iris(通过 GUI 或 /gazebo/set_model_state),观察模型坐标系如何随世界坐标系变化。
    • 示例命令:
rostopic pub /gazebo/set_model_state gazebo_msgs/ModelState "model_name: 'iris'
pose:
  position:
    x: 2.0
    y: 0.0
    z: 1.0
  orientation:
    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0"

四、总结

世界坐标系
  • 原点:地面中心 (0, 0, 0),由 .world 文件或默认设置确定。
  • 方向:X 东,Y 北,Z 上,通过 GUI 或 /gazebo/model_states 验证。
模型坐标系
  • 原点:base_link 的 <pose>((0, 0, 0)),即机身中心。
  • 方向:X 前,Y 右,Z 上,通过 SDF 配置和可视化(如旋翼、相机位置)确认。
实用建议
  • 调试:在 Gazebo 中添加坐标轴模型,或用 ROS 话题检查位姿。
  • 可视化:用 rviz 订阅 /test_camera/image_raw 和 /tf,直观显示坐标系关系。

六.依然是坐标系问题

解释一下下面的输出:

leaf@LAPTOP-NI05EP5K:~$ rostopic echo /gazebo/model_states -n 1
name:
  - ground_plane
  - asphalt_plane
  - iris
pose:
  -
    position:
      x: 0.0
      y: 0.0
      z: 0.0
    orientation:
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
  -
    position:
      x: 0.0
      y: 0.0
      z: 0.0
    orientation:
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
  -
    position:
      x: -0.03940256735964742
      y: 0.014403233290510268
      z: 0.10448983608463772
    orientation:
      x: 2.0178038215501333e-05
      y: 0.0010289933143760208
      z: -0.016112123443332602
      w: 0.9998696616278306
twist:
  -
    linear:
      x: 0.0
      y: 0.0
      z: 0.0
    angular:
      x: 0.0
      y: 0.0
      z: 0.0
  -
    linear:
      x: 0.0
      y: 0.0
      z: 0.0
    angular:
      x: 0.0
      y: 0.0
      z: 0.0
  -
    linear:
      x: -4.174362083928031e-06
      y: -3.40546941860435e-06
      z: -1.8908038290643137e-06
    angular:
      x: 6.162506394544502e-05
      y: -7.602476140973817e-05
      z: -5.77627563001367e-08
---

在 Gazebo 中,右键点击空白处,选择 “View -> Wireframe” 或 “View -> Orbit”,观察坐标轴,红绿蓝三条线分别对应的是xyz中的什么?

rotor_0 在机身的右前方,模型坐标系的 XYZ 方向是什么


我将逐一解释你的问题,包括 /gazebo/model_states 的输出、Gazebo GUI 中坐标轴的颜色对应,以及 rotor_0 位置与模型坐标系方向的关系。


一、解释 /gazebo/model_states 输出

命令与输出
leaf@LAPTOP-NI05EP5K:~$ rostopic echo /gazebo/model_states -n 1
  • 话题:/gazebo/model_states 是 Gazebo 发布的消息,类型为 gazebo_msgs/ModelStates,包含仿真中所有模型的状态(位置、姿态、速度)。
  • -n 1:仅显示一条消息。
输出内容
name:
  - ground_plane
  - asphalt_plane
  - iris
pose:
  -
    position: {x: 0.0, y: 0.0, z: 0.0}
    orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}
  -
    position: {x: 0.0, y: 0.0, z: 0.0}
    orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}
  -
    position: {x: -0.03940256735964742, y: 0.014403233290510268, z: 0.10448983608463772}
    orientation: {x: 2.0178038215501333e-05, y: 0.0010289933143760208, z: -0.016112123443332602, w: 0.9998696616278306}
twist:
  -
    linear: {x: 0.0, y: 0.0, z: 0.0}
    angular: {x: 0.0, y: 0.0, z: 0.0}
  -
    linear: {x: 0.0, y: 0.0, z: 0.0}
    angular: {x: 0.0, y: 0.0, z: 0.0}
  -
    linear: {x: -4.174362083928031e-06, y: -3.40546941860435e-06, z: -1.8908038290643137e-06}
    angular: {x: 6.162506394544502e-05, y: -7.602476140973817e-05, z: -5.77627563001367e-08}
分析
  1. name
    • ground_plane:地面模型。
    • asphalt_plane:可能是额外的地面或跑道模型。
    • iris:你的四旋翼无人机模型。
    • 顺序:与后续 pose 和 twist 的列表对应。
  2. pose(位置和姿态,相对于世界坐标系):
    • ground_plane
      • position: (0.0, 0.0, 0.0):位于世界坐标系原点。
      • orientation: (0, 0, 0, 1):四元数表示无旋转,与世界坐标系对齐。
    • asphalt_plane
      • position: (0.0, 0.0, 0.0):同样位于原点,可能与 ground_plane 重叠。
      • orientation: (0, 0, 0, 1):无旋转。
    • iris
      • position: (-0.0394, 0.0144, 0.1045):
        • X: -0.0394 m(略向西)。
        • Y: 0.0144 m(略向北)。
        • Z: 0.1045 m(上方约 10.45 cm)。
      • orientation: (2.018e-05, 0.001029, -0.01611, 0.99987):
        • 四元数表示微小旋转。
        • 转换为欧拉角(近似):偏航约 -1.84°(绕 Z 轴),俯仰和滚转几乎为 0。
        • 结论:iris 略微偏离原点,姿态接近水平。
  3. twist(线速度和角速度,相对于世界坐标系):
    • ground_plane 和 asphalt_plane
      • linear: (0, 0, 0):无线性速度(固定)。
      • angular: (0, 0, 0):无角速度。
    • iris
      • linear: (-4.17e-06, -3.41e-06, -1.89e-06):
        • 速度极小(微米/秒级别),几乎静止。
      • angular: (6.16e-05, -7.60e-05, -5.78e-08):
        • 角速度也很小(弧度/秒),表明几乎无旋转。
      • 结论:iris 当前处于稳定状态(可能是刚起飞或悬停)。
总结
  • 世界坐标系:ground_plane 和 asphalt_plane 在 (0, 0, 0),确认原点在地面中心。
  • iris 位置:位于世界坐标系的 (-0.0394, 0.0144, 0.1045),略微偏离原点,高度 10.45 cm,微小偏航。

二、Gazebo GUI 中坐标轴颜色对应

操作
  • 在 Gazebo 中,右键空白处,选择 “View -> Wireframe” 或 “View -> Orbit”。
  • 如果添加了坐标轴模型(例如通过 <include><uri>model://coordinate_frame</uri></include>),会显示红、绿、蓝三条线。
颜色与 XYZ 的对应
  • 红色:X 轴。
    • 世界坐标系:向东。
  • 绿色:Y 轴。
    • 世界坐标系:向北。
  • 蓝色:Z 轴。
    • 世界坐标系:向上。
  • 验证
    • 在 Gazebo 中,地面平面(X-Y 平面)为灰色,Z 轴(蓝色)垂直向上。
    • 若添加坐标轴模型到 iris,红线指向机头(X),绿线指向右侧(Y),蓝线指向顶部(Z)。

三、rotor_0 在右前方,模型坐标系的 XYZ 方向

rotor_0 的位置
  • 在 iris.sdf 中:
<link name='rotor_0'>
  <pose>0.13 -0.22 0.023 0 0 0</pose>
  ...
</link>
  • 解析
    • x: 0.13:向前 0.13 m。
    • y: -0.22:向左 0.22 m(Y 负方向)。
    • z: 0.023:向上 0.023 m。
  • 结论:相对于 base_link(模型坐标系原点),rotor_0 在 前方且偏左上方
    • 你提到“右前方”,可能是与实际定义不符,需澄清。
模型坐标系的 XYZ 方向
  • 原点:base_link 的 <pose>0 0 0 0 0 0</pose>,即机身中心。
  • 方向
    • X 轴:向前(正方向)。
      • rotor_0 的 x: 0.13 表示 X 正方向是机头方向。
    • Y 轴:向右(正方向)。
      • rotor_0 的 y: -0.22 表示向左(Y 负方向),因此 Y 正方向是右侧。
    • Z 轴:向上(正方向)。
      • rotor_0 的 z: 0.023 表示 Z 正方向是顶部。
  • 澄清“右前方”
    • 根据 SDF,rotor_0 在左前方(x: 0.13, y: -0.22)。
    • 若你认为它是“右前方”,可能是误解或参照了其他旋翼(如 rotor_2:<pose>0.13 0.22 0.023 0 0 0</pose>,右前方)。
验证
  • SDF 检查
    • rotor_0: (0.13, -0.22, 0.023) → 左前方。
    • rotor_2: (0.13, 0.22, 0.023) → 右前方。
  • Gazebo GUI
    • 启动仿真,查看 iris 模型,确认旋翼位置。
    • 若添加坐标轴模型,红线(X)向前,绿线(Y)向右,蓝线(Z)向上。

四、综合分析

  1. 世界坐标系
    • 原点:(0, 0, 0)(地面中心)。
    • 方向:X 东,Y 北,Z 上(红绿蓝对应)。
    • iris 当前位置:(-0.0394, 0.0144, 0.1045)。
  2. 模型坐标系
    • 原点:base_link(机身中心)。
    • 方向:X 前,Y 右,Z 上。
    • rotor_0 在左前方(若你指“右前方”,可能是 rotor_2)。
  3. 关系
    • iris 的模型坐标系原点在世界坐标系的 (-0.0394, 0.0144, 0.1045)。
    • rotor_0 世界坐标:(-0.0394 + 0.13, 0.0144 - 0.22, 0.1045 + 0.023) = (0.0906, -0.2056, 0.1275)。

五、建议

  • 确认“右前方”:检查 iris.sdf 中四个旋翼的 <pose>,明确哪个是右前方(应为 rotor_2)。
  • 可视化验证
roslaunch px4 mavros_posix_sitl.launch
    • 在 Gazebo 中观察 iris 的旋翼布局。
  • 进一步调试:若需更直观显示坐标系,添加坐标轴模型到 base_link。

网站公告

今日签到

点亮在社区的每一天
去签到