文章目录
注意,最权威的教程地址!:https://www.jianshu.com/p/5e6b77a2e4ae
TB2仿真
Turtlebot详细教程(indingo)
扫了一遍
Turtlebot与仿真
虽然仿真了大部分,后面多turtlebot没有仿真(因为根据教程的来仿真不来 其是indingo并且kinetic的没有某些东西,要搜kinetic的多turtlebot)以及最后两个demo不成功,倒数第二个跑的乱七八遭,倒数第一个gazibo的world没有出来,一片黑,然后要执行slam功能时候报错没有sklearn,在考虑是否要用anconda,因为py2.7的下sklearn挺麻烦)
SLAM 涉及到的算法
需要了解的东西:
SLAM:经典2D_SLAM算法比较:Hector slam、gmapping、cartographer
hector_slam 很久之前的
slam_karto
cartographer 貌似是现在的state of art
GMapping 貌似没有带回环检测,所以师兄不推荐
navigation
navigation,导航包
navigation介绍: http://wiki.ros.org/navigation
navigation应用:http://wiki.ros.org/navigation/Tutorials/RobotSetup
gmapping
gmapping SLAM建图软件包
gmapping介绍: http://wiki.ros.org/gmapping
gmapping介绍:http://wiki.ros.org/slam_gmapping
gmapping介绍:http://wiki.ros.org/openslam_gmapping?distro=indigo
AMCL
amcl介绍:http://wiki.ros.org/amcl
如果PRlidar端口改变
Error, cannot bind to the specified serial port /dev/rplidar.
https://blog.csdn.net/qq_40157728/article/details/88690223
https://unix.stackexchange.com/questions/437891/error-cannot-bind-to-the-specified-serial-port-dev-ttyusb0-during-boot-using-s
https://answers.ros.org/question/199561/rplidar-driver-installation-problem-on-ubuntu/
TB2base pkg
Ubuntu16.04+kinetic下学习turtlebot2之turtlebot2包的安装及简单测试
https://github.com/turtlebot/turtlebot_simulation.git
not found
changed to https://github.com/turtlebot/turtlebot_simulator.git
两个电脑ssh连接
https://blog.csdn.net/weixin_42056625/article/details/88413981
手柄控制TB2
turtlebot入门-xbox360无线游戏杆控制turtlebot
实验室是罗技手柄
罗技F710无线手柄在ROS下的安装使用:
这里需要注意的是
- 我们首先需要按下手柄中间的logitech这时候匹配了 才会有js0出现
- 注意手柄要选择direct 模式 也就是手柄前侧xd切换按钮那里。
- 出现js0之后使用sudo jstest /dev/input/js0测试,需要按下RT或者LT(手柄后方的防错误按纽)
- 如果发现不行,更换sudo jstest /dev/input/js0 js后面的数字,有时候会更变
然后按照
turtlebot入门-xbox360无线游戏杆控制turtlebot
使用手柄
关闭之前所有打开的终端,重新打开启动roscore
$ roscore
新终端启动turtlebot
$roslaunch turtlebot_bringup minimal.launch
新终端设置设备并启动游戏杆遥控支持
如果出现端口改变 从js0到js4,那么
rosparam set /joystick/dev /dev/input/js4
$rosparam set /joystick/dev /dev/input/js0
$roslaunch turtlebot_teleop logitech.launch
测试使用,按住左边的LB按钮激活游戏杆并移动左遥控杆,Turtlebot应该就有反应。
手柄控制小乌龟
ROS之游戏手柄控制乌龟和机器人
因为发现那个显示屏需要充电,所以先充他个几小时,为了加强自己开发ROS的能力,决定试一试这个手柄控制乌龟,如果之后想再锻炼,可以手柄控制仿真小乌龟
首先创建包的话catkin_create_pkg helloturtle std_msgs roscpp
写好logteleop.cpp名字之后
下面是根据我们的名字改的launch文件
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="sim">
</node>
<node pkg="helloturtle" type="logteleop" name="logteleop" output="screen">
</node>
<!--input axis -->
<param name="axis_linear" value="4" type="int"/>
<param name="axis_angular" value="3" type="int"/>
<!--input vel -->
<param name="vel_linear" value="2" type="double"/>
<param name="vel_angular" value="1.5" type="double"/>
<node respawn="true" pkg="joy" type="joy_node" name="joystick" >
</node>
</launch>
但是就是一直显示找不到
ERROR: cannot launch node of type [helloturtle/logteleop]: can’t locate node [logteleop] in package [helloturtle]
的确是
在rosrun自动补全后发现下面只能看到hello_world_node 明显是之前看教程的时候编译下来的node,而自己的node不存在,我还需要好好看一下ROS编程书
书中需要修改CMakeList.txt我在修改了package.xml and CMakeList.txt之后cm发现
#指定cmake最低版本
project(my_first_ros_pkg)#指定pkg名 需要和package.xmlpkg名相同
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs geometry_msgs sensor_msgs)#添加依赖包
catkin_package( CATKIN_DEPENDS roscpp std_msgs) #catkin构建选项
include_directories( ${catkin_INCLUDE_DIRS})#指定包含目录的选项
#构建之后要创建的可执行文件的选项,生成logteleop可执行文件
add_executable(logteleop src/logteleop.cpp)
#创建特定的可执行文件之前将库和可执行文件进行连接
target_link_libraries(logteleop ${catkin_LIBRARIES})
#构建之后要创建的可执行文件的选项,生成logteleop可执行文件
#创建特定的可执行文件之前将库和可执行文件进行连接
十分重要!
package.xml
<?xml version="1.0"?>
<package format="2">
<name>my_first_ros_pkg</name>
<version>0.0.0</version>
<description>The my_first_ros_pkg package</description>
<maintainer email="asber@todo.todo">asber</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>geometry_msgs</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>
如果出现端口改变 从js0到js4,那么
rosparam set /joystick/dev /dev/input/js4
或者在launch文件中添加
然后就可以动了!!!
真的是千辛万苦 a aaaaaaa。
应该用IDE开发了 Qtcreator ctrl+b构建
Turtlebot入门教程-源码安装turtlebot
在跑到
mkdir ~/kobuki
cd ~/kobuki
wstool init src -j5 https://raw.github.com/yujinrobot/yujin_tools/master/rosinstalls/indigo/kobuki.rosinstall
source ~/rocon/devel/setup.bash
rosdep install --from-paths src -i -y
catkin_make
的时候发现许多报错
/usr/include/gazebo-7/gazebo/msgs/world_modify.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Ple
^
/usr/include/gazebo-7/gazebo/msgs/world_modify.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
…
[ 97%] Linking CXX shared library /home/asber/turtlebot2/kobuki/devel/lib/libkobuki_nodelet.so
[ 97%] Built target kobuki_nodelet
Makefile:138: recipe for target ‘all’ failed
make: *** [all] Error 2
Invoking “make -j4 -l4” failed
网上找不到具体的解决方案
使用二进制安装了
TB2 RplidarA3 cartographer
turtlebot入门教程-cartographer在Turltlebot的应用
在执行rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y的时候报错
cartographer: Cannot locate rosdep definition for [ceres-solver]
按照此处说明
会出现无法下载 ceres-solver 的问题,我们可以修改其下载地址[3]:
1) 修改 /src/.rosinstall 文件
2) 修改 /src/cartographter_ros/cartographter_ros.rosinstall 文件
将两个文件中的 ceres-solver 路径改为从 github 下载
https://github.com/ceres-solver/ceres-solver.git
and I came across a problem:
ninja: build stopped: subcommand failed.
<== Failed to process package 'cartographer':
Command '['/home/asber/turtlebot_ws/install_isolated/env.sh', 'ninja', '-j4', '-l4']' returned non-zero exit status 1
Reproduce this error by running:
==> cd /home/asber/turtlebot_ws/build_isolated/cartographer && /home/asber/turtlebot_ws/install_isolated/env.sh ninja -j4 -l4
Command failed, exiting.
solution:
https://blog.csdn.net/Steve_Kung/article/details/89435998
后面不要下载demo,太慢了,按照此教程:
使用Turtlebot 2和Rplidar A2实现Cartographer
注意因为我用的是A3,所以波特率要改为256000
和gmapping的差不多,待加入手柄控制建图
PS:注意测试rplidar的时候只需要运行roslaunch rplidar_ros view_rplidar_a3.launch 就好了 roslaunch rplidar_ros rplidar_a3.launch和这个程序节点冲突
保存地图
只是之后cm就用不了了,如果想用,则需要删掉我们wstool下载的东西 以及cere的pkg
具体步骤:
- 启动Rplidar A2雷达
打开一个新终端,输入:
$ roslaunch turtlebot_navigation rplidar_laser.launch - 启动cartographer_turtlebot建地图
再打开一个新终端,输入:
$ roslaunch cartographer_turtlebot turtlebot_lidar_2d.launch - 使用键盘操作turtlebot2移动
又打开一个新终端,输入:
$ roslaunch turtlebot_teleop keyboard_teleop.launch
按提示利用键盘控制turtlebot2移动建图。
完成轨迹,如果不接受进一步的数据:
rosservice call /finish_trajectory 0
,否则不执行
序列化保存其当前状态
rosservice call /write_state "{filename: '${HOME}/map/cartographer1st.pbstream'}"
将pbstream转换为pgm和yaml
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/map/cartographer1st -pbstream_filename=${HOME}/map/cartographer1st.pbstream -resolution=0.025
生成对应的pgm和yaml,放于${HOME}/Downloads/mymap目录下
如果要第二次,跑完之后首先完成轨迹
rosservice call /finish_trajectory 0
序列化保存其当前状态
rosservice call /write_state "{filename: '${HOME}/map/cartographer2ed.pbstream'}"
将pbstream转换为pgm和yaml
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/map/cartographer2ed -pbstream_filename=${HOME}/map/cartographer2ed.pbstream -resolution=0.025
TB2 RplidarA3 gmapping
Turtlebot入门教程-激光雷达(Rplidar)gmapping构建地图
到"打开rplidar_laser.launch,并修改"
这里可以直接进roscd turtlebot_navigation 然后用sudo改laser/driver/rplidar_laser.launch文件如下:
<launch>
<node name="rplidarNode" pkg="rplidar_ros" type="rplidarNode" output="screen">
<param name="serial_port" type="string" value="/dev/ttyUSB0"/>
<param name="serial_baudrate" type="int" value="256000"/><!--A3 -->
<!--param name="serial_baudrate" type="int" value="115200"--><!--A1/A2 -->
<param name="frame_id" type="string" value="laser"/>
<param name="inverted" type="bool" value="false"/>
<param name="angle_compensate" type="bool" value="true"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0 0.0 0.0 base_link laser 100"/>
</launch>
之后按照此教程的确可以实现使用gmapping进行建图,不涉及任何代码层面的理解,还未尝试手柄建图的结果
以及电脑的尺寸32*20貌似太大 强行放会导致重心偏移。
base_link应该是最底部的圆盘中心。
可以结合此文一起查看
待加入手柄控制建图
TB2 RplidarA3 kartoSLAM
ROS与SLAM入门教程-激光雷达(Rplidar)slam_karto构建地图
roscore
roslaunch turtlebot_bringup minimal.launch
roslaunch turtlebot_navigation rplidar_karto_demo.launch
roslaunch turtlebot_teleop keyboard_teleop.launch
//或者使用手柄
rosparam set /joystick/dev /dev/input/js0
roslaunch turtlebot_teleop logitech.launch
测试使用,按住左边的LB按钮激活游戏杆并移动左遥控杆,Turtlebot应该就有反应。
roslaunch turtlebot_rviz_launchers view_navigation.launch
构建地图结束保存地图
上网本新开端口,建立目录,保存地图
$ mkdir -p ~/map
$ rosrun map_server map_saver -f ~/map/rplidar_karto
$ ls ~/map #查看内容,包含rplidar_karto.pgm rplidar_karto.yaml
错误提示:
1、错误:Failed to contact master
如果看到如下错误:
[ERROR] [1446531999.044935824]: [registerPublisher] Failed to contact master at [localhost:11311]. Retrying…
请检查 roscore 是否正常打开。
2、 如果下载源码,编译报错
In file included from /home/asber/turtlebot_ws/src/slam_karto/src/spa_solver.h:30:0,
from /home/asber/turtlebot_ws/src/slam_karto/src/spa_solver.cpp:18:
/opt/ros/kinetic/include/sparse_bundle_adjustment/spa2d.h:171:34: error: ‘constexpr’ needed for in-class initialization of static data member ‘const double sba::Con2dP2::qScale’ of non-integral type [-fpermissive]
const static double qScale = 1.0;
^
slam_karto/CMakeFiles/slam_karto.dir/build.make:86: recipe for target 'slam_karto/CMakeFiles/slam_karto.dir/src/spa_solver.cpp.o' failed
make[2]: *** [slam_karto/CMakeFiles/slam_karto.dir/src/spa_solver.cpp.o] Error 1
make[2]: *** 正在等待未完成的任务....
In file included from /home/asber/turtlebot_ws/src/slam_karto/src/spa_solver.h:30:0,
from /home/asber/turtlebot_ws/src/slam_karto/src/slam_karto.cpp:41:
/opt/ros/kinetic/include/sparse_bundle_adjustment/spa2d.h:171:34: error: ‘constexpr’ needed for in-class initialization of static data member ‘const double sba::Con2dP2::qScale’ of non-integral type [-fpermissive]
const static double qScale = 1.0;
^
slam_karto/CMakeFiles/slam_karto.dir/build.make:62: recipe for target 'slam_karto/CMakeFiles/slam_karto.dir/src/slam_karto.cpp.o' failed
make[2]: *** [slam_karto/CMakeFiles/slam_karto.dir/src/slam_karto.cpp.o] Error 1
CMakeFiles/Makefile2:1716: recipe for target 'slam_karto/CMakeFiles/slam_karto.dir/all' failed
make[1]: *** [slam_karto/CMakeFiles/slam_karto.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
可参考如下链接
sudo gedit /opt/ros/kinetic/include/sparse_bundle_adjustment/spa2d.h
修改错误代码
3、运行roslaunch turtlebot_navigation rplidar_karto_demo.launch的时候roslaunch turtlebot_bringup minimal.launch和roslaunch turtlebot_navigation rplidar_karto_demo.launch同时报错
[ERROR] [1578053848.999941494]: Kobuki : Timed out while waiting for serial data stream [/mobile_base].
[ERROR] [1578053853.345166787]: Error, operation time out. RESULT_OPERATION_TIMEOUT!
[rplidarNode-1] process has died [pid 19012, exit code 255, cmd /home/asber/turtlebot_ws/devel/lib/rplidar_ros/rplidarNode __name:=rplidarNode __log:=/home/asber/.ros/log/63d39a92-2e22-11ea-b620-1cb72c8b7412/rplidarNode-1.log].
log file: /home/asber/.ros/log/63d39a92-2e22-11ea-b620-1cb72c8b7412/rplidarNode-1*.log
[ WARN] [1578053854.122810128]: Timed out waiting for transform from base_footprint to map to become available before running costmap, tf error: Could not find a connection between 'map' and 'base_footprint' because they are not part of the same tree.Tf has two or more unconnected trees.. canTransform returned after 0.100409 timeout was 0.1.
USB口没有插对
发现一个现象:一开始激光到地图,然后TB2移动,但是移动之后轨迹不对,然后就构建强行构建地图,所以会出现那种走廊一道一道的,其实是检测到拐角,但是位置每次往前一点就会加在图上,往前一点就会加在图上,所以出现了波浪形状的地图。这其实是因为rplidar中 laser 到baselink的tf变换没有180度
Kartoslam参数
Documentation
Part of the documentation is available in the previously maintained karto package.
Nodes
slam_karto
The slam_karto node takes in sensor_msgs/LaserScan messages and builds a map (nav_msgs/OccupancyGrid). The map can be retrieved via a ROS topic or service.
Subscribed Topics
tf (tf/tfMessage)
Transforms necessary to relate frames for laser, base, and odometry (see below)
scan (sensor_msgs/LaserScan)
Laser scans to create the map from
Published Topics
map_metadata (nav_msgs/MapMetaData)
Get the metadata of the map data (resolution, width, height, ...)
map (nav_msgs/OccupancyGrid)
Get the map data from this topic, which is latched, and updated periodically
visualization_marker_array (visualization_msgs/MarkerArray)
Get the pose graph from this topic, which is updated periodically
Services
dynamic_map (nav_msgs/GetMap)
Call this service to get the map data
Parameters
~odom_frame (string, default: “odom”)
The frame attached to the odometry system. #里程计frame名字
~map_frame (string, default: “map”)
The frame attached to the map. #地图的frame名字
~base_frame (string, default: “base_link”)
The frame attached to the mobile base. #TB2底盘的frame名字
~throttle_scans (int, default: 1)#几线的激光
Process 1 out of every this many scans (set it to a higher number to skip more scans)
~map_update_interval (float, default: 5.0)#地图更新间隔 5s
How long (in seconds) between updates to the map. Lowering this number updates the occupancy grid more often, at the expense of greater computational load.
~resolution (float, default: 0.05)#地图分辨率
Resolution of the map (in metres per occupancy grid block)
~delta (float, default: 0.05)#每一个grid占据多少的面积的分辨率
Resolution of the map (in metres per occupancy grid block). Same as resolution. Defined for compatibility with the parameter names of gmapping.
~transform_publish_period (float, default: 0.05)#TF发布时间间隔
How long (in seconds) between transform publications. To disable broadcasting transforms, set to 0.
~use_scan_matching (bool, default: true)#这个scan_match 在real world是用来消除噪声的
When set to true, the mapper will use a scan matching algorithm. In most real-world situations this should be set to true so that the mapper algorithm can correct for noise and errors in odometry and scan data. In some simulator environments where the simulated scan and odometry data are very accurate, the scan matching algorithm can produce worse results. In those cases set this to false to improve results.
~use_scan_barycenter (bool, default: true)
Use the barycenter of scan endpoints to define distances between scans. 使用scan的中心去定义scans之间的距离
~minimum_travel_distance (double, default: 0.2)
Sets the minimum travel between scans. If a new scan's position is more than minimumTravelDistance from the previous scan, the mapper will use the data from the new scan. Otherwise, it will discard the new scan if it also does not meet the minimum change in heading requirement. For performance reasons, generally it is a good idea to only process scans if the robot has moved a reasonable amount.
最小的scan的距离,如果scan与scan之间的距离小于0.2米 那么会抛弃新scan
~minimum_travel_heading (double, default: deg2rad(10))
Sets the minimum heading change between scans. If a new scan's heading is more than minimum_travel_heading from the previous scan, the mapper will use the data from the new scan. Otherwise, it will discard the new scan if it also does not meet the minimum travel distance requirement. For performance reasons, generally it is a good idea to only process scans if the robot has moved a reasonable amount.
~scan_buffer_size (int, default: 70)
Sets the length of the scan chain stored for scan matching. scan_buffer_size should be set to approximately scan_buffer_maximum_scan_distance / minimum_travel_distance. The idea is to get an area approximately 20 meters long for scan matching. For example, if we add scans every minimum_travel_distance == 0.3 meters, then scan_buffer_size should be 20 / 0.3 = 67.
~scan_buffer_maximum_scan_distance (double, default: 20.)
Sets the maximum distance between the first and last scans in the scan chain stored for matching.
~link_match_minimum_response_fine (double, default: 0.8)
Scans are linked only if the correlation response value is greater than this value.
~link_scan_maximum_distance (double, default: 10.)
Sets the maximum distance between linked scans. Scans that are farther apart will not be linked regardless of the correlation response value.
~loop_search_maximum_distance (double, default: 4.)
Scans less than this distance from the current position will be considered for a match in loop closure.
~do_loop_closing (bool, default: true)
Enable/disable loop closure.
~loop_match_minimum_chain_size (int, default: 10)
When the loop closure detection finds a candidate it must be part of a large set of linked scans. If the chain of scans is less than this value, we do not attempt to close the loop.
~loop_match_maximum_variance_coarse (double, default: sqrt(0.4))
The co-variance values for a possible loop closure have to be less than this value to consider a viable solution. This applies to the coarse search.
~loop_match_minimum_response_coarse (double, default: 0.8)
If response is larger than this, then initiate loop closure search at the coarse resolution.
~loop_match_minimum_response_fine (double, default: 0.8)
If response is larger than this, then initiate loop closure search at the fine resolution.
~correlation_search_space_dimension (double, default: 0.3)
Sets the size of the search grid used by the matcher. The search grid will have the size correlation_search_space_dimension x correlation_search_space_dimension.
~correlation_search_space_resolution (double, default: 0.01)
Sets the resolution (size of a grid cell) of the correlation grid.
~correlation_search_space_smear_deviation (double, default: 0.03)
The point readings are smeared by this value in X and Y to create a smoother response.
~loop_search_space_dimension (double, default: 8.0)
The size of the search grid used by the matcher.
~loop_search_space_resolution (double, default: 0.05)
The resolution (size of a grid cell) of the correlation grid.
~loop_search_space_smear_deviation (double, default: 0.03)
The point readings are smeared by this value in X and Y to create a smoother response.
~distance_variance_penalty (double, default: sqrt(0.3))
Variance of penalty for deviating from odometry when scan-matching. The penalty is a multiplier (less than 1.0) is a function of the delta of the scan position being tested and the odometric pose.
~angle_variance_penalty (double, default: sqrt(deg2rad(20)))
See distance_variance_penalty.
~fine_search_angle_offset (double, default: deg2rad(0.2))
The range of angles to search during a fine search.
~coarse_search_angle_offset (double, default: deg2rad(20.0))
The range of angles to search during a coarse search.
~coarse_angle_resolution (double, default: deg2rad(2.0))
Resolution of angles to search during a coarse search.
~minimum_angle_penalty (double, default: 0.9)
Minimum value of the angle penalty multiplier so scores do not become too small.
~minimum_distance_penalty (double, default: 0.5)
Minimum value of the distance penalty multiplier so scores do not become too small.
~use_response_expansion (bool, default: false)
Whether to increase the search space if no good matches are initially found
Required tf Transforms
→ base_link
usually a fixed value, broadcast periodically by a robot_state_publisher, or a tf static_transform_publisher.
base_link → odom
usually provided by the odometry system (e.g., the driver for the mobile base)
Provided tf Transforms
map → odom
the current estimate of the robot's pose within the map frame