本文主要是介绍Noetic-cartographer跑自己的数据包----记录(脑子不好容易忘记),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
根据官网的提示 和大佬:https://blog.csdn.net/qq_40216084/article/details/104599308?的文章
1.在/cartographer_ws/install_isolated/share/cartographer_ros/目录下
(1)在上面的目录下urdf中建立你自己的urdf文件my_robot_.urdf
<!--Copyright 2016 The Cartographer AuthorsLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
-->
<!--加上上面这个之后 你必须用gedit 这个文件的名字 进行修改-->
<robot name="mini"><material name="orange"><color rgba="1.0 0.5 0.2 1" /></material><material name="gray"><color rgba="0.2 0.2 0.2 1" /></material><link name="imu"><visual><origin xyz="0 0 0" /><geometry><box size="0.06 0.04 0.02" /></geometry><material name="orange" /></visual></link><link name="lidar_mid"><visual><origin xyz="0 0 0" /><geometry><cylinder length="0.05" radius="0.03" /></geometry><material name="gray" /></visual></link><link name="base_link" /> <joint name="imu2lidar" type="fixed"><parent link="lidar_mid" /><child link="imu" /><origin xyz="0 0 0" /></joint><joint name="base_link2lidar" type="fixed"><parent link="base_link" /><child link="imu" /><origin xyz="0 0 0" /></joint></robot>
主要是声明坐标系以及自己的车的轮廓
(2)在configuration_files文件中建立mg_robot_config.lua
include "map_builder.lua"
include "trajectory_builder.lua"options = {map_builder = MAP_BUILDER,trajectory_builder = TRAJECTORY_BUILDER,map_frame = "map",tracking_frame = "imu", #这里用到了imu,所以跟踪的是imu,如果只用雷达,把这个写lidar_midpublished_frame = "lidar_mid",odom_frame = "odom",provide_odom_frame = false,#我不用里程计publish_frame_projected_to_2d = false,use_pose_extrapolator = false,use_odometry = false,use_nav_sat = false,#不用GPSuse_landmarks = false,num_laser_scans = 1,#雷达个数num_multi_echo_laser_scans = 0,num_subdivisions_per_laser_scan = 1,#这个参数必须要填,>=1,博主目前也没搞明白.num_point_clouds = 0,#3d的话这里要改,2d填0lookup_transform_timeout_sec = 0.2,submap_publish_period_sec = 0.3,pose_publish_period_sec = 5e-3,trajectory_publish_period_sec = 30e-3,rangefinder_sampling_ratio = 1.,odometry_sampling_ratio = 1.,fixed_frame_pose_sampling_ratio = 1.,imu_sampling_ratio = 1.,landmarks_sampling_ratio = 1.,
}MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.num_accumulated_range_data = 1return options
注意:上面盖的注释删了 .lua脚本中的注释我不知道怎么写
(3)在launch文件夹中建立两个launch文件1)my_robot01.launch
<launch><param name="robot_description"textfile="$(find cartographer_ros)/urdf/my_robot_.urdf" />#这里是你第一步定义的urdf文件<node name="robot_state_publisher" pkg="robot_state_publisher"type="robot_state_publisher" /><node name="cartographer_node" pkg="cartographer_ros"type="cartographer_node" args="-configuration_directory $(find cartographer_ros)/configuration_files-configuration_basename mg_robot_config.lua"#这里是你刚才新建的lua文件(运行时删除)output="screen"><remap from="scan" to="/scan" /><!--这里是我的2d包里雷达话题/Scan到carto框架Scan的映射--><remap from="imu" to="/imu" /></node><node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"type="cartographer_occupancy_grid_node" args="-resolution 0.05" />
</launch>
2)my_robot02.launch
<launch><param name="/use_sim_time" value="true" /><include file="$(find cartographer_ros)/launch/my_robot01.launch" />#这里是你刚才建立的launch文件<node name="rviz" pkg="rviz" type="rviz" required="true"args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" /><node name="playbag" pkg="rosbag" type="play"args="--clock $(arg bag_filename)" />
</launch>
运行时要把这两个文件中的#的注释删除
2.刷新环境变量
cd ~/cartographer_ws
source install_isolated/setup.bash
下载2d数据我的自己的 网址提取码:6375
在w10中下载
拖到Ubuntu中的一个文件夹中
3.运行
roslaunch cartographer_ros my_robot02.launch bag_filename:=拖进数据的文件夹路径/2d.bag
4.差不多跑完之后保存地图
首先要安装map——server
sudo apt install ros-<ROS版本>-map-server
我是用的launch文件来接受地图的
F:
<launch><arg name="filename" value="$(find demo01)/map/nav" /><node name="map_save" pkg="map_server" type="map_saver" args="-f $(arg filename)" />
</launch>
读取save的地图
<launch><!-- 设置地图的配置文件 --><arg name="map" default="nav.yaml" /><!-- 运行地图服务器,并且加载设置的地图--><node name="map_server" pkg="map_server" type="map_server" args="$(find demo01)/map/$(arg map)"/>
</launch>
读出来的地图是
这篇关于Noetic-cartographer跑自己的数据包----记录(脑子不好容易忘记)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!