costmap_controller_execution.cpp
Go to the documentation of this file.
00001 /*
00002  *  Copyright 2018, Magazino GmbH, Sebastian Pütz, Jorge Santos Simón
00003  *
00004  *  Redistribution and use in source and binary forms, with or without
00005  *  modification, are permitted provided that the following conditions
00006  *  are met:
00007  *
00008  *  1. Redistributions of source code must retain the above copyright
00009  *     notice, this list of conditions and the following disclaimer.
00010  *
00011  *  2. Redistributions in binary form must reproduce the above
00012  *     copyright notice, this list of conditions and the following
00013  *     disclaimer in the documentation and/or other materials provided
00014  *     with the distribution.
00015  *
00016  *  3. Neither the name of the copyright holder nor the names of its
00017  *     contributors may be used to endorse or promote products derived
00018  *     from this software without specific prior written permission.
00019  *
00020  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031  *  POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  *  costmap_controller_execution.cpp
00034  *
00035  *  authors:
00036  *    Sebastian Pütz <spuetz@uni-osnabrueck.de>
00037  *    Jorge Santos Simón <santos@magazino.eu>
00038  *
00039  */
00040 #include "mbf_costmap_nav/costmap_controller_execution.h"
00041 
00042 namespace mbf_costmap_nav
00043 {
00044 
00045 CostmapControllerExecution::CostmapControllerExecution(
00046     const std::string name,
00047     const mbf_costmap_core::CostmapController::Ptr &controller_ptr,
00048     const ros::Publisher& vel_pub,
00049     const ros::Publisher& goal_pub,
00050     const TFPtr &tf_listener_ptr,
00051     CostmapPtr &costmap_ptr,
00052     const MoveBaseFlexConfig &config,
00053     boost::function<void()> setup_fn,
00054     boost::function<void()> cleanup_fn)
00055       : AbstractControllerExecution(name, controller_ptr, vel_pub, goal_pub, tf_listener_ptr,
00056           toAbstract(config), setup_fn, cleanup_fn),
00057         costmap_ptr_(costmap_ptr)
00058 {
00059   ros::NodeHandle private_nh("~");
00060   private_nh.param("controller_lock_costmap", lock_costmap_, true);
00061 }
00062 
00063 CostmapControllerExecution::~CostmapControllerExecution()
00064 {
00065 }
00066 
00067 mbf_abstract_nav::MoveBaseFlexConfig CostmapControllerExecution::toAbstract(const MoveBaseFlexConfig &config)
00068 {
00069   // copy the controller-related abstract configuration common to all MBF-based navigation
00070   mbf_abstract_nav::MoveBaseFlexConfig abstract_config;
00071   abstract_config.controller_frequency = config.controller_frequency;
00072   abstract_config.controller_patience = config.controller_patience;
00073   abstract_config.controller_max_retries = config.controller_max_retries;
00074   abstract_config.oscillation_timeout = config.oscillation_timeout;
00075   abstract_config.oscillation_distance = config.oscillation_distance;
00076   return abstract_config;
00077 }
00078 
00079 uint32_t CostmapControllerExecution::computeVelocityCmd(
00080     const geometry_msgs::PoseStamped& robot_pose,
00081     const geometry_msgs::TwistStamped& robot_velocity,
00082     geometry_msgs::TwistStamped& vel_cmd,
00083     std::string& message)
00084 {
00085   // Lock the costmap while planning, but following issue #4, we allow to move the responsibility to the planner itself
00086   if (lock_costmap_)
00087   {
00088     boost::lock_guard<costmap_2d::Costmap2D::mutex_t> lock(*(costmap_ptr_->getCostmap()->getMutex()));
00089     return controller_->computeVelocityCommands(robot_pose, robot_velocity, vel_cmd, message);
00090   }
00091   return controller_->computeVelocityCommands(robot_pose, robot_velocity, vel_cmd, message);
00092 }
00093 
00094 } /* namespace mbf_costmap_nav */


mbf_costmap_nav
Author(s): Sebastian Pütz
autogenerated on Mon Jun 17 2019 20:11:40