摘要

这篇文章用于记录ROS使用中遇到的一些问题,仅供个人学习参考,因参考引用较多且零碎,有未标明之处请指出,望见谅。
注:ROS对Python3的支持并不完善,尽量使用Python2.

RLException: Invalid roslaunch XML syntax

详细报错日志:
RLException: Invalid roslaunch XML syntax: not well-formed (invalid token): line 1, column 1
The traceback for the exception was written to the log file

注意命令与文件程序对应
roslaunch 启动 .launch头文件
rosrun 运行 .py .cpp 程序以及可执行文件

Resource not found

Resource not found: kinova-ros
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/home/xia/catkin_ws/src
ROS path [2]=/opt/ros/melodic/share
The traceback for the exception was written to the log file
在这里插入图片描述

原因
1.没有source,需要catkin_make后source devel/setip.bash
2.找不到功能包,find 参数应为包含launch文件的功能包(只含有一个cmakelist的功能包)
在这里插入图片描述上面的路径不是包含要启动launch文件的功能包,报错,虽然该路径下可以找到文件launch文件,但find后 为 功能包名称,而非绝对路径

正确格式<include file="$(find flie_pkg_name)/launch/xx.launch">
3. include 包含的launch文件 ,需要在同一个综合功能包中
在这里插入图片描述

Unable to launch

RLException: Unable to launch [j2_gazebo_model-1].
If it is a script, you may be missing a ‘#!’ declaration at the top.
The traceback for the exception was written to the log file
在这里插入图片描述

解决:
可能是launch内部格式、参数不对
例如,使用node方法 启动 其他launch文件,正确应该用include方法 启动其他launch文件

The kinematics plugin (arm) failed to load

roslaunch j2n6s200_moveit_config demo.launch
在这里插入图片描述 解决:sudo apt-get install ros-melodic-trac-ik-kinematics-plugin
注意版本

Invalid roslaunch XML syntax

在这里插入图片描述通常是,launch文件的格式不对,或者引用launch文件的名称路径错误

ROSInitException: time is not initialized

需在执行程序(实例化)之前要先init_node

CMake Error // Invoking “make cmake_check_build_system” failed

发生这种报错的一些情况是,功能包下的CMakeLists文件中的问题,可能是缺少编译运行的依赖、拼写错误(这种还挺常发生)等等
不过终端都有报错信息,根据报错的日志信息检查配置文件修正即可。

ERROR: Unable to load type [xxx]

自定义消息或者服务信息,调用时出现错误:

ERROR: Unable to load type [plumbing_server/AddInts].
Have you typed 'make' in [plumbing_server]?

可能的原因是当前使用的终端的工作环境没有更新导致无法找到自定义的消息。
执行更新终端的工作环境:

source ./devel/setup.bash

https://blog.csdn.net/u011573853/article/details/103949737

ModuleNotFoundError: No module named ‘xxx’

场景:
我在自己的工作空间下的一个功能包demo01_action里写一个tools.py
在这里插入图片描述
内容比较简单,就一个常量:

#! /usr/bin/env python3
num = 1000

建个一个功能包 test_head_src,写个一个py程序 test_import.py
在这里插入图片描述
内容就使引用tools.py里的num常量

#! /usr/bin/env python3
from rospy.client import spin
from std_msgs.msg import String
import rospy
import os
import sys

path = os.path.abspath(".")
sys.path.insert(0,path + "/src/demo01_action/scripts")
import tools

if __name__=="__main__":

    rospy.init_node("test_import")
    rospy.loginfo("num=%d",tools.num)
    path = os.path.abspath(".")
    rospy.loginfo("%s",path)
...//省略

然后终端运行:

rosrun test_headpy use_tools.py

导包的路径没什么问题,可以正常运行。
在这里插入图片描述

然后再新建一个功能包 launch_basic,在里面新建一个launch文件启动use_tools.py

运行start_turtle.launch文件,roslaunch launch_basic start_turtle.launch
出错:ModuleNotFoundError: No module named ‘tools’
在这里插入图片描述
原因出在use_tools.py里这部分。

path = os.path.abspath(".")
sys.path.insert(0,path + "/src/demo01_action/scripts")
import tools

os.path.abspath(“.”) 是返回当前工作路径的绝对路径
可以测试:

使用rosrun运行 ~/mydemo01_ws$ rosrun test_headpy use_tools.py
在这里插入图片描述
返回的工作路径为:
即该文件运行在工作空间下
sys.path.insert(0,path + “/src/demo01_action/scripts”)就等/home/xia/mydemo01_ws/src/demo01_action/scripts,则能正确导入tools.py

将use_tools.py文件修改,先不使用tools.py,仅仅查看工作路径:
在这里插入图片描述
返回的工作路径为/home/xia/.ros,使用sys.path.insert(0,path + “/src/demo01_action/scripts”)找不到tools.py的正确路径,就会出先ModuleNotFoundError: No module named 'tools’的错误。

ubuntu20 安装moveit出错:无法定位软件包

使用sudo apt-get install ros-noetic-moveit安装moveit报错

正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
E: 无法定位软件包 ros-noetic-moveit

解决:
如果标准 ROS 存储库中(尚未)提供上游包,或者如果您在这些包中遇到任何构建错误,请尝试从 ROS 测试存储库中获取最新的候选版本。

sudo sh -c 'echo "deb http://packages.ros.org/ros-testing/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt update

sudo apt-get install ros-noetic-moveit #安装moveit
sudo apt-get install ros-noetic-moveit-resources #安装资源文件
source /opt/ros/noetic/setup.bash

启动

roslaunch moveit_setup_assistant setup_assistant.launch

参考自moveit官网

gazebo仿真:Could not load controller 'joint_state_controller‘ 'arm_controller’ ‘joint_positio_controller’…

启动gezebo仿真出现很多关于控制器的报错,gezebo中的模型倒塌
需要根据报错提示信息安装控制器

$ sudo apt-get install ros-$version$-joint-state-controller

$ sudo apt-get install ros-$version$-effort-controllers

$ sudo apt-get install ros-$version$-position-controllers 

$ sudo apt-get install ros-$version$-joint-trajectory-controller

其中 v e r s i o n version version为对应的ros版本。

.launch: 行 1: 未预期的符号“newline”附近有语法错误

错误:使用了rosrun启动launch文件
roslaunch启动launch文件
rosrun启动package文件(程序)

Failed to fetch current robot state

在ROS中使用moveit提供得API中得getCurrentPose()等函数获取机械臂状态时,发生错误
报错日志:

[ INFO] [1638930158.344021937]: Didn't receive robot state (joint angles) with recent timestamp within 1 seconds.
Check clock synchronization if your are running ROS across multiple machines!
[ERROR] [1638930158.344101317]: Failed to fetch current robot state

可能原因:
1.机械臂没有发布robot states或机械臂发布状态话题不是getCurrentPose()等函数的回调函数中订阅的话题。
解决:需要创建一个节点发布topic /joint_states,或将机械臂原本发布状态的话题重映射为 /joint_states。
如在kinova机械臂(j2n6s200)中,已经存在发布状态的topic,需将其重映射:

rosrun topic_tools relay /j2n6s200_driver/out/joint_state joint_states

参考:
https://blog.csdn.net/bbtang5568/article/details/112419250

https://github.com/ros-planning/moveit/issues/1187

https://answers.ros.org/question/324123/cant-get-robot-arms-current-pose-with-a-error-failed-to-fetch-current-robot-state/
2.没有获得函数之前对其进行初始化以及启动spinner.start()
C++:

ros::AsyncSpinner spinner(1);
spinner.start();
#执行获取函数
geometry_msgs::PoseStamped current_state = move_group.getCurrentPose("j2n6s200_link_3");

python:

from moveit_commander import roscpp_initialize
import sys
...
moveit_commander.roscpp_initialize(sys.argv)

参考:
https://blog.csdn.net/u012424737/article/details/106538277

正在连接 github.com (github.com)|20.205.243.166|:443… 失败:拒绝连接。

在使用安装脚本安装ompl时,发生:正在连接 github.com (github.com)|20.205.243.166|:443… 失败:拒绝连接。
其他解决方法已经有很多,若不成功可以尝试换成手机热点连接。

清除ros log缓存

rosclean check
rosclean purge

tf_conversions

tf_conversions包含了坐标变换计算所需要的函数
注:确定坐标轴xyz方向,面朝前为x正,右手为y正,上方为z正。

矩阵转四元数、四元数转矩阵:

#设置旋转矩阵
Matrix1 = (np.array([[1,0,0,0],[0,0,1,0],[0,-1,0,0],[0,0,0,1]])).T
#矩阵转四元数(wzyx)
quat1 = tf_conversions.transformations.quaternion_from_matrix(Matrix1)
#四元数转矩阵  
mat1 = tf_conversions.transformations.quaternion_matrix(quat1)     

欧拉角、矩阵转换:

#欧拉角
rpy1=[-3.870207123932865e-05, 4.404773198423996e-09, -1.5708068444806238]
#欧拉角转矩阵
mat1=tf_conversions.transformations.euler_matrix(float(rpy1[0]),float(rpy1[1]),float(rpy1[2]),axes='sxyz')
print(mat1)
#矩阵转欧拉角
rpy2=tf_conversions.transformations.euler_from_matrix(mat1)
print(rpy2)

欧拉角、四元数转换:

#欧拉角
rpy1=[-3.870207123932865e-05, 4.404773198423996e-09, -1.5708068444806238]
#欧拉角转四元数
quat1=tf_conversions.transformations.quaternion_from_euler(float(rpy1[0]),float(rpy1[1]),float(rpy1[2]),axes='sxyz')
print(quat1)
#四元数转欧拉角
rpy2=tf_conversions.transformations.euler_from_quaternion(quat1)
print(rpy2)
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐