40 #include <rclcpp/rclcpp.hpp>
43 #include <gtest/gtest.h>
54 test_node_ = std::make_shared<rclcpp::Node>(
"moveit_planning_scene_monitor_test");
55 executor_ = std::make_shared<rclcpp::executors::SingleThreadedExecutor>();
57 test_node_,
"robot_description",
"planning_scene_monitor");
64 std::this_thread::sleep_for(std::chrono::seconds{ 1 });
85 planning_scene::PlanningScenePtr
scene_;
91 auto scene{ planning_scene_monitor_->getPlanningScene() };
92 moveit_msgs::msg::PlanningScene msg;
93 msg.is_diff = msg.robot_state.is_diff =
true;
94 planning_scene_monitor_->newPlanningSceneMessage(msg);
95 EXPECT_EQ(
scene, planning_scene_monitor_->getPlanningScene());
96 msg.is_diff = msg.robot_state.is_diff =
false;
97 planning_scene_monitor_->newPlanningSceneMessage(msg);
98 EXPECT_EQ(
scene, planning_scene_monitor_->getPlanningScene());
103 #define TRIGGERS_UPDATE(msg, expected_update_type) \
105 planning_scene_monitor_->clearUpdateCallbacks(); \
106 auto received_update_type{ UpdateType::UPDATE_NONE }; \
107 planning_scene_monitor_->addUpdateCallback([&](auto type) { received_update_type = type; }); \
108 planning_scene_monitor_->newPlanningSceneMessage(msg); \
109 EXPECT_EQ(received_update_type, expected_update_type); \
114 moveit_msgs::msg::PlanningScene msg;
115 msg.is_diff = msg.robot_state.is_diff =
true;
118 msg.fixed_frame_transforms.emplace_back();
119 msg.fixed_frame_transforms.back().header.frame_id =
"base_link";
120 msg.fixed_frame_transforms.back().child_frame_id =
"object";
121 msg.fixed_frame_transforms.back().transform.rotation.w = 1.0;
123 msg.fixed_frame_transforms.clear();
125 msg.robot_state.is_diff =
true;
128 msg.robot_state.is_diff =
false;
129 TRIGGERS_UPDATE(msg, UpdateType::UPDATE_STATE | UpdateType::UPDATE_GEOMETRY);
131 msg.robot_state = moveit_msgs::msg::RobotState{};
132 msg.robot_state.is_diff =
true;
133 moveit_msgs::msg::CollisionObject collision_object;
134 collision_object.header.frame_id =
"base_link";
135 collision_object.id =
"object";
136 collision_object.operation = moveit_msgs::msg::CollisionObject::ADD;
137 collision_object.pose.orientation.w = 1.0;
138 collision_object.primitives.emplace_back();
139 collision_object.primitives.back().type = shape_msgs::msg::SolidPrimitive::SPHERE;
140 collision_object.primitives.back().dimensions = { 1.0 };
141 msg.world.collision_objects.emplace_back(collision_object);
144 msg.world.collision_objects.clear();
150 int main(
int argc,
char** argv)
152 rclcpp::init(argc, argv);
153 ::testing::InitGoogleTest(&argc, argv);
154 int result = RUN_ALL_TESTS();
planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_
rclcpp::Executor::SharedPtr executor_
planning_scene::PlanningScenePtr scene_
std::thread executor_thread_
std::shared_ptr< rclcpp::Node > test_node_
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::msg::RobotState &robot_state, bool copy_attached_bodies=true)
Convert a MoveIt robot state to a robot state message.
int main(int argc, char **argv)
TEST_F(PlanningSceneMonitorTest, TestPersistentScene)
#define TRIGGERS_UPDATE(msg, expected_update_type)