首页 > 其他分享 >基于领航-跟随模式的无人车编队仿真与导航

基于领航-跟随模式的无人车编队仿真与导航

时间:2024-08-08 09:29:08浏览次数:16  
标签:仿真 rosnoetic move camera base 领航 parameter VirtualBox 编队

基于领航-跟随模式的无人车编队仿真与导航

1. 查看系统环境

要运行本仿真程序,需要保证当前环境为ubuntu18.04+ros-melodic-desktop-full

查看ubuntu版本:

rosnoetic@rosnoetic-VirtualBox:~$ lsb_release -a

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.6 LTS
Release:	18.04
Codename:	bionic

可知,当前ubuntu版本满足18.04

查看ros版本:

rosnoetic@rosnoetic-VirtualBox:~$ rosversion -d

melodic

可知,当前ros版本满足melodic

2. 功能包准备

请先安装相关的ROS功能包:

  • 安装gmapping包(用于构建地图):sudo apt install ros-<ROS版本>-gmapping
rosnoetic@rosnoetic-VirtualBox:~$ sudo apt install ros-melodic-gmapping
  • 安装地图服务包(用于保存与读取地图):sudo apt install ros-<ROS版本>-map-server
rosnoetic@rosnoetic-VirtualBox:~$ sudo apt install ros-melodic-map-server
  • 安装navigation包(用于定位以及路径规划):sudo apt install ros-<ROS版本>-navigation
rosnoetic@rosnoetic-VirtualBox:~$ sudo apt install ros-melodic-navigation
  • 安装teleop-twist-keyboard包(用于键盘控制小车):sudo apt install ros-<ROS版本>-teleop-twist-keyboard
rosnoetic@rosnoetic-VirtualBox:~$ sudo apt install ros-melodic-teleop-twist-keyboard
  • 安装joint_state_publisher_gui包,需要注意自己当前的ros版本:
rosnoetic@rosnoetic-VirtualBox:~$ sudo apt-get install ros-melodic-joint-state-publisher-gui

3. 添加并编译机器人源码

multirobot_formation.zip压缩包拖拉至虚拟机的主文件夹

解压multirobot_formation.zip压缩包

multirobot_formation文件夹下的builddevel文件夹删除

在终端中重新编译multirobot_formation项目

rosnoetic@rosnoetic-VirtualBox:~$ cd multirobot_formation/

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ catkin_make

接着在终端中执行如下指令,从而可以用vscode打开multirobot_formation项目

rosnoetic@rosnoetic-VirtualBox:~$ cd multirobot_formation/

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ code .

快捷键ctrl+shift+B调用编译,选择:catkin_make:build

可以点击配置设置为默认,修改.vscode/tasks.json文件

使用如下内容进行覆盖

{
// 有关 tasks.json 格式的文档,请参见
    // https://go.microsoft.com/fwlink/?LinkId=733558
    "version": "2.0.0",
    "tasks": [
        {
            "label": "catkin_make:debug", //代表提示的描述性信息
            "type": "shell",  //可以选择shell或者process,如果是shell代码是在shell里面运行一个命令,如果是process代表作为一个进程来运行
            "command": "catkin_make",//这个是我们需要运行的命令
            "args": [],//如果需要在命令后面加一些后缀,可以写在这里,比如-DCATKIN_WHITELIST_PACKAGES=“pac1;pac2”
            "group": {"kind":"build","isDefault":true},
            "presentation": {
                "reveal": "always"//可选always或者silence,代表是否输出信息
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

4. 运行代码

4.1 启动无人车仿真程序

ctrl+~打开vscode终端,执行:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_description display_ares_laser.launch

ctrl+~打开vscode终端,执行:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_description display_ares_laser_gazebo.launch

ctrl+~打开vscode终端,执行:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_description display_ares_laser_gazebo.launch

  • 如果在启动仿真的过程中,出现错误:[Err] [REST.cc:205] Error in REST request

    解决方案

    rosnoetic@rosnoetic-VirtualBox:~$  sudo gedit ~/.ignition/fuel/config.yaml
    

    删除

    url: https://api.ignitionfuel.org

    添加

    url: https://api.ignitionrobotics.org

4.2 启动无人车键盘控制程序

键盘控制由launch文件中的<node name="ares_teleop" pkg="ares_teleop" type="ares_teleop.py" output="screen" />实现

ctrl+~打开vscode终端,执行:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_gazebo ares_cloister_gazebo_teleop.launch

vscode终端中,敲击键盘”i“,可以使中间的无人车向前方运动,敲击键盘”k“,可以使无人车暂停。

4.3 启动无人车导航程序

4.3.1 启动仿真程序

ctrl+~打开vscode终端,执行如下指令打开仿真场景:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_gazebo ares_cloister_gazebo.launch

新增vscode终端,执行如下指令打开导航:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_navigation navigation_demo.launch

该程序可以打开rviz仿真模块,需要等待片刻,使得所有的组件话题信息等待完成

使用Rviz界面上的"2D Nav Goal"工具指定导航的目标位置与方向,等待小车移动到目标位置。

4.3.2 查看坐标变换关系

首先调用rospack find tf2_tools查看是否包含该功能包,

rosnoetic@rosnoetic-VirtualBox:~$ rospack find tf2_tools

[rospack] Error: package 'tf2_tools' not found

如果没有,请使用如下命令进行安装:

rosnoetic@rosnoetic-VirtualBox:~$ sudo apt update

rosnoetic@rosnoetic-VirtualBox:~$ sudo apt install ros-melodic-tf2-tools

运行如下命令:

rosnoetic@rosnoetic-VirtualBox:~$ rosrun tf2_tools view_frames.py 

[INFO] [1695085300.825369]: Listening to tf data during 5 seconds...
[INFO] [1695085305.836649]: Generating graph in frames.pdf file...

查看当前目录会生成一个frames.pdf

4.3.3 查看话题列表

查看发布的话题列表

rosnoetic@rosnoetic-VirtualBox:~$ rostopic list

/amcl/parameter_descriptions
/amcl/parameter_updates
/amcl_pose

/ares1/base_pose_ground_truth
/ares1/camera/camera_info
/ares1/camera/image_raw
/ares1/camera/image_raw/compressed
/ares1/camera/image_raw/compressed/parameter_descriptions
/ares1/camera/image_raw/compressed/parameter_updates
/ares1/camera/image_raw/compressedDepth
/ares1/camera/image_raw/compressedDepth/parameter_descriptions
/ares1/camera/image_raw/compressedDepth/parameter_updates
/ares1/camera/image_raw/theora
/ares1/camera/image_raw/theora/parameter_descriptions
/ares1/camera/image_raw/theora/parameter_updates
/ares1/camera/parameter_descriptions
/ares1/camera/parameter_updates
/ares1/cmd_vel
/ares1/joint_states
/ares1/odom
/ares1/scan

/ares2/base_pose_ground_truth
/ares2/camera/camera_info
/ares2/camera/image_raw
/ares2/camera/image_raw/compressed
/ares2/camera/image_raw/compressed/parameter_descriptions
/ares2/camera/image_raw/compressed/parameter_updates
/ares2/camera/image_raw/compressedDepth
/ares2/camera/image_raw/compressedDepth/parameter_descriptions
/ares2/camera/image_raw/compressedDepth/parameter_updates
/ares2/camera/image_raw/theora
/ares2/camera/image_raw/theora/parameter_descriptions
/ares2/camera/image_raw/theora/parameter_updates
/ares2/camera/parameter_descriptions
/ares2/camera/parameter_updates
/ares2/cmd_vel
/ares2/joint_states
/ares2/odom
/ares2/scan

/ares3/base_pose_ground_truth
/ares3/camera/camera_info
/ares3/camera/image_raw
/ares3/camera/image_raw/compressed
/ares3/camera/image_raw/compressed/parameter_descriptions
/ares3/camera/image_raw/compressed/parameter_updates
/ares3/camera/image_raw/compressedDepth
/ares3/camera/image_raw/compressedDepth/parameter_descriptions
/ares3/camera/image_raw/compressedDepth/parameter_updates
/ares3/camera/image_raw/theora
/ares3/camera/image_raw/theora/parameter_descriptions
/ares3/camera/image_raw/theora/parameter_updates
/ares3/camera/parameter_descriptions
/ares3/camera/parameter_updates
/ares3/cmd_vel
/ares3/joint_states
/ares3/odom
/ares3/scan

/clock
/diagnostics

/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/set_link_state
/gazebo/set_model_state
/initialpose

/map
/map_metadata
/map_updates

/move_base/DWAPlannerROS/cost_cloud
/move_base/DWAPlannerROS/global_plan
/move_base/DWAPlannerROS/local_plan
/move_base/DWAPlannerROS/parameter_descriptions
/move_base/DWAPlannerROS/parameter_updates
/move_base/DWAPlannerROS/trajectory_cloud
/move_base/NavfnROS/plan
/move_base/TrajectoryPlannerROS/local_plan
/move_base/cancel
/move_base/current_goal
/move_base/feedback
/move_base/global_costmap/costmap
/move_base/global_costmap/costmap_updates
/move_base/global_costmap/footprint
/move_base/global_costmap/inflation_layer/parameter_descriptions
/move_base/global_costmap/inflation_layer/parameter_updates
/move_base/global_costmap/obstacle_layer/parameter_descriptions
/move_base/global_costmap/obstacle_layer/parameter_updates
/move_base/global_costmap/parameter_descriptions
/move_base/global_costmap/parameter_updates
/move_base/global_costmap/static_layer/parameter_descriptions
/move_base/global_costmap/static_layer/parameter_updates
/move_base/goal
/move_base/local_costmap/costmap
/move_base/local_costmap/costmap_updates
/move_base/local_costmap/footprint
/move_base/local_costmap/inflation_layer/parameter_descriptions
/move_base/local_costmap/inflation_layer/parameter_updates
/move_base/local_costmap/obstacle_layer/parameter_descriptions
/move_base/local_costmap/obstacle_layer/parameter_updates
/move_base/local_costmap/parameter_descriptions
/move_base/local_costmap/parameter_updates
/move_base/parameter_descriptions
/move_base/parameter_updates
/move_base/result
/move_base/status
/move_base_simple/goal

/odom
/particlecloud
/rosout
/rosout_agg
/tf
/tf_static
/waypoint_markers
/waypoint_markers_array

4.3.4 查看计算图

启动rqt_graph

rosnoetic@rosnoetic-VirtualBox:~$ rqt_graph

结果如下图所示:

圆圈是节点,方框是话题,箭头表示数据订阅发布的方向

4.4 启动无人车编队控制程序

ctrl+~打开vscode终端,执行如下指令打开仿真场景:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch ares_gazebo ares_playground_gazebo.launch

新增vscode终端,执行如下指令打开编队控制:

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ source ./devel/setup.bash 

rosnoetic@rosnoetic-VirtualBox:~/multirobot_formation$ roslaunch stage_first OnYourMarkGetSetGo.launch

运行后会提示如下错误,但是并不会影响功能

接着就可以在gazebo界面中看到小车运动起来,并最终呈现一字型的队形

标签:仿真,rosnoetic,move,camera,base,领航,parameter,VirtualBox,编队
From: https://www.cnblogs.com/windandchimes/p/18348288

相关文章