鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    Gazebo与RViz联合仿真时odom消失

    已定时 已固定 已锁定 已移动 已解决
    综合问题
    3
    21
    3.7k
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 小鱼小
      小鱼 技术大佬 @924453613
      最后由 编辑

      @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>
      

      新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

      9 1 条回复 最后回复 回复 引用 0
      • 9
        924453613 @小鱼
        最后由 编辑

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

        小鱼小 1 条回复 最后回复 回复 引用 0
        • 小鱼小
          小鱼 技术大佬 @924453613
          最后由 编辑

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

          新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

          9 1 条回复 最后回复 回复 引用 0
          • 9
            924453613 @小鱼
            最后由 924453613 编辑

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

            小鱼小 1 条回复 最后回复 回复 引用 0
            • 小鱼小
              小鱼 技术大佬 @924453613
              最后由 编辑

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

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

              新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

              9 1 条回复 最后回复 回复 引用 0
              • 9
                924453613 @小鱼
                最后由 编辑

                @小鱼 感谢鱼总这么晚还在解答我的问题 我删除arbotix后 我重新查看tf树发现以下问题
                1.odom到base_link断开
                2.tf树与最初发布帖子时不同
                134c18e1-4b0f-444f-b50e-7eb83f18b6f8-图片.png 6a5ec88e-d9c5-4a38-845e-653cfe0cb7cb-图片.png
                rqt_graph如下
                0c36c124-3303-4ca1-8f9d-b07d81b02d22-图片.png

                小鱼小 1 条回复 最后回复 回复 引用 0
                • 小鱼小
                  小鱼 技术大佬 @924453613
                  最后由 编辑

                  @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" />
                  

                  新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                  9 1 条回复 最后回复 回复 引用 0
                  • 9
                    924453613 @小鱼
                    最后由 编辑

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

                    小鱼小 1 条回复 最后回复 回复 引用 0
                    • 小鱼小
                      小鱼 技术大佬 @924453613
                      最后由 编辑

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

                      新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                      9 1 条回复 最后回复 回复 引用 0
                      • 9
                        924453613 @小鱼
                        最后由 编辑

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

                        小鱼小 1 条回复 最后回复 回复 引用 0
                        • 小鱼小
                          小鱼 技术大佬 @924453613
                          最后由 编辑

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

                          新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                          1 条回复 最后回复 回复 引用 0
                          • 9
                            924453613
                            最后由 编辑

                            解决后代码:
                            irobot.urdf

                            <?xml version="1.0" encoding="utf-8"?>
                            <robot
                              name="irobot">
                              <link
                                name="base_link">
                                <inertial>
                                  <origin
                                    xyz="0.035298 6.2375E-05 0.0016857"
                                    rpy="0 0 0" />
                                  <mass
                                    value="5" />
                                  <inertia
                                    ixx="0.038"
                                    ixy="0"
                                    ixz="0"
                                    iyy="0.026"
                                    iyz="0"
                                    izz="0.06" />
                                </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>
                              <link
                                name="top_link">
                                <inertial>
                                  <origin
                                    xyz="-0.0050829 -0.00015289 0.0008765"
                                    rpy="0 0 0" />
                                  <mass
                                    value="0.2" />
                                  <inertia
                                    ixx="0.00081"
                                    ixy="0"
                                    ixz="0"
                                    iyy="0.00071"
                                    iyz="0"
                                    izz="0.0015" />
                                </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_link2base_link"
                                type="fixed">
                                <origin
                                  xyz="0 0 0.033795"
                                  rpy="0 0 0" />
                                <parent
                                  link="base_link" />
                                <child
                                  link="top_link" />
                                <axis
                                  xyz="0 -1 0" />
                                <limit
                                  lower="0"
                                  upper="0"
                                  effort="0"
                                  velocity="0" />
                              </joint>
                              <link
                                name="laser_link">
                                <inertial>
                                  <origin
                                    xyz="1.1845E-09 4.4075E-09 0.0030295"
                                    rpy="0 0 0" />
                                  <mass
                                    value="0.1" />
                                  <inertia
                                    ixx="4.11E-08"
                                    ixy="0"
                                    ixz="0"
                                    iyy="4.11E-08"
                                    iyz="0"
                                    izz="7.88E-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_link2base_link"
                                type="fixed">
                                <origin
                                  xyz="0.155 0 0.038215"
                                  rpy="0 0 0" />
                                <parent
                                  link="base_link" />
                                <child
                                  link="laser_link" />
                                <axis
                                  xyz="0 -1 0" />
                                <limit
                                  lower="0"
                                  upper="0"
                                  effort="0"
                                  velocity="0" />
                              </joint>
                              <link
                                name="right_wheel">
                                <inertial>
                                  <origin
                                    xyz="-1.0317E-18 1.3878E-17 -1.7347E-18"
                                    rpy="0 0 0" />
                                  <mass
                                    value="0.05" />
                                  <inertia
                                    ixx="2.3E-05"
                                    ixy="0"
                                    ixz="0"
                                    iyy="4.3E-05"
                                    iyz="0"
                                    izz="2.3E-05" />
                                </inertial>
                                <visual>
                                  <origin
                                    xyz="0 0 0"
                                    rpy="0 0 0" />
                                  <geometry>
                                    <mesh
                                      filename="package://irobot/meshes/right_wheel.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.STL" />
                                  </geometry>
                                </collision>
                              </link>
                              <joint
                                name="right_wheel2base_link"
                                type="continuous">
                                <origin
                                  xyz="0 0.10045 -0.010735"
                                  rpy="0 0 0" />
                                <parent
                                  link="base_link" />
                                <child
                                  link="right_wheel" />
                                <axis
                                  xyz="0 -1 0" />
                                <limit
                                  lower="-3.14"
                                  upper="3.14"
                                  effort="100"
                                  velocity="2" />
                              </joint>
                              <link
                                name="left_wheel">
                                <inertial>
                                  <origin
                                    xyz="-1.1842E-18 0 -1.7347E-18"
                                    rpy="0 0 0" />
                                  <mass
                                    value="0.05" />
                                  <inertia
                                    ixx="2.3E-05"
                                    ixy="0"
                                    ixz="0"
                                    iyy="4.3E-05"
                                    iyz="0"
                                    izz="2.3E-05" />
                                </inertial>
                                <visual>
                                  <origin
                                    xyz="0 0 0"
                                    rpy="0 0 0" />
                                  <geometry>
                                    <mesh
                                      filename="package://irobot/meshes/left_wheel.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.STL" />
                                  </geometry>
                                </collision>
                              </link>
                              <joint
                                name="left_wheel2base_link"
                                type="continuous">
                                <origin
                                  xyz="0 -0.10045 -0.010735"
                                  rpy="0 0 0" />
                                <parent
                                  link="base_link" />
                                <child
                                  link="left_wheel" />
                                <axis
                                  xyz="0 -1 0" />
                                <limit
                                  lower="-3.14"
                                  upper="3.14"
                                  effort="100"
                                  velocity="2" />
                              </joint>
                              <link
                                name="driven_wheel">
                                <inertial>
                                  <origin
                                    xyz="0 -3.4443E-19 0"
                                    rpy="0 0 0" />
                                  <mass
                                    value="0.02" />
                                  <inertia
                                    ixx="1.27E-06"
                                    ixy="0"
                                    ixz="0"
                                    iyy="1.27E-06"
                                    iyz="0"
                                    izz="1.27E-06" />
                                </inertial>
                                <visual>
                                  <origin
                                    xyz="0 0 0"
                                    rpy="0 0 0" />
                                  <geometry>
                                    <mesh
                                      filename="package://irobot/meshes/driven_wheel.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_wheel.STL" />
                                  </geometry>
                                </collision>
                              </link>
                              <joint
                                name="driven_wheel2base_link"
                                type="fixed">
                                <origin
                                  xyz="0.13 0 -0.031735"
                                  rpy="0 0 0" />
                                <parent
                                  link="base_link" />
                                <child
                                  link="driven_wheel" />
                                <axis
                                  xyz="0 -1 0" />
                                <limit
                                  lower="0"
                                  upper="0"
                                  effort="0"
                                  velocity="0" />
                              </joint>
                              <link
                                name="base_footprint">
                                <visual>
                                  <geometry>
                                    <sphere
                                      radius="0.001" />
                                  </geometry>
                                  <material
                                    name="">
                                    <color
                                      rgba="0 0 0 0" />
                                  </material>
                                </visual>
                              </link>
                              <joint
                                name="base_link2base_footprint"
                                type="fixed">
                                    <parent
                                      link="base_footprint" />
                                    <child
                                      link="base_link" />
                                    <origin
                                      xyz="0 0 0.047" />
                              </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_wheel">
                                <material>Gazebo/White</material>
                              </gazebo>
                              <gazebo reference="left_wheel">
                                <material>Gazebo/White</material>
                              </gazebo>
                              <gazebo reference="right_wheel">
                                <material>Gazebo/White</material>
                              </gazebo>
                              <!-- controller -->
                              <transmission name="left_wheel2base_link_trans">
                                <type>transmission_interface/SimpleTransmission</type>
                                <joint name="left_wheel2base_link">
                                  <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
                                </joint>
                                <actuator name="left_wheel2base_link_motor">
                                  <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
                                  <mechanicalReduction>1</mechanicalReduction>
                                </actuator>
                              </transmission>
                              <transmission name="right_wheel2base_link_trans">
                                <type>transmission_interface/SimpleTransmission</type>
                                <joint name="right_wheel2base_link">
                                  <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
                                </joint>
                                <actuator name="right_wheel2base_link_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_wheel2base_link</leftJoint>
                                  <rightJoint>right_wheel2base_link</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>
                              <include
                                file="$(find gazebo_ros)/launch/empty_world.launch" />
                              <node
                                name="spawn_model"
                                pkg="gazebo_ros"
                                type="spawn_model"
                                args="-file $(find irobot)/urdf/irobot.urdf -urdf -model irobot"
                                output="screen" />
                              <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="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="rviz"
                                pkg="rviz"
                                type="rviz"
                                args="-d $(find irobot)/config/irobot.rviz" />
                            </launch>
                            
                            1 条回复 最后回复 回复 引用 0
                            • 小鱼小 小鱼 将这个主题转为问答主题,在
                            • 小鱼小 小鱼 将这个主题标记为已解决,在
                            • 第一个帖子
                              最后一个帖子
                            皖ICP备16016415号-7
                            Powered by NodeBB | 鱼香ROS