1、进入ROS工作空间的src目录下,下载racecar功能包
cd ~/catkin_ws/src
git clone https://github.com/xmy0916/racecar.git
这个过程很慢,建议使用手机热点下载
1、安装driver_base控件
sudo apt-get install ros-melodic-driver-base
2、安装controllers控件
sudo apt-get install ros-melodic-gazebo-ros-control
sudo apt-get install ros-melodic-effort-controllers
sudo apt-get install ros-melodic-joint-state-controller
3、安装ackermann_msgs控件
sudo apt-get install ros-melodic-ackermann-msgs
4、安装planne控件
sudo apt-get install ros-melodic-global-planner
sudo apt-get install ros-melodic-teb-local-planner
进入ROS工作空间编译
cd catkin_ws
catkin_make
cd catkin_ws
source ./devel/setup.bash #程序注册
roslaunch racecar_gazebo racecar.launch
出现上图即运行成功,将鼠标移至窗口,根据提示,按下WASD按键即可控制小车移动。
1、打开终端,进入gazebo
gazebo
2、点击Edit—>Building Editor创建跑道模型
保存跑道模型
这里我命名为track
进入ROS空间下运行小车模型
cd ~/catkin_ws
source ./devel/setup.bash
roslaunch racecar_gazebo racecar.launch
点击insert—>track,即可将跑道模型拖到小车模型中。注意:将小车放到适当的位置。
保存文件,点击File—>Save World As
将world文件放到racecar功能包的racecar_gazebo—>world的目录下
进入racecar功能包的racecar_gazebo—>launch的目录下,创建launch文件,配置跑道参数
cd ~/catkin_ws/src/racecar/racecar_gazebo/launch
touch track.launch
gedit track.launch
在track.launch文件中添加以下内容
<?xml version="1.0"?>
<launch>
<!-- Launch the racecar -->
<include file="$(find racecar_gazebo)/launch/racecar.launch">
<arg name="world_name" value="track"/>
</include>
</launch>
保存关闭,完成上面的步骤之后就可以运行跑道模型,控制小车跑图了
cd ~/catkin_ws
source ./devel/setup.bash
roslaunch racecar_gazebo track.launch
上面一步的终端保持开启状态,下面开始进行gmapping建图
roslaunch racecar_gazebo slam_gmapping.launch
控制小车跑一圈地图,建好的地图如下:
新建终端,保存gmapping创建的地图
cd ~/catkin_ws/src/racecar/racecar_gazebo/map
rosrun map_server map_saver -f track_map
1、新建终端,创建track1.launch文件
cd ~/catkin_ws/src/racecar/racecar_gazebo/launch
touch track1.launch
gedit track1.launch
在track1.launch文件中添加配置
<?xml version="1.0"?>
<launch>
<!-- Launch the racecar -->
<include file="$(find racecar_gazebo)/launch/racecar.launch">
<arg name="world_name" value="track1"/>
</include>
<!-- Launch the built-map -->
<node name="map_server" pkg="map_server" type="map_server" args="$(find racecar_gazebo)/map/track1_map.yaml" />
<!--Launch the move base with time elastic band-->
<param name="/use_sim_time" value="true"/>
<node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
<rosparam file="$(find racecar_gazebo)/config/costmap_common_params.yaml" command="load" ns="global_costmap" />
<rosparam file="$(find racecar_gazebo)/config/costmap_common_params.yaml" command="load" ns="local_costmap" />
<rosparam file="$(find racecar_gazebo)/config/local_costmap_params.yaml" command="load" />
<rosparam file="$(find racecar_gazebo)/config/global_costmap_params.yaml" command="load" />
<rosparam file="$(find racecar_gazebo)/config/teb_local_planner_params.yaml" command="load" />
<param name="base_global_planner" value="global_planner/GlobalPlanner" />
<param name="planner_frequency" value="0.01" />
<param name="planner_patience" value="5.0" />
<!--param name="use_dijkstra" value="false" /-->
<param name="base_local_planner" value="teb_local_planner/TebLocalPlannerROS" />
<param name="controller_frequency" value="5.0" />
<param name="controller_patience" value="15.0" />
<param name="clearing_rotation_allowed" value="false" />
</node>
</launch>
roslaunch racecar_gazebo track1.launch
roslaunch racecar_gazebo racecar_rviz.launch
选择2D Nav Goal指针规划路线,在地图上点击一个地方,进行导航
新建终端,运行path_pursuit.py文件,即可实现小车自主定位导航
cd ~/catkin_ws
source ./devel/setup.bash
rosrun racecar_gazebo path_pursuit.py
可以看见,在设定了目的地之后,小车即可自主规划路线向目的地行驶
需要注意的是小伙伴们在创建地图的时候要避免创建环形跑道,否则在设定目的地的时候想要环跑道一圈的额话,会出现问题。以上就是智能车自主导航的操作流程,有什么问题的话留言咨询吧!