40 #include <urdf_parser/urdf_parser.h>
43 #include <gtest/gtest.h>
44 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
45 #include <tf2/LinearMath/Vector3.h>
49 #ifndef VISUALIZE_PR2_RVIZ
50 #define VISUALIZE_PR2_RVIZ 0
53 #if VISUALIZE_PR2_RVIZ
54 #include <rclcpp/rclcpp.hpp>
55 #include <visualization_msgs/msg/marker.hpp>
56 #include <geometric_shapes/shape_operations.h>
92 EXPECT_NEAR(extents_base_footprint[0], 0.001, 1e-4);
93 EXPECT_NEAR(extents_base_footprint[1], 0.001, 1e-4);
94 EXPECT_NEAR(extents_base_footprint[2], 0.001, 1e-4);
98 EXPECT_NEAR(offset_base_footprint[0], 0.0, 1e-4);
99 EXPECT_NEAR(offset_base_footprint[1], 0.0, 1e-4);
100 EXPECT_NEAR(offset_base_footprint[2], 0.071, 1e-4);
104 EXPECT_NEAR(extents_base_link[0], 0.668242, 1e-4);
105 EXPECT_NEAR(extents_base_link[1], 0.668242, 1e-4);
106 EXPECT_NEAR(extents_base_link[2], 0.656175, 1e-4);
109 EXPECT_NEAR(offset_base_link[0], 0.0, 1e-4);
110 EXPECT_NEAR(offset_base_link[1], 0.0, 1e-4);
111 EXPECT_NEAR(offset_base_link[2], 0.656175 / 2, 1e-4);
113 std::vector<double> pr2_aabb;
115 ASSERT_EQ(pr2_aabb.size(), 6u);
117 EXPECT_NEAR(pr2_aabb[0], -0.3376, 1e-4);
118 EXPECT_NEAR(pr2_aabb[1], 0.6499, 1e-4);
119 EXPECT_NEAR(pr2_aabb[2], -0.6682 / 2, 1e-4);
120 EXPECT_NEAR(pr2_aabb[3], 0.6682 / 2, 1e-4);
121 EXPECT_NEAR(pr2_aabb[4], 0.0044, 1e-4);
122 EXPECT_NEAR(pr2_aabb[5], 1.6328, 1e-4);
133 EXPECT_NEAR(aabb.center()[0], 0.5394, 1e-4);
134 EXPECT_NEAR(aabb.center()[1], 0.1880, 1e-4);
135 EXPECT_NEAR(aabb.center()[2], 1.1665, 1e-4);
136 EXPECT_NEAR(aabb.sizes()[0], 0.2209, 1e-4);
137 EXPECT_NEAR(aabb.sizes()[1], 0.1201, 1e-4);
138 EXPECT_NEAR(aabb.sizes()[2], 0.2901, 1e-4);
140 #if VISUALIZE_PR2_RVIZ
141 std::cout <<
"Overall bounding box of PR2:" <<
'\n';
142 std::string dims[] = {
"x",
"y",
"z" };
143 for (std::size_t i = 0; i < 3; ++i)
145 double dim = pr2_aabb[2 * i + 1] - pr2_aabb[2 * i];
146 double center = dim / 2;
147 std::cout << dims[i] <<
": size=" << dim <<
", offset=" << (pr2_aabb[2 * i + 1] - center) <<
'\n';
153 rclcpp::init(argc, argv);
154 auto node = rclcpp::Node::make_shared(
"visualize_pr2");
156 node->create_publisher<visualization_msgs::msg::Marker>(
"/visualization_aabb", rmw_qos_profile_default);
157 auto pub_obb = node->create_publisher<visualization_msgs::msg::Marker>(
"/visualization_obb", rmw_qos_profile_default);
158 rclcpp::Rate loop_rate(10);
164 auto msg = std::make_shared<visualization_msgs::msg::Marker>();
166 msg->header.frame_id = pr2_state.
getRobotModel()->getRootLinkName();
167 msg->type = visualization_msgs::msg::Marker::CUBE;
169 msg->lifetime.sec = 3000;
173 msg->pose.position.x = (pr2_aabb[0] + pr2_aabb[1]) / 2;
174 msg->pose.position.y = (pr2_aabb[2] + pr2_aabb[3]) / 2;
175 msg->pose.position.z = (pr2_aabb[4] + pr2_aabb[5]) / 2;
176 msg->pose.orientation.x = msg->pose.orientation.y = msg->pose.orientation.z = 0;
177 msg->pose.orientation.w = 1;
178 msg->scale.x = pr2_aabb[1] - pr2_aabb[0];
179 msg->scale.y = pr2_aabb[3] - pr2_aabb[2];
180 msg->scale.z = pr2_aabb[5] - pr2_aabb[4];
181 pub_aabb->publish(msg);
184 std::vector<const moveit::core::LinkModel*> links = pr2_state.
getRobotModel()->getLinkModelsWithCollisionGeometry();
185 for (std::size_t i = 0; i < links.size(); ++i)
189 transform.translate(links[i]->getCenteredBoundingBoxOffset());
194 msg->ns = links[i]->getName();
195 msg->pose.position.x = transform.translation()[0];
196 msg->pose.position.y = transform.translation()[1];
197 msg->pose.position.z = transform.translation()[2];
198 msg->pose.orientation.x = msg->pose.orientation.y = msg->pose.orientation.z = 0;
199 msg->pose.orientation.w = 1;
202 msg->scale.x = aabb.sizes()[0];
203 msg->scale.y = aabb.sizes()[1];
204 msg->scale.z = aabb.sizes()[2];
205 pub_aabb->publish(msg);
209 msg->pose.position.x = transform.translation()[0];
210 msg->pose.position.y = transform.translation()[1];
211 msg->pose.position.z = transform.translation()[2];
212 msg->scale.x = extents[0];
213 msg->scale.y = extents[1];
214 msg->scale.z = extents[2];
217 Eigen::Quaterniond q(transform.linear());
218 msg->pose.orientation.x = q.x();
219 msg->pose.orientation.y = q.y();
220 msg->pose.orientation.z = q.z();
221 msg->pose.orientation.w = q.w();
222 pub_obb->publish(msg);
226 std::vector<const moveit::core::AttachedBody*> attached_bodies;
228 for (std::vector<const moveit::core::AttachedBody*>::const_iterator it = attached_bodies.begin();
229 it != attached_bodies.end(); ++it)
231 const EigenSTL::vector_Isometry3d& transforms = (*it)->getGlobalCollisionBodyTransforms();
232 const std::vector<shapes::ShapeConstPtr>&
shapes = (*it)->getShapes();
233 for (std::size_t i = 0; i < transforms.size(); ++i)
240 msg->ns = (*it)->getName() + std::to_string(i);
241 msg->pose.position.x = transforms[i].translation()[0];
242 msg->pose.position.y = transforms[i].translation()[1];
243 msg->pose.position.z = transforms[i].translation()[2];
244 msg->pose.orientation.x = msg->pose.orientation.y = msg->pose.orientation.z = 0;
245 msg->pose.orientation.w = 1;
248 msg->scale.x = aabb.sizes()[0];
249 msg->scale.y = aabb.sizes()[1];
250 msg->scale.z = aabb.sizes()[2];
251 pub_aabb->publish(msg);
255 msg->pose.position.x = transforms[i].translation()[0];
256 msg->pose.position.y = transforms[i].translation()[1];
257 msg->pose.position.z = transforms[i].translation()[2];
258 msg->scale.x = extents[0];
259 msg->scale.y = extents[1];
260 msg->scale.z = extents[2];
263 Eigen::Quaterniond q(transforms[i].linear());
264 msg->pose.orientation.x = q.x();
265 msg->pose.orientation.y = q.y();
266 msg->pose.orientation.z = q.z();
267 msg->pose.orientation.w = q.w();
268 pub_obb->publish(msg);
278 geometry_msgs::msg::Pose origin;
279 origin.position.x = 0;
280 origin.position.y = 0;
281 origin.position.z = 0.051;
282 origin.orientation.w = 1.0;
283 builder.
addChain(
"base_footprint->base_link",
"fixed", { origin });
285 origin.position.x = 0;
286 origin.position.y = 0;
287 origin.position.z = 0;
288 builder.
addCollisionMesh(
"base_link",
"package://moveit_resources_pr2_description/urdf/meshes/base_v0/base_L.stl",
291 origin.position.x = 0;
292 origin.position.y = 0;
293 origin.position.z = 0.071;
294 builder.
addCollisionBox(
"base_footprint", { 0.001, 0.001, 0.001 }, origin);
296 builder.
addVirtualJoint(
"odom_combined",
"base_footprint",
"planar",
"world_joint");
297 builder.
addGroup({}, {
"world_joint" },
"base");
299 ASSERT_TRUE(builder.
isValid());
301 std::vector<double> simple_aabb;
304 ASSERT_EQ(simple_aabb.size(), 6u);
305 EXPECT_NEAR(simple_aabb[0], -0.6682 / 2, 1e-4);
306 EXPECT_NEAR(simple_aabb[1], 0.6682 / 2, 1e-4);
307 EXPECT_NEAR(simple_aabb[2], -0.6682 / 2, 1e-4);
308 EXPECT_NEAR(simple_aabb[3], 0.6682 / 2, 1e-4);
309 EXPECT_NEAR(simple_aabb[4], 0.0510, 1e-4);
310 EXPECT_NEAR(simple_aabb[5], 0.7071, 1e-4);
317 geometry_msgs::msg::Pose origin;
318 origin.position.x = 0;
319 origin.position.y = 0;
320 origin.position.z = 1.0;
322 q.setRPY(0, 0, 1.5708);
323 origin.orientation = tf2::toMsg(q);
324 builder.
addChain(
"base_footprint->base_link",
"fixed", { origin });
325 origin.position.x = 5.0;
326 origin.position.y = 0;
327 origin.position.z = 1.0;
329 origin.position.x = 4.0;
330 origin.position.y = 0;
331 origin.position.z = 1.0;
333 origin.position.x = -5.0;
334 origin.position.y = 0;
335 origin.position.z = -1.0;
336 q.setRPY(0, 1.5708, 0);
337 origin.orientation = tf2::toMsg(q);
339 builder.
addVirtualJoint(
"odom_combined",
"base_footprint",
"planar",
"world_joint");
340 builder.
addGroup({}, {
"world_joint" },
"base");
342 ASSERT_TRUE(builder.
isValid());
359 std::vector<double> complex_aabb;
362 ASSERT_EQ(complex_aabb.size(), 6u);
363 EXPECT_NEAR(complex_aabb[0], -5.05, 1e-4);
364 EXPECT_NEAR(complex_aabb[1], 0.5, 1e-4);
365 EXPECT_NEAR(complex_aabb[2], -0.5, 1e-4);
366 EXPECT_NEAR(complex_aabb[3], 5.05, 1e-4);
367 EXPECT_NEAR(complex_aabb[4], -1.05, 1e-4);
368 EXPECT_NEAR(complex_aabb[5], 2.05, 1e-4);
371 int main(
int argc,
char** argv)
373 testing::InitGoogleTest(&argc, argv);
374 return RUN_ALL_TESTS();
moveit::core::RobotState loadModel(const moveit::core::RobotModelPtr &model)
moveit::core::RobotState loadModel(const std::string &robot_name)
Represents an axis-aligned bounding box.
void extendWithTransformedBox(const Eigen::Isometry3d &transform, const Eigen::Vector3d &box)
Extend with a box transformed by the given transform.
A link from the robot. Contains the constant transform applied to the link and its geometry.
const Eigen::Vector3d & getShapeExtentsAtOrigin() const
Get the extents of the link's geometry (dimensions of axis-aligned bounding box around all shapes tha...
const Eigen::Vector3d & getCenteredBoundingBoxOffset() const
Get the offset of the center of the bounding box of this link when the link is positioned at origin.
Easily build different robot models for testing. Essentially a programmer-friendly light wrapper arou...
void addChain(const std::string §ion, const std::string &type, const std::vector< geometry_msgs::msg::Pose > &joint_origins={}, urdf::Vector3 joint_axis=urdf::Vector3(1.0, 0.0, 0.0))
Adds a chain of links and joints to the builder. The joint names are generated automatically as "<par...
void addCollisionBox(const std::string &link_name, const std::vector< double > &dims, geometry_msgs::msg::Pose origin)
Adds a collision box to a specific link.
bool isValid()
Returns true if the building process so far has been valid.
void addGroup(const std::vector< std::string > &links, const std::vector< std::string > &joints, const std::string &name)
Adds a new group using a list of links and a list of joints.
moveit::core::RobotModelPtr build()
Builds and returns the robot model added to the builder.
void addVirtualJoint(const std::string &parent_frame, const std::string &child_link, const std::string &type, const std::string &name="")
Adds a virtual joint to the SRDF.
void addCollisionMesh(const std::string &link_name, const std::string &filename, geometry_msgs::msg::Pose origin)
Adds a collision mesh to a specific link.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
const Eigen::Isometry3d & getGlobalLinkTransform(const std::string &link_name)
Get the link transform w.r.t. the root link (model frame) of the RobotModel. This is typically the ro...
void getAttachedBodies(std::vector< const AttachedBody * > &attached_bodies) const
Get all bodies attached to the model corresponding to this state.
void computeAABB(std::vector< double > &aabb) const
Compute an axis-aligned bounding box that contains the current state. The format for aabb is (minx,...
const RobotModelConstPtr & getRobotModel() const
Get the robot model this state is constructed for.
void update(bool force=false)
Update all transforms.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
Vec3fX< details::Vec3Data< double > > Vector3d
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &robot_name)
Loads a robot from moveit_resources.
int main(int argc, char **argv)
TEST_F(TestAABB, TestPR2)