机器人操作系统ROS(13)turtlebot3安装摄像头turtlebot3+kinect相机

本文叙述了如何在Turtlebot3-Burger机器人已有激光雷达的基础上,通过修改xacro描述文件、添加模型文件,为其添加kinect深度相机并能够获取深度图像。

此操作需要完成 以下几步,具体参考: turtlebot3的仿真安装

 mkdir -p ~/tub3_ws/src
 cd ~/tub3_ws/src
 git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
 git clone https://github.com/ROBOTIS-GIT/turtlebot3.git
 git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git
 cd ~/tub3_ws
 rosdep install --from-paths src -i -y
 catkin_make

上述步骤完成后会在src turtlebot3文件夹下,自动创建turtlebot3_description
以下文件的操作均在此功能包下实现
详细位置:/home/ros/tub3_ws/ src / turtlebot3 / turtlebot3_description
在这里插入图片描述

1. 构建kinect描述文件

注: kinect_gazebo.xacro放置于turtlebot3_description/urdf文件夹下: (没有的话新建

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="kinect_camera">

    <xacro:macro name="kinect_camera" params="prefix:=camera">
        <!-- Create kinect reference frame -->
        <!-- Add mesh for kinect -->
        <link name="${prefix}_link">
            <origin xyz="0 0 0" rpy="0 0 0"/>
            <visual>
                <origin xyz="0 0 0" rpy="0 0 ${M_PI/2}"/>
                <geometry>
                    <mesh filename="package://turtlebot3_description/meshes/kinect.dae" scale="0.4 0.4 0.4" />
                </geometry>
            </visual>
            <collision>
                <geometry>
                    <box size="0.07 0.3 0.09"/>
                </geometry>
            </collision>
        </link>

        <joint name="${prefix}_optical_joint" type="fixed">
            <origin xyz="0 0 0" rpy="-1.5708 0 -1.5708"/>
            <parent link="${prefix}_link"/>
            <child link="${prefix}_frame_optical"/>
        </joint>

        <link name="${prefix}_frame_optical"/>

        <gazebo reference="${prefix}_link">
            <sensor type="depth" name="${prefix}">
                <always_on>true</always_on>
                <update_rate>20.0</update_rate>
                <camera>
                    <horizontal_fov>${60.0*M_PI/180.0}</horizontal_fov>
                    <image>
                        <format>R8G8B8</format>
                        <width>640</width>
                        <height>480</height>
                    </image>
                    <clip>
                        <near>0.05</near>
                        <far>8.0</far>
                    </clip>
                </camera>
                <plugin name="kinect_${prefix}_controller" filename="libgazebo_ros_openni_kinect.so">
                    <cameraName>${prefix}</cameraName>
                    <alwaysOn>true</alwaysOn>
                    <updateRate>10</updateRate>
                    <imageTopicName>rgb/image_raw</imageTopicName>
                    <depthImageTopicName>depth/image_raw</depthImageTopicName>
                    <pointCloudTopicName>depth/points</pointCloudTopicName>
                    <cameraInfoTopicName>rgb/camera_info</cameraInfoTopicName>
                    <depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName>
                    <frameName>${prefix}_frame_optical</frameName>
                    <baseline>0.1</baseline>
                    <distortion_k1>0.0</distortion_k1>
                    <distortion_k2>0.0</distortion_k2>
                    <distortion_k3>0.0</distortion_k3>
                    <distortion_t1>0.0</distortion_t1>
                    <distortion_t2>0.0</distortion_t2>
                    <pointCloudCutoff>0.4</pointCloudCutoff>
                </plugin>
            </sensor>
        </gazebo>

    </xacro:macro>
</robot>`

2. 修改turtlebot3_burger.urdf.xacro文件

注:turtlebot3_burger.urdf.xacro文件放置于turtlebot3_description/urdf文件夹下,替换原有同名文件。代码中5-17行为添加内容。

`<?xml version="1.0" ?>
<robot name="turtlebot3_burger" xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:include filename="$(find turtlebot3_description)/urdf/common_properties.xacro"/>
  <xacro:include filename="$(find turtlebot3_description)/urdf/turtlebot3_burger.gazebo.xacro"/>
  <xacro:include filename="$(find turtlebot3_description)/urdf/kinect_gazebo.xacro"/>

  <xacro:property name="kinect_offset_x" value="0.0" />
  <xacro:property name="kinect_offset_y" value="0.0" />
  <xacro:property name="kinect_offset_z" value="0.1" />
  <xacro:property name="M_PI" value="3.14159" />

  <xacro:kinect_camera prefix="camera"/>
  <joint name="kinect_frame_joint" type="fixed">
    <origin xyz="${kinect_offset_x} ${kinect_offset_y} ${kinect_offset_z}" rpy="0 0 0" />
    <parent link="base_link"/>
    <child link="camera_link"/>
  </joint>

  <link name="base_footprint"/>

  <joint name="base_joint" type="fixed">
    <parent link="base_footprint"/>
    <child link="base_link"/>
    <origin xyz="0.0 0.0 0.010" rpy="0 0 0"/>
  </joint>

  <link name="base_link">
    <visual>
      <origin xyz="-0.032 0 0.0" rpy="0 0 0"/>
      <geometry>
        <mesh filename="package://turtlebot3_description/meshes/bases/burger_base.stl" scale="0.001 0.001 0.001"/>
      </geometry>
      <material name="light_black"/>
    </visual>

    <collision>
      <origin xyz="-0.032 0 0.070" rpy="0 0 0"/>
      <geometry>
        <box size="0.140 0.140 0.143"/>
      </geometry>
    </collision>

    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <mass value="8.2573504e-01"/>
      <inertia ixx="2.2124416e-03" ixy="-1.2294101e-05" ixz="3.4938785e-05"
               iyy="2.1193702e-03" iyz="-5.0120904e-06"
               izz="2.0064271e-03" />
    </inertial>
  </link>

  <joint name="wheel_left_joint" type="continuous">
    <parent link="base_link"/>
    <child link="wheel_left_link"/>
    <origin xyz="0.0 0.08 0.023" rpy="-1.57 0 0"/>
    <axis xyz="0 0 1"/>
  </joint>

  <link name="wheel_left_link">
    <visual>
      <origin xyz="0 0 0" rpy="1.57 0 0"/>
      <geometry>
        <mesh filename="package://turtlebot3_description/meshes/wheels/left_tire.stl" scale="0.001 0.001 0.001"/>
      </geometry>
      <material name="dark"/>
    </visual>

    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <cylinder length="0.018" radius="0.033"/>
      </geometry>
    </collision>

    <inertial>
      <origin xyz="0 0 0" />
      <mass value="2.8498940e-02" />
      <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09"
               iyy="1.1192413e-05" iyz="-1.4400107e-11"
               izz="2.0712558e-05" />
      </inertial>
  </link>

  <joint name="wheel_right_joint" type="continuous">
    <parent link="base_link"/>
    <child link="wheel_right_link"/>
    <origin xyz="0.0 -0.080 0.023" rpy="-1.57 0 0"/>
    <axis xyz="0 0 1"/>
  </joint>

  <link name="wheel_right_link">
    <visual>
      <origin xyz="0 0 0" rpy="1.57 0 0"/>
      <geometry>
        <mesh filename="package://turtlebot3_description/meshes/wheels/right_tire.stl" scale="0.001 0.001 0.001"/>
      </geometry>
      <material name="dark"/>
    </visual>

    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
        <cylinder length="0.018" radius="0.033"/>
      </geometry>
    </collision>

    <inertial>
      <origin xyz="0 0 0" />
      <mass value="2.8498940e-02" />
      <inertia ixx="1.1175580e-05" ixy="-4.2369783e-11" ixz="-5.9381719e-09"
               iyy="1.1192413e-05" iyz="-1.4400107e-11"
               izz="2.0712558e-05" />
      </inertial>
  </link>

  <joint name="caster_back_joint" type="fixed">
    <parent link="base_link"/>
    <child link="caster_back_link"/>
    <origin xyz="-0.081 0 -0.004" rpy="-1.57 0 0"/>
  </joint>

  <link name="caster_back_link">
    <collision>
      <origin xyz="0 0.001 0" rpy="0 0 0"/>
      <geometry>
        <box size="0.030 0.009 0.020"/>
      </geometry>
    </collision>

    <inertial>
      <origin xyz="0 0 0" />
      <mass value="0.005" />
      <inertia ixx="0.001" ixy="0.0" ixz="0.0"
               iyy="0.001" iyz="0.0"
               izz="0.001" />
    </inertial>
  </link>

  <joint name="imu_joint" type="fixed">
    <parent link="base_link"/>
    <child link="imu_link"/>
    <origin xyz="-0.032 0 0.068" rpy="0 0 0"/>
  </joint>

  <link name="imu_link"/>

  <joint name="scan_joint" type="fixed">
    <parent link="base_link"/>
    <child link="base_scan"/>
    <origin xyz="-0.032 0 0.172" rpy="0 0 0"/>
  </joint>

  <link name="base_scan">
    <visual>
      <origin xyz="0 0 0.0" rpy="0 0 0"/>
      <geometry>
        <mesh filename="package://turtlebot3_description/meshes/sensors/lds.stl" scale="0.001 0.001 0.001"/>
      </geometry>
      <material name="dark"/>
    </visual>

    <collision>
      <origin xyz="0.015 0 -0.0065" rpy="0 0 0"/>
      <geometry>
        <cylinder length="0.0315" radius="0.055"/>
      </geometry>
    </collision>

    <inertial>
      <mass value="0.114" />
      <origin xyz="0 0 0" />
      <inertia ixx="0.001" ixy="0.0" ixz="0.0"
               iyy="0.001" iyz="0.0"
               izz="0.001" />
    </inertial>
  </link>

</robot>` 

3. 添加kinect相机模型文件

在这里插入图片描述

`链接:https://pan.baidu.com/s/18Z8IqXy4N8LGrvYmiLuknQ 
提取码:wuat` 

将以上三个文件放置于turtlebot3_description/meshes文件夹下

4. 编译刷新运行,查看效果

tub3_ws工作空间下

catkin_make
source devel/setup.bash # 建议把这个写入 bashrc中,要不每次新开端口都需要执行
# 新端口
roslaunch turtlebot3_gazebo turtlebot3_world.launch
# 新端口 图像
rqt_image_view
# 新端口 键盘
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

在这里插入图片描述
在这里插入图片描述

参考资料

week44 turtlebot3+kinect-rplidar

### 调整 TurtleBot3 相机高度的方法 在配置 TurtleBot3 的过程中,调整相机的高度通常涉及修改其对应的模型文件(URDF 或 SDF 文件)。这些文件定义了机器人的几何结构、物理属性以及传感器的位置。 #### 修改 URDF/SDF 文件中的相机位置 TurtleBot3 使用 Gazebo 进行仿真时,默认的机器人模型存储在一个 `.sdf` 或 `.urdf` 文件中。要调整相机的高度,可以编辑该文件中的 `<link>` 和 `<joint>` 标签来重新定位相机相对于底盘的位置[^3]。 以下是具体操作: 1. **找到模型文件路径** - 如果使用的是官方发布的 TurtleBot3 模型,可以在 `turtlebot3_description` 包中找到相关文件。 - 命令: ```bash roscd turtlebot3_description/urdf/ ``` 2. **打开并编辑模型文件** - 找到与相机相关的部分,通常是 `<gazebo reference="camera">` 或类似的标签。 - 编辑 `<origin xyz="..." rpy="..."/>` 中的 `xyz` 属性,增加 Z 坐标的值即可提升相机的高度。例如: ```xml <joint name="camera_joint" type="fixed"> <parent link="base_link"/> <child link="camera_link"/> <origin xyz="0 0 0.3" rpy="0 0 0"/> </joint> ``` 上述代码表示将相机链接固定在基座上方 0.3 米处。 3. **保存更改并重启仿真** - 完成编辑后,启动新的仿真会话以应用更新后的设置: ```bash roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch ``` #### 测试调整效果 为了验证相机高度是否已正确调整,可以通过以下方式查看实时数据流: ```bash rostopic echo /camera/image_raw ``` 或者利用 RViz 可视化工具加载 `/camera/image_raw` 主题进行观察[^2]。 --- ### 注意事项 - 确保所使用的坐标系遵循 ROS 的标准右手定则,在此框架下正向 Z 轴代表垂直向上方向。 - 若需进一步自定义环境参数,可参照官方文档或学习资源深入理解 Gazebo 插件机制及其配置选项[^4]。 ---
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值