mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
initFrom() -> configureInitFrom() + performInitFrom()
Use different function names for different semantics.
This commit is contained in:
parent
32a0de6bf3
commit
0d6dbee215
@ -49,21 +49,21 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::Gripper>("open gripper");
|
auto move = std::make_unique<stages::Gripper>("open gripper");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setTo("open");
|
move->setTo("open");
|
||||||
t.add(std::move(move));
|
t.add(std::move(move));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::Move>("move to pre-grasp");
|
auto move = std::make_unique<stages::Move>("move to pre-grasp");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setTimeout(8.0);
|
move->setTimeout(8.0);
|
||||||
t.add(std::move(move));
|
t.add(std::move(move));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::CartesianPositionMotion>("proceed to grasp pose");
|
auto move = std::make_unique<stages::CartesianPositionMotion>("proceed to grasp pose");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setMinMaxDistance(.05, 0.1);
|
move->setMinMaxDistance(.05, 0.1);
|
||||||
move->setCartesianStepSize(0.02);
|
move->setCartesianStepSize(0.02);
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto gengrasp = std::make_unique<stages::GenerateGraspPose>("generate grasp pose");
|
auto gengrasp = std::make_unique<stages::GenerateGraspPose>("generate grasp pose");
|
||||||
gengrasp->properties().initFrom(PARENT);
|
gengrasp->properties().configureInitFrom(PARENT);
|
||||||
gengrasp->setGripperGraspPose("open");
|
gengrasp->setGripperGraspPose("open");
|
||||||
gengrasp->setObject("object");
|
gengrasp->setObject("object");
|
||||||
gengrasp->setGraspFrame(Eigen::Translation3d(0,0,.05)*
|
gengrasp->setGraspFrame(Eigen::Translation3d(0,0,.05)*
|
||||||
@ -88,7 +88,7 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::Gripper>("grasp");
|
auto move = std::make_unique<stages::Gripper>("grasp");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setTo("closed");
|
move->setTo("closed");
|
||||||
move->graspObject("object");
|
move->graspObject("object");
|
||||||
t.add(std::move(move));
|
t.add(std::move(move));
|
||||||
@ -96,7 +96,7 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::CartesianPositionMotion>("lift object");
|
auto move = std::make_unique<stages::CartesianPositionMotion>("lift object");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setMinMaxDistance(0.03, 0.05);
|
move->setMinMaxDistance(0.03, 0.05);
|
||||||
move->setCartesianStepSize(0.01);
|
move->setCartesianStepSize(0.01);
|
||||||
|
|
||||||
|
|||||||
@ -49,14 +49,14 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::Gripper>("open gripper");
|
auto move = std::make_unique<stages::Gripper>("open gripper");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setTo("open");
|
move->setTo("open");
|
||||||
t.add(std::move(move));
|
t.add(std::move(move));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::Move>("move to pre-grasp");
|
auto move = std::make_unique<stages::Move>("move to pre-grasp");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setTimeout(8.0);
|
move->setTimeout(8.0);
|
||||||
t.add(std::move(move));
|
t.add(std::move(move));
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ int main(int argc, char** argv){
|
|||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::CartesianPositionMotion>("proceed to grasp pose");
|
auto move = std::make_unique<stages::CartesianPositionMotion>("proceed to grasp pose");
|
||||||
// move->addSolutionCallback(std::ref(t.introspection()));
|
// move->addSolutionCallback(std::ref(t.introspection()));
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setMinMaxDistance(.03, 0.1);
|
move->setMinMaxDistance(.03, 0.1);
|
||||||
move->setCartesianStepSize(0.02);
|
move->setCartesianStepSize(0.02);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto gengrasp = std::make_unique<stages::GenerateGraspPose>("generate grasp pose");
|
auto gengrasp = std::make_unique<stages::GenerateGraspPose>("generate grasp pose");
|
||||||
gengrasp->properties().initFrom(PARENT);
|
gengrasp->properties().configureInitFrom(PARENT);
|
||||||
gengrasp->setGripperGraspPose("open");
|
gengrasp->setGripperGraspPose("open");
|
||||||
gengrasp->setObject("object");
|
gengrasp->setObject("object");
|
||||||
gengrasp->setGraspFrame(Eigen::Translation3d(.03,0,0), "s_model_tool0");
|
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<stages::Gripper>("grasp");
|
auto move = std::make_unique<stages::Gripper>("grasp");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setTo("closed");
|
move->setTo("closed");
|
||||||
move->graspObject("object");
|
move->graspObject("object");
|
||||||
t.add(std::move(move));
|
t.add(std::move(move));
|
||||||
@ -95,7 +95,7 @@ int main(int argc, char** argv){
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto move = std::make_unique<stages::CartesianPositionMotion>("lift object");
|
auto move = std::make_unique<stages::CartesianPositionMotion>("lift object");
|
||||||
move->properties().initFrom(PARENT);
|
move->properties().configureInitFrom(PARENT);
|
||||||
move->setMinMaxDistance(0.03, 0.05);
|
move->setMinMaxDistance(0.03, 0.05);
|
||||||
move->setCartesianStepSize(0.01);
|
move->setCartesianStepSize(0.01);
|
||||||
|
|
||||||
|
|||||||
@ -58,6 +58,11 @@ enum PropertyInitializerSource {
|
|||||||
INTERFACE,
|
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 {
|
class Property {
|
||||||
friend class PropertyMap;
|
friend class PropertyMap;
|
||||||
|
|
||||||
@ -74,9 +79,10 @@ public:
|
|||||||
const std::string& description() const { return description_; }
|
const std::string& description() const { return description_; }
|
||||||
std::string typeName() const { return type_index_.name(); }
|
std::string typeName() const { return type_index_.name(); }
|
||||||
|
|
||||||
/// set an initializer function
|
/// configure initialization from source using an arbitrary function
|
||||||
Property &initFrom(PropertyInitializerSource source, const InitializerFunction& f = fromName);
|
Property &configureInitFrom(PropertyInitializerSource source, const InitializerFunction& f = fromName);
|
||||||
Property &initFrom(PropertyInitializerSource source, const std::string& other_name);
|
/// configure initialization from source using other property name
|
||||||
|
Property &configureInitFrom(PropertyInitializerSource source, const std::string& other_name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string description_;
|
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
|
class PropertyMap
|
||||||
{
|
{
|
||||||
std::map<std::string, Property> props_;
|
std::map<std::string, Property> props_;
|
||||||
@ -113,8 +124,8 @@ public:
|
|||||||
return const_cast<PropertyMap*>(this)->property(name);
|
return const_cast<PropertyMap*>(this)->property(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// allow initialization from given source for listed properties
|
/// allow initialization from given source for listed properties - always using the same name
|
||||||
void initFrom(PropertyInitializerSource source, const std::set<std::string> &properties = {});
|
void configureInitFrom(PropertyInitializerSource source, const std::set<std::string> &properties = {});
|
||||||
|
|
||||||
/// set the value of a property
|
/// set the value of a property
|
||||||
void set(const std::string& name, const boost::any& value);
|
void set(const std::string& name, const boost::any& value);
|
||||||
@ -134,9 +145,10 @@ public:
|
|||||||
|
|
||||||
/// reset properties to nil, if they have initializers
|
/// reset properties to nil, if they have initializers
|
||||||
void reset();
|
void reset();
|
||||||
/// init properties from initializers
|
|
||||||
void initFrom(PropertyInitializerSource source, const PropertyMap& other,
|
/// perform initialization of properties using configured initializers
|
||||||
bool checkConsistency = false);
|
void performInitFrom(PropertyInitializerSource source, const PropertyMap& other,
|
||||||
|
bool checkConsistency = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace task_constructor
|
} // namespace task_constructor
|
||||||
|
|||||||
@ -73,13 +73,13 @@ const boost::any &Property::value() const {
|
|||||||
return value_.empty() ? default_ : value_;
|
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;
|
initializers_[source] = f;
|
||||||
return *this;
|
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&) {
|
initializers_[source] = [other_name](const PropertyMap& other, const std::string&) {
|
||||||
return fromName(other, other_name);
|
return fromName(other, other_name);
|
||||||
@ -105,11 +105,11 @@ Property& PropertyMap::property(const std::string &name)
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertyMap::initFrom(PropertyInitializerSource source, const std::set<std::string> &properties)
|
void PropertyMap::configureInitFrom(PropertyInitializerSource source, const std::set<std::string> &properties)
|
||||||
{
|
{
|
||||||
for (auto &pair : props_) {
|
for (auto &pair : props_) {
|
||||||
if (properties.empty() || properties.count(pair.first))
|
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,
|
void PropertyMap::performInitFrom(PropertyInitializerSource source, const PropertyMap &other,
|
||||||
bool checkConsistency)
|
bool checkConsistency)
|
||||||
{
|
{
|
||||||
for (auto& pair : props_) {
|
for (auto& pair : props_) {
|
||||||
Property &p = pair.second;
|
Property &p = pair.second;
|
||||||
|
|||||||
@ -240,8 +240,8 @@ const InterfaceState& PropagatingEitherWayPrivate::fetchEndState(){
|
|||||||
void PropagatingEitherWayPrivate::initProperties(const InterfaceState& state)
|
void PropagatingEitherWayPrivate::initProperties(const InterfaceState& state)
|
||||||
{
|
{
|
||||||
properties_.reset();
|
properties_.reset();
|
||||||
properties_.initFrom(PARENT, parent()->properties());
|
properties_.performInitFrom(PARENT, parent()->properties());
|
||||||
properties_.initFrom(INTERFACE, state.properties());
|
properties_.performInitFrom(INTERFACE, state.properties());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropagatingEitherWayPrivate::canCompute() const
|
bool PropagatingEitherWayPrivate::canCompute() const
|
||||||
@ -433,7 +433,7 @@ bool GeneratorPrivate::compute() {
|
|||||||
void GeneratorPrivate::initProperties()
|
void GeneratorPrivate::initProperties()
|
||||||
{
|
{
|
||||||
properties_.reset();
|
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)
|
void ConnectingPrivate::initProperties(const InterfaceState &start, const InterfaceState &end)
|
||||||
{
|
{
|
||||||
properties_.reset();
|
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 from start/end states need to be consistent to each other
|
||||||
properties_.initFrom(INTERFACE, start.properties());
|
properties_.performInitFrom(INTERFACE, start.properties());
|
||||||
properties_.initFrom(INTERFACE, end.properties(), true);
|
properties_.performInitFrom(INTERFACE, end.properties(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectingPrivate::canCompute() const{
|
bool ConnectingPrivate::canCompute() const{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user