Gazebo与RViz联合仿真时odom消失

Gazebo与RViz联合仿真时odom消失

鱼香ROS介绍:

鱼香ROS是由机器人爱好者共同组成的社区,欢迎一起参与机器人技术交流。
进群加V:fishros2048

文章信息:

标题:Gazebo与RViz联合仿真时odom消失
原文地址:https://fishros.org.cn/forum/topic/34
关键词:
参与者: 924453613,小鱼,小伊,
版权声明: 文章中所有知识产权归鱼香ROS及原作者所有。


1. 924453613听着歌说:

irobot.urdf(sw2urdf导出urdf+differ_controller+laser)
odom_gazebo.launch
odom_rviz.launch

联合仿真时出现问题:
7c1df1f4-4baa-4e77-8c43-f9ef1e6d6809-图片.png

RViz单独仿真无问题:
e42204f9-29e3-4787-b953-9bb97dce057c-图片.png



2. 924453613看着电脑说:

irobot.urdf

<?xml version="1.0" encoding="utf-8"?>
<robot
  name="irobot">
  <link
    name="base_footprint">
    <visual>
      <geometry>
        <sphere
          radius="0.001" />
      </geometry>
      <material
        name="">
        <color
          rgba="0 0 0 0" />
      </material>
    </visual>
  </link>
  <link
    name="base_link">
    <inertial>
      <origin
        xyz="0.0353 6.2375E-05 0.0378"
        rpy="0 0 0" />
      <mass
        value="4.4466" />
      <inertia
        ixx="0.037776"
        ixy="0"
        ixz="0"
        iyy="0.026331"
        iyz="0"
        izz="0.060251" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/base_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0 0 0 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/base_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="base_link2base_footprint"
    type="fixed">
        <parent
          link="base_footprint" />
        <child
          link="base_link" />
        <origin
          xyz="0 0 0.011" />
        <!--irobot_height/2-->
  </joint>
  <link
    name="top_link">
    <inertial>
      <origin
        xyz="-0.005083 -0.000153 0.000877"
        rpy="0 0 0" />
      <mass
        value="0.11187" />
      <inertia
        ixx="0.0008137"
        ixy="0"
        ixz="0"
        iyy="0.00071"
        iyz="0"
        izz="0.001524" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/top_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0 1 0 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/top_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="top_joint"
    type="fixed">
    <origin
      xyz="0 0 0.0699"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="top_link" />
    <axis
      xyz="0 0 0" />
    <limit
      lower="0"
      upper="0"
      effort="0"
      velocity="0" />
  </joint>
  <link
    name="laser_link">
    <inertial>
      <origin
        xyz="-4.0578E-09 2.09E-09 0.00303"
        rpy="0 0 0" />
      <mass
        value="0.001737" />
      <inertia
        ixx="4.1116E-08"
        ixy="0"
        ixz="0"
        iyy="4.1116E-08"
        iyz="0"
        izz="7.8771E-08" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/laser_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 0 0 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/laser_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="laser_joint"
    type="fixed">
    <origin
      xyz="0.155 0 0.07433"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="laser_link" />
    <axis
      xyz="0 0 0" />
    <limit
      lower="0"
      upper="0"
      effort="0"
      velocity="0" />
  </joint>
  <link
    name="driven_link">
    <inertial>
      <origin
        xyz="0 -4.6809E-19 4.3368E-19"
        rpy="0 0 0" />
      <mass
        value="0.014137" />
      <inertia
        ixx="1.2723E-06"
        ixy="0"
        ixz="0"
        iyy="1.2723E-06"
        iyz="0"
        izz="1.2723E-06" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/driven_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/driven_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="driven_joint"
    type="continuous">
    <origin
      xyz="0.13 0 0.00438"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="driven_link" />
    <axis
      xyz="0 0 1" />
    <limit
      lower="-3.14"
      upper="3.14"
      effort="0"
      velocity="0" />
  </joint>
  <link
    name="left_wheel_link">
    <inertial>
      <origin
        xyz="5.9165E-31 -1.3878E-17 3.4694E-18"
        rpy="0 0 0" />
      <mass
        value="0.066366" />
      <inertia
        ixx="2.2972E-05"
        ixy="0"
        ixz="0"
        iyy="2.2972E-05"
        iyz="0"
        izz="4.3005E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/left_wheel_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/left_wheel_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="left_wheel_joint"
    type="continuous">
    <origin
      xyz="0 -0.10045 0.02538"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="left_wheel_link" />
    <axis
      xyz="0 -1 0" />
    <limit
      lower="-3.14"
      upper="3.14"
      effort="0"
      velocity="0" />
  </joint>
  <link
    name="right_wheel_link">
    <inertial>
      <origin
        xyz="-1.5766E-18 1.3878E-17 3.4694E-18"
        rpy="0 0 0" />
      <mass
        value="0.066366" />
      <inertia
        ixx="2.2972E-05"
        ixy="0"
        ixz="0"
        iyy="2.2972E-05"
        iyz="0"
        izz="4.3005E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/right_wheel_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://irobot/meshes/right_wheel_link.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="right_wheel_joint"
    type="continuous">
    <origin
      xyz="0 0.10045 0.02538"
      rpy="0 0 0" />
    <parent
      link="base_link" />
    <child
      link="right_wheel_link" />
    <axis
      xyz="0 -1 0" />
    <limit
      lower="-3.14"
      upper="3.14"
      effort="0"
      velocity="0" />
  </joint>
<!--color-->
  <gazebo reference="base_link">
    <material>Gazebo/Black</material>
  </gazebo>
  <gazebo reference="top_link">
    <material>Gazebo/Green</material>
  </gazebo>
  <gazebo reference="laser_link">
    <material>Gazebo/Red</material>
  </gazebo>
  <gazebo reference="camera_link">
    <material>Gazebo/Red</material>
  </gazebo>
  <gazebo reference="driven_link">
    <material>Gazebo/White</material>
  </gazebo>
  <gazebo reference="left_wheel_link">
    <material>Gazebo/White</material>
  </gazebo>
  <gazebo reference="right_wheel_link">
    <material>Gazebo/White</material>
  </gazebo>
  <!-- controller -->
  <transmission name="left_wheel_joint_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="left_wheel_joint">
      <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
    </joint>
    <actuator name="left_wheel_joint_motor">
      <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>
  <transmission name="right_wheel_joint_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="right_wheel_joint">
      <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
    </joint>
    <actuator name="right_wheel_joint_motor">
      <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>
  <gazebo>
    <plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller">
      <rosDebugLevel>Debug</rosDebugLevel>
      <publishWheelTF>true</publishWheelTF>
      <robotNamespace>/</robotNamespace>
      <publishTf>1</publishTf>
      <publishWheelJointState>true</publishWheelJointState>
      <alwaysOn>true</alwaysOn>
      <updateRate>100.0</updateRate>
      <legacyMode>true</legacyMode>
      <leftJoint>left_wheel_joint</leftJoint>
      <rightJoint>right_wheel_joint</rightJoint>
      <wheelSeparation>0.277</wheelSeparation>
      <wheelDiameter>0.073</wheelDiameter>
      <broadcastTF>1</broadcastTF>
      <wheelTorque>30</wheelTorque>
      <wheelAcceleration>1.8</wheelAcceleration>
      <commandTopic>cmd_vel</commandTopic>
      <odometryFrame>odom</odometryFrame>
      <odometryTopic>odom</odometryTopic>
      <robotBaseFrame>base_footprint</robotBaseFrame>
    </plugin>
  </gazebo>
  <!--laser-->
   <gazebo reference="laser_link">
    <sensor name="rplidar" type="ray">
      <pose>0 0 0 0 0 0</pose>
      <visualize>true</visualize>
      <update_rate>5.5</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>360</samples>
            <resolution>1</resolution>
            <min_angle>-3</min_angle>
            <max_angle>3</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.10</min>
          <max>30.0</max>
          <resolution>0.01</resolution>
        </range>
        <noise>
          <type>gaussian</type>
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin filename="libgazebo_ros_laser.so" name="gazebo_rplidar">
        <topicName>/scan</topicName>
        <frameName>laser_link</frameName>
      </plugin>
    </sensor>
  </gazebo> 
</robot>

odom_gazebo.launch

<launch>
  <param
    name="robot_description"
    textfile="$(find irobot)/urdf/irobot.urdf" />
  <include
    file="$(find gazebo_ros)/launch/empty_world.launch"/>
  <node
    name="tf_footprint_base"
    pkg="tf"    
    type="static_transform_publisher"
    args="0 0 0 0 0 0 base_link base_footprint 40" />
  <node
    pkg="gazebo_ros"
    type="spawn_model"
    name="model"
    args="-urdf -model irobot -param robot_description"  />
  <node
    name="fake_joint_calibration"
    pkg="rostopic"
    type="rostopic"
    args="pub /calibrated std_msgs/Bool true" />
</launch>

odom_rviz.launch

<launch>
    <param
    name="robot_description"
    textfile="$(find irobot)/urdf/irobot.urdf" />
  <node
    name="rviz"
    pkg="rviz"
    type="rviz"
    args="-d $(find irobot)/config/irobot.rviz" />
  <node
    name="joint_state_publisher_gui"
    pkg="joint_state_publisher_gui"
    type="joint_state_publisher_gui" />
  <node
    name="robot_state_publisher"
    pkg="robot_state_publisher"
    type="robot_state_publisher" />
  <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen">
    <rosparam file="$(find irobot)/config/diff_controller.yaml" command="load" />
    <param name="sim" value="true" />
  </node>
</launch>


3. 小鱼苦兮兮的说:

初步估计是TF问题,晚点我看一下,代码可以改成用代码块包裹一下,太长了,不好看。



4. 924453613掰着手指头说:

[[topic:post_is_deleted]]



5. 小伊掰着手指头说:

@924453613 每个帖子都可以再次编辑和删除的,不用再发一个哈哈,菜单在右下角。



6. 小鱼看着代码说:

@924453613
需要补充一些内容

  • 补充一下rqt_tf_tree的截图
  • 补充一下gazebo版本系统版本和ros版本
  • 补充config/diff_controller.yaml文件内容

同时做如下的尝试:

  • odom_rviz.launch删除arbotix节点后运行


7. 924453613吃着火锅说:

@小鱼
rqt_tf_tree
1e0c4984-ca45-444b-833e-16f44c9069b3-图片.png

ubuntu18.04-melodic-gazebo11
78ade14f-5a98-41ca-bd76-316985a0b9d3-图片.png

config/diff_controller.yaml

# 该文件是控制器配置,一个机器人模型可能有多个控制器,比如: 底盘、机械臂、夹持器(机械手)....
# 因此,根 name 是 controller
controllers: {
   # 单控制器设置
   base_controller: {
          #类型: 差速控制器
       type: diff_controller,
       #参考坐标
       base_frame_id: base_footprint, 
       #两个轮子之间的间距
       base_width: 0.277,
       #控制频率
       ticks_meter: 2000, 
       #PID控制参数,使机器人车轮快速达到预期速度
       Kp: 12, 
       Kd: 12, 
       Ki: 0, 
       Ko: 50, 
       #加速限制
       accel_limit: 1.0 
    }
}

删除arbotix结果
83430e43-1a52-4ccc-b5cc-7aac581c3b72-图片.png



8. 小鱼笑嘻嘻的说:

@924453613 看一下rqt_grapher,有几个joint_states的发布者。



9. 924453613看着电脑说:

@小鱼 只有一个
00a1b395-d203-4bff-a528-aa63fc73557a-图片.png



10. 小鱼看着电脑说:

@924453613 这个rqt_graph看起来非常不对劲。因为两轮差速这边也会发布机器人的joint_states,所以不需要再启动joint_state_publisher

修改odom_rviz.py

<launch>
    <param
    name="robot_description"
    textfile="$(find irobot)/urdf/irobot.urdf" />
  <node
    name="rviz"
    pkg="rviz"
    type="rviz"
    args="-d $(find irobot)/config/irobot.rviz" />
  <node
    name="robot_state_publisher"
    pkg="robot_state_publisher"
    type="robot_state_publisher" />
  <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen">
    <rosparam file="$(find irobot)/config/diff_controller.yaml" command="load" />
    <param name="sim" value="true" />
  </node>
</launch>


11. 924453613掰着手指头说:

@小鱼 有rqt_graph了 RViz中tf还是断开的
8bbac2b3-e02d-4d7a-9be9-3000decff09b-图片.png



12. 小鱼看着天空说:

@924453613 你看这里,一个话题有两个发布者,robot_state_publisher都不知道听谁的,所以导致TF错误,按照我上一条回复把joint_state_publisher干掉试试。



13. 924453613听着歌说:

@小鱼
干掉之后是这样的 RViz中tf还是断开的
e857fe89-24e4-407a-b58c-d15300f80029-图片.png



14. 小鱼听着歌说:

@924453613 现在还是有两个发布者在发布joint_states,只需要一个gazebo即可,请按照之前帖子里的提示删掉arbotix控制器程序。

另外需要注意的是,arbotix的功能和urdf中配置的differential_drive_controller功能是相同(从两者的配置可以看出,都有轮子名称,轮子间距等配置),但differential_drive_controller才是用于gazebo仿真使用的。



15. 924453613看着代码说:

@小鱼 感谢鱼总这么晚还在解答我的问题 我删除arbotix后 我重新查看tf树发现以下问题
1.odom到base_link断开
2.tf树与最初发布帖子时不同
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7dG7i3QA-1665484583961)(https://fishros.org.cn/static/files/60cf532a37a05cc07b5ff14a79ba6526.png)]
rqt_graph如下
0c36c124-3303-4ca1-8f9d-b07d81b02d22-图片.png



16. 小鱼听着歌说:

@924453613 首先恭喜你,离成功越来越近了,注意两轮差速模型的配置项robotBaseFrame,该项为其发布的joint_states参考的frame名称。

    <plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller">
      <robotBaseFrame>base_footprint</robotBaseFrame>
    </plugin>

尝试进一步修改:

  1. <robotBaseFrame>base_footprint->base_link,这样gazebo发布数据时应该会将base_link->left/right_joint
  2. 尝试删除静态发布footprint->base_link,因为在我看来,它也是多余的,两者之间的关系在URDF中已经给出。
  <node
    name="tf_footprint_base"
    pkg="tf"    
    type="static_transform_publisher"
    args="0 0 0 0 0 0 base_link base_footprint 40" />


17. 924453613看着电脑说:

@小鱼 感谢鱼总,目前tf树仍有问题,夜已深鱼总早点休息,明早我会继续尝试,非常感谢。
38ce58a1-cd0f-4612-9bd8-4ece42e04c6c-图片.png



18. 小鱼听着歌说:

@924453613 ok,目前看到对应的tf还是没有链接起来,需要注意的地方就是上文中提到的,可以多次修改尝试,祝早日成功,早点休息。



19. 924453613听着歌说:

@小鱼 非常感谢鱼总的解答目前已经解决,问题大概率是出现在odom_rviz.launch中重复出现了/arbotix,导致tf树出错了,谢谢👍
f6cf5071-6fe9-4246-b209-2d915ce5dbce-图片.png



20. 小鱼喜滋滋的说:

@924453613 很高兴能够看到该问题被解决掉,如果方便可以贴一下解决后的代码在本帖子中,方便其他小伙伴在遇到相同问题提供帮助。



  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值