Skip to content

Commit

Permalink
Add property to enable/disable pruning at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Jul 5, 2024
1 parent 907014c commit e9188d8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
4 changes: 1 addition & 3 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ catkin_package(
)

add_compile_options(-fvisibility-inlines-hidden)
if(ENABLE_PRUNING)
add_compile_definitions(ENABLE_PRUNING)
endif()
add_compile_definitions(ENABLE_PRUNING=$<BOOL:${ENABLE_PRUNING}>)

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

Expand Down
4 changes: 4 additions & 0 deletions core/include/moveit/task_constructor/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class ContainerBase : public Stage
PRIVATE_CLASS(ContainerBase)
using pointer = std::unique_ptr<ContainerBase>;

/// Explicitly enable/disable pruning
void setPruning(bool pruning) { setProperty("pruning", pruning); }
bool pruning() const { return properties().get<bool>("pruning"); }

size_t numChildren() const;
Stage* findChild(const std::string& name) const;
Stage* operator[](int index) const;
Expand Down
3 changes: 3 additions & 0 deletions core/include/moveit/task_constructor/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class Task : protected WrapperBase
using WrapperBase::setTimeout;
using WrapperBase::timeout;

using WrapperBase::pruning;
using WrapperBase::setPruning;

/// reset all stages
void reset() final;
/// initialize all stages with given scene
Expand Down
14 changes: 7 additions & 7 deletions core/src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ inline void updateStatePrios(const InterfaceState& s, const InterfaceState::Prio
}

void ContainerBasePrivate::onNewFailure(const Stage& child, const InterfaceState* from, const InterfaceState* to) {
#ifdef ENABLE_PRUNING
if (!static_cast<ContainerBase*>(me_)->pruning())
return;

ROS_DEBUG_STREAM_NAMED("Pruning", fmt::format("'{}' generated a failure", child.name()));
switch (child.pimpl()->interfaceFlags()) {
case GENERATE:
Expand All @@ -252,11 +254,6 @@ void ContainerBasePrivate::onNewFailure(const Stage& child, const InterfaceState
setStatus<Interface::FORWARD>(&child, from, to, InterfaceState::Status::ARMED);
break;
}
#else
(void)child;
(void)from;
(void)to;
#endif
// printChildrenInterfaces(*this, false, child);
}

Expand Down Expand Up @@ -328,7 +325,10 @@ void ContainerBasePrivate::liftSolution(const SolutionBasePtr& solution, const I
newSolution(solution);
}

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

size_t ContainerBase::numChildren() const {
return pimpl()->children().size();
Expand Down
1 change: 1 addition & 0 deletions core/src/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const ContainerBase* TaskPrivate::stages() const {

Task::Task(const std::string& ns, bool introspection, ContainerBase::pointer&& container)
: WrapperBase(new TaskPrivate(this, ns), std::move(container)) {
setPruning(ENABLE_PRUNING);
setTimeout(std::numeric_limits<double>::max());

// monitor state on commandline
Expand Down
2 changes: 0 additions & 2 deletions core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ if (CATKIN_ENABLE_TESTING)
mtc_add_gtest(test_stage.cpp)
mtc_add_gtest(test_container.cpp)
mtc_add_gmock(test_serial.cpp)
if(ENABLE_PRUNING)
mtc_add_gmock(test_pruning.cpp)
endif()
mtc_add_gtest(test_properties.cpp)
mtc_add_gtest(test_cost_terms.cpp)

Expand Down
19 changes: 17 additions & 2 deletions core/test/test_pruning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

using namespace moveit::task_constructor;

using Pruning = TaskTestBase;
struct Pruning : TaskTestBase
{
Pruning() : TaskTestBase() { t.setPruning(true); }
};

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

// Same as the previous test, except pruning is disabled for the whole task
TEST_F(Pruning, DisabledPruningPropagatorFailure) {
t.setPruning(false);
auto back = add(t, new BackwardMockup());
add(t, new GeneratorMockup({ 0 }));
add(t, new ForwardMockup({ INF }));
EXPECT_FALSE(t.plan());
ASSERT_EQ(t.solutions().size(), 0u);
// ForwardMockup fails, since we have pruning disabled backward should run
EXPECT_EQ(back->runs_, 1u);
}

TEST_F(Pruning, PruningMultiForward) {
add(t, new BackwardMockup());
add(t, new BackwardMockup());
Expand Down Expand Up @@ -127,7 +142,7 @@ TEST_F(Pruning, PropagateIntoContainer) {
EXPECT_EQ(con->runs_, 0u);
}

TEST_F(Pruning, PropagateIntoContainerAndReactivate) {
TEST_F(Pruning, DISABLED_PropagateIntoContainerAndReactivate) {
add(t, new GeneratorMockup({ 0 }));

auto serial = add(t, new SerialContainer());
Expand Down

0 comments on commit e9188d8

Please sign in to comment.