Skip to content

Commit 5775730

Browse files
committed
add modifier with both modified start/end states
Required to lift a SolutionSequence, and modify its states (e.g., to add properties).
1 parent 636bfca commit 5775730

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

core/include/moveit/task_constructor/container.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ class ParallelContainerBase : public ContainerBase
132132
/// lift a modified solution, changing the (single!) new associated start or end InterfaceState
133133
void liftModifiedSolution(SolutionBasePtr&& new_solution, InterfaceState&& new_propagated_state,
134134
const SolutionBase& child_solution);
135+
/// lift a modified solution, providing new start and end states
136+
/// The new states will only be used if this's should actually create the corresponding states
137+
void liftModifiedSolution(SolutionBasePtr&& new_solution, InterfaceState&& new_start_state,
138+
InterfaceState&& new_end_state, const SolutionBase& child_solution);
135139
};
136140

137141
/** Plan for different alternatives in parallel.

core/include/moveit/task_constructor/container_p.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ class ContainerBasePrivate : public StagePrivate
150150
/// copy external_state to a child's interface and remember the link in internal_external map
151151
template <Interface::Direction>
152152
void copyState(Interface::iterator external, const InterfacePtr& target, bool updated);
153-
/// lift solution from internal to external level, possibly replacing the generated InterfaceState with new_external
153+
/// lift solution from internal to external level, possibly replacing the generated InterfaceStates with new_*
154+
/// If specified, *new_from/*new_to will be moved from.
154155
void liftSolution(const SolutionBasePtr& solution, const InterfaceState* internal_from,
155-
const InterfaceState* internal_to, const InterfaceState* new_external = nullptr);
156+
const InterfaceState* internal_to, InterfaceState* new_from = nullptr,
157+
InterfaceState* new_to = nullptr);
156158

157159
/// protected writable overloads
158160
inline auto& internalToExternalMap() { return internal_external_.left; }

core/src/container.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ void ContainerBasePrivate::copyState(Interface::iterator external, const Interfa
204204
}
205205

206206
void ContainerBasePrivate::liftSolution(const SolutionBasePtr& solution, const InterfaceState* internal_from,
207-
const InterfaceState* internal_to, const InterfaceState* new_external) {
207+
const InterfaceState* internal_to, InterfaceState* new_from,
208+
InterfaceState* new_to) {
208209
const bool create_from{ requiredInterface().testFlag(WRITES_PREV_END) };
209210
const bool create_to{ requiredInterface().testFlag(WRITES_NEXT_START) };
210211

211212
// external states, nullptr if they don't exist yet
212-
const InterfaceState* external_from{ create_from ? new_external : internalToExternalMap().at(internal_from) };
213-
const InterfaceState* external_to{ create_to ? new_external : internalToExternalMap().at(internal_to) };
213+
const InterfaceState* external_from{ create_from ? new_from : internalToExternalMap().at(internal_from) };
214+
const InterfaceState* external_to{ create_to ? new_to : internalToExternalMap().at(internal_to) };
214215

215216
// computeCost
216217
// we can pass intern_{from/to} here because in this case the lifted states that might be created later
@@ -222,17 +223,16 @@ void ContainerBasePrivate::liftSolution(const SolutionBasePtr& solution, const I
222223
return;
223224
}
224225

225-
auto create_state = [this, new_external](const InterfaceState& internal) {
226-
InterfaceState* external{ storeState(new_external ? InterfaceState{ *new_external } :
227-
InterfaceState{ internal }) };
226+
auto create_state = [this](const InterfaceState& internal, InterfaceState* new_external) {
227+
InterfaceState* external{ storeState(new_external ? std::move(*new_external) : InterfaceState{ internal }) };
228228
internalToExternalMap().insert(std::make_pair(&internal, external));
229229
return external;
230230
};
231231

232232
if (create_from)
233-
external_from = create_state(*internal_from);
233+
external_from = create_state(*internal_from, new_from);
234234
if (create_to)
235-
external_to = create_state(*internal_to);
235+
external_to = create_state(*internal_to, new_to);
236236

237237
assert(external_from);
238238
assert(external_to);
@@ -749,7 +749,7 @@ void ParallelContainerBase::liftSolution(const SolutionBase& solution, double co
749749
solution.start(), solution.end());
750750
}
751751

752-
void ParallelContainerBase::liftModifiedSolution(SolutionBasePtr&& modified_solution, const SolutionBase &child_solution) {
752+
void ParallelContainerBase::liftModifiedSolution(SolutionBasePtr&& modified_solution, const SolutionBase& child_solution) {
753753
// child_solution is correctly prepared by a child of this container
754754
assert(child_solution.creator());
755755
assert(child_solution.creator()->parent() == this);
@@ -758,13 +758,22 @@ void ParallelContainerBase::liftModifiedSolution(SolutionBasePtr&& modified_solu
758758
child_solution.start(), child_solution.end());
759759
}
760760

761-
void ParallelContainerBase::liftModifiedSolution(SolutionBasePtr &&new_solution, InterfaceState &&new_propagated_state, const SolutionBase &child_solution) {
761+
void ParallelContainerBase::liftModifiedSolution(SolutionBasePtr&& new_solution, InterfaceState&& new_propagated_state, const SolutionBase& child_solution) {
762762
assert(child_solution.creator());
763763
assert(child_solution.creator()->parent() == this);
764+
assert(pimpl()->requiredInterface() == PROPAGATE_FORWARDS || pimpl()->requiredInterface() == PROPAGATE_BACKWARDS);
764765

765-
pimpl()->liftSolution(std::move(new_solution), child_solution.start(), child_solution.end(), &new_propagated_state);
766+
pimpl()->liftSolution(std::move(new_solution), child_solution.start(), child_solution.end(), &new_propagated_state, &new_propagated_state);
766767
}
767768

769+
void ParallelContainerBase::liftModifiedSolution(SolutionBasePtr&& new_solution, InterfaceState&& new_from, InterfaceState&& new_to, const SolutionBase& child_solution) {
770+
assert(child_solution.creator());
771+
assert(child_solution.creator()->parent() == this);
772+
773+
pimpl()->liftSolution(std::move(new_solution), child_solution.start(), child_solution.end(), &new_from, &new_to);
774+
}
775+
776+
768777
WrapperBasePrivate::WrapperBasePrivate(WrapperBase* me, const std::string& name)
769778
: ParallelContainerBasePrivate(me, name) {}
770779

0 commit comments

Comments
 (0)