• Turtlebot2简单控制


    遥控

    遥控前为了让turtlebot接受命令,需要启动

    roslaunch turtlebot_bringup minimal.lauch

    键盘操作命令:

    roslaunch turtlebot_teleop keyboard_teleop.launch

    简单脚本控制:

    首先输入命令

    roslaunch turtlebot_bringup minimal.launch

    然后运行编写的脚本,如直行脚本:goforward.py

    python goforward.py

    其内容如下:

    1. #!/usr/bin/env python
    2. '''
    3. Copyright (c) 2015, Mark Silliman
    4. All rights reserved.
    5. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
    6. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    7. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    8. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    9. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    10. '''
    11. # A very basic TurtleBot script that moves TurtleBot forward indefinitely. Press CTRL + C to stop. To run:
    12. # On TurtleBot:
    13. # roslaunch turtlebot_bringup minimal.launch
    14. # On work station:
    15. # python goforward.py
    16. import rospy
    17. from geometry_msgs.msg import Twist
    18. class GoForward():
    19. def __init__(self):
    20. # initiliaze
    21. rospy.init_node('GoForward', anonymous=False)
    22. # tell user how to stop TurtleBot
    23. rospy.loginfo("To stop TurtleBot CTRL + C")
    24. # What function to call when you ctrl + c
    25. rospy.on_shutdown(self.shutdown)
    26. # Create a publisher which can "talk" to TurtleBot and tell it to move
    27. # Tip: You may need to change cmd_vel_mux/input/navi to /cmd_vel if you're not using TurtleBot2
    28. self.cmd_vel = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=10)
    29. #TurtleBot will stop if we don't keep telling it to move. How often should we tell it to move? 10 HZ
    30. r = rospy.Rate(10);
    31. # Twist is a datatype for velocity
    32. move_cmd = Twist()
    33. # let's go forward at 0.2 m/s
    34. move_cmd.linear.x = 0.1
    35. # let's turn at 0 radians/s
    36. move_cmd.angular.z = 0
    37. # as long as you haven't ctrl + c keeping doing...
    38. while not rospy.is_shutdown():
    39. # publish the velocity
    40. self.cmd_vel.publish(move_cmd)
    41. # wait for 0.1 seconds (10 HZ) and publish again
    42. r.sleep()
    43. def shutdown(self):
    44. # stop turtlebot
    45. rospy.loginfo("Stop TurtleBot")
    46. # a default Twist has linear.x of 0 and angular.z of 0. So it'll stop TurtleBot
    47. self.cmd_vel.publish(Twist())
    48. # sleep just makes sure TurtleBot receives the stop command prior to shutting down the script
    49. rospy.sleep(1)
    50. if __name__ == '__main__':
    51. try:
    52. GoForward()
    53. except:
    54. rospy.loginfo("GoForward node terminated.")

    若想要tb2(turtlebot2,下同)走正方形等可自行探索其他脚本:

    https://github.com/markwsilliman/turtlebot/

     注:turtlebot只使用线性的。X和Z值的角,因为它在一个平面作品(2D)的世界,但无人机,海洋机器人与其他机器人占据的三维环境中,线性的。Y,X和Y的角,角的值是可用的。

    turtlebot开始在地板上画正方形但你会发现它很快开始漂离出发的路径。这是机器人和计算机的作用非常不同的地方。如果你问一台电脑做2 + 1,你会总是收到1。如果你问一个机器人向前移动1米,它将去大约一米,而不是完全直。知道机器人是(定位)是一个经典的机器人的挑战之一,尤其是在室内环境中,全球定位系统是不可靠的或足够精确。

    你可能会认为,因为你可以告诉机器人在0.2米/秒,这将是很容易编程的机器人,使它前进一米,通过发布一个线性的。x = 0.2米/秒5秒。如果机器人是一台计算机,这是完全正确的,但对于机器人,这是非常不准确的,由于打滑,不完善的校准,和其他因素。如果你写一个这样的脚本驱动在一个正方形,并运行10个周期,你会结束一个完全不同的地方,从你开始!幸运的是,令人惊讶的科学家和研究人员正走在我们的前面

    创建地图:

    1. roslaunch turtlebot_bringup minimal.launch
    2. roslaunch turtlebot_navigation gmapping_demo.launch

     

    1. roslaunch turtlebot_rviz_launchers view_navigation.launch
    2. roslaunch turtlebot_teleop keyboard_teleop.launch

     保存地图:

    1. rosrun map_server map_saver -f /tmp/my_map
    2. ls /tmp/

    现在你可以看到两个文件在/tmp目录my_map.pgm和my_map.yaml。 

    自主驾驶:

    1. roslaunch turtlebot_bringup minimal.launch
    2. roslaunch turtlebot_navigation amcl_demo.launch map_file:=/tmp/my_map.yaml

     

    如果你看到 odom received! 说明已经正常运行。

    问题

    如果你收到一个警告:Waiting on transform...,先重启minimal.launch,重新启动amcl_demo.lauch。您可能需要尝试重新启动几次。同时,关闭Kobuki基站并重开。

    turtlebot成功运行,在工作站运行:

    roslaunch turtlebot_rviz_launchers view_navigation.launch --screen
    • rviz应该公开展示你的地图。turtlebot不能够估计在启动姿态,尽管它可以在你初始化它的姿态。
    • 选择“2D Pose Estimate”在地图上的turtlebot位置点击并按住。当你握着鼠标的时候,一个箭头会出现在鼠标指针的下方,用这个来估计它的方向。

    • 设置后估计的姿态,选择“2D Nav Goal”,点击你想让turtlebot去的地方。您还可以指定一个目标方向,使用相同的技术如“2D Pose Estimate”。

    • turtlebot现在应该朝着你的目录自主前进。尝试指定一个目标,并走在前面,看看它如何反应的动态障碍。

     编码实现前进与避障

    1. roslaunch turtlebot_bringup minimal.launch
    2. python ~/helloworld/goforward.py

    tb2会前进,撞到东西,ctrl+c停止;

    若要实现避障

    1. roslaunch turtlebot_bringup minimal.launch
    2. roslaunch turtlebot_navigation amcl_demo.launch map_file:=/tmp/my_map.yaml
    3. roslaunch turtlebot_rviz_launchers view_navigation.launch --screen
    4. python ~/helloworld/goforward_and_avoid_obstacle.py

    tb2不能可靠地确定其初始姿态(在哪里)所以我们就把它用“2D Pose Estimate”。选择“2D Pose Estimate”和指定的位置turtlebot。保持rviz打开,我们可以监视它的路径规划。

    提示:在你估计tb2的姿势可以可靠地知道它在哪里,甚至在旅行。

     

    当它在驾驶时, 尝试走到机器人的路径,看看它如何响应。

    为什么它会在转圈?

    turtlebot四处寻找特征,比较他们的地图,以确定它的位置。这个过程被称为本地化。

    从代码分析:

     请注意,而不是说“向前几秒钟”,我们说:“无论什么路径,我们想在前进3米位置的地方结束”。turtlebot可能需要60秒来试图找到一个路径到这个位置。

    定点自导航:

    1. roslaunch turtlebot_bringup minimal.launch
    2. roslaunch turtlebot_navigation amcl_demo.launch map_file:=/tmp/my_map.yaml
    3. roslaunch turtlebot_rviz_launchers view_navigation.launch --screen

    在RViz,选择“二维姿态估计”,点击地图约在turtlebot是对准箭头指示方向。

    下一步,选择“发布点”,将鼠标悬停在你的地图(但不要点击),你想turtlebot去当你运行你的脚本。在屏幕的左下角旁边“选择这一点”,你会注意到三个数字,当你移动鼠标。这是你的观点,所以写下这些数字吧。

    提示:第三个数字是高度。它可能会显示一个数字,不是完美的0,但不管它说什么,使用0。

    在一个新的终端窗口运行:

    gedit ~/helloworld/go_to_specific_point_on_map.py

    83行

    position = {'x': 1.22, 'y' : 2.56}

     

    重写X,Y值与你写下的数字时,做“发布点”。保存和退出。

    然后运行:

    python ~/helloworld/go_to_specific_point_on_map.py

    注:如先前看到的,turtlebot会避开障碍物,要计算一个合理的路径,只要rospy.duration期限没有过期。

    提示:如果你认为你amcl_demo.launch终端运行它将显示一个报告,告诉你的时候,TurtleBot已经放弃了试图达成一个目标。

    查看电池状态:

     先启动

    roslaunch turtlebot_bringup minimal.launch

    查看发布的主题

    rostopic list

    其中 

    1. /laptop_charge 是笔记本电量信息
    2. /mobile_base/sensors/core 是Kobuki底座的电量信息

    可直接监听

    rostopic echo /laptop_charge

    或者运行脚本

    1. cd ~/helloworld/
    2. python netbook_battery.py

     笔记本电池脚本:

    rospy.Subscriber("/laptop_charge/",SmartBatteryStatus,self.NetbookPowerEventCallback)
    

    这意味着,“每一次新的数据公布在线程/laptop_charge/   。self.NetbookPowerEventCallback

    1. SmartBetteryStatus 是数据类型的线程包含。此数据类型定义在包含命令(在脚本的顶部附近):
    from smart_battery_msgs.msg import SmartBatteryStatus

    现在让我们看看在功能NetbookPowerEventCallback。数据传递给功能,组件可以打印这样:

     print("Percent: " + str(data.percentage)) 

     

    重要提示:稍后我们会检查是否data.percentage大于50看我们是否需要充电。Python是很严格的时候,比较不同类型的数据,所以总是用int()转换。例子:

    if (data.percentage < 50):
    

    会导致一个错误,但:

    if(int(data.percentage) < 50):
    

    将工作正常。

    底座电池信息:

    有多个电池,用于kobuki基地。功率百分比是用在kobuki_battery.py固定kobuki_base_max_charge值计算。

    确定你的电池的最大充电到满,让它在停靠站的一段,然后在turtlebot运行:

    rostopic echo /mobile_base/sensors/core
    

    注意电池的值,和编辑kobuki_battery.py:

    gedit kobuki_battery.py
    

    修改kobuki_base_max_charge价值。百分比功率现在将正确计算。

    按键事件:

    1. roslaunch turtlebot_bringup minimal.launch
    2. python kobuki_buttons.py

    会提示 

     跟随实验

    1. roslaunch turtlebot_bringup minimal.launch
    2. roslaunch turtlebot_follower follower.launch

    参数修改:

     

    1. # pre-groovy
    2. rosrun dynamic_reconfigure reconfigure_gui
    3. # groovy or later
    4. rosrun rqt_reconfigure rqt_reconfigure
    1. 选择 camera/follower

    2. 移动滑块则Turtlebot的跟随行为就改变

    3. Android 客户端

      参考Android 配对 通过Android客户端,可以运行跟随演示,开始或停止跟随行为。

     全景图实验:

    turtlebot3的功能

    1. roslaunch turtlebot_bringup minimal.launch
    2. roslaunch turtlebot_panorama panorama.launch
    1. 创建全景图,有两种方法创建。

    1. rostopic pub turtlebot_panorama/take_pano std_msgs/Empty
    2. rosservice call turtlebot_panorama/take_pano 0 360.0 30.0 0.3

    2、停止

     

    1. rostopic pub turtlebot_panorama/stop_pano std_msgs/Empty
    2. rosservice call turtlebot_panorama/take_pano 2 360.0 30.0 0.3

     

    配置参数

    上面利用rosservice 调用就使用了参数。2(模式) 360.0(角度) 30.0(间隔) 0.3(旋转速度)

    1. 模式:
    • 0 for snap&rotate (i.e. rotate, stop, snapshot, rotate, stop, snapshot, ...)
    • 1 for continuous (i.e. keep rotating while taking snapshots)
    • 2 to stop an ongoing panorama creation
    1. 角度

    2. 创建快照和旋转模式时为角度间隔(度),其他模式为时间间隔(以秒为单位)

    3. 旋转速度(弧度/秒)

    查看结果

    1. 在工作台上,执行命令:
    rosrun image_view image_view image:=/turtlebot_panorama/panorama
    

    注意:先执行此命令,在执行创建全景图命令,360度自转完成,即自动生成全景图, 点击图片右键即可自动保存。

    cartographer

    cartographer是少有的基于优化的开源激光SLAM。因为同通常的scan-to-scan激光匹配会累计误差,所以它引入了Submap这一概念,将原来的scan-to-scan匹配变成了scan-to-map匹配,就是激光先和submap进行匹配。

    每次得到一帧激光scan数据之后,cartographer将其与最近的submap去进行匹配,找到一个最优的位姿,将scan插入到submap中,因为在一个较短的时间内,这个匹配过程不会累加什么误差。当submap完成之后,便不会再有任何激光数据插入其中,它就是一个独立的已经完成了子地图,它只参与闭环的匹配了。接下来的工作有点类似与拼图过程,我们通过调整每个submap的位姿,使所有的submap之间互相重叠的部分(即约束)误差最小。

    1. 需要安装3个软件包,ceres solver、cartographer和cartographer_ros。为了管理方便,建立carto目录来存放ceres solver、cartographer。
    2. 安装依赖
    sudo apt-get install -y 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-indigo-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev
    1. 首先安装ceres solver,选择的版本是1.11
    1. cd ~/carto
    2. git clone https://github.com/hitcm/ceres-solver-1.11.0.git
    3. cd ceres-solver-1.11.0/build #如果build目录不存在,就自己建mkdir build
    4. cmake ..
    5. make –j
    6. sudo make install
    1. 然后安装 cartographer
    1. cd ~/carto
    2. git clone https://github.com/hitcm/cartographer.git
    3. cd cartographer/build #如果build目录不存在,就自己建mkdir build
    4. cmake .. -G Ninja #3
    5. ninja
    6. ninja test
    7. sudo ninja install

    上述第3步执行错误的同学可以忽略3-6步,改用下面的方法。

    1. cmake ..
    2. make
    3. sudo make install
    1. 安装cartographer_ros

    谷歌官方提供的安装方法比较繁琐,我对原来的文件进行了少许的修改,核心代码不变,只是修改了编译文件

    • 下载到catkin_ws下面的src文件夹下面
    git clone https://github.com/hitcm/cartographer_ros.git
    
    • 然后到catkin_ws下面运行
    $ catkin_make
    
    • 新包加入环境
    1. $ source ~/.bashrc
    2. $ rospack profile
    1. 数据下载测试, 并上传到carto目录下。
    • 2d数据,大概500M,用迅雷下载
    https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
    
    • 3d数据,8G左右,同样用迅雷下载
    https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/cartographer_3d_deutsches_museum.bag
    
    • 然后运行launch文件即可。
    1. roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:={$HOME}/carto/cartographer_paper_deutsches_museum.bag
    2. roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:={$HOME}/carto/cartographer_3d_deutsches_museum.bag
    • 刚开始使用ROS的同学运行下面两句是无法工作的,可能出现的错误如下。
    1. [demo_backpack_2d.launch] is neither a launch file in package [cartographer_ros] nor is [cartographer_ros] a launch file name
    2. The traceback for the exception was written to the log file
    • 这种错误的主要原因是ros的catkin_ws配置问题,可以运行rospack profile试试。

    • 实在不行还有如下所示的两种解决方法。推荐第二种。

    最终结果如下图

    • 2d效果

     

    • 3d效果

     

     gmapping建图和amcl导航

    建图:

    • 我们这里需要一个将深度图转为激光数据的包

     

     

    1. $ cd ~/catkin_ws/src
    2. $ git clone https://github.com/ros-perception/depthimage_to_laserscan.git
    • 我这里新建了一个bringup的包来专门存放launch 文件
    1. $ cd ~/catkin_ws/src
    2. $ catkin_create_pkg bringup roscpp
    • 在 bringup包内我们新建一个launch文件夹,然后在launch文件夹里添加
      kinect2_depthimage_to_laserscan_rviz_view.launch文件
    1. $ cd ~/catkin_ws/src/bringup
    2. $ mkdir launch
    3. $ touch launch/kinect2_depthimage_to_laserscan_rviz_view.launch
    4. $ vim launch/kinect2_depthimage_to_laserscan_rviz_view.launch
    • 内容如下:
    1. <launch>
    2. <!-- start sensor-->
    3. <include file="$(find kinect2_bridge)/launch/kinect2_bridge.launch">
    4. <arg name="base_name" value="kinect2"/>
    5. <arg name="sensor" value=""/>
    6. <arg name="publish_tf" value="true"/>
    7. <arg name="base_name_tf" value="kinect2"/>
    8. <arg name="fps_limit" value="-1.0"/>
    9. <arg name="calib_path" value="$(find kinect2_bridge)/data/"/>
    10. <arg name="use_png" value="false"/>
    11. <arg name="jpeg_quality" value="90"/>
    12. <arg name="png_level" value="1"/>
    13. <arg name="depth_method" value="default"/>
    14. <arg name="depth_device" value="-1"/>
    15. <arg name="reg_method" value="default"/>
    16. <arg name="reg_device" value="-1"/>
    17. <arg name="max_depth" value="12.0"/>
    18. <arg name="min_depth" value="0.1"/>
    19. <arg name="queue_size" value="5"/>
    20. <arg name="bilateral_filter" value="true"/>
    21. <arg name="edge_aware_filter" value="true"/>
    22. <arg name="worker_threads" value="4"/>
    23. </include>
    24. <!-- Run the depthimage_to_laserscan node -->
    25. <node pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" name="depthimage_to_laserscan" output="screen">
    26. <!--输入图像-->
    27. <remap from="image" to="/kinect2/qhd/image_depth_rect"/>
    28. <!--相关图像的相机信息。通常不需要重新变形,因为camera_info将从与图像相同的命名空间订阅。-->
    29. <remap from="camera_info" to="/kinect2/qhd/camera_info" />
    30. <!--输出激光数据的话题-->
    31. <remap from="scan" to="/scan" />
    32. <!--激光扫描的帧id。对于来自具有Z向前的“光学”帧的点云,该值应该被设置为具有X向前和Z向上的相应帧。-->
    33. <param name="output_frame_id" value="/kinect2_depth_frame"/>
    34. <!--用于生成激光扫描的像素行数。对于每一列,扫描将返回在图像中垂直居中的那些像素的最小值。-->
    35. <param name="scan_height" value="30"/>
    36. <!--返回的最小范围(以米为单位)。小于该范围的输出将作为-Inf输出。-->
    37. <param name="range_min" value="0.45"/>
    38. <!--返回的最大范围(以米为单位)。大于此范围将输出为+ Inf。-->
    39. <param name="range_max" value="8.00"/>
    40. </node>
    41. <!-- static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms -->
    42. <node pkg="tf" type="static_transform_publisher" name="base_footprint_to_base_link" args="0 0 0.5 0 0 0 base_footprint base_link 50" />
    43. <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0.5 0 0 0 base_link laser 50" />
    44. <node pkg="tf" type="static_transform_publisher" name="base_link_to_kinect2laser" args="0 0 0.5 0 0 0 base_link kinect2_depth_frame 50" />
    45. <node pkg="tf" type="static_transform_publisher" name="base_link_to_kinect2_link" args="0 0 0.5 -1.57 0 -1.57 base_link kinect2_link 50" />
    46. <!--start rviz view -->
    47. <node name="rviz" pkg="rviz" type="rviz" args="-d $(find bringup)/rviz/kinect2_depthimage_to_laserscan_view.rviz" />
    48. </launch>
    • 在 bringup 包里新建rviz文件夹,然后在rviz文件夹里添加
      kinect2_depthimage_to_laserscan_view.rviz文件
    1. $ cd ~/catkin_ws/src/bringup
    2. $ mkdir rviz
    3. $ touch rviz/kinect2_depthimage_to_laserscan_view.rviz
    4. $ vim rviz/kinect2_depthimage_to_laserscan_view.rviz
    • 内容如下:
    1. Panels:
    2. - Class: rviz/Displays
    3. Help Height: 78
    4. Name: Displays
    5. Property Tree Widget:
    6. Expanded:
    7. - /Global Options1
    8. - /Status1
    9. - /LaserScan1
    10. Splitter Ratio: 0.5
    11. Tree Height: 566
    12. - Class: rviz/Selection
    13. Name: Selection
    14. - Class: rviz/Tool Properties
    15. Expanded:
    16. - /2D Pose Estimate1
    17. - /2D Nav Goal1
    18. - /Publish Point1
    19. Name: Tool Properties
    20. Splitter Ratio: 0.588679
    21. - Class: rviz/Views
    22. Expanded:
    23. - /Current View1
    24. Name: Views
    25. Splitter Ratio: 0.5
    26. - Class: rviz/Time
    27. Experimental: false
    28. Name: Time
    29. SyncMode: 0
    30. SyncSource: LaserScan
    31. Visualization Manager:
    32. Class: ""
    33. Displays:
    34. - Alpha: 0.5
    35. Cell Size: 1
    36. Class: rviz/Grid
    37. Color: 160; 160; 164
    38. Enabled: true
    39. Line Style:
    40. Line Width: 0.03
    41. Value: Lines
    42. Name: Grid
    43. Normal Cell Count: 0
    44. Offset:
    45. X: 0
    46. Y: 0
    47. Z: 0
    48. Plane: XY
    49. Plane Cell Count: 10
    50. Reference Frame: <Fixed Frame>
    51. Value: true
    52. - Alpha: 1
    53. Autocompute Intensity Bounds: true
    54. Autocompute Value Bounds:
    55. Max Value: 0
    56. Min Value: 0
    57. Value: true
    58. Axis: Z
    59. Channel Name: intensity
    60. Class: rviz/LaserScan
    61. Color: 255; 255; 255
    62. Color Transformer: AxisColor
    63. Decay Time: 0
    64. Enabled: true
    65. Invert Rainbow: false
    66. Max Color: 255; 255; 255
    67. Max Intensity: 4096
    68. Min Color: 0; 0; 0
    69. Min Intensity: 0
    70. Name: LaserScan
    71. Position Transformer: XYZ
    72. Queue Size: 10
    73. Selectable: true
    74. Size (Pixels): 3
    75. Size (m): 0.01
    76. Style: Points
    77. Topic: /scan
    78. Unreliable: false
    79. Use Fixed Frame: true
    80. Use rainbow: true
    81. Value: true
    82. - Class: rviz/TF
    83. Enabled: true
    84. Frame Timeout: 15
    85. Frames:
    86. All Enabled: true
    87. base_footprint:
    88. Value: true
    89. kinect2_depth_frame:
    90. Value: true
    91. kinect2_ir_optical_frame:
    92. Value: true
    93. kinect2_link:
    94. Value: true
    95. kinect2_rgb_optical_frame:
    96. Value: true
    97. laser:
    98. Value: true
    99. Marker Scale: 1
    100. Name: TF
    101. Show Arrows: true
    102. Show Axes: true
    103. Show Names: true
    104. Tree:
    105. base_footprint:
    106. kinect2_depth_frame:
    107. {}
    108. kinect2_link:
    109. kinect2_rgb_optical_frame:
    110. kinect2_ir_optical_frame:
    111. {}
    112. laser:
    113. {}
    114. Update Interval: 0
    115. Value: true
    116. Enabled: true
    117. Global Options:
    118. Background Color: 48; 48; 48
    119. Fixed Frame: laser
    120. Frame Rate: 30
    121. Name: root
    122. Tools:
    123. - Class: rviz/Interact
    124. Hide Inactive Objects: true
    125. - Class: rviz/MoveCamera
    126. - Class: rviz/Select
    127. - Class: rviz/FocusCamera
    128. - Class: rviz/Measure
    129. - Class: rviz/SetInitialPose
    130. Topic: /initialpose
    131. - Class: rviz/SetGoal
    132. Topic: /move_base_simple/goal
    133. - Class: rviz/PublishPoint
    134. Single click: true
    135. Topic: /clicked_point
    136. Value: true
    137. Views:
    138. Current:
    139. Class: rviz/Orbit
    140. Distance: 10
    141. Enable Stereo Rendering:
    142. Stereo Eye Separation: 0.06
    143. Stereo Focal Distance: 1
    144. Swap Stereo Eyes: false
    145. Value: false
    146. Focal Point:
    147. X: 0
    148. Y: 0
    149. Z: 0
    150. Name: Current View
    151. Near Clip Distance: 0.01
    152. Pitch: 0.810398
    153. Target Frame: <Fixed Frame>
    154. Value: Orbit (rviz)
    155. Yaw: 3.2504
    156. Saved: ~
    157. Window Geometry:
    158. Displays:
    159. collapsed: false
    160. Height: 846
    161. Hide Left Dock: false
    162. Hide Right Dock: true
    163. QMainWindow State: 000000ff00000000fd00000004000000000000016a000002c4fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000028000002c4000000d600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002c4fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000028000002c4000000ac00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004b00000003efc0100000002fb0000000800540069006d00650100000000000004b0000002f600fffffffb0000000800540069006d0065010000000000000450000000000000000000000340000002c400000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
    164. Selection:
    165. collapsed: false
    166. Time:
    167. collapsed: false
    168. Tool Properties:
    169. collapsed: false
    170. Views:
    171. collapsed: true
    172. Width: 1200
    173. X: 50
    174. Y: 45
    • 基本工作我们都做完了,现在我们需要编译一下
    1. $ cd ~/catkin_ws
    2. $ catkin_make
    3. $ rospack profile
    • 我们现在可以接上KinectV2(注意!!!接USB3.0口).

    测试:

    • 新终端,执行
    roslaunch bringup kinect2_depthimage_to_laserscan_rviz_view.launch
    
    • 效果:

    • 查看TF树:文件生成在主文件夹
    1. cd ~
    2. rosrun tf view_frames
    • 效果:

    安装依赖包

    • 安装Gmapping包
    1. $ cd ~/catkin_ws/src
    2. $ git clone https://github.com/ros-perception/slam_gmapping.git
    3. $ cd ~/catkin_ws
    4. $ catkin_make
    5. $ rospack profile
    • 在我们之前的建的bringup/launch/下新建kinect2_gmapping.launch文件
    1. $ cd ~/catkin_ws/bringup/launch/
    2. $ touch kinect2_gmapping.launch
    3. $ vim kinect2_gmapping.launch
    • 代码如下:
    1. <?xml version="1.0"?>
    2. <launch>
    3. <!-- start kinect2-->
    4. <include file="$(find kinect2_bridge)/launch/kinect2_bridge.launch">
    5. <arg name="base_name" value="kinect2"/>
    6. <arg name="sensor" value=""/>
    7. <arg name="publish_tf" value="true"/>
    8. <arg name="base_name_tf" value="kinect2"/>
    9. <arg name="fps_limit" value="-1.0"/>
    10. <arg name="calib_path" value="$(find kinect2_bridge)/data/"/>
    11. <arg name="use_png" value="false"/>
    12. <arg name="jpeg_quality" value="90"/>
    13. <arg name="png_level" value="1"/>
    14. <arg name="depth_method" value="default"/>
    15. <arg name="depth_device" value="-1"/>
    16. <arg name="reg_method" value="default"/>
    17. <arg name="reg_device" value="-1"/>
    18. <arg name="max_depth" value="12.0"/>
    19. <arg name="min_depth" value="0.1"/>
    20. <arg name="queue_size" value="5"/>
    21. <arg name="bilateral_filter" value="true"/>
    22. <arg name="edge_aware_filter" value="true"/>
    23. <arg name="worker_threads" value="4"/>
    24. </include>
    25. <!-- Run the depthimage_to_laserscan node -->
    26. <node pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" name="depthimage_to_laserscan" output="screen">
    27. <!--输入图像-->
    28. <remap from="image" to="/kinect2/qhd/image_depth_rect"/>
    29. <!--相关图像的相机信息。通常不需要重新变形,因为camera_info将从与图像相同的命名空间订阅。-->
    30. <remap from="camera_info" to="/kinect2/qhd/camera_info" />
    31. <!--输出激光数据的话题-->
    32. <remap from="scan" to="/scan" />
    33. <!--激光扫描的帧id。对于来自具有Z向前的“光学”帧的点云,该值应该被设置为具有X向前和Z向上的相应帧。-->
    34. <param name="output_frame_id" value="/kinect2_depth_frame"/>
    35. <!--用于生成激光扫描的像素行数。对于每一列,扫描将返回在图像中垂直居中的那些像素的最小值。-->
    36. <param name="scan_height" value="30"/>
    37. <!--返回的最小范围(以米为单位)。小于该范围的输出将作为-Inf输出。-->
    38. <param name="range_min" value="0.45"/>
    39. <!--返回的最大范围(以米为单位)。大于此范围将输出为+ Inf。-->
    40. <param name="range_max" value="8.00"/>
    41. </node>
    42. <!--start gmapping node -->
    43. <node pkg="gmapping" type="slam_gmapping" name="simple_gmapping" output="screen">
    44. <param name="map_update_interval" value="5.0"/>
    45. <param name="maxUrange" value="5.0"/>
    46. <param name="maxRange" value="6.0"/>
    47. <param name="sigma" value="0.05"/>
    48. <param name="kernelSize" value="1"/>
    49. <param name="lstep" value="0.05"/>
    50. <param name="astep" value="0.05"/>
    51. <param name="iterations" value="5"/>
    52. <param name="lsigma" value="0.075"/>
    53. <param name="ogain" value="3.0"/>
    54. <param name="lskip" value="0"/>
    55. <param name="minimumScore" value="50"/>
    56. <param name="srr" value="0.1"/>
    57. <param name="srt" value="0.2"/>
    58. <param name="str" value="0.1"/>
    59. <param name="stt" value="0.2"/>
    60. <param name="linearUpdate" value="1.0"/>
    61. <param name="angularUpdate" value="0.5"/>
    62. <param name="temporalUpdate" value="3.0"/>
    63. <param name="resampleThreshold" value="0.5"/>
    64. <param name="particles" value="50"/>
    65. <param name="xmin" value="-5.0"/>
    66. <param name="ymin" value="-5.0"/>
    67. <param name="xmax" value="5.0"/>
    68. <param name="ymax" value="5.0"/>
    69. <param name="delta" value="0.05"/>
    70. <param name="llsamplerange" value="0.01"/>
    71. <param name="llsamplestep" value="0.01"/>
    72. <param name="lasamplerange" value="0.005"/>
    73. <param name="lasamplestep" value="0.005"/>
    74. </node>
    75. <!--start serial-port and odometry node-->
    76. <node name="base_controller" pkg="base_controller" type="base_controller"/>
    77. <!-- static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms -->
    78. <node pkg="tf" type="static_transform_publisher" name="base_footprint_to_base_link" args="0 0 0.5 0 0 0 base_footprint base_link 50" />
    79. <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0.5 0 0 0 base_link laser 50" />
    80. <node pkg="tf" type="static_transform_publisher" name="base_link_to_kinect2laser" args="0 0 0.5 0 0 0 base_link kinect2_depth_frame 50" />
    81. <node pkg="tf" type="static_transform_publisher" name="base_link_to_kinect2_link" args="0 0 0.5 -1.57 0 -1.57 base_link kinect2_link 50" />
    82. </launch>
    • 在我们之前的建的bringup/launch/下新建kinect2_gmapping_rviz_view.launch文件
    • 我们这里不把启动RVIZ写在kinect2_gmapping.launch里是方便以后的远程启动
    1. $ cd ~/catkin_ws/bringup/launch/
    2. $ touch kinect2_gmapping_rviz_view.launch
    3. $ vim kinect2_gmapping_rviz_view.launch
    • 内容如下:
    1. "1.0"?>
    2. <launch>
    3. <node name="rviz" pkg="rviz" type="rviz" args="-d $(find bringup)/rviz/kinect2_gmapping.rviz" />
    4. launch>
    • 还有在新建bringup/rviz/下新建kinect2_gmapping.rviz文件
    1. $ cd ~/catkin_ws/bringup/rviz/
    2. $ touch kinect2_gmapping.rviz
    3. $ vim kinect2_gmapping.rviz
    • 代码如下:
    1. Panels:
    2. - Class: rviz/Displays
    3. Help Height: 78
    4. Name: Displays
    5. Property Tree Widget:
    6. Expanded:
    7. - /Global Options1
    8. - /Status1
    9. - /Map1
    10. Splitter Ratio: 0.5
    11. Tree Height: 566
    12. - Class: rviz/Selection
    13. Name: Selection
    14. - Class: rviz/Tool Properties
    15. Expanded:
    16. - /2D Pose Estimate1
    17. - /2D Nav Goal1
    18. - /Publish Point1
    19. Name: Tool Properties
    20. Splitter Ratio: 0.588679
    21. - Class: rviz/Views
    22. Expanded:
    23. - /Current View1
    24. Name: Views
    25. Splitter Ratio: 0.5
    26. - Class: rviz/Time
    27. Experimental: false
    28. Name: Time
    29. SyncMode: 0
    30. SyncSource: LaserScan
    31. Visualization Manager:
    32. Class: ""
    33. Displays:
    34. - Alpha: 0.5
    35. Cell Size: 1
    36. Class: rviz/Grid
    37. Color: 160; 160; 164
    38. Enabled: true
    39. Line Style:
    40. Line Width: 0.03
    41. Value: Lines
    42. Name: Grid
    43. Normal Cell Count: 0
    44. Offset:
    45. X: 0
    46. Y: 0
    47. Z: 0
    48. Plane: XY
    49. Plane Cell Count: 10
    50. Reference Frame: <Fixed Frame>
    51. Value: true
    52. - Class: rviz/TF
    53. Enabled: true
    54. Frame Timeout: 15
    55. Frames:
    56. All Enabled: true
    57. base_footprint:
    58. Value: true
    59. base_link:
    60. Value: true
    61. kinect2_depth_frame:
    62. Value: true
    63. kinect2_ir_optical_frame:
    64. Value: true
    65. kinect2_link:
    66. Value: true
    67. kinect2_rgb_optical_frame:
    68. Value: true
    69. laser:
    70. Value: true
    71. map:
    72. Value: true
    73. odom:
    74. Value: true
    75. Marker Scale: 1
    76. Name: TF
    77. Show Arrows: true
    78. Show Axes: true
    79. Show Names: true
    80. Tree:
    81. map:
    82. odom:
    83. base_footprint:
    84. base_link:
    85. kinect2_depth_frame:
    86. {}
    87. kinect2_link:
    88. kinect2_rgb_optical_frame:
    89. kinect2_ir_optical_frame:
    90. {}
    91. laser:
    92. {}
    93. Update Interval: 0
    94. Value: true
    95. - Alpha: 1
    96. Autocompute Intensity Bounds: true
    97. Autocompute Value Bounds:
    98. Max Value: 1
    99. Min Value: 1
    100. Value: true
    101. Axis: Z
    102. Channel Name: intensity
    103. Class: rviz/LaserScan
    104. Color: 255; 255; 255
    105. Color Transformer: AxisColor
    106. Decay Time: 0
    107. Enabled: true
    108. Invert Rainbow: false
    109. Max Color: 255; 255; 255
    110. Max Intensity: 4096
    111. Min Color: 0; 0; 0
    112. Min Intensity: 0
    113. Name: LaserScan
    114. Position Transformer: XYZ
    115. Queue Size: 10
    116. Selectable: true
    117. Size (Pixels): 3
    118. Size (m): 0.01
    119. Style: Flat Squares
    120. Topic: /scan
    121. Unreliable: false
    122. Use Fixed Frame: true
    123. Use rainbow: true
    124. Value: true
    125. - Alpha: 0.7
    126. Class: rviz/Map
    127. Color Scheme: map
    128. Draw Behind: false
    129. Enabled: true
    130. Name: Map
    131. Topic: /map
    132. Unreliable: false
    133. Value: true
    134. Enabled: true
    135. Global Options:
    136. Background Color: 48; 48; 48
    137. Fixed Frame: odom
    138. Frame Rate: 30
    139. Name: root
    140. Tools:
    141. - Class: rviz/Interact
    142. Hide Inactive Objects: true
    143. - Class: rviz/MoveCamera
    144. - Class: rviz/Select
    145. - Class: rviz/FocusCamera
    146. - Class: rviz/Measure
    147. - Class: rviz/SetInitialPose
    148. Topic: /initialpose
    149. - Class: rviz/SetGoal
    150. Topic: /move_base_simple/goal
    151. - Class: rviz/PublishPoint
    152. Single click: true
    153. Topic: /clicked_point
    154. Value: true
    155. Views:
    156. Current:
    157. Class: rviz/Orbit
    158. Distance: 70.1093
    159. Enable Stereo Rendering:
    160. Stereo Eye Separation: 0.06
    161. Stereo Focal Distance: 1
    162. Swap Stereo Eyes: false
    163. Value: false
    164. Focal Point:
    165. X: 3.9777
    166. Y: -3.7323
    167. Z: -7.60875
    168. Name: Current View
    169. Near Clip Distance: 0.01
    170. Pitch: 0.355398
    171. Target Frame: <Fixed Frame>
    172. Value: Orbit (rviz)
    173. Yaw: 0.0404091
    174. Saved: ~
    175. Window Geometry:
    176. Displays:
    177. collapsed: false
    178. Height: 846
    179. Hide Left Dock: false
    180. Hide Right Dock: true
    181. QMainWindow State: 000000ff00000000fd00000004000000000000016a000002c4fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000028000002c4000000d600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002c4fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000028000002c4000000ac00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004b00000003efc0100000002fb0000000800540069006d00650100000000000004b0000002f600fffffffb0000000800540069006d0065010000000000000450000000000000000000000340000002c400000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
    182. Selection:
    183. collapsed: false
    184. Time:
    185. collapsed: false
    186. Tool Properties:
    187. collapsed: false
    188. Views:
    189. collapsed: true
    190. Width: 1200
    191. X: 50
    192. Y: 45
    • 最后我们依次启动我们的launch文件便可
    1. $ roslaunch kinect2_gmapping.launch
    2. $ roslaunch kinect2_gmapping_rviz_view.launch
    3. $ rosrun teleop_twist_keyboard teleop_twist_keyboard.py
    • 这样子我们就可以愉快的控制小车移动来建图了,当你建好图后运行一下指令就可以保存地图:
    rosrun map_server map_saver -f mymap
    
    • 地图保存在主文件夹,两个文件,mymap.pgm 和 mymap.yaml

    • 效果:

    • TF树:
    1. $ cd ~
    2. $ rosrun tf view_frames
    • 效果:

    AMCL导航 :

    • 安装一下所需的包
    1. $ cd ~/catkin_ws/src
    2. $ git clone -b indigo-devel https://github.com/ros-planning/navigation
    3. $ cd ~/catkin_ws
    4. $ catkin_make
    5. $ rospack profile
    • 在我们之前的建的bringup/下,新建nav_config文件夹,然后新建四个文件
    1. $ cd ~/catkin_ws/bringup/
    2. $ mkdir nav_config
    3. $ touch base_local_planner_params.yaml
    4. $ touch costmap_common_params.yaml
    5. $ touch global_costmap_params.yaml
    6. $ touch local_costmap_params.yaml
    • 这四个文件主要用于导航配置

    (1)base_local_planner_params.yaml文件内容:

    1. controller_frequency: 2.0
    2. recovery_behavior_enabled: false
    3. clearing_rotation_allowed: false
    4. TrajectoryPlannerROS:
    5. max_vel_x: 0.3
    6. min_vel_x: 0.05
    7. max_vel_y: 0.0 # zero for a differential drive robot
    8. min_vel_y: 0.0
    9. min_in_place_vel_theta: 0.5
    10. escape_vel: -0.1
    11. acc_lim_x: 2.5
    12. acc_lim_y: 0.0 # zero for a differential drive robot
    13. acc_lim_theta: 3.2
    14. holonomic_robot: false
    15. yaw_goal_tolerance: 0.1 # about 6 degrees
    16. xy_goal_tolerance: 0.15 # 10 cm
    17. latch_xy_goal_tolerance: false
    18. pdist_scale: 0.8
    19. gdist_scale: 0.6
    20. meter_scoring: true
    21. heading_lookahead: 0.325
    22. heading_scoring: false
    23. heading_scoring_timestep: 0.8
    24. occdist_scale: 0.1
    25. oscillation_reset_dist: 0.05
    26. publish_cost_grid_pc: false
    27. prune_plan: true
    28. sim_time: 2.5
    29. sim_granularity: 0.025
    30. angular_sim_granularity: 0.025
    31. vx_samples: 8
    32. vy_samples: 0 # zero for a differential drive robot
    33. vtheta_samples: 20
    34. dwa: true
    35. simple_attractor: false

    (2)costmap_common_params.yaml文件

    1. obstacle_range: 2.5
    2. raytrace_range: 3.0
    3. robot_radius: 0.30
    4. inflation_radius: 0.15
    5. max_obstacle_height: 0.6
    6. min_obstacle_height: 0.0
    7. observation_sources: scan
    8. scan: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, expected_update_rate: 0}

    (3)global_costmap_params.yaml文件

    1. global_costmap:
    2. global_frame: /map
    3. robot_base_frame: /base_link
    4. update_frequency: 1.0
    5. publish_frequency: 0
    6. static_map: true
    7. rolling_window: false
    8. resolution: 0.01
    9. transform_tolerance: 0.5
    10. map_type: costmap

    (4)local_costmap_params.yaml文件

    1. local_costmap:
    2. global_frame: /odom
    3. robot_base_frame: /base_link
    4. update_frequency: 1.0
    5. publish_frequency: 1.0
    6. static_map: false
    7. rolling_window: true
    8. width: 6.0
    9. height: 6.0
    10. resolution: 0.01
    11. transform_tolerance: 0.5
    12. map_type: costmap
    • 在我们之前的建的bringup/下,新建map文件夹
    • 然后将之前建图生成的两个文件 mymap.pgm 和 mymap.yaml 移到map文件夹里
    • 然后修改 mymap.yaml ,做如下修改:将image这一行的改为你的mymap.pgm文件所在路径,如
    image: /home/forrest/catkin_ws/src/bringup/map/mymap.pgm
    
    • 在我们之前的建的bringup/launch/下新建kinect2_nav.launch文件
    1. $ cd ~/catkin_ws/src/bringup/launch/
    2. $ touch kinect2_nav.launch
    3. $ vim kinect2_nav.launch
    • 代码如下:
    1. <launch>
    2. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    3. <param name="use_sim_time" value="false" />
    4. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    5. <!-- 启动kinect2驱动节点 -->
    6. <include file="$(find kinect2_bridge)/launch/kinect2_bridge.launch">
    7. <arg name="base_name" value="kinect2"/>
    8. <arg name="sensor" value=""/>
    9. <arg name="publish_tf" value="true"/>
    10. <arg name="base_name_tf" value="kinect2"/>
    11. <arg name="fps_limit" value="-1.0"/>
    12. <arg name="calib_path" value="$(find kinect2_bridge)/data/"/>
    13. <arg name="use_png" value="false"/>
    14. <arg name="jpeg_quality" value="90"/>
    15. <arg name="png_level" value="1"/>
    16. <arg name="depth_method" value="default"/>
    17. <arg name="depth_device" value="-1"/>
    18. <arg name="reg_method" value="default"/>
    19. <arg name="reg_device" value="-1"/>
    20. <arg name="max_depth" value="12.0"/>
    21. <arg name="min_depth" value="0.1"/>
    22. <arg name="queue_size" value="5"/>
    23. <arg name="bilateral_filter" value="true"/>
    24. <arg name="edge_aware_filter" value="true"/>
    25. <arg name="worker_threads" value="4"/>
    26. </include>
    27. <!-- 启动深度图转换激光数据节点 -->
    28. <node pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" name="depthimage_to_laserscan" output="screen">
    29. <!--输入图像-->
    30. <remap from="image" to="/kinect2/qhd/image_depth_rect"/>
    31. <!--相关图像的相机信息。通常不需要重新变形,因为camera_info将从与图像相同的命名空间订阅。-->
    32. <remap from="camera_info" to="/kinect2/qhd/camera_info" />
    33. <!--输出激光数据的话题-->
    34. <remap from="scan" to="/scan" />
    35. <!--激光扫描的帧id。对于来自具有Z向前的“光学”帧的点云,该值应该被设置为具有X向前和Z向上的相应帧。-->
    36. <param name="output_frame_id" value="/kinect2_depth_frame"/>
    37. <!--用于生成激光扫描的像素行数。对于每一列,扫描将返回在图像中垂直居中的那些像素的最小值。-->
    38. <param name="scan_height" value="30"/>
    39. <!--返回的最小范围(以米为单位)。小于该范围的输出将作为-Inf输出。-->
    40. <param name="range_min" value="0.45"/>
    41. <!--返回的最大范围(以米为单位)。大于此范围将输出为+ Inf。-->
    42. <param name="range_max" value="8.00"/>
    43. </node>
    44. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    45. <!-- 启动地图服务器载入地图 -->
    46. <node name="map_server" pkg="map_server" type="map_server" args="$(find bringup)/map/mymap.yaml"/>
    47. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    48. <!-- 启动 move_base 节点 -->
    49. <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true">
    50. <rosparam file="$(find bringup)/nav_config/costmap_common_params.yaml" command="load" ns="global_costmap" />
    51. <rosparam file="$(find bringup)/nav_config/costmap_common_params.yaml" command="load" ns="local_costmap" />
    52. <rosparam file="$(find bringup)/nav_config/local_costmap_params.yaml" command="load" />
    53. <rosparam file="$(find bringup)/nav_config/global_costmap_params.yaml" command="load" />
    54. <rosparam file="$(find bringup)/nav_config/base_local_planner_params.yaml" command="load" />
    55. <!-- <rosparam file="$(find odom_tf_package)/config/nav_obstacles_params.yaml" command="load" /> -->
    56. </node>
    57. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    58. <!-- 启动 AMCL 节点 -->
    59. <node pkg="amcl" type="amcl" name="amcl" clear_params="true">
    60. <param name="use_map_topic" value="false"/>
    61. <!-- Publish scans from best pose at a max of 10 Hz -->
    62. <param name="odom_model_type" value="diff"/>
    63. <param name="odom_alpha5" value="0.1"/>
    64. <param name="gui_publish_rate" value="10.0"/>
    65. <param name="laser_max_beams" value="60"/>
    66. <param name="laser_max_range" value="12.0"/>
    67. <param name="min_particles" value="500"/>
    68. <param name="max_particles" value="2000"/>
    69. <param name="kld_err" value="0.05"/>
    70. <param name="kld_z" value="0.99"/>
    71. <param name="odom_alpha1" value="0.2"/>
    72. <param name="odom_alpha2" value="0.2"/>
    73. <!-- translation std dev, m -->
    74. <param name="odom_alpha3" value="0.2"/>
    75. <param name="odom_alpha4" value="0.2"/>
    76. <param name="laser_z_hit" value="0.5"/>
    77. <param name="laser_z_short" value="0.05"/>
    78. <param name="laser_z_max" value="0.05"/>
    79. <param name="laser_z_rand" value="0.5"/>
    80. <param name="laser_sigma_hit" value="0.2"/>
    81. <param name="laser_lambda_short" value="0.1"/>
    82. <param name="laser_model_type" value="likelihood_field"/>
    83. <!-- <param name="laser_model_type" value="beam"/> -->
    84. <param name="laser_likelihood_max_dist" value="2.0"/>
    85. <param name="update_min_d" value="0.25"/>
    86. <param name="update_min_a" value="0.2"/>
    87. <param name="odom_frame_id" value="odom"/>
    88. <param name="resample_interval" value="1"/>
    89. <!-- Increase tolerance because the computer can get quite busy -->
    90. <param name="transform_tolerance" value="1.0"/>
    91. <param name="recovery_alpha_slow" value="0.0"/>
    92. <param name="recovery_alpha_fast" value="0.0"/>
    93. <!-- scan topic -->
    94. <remap from="scan" to="scan"/>
    95. </node>
    96. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    97. <!-- 启动基础控制器节点:发布里程计,控制小车 -->
    98. <node name="base_controller" pkg="base_controller" type="base_controller"/>
    99. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    100. <!-- tf 转换 -->
    101. <!-- static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms -->
    102. <node pkg="tf" type="static_transform_publisher" name="base_footprint_to_base_link" args="0 0 0.5 0 0 0 base_footprint base_link 50" />
    103. <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0.5 0 0 0 base_link laser 50" />
    104. <node pkg="tf" type="static_transform_publisher" name="base_link_to_kinect2laser" args="0 0 0.5 0 0 0 base_link kinect2_depth_frame 50" />
    105. <node pkg="tf" type="static_transform_publisher" name="base_link_to_kinect2_link" args="0 0 0.5 -1.57 0 -1.57 base_link kinect2_link 50" />
    106. <!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->
    107. </launch>
    • 在我们之前的建的bringup/launch/下新建kinect2_nav_rviz_view.launch文件
    1. $ cd ~/catkin_ws/src/bringup/launch/
    2. $ touch kinect2_nav_rviz_view.launch
    3. $ vim kinect2_nav_rviz_view.launch
    • 代码如下:
    1. "1.0"?>
    2. <launch>
    3. <node name="rviz" pkg="rviz" type="rviz" args="-d $(find bringup)/rviz/kinect2_nav.rviz" />
    4. launch>
    • 还有在新建bringup/rviz/下新建kinect2_nav.rviz文件
    1. $ cd ~/catkin_ws/src/bringup/rviz
    2. $ touch kinect2_nav.rviz
    3. $ vim kinect2_nav.rviz
    • 代码如下:
    1. Panels:
    2. - Class: rviz/Displays
    3. Help Height: 78
    4. Name: Displays
    5. Property Tree Widget:
    6. Expanded:
    7. - /Global Options1
    8. - /Odometry1
    9. - /RobotModel1/Links1/base_footprint1
    10. - /Marker1/Namespaces1
    11. Splitter Ratio: 0.652661
    12. Tree Height: 457
    13. - Class: rviz/Selection
    14. Name: Selection
    15. - Class: rviz/Tool Properties
    16. Expanded:
    17. - /2D Pose Estimate1
    18. - /2D Nav Goal1
    19. Name: Tool Properties
    20. Splitter Ratio: 0.428571
    21. - Class: rviz/Views
    22. Expanded:
    23. - /Current View1
    24. Name: Views
    25. Splitter Ratio: 0.5
    26. - Class: rviz/Time
    27. Experimental: false
    28. Name: Time
    29. SyncMode: 0
    30. SyncSource: ""
    31. Visualization Manager:
    32. Class: ""
    33. Displays:
    34. - Alpha: 0.5
    35. Cell Size: 0.5
    36. Class: rviz/Grid
    37. Color: 160; 160; 164
    38. Enabled: true
    39. Line Style:
    40. Line Width: 0.03
    41. Value: Lines
    42. Name: Grid
    43. Normal Cell Count: 0
    44. Offset:
    45. X: 0
    46. Y: 0
    47. Z: 0
    48. Plane: XY
    49. Plane Cell Count: 80
    50. Reference Frame: odom
    51. Value: true
    52. - Angle Tolerance: 0.1
    53. Class: rviz/Odometry
    54. Color: 221; 200; 14
    55. Enabled: true
    56. Keep: 100
    57. Length: 0.6
    58. Name: Odometry
    59. Position Tolerance: 0.1
    60. Topic: /odom
    61. Value: true
    62. - Angle Tolerance: 0.1
    63. Class: rviz/Odometry
    64. Color: 255; 85; 0
    65. Enabled: false
    66. Keep: 100
    67. Length: 0.6
    68. Name: Odometry EKF
    69. Position Tolerance: 0.1
    70. Topic: /odom_ekf
    71. Value: false
    72. - Alpha: 1
    73. Class: rviz/RobotModel
    74. Collision Enabled: false
    75. Enabled: true
    76. Links:
    77. All Links Enabled: true
    78. Expand Joint Details: false
    79. Expand Link Details: false
    80. Expand Tree: false
    81. Link Tree Style: Links in Alphabetic Order
    82. base_footprint:
    83. Alpha: 1
    84. Show Axes: false
    85. Show Trail: false
    86. Value: true
    87. base_link:
    88. Alpha: 1
    89. Show Axes: false
    90. Show Trail: false
    91. Value: true
    92. camera_depth_frame:
    93. Alpha: 1
    94. Show Axes: false
    95. Show Trail: false
    96. camera_depth_optical_frame:
    97. Alpha: 1
    98. Show Axes: false
    99. Show Trail: false
    100. camera_link:
    101. Alpha: 1
    102. Show Axes: false
    103. Show Trail: false
    104. Value: true
    105. camera_rgb_frame:
    106. Alpha: 1
    107. Show Axes: false
    108. Show Trail: false
    109. camera_rgb_optical_frame:
    110. Alpha: 1
    111. Show Axes: false
    112. Show Trail: false
    113. front_wheel_link:
    114. Alpha: 1
    115. Show Axes: false
    116. Show Trail: false
    117. Value: true
    118. gyro_link:
    119. Alpha: 1
    120. Show Axes: false
    121. Show Trail: false
    122. laser:
    123. Alpha: 1
    124. Show Axes: false
    125. Show Trail: false
    126. Value: true
    127. left_cliff_sensor_link:
    128. Alpha: 1
    129. Show Axes: false
    130. Show Trail: false
    131. left_wheel_link:
    132. Alpha: 1
    133. Show Axes: false
    134. Show Trail: false
    135. Value: true
    136. leftfront_cliff_sensor_link:
    137. Alpha: 1
    138. Show Axes: false
    139. Show Trail: false
    140. plate_0_link:
    141. Alpha: 1
    142. Show Axes: false
    143. Show Trail: false
    144. Value: true
    145. plate_1_link:
    146. Alpha: 1
    147. Show Axes: false
    148. Show Trail: false
    149. Value: true
    150. plate_2_link:
    151. Alpha: 1
    152. Show Axes: false
    153. Show Trail: false
    154. Value: true
    155. plate_3_link:
    156. Alpha: 1
    157. Show Axes: false
    158. Show Trail: false
    159. Value: true
    160. rear_wheel_link:
    161. Alpha: 1
    162. Show Axes: false
    163. Show Trail: false
    164. Value: true
    165. right_cliff_sensor_link:
    166. Alpha: 1
    167. Show Axes: false
    168. Show Trail: false
    169. right_wheel_link:
    170. Alpha: 1
    171. Show Axes: false
    172. Show Trail: false
    173. Value: true
    174. rightfront_cliff_sensor_link:
    175. Alpha: 1
    176. Show Axes: false
    177. Show Trail: false
    178. spacer_0_link:
    179. Alpha: 1
    180. Show Axes: false
    181. Show Trail: false
    182. Value: true
    183. spacer_1_link:
    184. Alpha: 1
    185. Show Axes: false
    186. Show Trail: false
    187. Value: true
    188. spacer_2_link:
    189. Alpha: 1
    190. Show Axes: false
    191. Show Trail: false
    192. Value: true
    193. spacer_3_link:
    194. Alpha: 1
    195. Show Axes: false
    196. Show Trail: false
    197. Value: true
    198. standoff_2in_0_link:
    199. Alpha: 1
    200. Show Axes: false
    201. Show Trail: false
    202. Value: true
    203. standoff_2in_1_link:
    204. Alpha: 1
    205. Show Axes: false
    206. Show Trail: false
    207. Value: true
    208. standoff_2in_2_link:
    209. Alpha: 1
    210. Show Axes: false
    211. Show Trail: false
    212. Value: true
    213. standoff_2in_3_link:
    214. Alpha: 1
    215. Show Axes: false
    216. Show Trail: false
    217. Value: true
    218. standoff_2in_4_link:
    219. Alpha: 1
    220. Show Axes: false
    221. Show Trail: false
    222. Value: true
    223. standoff_2in_5_link:
    224. Alpha: 1
    225. Show Axes: false
    226. Show Trail: false
    227. Value: true
    228. standoff_2in_6_link:
    229. Alpha: 1
    230. Show Axes: false
    231. Show Trail: false
    232. Value: true
    233. standoff_2in_7_link:
    234. Alpha: 1
    235. Show Axes: false
    236. Show Trail: false
    237. Value: true
    238. standoff_8in_0_link:
    239. Alpha: 1
    240. Show Axes: false
    241. Show Trail: false
    242. Value: true
    243. standoff_8in_1_link:
    244. Alpha: 1
    245. Show Axes: false
    246. Show Trail: false
    247. Value: true
    248. standoff_8in_2_link:
    249. Alpha: 1
    250. Show Axes: false
    251. Show Trail: false
    252. Value: true
    253. standoff_8in_3_link:
    254. Alpha: 1
    255. Show Axes: false
    256. Show Trail: false
    257. Value: true
    258. standoff_kinect_0_link:
    259. Alpha: 1
    260. Show Axes: false
    261. Show Trail: false
    262. Value: true
    263. standoff_kinect_1_link:
    264. Alpha: 1
    265. Show Axes: false
    266. Show Trail: false
    267. Value: true
    268. wall_sensor_link:
    269. Alpha: 1
    270. Show Axes: false
    271. Show Trail: false
    272. Name: RobotModel
    273. Robot Description: robot_description
    274. TF Prefix: ""
    275. Update Interval: 0
    276. Value: true
    277. Visual Enabled: true
    278. - Alpha: 0.2
    279. Class: rviz/Map
    280. Color Scheme: map
    281. Draw Behind: true
    282. Enabled: true
    283. Name: Map
    284. Topic: /map
    285. Value: true
    286. - Alpha: 1
    287. Buffer Length: 1
    288. Class: rviz/Path
    289. Color: 255; 0; 0
    290. Enabled: true
    291. Name: Local Plan
    292. Topic: /move_base/TrajectoryPlannerROS/local_plan
    293. Value: true
    294. - Alpha: 1
    295. Buffer Length: 1
    296. Class: rviz/Path
    297. Color: 0; 213; 0
    298. Enabled: true
    299. Name: Global Plan
    300. Topic: /move_base/TrajectoryPlannerROS/global_plan
    301. Value: true
    302. - Class: rviz/Marker
    303. Enabled: true
    304. Marker Topic: /waypoint_markers
    305. Name: Marker
    306. Namespaces:
    307. {}
    308. Queue Size: 100
    309. Value: true
    310. - Alpha: 1
    311. Autocompute Intensity Bounds: true
    312. Autocompute Value Bounds:
    313. Max Value: 0.304
    314. Min Value: 0.304
    315. Value: true
    316. Axis: Z
    317. Channel Name: intensity
    318. Class: rviz/LaserScan
    319. Color: 255; 255; 255
    320. Color Transformer: FlatColor
    321. Decay Time: 0
    322. Enabled: true
    323. Invert Rainbow: false
    324. Max Color: 255; 255; 255
    325. Max Intensity: 4096
    326. Min Color: 0; 0; 0
    327. Min Intensity: 0
    328. Name: LaserScan
    329. Position Transformer: XYZ
    330. Queue Size: 10
    331. Selectable: true
    332. Size (Pixels): 3
    333. Size (m): 0.01
    334. Style: Spheres
    335. Topic: /scan
    336. Use Fixed Frame: true
    337. Use rainbow: true
    338. Value: true
    339. - Alpha: 1
    340. Axes Length: 1
    341. Axes Radius: 0.1
    342. Class: rviz/Pose
    343. Color: 0; 255; 0
    344. Enabled: true
    345. Head Length: 0.1
    346. Head Radius: 0.15
    347. Name: Mouse Goal
    348. Shaft Length: 0.5
    349. Shaft Radius: 0.03
    350. Shape: Arrow
    351. Topic: /move_base/current_goal
    352. Value: true
    353. - Alpha: 1
    354. Axes Length: 1
    355. Axes Radius: 0.1
    356. Class: rviz/Pose
    357. Color: 0; 255; 0
    358. Enabled: true
    359. Head Length: 0.1
    360. Head Radius: 0.15
    361. Name: Goal Pose
    362. Shaft Length: 0.5
    363. Shaft Radius: 0.03
    364. Shape: Arrow
    365. Topic: /move_base_simple/goal
    366. Value: true
    367. - Arrow Length: 0.3
    368. Class: rviz/PoseArray
    369. Color: 255; 25; 0
    370. Enabled: false
    371. Name: Pose Array
    372. Topic: ""
    373. Value: false
    374. Enabled: true
    375. Global Options:
    376. Background Color: 0; 0; 0
    377. Fixed Frame: map
    378. Frame Rate: 30
    379. Name: root
    380. Tools:
    381. - Class: rviz/MoveCamera
    382. - Class: rviz/Interact
    383. Hide Inactive Objects: true
    384. - Class: rviz/Select
    385. - Class: rviz/SetInitialPose
    386. Topic: /initialpose
    387. - Class: rviz/SetGoal
    388. Topic: /move_base_simple/goal
    389. Value: true
    390. Views:
    391. Current:
    392. Angle: -1.57
    393. Class: rviz/TopDownOrtho
    394. Name: Current View
    395. Near Clip Distance: 0.01
    396. Scale: 205.257
    397. Target Frame: <Fixed Frame>
    398. Value: TopDownOrtho (rviz)
    399. X: 0.755064
    400. Y: 0.634474
    401. Saved: ~
    402. Window Geometry:
    403. Displays:
    404. collapsed: false
    405. Height: 695
    406. Hide Left Dock: false
    407. Hide Right Dock: false
    408. QMainWindow State: 000000ff00000000fd00000004000000000000012d00000258fc0200000005fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006400fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000198000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000004100000258000000dd00ffffff000000010000010f00000270fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000270000000b000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004a00000003efc0100000002fb0000000800540069006d00650000000000000004a0000002f600fffffffb0000000800540069006d00650100000000000004500000000000000000000002b80000025800000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
    409. Selection:
    410. collapsed: false
    411. Time:
    412. collapsed: false
    413. Tool Properties:
    414. collapsed: false
    415. Views:
    416. collapsed: false
    417. Width: 1003
    418. X: 787
    419. Y: 348

    测试

    • 最后我们依次启动我们的launch文件便可进行导航

    • 新终端,执行roscore

    $ roscore 
    
    • 新终端,执行:
    roslaunch kinect2_nav.launch
    
    • 新终端,执行:
    roslaunch kinect2_nav_rviz_view.launch
    
    • 启动成功的话会看到一下画面:

     

    如果你看到 odom received! 说明已经正常运行。

    rviz会展现出已经保存的地图。turtlebot不能够估计启动时的姿态。我们可以通过“2D Pose Estimate”来进行位姿的初始化。

    选择“2D Pose Estimate”,在地图上的turtlebot位置点击并按住。当你握着鼠标的时候,一个箭头会出现在鼠标指针的下方,用这个来估计它的方向。

    设置后估计的姿态,选择“2D Nav Goal”,点击你想让turtlebot去的地方。您还可以指定一个目标方向,使用相同的技术如“2D Pose Estimate”。
    turtlebot现在应该朝着你的目录自主前进。尝试指定一个目标,并走在前面,看看它如何反应的动态障碍。
     

  • 相关阅读:
    【Java笔试强训】Day1(100449-组队竞赛 、OR63 删除公共字符)
    【爬虫】第二部分 urllib_handler处理器
    Redis3.2.1如何设置远程连接?允许局域网访问
    (三)使用 Vue 脚手架
    carrier开利触摸屏ICVC控制面板维修CEPL130445
    状态栏QStatusBar
    AI高考志愿填报:大厂神仙打架,考生付费围观
    JavaScript从入门到精通|函数
    (十五)IO 流
    kubernetes集群配置默认存储类(nfs)
  • 原文地址:https://blog.csdn.net/qqGHJ/article/details/128087091