Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9472058
  • 博文数量: 1751
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20101
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1751)

文章存档

2024年(27)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2019-05-28 17:07:32

ROS中, 经常出现 recovery behavior start, 在kinetic中默认用的是 rotate_recovery, 即旋转360, 清除costmap的方式.

但是对于我的机器人使用了UWB进行定位, 激光雷达所做的地图被手动改动了很多, 而且加入了 sonar layer之后, 会有很大的噪点障碍. 用rotate_recovery比较难于恢复和定位. 需要改写.

点击(此处)折叠或打开

  1. #include <ros/ros.h>
  2. #include <nav_core/recovery_behavior.h>
  3. #include <costmap_2d/costmap_2d_ros.h>
  4. #include <boost/thread.hpp>
  5. #include <dynamic_reconfigure/Reconfigure.h>

  6. namespace custom_recovery_behavior
  7. {
  8.   class CustomRecoveryAction : public nav_core::RecoveryBehavior
  9.   {
  10.     public:
  11.       CustomRecoveryAction();
  12.       ~CustomRecoveryAction();

  13.       /// Initialize the parameters of the behavior
  14.       void initialize (std::string n, tf::TransformListener* tf,
  15.           costmap_2d::Costmap2DROS* global_costmap,
  16.           costmap_2d::Costmap2DROS* local_costmap);

  17.       /// Run the behavior
  18.       void runBehavior();

  19.     private:
  20.       bool initialized_;
  21.       ros::Publisher custom_recovery_reset;    //costmap/plan/pose 重置
  22.   };
  23. }

点击(此处)折叠或打开

  1. #include <custom_recovery_behavior.h>
  2. #include <pluginlib/class_list_macros.h>
  3. #include <costmap_2d/obstacle_layer.h>
  4. #include <std_msgs/Empty.h>

  5. PLUGINLIB_EXPORT_CLASS(custom_recovery_behavior::CustomRecoveryAction, nav_core::RecoveryBehavior)

  6. namespace custom_recovery_behavior
  7. {
  8.   CustomRecoveryAction::CustomRecoveryAction(): initialized_(false) {}

  9.   CustomRecoveryAction::~CustomRecoveryAction() {}

  10.   void CustomRecoveryAction::initialize (std::string n, tf::TransformListener* tf,
  11.       costmap_2d::Costmap2DROS* global_costmap,
  12.       costmap_2d::Costmap2DROS* local_costmap)
  13.   {
  14.     //声明topic, 通知外部app, 清除costmap并重新定位.
  15.     ros::NodeHandle nh;
  16.     custom_recovery_reset = nh.advertise<std_msgs::Empty>("custom_recovery_reset", 1);            
  17.     initialized_ = true;
  18.     ROS_WARN("Custom recovery behavior initialize.");
  19.   }

  20.   //自定义 RecoveryBehavior 的动作.
  21.   void CustomRecoveryAction::runBehavior()
  22.   {
  23.     if(!initialized_)
  24.     {
  25.       ROS_ERROR("Custom recovery behavior has not been initialized, doing nothing.");
  26.       return;
  27.     }
  28.     ROS_WARN("Custom recovery behavior started.");

  29.     std_msgs::Empty msg;
  30.     custom_recovery_reset.publish(msg);
  31.   }
  32. }
其他的节点程序中,实现清除costmap : 相当于 rosservice call /move_base/clear_costmaps
然后使用uwb的位置更新机器人位置. 
g_rt_ctx->pub_initalpose = nh.advertise("initialpose", 1);

点击(此处)折叠或打开

  1. void clear_costmaps(void)
  2. {
  3.     //clear costmaps.
  4.   std_srvs::Empty srv;
  5.     g_rt_ctx->srv_clear_costmap.call(srv);
  6. }

  7. void set_robot_initialpose(double x, double y, double th)
  8. {
  9.   geometry_msgs::PoseWithCovarianceStamped init_pose;
  10.   init_pose.header.frame_id = "map"; //基于Map的点.
  11.   init_pose.header.stamp = ros::Time::now();

  12.   init_pose.pose.pose.position.x = x; //起始位置点
  13.   init_pose.pose.pose.position.y = y;
  14.   
  15.   tf::Quaternion q;
  16.   //th 调校到 -180 , 180 区间
  17.   th = (th <= 180)? th : (th - 360);
  18.   double arc = (th) * M_PI/180;
  19.   q.setRPY(0, 0, arc);
  20.   init_pose.pose.pose.orientation.x=q[0];
  21.   init_pose.pose.pose.orientation.y=q[1];
  22.   init_pose.pose.pose.orientation.z=q[2];
  23.   init_pose.pose.pose.orientation.w=q[3];

  24.   g_rt_ctx->pub_initalpose.publish(init_pose);
  25.   clear_costmaps();
  26. }

配置的部分比较重要
package.xml

点击(此处)折叠或打开

  1. <?xml version="1.0"?>
  2. <package format="2">
  3.   <name>big_navigation</name>
  4.   <version>1.2.0</version>
  5.   <description>
  6.     The big_navigation provides roslaunch scripts for starting the navigation.
  7.   </description>
  8.   <author email="iibull@yeah.net">iibull</author>
  9.   <license>Apache 2.0</license>
  10.   <maintainer email="iibull@yeah.net">iibull</maintainer>

  11.   <buildtool_depend>catkin</buildtool_depend>
  12.   <exec_depend>amcl</exec_depend>
  13.   <exec_depend>map_server</exec_depend>
  14.   <exec_depend>move_base</exec_depend>
  15.   <exec_depend>big_bringup</exec_depend>
  16.   <build_depend>message_generation</build_depend>
  17.   <build_depend>roscpp</build_depend>
  18.   <build_depend>std_msgs</build_depend>
  19.   <build_export_depend>roscpp</build_export_depend>
  20.   <build_export_depend>std_msgs</build_export_depend>
  21.   <build_export_depend>message_generation</build_export_depend>
  22.   <exec_depend>roscpp</exec_depend>
  23.   <exec_depend>std_msgs</exec_depend>
  24.   <depend>big_msgs</depend>
  25.   <depend>sensor_msgs</depend>
  26.   <depend>tf</depend>

  27.   <build_depend>cmake_modules</build_depend>
  28.   <build_depend>pluginlib</build_depend>
  29.   <exec_depend>pluginlib</exec_depend>
  30.   <build_depend>nav_core</build_depend>
  31.   <exec_depend>nav_core</exec_depend>
  32.   <build_depend>costmap_2d</build_depend>
  33.   <exec_depend>costmap_2d</exec_depend>
  34.   <build_depend>geometry_msgs</build_depend>
  35.   <exec_depend>geometry_msgs</exec_depend>

  36.   <export>
  37.     <nav_core plugin="${prefix}/recovery_plugin.xml" />
  38.   </export>
  39. </package>
CMakeLists.txt

点击(此处)折叠或打开

  1. ################################################################################
  2. # Set minimum required version of cmake, project name and compile options
  3. ################################################################################
  4. cmake_minimum_required(VERSION 2.8.3)
  5. project(big_navigation)

  6. ################################################################################
  7. # Find catkin packages and libraries for catkin and system dependencies
  8. ################################################################################
  9. find_package(catkin REQUIRED COMPONENTS
  10.   message_generation
  11.   roscpp
  12.   std_msgs
  13.   big_msgs
  14.   tf
  15.   sensor_msgs
  16.   cmake_modules
  17.   costmap_2d
  18.   geometry_msgs
  19.   nav_core
  20.   pluginlib
  21. )

  22. ################################################################################
  23. # Setup for python modules and scripts
  24. ################################################################################

  25. ################################################################################
  26. # Declare ROS messages, services and actions
  27. ################################################################################

  28. ################################################################################
  29. # Declare ROS dynamic reconfigure parameters
  30. ################################################################################

  31. ################################################################################
  32. # Declare catkin specific configuration to be passed to dependent projects
  33. ################################################################################

  34. catkin_package(
  35.   INCLUDE_DIRS include
  36.   LIBRARIES custom_recovery_behavior
  37.   CATKIN_DEPENDS message_generation roscpp std_msgs big_msgs sensor_msgs tf geometry_msgs nav_core pluginlib
  38. # DEPENDS system_lib
  39. )

  40. ################################################################################
  41. # Build
  42. ################################################################################
  43. find_package(Eigen3 REQUIRED)
  44. find_package(PCL REQUIRED)
  45. remove_definitions(-DDISABLE_LIBUSB-1.0)
  46. find_package(Boost REQUIRED COMPONENTS thread)

  47. include_directories(
  48.   include
  49.   ${catkin_INCLUDE_DIRS}
  50.   ${catkin_INCLUDE_DIRS}
  51.   ${EIGEN3_INCLUDE_DIRS}
  52.   ${PCL_INCLUDE_DIRS}
  53. )
  54. add_definitions(${EIGEN3_DEFINITIONS})

  55. add_library(custom_recovery_behavior src/custom_recovery_behavior.cpp)
  56. add_dependencies(custom_recovery_behavior ${catkin_EXPORTED_TARGETS})
  57. target_link_libraries(custom_recovery_behavior
  58.     ${Boost_LIBRARIES}
  59.     ${catkin_LIBRARIES}
  60. )


  61. ################################################################################
  62. # Install
  63. ################################################################################
  64. install(DIRECTORY launch param rviz
  65.   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  66. )

  67. install(TARGETS custom_recovery_behavior
  68.        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  69.        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  70. )

  71. install(FILES recovery_plugin.xml
  72.     DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  73. )

  74. ## Install project namespaced headers
  75. install(DIRECTORY include/
  76.     DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  77.     FILES_MATCHING PATTERN "*.h"
  78.     #PATTERN ".svn" EXCLUDE
  79. )


  80. ################################################################################
  81. # Test
  82. ################################################################################
recovery_plugin.xml

点击(此处)折叠或打开

  1. <library path="lib/libcustom_recovery_behavior">
  2.   <class name="custom_recovery_behavior/CustomRecoveryAction" type="custom_recovery_behavior::CustomRecoveryAction" base_class_type="nav_core::RecoveryBehavior">
  3.     <description>
  4.       自定义的recovery behavior. 用于清除costmap,限定运行速度.
  5.     </description>
  6.   </class>
  7. </library>
然后在 move_base.launch 中覆盖默认的 behavior.


点击(此处)折叠或打开

  1. <launch>
  2.   <arg name="model" default="$(env BIG_MODEL)" doc="Waffle"/>
  3.   <arg name="cmd_vel_topic" default="/cmd_vel" />
  4.   <arg name="odom_topic" default="odom" />
  5.   <arg name="move_forward_only" default="false"/>
  6.   <arg name="PlannerROS" default="DWAPlannerROS" />
  7.   <rosparam param="recovery_behaviors"> [ { name: "custom_recovery_behavior", type: "custom_recovery_behavior/CustomRecoveryAction" } ] </rosparam>

  8.   <!-- move_base -->
  9.   <group if="$(eval arg('PlannerROS') == 'DWAPlannerROS')">
  10.     <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
  11.       <param name="base_local_planner" value="dwa_local_planner/DWAPlannerROS" />
  12.       <rosparam file="$(find big_navigation)/param/costmap_common_params_$(arg model).yaml" command="load" ns="global_costmap" />
  13.       <rosparam file="$(find big_navigation)/param/costmap_common_params_$(arg model).yaml" command="load" ns="local_costmap" />
  14.       <rosparam file="$(find big_navigation)/param/local_costmap_params.yaml" command="load" />
  15.       <rosparam file="$(find big_navigation)/param/global_costmap_params.yaml" command="load" />
  16.       <rosparam file="$(find big_navigation)/param/move_base_params.yaml" command="load" />
  17.       <rosparam file="$(find big_navigation)/param/dwa_local_planner_params_$(arg model).yaml" command="load" />
  18.       <remap from="cmd_vel" to="$(arg cmd_vel_topic)"/>
  19.       <remap from="odom" to="$(arg odom_topic)"/>
  20.       <param name="DWAPlannerROS/min_vel_x" value="0.0" if="$(arg move_forward_only)" />
  21.     </node>
  22.   </group>

  23.   <group if="$(eval arg('PlannerROS') == 'TrajectoryPlannerROS')">
  24.     <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
  25.       <param name="base_local_planner" value="base_local_planner/TrajectoryPlannerROS" />
  26.       <rosparam file="$(find big_navigation)/param/costmap_common_params_$(arg model).yaml" command="load" ns="global_costmap" />
  27.       <rosparam file="$(find big_navigation)/param/costmap_common_params_$(arg model).yaml" command="load" ns="local_costmap" />
  28.       <rosparam file="$(find big_navigation)/param/local_costmap_params.yaml" command="load" />
  29.       <rosparam file="$(find big_navigation)/param/global_costmap_params.yaml" command="load" />
  30.       <rosparam file="$(find big_navigation)/param/move_base_params.yaml" command="load" />
  31.       <rosparam file="$(find big_navigation)/param/base_local_planner_params.yaml" command="load" />
  32.       <remap from="cmd_vel" to="$(arg cmd_vel_topic)"/>
  33.       <remap from="odom" to="$(arg odom_topic)"/>
  34.       <param name="TrajectoryPlannerROS/min_vel_x" value="0.0" if="$(arg move_forward_only)" />
  35.     </node>
  36.   </group>

  37. </launch>
运行出现

点击(此处)折叠或打开

  1.  * /move_base/planner_patience: 5.0
     * /move_base/shutdown_costmaps: False
     * /recovery_behaviors: [{'type': 'custom...
     * /robot_description:  * /robot_state_publisher/publish_frequency: 50.0
在local_costmap无路可走的时候, 会被调用.








阅读(18492) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

展翅飞翔mxq2019-06-12 09:34:37

博主您好,看了您的这篇文章感觉帮助特别大,有两点不太理解的想跟您请教一下,请问你在自定义 RecoveryBehavior 的动作是什么,代码是没有贴出来么?还有void clear_costmaps(void)这个函数是用在哪里的呢?