Turtlebot2简单控制

news2024/11/24 15:53:56

遥控

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

roslaunch turtlebot_bringup minimal.lauch

键盘操作命令:

roslaunch turtlebot_teleop keyboard_teleop.launch

简单脚本控制:

首先输入命令

roslaunch turtlebot_bringup minimal.launch

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

python goforward.py

其内容如下:

#!/usr/bin/env python

'''
Copyright (c) 2015, Mark Silliman
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

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.

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.

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.
'''

# A very basic TurtleBot script that moves TurtleBot forward indefinitely. Press CTRL + C to stop.  To run:
# On TurtleBot:
# roslaunch turtlebot_bringup minimal.launch
# On work station:
# python goforward.py

import rospy
from geometry_msgs.msg import Twist

class GoForward():
    def __init__(self):
        # initiliaze
        rospy.init_node('GoForward', anonymous=False)

	# tell user how to stop TurtleBot
	rospy.loginfo("To stop TurtleBot CTRL + C")

        # What function to call when you ctrl + c    
        rospy.on_shutdown(self.shutdown)
        
	# Create a publisher which can "talk" to TurtleBot and tell it to move
        # Tip: You may need to change cmd_vel_mux/input/navi to /cmd_vel if you're not using TurtleBot2
        self.cmd_vel = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=10)
     
	#TurtleBot will stop if we don't keep telling it to move.  How often should we tell it to move? 10 HZ
        r = rospy.Rate(10);

        # Twist is a datatype for velocity
        move_cmd = Twist()
	# let's go forward at 0.2 m/s
        move_cmd.linear.x = 0.1
	# let's turn at 0 radians/s
	move_cmd.angular.z = 0

	# as long as you haven't ctrl + c keeping doing...
        while not rospy.is_shutdown():
	    # publish the velocity
            self.cmd_vel.publish(move_cmd)
	    # wait for 0.1 seconds (10 HZ) and publish again
            r.sleep()
                        
        
    def shutdown(self):
        # stop turtlebot
        rospy.loginfo("Stop TurtleBot")
	# a default Twist has linear.x of 0 and angular.z of 0.  So it'll stop TurtleBot
        self.cmd_vel.publish(Twist())
	# sleep just makes sure TurtleBot receives the stop command prior to shutting down the script
        rospy.sleep(1)
 
if __name__ == '__main__':
    try:
        GoForward()
    except:
        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个周期,你会结束一个完全不同的地方,从你开始!幸运的是,令人惊讶的科学家和研究人员正走在我们的前面

创建地图:

roslaunch turtlebot_bringup minimal.launch
roslaunch turtlebot_navigation gmapping_demo.launch

 

roslaunch turtlebot_rviz_launchers view_navigation.launch
roslaunch turtlebot_teleop keyboard_teleop.launch

 保存地图:

rosrun map_server map_saver -f /tmp/my_map
ls /tmp/

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

自主驾驶:

roslaunch turtlebot_bringup minimal.launch
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现在应该朝着你的目录自主前进。尝试指定一个目标,并走在前面,看看它如何反应的动态障碍。

 编码实现前进与避障

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

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

若要实现避障

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

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

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

 

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

为什么它会在转圈?

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

从代码分析:

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

定点自导航:

roslaunch turtlebot_bringup minimal.launch
roslaunch turtlebot_navigation amcl_demo.launch map_file:=/tmp/my_map.yaml
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

其中 

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

可直接监听

rostopic echo /laptop_charge

或者运行脚本

cd ~/helloworld/
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价值。百分比功率现在将正确计算。

按键事件:

roslaunch turtlebot_bringup minimal.launch
python kobuki_buttons.py

会提示 

 跟随实验

roslaunch turtlebot_bringup minimal.launch
roslaunch turtlebot_follower follower.launch

参数修改:

 

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

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

  3. Android 客户端

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

 全景图实验:

turtlebot3的功能

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

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

2、停止

 

rostopic pub turtlebot_panorama/stop_pano std_msgs/Empty
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
cd ~/carto
git clone https://github.com/hitcm/ceres-solver-1.11.0.git
cd ceres-solver-1.11.0/build #如果build目录不存在,就自己建mkdir build
cmake ..
make –j
sudo make install
  1. 然后安装 cartographer
cd ~/carto
git clone https://github.com/hitcm/cartographer.git
cd cartographer/build   #如果build目录不存在,就自己建mkdir build
cmake .. -G Ninja    #3
ninja
ninja test
sudo ninja install 

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

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

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

  • 下载到catkin_ws下面的src文件夹下面
git clone https://github.com/hitcm/cartographer_ros.git
  • 然后到catkin_ws下面运行
$ catkin_make
  • 新包加入环境
$ source ~/.bashrc
$ 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文件即可。
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:={$HOME}/carto/cartographer_paper_deutsches_museum.bag

roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:={$HOME}/carto/cartographer_3d_deutsches_museum.bag
  • 刚开始使用ROS的同学运行下面两句是无法工作的,可能出现的错误如下。
[demo_backpack_2d.launch] is neither a launch file in package [cartographer_ros] nor is [cartographer_ros] a launch file name
The traceback for the exception was written to the log file
  • 这种错误的主要原因是ros的catkin_ws配置问题,可以运行rospack profile试试。

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

最终结果如下图

  • 2d效果

 

  • 3d效果

 

 gmapping建图和amcl导航

建图:

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

 

 

$ cd ~/catkin_ws/src
$ git clone  https://github.com/ros-perception/depthimage_to_laserscan.git
  • 我这里新建了一个bringup的包来专门存放launch 文件
$ cd ~/catkin_ws/src
$ catkin_create_pkg bringup  roscpp
  • 在 bringup包内我们新建一个launch文件夹,然后在launch文件夹里添加
    kinect2_depthimage_to_laserscan_rviz_view.launch文件
$ cd ~/catkin_ws/src/bringup
$ mkdir  launch 
$ touch  launch/kinect2_depthimage_to_laserscan_rviz_view.launch
$ vim   launch/kinect2_depthimage_to_laserscan_rviz_view.launch
  • 内容如下:
<launch>
    <!-- start sensor-->            
    <include file="$(find kinect2_bridge)/launch/kinect2_bridge.launch">
        <arg name="base_name"         value="kinect2"/>
        <arg name="sensor"            value=""/>
        <arg name="publish_tf"        value="true"/>
        <arg name="base_name_tf"      value="kinect2"/>
        <arg name="fps_limit"         value="-1.0"/>
        <arg name="calib_path"        value="$(find kinect2_bridge)/data/"/>
        <arg name="use_png"           value="false"/>
        <arg name="jpeg_quality"      value="90"/>
        <arg name="png_level"         value="1"/>
        <arg name="depth_method"      value="default"/>
        <arg name="depth_device"      value="-1"/>
        <arg name="reg_method"        value="default"/>
        <arg name="reg_device"        value="-1"/>
        <arg name="max_depth"         value="12.0"/>
        <arg name="min_depth"         value="0.1"/>
        <arg name="queue_size"        value="5"/>
        <arg name="bilateral_filter"  value="true"/>
        <arg name="edge_aware_filter" value="true"/>
        <arg name="worker_threads"    value="4"/>
    </include>  

  <!-- Run the depthimage_to_laserscan node -->
  <node pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" name="depthimage_to_laserscan" output="screen">
    <!--输入图像-->
    <remap from="image" to="/kinect2/qhd/image_depth_rect"/>
    <!--相关图像的相机信息。通常不需要重新变形,因为camera_info将从与图像相同的命名空间订阅。-->
    <remap from="camera_info" to="/kinect2/qhd/camera_info" />
    <!--输出激光数据的话题-->
    <remap from="scan" to="/scan" /> 

        <!--激光扫描的帧id。对于来自具有Z向前的“光学”帧的点云,该值应该被设置为具有X向前和Z向上的相应帧。-->
    <param name="output_frame_id" value="/kinect2_depth_frame"/>
    <!--用于生成激光扫描的像素行数。对于每一列,扫描将返回在图像中垂直居中的那些像素的最小值。-->
    <param name="scan_height" value="30"/>
    <!--返回的最小范围(以米为单位)。小于该范围的输出将作为-Inf输出。-->
    <param name="range_min" value="0.45"/>
    <!--返回的最大范围(以米为单位)。大于此范围将输出为+ Inf。-->
    <param name="range_max" value="8.00"/>
  </node>

  <!-- static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms -->  
  <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" />
  <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0.5 0 0 0 base_link laser 50" />
  <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" />
  <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" />

    <!--start rviz view -->
    <node name="rviz" pkg="rviz" type="rviz" args="-d $(find bringup)/rviz/kinect2_depthimage_to_laserscan_view.rviz" />

</launch>
  • 在 bringup 包里新建rviz文件夹,然后在rviz文件夹里添加
    kinect2_depthimage_to_laserscan_view.rviz文件
$ cd ~/catkin_ws/src/bringup
$ mkdir  rviz
$ touch  rviz/kinect2_depthimage_to_laserscan_view.rviz
$ vim   rviz/kinect2_depthimage_to_laserscan_view.rviz
  • 内容如下:
Panels:
  - Class: rviz/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /Status1
        - /LaserScan1
      Splitter Ratio: 0.5
    Tree Height: 566
  - 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: LaserScan
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: 10
      Reference Frame: <Fixed Frame>
      Value: true
    - Alpha: 1
      Autocompute Intensity Bounds: true
      Autocompute Value Bounds:
        Max Value: 0
        Min Value: 0
        Value: true
      Axis: Z
      Channel Name: intensity
      Class: rviz/LaserScan
      Color: 255; 255; 255
      Color Transformer: AxisColor
      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: LaserScan
      Position Transformer: XYZ
      Queue Size: 10
      Selectable: true
      Size (Pixels): 3
      Size (m): 0.01
      Style: Points
      Topic: /scan
      Unreliable: false
      Use Fixed Frame: true
      Use rainbow: true
      Value: true
    - Class: rviz/TF
      Enabled: true
      Frame Timeout: 15
      Frames:
        All Enabled: true
        base_footprint:
          Value: true
        kinect2_depth_frame:
          Value: true
        kinect2_ir_optical_frame:
          Value: true
        kinect2_link:
          Value: true
        kinect2_rgb_optical_frame:
          Value: true
        laser:
          Value: true
      Marker Scale: 1
      Name: TF
      Show Arrows: true
      Show Axes: true
      Show Names: true
      Tree:
        base_footprint:
          kinect2_depth_frame:
            {}
          kinect2_link:
            kinect2_rgb_optical_frame:
              kinect2_ir_optical_frame:
                {}
          laser:
            {}
      Update Interval: 0
      Value: true
  Enabled: true
  Global Options:
    Background Color: 48; 48; 48
    Fixed Frame: laser
    Frame Rate: 30
  Name: root
  Tools:
    - Class: rviz/Interact
      Hide Inactive Objects: true
    - Class: rviz/MoveCamera
    - Class: rviz/Select
    - Class: rviz/FocusCamera
    - Class: rviz/Measure
    - Class: rviz/SetInitialPose
      Topic: /initialpose
    - Class: rviz/SetGoal
      Topic: /move_base_simple/goal
    - Class: rviz/PublishPoint
      Single click: true
      Topic: /clicked_point
  Value: true
  Views:
    Current:
      Class: rviz/Orbit
      Distance: 10
      Enable Stereo Rendering:
        Stereo Eye Separation: 0.06
        Stereo Focal Distance: 1
        Swap Stereo Eyes: false
        Value: false
      Focal Point:
        X: 0
        Y: 0
        Z: 0
      Name: Current View
      Near Clip Distance: 0.01
      Pitch: 0.810398
      Target Frame: <Fixed Frame>
      Value: Orbit (rviz)
      Yaw: 3.2504
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 846
  Hide Left Dock: false
  Hide Right Dock: true
  QMainWindow State: 000000ff00000000fd00000004000000000000016a000002c4fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000028000002c4000000d600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002c4fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000028000002c4000000ac00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004b00000003efc0100000002fb0000000800540069006d00650100000000000004b0000002f600fffffffb0000000800540069006d0065010000000000000450000000000000000000000340000002c400000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  Selection:
    collapsed: false
  Time:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: true
  Width: 1200
  X: 50
  Y: 45
  • 基本工作我们都做完了,现在我们需要编译一下
$ cd ~/catkin_ws
$ catkin_make 
$ rospack profile
  • 我们现在可以接上KinectV2(注意!!!接USB3.0口).

测试:

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

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

安装依赖包

  • 安装Gmapping包
$ cd ~/catkin_ws/src
$ git clone  https://github.com/ros-perception/slam_gmapping.git
$ cd ~/catkin_ws
$ catkin_make 
$ rospack profile
  • 在我们之前的建的bringup/launch/下新建kinect2_gmapping.launch文件
$ cd ~/catkin_ws/bringup/launch/
$ touch kinect2_gmapping.launch
$ vim kinect2_gmapping.launch
  • 代码如下:
<?xml version="1.0"?>

<launch>    
    <!-- start kinect2-->            
    <include file="$(find kinect2_bridge)/launch/kinect2_bridge.launch">
        <arg name="base_name"         value="kinect2"/>
        <arg name="sensor"            value=""/>
        <arg name="publish_tf"        value="true"/>
        <arg name="base_name_tf"      value="kinect2"/>
        <arg name="fps_limit"         value="-1.0"/>
        <arg name="calib_path"        value="$(find kinect2_bridge)/data/"/>
        <arg name="use_png"           value="false"/>
        <arg name="jpeg_quality"      value="90"/>
        <arg name="png_level"         value="1"/>
        <arg name="depth_method"      value="default"/>
        <arg name="depth_device"      value="-1"/>
        <arg name="reg_method"        value="default"/>
        <arg name="reg_device"        value="-1"/>
        <arg name="max_depth"         value="12.0"/>
        <arg name="min_depth"         value="0.1"/>
        <arg name="queue_size"        value="5"/>
        <arg name="bilateral_filter"  value="true"/>
        <arg name="edge_aware_filter" value="true"/>
        <arg name="worker_threads"    value="4"/>
    </include>  

  <!-- Run the depthimage_to_laserscan node -->
  <node pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" name="depthimage_to_laserscan" output="screen">
    <!--输入图像-->
    <remap from="image" to="/kinect2/qhd/image_depth_rect"/>
    <!--相关图像的相机信息。通常不需要重新变形,因为camera_info将从与图像相同的命名空间订阅。-->
    <remap from="camera_info" to="/kinect2/qhd/camera_info" />
    <!--输出激光数据的话题-->
    <remap from="scan" to="/scan" /> 

        <!--激光扫描的帧id。对于来自具有Z向前的“光学”帧的点云,该值应该被设置为具有X向前和Z向上的相应帧。-->
    <param name="output_frame_id" value="/kinect2_depth_frame"/>
    <!--用于生成激光扫描的像素行数。对于每一列,扫描将返回在图像中垂直居中的那些像素的最小值。-->
    <param name="scan_height" value="30"/>
    <!--返回的最小范围(以米为单位)。小于该范围的输出将作为-Inf输出。-->
    <param name="range_min" value="0.45"/>
    <!--返回的最大范围(以米为单位)。大于此范围将输出为+ Inf。-->
    <param name="range_max" value="8.00"/>
  </node>

    <!--start gmapping node -->
    <node pkg="gmapping" type="slam_gmapping" name="simple_gmapping" output="screen">
        <param name="map_update_interval" value="5.0"/>  
        <param name="maxUrange" value="5.0"/> 
        <param name="maxRange" value="6.0"/> 
        <param name="sigma" value="0.05"/>  
        <param name="kernelSize" value="1"/>  
        <param name="lstep" value="0.05"/>  
        <param name="astep" value="0.05"/>  
        <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="50"/>  
        <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="3.0"/>  
        <param name="resampleThreshold" value="0.5"/>  
        <param name="particles" value="50"/>  
        <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.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"/>  
    </node>

    <!--start serial-port and odometry node-->
    <node name="base_controller" pkg="base_controller" type="base_controller"/>

    <!-- static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms -->  
  <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" />
  <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0.5 0 0 0 base_link laser 50" />
  <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" />
  <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" />

</launch>
  • 在我们之前的建的bringup/launch/下新建kinect2_gmapping_rviz_view.launch文件
  • 我们这里不把启动RVIZ写在kinect2_gmapping.launch里是方便以后的远程启动
$ cd ~/catkin_ws/bringup/launch/
$ touch kinect2_gmapping_rviz_view.launch
$ vim kinect2_gmapping_rviz_view.launch
  • 内容如下:
<?xml version="1.0"?>

<launch>

    <!--start rviz view -->
    <node name="rviz" pkg="rviz" type="rviz" args="-d $(find bringup)/rviz/kinect2_gmapping.rviz" />

</launch>
  • 还有在新建bringup/rviz/下新建kinect2_gmapping.rviz文件
$ cd ~/catkin_ws/bringup/rviz/
$ touch kinect2_gmapping.rviz
$ vim kinect2_gmapping.rviz
  • 代码如下:
Panels:
  - Class: rviz/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /Status1
        - /Map1
      Splitter Ratio: 0.5
    Tree Height: 566
  - 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: LaserScan
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: 10
      Reference Frame: <Fixed Frame>
      Value: true
    - Class: rviz/TF
      Enabled: true
      Frame Timeout: 15
      Frames:
        All Enabled: true
        base_footprint:
          Value: true
        base_link:
          Value: true
        kinect2_depth_frame:
          Value: true
        kinect2_ir_optical_frame:
          Value: true
        kinect2_link:
          Value: true
        kinect2_rgb_optical_frame:
          Value: true
        laser:
          Value: true
        map:
          Value: true
        odom:
          Value: true
      Marker Scale: 1
      Name: TF
      Show Arrows: true
      Show Axes: true
      Show Names: true
      Tree:
        map:
          odom:
            base_footprint:
              base_link:
                kinect2_depth_frame:
                  {}
                kinect2_link:
                  kinect2_rgb_optical_frame:
                    kinect2_ir_optical_frame:
                      {}
                laser:
                  {}
      Update Interval: 0
      Value: true
    - Alpha: 1
      Autocompute Intensity Bounds: true
      Autocompute Value Bounds:
        Max Value: 1
        Min Value: 1
        Value: true
      Axis: Z
      Channel Name: intensity
      Class: rviz/LaserScan
      Color: 255; 255; 255
      Color Transformer: AxisColor
      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: LaserScan
      Position Transformer: XYZ
      Queue Size: 10
      Selectable: true
      Size (Pixels): 3
      Size (m): 0.01
      Style: Flat Squares
      Topic: /scan
      Unreliable: false
      Use Fixed Frame: true
      Use rainbow: true
      Value: true
    - Alpha: 0.7
      Class: rviz/Map
      Color Scheme: map
      Draw Behind: false
      Enabled: true
      Name: Map
      Topic: /map
      Unreliable: false
      Value: true
  Enabled: true
  Global Options:
    Background Color: 48; 48; 48
    Fixed Frame: odom
    Frame Rate: 30
  Name: root
  Tools:
    - Class: rviz/Interact
      Hide Inactive Objects: true
    - Class: rviz/MoveCamera
    - Class: rviz/Select
    - Class: rviz/FocusCamera
    - Class: rviz/Measure
    - Class: rviz/SetInitialPose
      Topic: /initialpose
    - Class: rviz/SetGoal
      Topic: /move_base_simple/goal
    - Class: rviz/PublishPoint
      Single click: true
      Topic: /clicked_point
  Value: true
  Views:
    Current:
      Class: rviz/Orbit
      Distance: 70.1093
      Enable Stereo Rendering:
        Stereo Eye Separation: 0.06
        Stereo Focal Distance: 1
        Swap Stereo Eyes: false
        Value: false
      Focal Point:
        X: 3.9777
        Y: -3.7323
        Z: -7.60875
      Name: Current View
      Near Clip Distance: 0.01
      Pitch: 0.355398
      Target Frame: <Fixed Frame>
      Value: Orbit (rviz)
      Yaw: 0.0404091
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 846
  Hide Left Dock: false
  Hide Right Dock: true
  QMainWindow State: 000000ff00000000fd00000004000000000000016a000002c4fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000028000002c4000000d600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002c4fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a005600690065007700730000000028000002c4000000ac00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004b00000003efc0100000002fb0000000800540069006d00650100000000000004b0000002f600fffffffb0000000800540069006d0065010000000000000450000000000000000000000340000002c400000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  Selection:
    collapsed: false
  Time:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: true
  Width: 1200
  X: 50
  Y: 45
  • 最后我们依次启动我们的launch文件便可
$ roslaunch kinect2_gmapping.launch
$ roslaunch kinect2_gmapping_rviz_view.launch
$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py
  • 这样子我们就可以愉快的控制小车移动来建图了,当你建好图后运行一下指令就可以保存地图:
rosrun map_server map_saver -f mymap
  • 地图保存在主文件夹,两个文件,mymap.pgm 和 mymap.yaml

  • 效果:

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

AMCL导航 :

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

(1)base_local_planner_params.yaml文件内容:

controller_frequency: 2.0
recovery_behavior_enabled: false
clearing_rotation_allowed: false

TrajectoryPlannerROS:
   max_vel_x: 0.3
   min_vel_x: 0.05
   max_vel_y: 0.0  # zero for a differential drive robot
   min_vel_y: 0.0
   min_in_place_vel_theta: 0.5
   escape_vel: -0.1
   acc_lim_x: 2.5
   acc_lim_y: 0.0 # zero for a differential drive robot
   acc_lim_theta: 3.2

   holonomic_robot: false
   yaw_goal_tolerance: 0.1 # about 6 degrees
   xy_goal_tolerance: 0.15  # 10 cm
   latch_xy_goal_tolerance: false
   pdist_scale: 0.8
   gdist_scale: 0.6
   meter_scoring: true

   heading_lookahead: 0.325
   heading_scoring: false
   heading_scoring_timestep: 0.8
   occdist_scale: 0.1
   oscillation_reset_dist: 0.05
   publish_cost_grid_pc: false
   prune_plan: true

   sim_time: 2.5
   sim_granularity: 0.025
   angular_sim_granularity: 0.025
   vx_samples: 8
   vy_samples: 0 # zero for a differential drive robot
   vtheta_samples: 20
   dwa: true
   simple_attractor: false

(2)costmap_common_params.yaml文件

obstacle_range: 2.5
raytrace_range: 3.0
robot_radius: 0.30
inflation_radius: 0.15
max_obstacle_height: 0.6
min_obstacle_height: 0.0
observation_sources: scan
scan: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, expected_update_rate: 0}

(3)global_costmap_params.yaml文件

global_costmap:
global_frame: /map
robot_base_frame: /base_link
update_frequency: 1.0
publish_frequency: 0
static_map: true
rolling_window: false
resolution: 0.01
transform_tolerance: 0.5
map_type: costmap

(4)local_costmap_params.yaml文件

local_costmap:
global_frame: /odom
robot_base_frame: /base_link
update_frequency: 1.0
publish_frequency: 1.0
static_map: false
rolling_window: true
width: 6.0
height: 6.0
resolution: 0.01
transform_tolerance: 0.5
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文件
$ cd ~/catkin_ws/src/bringup/launch/
$ touch kinect2_nav.launch
$ vim kinect2_nav.launch
  • 代码如下:
<launch>
<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->

  <param name="use_sim_time" value="false" />

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->

    <!-- 启动kinect2驱动节点 -->            
    <include file="$(find kinect2_bridge)/launch/kinect2_bridge.launch">
        <arg name="base_name"         value="kinect2"/>
        <arg name="sensor"            value=""/>
        <arg name="publish_tf"        value="true"/>
        <arg name="base_name_tf"      value="kinect2"/>
        <arg name="fps_limit"         value="-1.0"/>
        <arg name="calib_path"        value="$(find kinect2_bridge)/data/"/>
        <arg name="use_png"           value="false"/>
        <arg name="jpeg_quality"      value="90"/>
        <arg name="png_level"         value="1"/>
        <arg name="depth_method"      value="default"/>
        <arg name="depth_device"      value="-1"/>
        <arg name="reg_method"        value="default"/>
        <arg name="reg_device"        value="-1"/>
        <arg name="max_depth"         value="12.0"/>
        <arg name="min_depth"         value="0.1"/>
        <arg name="queue_size"        value="5"/>
        <arg name="bilateral_filter"  value="true"/>
        <arg name="edge_aware_filter" value="true"/>
        <arg name="worker_threads"    value="4"/>
    </include>  

  <!-- 启动深度图转换激光数据节点 -->
  <node pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" name="depthimage_to_laserscan" output="screen">
    <!--输入图像-->
    <remap from="image" to="/kinect2/qhd/image_depth_rect"/>
    <!--相关图像的相机信息。通常不需要重新变形,因为camera_info将从与图像相同的命名空间订阅。-->
    <remap from="camera_info" to="/kinect2/qhd/camera_info" />
    <!--输出激光数据的话题-->
    <remap from="scan" to="/scan" /> 

        <!--激光扫描的帧id。对于来自具有Z向前的“光学”帧的点云,该值应该被设置为具有X向前和Z向上的相应帧。-->
    <param name="output_frame_id" value="/kinect2_depth_frame"/>
    <!--用于生成激光扫描的像素行数。对于每一列,扫描将返回在图像中垂直居中的那些像素的最小值。-->
    <param name="scan_height" value="30"/>
    <!--返回的最小范围(以米为单位)。小于该范围的输出将作为-Inf输出。-->
    <param name="range_min" value="0.45"/>
    <!--返回的最大范围(以米为单位)。大于此范围将输出为+ Inf。-->
    <param name="range_max" value="8.00"/>
  </node>

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->

  <!-- 启动地图服务器载入地图 -->
    <node name="map_server" pkg="map_server" type="map_server" args="$(find bringup)/map/mymap.yaml"/>

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->

  <!-- 启动 move_base 节点 -->
  <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true">
    <rosparam file="$(find bringup)/nav_config/costmap_common_params.yaml" command="load" ns="global_costmap" />
    <rosparam file="$(find bringup)/nav_config/costmap_common_params.yaml" command="load" ns="local_costmap" />
    <rosparam file="$(find bringup)/nav_config/local_costmap_params.yaml" command="load" />
    <rosparam file="$(find bringup)/nav_config/global_costmap_params.yaml" command="load" />
    <rosparam file="$(find bringup)/nav_config/base_local_planner_params.yaml" command="load" />

    <!-- <rosparam file="$(find odom_tf_package)/config/nav_obstacles_params.yaml" command="load" /> -->
  </node>

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->  

  <!-- 启动 AMCL 节点 -->
  <node pkg="amcl" type="amcl" name="amcl" clear_params="true">
    <param name="use_map_topic" value="false"/>
    <!-- Publish scans from best pose at a max of 10 Hz -->
    <param name="odom_model_type" value="diff"/>
    <param name="odom_alpha5" value="0.1"/>
    <param name="gui_publish_rate" value="10.0"/>
    <param name="laser_max_beams" value="60"/>
    <param name="laser_max_range" value="12.0"/>
    <param name="min_particles" value="500"/>
    <param name="max_particles" value="2000"/>
    <param name="kld_err" value="0.05"/>
    <param name="kld_z" value="0.99"/>
    <param name="odom_alpha1" value="0.2"/>
    <param name="odom_alpha2" value="0.2"/>
    <!-- translation std dev, m -->
    <param name="odom_alpha3" value="0.2"/>
    <param name="odom_alpha4" value="0.2"/>
    <param name="laser_z_hit" value="0.5"/>
    <param name="laser_z_short" value="0.05"/>
    <param name="laser_z_max" value="0.05"/>
    <param name="laser_z_rand" value="0.5"/>
    <param name="laser_sigma_hit" value="0.2"/>
    <param name="laser_lambda_short" value="0.1"/>
    <param name="laser_model_type" value="likelihood_field"/>
    <!-- <param name="laser_model_type" value="beam"/> -->
    <param name="laser_likelihood_max_dist" value="2.0"/>
    <param name="update_min_d" value="0.25"/>
    <param name="update_min_a" value="0.2"/>

    <param name="odom_frame_id" value="odom"/>

    <param name="resample_interval" value="1"/>
    <!-- Increase tolerance because the computer can get quite busy -->
    <param name="transform_tolerance" value="1.0"/>
    <param name="recovery_alpha_slow" value="0.0"/>
    <param name="recovery_alpha_fast" value="0.0"/>
    <!-- scan topic -->
    <remap from="scan" to="scan"/>
  </node>

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->

  <!-- 启动基础控制器节点:发布里程计,控制小车 -->
    <node name="base_controller" pkg="base_controller" type="base_controller"/>

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->

    <!-- tf 转换 -->
    <!-- static_transform_publisher x y z yaw pitch roll frame_id child_frame_id period_in_ms -->  
  <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" />
  <node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0 0 0.5 0 0 0 base_link laser 50" />
  <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" />
  <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" />

<!-- ×××××××××××××××××××××××××××××××××××××××××××× 华丽分割线 ×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××× -->  
</launch>
  • 在我们之前的建的bringup/launch/下新建kinect2_nav_rviz_view.launch文件
$ cd ~/catkin_ws/src/bringup/launch/
$ touch kinect2_nav_rviz_view.launch
$ vim kinect2_nav_rviz_view.launch
  • 代码如下:
<?xml version="1.0"?>

<launch>

    <!--start rviz view -->
    <node name="rviz" pkg="rviz" type="rviz" args="-d $(find bringup)/rviz/kinect2_nav.rviz" />

</launch>
  • 还有在新建bringup/rviz/下新建kinect2_nav.rviz文件
$ cd ~/catkin_ws/src/bringup/rviz
$ touch kinect2_nav.rviz
$ vim kinect2_nav.rviz
  • 代码如下:
Panels:
  - Class: rviz/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /Odometry1
        - /RobotModel1/Links1/base_footprint1
        - /Marker1/Namespaces1
      Splitter Ratio: 0.652661
    Tree Height: 457
  - Class: rviz/Selection
    Name: Selection
  - Class: rviz/Tool Properties
    Expanded:
      - /2D Pose Estimate1
      - /2D Nav Goal1
    Name: Tool Properties
    Splitter Ratio: 0.428571
  - Class: rviz/Views
    Expanded:
      - /Current View1
    Name: Views
    Splitter Ratio: 0.5
  - Class: rviz/Time
    Experimental: false
    Name: Time
    SyncMode: 0
    SyncSource: ""
Visualization Manager:
  Class: ""
  Displays:
    - Alpha: 0.5
      Cell Size: 0.5
      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: 80
      Reference Frame: odom
      Value: true
    - Angle Tolerance: 0.1
      Class: rviz/Odometry
      Color: 221; 200; 14
      Enabled: true
      Keep: 100
      Length: 0.6
      Name: Odometry
      Position Tolerance: 0.1
      Topic: /odom
      Value: true
    - Angle Tolerance: 0.1
      Class: rviz/Odometry
      Color: 255; 85; 0
      Enabled: false
      Keep: 100
      Length: 0.6
      Name: Odometry EKF
      Position Tolerance: 0.1
      Topic: /odom_ekf
      Value: false
    - 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_footprint:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        base_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        camera_depth_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        camera_depth_optical_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        camera_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        camera_rgb_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        camera_rgb_optical_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        front_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        gyro_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        laser:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        left_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        left_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        leftfront_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        plate_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        plate_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        plate_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        plate_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        rear_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        right_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        right_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        rightfront_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        spacer_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        spacer_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        spacer_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        spacer_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_4_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_5_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_6_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_7_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_kinect_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_kinect_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        wall_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
      Name: RobotModel
      Robot Description: robot_description
      TF Prefix: ""
      Update Interval: 0
      Value: true
      Visual Enabled: true
    - Alpha: 0.2
      Class: rviz/Map
      Color Scheme: map
      Draw Behind: true
      Enabled: true
      Name: Map
      Topic: /map
      Value: true
    - Alpha: 1
      Buffer Length: 1
      Class: rviz/Path
      Color: 255; 0; 0
      Enabled: true
      Name: Local Plan
      Topic: /move_base/TrajectoryPlannerROS/local_plan
      Value: true
    - Alpha: 1
      Buffer Length: 1
      Class: rviz/Path
      Color: 0; 213; 0
      Enabled: true
      Name: Global Plan
      Topic: /move_base/TrajectoryPlannerROS/global_plan
      Value: true
    - Class: rviz/Marker
      Enabled: true
      Marker Topic: /waypoint_markers
      Name: Marker
      Namespaces:
        {}
      Queue Size: 100
      Value: true
    - Alpha: 1
      Autocompute Intensity Bounds: true
      Autocompute Value Bounds:
        Max Value: 0.304
        Min Value: 0.304
        Value: true
      Axis: Z
      Channel Name: intensity
      Class: rviz/LaserScan
      Color: 255; 255; 255
      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: LaserScan
      Position Transformer: XYZ
      Queue Size: 10
      Selectable: true
      Size (Pixels): 3
      Size (m): 0.01
      Style: Spheres
      Topic: /scan
      Use Fixed Frame: true
      Use rainbow: true
      Value: true
    - Alpha: 1
      Axes Length: 1
      Axes Radius: 0.1
      Class: rviz/Pose
      Color: 0; 255; 0
      Enabled: true
      Head Length: 0.1
      Head Radius: 0.15
      Name: Mouse Goal
      Shaft Length: 0.5
      Shaft Radius: 0.03
      Shape: Arrow
      Topic: /move_base/current_goal
      Value: true
    - Alpha: 1
      Axes Length: 1
      Axes Radius: 0.1
      Class: rviz/Pose
      Color: 0; 255; 0
      Enabled: true
      Head Length: 0.1
      Head Radius: 0.15
      Name: Goal Pose
      Shaft Length: 0.5
      Shaft Radius: 0.03
      Shape: Arrow
      Topic: /move_base_simple/goal
      Value: true
    - Arrow Length: 0.3
      Class: rviz/PoseArray
      Color: 255; 25; 0
      Enabled: false
      Name: Pose Array
      Topic: ""
      Value: false
  Enabled: true
  Global Options:
    Background Color: 0; 0; 0
    Fixed Frame: map
    Frame Rate: 30
  Name: root
  Tools:
    - Class: rviz/MoveCamera
    - Class: rviz/Interact
      Hide Inactive Objects: true
    - Class: rviz/Select
    - Class: rviz/SetInitialPose
      Topic: /initialpose
    - Class: rviz/SetGoal
      Topic: /move_base_simple/goal
  Value: true
  Views:
    Current:
      Angle: -1.57
      Class: rviz/TopDownOrtho
      Name: Current View
      Near Clip Distance: 0.01
      Scale: 205.257
      Target Frame: <Fixed Frame>
      Value: TopDownOrtho (rviz)
      X: 0.755064
      Y: 0.634474
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 695
  Hide Left Dock: false
  Hide Right Dock: false
  QMainWindow State: 000000ff00000000fd00000004000000000000012d00000258fc0200000005fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006400fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000198000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000004100000258000000dd00ffffff000000010000010f00000270fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000270000000b000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004a00000003efc0100000002fb0000000800540069006d00650000000000000004a0000002f600fffffffb0000000800540069006d00650100000000000004500000000000000000000002b80000025800000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  Selection:
    collapsed: false
  Time:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: false
  Width: 1003
  X: 787
  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现在应该朝着你的目录自主前进。尝试指定一个目标,并走在前面,看看它如何反应的动态障碍。
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/48810.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

WebRTC学习笔记七 pion/webrtc

一、Usage用法 1.使用Go Modules Go Modules are mandatory for using Pion WebRTC. So make sure you set export GO111MODULEon, and explicitly specify /v2 or /v3 when importing. 2.常见示例 example applications contains code samples of common things people bu…

Web3.0带来天翻地覆的变化?全面科普!所谓的Web3.0到底是什么?

Web3.0在2021年尾声突然蹿红&#xff0c;在美国国会的听证会里&#xff0c;一句“我们如何确保web3革命发生在美国”引发了大家对于Web3.0的关注&#xff0c;而后马斯克一篇内容为“有人看过web3.0吗? 我没有找到”的推文&#xff0c;将关于Web3.0的讨论推向了高潮。 甚至于这…

零基础入门JavaWeb——CSS相关知识

一、CSS的作用 SS是用于设置HTML页面标签的样式&#xff0c;用于美化HTML页面。 二、CSS的引入方式 2.1 行内样式 在要设置样式的标签中添加style属性&#xff0c;编写css样式&#xff1b;行内样式仅对当前标签生效。 <div style"border: 1px solid red;width: 10…

「MySQL高级篇」SQL优化

大家好&#xff0c;我是Zhan&#xff0c;一名个人练习时长一年半的大二后台练习生&#xff0c;最近在学MySQL高级篇&#xff0c;欢迎各路大佬一起交流讨论 &#x1f449;本篇速览 在前面对索引的的学习中&#xff0c;我们学习到了从MySQL“底层”优化了SQL执行查询的算法&…

认识微服务

认识微服务&#xff1a; 背景&#xff1a;随着互联网行业的发展&#xff0c;对服务的要求也越来越高&#xff0c;服务架构也从单体架构逐渐演变为现在流行的微服务架构。 这些架构之间有怎样的差别呢&#xff1f; 单体架构&#xff1a; 单体架构&#xff1a;将业务的所有功…

颜色的感知

人体内有三种颜色感知细胞&#xff0c;能感知红、绿、蓝三种颜色。 人体内还有一种光强感知细胞&#xff0c;这种关光的波长刚好和绿光接近。 椎状感应颜色 柱状感应强度。

[附源码]Python计算机毕业设计Django的专业技能认证系统

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;…

RocketMQ 的消费者类型详解与最佳实践

作者&#xff1a;凌楚 在 RocketMQ 5.0 中&#xff0c;更加强调了客户端类型的概念&#xff0c;尤其是消费者类型。为了满足多样的 RocketMQ 中一共有三种不同的消费者类型&#xff0c;分别是 PushConsumer、SimpleConsumer 和 PullConsumer。不同的消费者类型对应着不同的业务…

AI美颜SDK算法详解

AI美颜SDK是近几年兴起的新兴美颜方式&#xff0c;区别于传统的美颜工具&#xff0c;AI美颜采用人工智能的深度学习算法实现智能化美颜&#xff0c;下文小编将为大家讲解一下AI美颜SDK相关的知识。 一、与传统美颜的区别之处 从宏观角度来讲&#xff0c;AI美颜技术与传统美颜…

高维多元时序数据聚类

1. 简介 收集数据的能力不断增强&#xff0c;使我们有可能收集大量的异构数据。在可用的异构数据中&#xff0c;时间序列代表着尚未被充分探索的信息母体。当前的数据挖掘技术在分析时间序列时存在多个缺点&#xff0c;尤其是在应同时分析多个时间序列&#xff08;即多维时间序…

C# Winform控件库分享,免费开源,支持中文!(附DLL及教程)

这款控件包是基于MaterialSkin2二次开发的&#xff0c;可以更换想要的皮肤主题&#xff0c;一键转换暗色系&#xff0c;还拥有非常炫酷的动画&#xff0c;非常好看&#xff0c;原本的MaterialSkin2是国外团队开发的&#xff0c;不支持中文&#xff0c;所以我在里面加了几款中文…

springboot学生宿舍报修换宿管理系统-宿管

宿舍管理系统设计与实现由管理员和学生、宿管交互构成。学生对于本系统的使用&#xff0c;学生可以通过系统注册、登录&#xff0c;修改个人信息&#xff0c;查看学生宿舍、消息通知、换宿申请等功能。 宿管对于本系统的使用&#xff0c;宿管可以通过系统登录&#xff0c;修改个…

RabbitMQ如何确保消息发送 ? 消息接收?

发送方确认机制&#xff1a; 信道需要设置为 confirm 模式&#xff0c;则所有在信道上发布的消息都会分配⼀个唯⼀ ID。⼀旦消息被投递到queue&#xff08;可持久化的消息需要写⼊磁盘&#xff09;&#xff0c;信道会发送⼀个确认给⽣产者&#xff08;包含消息唯⼀ ID&#xff…

Codeforces Round #719 (Div. 3) E. Arranging The Sheep

翻译&#xff1a; 你正在玩“安排羊”游戏。这个游戏的目标是让羊排好队。游戏中的关卡是由长度为&#x1d45b;的字符串描述的&#xff0c;由角色的’组成。(空格)和*(绵羊)。在一个动作中&#xff0c;你可以移动任何羊向左或向右移动一个方格&#xff0c;如果相应的方格存在…

Paper写作怎么按照要求来具体分析?

许多留学生通常面临写学术Paper的问题&#xff0c;而大多数都不知道Paper如何写&#xff0c;因为写Paper并不是容易的事情。学术Paper应按照严格要求和规则撰写&#xff0c;而其应提供扎实&#xff0c;有争议的论点&#xff0c;然后由相关的无论是来自其他来源还是自己研究的证…

流媒体直播播放协议:HLS、RTMP、HTTP-FLV

流媒体直播播放协议&#xff1a;HLS、RTMP、HTTP-FLV一、推拉流二、协议介绍1. HLS2. RTMP3. HDL (HTTP-FLV)一、推拉流 在开始之前&#xff0c;先把流媒体服务中的双端关系说一下&#xff1a;在一个完整的流媒体服务框架中&#xff0c;角色就是“两端加一服”。推流端、拉流端…

httpclient

1.什么是httpclient HttpClient 是Apache Jakarta Common 下的子项目&#xff0c;可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包&#xff0c;并且它支持 HTTP 协议最新的版本和建议。 2.http请求&#xff08;结合spring的注解&#xff09; 2-1GET请…

相对位置编码之RPR式:《Self-Attention with Relative Position Representations》论文笔记

&#x1f604; 额&#xff0c;本想学学XLNet的&#xff0c;然后XLNet又是以transformer-XL为主要结构&#xff0c;然后transformer-XL做了两个改进&#xff1a;一个是结构上做了segment-level的循环机制&#xff0c;一个是在attention机制里引入了相对位置编码信息来避免不同se…

AutoCAD Electrical 2022—源箭头和目标箭头

在一张图纸上插入源 箭头&#xff1b; 选中一根导线&#xff1b; 如果源和目标在同一张图纸上&#xff0c;则可以点击确定&#xff0c;插入目标箭头&#xff1b; 如果不在同一张图纸上&#xff0c;则点击否&#xff0c;后面在插入目标箭头&#xff1b; 在另一张图纸上插入目标…

学习笔记:引用

概念 引用的作用是给一个变量起别名 格式&#xff1a; type & 别名 原名 引用必须初始化&#xff0c;在初始化后不能改变 int &b;ba;错误 int& b a; bc;不是将b从a的别名变为c的别名 而是将c的值赋给a int a 10; int& b a; b 20;//用别名改数据&…