系统环境:
64位/ubuntu14 /ros-indogo
一、 在ros中安装hokuyo node:
1)连接激光到虚拟机,打开一个terminal ,下载激光的节点包 # sudo apt-get install ros-indigo-hokuyo-node
2)接下来配置激光节点,首先确保虚拟机菜单中 虚拟机-可移动设备 已经接上URG,然后可以开始配置:
# cd /etc/udev/rules.d
#cd touch 50-laser.rules
#sudo gedit 50-laserr.rules
在文件中添加以下内容: KERNEL="ttyACM[0-9]*" ,MODE="0777"
重启.rules使之生效:
#sudo /etc/init.d/udev restart
检查权限#ls -al /dev/ttyACM0 如果显示 crw-rw 则输入 #sudo chmod a+rw /dev/tty/ACM0 权限应为 crw-rw-rw.....
这样激光就在ros中可以使用啦!接下来下载slam的程序包
二、安装谷歌slam Cartographer_ros
源码安装地址 : https://google-cartographer-ros.readthedocs.io/en/latest/
# Install wstool and rosdep.
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build
# Create a new workspace in 'catkin_ws'.
mkdir catkin_ws
cd catkin_ws
wstool init src
# Merge the cartographer_ros.rosinstall file and fetch code for dependencies.
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src
# Install deb dependencies.
rosdep init
rosdep update #(多试几遍,早晨容易成功)
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
# Build and install.
catkin_make_isolated --install --use-ninja (#这边容易出错)
source install_isolated/setup.bash
值得注意的是,cartographer的包一直在更新,很多人运行Catkin_make_isolated时很容易报错,说找不到ceres库,有人说用VPN或者改IP地址等等,在此贴上几个博客,以供参考 :
http://www.cnblogs.com/wenhust/p/6112845.html
安装成功后,就可以跑激光啦!
三、北洋激光连接谷歌slam
在launch文件夹下新建一个文件demo_hokuyo.launch ,本人建议先拷贝一个其他的demo的launch(这样里面还是彩色的,不然是黑白的),然后再自己改个名字,再在文件中加入以下内容:
<launch>
<param name="/use_sim_time" value="true" />
<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename demo_hokuyo.lua"
output="screen">
<remap from="scan" to="scan" />
</node>
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
</launch>
这其实就是改了 from scan to scan
然后再上一层文件夹中寻找配置文件夹,打开,新建一个demo_hokuyo.lua的文件,写入以下内容:
-- Copyright 2016 The Cartographer Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
include "map_builder.lua"
options = {
map_builder = MAP_BUILDER,
sensor_bridge={
horizontal_laser_min_range=0.,
horizontal_laser_max_range=30.,
horizontal_laser_missing_echo_ray_length=1.,
constant_odometry_translational_variance=0.,
constant_odometry_rotational_variance=0.,
},
map_frame = "map",
tracking_frame = "laser",
published_frame = "laser",
odom_frame = "odom",
provide_odom_frame = true,
use_odometry = false,
use_laser_scan = true,
use_multi_echo_laser_scan = false,
num_point_clouds = 0,
lookup_transform_timeout_sec = 0.2,
submap_publish_period_sec = 0.3,
pose_publish_period_sec = 5e-3,
}
MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.laser_min_range = 0.1
TRAJECTORY_BUILDER_2D.laser_max_range = 30.
TRAJECTORY_BUILDER_2D.laser_missing_echo_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
SPARSE_POSE_GRAPH.optimization_problem.huber_scale = 1e2
return options
(经过比对发现 .rviz文件不用改)
这样就完成啦!重新make 一下,再source一下 ,运行 roslaunch cartographer_ros demo_hokuyo.launch 就可以看到激光建地图啦!
如果要跑bag文件,请参考谷歌原地址。