|
| 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 | + |
| 15 | +/** @file constant_features.hpp |
| 16 | + * @brief User-specified constant features to key the trajectory cache on. |
| 17 | + * |
| 18 | + * This allows a user to specify custom information to populate a fetch query or insert metadata that might not have |
| 19 | + * been obtained via extracting from a FeatureSourceT. |
| 20 | + * |
| 21 | + * @see FeaturesInterface<FeatureSourceT> |
| 22 | + * |
| 23 | + * @author methylDragon |
| 24 | + */ |
| 25 | + |
| 26 | +#pragma once |
| 27 | + |
| 28 | +#include <moveit/trajectory_cache/features/features_interface.hpp> |
| 29 | + |
| 30 | +namespace moveit_ros |
| 31 | +{ |
| 32 | +namespace trajectory_cache |
| 33 | +{ |
| 34 | + |
| 35 | +// Queries. ======================================================================================== |
| 36 | + |
| 37 | +/** @class QueryOnlyEqFeature<AppendT, FeatureSourceT> |
| 38 | + * @brief Appends an equals query, with no metadata. |
| 39 | + */ |
| 40 | +template <class AppendT, class FeatureSourceT> |
| 41 | +class QueryOnlyEqFeature : public FeaturesInterface<FeatureSourceT> |
| 42 | +{ |
| 43 | +public: |
| 44 | + QueryOnlyEqFeature(std::string name, AppendT value) : name_(name), value_(value) |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + std::string getName() const override |
| 49 | + { |
| 50 | + return "QueryOnlyEqFeature." + name_; |
| 51 | + } |
| 52 | + |
| 53 | + moveit::core::MoveItErrorCode |
| 54 | + appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& source, |
| 55 | + const moveit::planning_interface::MoveGroupInterface& move_group, |
| 56 | + double exact_match_precision) const override |
| 57 | + { |
| 58 | + return appendFeaturesAsExactFetchQuery(query, source, move_group, exact_match_precision); |
| 59 | + } |
| 60 | + |
| 61 | + moveit::core::MoveItErrorCode |
| 62 | + appendFeaturesAsExactFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& /*source*/, |
| 63 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/, |
| 64 | + double /*exact_match_precision*/) const override |
| 65 | + { |
| 66 | + query.append(name_, value_); |
| 67 | + return moveit::core::MoveItErrorCode::SUCCESS; |
| 68 | + } |
| 69 | + |
| 70 | + moveit::core::MoveItErrorCode |
| 71 | + appendFeaturesAsInsertMetadata(warehouse_ros::Metadata& /*metadata*/, const FeatureSourceT& /*source*/, |
| 72 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/) const override |
| 73 | + { |
| 74 | + return moveit::core::MoveItErrorCode::SUCCESS; // No-op. |
| 75 | + } |
| 76 | + |
| 77 | +private: |
| 78 | + std::string name_; |
| 79 | + AppendT value_; |
| 80 | +}; |
| 81 | + |
| 82 | +/** @class QueryOnlyLTEFeature<AppendT, FeatureSourceT> |
| 83 | + * @brief Appends a less-than or equal-to query, with no metadata. |
| 84 | + */ |
| 85 | +template <class AppendT, class FeatureSourceT> |
| 86 | +class QueryOnlyLTEFeature : public FeaturesInterface<FeatureSourceT> |
| 87 | +{ |
| 88 | +public: |
| 89 | + QueryOnlyLTEFeature(std::string name, AppendT value) : name_(name), value_(value) |
| 90 | + { |
| 91 | + } |
| 92 | + |
| 93 | + std::string getName() const override |
| 94 | + { |
| 95 | + return "QueryOnlyLTEFeature." + name_; |
| 96 | + } |
| 97 | + |
| 98 | + moveit::core::MoveItErrorCode |
| 99 | + appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& source, |
| 100 | + const moveit::planning_interface::MoveGroupInterface& move_group, |
| 101 | + double exact_match_precision) const override |
| 102 | + { |
| 103 | + return appendFeaturesAsExactFetchQuery(query, source, move_group, exact_match_precision); |
| 104 | + } |
| 105 | + |
| 106 | + moveit::core::MoveItErrorCode |
| 107 | + appendFeaturesAsExactFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& /*source*/, |
| 108 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/, |
| 109 | + double /*exact_match_precision*/) const override |
| 110 | + { |
| 111 | + query.appendLTE(name_, value_); |
| 112 | + return moveit::core::MoveItErrorCode::SUCCESS; |
| 113 | + } |
| 114 | + |
| 115 | + moveit::core::MoveItErrorCode |
| 116 | + appendFeaturesAsInsertMetadata(warehouse_ros::Metadata& /*metadata*/, const FeatureSourceT& /*source*/, |
| 117 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/) const override |
| 118 | + { |
| 119 | + return moveit::core::MoveItErrorCode::SUCCESS; // No-op. |
| 120 | + } |
| 121 | + |
| 122 | +private: |
| 123 | + std::string name_; |
| 124 | + AppendT value_; |
| 125 | +}; |
| 126 | + |
| 127 | +/** @class QueryOnlyGTEFeature<AppendT, FeatureSourceT> |
| 128 | + * @brief Appends a less-than or equal-to query, with no metadata. |
| 129 | + */ |
| 130 | +template <class AppendT, class FeatureSourceT> |
| 131 | +class QueryOnlyGTEFeature : public FeaturesInterface<FeatureSourceT> |
| 132 | +{ |
| 133 | +public: |
| 134 | + QueryOnlyGTEFeature(std::string name, AppendT value) : name_(name), value_(value) |
| 135 | + { |
| 136 | + } |
| 137 | + |
| 138 | + std::string getName() const override |
| 139 | + { |
| 140 | + return "QueryOnlyGTEFeature." + name_; |
| 141 | + } |
| 142 | + |
| 143 | + moveit::core::MoveItErrorCode |
| 144 | + appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& source, |
| 145 | + const moveit::planning_interface::MoveGroupInterface& move_group, |
| 146 | + double exact_match_precision) const override |
| 147 | + { |
| 148 | + return appendFeaturesAsExactFetchQuery(query, source, move_group, exact_match_precision); |
| 149 | + } |
| 150 | + |
| 151 | + moveit::core::MoveItErrorCode |
| 152 | + appendFeaturesAsExactFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& /*source*/, |
| 153 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/, |
| 154 | + double /*exact_match_precision*/) const override |
| 155 | + { |
| 156 | + query.appendGTE(name_, value_); |
| 157 | + return moveit::core::MoveItErrorCode::SUCCESS; |
| 158 | + } |
| 159 | + |
| 160 | + moveit::core::MoveItErrorCode |
| 161 | + appendFeaturesAsInsertMetadata(warehouse_ros::Metadata& /*metadata*/, const FeatureSourceT& /*source*/, |
| 162 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/) const override |
| 163 | + { |
| 164 | + return moveit::core::MoveItErrorCode::SUCCESS; // No-op. |
| 165 | + } |
| 166 | + |
| 167 | +private: |
| 168 | + std::string name_; |
| 169 | + AppendT value_; |
| 170 | +}; |
| 171 | + |
| 172 | +/** @class QueryOnlyRangeInclusiveWithToleranceFeature<AppendT, FeatureSourceT> |
| 173 | + * @brief Appends a less-than or equal-to query, with no metadata. |
| 174 | + */ |
| 175 | +template <class AppendT, class FeatureSourceT> |
| 176 | +class QueryOnlyRangeInclusiveWithToleranceFeature : public FeaturesInterface<FeatureSourceT> |
| 177 | +{ |
| 178 | +public: |
| 179 | + QueryOnlyRangeInclusiveWithToleranceFeature(std::string name, AppendT lower, AppendT upper) |
| 180 | + : name_(name), lower_(lower), upper_(upper) |
| 181 | + { |
| 182 | + } |
| 183 | + |
| 184 | + std::string getName() const override |
| 185 | + { |
| 186 | + return "QueryOnlyRangeInclusiveWithToleranceFeature." + name_; |
| 187 | + } |
| 188 | + |
| 189 | + moveit::core::MoveItErrorCode |
| 190 | + appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& source, |
| 191 | + const moveit::planning_interface::MoveGroupInterface& move_group, |
| 192 | + double exact_match_precision) const override |
| 193 | + { |
| 194 | + return appendFeaturesAsExactFetchQuery(query, source, move_group, exact_match_precision); |
| 195 | + } |
| 196 | + |
| 197 | + moveit::core::MoveItErrorCode |
| 198 | + appendFeaturesAsExactFetchQuery(warehouse_ros::Query& query, const FeatureSourceT& /*source*/, |
| 199 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/, |
| 200 | + double /*exact_match_precision*/) const override |
| 201 | + { |
| 202 | + query.appendRangeInclusive(name_, lower_, upper_); |
| 203 | + return moveit::core::MoveItErrorCode::SUCCESS; |
| 204 | + } |
| 205 | + |
| 206 | + moveit::core::MoveItErrorCode |
| 207 | + appendFeaturesAsInsertMetadata(warehouse_ros::Metadata& /*metadata*/, const FeatureSourceT& /*source*/, |
| 208 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/) const override |
| 209 | + { |
| 210 | + return moveit::core::MoveItErrorCode::SUCCESS; // No-op. |
| 211 | + } |
| 212 | + |
| 213 | +private: |
| 214 | + std::string name_; |
| 215 | + AppendT lower_; |
| 216 | + AppendT upper_; |
| 217 | +}; |
| 218 | + |
| 219 | +// Metadata. ======================================================================================= |
| 220 | + |
| 221 | +/** @class MetadataOnlyFeature<AppendT, FeatureSourceT> |
| 222 | + * @brief Appends a single metadata value, with no query. |
| 223 | + */ |
| 224 | +template <class AppendT, class FeatureSourceT> |
| 225 | +class MetadataOnlyFeature : public FeaturesInterface<FeatureSourceT> |
| 226 | +{ |
| 227 | +public: |
| 228 | + MetadataOnlyFeature(std::string name, AppendT value) : name_(name), value_(value) |
| 229 | + { |
| 230 | + } |
| 231 | + |
| 232 | + std::string getName() const override |
| 233 | + { |
| 234 | + return "MetadataOnlyFeature." + name_; |
| 235 | + } |
| 236 | + |
| 237 | + moveit::core::MoveItErrorCode |
| 238 | + appendFeaturesAsFuzzyFetchQuery(warehouse_ros::Query& /*query*/, const FeatureSourceT& /*source*/, |
| 239 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/, |
| 240 | + double /*exact_match_precision*/) const override |
| 241 | + { |
| 242 | + return moveit::core::MoveItErrorCode::SUCCESS; // No-op. |
| 243 | + } |
| 244 | + |
| 245 | + moveit::core::MoveItErrorCode |
| 246 | + appendFeaturesAsExactFetchQuery(warehouse_ros::Query& /*query*/, const FeatureSourceT& /*source*/, |
| 247 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/, |
| 248 | + double /*exact_match_precision*/) const override |
| 249 | + { |
| 250 | + return moveit::core::MoveItErrorCode::SUCCESS; // No-op. |
| 251 | + } |
| 252 | + |
| 253 | + moveit::core::MoveItErrorCode |
| 254 | + appendFeaturesAsInsertMetadata(warehouse_ros::Metadata& metadata, const FeatureSourceT& /*source*/, |
| 255 | + const moveit::planning_interface::MoveGroupInterface& /*move_group*/) const override |
| 256 | + { |
| 257 | + metadata.append(name_, value_); |
| 258 | + return moveit::core::MoveItErrorCode::SUCCESS; |
| 259 | + } |
| 260 | + |
| 261 | +private: |
| 262 | + std::string name_; |
| 263 | + AppendT value_; |
| 264 | +}; |
| 265 | + |
| 266 | +} // namespace trajectory_cache |
| 267 | +} // namespace moveit_ros |
0 commit comments