22#include <rclcpp/logging.hpp>
23#include <warehouse_ros/message_collection.h>
28#include <moveit_msgs/srv/get_cartesian_path.hpp>
35namespace trajectory_cache
38using ::warehouse_ros::Metadata;
39using ::warehouse_ros::Query;
41using ::moveit::core::MoveItErrorCode;
42using ::moveit::planning_interface::MoveGroupInterface;
44using ::moveit_msgs::srv::GetCartesianPath;
60 const GetCartesianPath::Request& source,
62 double exact_match_precision)
const
68 const GetCartesianPath::Request& source,
72 query.append(name_ +
".group_name", source.group_name);
74 return moveit::core::MoveItErrorCode::SUCCESS;
78 const GetCartesianPath::Request& source,
81 metadata.append(name_ +
".group_name", source.group_name);
83 return moveit::core::MoveItErrorCode::SUCCESS;
89 : name_(
"CartesianStartStateJointStateFeatures"), match_tolerance_(match_tolerance)
99 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
100 double exact_match_precision)
const
102 return appendFeaturesAsFetchQueryWithTolerance(query, source,
move_group, match_tolerance_ + exact_match_precision);
106 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
107 double exact_match_precision)
const
109 return appendFeaturesAsFetchQueryWithTolerance(query, source,
move_group, exact_match_precision);
113 Metadata& metadata,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group)
const
118MoveItErrorCode CartesianStartStateJointStateFeatures::appendFeaturesAsFetchQueryWithTolerance(
119 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
120 double match_tolerance)
const
123 name_ +
".start_state");
131 : name_(
"CartesianMaxSpeedAndAccelerationFeatures")
141 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
142 double exact_match_precision)
const
148 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface& ,
151 if (source.max_velocity_scaling_factor <= 0 || source.max_velocity_scaling_factor > 1.0)
153 query.appendLTE(name_ +
".max_velocity_scaling_factor", 1.0);
157 query.appendLTE(name_ +
".max_velocity_scaling_factor", source.max_velocity_scaling_factor);
160 if (source.max_acceleration_scaling_factor <= 0 || source.max_acceleration_scaling_factor > 1.0)
162 query.appendLTE(name_ +
".max_acceleration_scaling_factor", 1.0);
166 query.appendLTE(name_ +
".max_acceleration_scaling_factor", source.max_acceleration_scaling_factor);
169 if (source.max_cartesian_speed > 0)
171 query.append(name_ +
".cartesian_speed_limited_link", source.cartesian_speed_limited_link);
172 query.appendLTE(name_ +
".max_cartesian_speed", source.max_cartesian_speed);
175 return moveit::core::MoveItErrorCode::SUCCESS;
179 Metadata& metadata,
const GetCartesianPath::Request& source,
const MoveGroupInterface& )
const
181 if (source.max_velocity_scaling_factor <= 0 || source.max_velocity_scaling_factor > 1.0)
183 metadata.append(name_ +
".max_velocity_scaling_factor", 1.0);
187 metadata.append(name_ +
".max_velocity_scaling_factor", source.max_velocity_scaling_factor);
190 if (source.max_acceleration_scaling_factor <= 0 || source.max_acceleration_scaling_factor > 1.0)
192 metadata.append(name_ +
".max_acceleration_scaling_factor", 1.0);
196 metadata.append(name_ +
".max_acceleration_scaling_factor", source.max_acceleration_scaling_factor);
199 if (source.max_cartesian_speed > 0)
201 metadata.append(name_ +
".cartesian_speed_limited_link", source.cartesian_speed_limited_link);
202 metadata.append(name_ +
".max_cartesian_speed", source.max_cartesian_speed);
205 return moveit::core::MoveItErrorCode::SUCCESS;
211 : name_(
"CartesianMaxStepAndJumpThresholdFeatures")
221 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
222 double exact_match_precision)
const
228 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface& ,
231 query.appendLTE(name_ +
".max_step", source.max_step);
233 if (source.jump_threshold > 0)
235 query.appendLTE(name_ +
".jump_threshold", source.jump_threshold);
237 if (source.prismatic_jump_threshold > 0)
239 query.appendLTE(name_ +
".prismatic_jump_threshold", source.prismatic_jump_threshold);
241 if (source.revolute_jump_threshold > 0)
243 query.appendLTE(name_ +
".revolute_jump_threshold", source.revolute_jump_threshold);
246 return moveit::core::MoveItErrorCode::SUCCESS;
250 Metadata& metadata,
const GetCartesianPath::Request& source,
const MoveGroupInterface& )
const
252 metadata.append(name_ +
".max_step", source.max_step);
254 if (source.jump_threshold > 0)
256 metadata.append(name_ +
".jump_threshold", source.jump_threshold);
258 if (source.prismatic_jump_threshold > 0)
260 metadata.append(name_ +
".prismatic_jump_threshold", source.prismatic_jump_threshold);
262 if (source.revolute_jump_threshold > 0)
264 metadata.append(name_ +
".revolute_jump_threshold", source.revolute_jump_threshold);
267 return moveit::core::MoveItErrorCode::SUCCESS;
273 : name_(
"CartesianWaypointsFeatures"), match_tolerance_(match_tolerance)
283 const GetCartesianPath::Request& source,
285 double exact_match_precision)
const
287 return appendFeaturesAsFetchQueryWithTolerance(query, source,
move_group, match_tolerance_ + exact_match_precision);
291 const GetCartesianPath::Request& source,
293 double exact_match_precision)
const
295 return appendFeaturesAsFetchQueryWithTolerance(query, source,
move_group, exact_match_precision);
299 const GetCartesianPath::Request& source,
303 std::string base_frame =
move_group.getRobotModel()->getModelFrame();
305 metadata.append(name_ +
".link_name", source.link_name);
306 metadata.append(name_ +
".robot_model.frame_id", base_frame);
310 size_t waypoint_idx = 0;
311 for (
const auto& waypoint : source.waypoints)
313 std::string meta_name = name_ +
".waypoints_" + std::to_string(waypoint_idx++);
315 geometry_msgs::msg::Point canonical_position = waypoint.position;
316 geometry_msgs::msg::Quaternion canonical_orientation = waypoint.orientation;
319 if (path_request_frame_id != base_frame)
322 &canonical_position, &canonical_orientation, tf2::TimePointZero);
323 status != MoveItErrorCode::SUCCESS)
328 std::stringstream ss;
329 ss <<
"Skipping " << name_ <<
" metadata append: " << status.message;
330 return MoveItErrorCode(status.val, status.message);
335 metadata.append(meta_name +
".position.x", canonical_position.x);
336 metadata.append(meta_name +
".position.y", canonical_position.y);
337 metadata.append(meta_name +
".position.z", canonical_position.z);
340 metadata.append(meta_name +
".orientation.x", canonical_orientation.x);
341 metadata.append(meta_name +
".orientation.y", canonical_orientation.y);
342 metadata.append(meta_name +
".orientation.z", canonical_orientation.z);
343 metadata.append(meta_name +
".orientation.w", canonical_orientation.w);
346 return moveit::core::MoveItErrorCode::SUCCESS;
349MoveItErrorCode CartesianWaypointsFeatures::appendFeaturesAsFetchQueryWithTolerance(
350 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
351 double match_tolerance)
const
354 std::string base_frame =
move_group.getRobotModel()->getModelFrame();
356 query.append(name_ +
".link_name", source.link_name);
357 query.append(name_ +
".robot_model.frame_id", base_frame);
361 size_t waypoint_idx = 0;
362 for (
const auto& waypoint : source.waypoints)
364 std::string meta_name = name_ +
".waypoints_" + std::to_string(waypoint_idx++);
366 geometry_msgs::msg::Point canonical_position = waypoint.position;
367 geometry_msgs::msg::Quaternion canonical_orientation = waypoint.orientation;
370 if (path_request_frame_id != base_frame)
373 &canonical_position, &canonical_orientation, tf2::TimePointZero);
374 status != MoveItErrorCode::SUCCESS)
379 std::stringstream ss;
380 ss <<
"Skipping " << name_ <<
" query append: " << status.message;
381 return MoveItErrorCode(status.val, status.message);
397 return moveit::core::MoveItErrorCode::SUCCESS;
403 : name_(
"CartesianPathConstraintsFeatures"), match_tolerance_(match_tolerance)
415 double exact_match_precision)
const
417 return appendFeaturesAsFetchQueryWithTolerance(query, source,
move_group, match_tolerance_ + exact_match_precision);
423 double exact_match_precision)
const
425 return appendFeaturesAsFetchQueryWithTolerance(query, source,
move_group, exact_match_precision);
429 Metadata& metadata,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group)
const
433 name_ +
".path_constraints");
436MoveItErrorCode CartesianPathConstraintsFeatures::appendFeaturesAsFetchQueryWithTolerance(
437 Query& query,
const GetCartesianPath::Request& source,
const MoveGroupInterface&
move_group,
438 double match_tolerance)
const
442 name_ +
".path_constraints");
moveit::core::MoveItErrorCode appendFeaturesAsExactFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with exact matching.
moveit::core::MoveItErrorCode appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with fuzzy matching.
CartesianMaxSpeedAndAccelerationFeatures()
std::string getName() const override
Gets the name of the features implementation.
moveit::core::MoveItErrorCode appendFeaturesAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group) const override
Extracts relevant features from FeatureSourceT, to be appended to a cache entry's metadata.
moveit::core::MoveItErrorCode appendFeaturesAsExactFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with exact matching.
moveit::core::MoveItErrorCode appendFeaturesAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group) const override
Extracts relevant features from FeatureSourceT, to be appended to a cache entry's metadata.
std::string getName() const override
Gets the name of the features implementation.
CartesianMaxStepAndJumpThresholdFeatures()
moveit::core::MoveItErrorCode appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with fuzzy matching.
moveit::core::MoveItErrorCode appendFeaturesAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group) const override
Extracts relevant features from FeatureSourceT, to be appended to a cache entry's metadata.
moveit::core::MoveItErrorCode appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with fuzzy matching.
CartesianPathConstraintsFeatures(double match_tolerance)
moveit::core::MoveItErrorCode appendFeaturesAsExactFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with exact matching.
std::string getName() const override
Gets the name of the features implementation.
moveit::core::MoveItErrorCode appendFeaturesAsExactFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with exact matching.
moveit::core::MoveItErrorCode appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with fuzzy matching.
CartesianStartStateJointStateFeatures(double match_tolerance)
moveit::core::MoveItErrorCode appendFeaturesAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group) const override
Extracts relevant features from FeatureSourceT, to be appended to a cache entry's metadata.
std::string getName() const override
Gets the name of the features implementation.
moveit::core::MoveItErrorCode appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with fuzzy matching.
moveit::core::MoveItErrorCode appendFeaturesAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group) const override
Extracts relevant features from FeatureSourceT, to be appended to a cache entry's metadata.
std::string getName() const override
Gets the name of the features implementation.
moveit::core::MoveItErrorCode appendFeaturesAsExactFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with exact matching.
CartesianWaypointsFeatures(double match_tolerance)
moveit::core::MoveItErrorCode appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with fuzzy matching.
moveit::core::MoveItErrorCode appendFeaturesAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group) const override
Extracts relevant features from FeatureSourceT, to be appended to a cache entry's metadata.
moveit::core::MoveItErrorCode appendFeaturesAsExactFetchQuery(warehouse_ros::Query &query, const moveit_msgs::srv::GetCartesianPath::Request &source, const moveit::planning_interface::MoveGroupInterface &move_group, double exact_match_precision) const override
Extracts relevant features from FeatureSourceT, to be appended to a fetch query, with exact matching.
CartesianWorkspaceFeatures()
std::string getName() const override
Gets the name of the features implementation.
moveit_msgs::srv::GetCartesianPath::Request features to key the trajectory cache on.
Utilities used by the trajectory_cache package.
moveit::core::MoveItErrorCode appendConstraintsAsFetchQueryWithTolerance(warehouse_ros::Query &query, std::vector< moveit_msgs::msg::Constraints > constraints, const moveit::planning_interface::MoveGroupInterface &move_group, double match_tolerance, const std::string &reference_frame_id, const std::string &prefix)
Extracts relevant features from a vector of moveit_msgs::msg::Constraints messages to a fetch query,...
moveit::core::MoveItErrorCode restateInNewFrame(const std::shared_ptr< tf2_ros::Buffer > &tf, const std::string &target_frame, const std::string &source_frame, geometry_msgs::msg::Point *translation, geometry_msgs::msg::Quaternion *rotation, const tf2::TimePoint &lookup_time=tf2::TimePointZero)
Restates a translation and rotation in a new frame.
std::string getCartesianPathRequestFrameId(const moveit::planning_interface::MoveGroupInterface &move_group, const moveit_msgs::srv::GetCartesianPath::Request &path_request)
Gets cartesian path request frame ID. If path_request has no frame ID, fetch it from move_group.
moveit::core::MoveItErrorCode appendConstraintsAsInsertMetadata(warehouse_ros::Metadata &metadata, std::vector< moveit_msgs::msg::Constraints > constraints, const moveit::planning_interface::MoveGroupInterface &move_group, const std::string &reference_frame_id, const std::string &prefix)
Extracts relevant features from a vector of moveit_msgs::msg::Constraints messages to a cache entry's...
moveit::core::MoveItErrorCode appendRobotStateJointStateAsInsertMetadata(warehouse_ros::Metadata &metadata, const moveit_msgs::msg::RobotState &robot_state, const moveit::planning_interface::MoveGroupInterface &move_group, const std::string &prefix)
Extracts relevant features from a vector of moveit_msgs::msg::Constraints messages to a cache entry's...
moveit::core::MoveItErrorCode appendRobotStateJointStateAsFetchQueryWithTolerance(warehouse_ros::Query &query, const moveit_msgs::msg::RobotState &robot_state, const moveit::planning_interface::MoveGroupInterface &move_group, double match_tolerance, const std::string &prefix)
Extracts relevant features from a vector of moveit_msgs::msg::Constraints messages to a fetch query,...
void queryAppendCenterWithTolerance(warehouse_ros::Query &query, const std::string &name, double center, double tolerance)
Appends a range inclusive query with some tolerance about some center value.