太长不看版:本帖记录了问题解决过程中的学习过程,只关心结果的同学请直接跳至问题的解决方案部分
编译报错
1. (.text+0x20)
-
问题: 学习古月居ROS第二章(ROS基础)话题编程时,自己手敲代码编译不通过,报错如下:
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - learning_com -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'learning_com' -- ==> add_subdirectory(learning_com) -- Configuring done -- Generating done -- Build files have been written to: /home/xxx/Study/ROS/2/catkin_ws/build #### #### Running command: "make -j6 -l6" in "/home/xxx/Study/ROS/2/catkin_ws/build" #### Scanning dependencies of target listener [ 25%] Building CXX object learning_com/CMakeFiles/listener.dir/src/listener.cpp.o [ 50%] Linking CXX executable /home/xxx/Study/ROS/2/catkin_ws/devel/lib/learning_com/listener /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status learning_com/CMakeFiles/listener.dir/build.make:113: recipe for target '/home/xxx/Study/ROS/2/catkin_ws/devel/lib/learning_com/listener' failed make[2]: *** [/home/xxx/Study/ROS/2/catkin_ws/devel/lib/learning_com/listener] Error 1 CMakeFiles/Makefile2:557: recipe for target 'learning_com/CMakeFiles/listener.dir/all' failed make[1]: *** [learning_com/CMakeFiles/listener.dir/all] Error 2 Makefile:138: recipe for target 'all' failed make: *** [all] Error 2 Invoking "make -j6 -l6" failed
-
解决方案: 其实问题就是因为Python留下的习惯,在.cpp文件最后一行留了空格,删除空格后编译通过。
roslaunch报错
1. 找不到serial、tf2
-
问题: 学习古月居ROS第四章(机器人仿真)尝试运行视频提供的代码时报错,如下:
started core service [/rosout] process[arbotix-2]: started with pid [15249] process[joint_state_publisher-3]: started with pid [15255] process[robot_state_publisher-4]: started with pid [15256] process[rviz-5]: started with pid [15257] Traceback (most recent call last): File "/home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros-noetic-devel/arbotix_python/bin/arbotix_driver", line 37, in <module> from arbotix_python.diff_controller import DiffController File "/home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros-noetic-devel/arbotix_python/src/arbotix_python/diff_controller.py", line 38, in <module> from tf.broadcaster import TransformBroadcaster File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf/__init__.py", line 28, in <module> from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module> from tf2_py import * File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module> from ._tf2 import * ImportError: dynamic module does not define module export function (PyInit__tf2) [arbotix-2] process has died [pid 15249, exit code 1, cmd /home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros-noetic-devel/arbotix_python/bin/arbotix_driver __name:=arbotix __log:=/home/xxx/.ros/log/ffc963b4-d817-11eb-af38-b42e998b06c6/arbotix-2.log]. log file: /home/xxx/.ros/log/ffc963b4-d817-11eb-af38-b42e998b06c6/arbotix-2*.log ================================================================================REQUIRED process [rviz-5] has died! process has finished cleanly log file: /home/xxx/.ros/log/ffc963b4-d817-11eb-af38-b42e998b06c6/rviz-5*.log Initiating shutdown! ================================================================================ [robot_state_publisher-4] killing on exit [rviz-5] killing on exit [joint_state_publisher-3] killing on exit [rosout-1] killing on exit [master] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done
-
尝试: 尝试了以下方法中的前三个,均未解决:
(1)Dr. 慧珍儿的方法
(2)232hdsjdh的方法
(3)修改python环境 系统环境已顺利修改为python2.7,且在终端中运行python可以正常import tf
,尝试重新编译但依旧报错。
(4)使用python3模块编译 这个方法暂时没敢尝试,因为看到有人说自己的ros在执行后被卸载了,但是我目前认为这个方法可行。
(5)使用python3模块编译,解决tf2的问题 这个介绍的更详细。 -
原因猜测:
(1)首先在python2.7环境下无论是import serial
还是import tf
都完全没问题;
(2)其次,最开始的报错是缺少“serial”等模块,通过pip install
方法一一安装之后报错信息变为了上面图片中的找不到tf。初始报错信息:
started core service [/rosout] process[arbotix-2]: started with pid [14997] process[joint_state_publisher-3]: started with pid [15003] process[robot_state_publisher-4]: started with pid [15004] process[rviz-5]: started with pid [15005] Traceback (most recent call last): File "/home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros-noetic-devel/arbotix_python/bin/arbotix_driver", line 36, in <module> from arbotix_python.arbotix import ArbotiX, ArbotiXException File "/home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros-noetic-devel/arbotix_python/src/arbotix_python/arbotix.py", line 33, in <module> import serial, time, sys, threading ImportError: No module named 'serial' [arbotix-2] process has died [pid 14997, exit code 1, cmd /home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros-noetic-devel/arbotix_python/bin/arbotix_driver __name:=arbotix __log:=/home/xxx/.ros/log/68a73262-d8b8-11eb-af38-b42e998b06c6/arbotix-2.log]. log file: /home/xxx/.ros/log/68a73262-d8b8-11eb-af38-b42e998b06c6/arbotix-2*.log ================================================================================REQUIRED process [rviz-5] has died! process has finished cleanly log file: /home/xxx/.ros/log/68a73262-d8b8-11eb-af38-b42e998b06c6/rviz-5*.log Initiating shutdown! ================================================================================
原本都是在conda的base环境下操作的,之前退出conda环境后报错信息不变,但当采用了上述232hdsjdh和Dr. 慧珍儿的方法后发现报错信息又变为了初始的缺少 “serial”,仔细对比了下操作前后的环境变量(
export | grep ROS
),发现232hdsjdh方法可以将原本在PATH中的conda base环境的python路径(anaconda3/bin
)删除。
(3)由此,推测出现这个问题的原因是roslaunch执行的过程中,从环境变量查找到了其他位置(其他版本)的python路径,从而找不到serial
、tf
等等模块。下面想办法验证和解决。事实证明上面的推测是对的,而且上述方法已经解决了问题,
anaconda3/bin
不出现在环境变量PATH里面的话ROS就会找到系统的python2.7就可以正常运行了。
但是后面用232hdsjdh的方法又不灵了,anaconda3/bin
还是会出现在环境变量里,尝试的方法太多,没来得及及时记录,不记得到底是哪个操作能够成功屏蔽anaconda路径了。 😦 -
解决方案: 问题的核心在于launch文件调用了
arbotix_ros
模块中的python文件。
(1)首先检查下载的arbotix_ros
模块版本是否正确,默认下载的是对应ROS noetic版本的包,而巧就巧在ROS noetic是首个支持python3版本的ROS,所以arbotix_ros
模块里面的python文件时python3版本的。【ps.这也是为什么我上面初次尝试删除掉anaconda的路径后依旧报错的原因】
(2)arbotix_ros
模块版本正确的话roslaunch
会报这个错:
started core service [/rosout] process[arbotix-2]: started with pid [14264] process[joint_state_publisher-3]: started with pid [14271] process[robot_state_publisher-4]: started with pid [14272] process[rviz-5]: started with pid [14273] Traceback (most recent call last): File "/home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros/arbotix_python/bin/arbotix_driver", line 36, in <module> from arbotix_python.arbotix import ArbotiX File "/home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros/arbotix_python/src/arbotix_python/arbotix.py", line 69 print e ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(e)? [arbotix-2] process has died [pid 14264, exit code 1, cmd /home/xxx/Study/ROS/4/catkin_4/src/arbotix_ros/arbotix_python/bin/arbotix_driver __name:=arbotix __log:=/home/xxx/.ros/log/cb83a8a2-d8d6-11eb-aa21-b42e998b06c6/arbotix-2.log]. log file: /home/xxx/.ros/log/cb83a8a2-d8d6-11eb-aa21-b42e998b06c6/arbotix-2*.log
这一看就是python版本的问题,提示你用python3运行了python2的代码,于是检查当前的环境变量:
export | grep PATH
关注
PATH
变量的值:
PATH=/home/xxx/Study/ROS/4/catkin_4/devel/bin:/home/xxx/Navigation/Test/test_crowd_drl_nav_ws/devel/bin:/opt/ros/kinetic/bin:/home/xxx/anaconda3/bin:/home/xxx/anaconda3/condabin:/home/xxx/bin:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda/bin
anaconda的路径赫然在列,而且在系统python路径(
/usr/bin
)的前面,基本验证了前面的猜想。于是可以通过修改PATH变量临时解决这个问题:export PATH=/home/xxx/Study/ROS/4/catkin_4/devel/bin:/home/xxx/Navigation/Test/test_crowd_drl_nav_ws/devel/bin:/opt/ros/kinetic/bin:/home/xxx/bin:/home/xxx/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda/bin
上面这句命令即是将打印出的PATH变量复制下来,删除带有anaconda的路径后直接再赋值给环境变量的PATH,命令中的
xxx
为当前的用户名。【此段需根据自己电脑的终端输出修改,直接复制无效。(不知道还有没有更好的办法可以删除PATH变量内的anaconda路径,还请大佬在评论中提供)】
注意:
export
命令仅在当前终端生效,因此这是一个临时解决的办法。想要“一劳永逸”就要弄清楚系统是如何在source devel/setup.zsh
时找到anaconda的路径的,还请前辈在评论区指点迷津。