解决ROS默认支持 python2,不支持 python3问题
由于 ROS 默认支持 python2,不支持 python3,需要编译 ROS python3 开发环境,同时需要 编译 CV_Bridge,ROS 在进行图像传输时,通过这个包来实现,可以将 opencv 数据进行转化完成传输
mkdir -p ~/project_ws/src
cd ~/project_ws/src
cd ../
catkin init
cd src
git clone -b noetic https://github.com/ros-perception/vision_opencv.git
#将 CV_Bridge 下的 CMakeLists 中的 Python37 改成 Python3
创建 ROS 功能包
catkin create pkg test_ros --catkin-deps std_msgs rospy roscpp # catkin 和 catkin_make 不能混用
catkin 配置
# 指令一:
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3
-DPYTHON_INCLUDE_DIR=/usr/include/python3.6m
-DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/libpython3.6m.so
# 指令二:
catkin config --install(optional) # catkin config # 没有特别需求直接使用 catkin config
catkin 编译
catkin build
source ~/project_ws/devel/setup.bash
source ~/.bashrc
#这样一来,test_ros功能报下的.py文件就会使用python3了