ROS2 3Dslam建图 cartographer
-
最近有个项目用的是宇树雷达L1进行3D建图,按照网上的教程打算用cartographer算法来搞,但是运行起来从rviz来看只有2维地图,点云和imu的数据都是有的
import os from launch import LaunchDescription from launch.substitutions import LaunchConfiguration from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare def generate_launch_description(): # 定位到功能包的地址 pkg_share = FindPackageShare(package='robot_cartographer').find('robot_cartographer') #=====================运行节点需要的配置======================================================================= # 是否使用仿真时间 use_sim_time = LaunchConfiguration('use_sim_time', default='false') # 地图的分辨率 resolution = LaunchConfiguration('resolution', default='0.05') # 地图的发布周期 publish_period_sec = LaunchConfiguration('publish_period_sec', default='1.0') # 配置文件夹路径 configuration_directory = LaunchConfiguration('configuration_directory',default= os.path.join(pkg_share, 'config') ) # 配置文件 configuration_basename = LaunchConfiguration('configuration_basename', default='robot_3d.lua') rviz_config_dir = LaunchConfiguration('rviz_config_dir',default= os.path.join(pkg_share, 'rviz') ) #=====================声明三个节点,cartographer/occupancy_grid_node/rviz_node================================= cartographer_node = Node( package='cartographer_ros', executable='cartographer_node', name='cartographer_node', output='screen', parameters=[{'use_sim_time': use_sim_time}], arguments=['-configuration_directory', configuration_directory, '-configuration_basename', configuration_basename], remappings = [ ('points2', 'cloud')],) occupancy_grid_node = Node( package='cartographer_ros', executable='cartographer_occupancy_grid_node', name='occupancy_grid_node', output='screen', parameters=[{'use_sim_time': use_sim_time}], arguments=['-resolution', resolution, '-publish_period_sec', publish_period_sec]) rviz_node = Node( package='rviz2', executable='rviz2', name='rviz2', arguments=['-d', rviz_config_dir], parameters=[{'use_sim_time': use_sim_time}], output='screen') #===============================================定义启动文件======================================================== ld = LaunchDescription() ld.add_action(cartographer_node) ld.add_action(occupancy_grid_node) ld.add_action(rviz_node) return ld
- robot_3d.lua
-- Copyright 2016 The Cartographer Authors -- -- Licensed 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 at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed 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 and -- limitations under the License. include "map_builder.lua" include "trajectory_builder.lua" options = { map_builder = MAP_BUILDER, trajectory_builder = TRAJECTORY_BUILDER, map_frame = "map", tracking_frame = "imu_link", published_frame = "base_link", odom_frame = "odom", provide_odom_frame = false, publish_frame_projected_to_2d = false, -- use_pose_extrapolator = true, use_odometry = false, use_nav_sat = false, use_landmarks = false, num_laser_scans = 0, num_multi_echo_laser_scans = 0, num_subdivisions_per_laser_scan = 1, num_point_clouds = 1, lookup_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., } TRAJECTORY_BUILDER_3D.num_accumulated_range_data = 160 MAP_BUILDER.use_trajectory_builder_3d = true MAP_BUILDER.num_background_threads = 7 POSE_GRAPH.optimization_problem.huber_scale = 5e2 POSE_GRAPH.optimize_every_n_nodes = 320 POSE_GRAPH.constraint_builder.sampling_ratio = 0.03 POSE_GRAPH.optimization_problem.ceres_solver_options.max_num_iterations = 10 POSE_GRAPH.constraint_builder.min_score = 0.62 POSE_GRAPH.constraint_builder.global_localization_min_score = 0.66 return options
- 机器人urdf文件
<robot name="cartographer_backpack_3d"> <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> <!-- IMU or 底盘 (可以描述尺寸大小也可以不描述) --> <link name="base_link" /> <link name="imu_link" /> <joint name="imu_link_joint" type="fixed"> <parent link="base_link" /> <child link="imu_link" /> <origin xyz="0 0 0" rpy="0 0 0" /> </joint> <!-- 描述雷达的尺寸大小、颜色 --> <link name="laser_link"> <visual> <origin xyz="0.0 0.0 0.0" /> <geometry> <cylinder length="0.07" radius="0.05" /> </geometry> <material name="gray" /> </visual> </link> <!-- 描述 雷达和IMU/底盘 的相对位姿 --> <joint name="laser_link_joint" type="fixed"> <parent link="imu_link" /> <child link="laser_link" /> <origin xyz="0.007698 0.014655 -0.00667" rpy="0 0 0" /> </joint> </robot>
- 所有话题
robot@ubuntu:~$ ros2 topic list /clicked_point /cloud /constraint_list /goal_pose /initialpose /joint_states /landmark_poses_list /map /map_updates /parameter_events /robot_description /rosout /scan_matched_points2 /submap_list /tf /tf_static /trajectory_node_list
-
rqt的节点图
-
rviz界面