Skip to content

Commit 223b5d1

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 cba9d4c commit 223b5d1

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

core/include/moveit/task_constructor/container.h

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

136140
/** 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: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,14 @@ void ContainerBasePrivate::copyState(Interface::iterator external, const Interfa
203203
}
204204

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

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

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

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

231231
if (create_from)
232-
external_from = create_state(*internal_from);
232+
external_from = create_state(*internal_from, new_from);
233233
if (create_to)
234-
external_to = create_state(*internal_to);
234+
external_to = create_state(*internal_to, new_to);
235235

236236
assert(external_from);
237237
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,23 @@ 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+
assert(pimpl()->requiredInterface() == PROPAGATE_FORWARDS || pimpl()->requiredInterface() == PROPAGATE_BACKWARDS);
773+
774+
pimpl()->liftSolution(std::move(new_solution), child_solution.start(), child_solution.end(), &new_from, &new_to);
775+
}
776+
777+
768778
WrapperBasePrivate::WrapperBasePrivate(WrapperBase* me, const std::string& name)
769779
: ParallelContainerBasePrivate(me, name) {}
770780

0 commit comments

Comments
 (0)