Skip to main content

ROS探索 常见问题

1、“python\r” 问题

运行py脚本的时候有时候会出现问题:


使用dos2unix工具

dos2unix 文件名

/usr/bin/env: ‘python\r’: No such file or directory 

网上说在python脚本中

#!/usr/bin/env python  

在ubuntu会变成

#!/usr/bin/env python\r  

而 \r 会被 shell 当成参数

所以出现: /usr/bin/env: ‘python\r’: No such file or directory

解决方法:

vi 此文件

输入: set ff=unix

再输入: wq

运行成功。

2、虚拟机调用本机USB摄像头

VMware需要先将设备连接到虚拟机。 运行如下命令查看摄像头设备

ls /dev/video*

在这里插入图片描述

一般笔记本摄像头的设备号为 video0

其次还需要将VMware设备兼容改为USB3.0 不然会出现错误 在这里插入图片描述

3、虚拟机中运行ROS usb_cam 包

下载

git clone https://github.com/ros-drivers/usb_cam.git

编译 运行

roslaunch usb_cam usb_cam-test.launch

应该就能看到图像

4、Cartographer ROS 国内安装问题

系统要求

Cartographer ROS 支持四种版本的ROS Indigo Kinetic Lunar Melodic

Cartographer总是安装失败,原因是有一个地方需要从google drive下载 以下来源于官方文档 https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html

编译 & 安装

编译Cartographer ROS,我们推荐使用 wstool和rosdep,为了更快的编译,我们同样推荐使用Ninja

sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build

创建一个新的cartographer_ros工作空间名为 ‘catkin_ws’.

mkdir catkin_ws
cd catkin_ws
wstool init src
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
sudo gedit ~/catkin_ws/src/.rosinstall #这里更改
wstool update -t src

!!注意:更改ceres-solver的uri为 uri: https://github.com/ceres-solver/ceres-solver.git 在这里插入图片描述

安装 cartographer_ros’ 的依赖 (proto3 and deb packages). 命令 ‘sudo rosdep init’ 将会打印一个错误如果你之前已经安装了这些文件. 这个错误可以忽略

src/cartographer/scripts/install_proto3.sh
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y

编译、安装

catkin_make_isolated --install --use-ninja

5、Cartographer lua 脚本报错

在使用古月的mrobot的cartographer例程的时候会报错

attempt to index global 'SPARSE_POSE_GRAPH' (a nil value)ailed: status == 0 (2 vs. 0) 

原因是新版本的cartographer的脚本写法和之前不一样,参照 cartographer_ros/cartographer_ros/configuration_files/revo_lds.lua的写法 改进rplidar.lua

include "map_builder.lua"
include "trajectory_builder.lua"

options = {
map_builder = MAP_BUILDER,
trajectory_builder = TRAJECTORY_BUILDER,
map_frame = "map",
tracking_frame = "laser_link",
published_frame = "laser_link",
odom_frame = "odom",
provide_odom_frame = true,
publish_frame_projected_to_2d = false,
use_odometry = false,
use_nav_sat = false,
use_landmarks = false,
num_laser_scans = 1,
num_multi_echo_laser_scans = 0,
num_subdivisions_per_laser_scan = 1,
num_point_clouds = 0,
lookup_transform_timeout_sec = 0.2,
submap_publish_period_sec = 0.3,
pose_publish_period_sec = 5e-3,
trajectory_publish_period_sec = 30e-3,
rangefinder_sampling_ratio = 1.,
odometry_sampling_ratio = 1.,
fixed_frame_pose_sampling_ratio = 1.,
imu_sampling_ratio = 1.,
landmarks_sampling_ratio = 1.,
}

MAP_BUILDER.use_trajectory_builder_2d = true

TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1

POSE_GRAPH.optimization_problem.huber_scale = 1e2
POSE_GRAPH.optimize_every_n_nodes = 35
POSE_GRAPH.constraint_builder.min_score = 0.65

return options

使用 POSE_GRAPH 替换 SPARSE_POSE_GRAPH 在option中增加use_nav_sat 等配置,再运行就不会报错了。

6、rosdep 一键安装依赖

rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y

7、Gazebo 加载慢

2020.7.21更新: 原地址已经迁移,转移到github上了,国内下载速度异常缓慢,因此我fork一份到gitee上,可以从这里下载 我clone到gitee上的地址:

https://gitee.com/yltzdhbc/gazebo_models

原地址:

https://bitbucket.org/osrf/gazebo_models/downloads

在文件夹主目录下 ctrl+h 切换显示隐藏文件 到 home/.gazebo/ 目录下 新建models文件夹

sudo mkdir ~/.gazebo/models

将所有文件复制到

~/.gazebo/models

即可