planning_scene_monitor_test.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2023, University of Hamburg
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Michael 'v4hn' Goerner
36  Desc: Tests for PlanningSceneMonitor
37 */
38 
39 // ROS
40 #include <ros/ros.h>
41 
42 // Testing
43 #include <gtest/gtest.h>
44 
45 // Main class
48 
49 class PlanningSceneMonitorTest : public ::testing::Test
50 {
51 public:
52  void SetUp() override
53  {
54  psm = std::make_unique<planning_scene_monitor::PlanningSceneMonitor>("robot_description");
55  psm->monitorDiffs(true);
56  scene = psm->getPlanningScene();
57  }
58 
59  void TearDown() override
60  {
61  scene.reset();
62  }
63 
64 protected:
65  planning_scene_monitor::PlanningSceneMonitorPtr psm;
66  planning_scene::PlanningScenePtr scene;
67 };
68 
69 // various code expects the monitored scene to remain the same
70 TEST_F(PlanningSceneMonitorTest, TestPersistentScene)
71 {
72  auto scene{ psm->getPlanningScene() };
73  moveit_msgs::PlanningScene msg;
74  msg.is_diff = msg.robot_state.is_diff = true;
75  psm->newPlanningSceneMessage(msg);
76  EXPECT_EQ(scene, psm->getPlanningScene());
77 
78  msg.is_diff = msg.robot_state.is_diff = false;
79  psm->newPlanningSceneMessage(msg);
80  EXPECT_EQ(scene, psm->getPlanningScene());
81 }
82 
84 
85 #define TRIGGERS_UPDATE(msg, expected_update_type) \
86  { \
87  psm->clearUpdateCallbacks(); \
88  auto received_update_type{ UpdateType::UPDATE_NONE }; \
89  psm->addUpdateCallback([&](auto type) { received_update_type = type; }); \
90  psm->newPlanningSceneMessage(msg); \
91  EXPECT_EQ(received_update_type, expected_update_type); \
92  }
93 
95 {
96  moveit_msgs::PlanningScene msg;
97  msg.is_diff = msg.robot_state.is_diff = true;
98  TRIGGERS_UPDATE(msg, UpdateType::UPDATE_NONE);
99 
100  msg.fixed_frame_transforms.emplace_back();
101  msg.fixed_frame_transforms.back().header.frame_id = "base_link";
102  msg.fixed_frame_transforms.back().child_frame_id = "object";
103  msg.fixed_frame_transforms.back().transform.rotation.w = 1.0;
104  TRIGGERS_UPDATE(msg, UpdateType::UPDATE_TRANSFORMS);
105  msg.fixed_frame_transforms.clear();
106 
107  moveit::core::robotStateToRobotStateMsg(scene->getCurrentState(), msg.robot_state, false);
108  msg.robot_state.is_diff = true;
109  TRIGGERS_UPDATE(msg, UpdateType::UPDATE_STATE);
110 
111  msg.robot_state.is_diff = false;
112  TRIGGERS_UPDATE(msg, UpdateType::UPDATE_STATE | UpdateType::UPDATE_GEOMETRY);
113 
114  msg.robot_state = moveit_msgs::RobotState{};
115  msg.robot_state.is_diff = true;
116  moveit_msgs::CollisionObject co;
117  co.header.frame_id = "base_link";
118  co.id = "object";
119  co.operation = moveit_msgs::CollisionObject::ADD;
120  co.pose.orientation.w = 1.0;
121  co.primitives.emplace_back();
122  co.primitives.back().type = shape_msgs::SolidPrimitive::SPHERE;
123  co.primitives.back().dimensions = { 1.0 };
124  msg.world.collision_objects.emplace_back(co);
125  TRIGGERS_UPDATE(msg, UpdateType::UPDATE_GEOMETRY);
126 
127  msg.world.collision_objects.clear();
128  msg.is_diff = false;
129 
130  TRIGGERS_UPDATE(msg, UpdateType::UPDATE_SCENE);
131 }
132 
133 int main(int argc, char** argv)
134 {
135  testing::InitGoogleTest(&argc, argv);
136  ros::init(argc, argv, "planning_scene_monitor_test");
137 
138  // ros::AsyncSpinner spinner{ 1 };
139  // spinner.start();
140 
141  return RUN_ALL_TESTS();
142 }
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
main
int main(int argc, char **argv)
Definition: planning_scene_monitor_test.cpp:133
PlanningSceneMonitorTest::SetUp
void SetUp() override
Definition: planning_scene_monitor_test.cpp:84
planning_scene_monitor::PlanningSceneMonitor::SceneUpdateType
SceneUpdateType
Definition: planning_scene_monitor.h:96
PlanningSceneMonitorTest::scene
planning_scene::PlanningScenePtr scene
Definition: planning_scene_monitor_test.cpp:98
PlanningSceneMonitorTest::TearDown
void TearDown() override
Definition: planning_scene_monitor_test.cpp:91
planning_scene_monitor.h
PlanningSceneMonitorTest::psm
planning_scene_monitor::PlanningSceneMonitorPtr psm
Definition: planning_scene_monitor_test.cpp:97
PlanningSceneMonitorTest
Definition: planning_scene_monitor_test.cpp:49
conversions.h
TRIGGERS_UPDATE
#define TRIGGERS_UPDATE(msg, expected_update_type)
Definition: planning_scene_monitor_test.cpp:85
moveit::core::robotStateToRobotStateMsg
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)
EXPECT_EQ
#define EXPECT_EQ(a, b)
TEST_F
TEST_F(PlanningSceneMonitorTest, TestPersistentScene)
Definition: planning_scene_monitor_test.cpp:70


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Mon May 27 2024 02:27:24