SLAM建图的那些事

这一节将来总结关于SLAM构建地图的相关知识,从具体的场景来写,然后对于用到的知识将会详细补充。
在构建地图时用到的launch文件是exploring_slam_demo,首先是他的代码部分:



    

    
    

    
    


很容易看出是由三部分组成,以下分三块来讲

一 gmapping.launch文件

路径:mbot_navigation/launch
代码:


      // laser的topic名称,与自己的激光的topic相对应 

      //启动slam的节点
    
        
          //地图更新的频率,两次scanmatch的间隔,地图更新也受scanmach的影响,如果scanmatch没有成功的话,是不会更新地图的
        
          // 传感器的最大范围。如果传感器范围内没有障碍物的区域在地图中显示为自由空间,则设置maxUrange <实际传感器的最大范围<= maxRange。
          // //set maxUrange < maximum range of the real sensor <= maxRange 激光的最大可用范围。光束被裁剪为该值。
        
         // 内核中要查找一个对应关系
          //optimize机器人移动的初始值(距离)
          // optimize机器人移动的初始值(角度)
          ////icp的迭代次数
         //用于计算的波束可能性的sigma
         //在评估可能性时使用的增益,用于平滑重采样效果
          ////为0,表示所有的激光都处理,尽可能为零,如果计算压力过大,可以改成1
          //作为平移函数的平移误差(rho / rho)
           //作为旋转的函数的平移误差(rho / theta)
          //作为平移函数的旋转中的测量误差(θ/ rho)
          // 作为旋转的函数的旋转中的测量误差(θ/θ)
          ////机器人移动linearUpdate距离,进行scanmatch(每次[机器人翻译远处时,处理一次扫描)
            //机器人选装angularUpdate角度,进行scanmatch  (俗话说:每次机器人旋转这么远时处理一次扫描)
          //如果上次扫描处理的时间早于更新时间(秒),则处理扫描。小于零的值将关闭基于时间的更新。
          //基于Neff的重采样阈值
          //很重要,粒子个数
          //map初始化的大小
          //初始地图大小Y最小值
          // 初始地图大小X最大值
          //初始地图大小Y最大值
          //地图的分辨率
          //可能性的平移采样范围
          // 可能性的平移采样步骤
          //角度采样范围的可能性
          //角度采样步骤的可能性
          //  激光扫描从中创建地图
    

上面的注释来源于:gmapping介绍及参数说明
使用slam_gmapping节点,需要移动机器人提供里程计数据,并且机器人配备有固定激光测距仪。slam_gmapping节点将每个传入的扫描转化为odom(里程计)TF框架,可以参照:TF参照
节点:

  • slam_gmapping
    该slam_gmapping节点发生在sensor_msgs /激光扫描信息,并建立一个映射(nav_msgs / OccupancyGrid)。可以通过ROS 主题或服务检索地图。
  • 订阅主题
  1. tf(tf / tfMessage)
    需要进行激光,基准和测距的相关框架转换
  2. scan (sensor_msgs / LaserScan)
    激光扫描从中创建地图
  • 发布主题
  1. scan (sensor_msgs / LaserScan)
    激光扫描从中创建地图
  2. map(nav_msgs / OccupancyGrid)
    从此主题获取地图数据,将其锁定并定期更新
  3. 〜entropy (std_msgs / Float64)
    机器人姿态分布的熵的估计值(较高的值表示较大的不确定性)。
  • 服务
    dynamic_map(nav_msgs / GetMap)
    调用此服务以获取地图数据
  • 必需的tf转换
  1. <传入激光数据的框架> → base_link
    通常是固定值,由robot_state_publisher或tf static_transform_publisher定期广播。
  2. base_link → odom
    通常由里程表系统(例如,移动基座的驱动器)提供,
  • 提供tf转换
    地图 → odom
    在地图框架内的机器人姿势的当前估计
    软件包摘要:

这个包包含一个用于OpenSlam的Gmapping的ROS包。gmapping包提供基于激光的SLAM(同时定位和建图),作为称为slam_gmapping的ROS节点。使用slam_gmapping,您可以从移动机器人收集的激光和姿势数据创建2-D占用网格地图(如建筑平面图)。

重要参数说明:

  • particles (int, default: 30) gmapping算法中的粒子数,因为gmapping使用的是粒子滤波算法,粒子在不断地迭代更新,所以选取一个合适的粒子数可以让算法在保证比较准确的同时有较高的速度。
  • minimumScore (float, default: 0.0) 最小匹配得分,这个参数很重要,它决定了对激光的一个置信度,越高说明对激光匹配算法的要求越高,激光的匹配也越容易失败而转去使用里程计数据,而设的太低又会使地图中出现大量噪声,所以需要权衡调整。(在这个launch文件中没有用到这个参数具体原因还不知道)

二 move_base.launch 文件

路径:mbot_navigation/launch
代码:



  
    
    
    
    
    
  
 

路径:mbot_navigation/config/mbot
代码说明:

  • costmap_common_params.yaml 代价地图通用配置文件
  • global_costmap_params.yaml 全局代价地图配置文件
  • local_costmap_params.yaml 本地代价地图配置文件
  • base_local_planner_params.yaml 本地规划器配置文件
    具体关于每一个问价参照博客;move_base配置参数
    关于move_base的说明参照move_base

三 运行rviz

路径:mbot_navigation/rviz
代码:

Panels:
  - Class: rviz/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /RobotModel1/Links1/base_footprint1
        - /Pose Array1
      Splitter Ratio: 0.652661026
    Tree Height: 691
  - Class: rviz/Selection
    Name: Selection
  - Class: rviz/Tool Properties
    Expanded:
      - /2D Pose Estimate1
      - /2D Nav Goal1
    Name: Tool Properties
    Splitter Ratio: 0.428570986
  - 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: 0.5
      Class: rviz/Grid
      Color: 0; 0; 0
      Enabled: true
      Line Style:
        Line Width: 0.0299999993
        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.100000001
      Class: rviz/Odometry
      Covariance:
        Orientation:
          Alpha: 0.5
          Color: 255; 255; 127
          Color Style: Unique
          Frame: Local
          Offset: 1
          Scale: 1
          Value: true
        Position:
          Alpha: 0.300000012
          Color: 204; 51; 204
          Scale: 1
          Value: true
        Value: true
      Enabled: false
      Keep: 100
      Name: Odometry
      Position Tolerance: 0.100000001
      Shape:
        Alpha: 1
        Axes Length: 1
        Axes Radius: 0.100000001
        Color: 255; 25; 0
        Head Length: 0.300000012
        Head Radius: 0.100000001
        Shaft Length: 1
        Shaft Radius: 0.0500000007
        Value: Arrow
      Topic: /odom
      Unreliable: false
      Value: false
    - Angle Tolerance: 0.100000001
      Class: rviz/Odometry
      Covariance:
        Orientation:
          Alpha: 0.5
          Color: 255; 255; 127
          Color Style: Unique
          Frame: Local
          Offset: 1
          Scale: 1
          Value: true
        Position:
          Alpha: 0.300000012
          Color: 204; 51; 204
          Scale: 1
          Value: true
        Value: true
      Enabled: false
      Keep: 100
      Name: Odometry EKF
      Position Tolerance: 0.100000001
      Shape:
        Alpha: 1
        Axes Length: 1
        Axes Radius: 0.100000001
        Color: 255; 25; 0
        Head Length: 0.300000012
        Head Radius: 0.100000001
        Shaft Length: 1
        Shaft Radius: 0.0500000007
        Value: Arrow
      Topic: /odom
      Unreliable: false
      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
        back_caster_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        base_footprint:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        base_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        front_caster_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        laser_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        left_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        right_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
      Name: RobotModel
      Robot Description: robot_description
      TF Prefix: ""
      Update Interval: 0
      Value: true
      Visual Enabled: true
    - Alpha: 0.699999988
      Class: rviz/Map
      Color Scheme: map
      Draw Behind: true
      Enabled: true
      Name: Map
      Topic: /map
      Unreliable: false
      Use Timestamp: false
      Value: true
    - Alpha: 1
      Buffer Length: 1
      Class: rviz/Path
      Color: 255; 0; 0
      Enabled: true
      Head Diameter: 0.300000012
      Head Length: 0.200000003
      Length: 0.300000012
      Line Style: Lines
      Line Width: 0.0299999993
      Name: Local Plan
      Offset:
        X: 0
        Y: 0
        Z: 0
      Pose Color: 255; 85; 255
      Pose Style: None
      Radius: 0.0299999993
      Shaft Diameter: 0.100000001
      Shaft Length: 0.100000001
      Topic: /move_base/TrajectoryPlannerROS/local_plan
      Unreliable: false
      Value: true
    - Alpha: 1
      Buffer Length: 1
      Class: rviz/Path
      Color: 0; 213; 0
      Enabled: true
      Head Diameter: 0.300000012
      Head Length: 0.200000003
      Length: 0.300000012
      Line Style: Lines
      Line Width: 0.0299999993
      Name: Global Plan
      Offset:
        X: 0
        Y: 0
        Z: 0
      Pose Color: 255; 85; 255
      Pose Style: None
      Radius: 0.0299999993
      Shaft Diameter: 0.100000001
      Shaft Length: 0.100000001
      Topic: /move_base/TrajectoryPlannerROS/global_plan
      Unreliable: false
      Value: true
    - Alpha: 1
      Arrow Length: 0.300000012
      Axes Length: 0.300000012
      Axes Radius: 0.00999999978
      Class: rviz/PoseArray
      Color: 170; 255; 127
      Enabled: true
      Head Length: 0.0700000003
      Head Radius: 0.0299999993
      Name: Pose Array
      Shaft Length: 0.230000004
      Shaft Radius: 0.00999999978
      Shape: Arrow (Flat)
      Topic: /particlecloud
      Unreliable: false
      Value: true
    - Alpha: 1
      Autocompute Intensity Bounds: true
      Autocompute Value Bounds:
        Max Value: 0.30399999
        Min Value: 0.30399999
        Value: true
      Axis: Z
      Channel Name: intensity
      Class: rviz/LaserScan
      Color: 255; 0; 0
      Color Transformer: FlatColor
      Decay Time: 0
      Enabled: true
      Invert Rainbow: false
      Max Color: 255; 255; 255
      Max Intensity: 4096
      Min Color: 0; 0; 0
      Min Intensity: 0
      Name: LaserScan
      Position Transformer: XYZ
      Queue Size: 10
      Selectable: true
      Size (Pixels): 3
      Size (m): 0.00999999978
      Style: Points
      Topic: /scan
      Unreliable: false
      Use Fixed Frame: true
      Use rainbow: true
      Value: true
    - Alpha: 1
      Axes Length: 1
      Axes Radius: 0.100000001
      Class: rviz/Pose
      Color: 0; 255; 0
      Enabled: true
      Head Length: 0.100000001
      Head Radius: 0.150000006
      Name: Goal Pose
      Shaft Length: 0.5
      Shaft Radius: 0.0299999993
      Shape: Arrow
      Topic: /move_base_simple/goal
      Unreliable: false
      Value: true
    - Alpha: 0.699999988
      Class: rviz/Map
      Color Scheme: costmap
      Draw Behind: false
      Enabled: true
      Name: Inflated Obstacles
      Topic: /move_base/local_costmap/costmap
      Unreliable: false
      Use Timestamp: false
      Value: true
    - Class: rviz/Marker
      Enabled: true
      Marker Topic: /waypoint_markers
      Name: Marker
      Namespaces:
        {}
      Queue Size: 100
      Value: true
  Enabled: true
  Global Options:
    Background Color: 0; 0; 0
    Default Light: true
    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: -6.3000164
      Class: rviz/TopDownOrtho
      Enable Stereo Rendering:
        Stereo Eye Separation: 0.0599999987
        Stereo Focal Distance: 1
        Swap Stereo Eyes: false
        Value: false
      Invert Z Axis: false
      Name: Current View
      Near Clip Distance: 0.00999999978
      Scale: 52.4497948
      Target Frame: 
      Value: TopDownOrtho (rviz)
      X: 0.412709981
      Y: -2.02176332
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 904
  Hide Left Dock: false
  Hide Right Dock: false
  QMainWindow State: 000000ff00000000fd00000004000000000000016a00000342fc0200000005fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000198000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000002800000342000000d700ffffff000000010000010f00000270fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000270000000ad00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004a00000003efc0100000002fb0000000800540069006d00650000000000000004a00000030000fffffffb0000000800540069006d00650100000000000004500000000000000000000004280000034200000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  Selection:
    collapsed: false
  Time:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: false
  Width: 1432
  X: 2298
  Y: 239

备注:这一块代码属于建立rviz界面中的控件,添加控件属性,订阅话题。如下图左侧的栏目框:


SLAM建图的那些事_第1张图片
Screenshot from 2019-01-24 11-05-05.png

以上是mbot_navigation功能包三大块。

你可能感兴趣的:(SLAM建图的那些事)