moveit2
The MoveIt Motion Planning Framework for ROS 2.
best_seen_execution_time_policy.hpp
Go to the documentation of this file.
1 // Copyright 2024 Intrinsic Innovation LLC.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
24 #pragma once
25 
26 #include <memory>
27 
28 #include <warehouse_ros/message_collection.h>
30 #include <moveit_msgs/msg/motion_plan_request.hpp>
31 #include <moveit_msgs/msg/robot_trajectory.hpp>
32 #include <moveit_msgs/srv/get_cartesian_path.hpp>
33 
36 
37 namespace moveit_ros
38 {
39 namespace trajectory_cache
40 {
41 
42 // =================================================================================================
43 // BestSeenExecutionTimePolicy.
44 // =================================================================================================
45 // moveit_msgs::msg::MotionPlanRequest <=> moveit::planning_interface::MoveGroupInterface::Plan
46 
90  : public CacheInsertPolicyInterface<moveit_msgs::msg::MotionPlanRequest,
91  moveit::planning_interface::MoveGroupInterface::Plan,
92  moveit_msgs::msg::RobotTrajectory>
93 {
94 public:
96  static std::vector<std::unique_ptr<FeaturesInterface<moveit_msgs::msg::MotionPlanRequest>>>
97  getSupportedFeatures(double start_tolerance, double goal_tolerance);
98 
100 
101  std::string getName() const override;
102 
105  const warehouse_ros::MessageCollection<moveit_msgs::msg::RobotTrajectory>& coll,
108 
109  std::vector<warehouse_ros::MessageWithMetadata<moveit_msgs::msg::RobotTrajectory>::ConstPtr>
111  const warehouse_ros::MessageCollection<moveit_msgs::msg::RobotTrajectory>& coll,
114  double exact_match_precision) override;
115 
119  const warehouse_ros::MessageWithMetadata<moveit_msgs::msg::RobotTrajectory>::ConstPtr& matching_entry,
120  std::string* reason = nullptr) override;
121 
125  std::string* reason = nullptr) override;
126 
128  appendInsertMetadata(warehouse_ros::Metadata& metadata,
132 
133  void reset() override;
134 
135 private:
136  const std::string name_;
137  std::vector<std::unique_ptr<FeaturesInterface<moveit_msgs::msg::MotionPlanRequest>>> exact_matching_supported_features_;
138 
139  double best_seen_execution_time_;
140 };
141 
142 // =================================================================================================
143 // CartesianBestSeenExecutionTimePolicy.
144 // =================================================================================================
145 // moveit_msgs::srv::GetCartesianPath::Request <=> moveit_msgs::srv::GetCartesianPath::Response
146 
195  : public CacheInsertPolicyInterface<moveit_msgs::srv::GetCartesianPath::Request,
196  moveit_msgs::srv::GetCartesianPath::Response, moveit_msgs::msg::RobotTrajectory>
197 {
198 public:
200  static std::vector<std::unique_ptr<FeaturesInterface<moveit_msgs::srv::GetCartesianPath::Request>>>
201  getSupportedFeatures(double start_tolerance, double goal_tolerance, double min_fraction);
202 
204 
205  std::string getName() const override;
206 
209  const warehouse_ros::MessageCollection<moveit_msgs::msg::RobotTrajectory>& coll,
210  const moveit_msgs::srv::GetCartesianPath::Request& key,
211  const moveit_msgs::srv::GetCartesianPath::Response& value) override;
212 
213  std::vector<warehouse_ros::MessageWithMetadata<moveit_msgs::msg::RobotTrajectory>::ConstPtr>
215  const warehouse_ros::MessageCollection<moveit_msgs::msg::RobotTrajectory>& coll,
216  const moveit_msgs::srv::GetCartesianPath::Request& key,
217  const moveit_msgs::srv::GetCartesianPath::Response& value,
218  double exact_match_precision) override;
219 
222  const moveit_msgs::srv::GetCartesianPath::Request& key, const moveit_msgs::srv::GetCartesianPath::Response& value,
223  const warehouse_ros::MessageWithMetadata<moveit_msgs::msg::RobotTrajectory>::ConstPtr& matching_entry,
224  std::string* reason = nullptr) override;
225 
227  const moveit_msgs::srv::GetCartesianPath::Request& key,
228  const moveit_msgs::srv::GetCartesianPath::Response& value, std::string* reason = nullptr) override;
229 
230  moveit::core::MoveItErrorCode appendInsertMetadata(warehouse_ros::Metadata& metadata,
232  const moveit_msgs::srv::GetCartesianPath::Request& key,
233  const moveit_msgs::srv::GetCartesianPath::Response& value) override;
234 
235  void reset() override;
236 
237 private:
238  const std::string name_;
239  std::vector<std::unique_ptr<FeaturesInterface<moveit_msgs::srv::GetCartesianPath::Request>>>
240  exact_matching_supported_features_;
241 
242  double best_seen_execution_time_;
243 };
244 
245 } // namespace trajectory_cache
246 } // namespace moveit_ros
Abstract template class for injecting logic for determining when to prune and insert a cache entry,...
a wrapper around moveit_msgs::MoveItErrorCodes to make it easier to return an error code message from...
Client class to conveniently use the ROS interfaces provided by the move_group node.
A cache insertion policy that only decides to insert if the motion plan is the one with the shortest ...
std::string getName() const override
Gets the name of the cache insert policy.
moveit::core::MoveItErrorCode appendInsertMetadata(warehouse_ros::Metadata &metadata, const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::msg::MotionPlanRequest &key, const moveit::planning_interface::MoveGroupInterface::Plan &value) override
Appends the insert metadata with the features supported by the policy.
moveit::core::MoveItErrorCode checkCacheInsertInputs(const moveit::planning_interface::MoveGroupInterface &move_group, const warehouse_ros::MessageCollection< moveit_msgs::msg::RobotTrajectory > &coll, const moveit_msgs::msg::MotionPlanRequest &key, const moveit::planning_interface::MoveGroupInterface::Plan &value) override
Checks inputs to the cache insert call to see if we should abort instead.
static std::vector< std::unique_ptr< FeaturesInterface< moveit_msgs::msg::MotionPlanRequest > > > getSupportedFeatures(double start_tolerance, double goal_tolerance)
Configures and returns a vector of feature extractors that can be used with this policy.
bool shouldInsert(const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::msg::MotionPlanRequest &key, const moveit::planning_interface::MoveGroupInterface::Plan &value, std::string *reason=nullptr) override
Returns whether the insertion candidate should be inserted into the cache.
std::vector< warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotTrajectory >::ConstPtr > fetchMatchingEntries(const moveit::planning_interface::MoveGroupInterface &move_group, const warehouse_ros::MessageCollection< moveit_msgs::msg::RobotTrajectory > &coll, const moveit_msgs::msg::MotionPlanRequest &key, const moveit::planning_interface::MoveGroupInterface::Plan &value, double exact_match_precision) override
Fetches all "matching" cache entries for comparison for pruning.
bool shouldPruneMatchingEntry(const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::msg::MotionPlanRequest &key, const moveit::planning_interface::MoveGroupInterface::Plan &value, const warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotTrajectory >::ConstPtr &matching_entry, std::string *reason=nullptr) override
A cache insertion policy that only decides to insert if the motion plan is the one with the shortest ...
moveit::core::MoveItErrorCode appendInsertMetadata(warehouse_ros::Metadata &metadata, const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::srv::GetCartesianPath::Request &key, const moveit_msgs::srv::GetCartesianPath::Response &value) override
Appends the insert metadata with the features supported by the policy.
static std::vector< std::unique_ptr< FeaturesInterface< moveit_msgs::srv::GetCartesianPath::Request > > > getSupportedFeatures(double start_tolerance, double goal_tolerance, double min_fraction)
Configures and returns a vector of feature extractors that can be used with this policy.
moveit::core::MoveItErrorCode checkCacheInsertInputs(const moveit::planning_interface::MoveGroupInterface &move_group, const warehouse_ros::MessageCollection< moveit_msgs::msg::RobotTrajectory > &coll, const moveit_msgs::srv::GetCartesianPath::Request &key, const moveit_msgs::srv::GetCartesianPath::Response &value) override
Checks inputs to the cache insert call to see if we should abort instead.
std::vector< warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotTrajectory >::ConstPtr > fetchMatchingEntries(const moveit::planning_interface::MoveGroupInterface &move_group, const warehouse_ros::MessageCollection< moveit_msgs::msg::RobotTrajectory > &coll, const moveit_msgs::srv::GetCartesianPath::Request &key, const moveit_msgs::srv::GetCartesianPath::Response &value, double exact_match_precision) override
Fetches all "matching" cache entries for comparison for pruning.
std::string getName() const override
Gets the name of the cache insert policy.
bool shouldInsert(const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::srv::GetCartesianPath::Request &key, const moveit_msgs::srv::GetCartesianPath::Response &value, std::string *reason=nullptr) override
Returns whether the insertion candidate should be inserted into the cache.
bool shouldPruneMatchingEntry(const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::srv::GetCartesianPath::Request &key, const moveit_msgs::srv::GetCartesianPath::Response &value, const warehouse_ros::MessageWithMetadata< moveit_msgs::msg::RobotTrajectory >::ConstPtr &matching_entry, std::string *reason=nullptr) override
Abstract template class for extracting features from some FeatureSourceT.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
The representation of a motion plan (as ROS messages)