moveit2
The MoveIt Motion Planning Framework for ROS 2.
single_plan_execution.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, PickNik Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of PickNik Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
36 
37 namespace
38 {
39 const rclcpp::Logger LOGGER = rclcpp::get_logger("hybrid_planning_manager");
40 }
41 
43 {
44 bool SinglePlanExecution::initialize(const std::shared_ptr<HybridPlanningManager>& hybrid_planning_manager)
45 {
46  hybrid_planning_manager_ = hybrid_planning_manager;
47  return true;
48 }
49 
51 {
52  switch (event)
53  {
55  // Handle new hybrid planning request
56  if (!hybrid_planning_manager_->sendGlobalPlannerAction()) // Start global planning
57  {
58  hybrid_planning_manager_->sendHybridPlanningResponse(false);
59  }
60  // Reset local planner started flag
61  local_planner_started_ = false;
62  return ReactionResult(event, "", moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
64  // Do nothing since we wait for the global planning action to finish
65  return ReactionResult(event, "Do nothing", moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
67  // Activate local planner once global solution is available
68  if (!local_planner_started_)
69  { // ensure the local planner is not started twice
70  if (!hybrid_planning_manager_->sendLocalPlannerAction()) // Start local planning
71  {
72  hybrid_planning_manager_->sendHybridPlanningResponse(false);
73  }
74  local_planner_started_ = true;
75  }
76  return ReactionResult(event, "", moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
78  // Abort hybrid planning if no global solution is found
79  return ReactionResult(event, "Global planner failed to find a solution",
80  moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED);
82  // Finish hybrid planning action successfully because local planning action succeeded
83  hybrid_planning_manager_->sendHybridPlanningResponse(true);
84  return ReactionResult(event, "", moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
86  // Local planning failed so abort hybrid planning
87  return ReactionResult(event, "Local planner failed to find a solution",
88  moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED);
89  default:
90  // Unknown event, abort hybrid planning
91  return ReactionResult(event, "Unknown event", moveit_msgs::msg::MoveItErrorCodes::FAILURE);
92  }
93 }
94 
95 ReactionResult SinglePlanExecution::react(const std::string& event)
96 {
97  return ReactionResult(event, "'Single-Plan-Execution' plugin cannot handle events given as string.",
98  moveit_msgs::msg::MoveItErrorCodes::FAILURE);
99 };
100 } // namespace moveit::hybrid_planning
101 
102 #include <pluginlib/class_list_macros.hpp>
103 
PLUGINLIB_EXPORT_CLASS(cached_ik_kinematics_plugin::CachedIKKinematicsPlugin< kdl_kinematics_plugin::KDLKinematicsPlugin >, kinematics::KinematicsBase)
std::shared_ptr< HybridPlanningManager > hybrid_planning_manager_
bool initialize(const std::shared_ptr< HybridPlanningManager > &hybrid_planning_manager) override
ReactionResult react(const HybridPlanningEvent &event) override
const rclcpp::Logger LOGGER
Definition: async_test.h:31