Tinymal-B感知教程2-基于Hector SLAM的2D雷达导航

本教程基于ROS Melodic自带的Hector SLAM算法完成2D雷达与四足机器人里程计结合的建图与导航

在运行我们的例程之前,首先需要采用WinSCP进入目标机空间,下载并解压我们的项目文件,替换catkin_ws中src文件内容,删除build中已有的文件,重新catkin_make进行编译,我们主要完成了对以下4个文件夹内容的修改:
资料地址:
链接:https://pan.baidu.com/s/1pEhY0935xjn0dbgVULUQ2A 提取码:995l
注:由于版本更新,请在第一次使用拷贝代码后确认base_control中base_control_moco.py,如下代码符号:

基于2D雷达的导航例程

本例程介绍如何基于ROS Melodic基本的导航包完成四足机器人在室内的自主导航,由于雷达坐标系的定义问题,如采用LD06雷达其外壳箭头需要朝向机尾。
修改robot_navigation中lidar.launch雷达相对机器人质心的位置与姿态如下,其中位置需要基于具体安装位置进行修改:
第二修改目标机.bashrc文件中雷达类型:
export LIDAR_TYPE=LD06
机器人类型:
export BASE_TYPE=NanoRobot_Pro
修改base_control中base_control.launch中SDK节点IP为主控对应的IP:
之后打开虚拟机修改.bashrc中ROS Master地址为感知主控的地址,确保感知主控roscore后在虚拟机中可以显示其对应话题,然后打开4个控制台通过ssh远程进入目标机依次运行如下脚本:
roslaunch robot_navigation robot_lidar.launch roslaunch robot_navigation hector.launch roslaunch robot_vslam move_base.launch planner:=teb move_forward_only:=false
如无误后,打开Rviz可视化,既可以看到导航结果:
roslaunch robot_navigation navigation_rviz.launch
在发布2D Nav Goal后产生相应的机器人运动轨迹规划结果:
并在robot_lidar.launch的控制台中实时打印当前产生的控制指令,而机器人将以该指令作为期望,如此时机器人可移动则在进入站立后按A键进入步态运动马上按Start按键机器人自主移动,如需要遥控接管则按A恢复:
TebLocalPlannerROS: footprint_model: # types: "point", "circular", "line", "two_circles", "polygon" type: "line" radius: 0.2 # for type "circular" line_start: [-0.13, 0.0] # for type "line" line_end: [0.13, 0.0] # for type "line" front_offset: 0.2 # for type "two_circles" front_radius: 0.2 # for type "two_circles" rear_offset: 0.2 # for type "two_circles" rear_radius: 0.2 # for type "two_circles" vertices: [ [0.25, -0.05], [0.18, -0.05], [0.18, -0.18], [-0.19, -0.18], [-0.25, 0], [-0.19, 0.18], [0.18, 0.18], [0.18, 0.05], [0.25, 0.05] ] # for type "polygon"
当然你也可以采用两个圆的模型,其近似机器人轮廓的另一种可能性包括定义两个圆。每个圆由沿机器人 x 轴的偏移量和半径描述,参考下图作为示例:
关于Teb导航的参数可以在资料中查看:
如果想实现自动化的导航和路点移动,可以运行way_point.launch或multi_points_navigation.launch如相应py脚本运行报错则需要在控制台中使用chmod +x进行授权:
如运行多路点需要重新打开rviz:
roslaunch robot_navigation multi_navigation.launch
资料:
https://blog.csdn.net/qq_40828914/article/details/123059651
如需要保存地图则cd到map文件夹下,输入名称保存所需要的地图:
rosrun map_server map_saver -f home
如需要载入已经建立好的地图进行查看:
rosrun map_server map_serv home.yaml
这里的/syscommand话题是为了重置建立的地图而设置的,即当向该话题中发布字符串reset时,就会将/hector_map话题中数据清除,重新开始建图,完整命令如下:
rostopic pub -1 /syscommand std_msgs/String "reset"
如果想直接采用建立好的地图进行导航,固定坐标点发布连续导航路径,可以新建如下launch robot_navigation_laser,修改载入地图的名字,然后发布2D Pos estimate:
<launch> <!-- Arguments --> <arg name="map_file" default="$(find robot_navigation)/maps/home.yaml"/> <arg name="simulation" default= "false"/> <arg name="planner" default="teb" doc="opt: dwa, teb"/> <arg name="open_rviz" default="false"/> <arg name="use_dijkstra" default= "true"/> <group unless="$(arg simulation)"> <!-- Map server --> <node pkg="map_server" name="map_server" type="map_server" args="$(arg map_file)"> <param name="frame_id" value="map"/> </node> <!-- AMCL --> <node pkg="amcl" type="amcl" name="amcl" output="screen"> <rosparam file="$(find robot_navigation)/param/$(env BASE_TYPE)/amcl_params.yaml" command="load" /> <param name="initial_pose_x" value="0.0"/> <param name="initial_pose_y" value="0.0"/> <param name="initial_pose_a" value="0.0"/> </node> </group> </launch>
同样启动雷达和规划节点:
roslaunch robot_navigation robot_lidar.launch roslaunch robot_navigation robot_navigation_laser.launch roslaunch robot_vslam move_base.launch planner:=teb move_forward_only:=false roslaunch robot_navigation multi_navigation.launch
关于Teb规划器调参可以参考:
https://blog.csdn.net/pricem/article/details/122891310
推荐的Teb Yaml参数,注意TEB导航参数参考launch使用的是robot_vslam文件夹config内对应的参数
TebLocalPlannerROS: odom_topic: odom # Trajectory teb_autosize: True dt_ref: 0.3 dt_hysteresis: 0.1 max_samples: 500 global_plan_overwrite_orientation: True allow_init_with_backwards_motion: True max_global_plan_lookahead_dist: 3.0 global_plan_viapoint_sep: -1 global_plan_prune_distance: 1 exact_arc_length: False feasibility_check_no_poses: 2 publish_feedback: False # Robot max_vel_x: 0.3 max_vel_x_backwards: 0.2 max_vel_y: 0.2 max_vel_theta: 6.0 # the angular velocity is also bounded by min_turning_radius in case of a carlike robot (r = v / omega) acc_lim_x: 0.5 acc_lim_y: 0.5 acc_lim_theta: 1.5 # ********************** Carlike robot parameters ******************** min_turning_radius: 0.075 # Min turning radius of the carlike robot (compute value using a model or adjust with rqt_reconfigure manually) wheelbase: 0.13 # Wheelbase of our robot cmd_angle_instead_rotvel: False # stage simulator takes the angle instead of the rotvel as input (twist message) # ******************************************************************** footprint_model: # types: "point", "circular", "two_circles", "line", "polygon" type: "line" line_start: [-0.13, 0.0] # for type "line" line_end: [0.13, 0.0] # for type "line" # GoalTolerance xy_goal_tolerance: 0.15 yaw_goal_tolerance: 3.14 free_goal_vel: False complete_global_plan: True # Obstacles min_obstacle_dist: 0.1 # This value must also include our robot's expansion, since footprint_model is set to "line". inflation_dist: 0.6 include_costmap_obstacles: True costmap_obstacles_behind_robot_dist: 1.0 obstacle_poses_affected: 15 dynamic_obstacle_inflation_dist: 0.6 include_dynamic_obstacles: True costmap_converter_plugin: "" costmap_converter_spin_thread: True costmap_converter_rate: 5 # Optimization no_inner_iterations: 5 no_outer_iterations: 4 optimization_activate: True optimization_verbose: False penalty_epsilon: 0.1 obstacle_cost_exponent: 4 weight_max_vel_x: 2 weight_max_vel_theta: 1 weight_acc_lim_x: 1 weight_acc_lim_theta: 1 weight_kinematics_nh: 1000 weight_kinematics_forward_drive: 1 weight_kinematics_turning_radius: 1 weight_optimaltime: 1 # must be > 0 weight_shortest_path: 0 weight_obstacle: 100 weight_inflation: 0.2 weight_dynamic_obstacle: 10 # not in use yet weight_dynamic_obstacle_inflation: 0.2 weight_viapoint: 1 weight_adapt_factor: 2 # Homotopy Class Planner enable_homotopy_class_planning: False enable_multithreading: True max_number_classes: 4 selection_cost_hysteresis: 1.0 selection_prefer_initial_plan: 0.95 selection_obst_cost_scale: 1.0 selection_alternative_time_cost: False roadmap_graph_no_samples: 15 roadmap_graph_area_width: 5 roadmap_graph_area_length_scale: 1.0 h_signature_prescaler: 0.5 h_signature_threshold: 0.1 obstacle_heading_threshold: 0.45 switching_blocking_period: 0.0 viapoints_all_candidates: True delete_detours_backwards: True max_ratio_detours_duration_best_duration: 3.0 visualize_hc_graph: False visualize_with_time_as_z_axis_scale: False # Recovery shrink_horizon_backup: True shrink_horizon_min_duration: 10 oscillation_recovery: True oscillation_v_eps: 0.1 oscillation_omega_eps: 0.1 oscillation_recovery_min_duration: 10 oscillation_filter_duration: 10
在线参数调节可以使用:
rosrun rqt_reconfigure rqt_reconfigure
2023-02-18