37#include <gtest/gtest.h>
41#include <urdf_parser/urdf_parser.h>
46#include <tf2_eigen/tf2_eigen.hpp>
50void 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);
63TEST(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;
75 Eigen::Isometry3d primitive_pose;
76 tf2::fromMsg(co.primitive_poses.at(0), primitive_pose);
79 <<
"scene did not use only primitive pose as object pose";
82TEST(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);
96 Eigen::Isometry3d object_pose;
97 tf2::fromMsg(co.pose, object_pose);
100 <<
"scene did not implicitly fill in identity pose for only primitive";
103TEST(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(?)";
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();
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;
157 <<
"scene removed attached object from collision world (although it's not there)";
160 aco.object.operation = moveit_msgs::msg::CollisionObject::REMOVE;
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";
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....
bool usePlanningSceneMsg(const moveit_msgs::msg::PlanningScene &scene)
Call setPlanningSceneMsg() or setPlanningSceneDiffMsg() depending on how the is_diff member of the me...
bool processCollisionObjectMsg(const moveit_msgs::msg::CollisionObject &object)
const Eigen::Isometry3d & getFrameTransform(const std::string &id) const
Get the transform corresponding to the frame id. This will be known if id is a link name,...
const object_recognition_msgs::msg::ObjectType & getObjectType(const std::string &id) const
bool knowsFrameTransform(const std::string &id) const
Check if a transform to the frame id is known. This will be known if id is a link name,...
bool processAttachedCollisionObjectMsg(const moveit_msgs::msg::AttachedCollisionObject &object)
bool hasObjectColor(const std::string &id) const
bool hasObjectType(const std::string &id) const
const std_msgs::msg::ColorRGBA & getObjectColor(const std::string &id) const
Gets the current color of an object.
int main(int argc, char **argv)
TEST(PlanningScene, fillInObjectPoseFromPrimitive)