目录
0 前言
1 下载编译
1.1 下载
1.2 编译
2 从点云数据包创建栅格地图
2.1 ImportError: cannot import name perf_counter
ImportError: dynamic module does not define module export function (PyInit__tf2)
2.2 目录不对
2.3 缺包
2.4 NameError: name 'reload' is not defined
2.5 运行效果
0 前言
github仓地址:https://github.com/lukovicaleksa/grid-mapping-in-ROS
grid-mapping-in-ROS用python写的,用cmake编译配置了ros接口
本次使用环境:ubuntu18.04,python2.7
1 下载编译 1.1 下载mkdir -p grid_mapping_in_ros_ws/src
cd grid_mapping_in_ros_ws/src
git clone https://github.com/lukovicaleksa/grid-mapping-in-ROS.git
1.2 编译
到工作空间目录下grid_mapping_in_ros_ws。
catkin_make
因为是python文件,一般编译不会报错
2 从点云数据包创建栅格地图python文件地址:/home/meng/Desktop/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/scripts/create_from_rosbag.py
cd /home/meng/Desktop/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/scripts
python create_from_rosbag.py
下面按顺序记录报错及解决办法
2.1 ImportError: cannot import name perf_counter报错原因:python2.7(ubuntu16和ubuntu18自带的python版本)的time这个模块没有perf_counter这个函数。
解决办法:用time.clock()函数替换time.perf_counter()函数;具体两个函数区别,大家可以查一查
#注:time.clock()这个函数好像在python3.4之后被弃用了
替换create_from_rosbag.py文件对应位置如下:
# from time import perf_counter 8行
from time import time
# Init time 75行
t_start = time()
# t_start = perf_counter()
t_step = time() #190多行
# t_step = perf_counter()
------------------------------------------------------------------------------------------------------------------------
!!!此外 python3.6、python3.7版本的time模块会有这个perf_counter()函数,但这里不要替换python版本;我试着替换为python3.7版本,这个报错没有了,但后面因为需要使用ros,而ros与python2.7版本紧密结合,会让系统出现多个python版本,引发下面的错误
ImportError: dynamic module does not define module export function (PyInit__tf2)--报错原因是系统出现了多个python版本
Failed to load Python extension for LZ4 support. LZ4 compression will not be available.
Traceback (most recent call last):
File "create_from_rosbag.py", line 25, in
from utils import *
File "/home/meng/ideas/auto_resolution_map/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/scripts/utils.py", line 5, in
from tf.transformations import euler_from_quaternion, quaternion_from_euler
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)
在下面博客得到系统有多个版本这个信息
https://blog.csdn.net/pangweijian/article/details/104915171
------------------------------------------------------------------------------------------------------------------------
2.2 目录不对修改目录为自己的目录,示例如下:
# SCRIPTS_PATH = '/home/maestro/catkin_ws/src/grid_mapping/scripts'
# BAG_FILE_PATH = '/home/maestro/catkin_ws/src/grid_mapping/bagfiles'
# MAPS_PATH = '/home/maestro/catkin_ws/src/grid_mapping/maps'
SCRIPTS_PATH = '/home/meng/Desktop/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/scripts'
BAG_FILE_PATH = '/home/meng/Desktop/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/bagfiles'
MAPS_PATH = '/home/meng/Desktop/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/maps'
2.3 缺包
见python(4):ModuleNotFoundError: No module named ‘*‘_biter0088的博客-CSDN博客
的1 rosbag相关
2.4 NameError: name 'reload' is not defined如果遇到这个错误,修改这个报错里面最后一个文件,修改参考如下:
meng@meng:~/ideas/auto_resolution_map/grid_mapping_in_ros_ws/src/grid-mapping-in-ROS/scripts$ python create_from_rosbag.py
Traceback (most recent call last):
File "create_from_rosbag.py", line 3, in
import rospy
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in
from .client import spin, myargv, init_node, \
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 52, in
import roslib
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/__init__.py", line 53, in
import roslib.stacks # noqa: F401, I100
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/stacks.py", line 45, in
import roslib.packages
File "/opt/ros/melodic/lib/python2.7/dist-packages/roslib/packages.py", line 44, in
reload(sys)
NameError: name 'reload' is not defined
sudo gedit /opt/ros/melodic/lib/python2.7/dist-packages/roslib/packages.py
注释掉原来的import(sys),加上python2.x对应的import sys的方式即可
####hxz python 2.x
# -*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
####hxz
import os
import stat
#import sys #hxz
from subprocess import PIPE
from subprocess import Popen
参考链接:https://blog.csdn.net/lxw1844912514/article/details/100029431
2.5 运行效果欢迎分享,转载请注明来源:内存溢出
评论列表(0条)