Skip to content

Commit 1655762

Browse files
Avoid duplicate scenes in Solution.msg from generator stages (#639)
If start and end scene of a stage are identical (e.g. from a generator), we can use an (empty) scene diff as well.
1 parent 7384702 commit 1655762

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

core/src/storage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ void SubTrajectory::appendTo(moveit_task_constructor_msgs::Solution& msg, Intros
231231
if (trajectory())
232232
trajectory()->getRobotTrajectoryMsg(t.trajectory);
233233

234-
if (this->end()->scene()->getParent() == this->start()->scene())
234+
if (this->end()->scene()->getParent() == this->start()->scene() || // diff
235+
this->end()->scene() == this->start()->scene()) // identical (from generator)
235236
this->end()->scene()->getPlanningSceneDiffMsg(t.scene_diff);
236237
else
237238
this->end()->scene()->getPlanningSceneMsg(t.scene_diff);

core/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ if (CATKIN_ENABLE_TESTING)
4242
mtc_add_gmock(test_pruning.cpp)
4343
mtc_add_gtest(test_properties.cpp)
4444
mtc_add_gtest(test_cost_terms.cpp)
45+
mtc_add_gtest(test_storage.cpp)
4546

4647
mtc_add_gmock(test_fallback.cpp)
4748
mtc_add_gmock(test_cost_queue.cpp)

core/test/test_storage.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "models.h"
2+
3+
#include <moveit/task_constructor/task.h>
4+
#include <moveit/task_constructor/stages/fixed_state.h>
5+
6+
#include <moveit/planning_scene/planning_scene.h>
7+
8+
#include <ros/console.h>
9+
#include <gtest/gtest.h>
10+
11+
using namespace moveit::task_constructor;
12+
using namespace planning_scene;
13+
using namespace moveit::core;
14+
15+
// https://github.com/moveit/moveit_task_constructor/issues/638
16+
TEST(SolutionMsg, DuplicateScenes) {
17+
Task t;
18+
PlanningScenePtr scene;
19+
20+
t.setRobotModel(getModel());
21+
scene = std::make_shared<PlanningScene>(t.getRobotModel());
22+
t.add(std::make_unique<stages::FixedState>("start", scene));
23+
24+
EXPECT_TRUE(t.plan(1));
25+
EXPECT_EQ(t.solutions().size(), 1u);
26+
27+
// create solution
28+
moveit_task_constructor_msgs::Solution solution_msg;
29+
t.solutions().front()->toMsg(solution_msg);
30+
31+
// all sub trajectories `scene_diff` should be a diff
32+
EXPECT_EQ(solution_msg.sub_trajectory.size(), 1u);
33+
EXPECT_EQ(solution_msg.start_scene.is_diff, false);
34+
EXPECT_EQ(solution_msg.sub_trajectory.front().scene_diff.is_diff, true);
35+
}

0 commit comments

Comments
 (0)