mesh_navigation_server.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020, Sebastian Pütz
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * authors:
34  * Sebastian Pütz <spuetz@uni-osnabrueck.de>
35  *
36  */
37 
38 #include <geometry_msgs/PoseArray.h>
39 #include <mbf_abstract_nav/MoveBaseFlexConfig.h>
40 #include <mesh_map/mesh_map.h>
41 #include <nav_msgs/Path.h>
42 
44 
45 namespace mbf_mesh_nav
46 {
48  : AbstractNavigationServer(tf_listener_ptr)
49  , recovery_plugin_loader_("mbf_mesh_core", "mbf_mesh_core::MeshRecovery")
50  , controller_plugin_loader_("mbf_mesh_core", "mbf_mesh_core::MeshController")
51  , planner_plugin_loader_("mbf_mesh_core", "mbf_mesh_core::MeshPlanner")
52  , mesh_ptr_(new mesh_map::MeshMap(*tf_listener_ptr_))
53  , setup_reconfigure_(false)
54 {
55  // advertise services and current goal topic
61 
62  // dynamic reconfigure server for mbf_mesh_nav configuration; also include
63  // abstract server parameters
64  dsrv_mesh_ = boost::make_shared<dynamic_reconfigure::Server<mbf_mesh_nav::MoveBaseFlexConfig>>(private_nh_);
65  dsrv_mesh_->setCallback(boost::bind(&MeshNavigationServer::reconfigure, this, _1, _2));
66 
67  ROS_INFO_STREAM("Reading map file...");
68  mesh_ptr_->readMap();
69 
70  // initialize all plugins
72 
73  // start all action servers
75 }
76 
78  const std::string &plugin_name, const mbf_abstract_core::AbstractPlanner::Ptr plugin_ptr)
79 {
80  return boost::make_shared<mbf_mesh_nav::MeshPlannerExecution>(
81  plugin_name, boost::static_pointer_cast<mbf_mesh_core::MeshPlanner>(plugin_ptr), mesh_ptr_, last_config_);
82 }
83 
85  const std::string &plugin_name, const mbf_abstract_core::AbstractController::Ptr plugin_ptr)
86 {
87  return boost::make_shared<mbf_mesh_nav::MeshControllerExecution>(
88  plugin_name, boost::static_pointer_cast<mbf_mesh_core::MeshController>(plugin_ptr), vel_pub_, goal_pub_,
90 }
91 
93  const std::string &plugin_name, const mbf_abstract_core::AbstractRecovery::Ptr plugin_ptr)
94 {
95  return boost::make_shared<mbf_mesh_nav::MeshRecoveryExecution>(
96  plugin_name, boost::static_pointer_cast<mbf_mesh_core::MeshRecovery>(plugin_ptr), tf_listener_ptr_,
97  boost::ref(mesh_ptr_), last_config_);
98 }
99 
101 {
103  try
104  {
105  planner_ptr = boost::static_pointer_cast<mbf_abstract_core::AbstractPlanner>(
106  planner_plugin_loader_.createInstance(planner_type));
107  std::string planner_name = planner_plugin_loader_.getName(planner_type);
108  ROS_DEBUG_STREAM("mbf_mesh_core-based planner plugin " << planner_name << " loaded.");
109  }
110  catch (const pluginlib::PluginlibException& ex_mbf_core)
111  {
112  ROS_FATAL_STREAM("Failed to load the " << planner_type << " planner, are you sure it's properly registered"
113  << " and that the containing library is built? " << ex_mbf_core.what());
114  }
115 
116  return planner_ptr;
117 }
118 
120  const mbf_abstract_core::AbstractPlanner::Ptr& planner_ptr)
121 {
122  mbf_mesh_core::MeshPlanner::Ptr mesh_planner_ptr =
123  boost::static_pointer_cast<mbf_mesh_core::MeshPlanner>(planner_ptr);
124  ROS_DEBUG_STREAM("Initialize planner \"" << name << "\".");
125 
126  if (!mesh_ptr_)
127  {
128  ROS_FATAL_STREAM("The mesh pointer has not been initialized!");
129  return false;
130  }
131  return mesh_planner_ptr->initialize(name, mesh_ptr_);
132 }
133 
135 MeshNavigationServer::loadControllerPlugin(const std::string& controller_type)
136 {
138  try
139  {
140  controller_ptr = controller_plugin_loader_.createInstance(controller_type);
141  std::string controller_name = controller_plugin_loader_.getName(controller_type);
142  ROS_DEBUG_STREAM("mbf_mesh_core-based controller plugin " << controller_name << " loaded.");
143  }
144  catch (const pluginlib::PluginlibException& ex_mbf_core)
145  {
146  ROS_FATAL_STREAM("Failed to load the " << controller_type << " controller, are you sure it's properly registered"
147  << " and that the containing library is built? " << ex_mbf_core.what());
148  }
149  return controller_ptr;
150 }
151 
153  const mbf_abstract_core::AbstractController::Ptr& controller_ptr)
154 {
155  ROS_DEBUG_STREAM("Initialize controller \"" << name << "\".");
156 
157  if (!tf_listener_ptr_)
158  {
159  ROS_FATAL_STREAM("The tf listener pointer has not been initialized!");
160  return false;
161  }
162 
163  if (!mesh_ptr_)
164  {
165  ROS_FATAL_STREAM("The mesh pointer has not been initialized!");
166  return false;
167  }
168 
169  mbf_mesh_core::MeshController::Ptr mesh_controller_ptr =
170  boost::static_pointer_cast<mbf_mesh_core::MeshController>(controller_ptr);
171  mesh_controller_ptr->initialize(name, tf_listener_ptr_, mesh_ptr_);
172  ROS_DEBUG_STREAM("Controller plugin \"" << name << "\" initialized.");
173  return true;
174 }
175 
177 {
179 
180  try
181  {
182  recovery_ptr = boost::static_pointer_cast<mbf_abstract_core::AbstractRecovery>(
183  recovery_plugin_loader_.createInstance(recovery_type));
184  std::string recovery_name = recovery_plugin_loader_.getName(recovery_type);
185  ROS_DEBUG_STREAM("mbf_mesh_core-based recovery behavior plugin " << recovery_name << " loaded.");
186  }
187  catch (pluginlib::PluginlibException& ex_mbf_core)
188  {
189  ROS_FATAL_STREAM("Failed to load the " << recovery_type
190  << " recovery behavior, are you sure it's properly registered"
191  << " and that the containing library is built? " << ex_mbf_core.what());
192  }
193 
194  return recovery_ptr;
195 }
196 
198  const mbf_abstract_core::AbstractRecovery::Ptr& behavior_ptr)
199 {
200  ROS_DEBUG_STREAM("Initialize recovery behavior \"" << name << "\".");
201 
202  if (!tf_listener_ptr_)
203  {
204  ROS_FATAL_STREAM("The tf listener pointer has not been initialized!");
205  return false;
206  }
207 
208  if (!mesh_ptr_)
209  {
210  ROS_FATAL_STREAM("The mesh map pointer has not been initialized!");
211  return false;
212  }
213 
214  mbf_mesh_core::MeshRecovery::Ptr behavior = boost::static_pointer_cast<mbf_mesh_core::MeshRecovery>(behavior_ptr);
215  behavior->initialize(name, tf_listener_ptr_, mesh_ptr_);
216  ROS_DEBUG_STREAM("Recovery behavior plugin \"" << name << "\" initialized.");
217  return true;
218 }
219 
221 {
222  AbstractNavigationServer::stop();
223  // TODO
224  // ROS_INFO_STREAM_NAMED("mbf_mesh_nav", "Stopping mesh map for shutdown");
225  // mesh_ptr_->stop();
226 }
227 
229 {
230 }
231 
232 void MeshNavigationServer::reconfigure(mbf_mesh_nav::MoveBaseFlexConfig& config, uint32_t level)
233 {
234  // Make sure we have the original configuration the first time we're called,
235  // so we can restore it if needed
236  if (!setup_reconfigure_)
237  {
238  default_config_ = config;
239  setup_reconfigure_ = true;
240  }
241 
242  if (config.restore_defaults)
243  {
244  config = default_config_;
245  // if someone sets restore defaults on the parameter server, prevent looping
246  config.restore_defaults = false;
247  }
248 
249  // fill the abstract configuration common to all MBF-based navigation
250  mbf_abstract_nav::MoveBaseFlexConfig abstract_config;
251  abstract_config.planner_frequency = config.planner_frequency;
252  abstract_config.planner_patience = config.planner_patience;
253  abstract_config.planner_max_retries = config.planner_max_retries;
254  abstract_config.controller_frequency = config.controller_frequency;
255  abstract_config.controller_patience = config.controller_patience;
256  abstract_config.controller_max_retries = config.controller_max_retries;
257  abstract_config.recovery_enabled = config.recovery_enabled;
258  abstract_config.recovery_patience = config.recovery_patience;
259  abstract_config.oscillation_timeout = config.oscillation_timeout;
260  abstract_config.oscillation_distance = config.oscillation_distance;
261  abstract_config.restore_defaults = config.restore_defaults;
263 
264  last_config_ = config;
265 }
266 
267 bool MeshNavigationServer::callServiceCheckPoseCost(mbf_msgs::CheckPose::Request& request,
268  mbf_msgs::CheckPose::Response& response)
269 {
270  // TODO implement
271  return false;
272 }
273 
274 bool MeshNavigationServer::callServiceCheckPathCost(mbf_msgs::CheckPath::Request& request,
275  mbf_msgs::CheckPath::Response& response)
276 {
277  // TODO implement
278  return false;
279 }
280 
281 bool MeshNavigationServer::callServiceClearMesh(std_srvs::Empty::Request& request, std_srvs::Empty::Response& response)
282 {
283  mesh_ptr_->resetLayers();
284  return true;
285 }
286 
287 } /* namespace mbf_mesh_nav */
mbf_mesh_nav::MeshNavigationServer::callServiceCheckPathCost
bool callServiceCheckPathCost(mbf_msgs::CheckPath::Request &request, mbf_msgs::CheckPath::Response &response)
Callback method for the check_path_cost service.
Definition: mesh_navigation_server.cpp:274
mbf_mesh_nav::MeshNavigationServer::check_path_cost_srv_
ros::ServiceServer check_path_cost_srv_
Service Server for the check_path_cost service.
Definition: mesh_navigation_server.h:230
mbf_mesh_nav::MeshNavigationServer::loadPlannerPlugin
virtual mbf_abstract_core::AbstractPlanner::Ptr loadPlannerPlugin(const std::string &planner_type)
Loads the plugin associated with the given planner_type parameter.
Definition: mesh_navigation_server.cpp:100
boost::shared_ptr< tf::TransformListener >
mbf_mesh_nav::MeshNavigationServer::default_config_
mbf_mesh_nav::MoveBaseFlexConfig default_config_
the default parameter configuration save
Definition: mesh_navigation_server.h:215
mesh_map
mbf_mesh_nav::MeshNavigationServer::loadRecoveryPlugin
virtual mbf_abstract_core::AbstractRecovery::Ptr loadRecoveryPlugin(const std::string &recovery_type)
Loads a Recovery plugin associated with given recovery type parameter.
Definition: mesh_navigation_server.cpp:176
mbf_abstract_nav::AbstractNavigationServer::initializeServerComponents
virtual void initializeServerComponents()
ROS_FATAL_STREAM
#define ROS_FATAL_STREAM(args)
mbf_mesh_nav::MeshNavigationServer::setup_reconfigure_
bool setup_reconfigure_
true, if the dynamic reconfigure has been setup
Definition: mesh_navigation_server.h:218
mbf_abstract_nav::AbstractNavigationServer::private_nh_
ros::NodeHandle private_nh_
mesh_navigation_server.h
ros::NodeHandle::advertiseService
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
mbf_mesh_nav::MeshNavigationServer::clear_mesh_srv_
ros::ServiceServer clear_mesh_srv_
Service Server to clear the mesh.
Definition: mesh_navigation_server.h:224
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
mbf_abstract_nav::AbstractNavigationServer::vel_pub_
ros::Publisher vel_pub_
mbf_mesh_nav::MeshNavigationServer::~MeshNavigationServer
virtual ~MeshNavigationServer()
Destructor.
Definition: mesh_navigation_server.cpp:228
pluginlib::PluginlibException
mbf_mesh_nav::MeshNavigationServer::callServiceCheckPoseCost
bool callServiceCheckPoseCost(mbf_msgs::CheckPose::Request &request, mbf_msgs::CheckPose::Response &response)
Callback method for the check_pose_cost service.
Definition: mesh_navigation_server.cpp:267
mbf_mesh_nav::MeshNavigationServer::initializePlannerPlugin
virtual bool initializePlannerPlugin(const std::string &name, const mbf_abstract_core::AbstractPlanner::Ptr &planner_ptr)
Initializes the controller plugin with its name and pointer to the mesh.
Definition: mesh_navigation_server.cpp:119
mbf_abstract_nav::AbstractNavigationServer::tf_listener_ptr_
const TFPtr tf_listener_ptr_
mbf_mesh_nav::MeshNavigationServer::initializeRecoveryPlugin
virtual bool initializeRecoveryPlugin(const std::string &name, const mbf_abstract_core::AbstractRecovery::Ptr &behavior_ptr)
Initializes a recovery behavior plugin with its name and pointers to the global and local meshs.
Definition: mesh_navigation_server.cpp:197
mbf_mesh_nav::MeshNavigationServer::MeshNavigationServer
MeshNavigationServer(const TFPtr &tf_listener_ptr)
Constructor.
Definition: mesh_navigation_server.cpp:47
mbf_mesh_nav::MeshNavigationServer::newControllerExecution
virtual mbf_abstract_nav::AbstractControllerExecution::Ptr newControllerExecution(const std::string &plugin_name, const mbf_abstract_core::AbstractController::Ptr plugin_ptr)
shared pointer to a new ControllerExecution
Definition: mesh_navigation_server.cpp:84
mbf_abstract_nav::AbstractNavigationServer::reconfigure
virtual void reconfigure(mbf_abstract_nav::MoveBaseFlexConfig &config, uint32_t level)
mbf_abstract_nav::AbstractNavigationServer::startActionServers
virtual void startActionServers()
mbf_mesh_nav::MeshNavigationServer::callServiceClearMesh
bool callServiceClearMesh(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
Callback method for the make_plan service.
Definition: mesh_navigation_server.cpp:281
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
mbf_mesh_nav::MeshNavigationServer::newPlannerExecution
virtual mbf_abstract_nav::AbstractPlannerExecution::Ptr newPlannerExecution(const std::string &plugin_name, const mbf_abstract_core::AbstractPlanner::Ptr plugin_ptr)
shared pointer to a new PlannerExecution
Definition: mesh_navigation_server.cpp:77
mbf_mesh_nav
Definition: mesh_controller_execution.h:46
mbf_mesh_nav::MeshNavigationServer::dsrv_mesh_
DynamicReconfigureServerMeshNav dsrv_mesh_
Dynamic reconfigure server for the mbf_mesh2d_specific part.
Definition: mesh_navigation_server.h:209
mbf_mesh_nav::MeshNavigationServer::loadControllerPlugin
virtual mbf_abstract_core::AbstractController::Ptr loadControllerPlugin(const std::string &controller_type)
Loads the plugin associated with the given controller type parameter.
Definition: mesh_navigation_server.cpp:135
mbf_mesh_nav::MeshNavigationServer::newRecoveryExecution
virtual mbf_abstract_nav::AbstractRecoveryExecution::Ptr newRecoveryExecution(const std::string &plugin_name, const mbf_abstract_core::AbstractRecovery::Ptr plugin_ptr)
shared pointer to a new RecoveryExecution
Definition: mesh_navigation_server.cpp:92
pluginlib::ClassLoader::createInstance
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
pluginlib::ClassLoader::getName
virtual std::string getName(const std::string &lookup_name)
mbf_mesh_nav::MeshNavigationServer::planner_plugin_loader_
pluginlib::ClassLoader< mbf_mesh_core::MeshPlanner > planner_plugin_loader_
plugin class loader for planner plugins
Definition: mesh_navigation_server.h:206
mesh_map.h
mbf_mesh_nav::MeshNavigationServer::mesh_ptr_
MeshPtr mesh_ptr_
Shared pointer to the common global mesh.
Definition: mesh_navigation_server.h:221
mbf_mesh_nav::MeshNavigationServer::check_pose_cost_srv_
ros::ServiceServer check_pose_cost_srv_
Service Server for the check_pose_cost service.
Definition: mesh_navigation_server.h:227
mbf_abstract_nav::AbstractNavigationServer::goal_pub_
ros::Publisher goal_pub_
mbf_mesh_nav::MeshNavigationServer::controller_plugin_loader_
pluginlib::ClassLoader< mbf_mesh_core::MeshController > controller_plugin_loader_
plugin class loader for controller plugins
Definition: mesh_navigation_server.h:203
mbf_mesh_nav::MeshNavigationServer::stop
virtual void stop()
Definition: mesh_navigation_server.cpp:220
mbf_mesh_nav::MeshNavigationServer::recovery_plugin_loader_
pluginlib::ClassLoader< mbf_mesh_core::MeshRecovery > recovery_plugin_loader_
plugin class loader for recovery behaviors plugins
Definition: mesh_navigation_server.h:200
mbf_mesh_nav::MeshNavigationServer::last_config_
mbf_mesh_nav::MoveBaseFlexConfig last_config_
last configuration save
Definition: mesh_navigation_server.h:212
mbf_mesh_nav::MeshNavigationServer::reconfigure
void reconfigure(mbf_mesh_nav::MoveBaseFlexConfig &config, uint32_t level)
Reconfiguration method called by dynamic reconfigure.
Definition: mesh_navigation_server.cpp:232
mbf_mesh_nav::MeshNavigationServer::initializeControllerPlugin
virtual bool initializeControllerPlugin(const std::string &name, const mbf_abstract_core::AbstractController::Ptr &controller_ptr)
Initializes the controller plugin with its name, a pointer to the TransformListener and pointer to th...
Definition: mesh_navigation_server.cpp:152


mbf_mesh_nav
Author(s): Sebastian Pütz
autogenerated on Thu Jan 25 2024 03:42:57