Skip to content

Commit fbc05e4

Browse files
authored
Add property to enable/disable pruning at runtime (moveit#590)
1 parent 907014c commit fbc05e4

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

core/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ find_package(catkin REQUIRED COMPONENTS
1818
)
1919

2020
option(MOVEIT_CI_WARNINGS "Enable all warnings used by CI" OFF) # We use our own set of warnings
21-
option(ENABLE_PRUNING "Enable pruning on failed solutions" OFF)
2221
moveit_build_options()
2322

2423
catkin_python_setup()
@@ -40,9 +39,6 @@ catkin_package(
4039
)
4140

4241
add_compile_options(-fvisibility-inlines-hidden)
43-
if(ENABLE_PRUNING)
44-
add_compile_definitions(ENABLE_PRUNING)
45-
endif()
4642

4743
set(PROJECT_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include/moveit/task_constructor)
4844

core/include/moveit/task_constructor/container.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class ContainerBase : public Stage
5151
PRIVATE_CLASS(ContainerBase)
5252
using pointer = std::unique_ptr<ContainerBase>;
5353

54+
/// Explicitly enable/disable pruning
55+
void setPruning(bool pruning) { setProperty("pruning", pruning); }
56+
bool pruning() const { return properties().get<bool>("pruning"); }
57+
5458
size_t numChildren() const;
5559
Stage* findChild(const std::string& name) const;
5660
Stage* operator[](int index) const;

core/include/moveit/task_constructor/task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class Task : protected WrapperBase
117117
using WrapperBase::setTimeout;
118118
using WrapperBase::timeout;
119119

120+
using WrapperBase::pruning;
121+
using WrapperBase::setPruning;
122+
120123
/// reset all stages
121124
void reset() final;
122125
/// initialize all stages with given scene

core/src/container.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ inline void updateStatePrios(const InterfaceState& s, const InterfaceState::Prio
232232
}
233233

234234
void ContainerBasePrivate::onNewFailure(const Stage& child, const InterfaceState* from, const InterfaceState* to) {
235-
#ifdef ENABLE_PRUNING
235+
if (!static_cast<ContainerBase*>(me_)->pruning())
236+
return;
237+
236238
ROS_DEBUG_STREAM_NAMED("Pruning", fmt::format("'{}' generated a failure", child.name()));
237239
switch (child.pimpl()->interfaceFlags()) {
238240
case GENERATE:
@@ -252,11 +254,6 @@ void ContainerBasePrivate::onNewFailure(const Stage& child, const InterfaceState
252254
setStatus<Interface::FORWARD>(&child, from, to, InterfaceState::Status::ARMED);
253255
break;
254256
}
255-
#else
256-
(void)child;
257-
(void)from;
258-
(void)to;
259-
#endif
260257
// printChildrenInterfaces(*this, false, child);
261258
}
262259

@@ -328,7 +325,10 @@ void ContainerBasePrivate::liftSolution(const SolutionBasePtr& solution, const I
328325
newSolution(solution);
329326
}
330327

331-
ContainerBase::ContainerBase(ContainerBasePrivate* impl) : Stage(impl) {}
328+
ContainerBase::ContainerBase(ContainerBasePrivate* impl) : Stage(impl) {
329+
auto& p = properties();
330+
p.declare<bool>("pruning", std::string("enable pruning?")).configureInitFrom(Stage::PARENT, "pruning");
331+
}
332332

333333
size_t ContainerBase::numChildren() const {
334334
return pimpl()->children().size();

core/src/task.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const ContainerBase* TaskPrivate::stages() const {
9292

9393
Task::Task(const std::string& ns, bool introspection, ContainerBase::pointer&& container)
9494
: WrapperBase(new TaskPrivate(this, ns), std::move(container)) {
95+
setPruning(false);
9596
setTimeout(std::numeric_limits<double>::max());
9697

9798
// monitor state on commandline

core/test/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ if (CATKIN_ENABLE_TESTING)
3838
mtc_add_gtest(test_stage.cpp)
3939
mtc_add_gtest(test_container.cpp)
4040
mtc_add_gmock(test_serial.cpp)
41-
if(ENABLE_PRUNING)
4241
mtc_add_gmock(test_pruning.cpp)
43-
endif()
4442
mtc_add_gtest(test_properties.cpp)
4543
mtc_add_gtest(test_cost_terms.cpp)
4644

core/test/test_pruning.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
using namespace moveit::task_constructor;
1010

11-
using Pruning = TaskTestBase;
11+
struct Pruning : TaskTestBase
12+
{
13+
Pruning() : TaskTestBase() { t.setPruning(true); }
14+
};
1215

1316
TEST_F(Pruning, PropagatorFailure) {
1417
auto back = add(t, new BackwardMockup());
@@ -21,6 +24,18 @@ TEST_F(Pruning, PropagatorFailure) {
2124
EXPECT_EQ(back->runs_, 0u);
2225
}
2326

27+
// Same as the previous test, except pruning is disabled for the whole task
28+
TEST_F(Pruning, DisabledPruningPropagatorFailure) {
29+
t.setPruning(false);
30+
auto back = add(t, new BackwardMockup());
31+
add(t, new GeneratorMockup({ 0 }));
32+
add(t, new ForwardMockup({ INF }));
33+
EXPECT_FALSE(t.plan());
34+
ASSERT_EQ(t.solutions().size(), 0u);
35+
// ForwardMockup fails, since we have pruning disabled backward should run
36+
EXPECT_EQ(back->runs_, 1u);
37+
}
38+
2439
TEST_F(Pruning, PruningMultiForward) {
2540
add(t, new BackwardMockup());
2641
add(t, new BackwardMockup());
@@ -127,7 +142,7 @@ TEST_F(Pruning, PropagateIntoContainer) {
127142
EXPECT_EQ(con->runs_, 0u);
128143
}
129144

130-
TEST_F(Pruning, PropagateIntoContainerAndReactivate) {
145+
TEST_F(Pruning, DISABLED_PropagateIntoContainerAndReactivate) {
131146
add(t, new GeneratorMockup({ 0 }));
132147

133148
auto serial = add(t, new SerialContainer());

0 commit comments

Comments
 (0)