实验室买了一个线控差动底盘,4轮差动转向,计算平台采用nvidia-agx,激光雷达是velodyne-vlp16,软件上基于cartographer算法建图+amcl定位+ros包move_base 进行室内导航。nvidia-agx内置ubuntu18.04,ros-melodic,**路由器一个工业的或者普通路由器均可,普通路由器需要修改激光雷达的广播类型,**从255.255.255.0的广播形式修改为计算平台的ip地址,否则路由器受到带宽限制可能会造成网络拥堵,工业路由器或交换器请忽略。
一、激光雷达数据接入
新建一个ros工作空间catkin_ws,下载velodyne驱动程序,在src文件夹下,
git clone https://github.com/ros-drivers/velodyne.git
然后编译软件包
catkin_make
source devel/setup.bash
通过给的VLP-16.yaml生成xml文件:
roslaunch velodyne_pointcloud gen_calibreation.py calibration:=${path}/VLP-16.xml
启动雷达节点
#start lidar node
roslaunch velodyne_pointcloud VLP16_points.launch calibration:=${path}/VLP-16.yaml
接入小车底盘,包括里程计数据,小车控制量等信息。
git clone https://github.com/agilexrobotics/scout_ros.git
catkin_make
#start scout_base
roslaunch scout_bringup scout_minimal_uart.launch
cartographer_ros包参考https://github.com/cartographer-project/cartographer_ros进行安装和下载。
建图时一般先通过录制rosbag的方式,
Roslaunch velodyne_pointcloud VLP16_points.launch calibration:=${path}/VLP-16.yaml
rosbag record /scan
根据激光雷达信息修改,demo_velodyne_2d_online.launch 配置文件。
启动建图:
roslaunch cartographer_ros demo_velodyne_2d_online.launch bag_filename:=${rosbag_path}.bag
自动启动RVIZ进行建图,建图结束后执行:
dir_path="/home/nvidia/Downloads/graph"
cd $dir_path
time_cur=$(date "+%Y-%m-%d-%H-%M-%S")
mkdir $time_cur
rosservice call /finish_trajectory 0
rosservice call /write_state "filename: '${dir_path}/${time_cur}/${time_cur}.pbstream'"
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${dir_path}/${time_cur}/${time_cur} -pbstream_filename=${dir_path}/${time_cur}/${time_cur}.pbstream -resolution=0.05
得到三个文件:mymap.pbstream,mymap.pgm,mymap.yaml,yaml用来后续加载地图。
下载:
git clone https://github.com/ros-planning/navigation.git
#install
catkin_make
对算法进行配置:
需要配置6个配置文件,配置文件参考变量名,分别为:
-->base_local_planner_params.yaml
TrajectoryPlannerROS:
max_vel_x: 1.4
min_vel_x: 0.1
max_vel_theta: 1.0
min_in_place_vel_theta: 0.4
acc_lim_theta: 3.2
acc_lim_x: 2.5
acc_lim_y: 2.5
holonomic_robot: true
-->costmap_common_params.yaml
obstacle_range: 2.5
raytrace_range: 3.0
footprint: [[0.364, 0.54], [0.364, -0.54], [-0.364, 0.54], [-0.364, -0.54]]
#robot_radius: ir_of_robot
inflation_radius: 0.55
#observation_sources: laser_scan_sensor point_cloud_sensor
observation_sources: laser_scan_sensor
laser_scan_sensor: {sensor_frame: velodyne, data_type: LaserScan, topic: scan , marking: true, clearing: true}
#point_cloud_sensor: {sensor_frame: frame_name, data_type: PointCloud, topic: topic_name, marking: true, clearing: true}
-->global_costmap_params.yaml
global_costmap:
global_frame: map
robot_base_frame: base_link
update_frequency: 5.0
static_map: true
-->local_cost_map_params.yaml
local_costmap:
global_frame: odom
robot_base_frame: base_link
update_frequency: 5.0
publish_frequency: 2.0
static_map: false
rolling_window: true
width: 6.0
height: 6.0
resolution: 0.05
-->move_base.launch
<launch>
<master auto="start"/>
<include file="$(find amcl)/examples/amcl_diff.launch" />
<node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
<rosparam file="$(find my_robot_name_2dnav)/costmap_common_params.yaml" command="load" ns="global_costmap" />
<rosparam file="$(find my_robot_name_2dnav)/costmap_common_params.yaml" command="load" ns="local_costmap" />
<rosparam file="$(find my_robot_name_2dnav)/local_costmap_params.yaml" command="load" />
<rosparam file="$(find my_robot_name_2dnav)/global_costmap_params.yaml" command="load" />
<rosparam file="$(find my_robot_name_2dnav)/base_local_planner_params.yaml" command="load" />
node>
launch>
算法有四个输入,分别是雷达信号,地图信息,里程计信息,还有坐标系变换tf。
Roslaunch velodyne_pointcloud VLP16_points.launch calibration:=${path}/VLP-16.yaml
roslaunch scout_bringup scout_minimal_uart.launch
主要用来转换激光雷达和底盘的坐标系变换。
#include
#include
int main(int argc, char **argv){
ros::init(argc,argv,"robot_tf_publisher");
ros::NodeHandle n;
ros::Rate r(50);
tf::TransformBroadcaster broadcaster;
while(n.ok()){
broadcaster.sendTransform(
tf::StampedTransform(
tf::Transform(tf::Quaternion(0,0,0,1), tf::Vector3(0.1,0.0,0.2)),
ros::Time::now(),"base_link","velodyne"));
r.sleep();
}
return 0;
}
rosrun map_server map_server mymap.yaml
roslaunch move_base.launch
rosrun rviz rviz
加载地图,在地图中利用rviz上方工具,设置导航目标点,启动导航,然后就可以自己玩啦。因为计算平台需要车载,因此用了vnc服务,远程发布目标点信息。
有小问题可以在下面留言哈,
未经作者同意请勿用于商业用途