最新消息:网站支持在线创作,微信分享,请点击【创作中心】编辑作品。

搭建ROS小车底盘B-使用Kinect2导航

ROBOTS/其他机器人 少儿编程 410浏览 0评论
搭建ROS小车底盘B

搭建ROS小车底盘B-使用Kinect2导航

说明:

  • 介绍利用kinect2实现自主导航

安装依赖包

  • 安装一下所需的包
$ cd ~/catkin_ws/src
$ git clone  https://github.com/ros-planning/navigation/tree/indigo-devel
$ 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
  • 启动成功的话会看到一下画面:

搭建ROS小车底盘B-使用Kinect2导航

您必须 登录 才能发表评论!