说明:过程中参照了其他大神的文章,相关链接全部汇总在我上一篇这里就不一一贴出了(如有不妥请联系)
参考文章网址汇总
小白刚刚接触,如有错误请不吝指教!感谢!
Hector-slam
安装Hokuyo雷达驱动
在hector_ws工作空间内建立文件夹src
从github上clone驱动所需包driver_common和hokuyo_node:
cd ~/catkin_ws/src
git clone https://github.com/ros-drivers/driver_common.git
cd ..
catkin_make
cd src
git clone https://github.com/ros-drivers/hokuyo_node.git
cd ..
catkin_make
先driver_common再hokuyo_node不然就失败了…我也不知道为什么…
安装Hector_slam算法包
系统命令:
$ sudo apt-get installros-kinetic-hector-slam //安装hector_slam
但失败…据说是因为kinetic并未提供此种下载方法
故只能从github上进行下载:
cd ~/hector_ws/src
git clone http://github.com/tu-darmstadt-ros-pkg/hector_slam.git
catkin_make
一定要记得设置路径:
source ~/hector_ws/devel/setup.bash
修改要运行的launch文件
编写接收scan topic的hector_slam launch文件–
tutorial.launch:
<launch>
<include file="$(find hector_mapping)/launch/mapping_default.launch">
<arg name="base_frame" value="base_frame"/>
<arg name="odom_frame" value="base_frame"/> //要把odom值换成base_frame,这样就不需要odemetry,不然会报错
</include>
<include file="$(find hector_geotiff)/launch/geotiff_mapper.launch">
<arg name="trajectory_source_frame_name" value="base_frame"/>
</include>
<node pkg="tf" type="static_transform_publisher" name="base_frame_to_laser_broadcaster" args="0 0 0 0 0 0 base_frame laser 100"/>
<node pkg="rviz" type="rviz" name="rviz"
args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/>
</launch>
编译完成后就可以运行了
运行
首先:
roscore
打开另一个终端:
source ~/hector_ws/devel/setup.bash
rosrun hokuyo_node hokuyo_node //启动hokuyo节点
如果报错,可能是串口权限没有打开,输入以下指令打开串口:
sudo chmod a+rw /dev/ttyACM0
再进行节点启动
打开另一个终端,启动hector_slam:
source ~/hector_ws/devel/setup.bash
roslaunch hector_slam_launch tutorial.launch
启动后会自动打开rviz软件窗口界面,有图像生成,移动激光雷达,即可逐渐获得地图。
但是!!!!!!!!!!稍微一动,就报错移动too large…不管小不小心都会混乱…体验真的不好…难用…极其
最后一步,建模完成后,保存地图图片:
rosrun map_server map_saver
会自动在home目录下保存一个名为“map.pgm”的文件。
最终图片
我太菜了,手抖删了好的图片,只剩下这一张断腿的了…
Gmapping
安装Hokuyo雷达驱动
安装所需包
在工作空间目录下载gmapping和laser_scan_matcher以及依赖csm的源码包:
cd ~/gmap_ws/src
git clonehttps://github.com/ros-perception/slam_gmapping.git
git clone https://github.com/ccny-ros-pkg/scan_tools.git //可以删除laser_scan_matcher之外的其他包
git clone https://github.com/AndreaCensi/csm.git
cd ..
catkin_make
添加修改所需文件
改写运行的scan_tools/laser_scan_matcher/demo/demo_gmapping.launch文件:
//删去读取bag的语句
<launch>
#### publish an example base_link -> laser transform ###########
<node pkg="tf" type="static_transform_publisher" name="base_link_to_laser"
args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /laser 40" />
#### start rviz ################################################
<node pkg="rviz" type="rviz" name="rviz"
args="-d $(find laser_scan_matcher)/demo/demo_gmapping.rviz"/>
#### start the laser scan_matcher ##############################
<node pkg="laser_scan_matcher" type="laser_scan_matcher_node"
name="laser_scan_matcher_node" output="screen">
<param name="fixed_frame" value = "odom"/>
<param name="max_iterations" value="10"/>
#####-----------------增加--------------------######
<param name="base_frame" value="base_link"/>
<param name="use_odom" value="false"/>
<param name="publy_pose" value="true"/>
<param name="publy_tf" value="true"/>
#####-----------------增加--------------------######
</node>
#### start gmapping ############################################
<node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
<param name="map_udpate_interval" value="1.0"/>
<param name="maxUrange" value="5.0"/>
<param name="sigma" value="0.1"/>
<param name="kernelSize" value="1"/>
<param name="lstep" value="0.15"/>
<param name="astep" value="0.15"/>
<param name="iterations" value="1"/>
<param name="lsigma" value="0.1"/>
<param name="ogain" value="3.0"/>
<param name="lskip" value="1"/>
<param name="srr" value="0.1"/>
<param name="srt" value="0.2"/>
<param name="str" value="0.1"/>
<param name="stt" value="0.2"/>
<param name="linearUpdate" value="1.0"/>
<param name="angularUpdate" value="0.5"/>
<param name="temporalUpdate" value="0.4"/>
<param name="resampleThreshold" value="0.5"/>
<param name="particles" value="10"/>
<param name="xmin" value="-5.0"/>
<param name="ymin" value="-5.0"/>
<param name="xmax" value="5.0"/>
<param name="ymax" value="5.0"/>
<param name="delta" value="0.02"/>
<param name="llsamplerange" value="0.01"/>
<param name="llsamplestep" value="0.05"/>
<param name="lasamplerange" value="0.05"/>
<param name="lasamplestep" value="0.05"/>
</node>
</launch>
改写hokuyo_node/hokuyo_test.launch文件:
<launch>
<node name="hokuyo" pkg="hokuyo_node" type="hokuyo_node" respawn="false" output="screen">
<!-- Starts up faster, but timestamps will be inaccurate. -->
<param name="calibrate_time" type="bool" value="false"/>
<!-- Set the port to connect to here -->
<param name="port" type="string" value="/dev/ttyACM0"/>
<param name="frame_id" type="string" value="laser"/> //确定此处正确
<param name="intensity" type="bool" value="false"/>
</node>
<!--
<node name="rviz" pkg="rviz" type="rviz" respawn="false" output="screen" args="-d $(find hokuyo_node)/hokuyo_test.vcg"/>
-->
</launch>
新建运行所需的slam_gmapping/gmapping/launch/gmapping.launch文件,并添加base_link到laser_scan的静态坐标变换:
<launch>
<arg name="scan_topic" default="scan" />
<arg name="base_frame" default="base_link"/>
<arg name="odom_frame" default="odom"/>
<node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
<param name="base_frame" value="$(arg base_frame)"/>
<param name="odom_frame" value="$(arg odom_frame)"/>
<param name="map_update_interval" value="1"/>
<param name="maxUrange" value="4.0"/>
<param name="maxRange" value="5.0"/>
<param name="sigma" value="0.05"/>
<param name="kernelSize" value="3"/>
<!-- 机器人移动的初始值(距离) -->
<param name="lstep" value="0.05"/>
<!-- 机器人移动的初始值(角度) -->
<param name="astep" value="0.05"/>
<!-- ICP -->
<param name="iterations" value="5"/>
<param name="lsigma" value="0.075"/>
<param name="ogain" value="3.0"/>
<param name="lskip" value="0"/>
<!-- 重要 -->
<param name="minimumScore" value="200"/>
<param name="srr" value="0.01"/>
<param name="srt" value="0.02"/>
<param name="str" value="0.01"/>
<param name="stt" value="0.02"/>
<param name="linearUpdate" value="0.05"/>
<param name="angularUpdate" value="0.0436"/>
<param name="temporalUpdate" value="-1.0"/>
<param name="resampleThreshold" value="0.5"/>
<!-- 重要(粒子数) -->
<param name="particles" value="60"/>
<!--
<param name="xmin" value="-50.0"/>
<param name="ymin" value="-50.0"/>
<param name="xmax" value="50.0"/>
<param name="ymax" value="50.0"/>
make the starting size small for the benefit of the Android client's memory...
-->
<param name="xmin" value="-1.0"/>
<param name="ymin" value="-1.0"/>
<param name="xmax" value="1.0"/>
<param name="ymax" value="1.0"/>
<param name="delta" value="0.05"/>
<param name="llsamplerange" value="0.01"/>
<param name="llsamplestep" value="0.01"/>
<param name="lasamplerange" value="0.005"/>
<param name="lasamplestep" value="0.005"/>
<remap from="scan" to="$(arg scan_topic)"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="base_frame_to_laser_broadcaster" args="0 0 0 0 0 0 base_frame laser 100"/>
</launch>
运行
首先:
roscore
source ~/hector_ws/devel/setup.bash
rosrun hokuyo_node hokuyo_node //启动hokuyo节点
节点正常打开后,roslaunch改写的demo_gmapping.launch文件,自动弹出rviz界面,看到地图开始构建。
但出现了虚拟里程计odom,应该是因为有了依赖的csm算法源码包??感觉还需要进一步进行确认。Gmapping明显感觉上比Hector_slam更稳更好用一些,舒服很多啊…文件参数虽然搞出来了个大概,但还是有点懵啊…
最终图片
哦呼,又是一张不完整的图诶
Cartographer
安装Hokuyo雷达驱动
安装所需包
首先安装所有依赖项:
# Install the required libraries that are available as debs.
sudo apt-get update
sudo apt-get install -y \
cmake \
g++ \
git \
google-mock \
libboost-all-dev \
libeigen3-dev \
libgflags-dev \
libgoogle-glog-dev \
liblua5.2-dev \
libprotobuf-dev \
libsuitesparse-dev \
libwebp-dev \
ninja-build \
protobuf-compiler \
python-sphinx \
ros-kinetic-tf2-eigen \
libatlas-base-dev \
libsuitesparse-dev \
liblapack-dev
安装ceres solver在主目录下,从github:
git clone https://github.com/hitcm/ceres-solver-1.11.0.git
cd ceres-solver-1.11.0
mkdir build
cd build
cmake .. -G Ninja
ninja
ninja test
sudo ninja install
安装cartographer在主目录下,从github:
git clone https://github.com/hitcm/cartographer.git
cd cartographer
mkdir build
cd build
cmake .. -G Ninja
ninja
ninja test
sudo ninja install
安装cartographer_ros在工作空间src文件夹下:
# 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
# 下载到catkin_ws下面的src文件夹下面
cd src
git clone https://github.com/hitcm/cartographer_ros.git
# 然后到catkin_ws下面运行catkin_make安装
cd
cd catkin_ws
catkin_make
source ./devel/setup.bash
-
将ROS环境变量添加到bash会话中(自动配置好):
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc source ~/.bashrc
创建相关文件
创建carto_ws/src/cartographer_ros/cartographer_ros/launch/demo_hokuyo.launch:
<launch>
<param name="/use_sim_time" value="false" />
<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">
</node>
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_hokuyo.rviz" />
</launch>
创建carto_ws/src/cartographer_ros/cartographer_ros/configuration_files/demo_hokuyo.lua:
include "map_builder.lua"
options = {
map_builder = MAP_BUILDER,
map_frame = "map",
tracking_frame = "laser",
published_frame = "laser",
odom_frame = "odom",
provide_odom_frame = true,
use_odometry_data = false,
use_constant_odometry_variance = false,
constant_odometry_translational_variance = 0.,
constant_odometry_rotational_variance = 0.,
use_horizontal_laser = true,
use_horizontal_multi_echo_laser = false,
horizontal_laser_min_range = 0.3,
horizontal_laser_max_range = 30.,
horizontal_laser_missing_echo_ray_length = 1.,
num_lasers_3d = 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.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
SPARSE_POSE_GRAPH.optimization_problem.huber_scale = 1e2
return options
创建carto_ws/src/cartographer_ros/cartographer_ros/comfiguration_files/demo_hokuyo.rviz:
Panels:
- Class: rviz/Displays
Help Height: 78
Name: Displays
Property Tree Widget:
Expanded:
- /Submaps1
- /PointCloud21
Splitter Ratio: 0.600671
Tree Height: 821
- Class: rviz/Selection
Name: Selection
- Class: rviz/Tool Properties
Expanded:
- /2D Pose Estimate1
- /2D Nav Goal1
- /Publish Point1
Name: Tool Properties
Splitter Ratio: 0.588679
- Class: rviz/Views
Expanded:
- /Current View1
Name: Views
Splitter Ratio: 0.5
- Class: rviz/Time
Experimental: false
Name: Time
SyncMode: 0
SyncSource: PointCloud2
Visualization Manager:
Class: ""
Displays:
- Alpha: 0.5
Cell Size: 1
Class: rviz/Grid
Color: 160; 160; 164
Enabled: true
Line Style:
Line Width: 0.03
Value: Lines
Name: Grid
Normal Cell Count: 0
Offset:
X: 0
Y: 0
Z: 0
Plane: XY
Plane Cell Count: 100
Reference Frame: <Fixed Frame>
Value: true
- Class: rviz/TF
Enabled: true
Frame Timeout: 15
Frames:
All Enabled: true
base_link:
Value: true
horizontal_laser_link:
Value: true
imu_link:
Value: true
map:
Value: true
odom:
Value: true
vertical_laser_link:
Value: true
Marker Scale: 1
Name: TF
Show Arrows: true
Show Axes: true
Show Names: true
Tree:
map:
odom:
base_link:
horizontal_laser_link:
{}
imu_link:
{}
vertical_laser_link:
{}
Update Interval: 0
Value: true
- Alpha: 1
Class: rviz/RobotModel
Collision Enabled: false
Enabled: true
Links:
All Links Enabled: true
Expand Joint Details: false
Expand Link Details: false
Expand Tree: false
Link Tree Style: Links in Alphabetic Order
base_link:
Alpha: 1
Show Axes: false
Show Trail: false
horizontal_laser_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
imu_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
vertical_laser_link:
Alpha: 1
Show Axes: false
Show Trail: false
Value: true
Name: RobotModel
Robot Description: robot_description
TF Prefix: ""
Update Interval: 0
Value: true
Visual Enabled: true
- Class: Submaps
Enabled: true
Map frame: map
Name: Submaps
Submap query service: /submap_query
Topic: /submap_list
Tracking frame: base_link
Unreliable: false
Value: true
- Alpha: 1
Autocompute Intensity Bounds: true
Autocompute Value Bounds:
Max Value: 10
Min Value: -10
Value: true
Axis: Z
Channel Name: intensity
Class: rviz/PointCloud2
Color: 0; 255; 0
Color Transformer: FlatColor
Decay Time: 0
Enabled: true
Invert Rainbow: false
Max Color: 255; 255; 255
Max Intensity: 4096
Min Color: 0; 0; 0
Min Intensity: 0
Name: PointCloud2
Position Transformer: XYZ
Queue Size: 10
Selectable: true
Size (Pixels): 3
Size (m): 0.05
Style: Flat Squares
Topic: /scan_matched_points2
Unreliable: false
Use Fixed Frame: true
Use rainbow: true
Value: true
Enabled: true
Global Options:
Background Color: 100; 100; 100
Fixed Frame: map
Frame
运行
roscore
rosrun hokuyo_node hokuyo_node
roslaunch cartographer_ros demo_hokuyo.launch
然后移动激光建图,得到地图。保存。
最终图片
虽然好像建图亭稳定,但是前期配置真的很头疼啊,N次下载不成功编译失败,被墙不能在官方地址下载github包也可能有错误,