gazebo教程---使用gazebo插件

2023-05-16

一. 添加传感器插件
(1)在rrbot.xacro中添加< link/>和< joint/>,内容如下:

<joint name="camera_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="${camera_link} 0 ${height3 - axel_offset*2}" rpy="0 0 0"/>
    <parent link="link3"/>
    <child link="camera_link"/>
  </joint>

  <!-- Camera -->
  <link name="camera_link">
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
	<box size="${camera_link} ${camera_link} ${camera_link}"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
	<box size="${camera_link} ${camera_link} ${camera_link}"/>
      </geometry>
      <material name="red"/>
    </visual>

    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

上面是用于rviz加载
(2)在rrbot.gazebo中添加如下内容:

  <!-- camera -->
  <gazebo reference="camera_link">
    <sensor type="camera" name="camera1">
      <update_rate>30.0</update_rate>
      <camera name="head">
        <horizontal_fov>1.3962634</horizontal_fov>
        <image>
          <width>800</width>
          <height>800</height>
          <format>R8G8B8</format>
        </image>
        <clip>
          <near>0.02</near>
          <far>300</far>
        </clip>
        <noise>
          <type>gaussian</type>
          <!-- Noise is sampled independently per pixel on each frame.
               That pixel's noise value is added to each of its color
               channels, which at that point lie in the range [0,1]. -->
          <mean>0.0</mean>
          <stddev>0.007</stddev>
        </noise>
      </camera>
      <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
        <alwaysOn>true</alwaysOn>
        <updateRate>0.0</updateRate>
        <cameraName>rrbot/camera1</cameraName>
        <imageTopicName>image_raw</imageTopicName>
        <cameraInfoTopicName>camera_info</cameraInfoTopicName>
        <frameName>camera_link_optical</frameName>
        <!-- setting hackBaseline to anything but 0.0 will cause a misalignment
            between the gazebo sensor image and the frame it is supposed to
            be attached to -->
        <hackBaseline>0.0</hackBaseline>
        <distortionK1>0.0</distortionK1>
        <distortionK2>0.0</distortionK2>
        <distortionK3>0.0</distortionK3>
        <distortionT1>0.0</distortionT1>
        <distortionT2>0.0</distortionT2>
        <CxPrime>0</CxPrime>
        <Cx>0.0</Cx>
        <Cy>0.0</Cy>
        <focalLength>0.0</focalLength>
      </plugin>
    </sensor>
  </gazebo>
<gazebo reference="camera_link">

首先这个link的名字必须与我们添加到xacro文件中的canera的link匹配。

<sensor type="camera" name="camera1">

其次传感器的名字必须是唯一的,除了在gazebo插件中,这个名字不能用在其它地方。

<update_rate>30.0</update_rate>

这是在仿真期间传感器尝试刷新的最大频率,但是当物理仿真速度快于传感器生成的速度时,它会低于这个目标值。

        <horizontal_fov>1.3962634</horizontal_fov>
        <image>
          <width>800</width>
          <height>800</height>
          <format>R8G8B8</format>
        </image>
        <clip>
          <near>0.02</near>
          <far>300</far>
        </clip>

上面的取值是与自身相机物理硬件的规格相匹配。而< near>和< far>表示的是相机可以看到物体的最近和最远距离。

<plugin name="camera_controller" filename="libgazebo_ros_camera.so">

这个是实际文件gazebo_ros/gazebo_ros_camera.cpp所要链接的。

        <cameraName>rrbot/camera1</cameraName>
        <imageTopicName>image_raw</imageTopicName>
        <cameraInfoTopicName>camera_info</cameraInfoTopicName>

这里定义的是相机发布的话题。对于rrbot,我们所要订阅的话题为:

/rrbot/camera1/image_raw
/rrbot/camera1/camera_info

二. 运行launch文件

roslaunch rrbot_gazebo rrbot_world.launch
roslaunch rrbot_description rrbot_rviz.launch

结果如下图:
在这里插入图片描述
在这里插入图片描述
运行rqt_graph,显示节点图:
在这里插入图片描述
可以看出gazebo和rviz中的机器人状态不一致。
此时加载的rrbot_world.launch的内容如下:

<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find rrbot_gazebo)/worlds/rrbot.world"/>
    <arg name="debug" value="$(arg debug)" />
    <arg name="gui" value="$(arg gui)" />
    <arg name="paused" value="$(arg paused)"/>
    <arg name="use_sim_time" value="$(arg use_sim_time)"/>
    <arg name="headless" value="$(arg headless)"/>
  </include>

  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find rrbot_description)/urdf/rrbot.xacro'" />

  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
    args="-urdf -model rrbot -param robot_description"/>

</launch>

rrbot_rviz.launch的内容如下:

<launch>
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find rrbot_description)/urdf/rrbot.xacro'" />

  <!-- send fake joint values -->
  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
    <param name="use_gui" value="true"/>
  </node>

  <!-- Combine joint values -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>

  <!-- Show in Rviz   -->
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find rrbot_description)/launch/rrbot.rviz"/>

</launch>

对于添加激光雷达插件是一样的原理。

参考:
http://gazebosim.org/tutorials?tut=ros_gzplugins

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

gazebo教程---使用gazebo插件 的相关文章

随机推荐

  • VINS知识点汇总

    0 总体框架 包括5个部分 xff1a 数据预处理 初始化 后端非线性优化 闭环检测 位姿图优化 图片来自大佬博客 xff1a https blog csdn net try again later article details 1048
  • 语义SLAM综述

    1 摘要 SLAM技术在计算机视觉和机器人领域中占有重要低位 传统的SLAM框架采用了较强的静态世界假设 xff0c 便于分析 大多基于小区域静态环境 在大规模的动态环境下 xff0c 它们大多难以获得较好的性能 xff0c 系统的准确性
  • VINS-Mono学习(三)——基于滑动窗口的VIO紧耦合后端非线性优化

    nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 初始化后 采用基于滑动窗口的紧耦合单目VIO进行状态估计 首先来看VINS Mono后端的整体思路 nbsp nbsp nbsp nbsp nbsp nbsp
  • VINS-Mono学习(五)——闭环优化4DoF

    这里再重写一边VINS开启的新线程 xff1a 前端图像跟踪后端非线性优化闭环检测闭环优化 闭环优化是跟在闭环检测之后步骤 首先回顾闭环检测的过程 xff1a 1 pose graph node cpp开启process闭环检测线程 xff
  • C语言预定义跟踪调试

    标准C语言预处理要求定义某些对象宏 xff0c 每个预定义宏的名称一两个下划线字符开头和结尾 xff0c 这些预定义宏不能被取消定义 xff08 undef xff09 或由编程人员重新定义 下面预定义宏表 xff0c 被我抄了下来 LIN
  • 链式存储

    1 特点 线性表的链式存储结构的特点是用一组任意的存储单元存储线性表的数据元素 xff0c 这组存储单元可以是连续的 xff0c 也可以是不连续的这就意味着 xff0c 这些数据元素可以存在内存未被占用的任意位置 2 结点是什么 在数据结构
  • ROS驱动包无法连接A2M7雷达解决办法

    我在使用A2M7雷达时 xff0c 波特率是256000 xff0c 之前驱动跑A2M6和A2M8雷达时 xff0c 波特率115200 xff0c 都可以使用 xff0c 现在跑M7就不行 xff0c 显示无法绑定到串口 xff0c 刚开
  • FreeRTOS prvTaskExitError 创建任务错误

    文件port c prvTaskExitError 任务退出错误 xff0c 一个可能在任务里面写了return xff0c 另一个可能任务切换退出问题 xff0c 入栈和出栈的时候出了问题 1 static void prvTaskExi
  • Ubuntu18.04下VSCode环境编写Linux相关驱动程序时出现未定义标识符问题

    Ubuntu18 04下VSCode环境编写Linux相关驱动程序时出现未定义标识符问题 编译Linux相关驱动程序时 xff0c 出现未定义标识符问题 但是ctrl 43 鼠标左键可以找到相关定义 这是因为没有加载对应Linux内核中头文
  • postman基础使用教程

    Postman教程大全 简书 推荐一款接口测试工具 xff01 POSTMAN xff01 简单来说 xff0c 四个词 xff0c 简单实用大方美观 xff01 Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插
  • Make、Makefile、CMake和CMakeLists

    一 Make 在 认识编译器和C C 43 43 编译 一文中介绍过 xff0c 一个 c cpp 文件从源文件到目标文件的过程叫做编译 xff0c 但是一个项目中不可能只存在一个文件 xff0c 这就涉及到多个文件的编译问题 xff0c
  • C++将类写在头文件中

    比如有个类ABC要在main cpp内使用 xff0c 创建两个文件 ABC h xff0c ABC cpp 把类的声明都写在h里面 xff0c 方法的实现写在cpp里面 xff0c 然后在main cpp内 include ABC h x
  • ubuntu搭建一个简单的http服务器

    使用ubuntu搭建一个简单的http服务器 安装apache2 1 sudo apt get update 2 sudo apt get install apache2 安装成功后 xff0c 再 etc apache2目录可见其配置文件
  • Postman操作基本教程

    一 xff1a 基本介绍 xff1a Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件 Postman背景介绍 用户在开发或者调试网络程序或者是网页B S模式的程序的时候是需要一些方法来跟踪网页请求的 xff0
  • ROS中rosserial通讯协议初探

    ROS中rosserial通讯协议初探 串行的通讯 xff0c 我们用串口模拟下通讯图 官方 http wiki ros org rosserial rosserial 1概述 标准ROS序列化message的协议 xff0c 可以让一个字
  • 使用cmake交叉编译arm平台so

    使用cmake交叉编译arm平台so 众所周知 xff0c androidStudio可以编译apk及so 具体配置此处不一一介绍 xff0c 但对于需要经常编译不同项目的小编来说 xff0c 太过重量级了 xff0c 假如在编译系统下并没
  • Linux编译C文件

    熟悉了Windows平台下编译一个C 43 43 工程后 xff0c 你是否会提出这样一个问题 xff1a 在Linux平台下又如何编译一个C 43 43 工程呢 xff1f 希望本文能给正在学习或想学习Linux C 43 43 开发的你
  • stm32 esp8266 ota升级-qt bin文件处理工具

    stm32 esp8266 ota系列文章 xff1a stm32 esp8266 ota 快速搭建web服务器之docker安装openresty stm32 esp8266 ota升级 tcp模拟http stm32 esp8266 o
  • 04.Android调用C语言的方法

    为了在Android端调用底层的驱动程序 xff0c 我们需要在Android中调用C语言 直接新建一个Native C 43 43 工程 xff0c 然后按照这篇文章的方法 xff1a JNI与NDK简析 xff08 一 xff09 St
  • gazebo教程---使用gazebo插件

    一 添加传感器插件 xff08 1 xff09 在rrbot xacro中添加 lt link gt 和 lt joint gt xff0c 内容如下 xff1a lt joint name 61 span class token stri