Ubuntu18.04使用工程与carla0.9.5联合仿真报错
1
File "/home/cg/Auto_driving/src/ros-bridge/carla_ros_bridge/src/carla_ros_bridge/client.py", line 18, in <module>
from carla_ros_bridge.bridge_with_rosbag import CarlaRosBridgeWithBag
File "/home/cg/Auto_driving/src/ros-bridge/carla_ros_bridge/src/carla_ros_bridge/bridge_with_rosbag.py", line 16, in <module>
import rosbag
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/__init__.py", line 33, in <module>
from .bag import Bag, Compression, ROSBagException, ROSBagFormatException, ROSBagUnindexedException
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py", line 53, in <module>
from Cryptodome.Cipher import AES
ModuleNotFoundError: No module named 'Cryptodome'
运行
pip install pycryptodomex -i https://pypi.tuna.tsinghua.edu.cn/simple
2
Traceback (most recent call last):
File "/home/cg/Auto_driving/src/ros-bridge/carla_ackermann_control/src/carla_ackermann_control/carla_ackermann_control_node.py", line 527, in <module>
main()
File "/home/cg/Auto_driving/src/ros-bridge/carla_ackermann_control/src/carla_ackermann_control/carla_ackermann_control_node.py", line 518, in main
controller = CarlaAckermannControl()
File "/home/cg/Auto_driving/src/ros-bridge/carla_ackermann_control/src/carla_ackermann_control/carla_ackermann_control_node.py", line 88, in __init__
lambda: rospy.get_rostime().to_sec() - 0.1)
KeyError: 'simple_pid.PID'
Traceback (most recent call last):
File "/home/cg/Auto_driving/src/ros-bridge/carla_ego_vehicle/src/carla_ego_vehicle/carla_ego_vehicle.py", line 42, in <module>
from agents.navigation.global_route_planner import GlobalRoutePlanner
ModuleNotFoundError: No module named 'agents'
在.bashrc文件中添加
export PYTHONPATH=$PYTHONPATH:/home/cg/carla-0.9.5/PythonAPI/carla/dist/carla-0.9.5-py3.5-linux-x86_64.egg:/home/cg/carla-0.9.5/PythonAPI/carla
注意改成自己的路径
3
ModuleNotFoundError: No module named 'gnupg'
pip install gnupg -i https://pypi.tuna.tsinghua.edu.cn/simple
4
Traceback (most recent call last):
File "/home/cg/Auto_driving/src/ros-bridge/carla_ego_vehicle/src/carla_ego_vehicle/carla_ego_vehicle.py", line 360, in main
ego_vehicle.run()
File "/home/cg/Auto_driving/src/ros-bridge/carla_ego_vehicle/src/carla_ego_vehicle/carla_ego_vehicle.py", line 339, in run
self.world = client.get_world()
RuntimeError: rpc::rpc_error during call in function version
因为手动pip安装了其他carla版本,比如carla-0.9.11,pip卸载就可以:
pip uninstall carla
5
Traceback (most recent call last):
File "/home/cg/Auto_driving/src/ros-bridge/carla_ackermann_control/src/carla_ackermann_control/carla_ackermann_control_node.py", line 527, in <module>
main()
File "/home/cg/Auto_driving/src/ros-bridge/carla_ackermann_control/src/carla_ackermann_control/carla_ackermann_control_node.py", line 518, in main
controller = CarlaAckermannControl()
File "/home/cg/Auto_driving/src/ros-bridge/carla_ackermann_control/src/carla_ackermann_control/carla_ackermann_control_node.py", line 88, in __init__
lambda: rospy.get_rostime().to_sec() - 0.1)
KeyError: 'simple_pid.PID'
simple_pid版本不对,安装
pip install simple_pid==0.2.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
6
Traceback (most recent call last):
File “/opt/ros/melodic/lib/turtle_tf/turtle_tf_broadcaster.py”, line 37, in
import tf
File “/opt/ros/melodic/lib/python2.7/dist-packages/tf/init.py”, line 30, in
from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException
File “/opt/ros/melodic/lib/python2.7/dist-packages/tf2_ros/init.py”, line 38, in
from tf2_py import *
File “/opt/ros/melodic/lib/python2.7/dist-packages/tf2_py/init.py”, line 38, in
from ._tf2 import *
ImportError: dynamic module does not define module export function (PyInit__tf2)9
出现这种问题一般是由于Ros目前只支持Python2,一些主要的功能包如tf2等都是在Python2的环境下运行的,在Python2中导入相关包不会出现问题,但在Python3中会出错。安装:
sudo apt update
sudo apt install python3-catkin-pkg-modules python3-rospkg-modules python3-empy
#准备一个catkin工作空间,因为都叫catkin_ws,我就把它和ros-bridge放同一个目录下了
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws
catkin_make
source devel/setup.bash
wstool init
wstool set -y src/geometry2 --git https://github.com/ros/geometry2 -v 0.6.5
wstool up
rosdep install --from-paths src --ignore-src -y -r
#最后用Python3编译,注意,编译的python环境也得是python3
catkin build --cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
7
Traceback (most recent call last):
File "/opt/anaconda3/envs/autoware/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/opt/anaconda3/envs/autoware/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/bridge.py", line 271, in _synchronous_mode_update
self._update(frame, world_snapshot.timestamp.elapsed_seconds)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/bridge.py", line 312, in _update
self.actor_factory.update_actor_states(frame_id, timestamp)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/actor_factory.py", line 143, in update_actor_states
self.actors[actor_id].update(frame_id, timestamp)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/sensor.py", line 253, in update
self._update_synchronous_sensor(frame, timestamp)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/sensor.py", line 234, in _update_synchronous_sensor
self.sensor_data_updated(carla_sensor_data)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/camera.py", line 121, in sensor_data_updated
img_msg = self.get_ros_image(carla_camera_data)
File "/home/cg/ros_carla/src/carla_ros_bridge/src/carla_ros_bridge/camera.py", line 163, in get_ros_image
img_msg = Camera.cv_bridge.cv2_to_imgmsg(image_data_array, encoding=encoding)
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 259, in cv2_to_imgmsg
if self.cvtype_to_name[self.encoding_to_cvtype2(encoding)] != cv_type:
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
参考:https://blog.csdn.net/qq_41035283/article/details/120887112
就是要注意下载的vision_opencv版本要是melodic的。
总结
ubuntu18.04运行carla比较麻烦,因为默认的python是2.7,包括ros自带的也是python2,所以会遇到一些错误,但是不慌,慢慢学习,解决。还有最好使用conda去创建python3环境,良好习惯。
需要购买代码的可以私。