Stage: generally allow forwarding of interface properties

This commit is contained in:
Robert Haschke 2018-06-02 13:53:00 +02:00
parent 92296e020f
commit 0dab499533
4 changed files with 23 additions and 11 deletions

View File

@ -159,6 +159,13 @@ public:
void setTimeout(double timeout) { setProperty("timeout", timeout); }
double timeout() const { return properties().get<double>("timeout"); }
/// forwarding of properties between interface states
void forwardProperties(const InterfaceState& source, InterfaceState& dest);
std::set<std::string> forwardedProperties() const
{ return properties().get<std::set<std::string>>("forwarded_properties"); }
void setForwardedProperties(const std::set<std::string>& names)
{ setProperty("forwarded_properties", names); }
typedef std::function<void(const SolutionBase &s)> SolutionCallback;
typedef std::list<SolutionCallback> SolutionCallbackList;
/// add function to be called for every newly found solution or failure

View File

@ -104,10 +104,6 @@ public:
void setIgnoreCollisions(bool flag) {
setProperty("ignore_collisions", flag);
}
void setForwardedProperties(const std::set<std::string>& names) {
setProperty("forward_properties", names);
}
};
} } }

View File

@ -105,6 +105,7 @@ void StagePrivate::sendForward(const InterfaceState& from, InterfaceState&& to,
assert(nextStarts());
if (!storeSolution(solution))
return; // solution dropped
me()->forwardProperties(from, to);
auto to_it = states_.insert(states_.end(), std::move(to));
@ -122,6 +123,7 @@ void StagePrivate::sendBackward(InterfaceState&& from, const InterfaceState& to,
assert(prevEnds());
if (!storeSolution(solution))
return; // solution dropped
me()->forwardProperties(to, from);
auto from_it = states_.insert(states_.end(), std::move(from));
@ -181,6 +183,8 @@ Stage::Stage(StagePrivate *impl)
assert(impl);
auto& p = properties();
p.declare<double>("timeout", "timeout per run (s)");
p.declare<std::set<std::string>>("forwarded_properties", std::set<std::string>(),
"set of interface properties to forward");
p.declare<std::string>("marker_ns", "marker namespace");
}
@ -246,6 +250,17 @@ void Stage::setName(const std::string& name)
pimpl_->name_ = name;
}
void Stage::forwardProperties(const InterfaceState& source, InterfaceState& dest)
{
const PropertyMap& src = source.properties();
PropertyMap& dst = dest.properties();
for (const auto& name : forwardedProperties()) {
if (!src.hasProperty(name))
continue;
dst.set(name, src.get(name));
}
}
Stage::SolutionCallbackList::const_iterator Stage::addSolutionCallback(SolutionCallback &&cb)
{
auto impl = pimpl();

View File

@ -61,7 +61,6 @@ ComputeIK::ComputeIK(const std::string &name, Stage::pointer &&child)
p.declare<std::string>("default_pose", "", "default joint pose of active group (defines cost of IK)");
p.declare<uint32_t>("max_ik_solutions", 1);
p.declare<bool>("ignore_collisions", false);
p.declare<std::set<std::string>>("forward_properties", "to-be-forwarded properties from input");
// ik_frame and target_pose are read from the interface
p.declare<geometry_msgs::PoseStamped>("ik_frame", "frame to be moved towards goal pose");
@ -370,12 +369,7 @@ void ComputeIK::onNewSolution(const SolutionBase &s)
robot_state.update();
InterfaceState state(scene);
const boost::any &forwards = props.get("forward_properties");
if (!forwards.empty()) {
auto p = s.start()->properties();
p.exposeTo(state.properties(), boost::any_cast<std::set<std::string>>(forwards));
}
forwardProperties(*s.start(), state);
spawn(std::move(state), std::move(solution));
}