From 0d6dbee2151ab0c7874968a1fea0eb7e6e8d4640 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 3 Feb 2018 10:57:38 +0100 Subject: [PATCH] initFrom() -> configureInitFrom() + performInitFrom() Use different function names for different semantics. --- core/demo/plan_pick_pa10.cpp | 12 ++++---- core/demo/plan_pick_ur5.cpp | 12 ++++---- .../moveit/task_constructor/properties.h | 28 +++++++++++++------ core/src/properties.cpp | 12 ++++---- core/src/stage.cpp | 12 ++++---- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/core/demo/plan_pick_pa10.cpp b/core/demo/plan_pick_pa10.cpp index 16897048..f728b0ee 100644 --- a/core/demo/plan_pick_pa10.cpp +++ b/core/demo/plan_pick_pa10.cpp @@ -49,21 +49,21 @@ int main(int argc, char** argv){ { auto move = std::make_unique("open gripper"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setTo("open"); t.add(std::move(move)); } { auto move = std::make_unique("move to pre-grasp"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setTimeout(8.0); t.add(std::move(move)); } { auto move = std::make_unique("proceed to grasp pose"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setMinMaxDistance(.05, 0.1); move->setCartesianStepSize(0.02); @@ -75,7 +75,7 @@ int main(int argc, char** argv){ { auto gengrasp = std::make_unique("generate grasp pose"); - gengrasp->properties().initFrom(PARENT); + gengrasp->properties().configureInitFrom(PARENT); gengrasp->setGripperGraspPose("open"); gengrasp->setObject("object"); gengrasp->setGraspFrame(Eigen::Translation3d(0,0,.05)* @@ -88,7 +88,7 @@ int main(int argc, char** argv){ { auto move = std::make_unique("grasp"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setTo("closed"); move->graspObject("object"); t.add(std::move(move)); @@ -96,7 +96,7 @@ int main(int argc, char** argv){ { auto move = std::make_unique("lift object"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setMinMaxDistance(0.03, 0.05); move->setCartesianStepSize(0.01); diff --git a/core/demo/plan_pick_ur5.cpp b/core/demo/plan_pick_ur5.cpp index e4f514f7..bf76aa3e 100644 --- a/core/demo/plan_pick_ur5.cpp +++ b/core/demo/plan_pick_ur5.cpp @@ -49,14 +49,14 @@ int main(int argc, char** argv){ { auto move = std::make_unique("open gripper"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setTo("open"); t.add(std::move(move)); } { auto move = std::make_unique("move to pre-grasp"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setTimeout(8.0); t.add(std::move(move)); } @@ -64,7 +64,7 @@ int main(int argc, char** argv){ { auto move = std::make_unique("proceed to grasp pose"); // move->addSolutionCallback(std::ref(t.introspection())); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setMinMaxDistance(.03, 0.1); move->setCartesianStepSize(0.02); @@ -76,7 +76,7 @@ int main(int argc, char** argv){ { auto gengrasp = std::make_unique("generate grasp pose"); - gengrasp->properties().initFrom(PARENT); + gengrasp->properties().configureInitFrom(PARENT); gengrasp->setGripperGraspPose("open"); gengrasp->setObject("object"); gengrasp->setGraspFrame(Eigen::Translation3d(.03,0,0), "s_model_tool0"); @@ -87,7 +87,7 @@ int main(int argc, char** argv){ { auto move = std::make_unique("grasp"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setTo("closed"); move->graspObject("object"); t.add(std::move(move)); @@ -95,7 +95,7 @@ int main(int argc, char** argv){ { auto move = std::make_unique("lift object"); - move->properties().initFrom(PARENT); + move->properties().configureInitFrom(PARENT); move->setMinMaxDistance(0.03, 0.05); move->setCartesianStepSize(0.01); diff --git a/core/include/moveit/task_constructor/properties.h b/core/include/moveit/task_constructor/properties.h index 07f11e2d..79f0640e 100644 --- a/core/include/moveit/task_constructor/properties.h +++ b/core/include/moveit/task_constructor/properties.h @@ -58,6 +58,11 @@ enum PropertyInitializerSource { INTERFACE, }; +/** Property is a wrapper for a boost::any value, also providing a default value and a description. + * + * Properties can be configured to be initialized from another PropertyMap. + * Potential sources are the properties of the parent of a stage, or the properties passed in the interface. + */ class Property { friend class PropertyMap; @@ -74,9 +79,10 @@ public: const std::string& description() const { return description_; } std::string typeName() const { return type_index_.name(); } - /// set an initializer function - Property &initFrom(PropertyInitializerSource source, const InitializerFunction& f = fromName); - Property &initFrom(PropertyInitializerSource source, const std::string& other_name); + /// configure initialization from source using an arbitrary function + Property &configureInitFrom(PropertyInitializerSource source, const InitializerFunction& f = fromName); + /// configure initialization from source using other property name + Property &configureInitFrom(PropertyInitializerSource source, const std::string& other_name); private: std::string description_; @@ -87,6 +93,11 @@ private: }; +/** PropertyMap is map of (name, Property) pairs. + * + * Conveniency methods are provided to setup property initialization for several + * properties at once - always inheriting from the identically named external property. + */ class PropertyMap { std::map props_; @@ -113,8 +124,8 @@ public: return const_cast(this)->property(name); } - /// allow initialization from given source for listed properties - void initFrom(PropertyInitializerSource source, const std::set &properties = {}); + /// allow initialization from given source for listed properties - always using the same name + void configureInitFrom(PropertyInitializerSource source, const std::set &properties = {}); /// set the value of a property void set(const std::string& name, const boost::any& value); @@ -134,9 +145,10 @@ public: /// reset properties to nil, if they have initializers void reset(); - /// init properties from initializers - void initFrom(PropertyInitializerSource source, const PropertyMap& other, - bool checkConsistency = false); + + /// perform initialization of properties using configured initializers + void performInitFrom(PropertyInitializerSource source, const PropertyMap& other, + bool checkConsistency = false); }; } // namespace task_constructor diff --git a/core/src/properties.cpp b/core/src/properties.cpp index c4ad4d2c..318185a6 100644 --- a/core/src/properties.cpp +++ b/core/src/properties.cpp @@ -73,13 +73,13 @@ const boost::any &Property::value() const { return value_.empty() ? default_ : value_; } -Property& Property::initFrom(PropertyInitializerSource source, const Property::InitializerFunction &f) +Property& Property::configureInitFrom(PropertyInitializerSource source, const Property::InitializerFunction &f) { initializers_[source] = f; return *this; } -Property& Property::initFrom(PropertyInitializerSource source, const std::string &other_name) +Property& Property::configureInitFrom(PropertyInitializerSource source, const std::string &other_name) { initializers_[source] = [other_name](const PropertyMap& other, const std::string&) { return fromName(other, other_name); @@ -105,11 +105,11 @@ Property& PropertyMap::property(const std::string &name) return it->second; } -void PropertyMap::initFrom(PropertyInitializerSource source, const std::set &properties) +void PropertyMap::configureInitFrom(PropertyInitializerSource source, const std::set &properties) { for (auto &pair : props_) { if (properties.empty() || properties.count(pair.first)) - pair.second.initFrom(source); + pair.second.configureInitFrom(source); } } @@ -154,8 +154,8 @@ void PropertyMap::reset() } } -void PropertyMap::initFrom(PropertyInitializerSource source, const PropertyMap &other, - bool checkConsistency) +void PropertyMap::performInitFrom(PropertyInitializerSource source, const PropertyMap &other, + bool checkConsistency) { for (auto& pair : props_) { Property &p = pair.second; diff --git a/core/src/stage.cpp b/core/src/stage.cpp index aaf92772..6f2a9952 100644 --- a/core/src/stage.cpp +++ b/core/src/stage.cpp @@ -240,8 +240,8 @@ const InterfaceState& PropagatingEitherWayPrivate::fetchEndState(){ void PropagatingEitherWayPrivate::initProperties(const InterfaceState& state) { properties_.reset(); - properties_.initFrom(PARENT, parent()->properties()); - properties_.initFrom(INTERFACE, state.properties()); + properties_.performInitFrom(PARENT, parent()->properties()); + properties_.performInitFrom(INTERFACE, state.properties()); } bool PropagatingEitherWayPrivate::canCompute() const @@ -433,7 +433,7 @@ bool GeneratorPrivate::compute() { void GeneratorPrivate::initProperties() { properties_.reset(); - properties_.initFrom(PARENT, parent()->properties()); + properties_.performInitFrom(PARENT, parent()->properties()); } @@ -482,10 +482,10 @@ void ConnectingPrivate::newEndState(const Interface::iterator& it) void ConnectingPrivate::initProperties(const InterfaceState &start, const InterfaceState &end) { properties_.reset(); - properties_.initFrom(PARENT, parent()->properties()); + properties_.performInitFrom(PARENT, parent()->properties()); // properties from start/end states need to be consistent to each other - properties_.initFrom(INTERFACE, start.properties()); - properties_.initFrom(INTERFACE, end.properties(), true); + properties_.performInitFrom(INTERFACE, start.properties()); + properties_.performInitFrom(INTERFACE, end.properties(), true); } bool ConnectingPrivate::canCompute() const{