37 #include <gtest/gtest.h>
41 #include <urdf_parser/urdf_parser.h>
46 #include <tf2_eigen/tf2_eigen.hpp>
50 void makeSphere(moveit_msgs::msg::CollisionObject& co)
53 shape_msgs::msg::SolidPrimitive primitive;
54 primitive.type = shape_msgs::msg::SolidPrimitive::SPHERE;
55 primitive.dimensions.push_back( 1.0);
56 co.primitives.push_back(primitive);
57 geometry_msgs::msg::Pose pose;
58 pose.orientation.w = 1.0;
59 co.primitive_poses.push_back(pose);
63 TEST(PlanningScene, fillInObjectPoseFromPrimitive)
68 moveit_msgs::msg::CollisionObject co;
69 co.header.frame_id = robot_model->getModelFrame();
70 co.id =
"object_no_pose";
71 co.operation = moveit_msgs::msg::CollisionObject::ADD;
73 scene.processCollisionObjectMsg(co);
75 Eigen::Isometry3d primitive_pose;
76 tf2::fromMsg(co.primitive_poses.at(0), primitive_pose);
77 ASSERT_TRUE(
scene.knowsFrameTransform(co.id)) <<
"failed to add object";
78 EXPECT_TRUE(
scene.getFrameTransform(co.id).isApprox(primitive_pose))
79 <<
"scene did not use only primitive pose as object pose";
82 TEST(PlanningScene, fillInPrimitivePose)
87 moveit_msgs::msg::CollisionObject co;
88 co.header.frame_id = robot_model->getModelFrame();
89 co.id =
"object_no_primitive_pose";
90 co.operation = moveit_msgs::msg::CollisionObject::ADD;
92 co.pose = co.primitive_poses.at(0);
93 co.primitive_poses.resize(0);
94 scene.processCollisionObjectMsg(co);
96 Eigen::Isometry3d object_pose;
97 tf2::fromMsg(co.pose, object_pose);
98 ASSERT_TRUE(
scene.knowsFrameTransform(co.id)) <<
"failed to add object";
99 EXPECT_TRUE(
scene.getFrameTransform(co.id).isApprox(object_pose))
100 <<
"scene did not implicitly fill in identity pose for only primitive";
103 TEST(PlanningScene, rememberMetadataWhenAttached)
109 moveit_msgs::msg::PlanningScene scene_msg;
110 scene_msg.robot_model_name = robot_model->getName();
111 scene_msg.is_diff =
true;
112 scene_msg.robot_state.is_diff =
true;
114 moveit_msgs::msg::CollisionObject co;
115 co.header.frame_id = robot_model->getModelFrame();
116 co.id =
"blue_sphere";
117 co.operation = moveit_msgs::msg::CollisionObject::ADD;
118 co.pose.orientation.w = 1.0;
122 co.type.key =
"blue_sphere_type";
123 co.type.db =
"{'type':'CustomDB'}";
124 scene_msg.world.collision_objects.push_back(co);
127 moveit_msgs::msg::ObjectColor color;
131 scene_msg.object_colors.push_back(color);
133 EXPECT_FALSE(
scene.hasObjectColor(co.id)) <<
"scene knows color before adding it(?)";
134 EXPECT_FALSE(
scene.hasObjectType(co.id)) <<
"scene knows type before adding it(?)";
137 scene.usePlanningSceneMsg(scene_msg);
139 EXPECT_TRUE(
scene.hasObjectColor(co.id)) <<
"scene failed to add object color";
140 EXPECT_EQ(
scene.getObjectColor(co.id), color.color) <<
"scene added wrong object color";
141 EXPECT_TRUE(
scene.hasObjectType(co.id)) <<
"scene failed to add object type";
142 EXPECT_EQ(
scene.getObjectType(co.id), co.type) <<
"scene added wrong object type";
145 moveit_msgs::msg::AttachedCollisionObject aco;
146 aco.object.operation = moveit_msgs::msg::CollisionObject::ADD;
147 aco.object.id = co.id;
148 aco.link_name = robot_model->getModelFrame();
149 scene.processAttachedCollisionObjectMsg(aco);
151 EXPECT_EQ(
scene.getObjectColor(co.id), color.color) <<
"scene forgot object color after it got attached";
152 EXPECT_EQ(
scene.getObjectType(co.id), co.type) <<
"scene forgot object type after it got attached";
155 co.operation = moveit_msgs::msg::CollisionObject::REMOVE;
156 EXPECT_FALSE(
scene.processCollisionObjectMsg(co))
157 <<
"scene removed attached object from collision world (although it's not there)";
160 aco.object.operation = moveit_msgs::msg::CollisionObject::REMOVE;
161 scene.processAttachedCollisionObjectMsg(aco);
163 EXPECT_EQ(
scene.getObjectColor(co.id), color.color) <<
"scene forgot specified color after attach/detach";
164 EXPECT_EQ(
scene.getObjectType(co.id), co.type) <<
"scene forgot specified type after attach/detach";
167 int main(
int argc,
char** argv)
169 testing::InitGoogleTest(&argc, argv);
170 return RUN_ALL_TESTS();
Easily build different robot models for testing. Essentially a programmer-friendly light wrapper arou...
This class maintains the representation of the environment as seen by a planning instance....
int main(int argc, char **argv)
TEST(PlanningScene, fillInObjectPoseFromPrimitive)