ROS导航仿真中遇到的问题汇总

前言

由于古月居使用的ROS是 melodic 版本,因此在使用 Ubuntu20.04 时(对应ROS的版本为 noetic),因此在一些语法上出现了问题,源码来自于:ros_basic_tutorials 中的 mbot_navigation,故整理如下:

1、古月居课程:如何实现ROS机器人自主导航

运行

roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch

报错:

[ERROR] [1710129366.949570783]: Failed to build tree: parent link [base_link] of joint [lidar_joint] not found.  This is not valid according to the URDF spec. Every link you refer to from a joint needs to be explicitly defined in the robot description. To fix this problem you can either remove this joint [lidar_joint] from your urdf file, or add "<link name="base_link" />" to your urdf file.
[robot_state_publisher-5] process has died [pid 46841, exit code 1, cmd /opt/ros/noetic/lib/robot_state_publisher/robot_state_publisher __name:=robot_state_publisher __log:=/home/yin-roc/.ros/log/493470dc-df5b-11ee-b611-e12e66a83225/robot_state_publisher-5.log].
log file: /home/yin-roc/.ros/log/493470dc-df5b-11ee-b611-e12e66a83225/robot_state_publisher-5*.log

解决方法:

想要尝试运行 mbot_description 包中的 display_mbot_xacro.launch 文件,但报错:

No link elements found in urdf file [robot_state_publisher-2] process has died [pid 7059, exit code 1, cmd /opt/ros/noetic/lib/robot_state_publisher/robot_state_publisher __name:=robot_state_publisher __log:=/home/yin-roc/.ros/log/db1ea2b4-df6b-11ee-bd56-319dd3cac4a1/robot_state_publisher-2.log]. log file: /home/yin-roc/.ros/log/db1ea2b4-df6b-11ee-bd56-319dd3cac4a1/robot_state_publisher-2*.log [ERROR] [1710138080.036809832, 1890.294000000]: No link elements found in urdf file

于是在功能包 mbot_description 中查找问题,发现是版本原因,古月居的 melodic 版本中xacro调用不需要加前缀,但 Ubuntu20.04(noetic)版本中需要加前缀 xacro: 来引用:于是进行以下修改:

1.mbot_gazebo.xacro文件中添加如下语句:
<xacro:mbot_base_gazebo/>

2.轮子不显示问题,在 mbot_base_gazebo.xacro 文件中宏调用添加如下前缀,修改如下:
<xacro:wheel prefix="left"  reflect="1"/>
<xacro:wheel prefix="right" reflect="-1"/>

<xacro:caster prefix="front" reflect="-1"/>
<xacro:caster prefix="back"  reflect="1"/>

3.mbot_base_gazebo.xacro 文件中的类似的惯性参数都要添加前缀 xacro:
<xacro:cylinder_inertial_matrix  m="${base_mass}" r="${base_radius}" h="${base_length}" />

但运行:

roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch

仍是报错!!!且不显示模型!!!

[ERROR] [1710139681.124637466]: Failed to build tree: parent link [base_link] of joint [lidar_joint] not found.  This is not valid according to the URDF spec. Every link you refer to from a joint needs to be explicitly defined in the robot description. To fix this problem you can either remove this joint [lidar_joint] from your urdf file, or add "<link name="base_link" />" to your urdf file.
[INFO] [1710139681.454924, 0.000000]: Loading model XML from ros parameter robot_description
[INFO] [1710139681.458569, 0.000000]: Waiting for service /gazebo/spawn_urdf_model
[robot_state_publisher-5] process has died [pid 12334, exit code 1, cmd /opt/ros/noetic/lib/robot_state_publisher/robot_state_publisher __name:=robot_state_publisher __log:=/home/yin-roc/.ros/log/4cfed6fe-df73-11ee-bd56-319dd3cac4a1/robot_state_publisher-5.log].
log file: /home/yin-roc/.ros/log/4cfed6fe-df73-11ee-bd56-319dd3cac4a1/robot_state_publisher-5*.log

于是尝试单独的运行某个模型展示 launch,比如 view_mbot_with_camera_gazebo.launch,也出现如下类似问题:

Failed to build tree: parent link [base_link] of joint [camera_joint] not found.  This is not valid according to the URDF spec. Every link you refer to from a joint needs to be explicitly defined in the robot description. To fix this problem you can either remove this joint [camera_joint] from your urdf file, or add "<link name="base_link" />" to your urdf file. [robot_state_publisher-5] process has died [pid 9714, exit code 1, cmd /opt/ros/noetic/lib/robot_state_publisher/robot_state_publisher __name:=robot_state_publisher __log:=/home/yin-roc/.ros/log/f7e71bd2-df71-11ee-bd56-319dd3cac4a1/robot_state_publisher-5.log]. log file: /home/yin-roc/.ros/log/f7e71bd2-df71-11ee-bd56-319dd3cac4a1/robot_state_publisher-5*.log

经查找,有可能同样是因为环境原因,在宏调用处出现问题:

在 mbot_with_camera_gazebo.xacro 文件中添加

<mbot_base_gazebo/>
<xacro:mbot_base_gazebo/>

修改如下:

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

    <xacro:include filename="$(find mbot_description)/urdf/mbot_base_gazebo.xacro" />
    <xacro:include filename="$(find mbot_description)/urdf/sensors/camera_gazebo.xacro" />

	<mbot_base_gazebo/>
	
    <xacro:property name="camera_offset_x" value="0.17" />
    <xacro:property name="camera_offset_y" value="0" />
    <xacro:property name="camera_offset_z" value="0.10" />

    <!-- Camera -->
    <joint name="camera_joint" type="fixed">
        <origin xyz="${camera_offset_x} ${camera_offset_y} ${camera_offset_z}" rpy="0 0 0" />
        <parent link="base_link"/>
        <child link="camera_link"/>
    </joint>

    <xacro:usb_camera prefix="camera"/>

    <xacro:mbot_base_gazebo/>

</robot>

mbot_with_kinect_gazebo.xacro 和 mbot_with_laser_gazebo.xacro 同样在类似位置添加 xacro:mbot_base_gazebo/,修改结果如下:

  1. kinect 文件
<?xml version="1.0"?>
<robot name="arm" xmlns:xacro="http://www.ros.org/wiki/xacro">

    <xacro:include filename="$(find mbot_description)/urdf/mbot_base_gazebo.xacro" />
    <xacro:include filename="$(find mbot_description)/urdf/sensors/kinect_gazebo.xacro" />

	<mbot_base_gazebo/>
	
    <xacro:property name="kinect_offset_x" value="0.15" />
    <xacro:property name="kinect_offset_y" value="0" />
    <xacro:property name="kinect_offset_z" value="0.11" />

    <!-- kinect -->
    <joint name="kinect_joint" type="fixed">
        <origin xyz="${kinect_offset_x} ${kinect_offset_y} ${kinect_offset_z}" rpy="0 0 0" />
        <parent link="base_link"/>
        <child link="kinect_link"/>
    </joint>

    <xacro:kinect_camera prefix="kinect"/>

    <xacro:mbot_base_gazebo/>

</robot>
  1. laser 文件
<?xml version="1.0"?>
<robot name="arm" xmlns:xacro="http://www.ros.org/wiki/xacro">

    <xacro:include filename="$(find mbot_description)/urdf/mbot_base_gazebo.xacro" />
    <xacro:include filename="$(find mbot_description)/urdf/sensors/lidar_gazebo.xacro" />

	<mbot_base_gazebo/>
	
    <xacro:property name="lidar_offset_x" value="0" />
    <xacro:property name="lidar_offset_y" value="0" />
    <xacro:property name="lidar_offset_z" value="0.105" />

    <!-- lidar -->
    <joint name="lidar_joint" type="fixed">
        <origin xyz="${lidar_offset_x} ${lidar_offset_y} ${lidar_offset_z}" rpy="0 0 0" />
        <parent link="base_link"/>
        <child link="laser_link"/>
    </joint>

    <xacro:rplidar prefix="laser"/>

    <xacro:mbot_base_gazebo/>

</robot>

随后再次运行:

roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch

运行成功,显示小车模型(包括车轮)成功!!!
在这里插入图片描述
只是有部分报出警告:

missing <publishOdomTF> default is true
missing <odometrySource> default is 1

主要原因是 gazebo 差速驱动控制器处漏写:

<odometrySource>world</odometrySource> 
<publishOdomTF>1</publishTF>

在这里插入图片描述
重新运行则不会报出警告!!!

2、古月居课程:如何实现ROS机器人自主导航

运行

roslaunch mbot_navigation nav_cloister_demo.launch

报错如下:

[ WARN] [1710125333.011436277, 380.872000000]: Timed out waiting for transform from base_footprint to map to become available before running costmap, tf error: canTransform: target_frame map does not exist.. canTransform returned after 380.872 timeout was 0.1.
[ WARN] [1710125333.011488663, 380.872000000]: No laser scan received (and thus no pose updates have been published) for 380.872000 seconds.  Verify that data is being published on the /scan topic.

rviz中不能显示机器人模型
在这里插入图片描述

经过查证:问题2完全是由问题1引起的,按照问题1解决!!!

解决完上述问题,能够正常运行,但出现警告:

TF_REPEATED_DATA ignoring data with redundant timestamp for frame right_wheel_link (parent base_link) at time 476.692000 according to authority unknown_publisher

运行:

roswtf

如下所示:
在这里插入图片描述
经查找:
已解决(一分钟)TF_REPEATED_DATA ignoring data with redundant timestamp for frame base_footprint at time解决方案
Warning: TF_REPEATED_DATA ignoring data with redundant timestamp for frame odom at time 338.607000 a
步骤1:在 nav_cloister_demo.launch 中加入:

<node pkg="tf" type="static_transform_publisher" name="odom_to_base_footprint" args="0.0 0.0 0.0 0 0 0.0 /odom /base_footprint 10000"/>

步骤2:修改mbot_base_gazebo.xacro文件中

<publishWheelTF>false</publishWheelTF>
<publishWheelJointState>false</publishWheelJointState>
<updateRate>10.0</updateRate>

TIPS:
但是奇怪的是,在 mbot_laser_nav_gazebo.launch 中加入同样的代码:

效果却更好!!!

此外,古月居书中 nav_cloister_demo.launch 的有关部分代码为:

<node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0.0 0.0 0.0 0 0 0.0 /map /odom 100"/>

运行该代码后,小车运行的不是很丝滑,有抖动现象!!!
但是离谱的是,再次在 mbot_laser_nav_gazebo.launch 中加入同样的代码:

<node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0.0 0.0 0.0 0 0 0.0 /map /odom 100"/>

小车运行居然变得很丝滑!!!
具体原因还未找到,有朋友找到踢我一脚!

3、古月居课程:如何实现ROS机器人自主导航

运行:

rosrun mbot_navigation exploring_random.py

报错如下:

Traceback (most recent call last):
  File "/home/yin-roc/catkin_ws_01/src/mbot_navigation/mbot_navigation/scripts/exploring_random.py", line 170, in <module>
    NavTest()  
  File "/home/yin-roc/catkin_ws_01/src/mbot_navigation/mbot_navigation/scripts/exploring_random.py", line 79, in __init__
    sequence = sample(locations, n_locations)  
  File "/usr/lib/python3.8/random.py", line 359, in sample
    raise TypeError("Population must be a sequence or set.  For dicts, use list(d).")
TypeError: Population must be a sequence or set.  For dicts, use list(d).
[INFO] [1710164272.955600, 1537.153000]: Stopping the robot...

4、古月居课程:如何实现ROS机器人自主导航

运行:

roslaunch mbot_navigation nav_cloister_demo.launch

报错:

Failed to create the dwa_local_planner/DWAPlannerROS planner, are you sure it is properly registered and that the containing library is built? Exception: According to the loaded plugin descriptions the class dwa_local_planner/DWAPlannerROS with base class type nav_core::BaseLocalPlanner does not exist. Declared types are  base_local_planner/TrajectoryPlannerROS

解决方法:

sudo apt-get install ros-noetic-dwa-local-planner

5、古月居课程:如何实现ROS机器人自主导航

运行:

roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch

报错:

Spawn service failed. Exiting.

尝试了以下解决方法:
方法1:
修改运行 gazebo 文件中使用到的 world文件,比如我的是 cloister.world 文件:

    <arg name="world_name" value="$(find mbot_gazebo)/worlds/cloister.world"/>

也就是 gazebo 自定义建图时保存的那个 world 文件,进入 ctrl + F 搜索并修改如下代码:

      <sim_time>0</sim_time>

但是虽然能够正常打开 gazebo 场景,但是运行代码时却发现原来的导航效果变差!!!
故寻求另外的解决方法。

但再次运行时,已无此错误。建议重新运行一下。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值