40 #include <moveit_resources/config.h> 41 #include <urdf_parser/urdf_parser.h> 43 #include <boost/filesystem.hpp> 44 #include <gtest/gtest.h> 47 #ifndef VISUALIZE_PR2_RVIZ 48 #define VISUALIZE_PR2_RVIZ 0 51 #if VISUALIZE_PR2_RVIZ 53 #include <visualization_msgs/Marker.h> 62 std::string file_string;
63 std::fstream file(path.string().c_str(), std::fstream::in);
69 std::getline(file, line);
70 file_string += (line +
"\n");
81 urdf::ModelInterfaceSharedPtr parsed_urdf(urdf::parseURDF(urdf));
83 throw std::runtime_error(
"Cannot parse URDF.");
86 bool srdf_ok = parsed_srdf->initString(*parsed_urdf, srdf);
88 throw std::runtime_error(
"Cannot parse URDF.");
107 boost::filesystem::path res_path(MOVEIT_TEST_RESOURCES_DIR);
109 const std::string PR2_URDF = this->
readFileToString(res_path /
"pr2_description/urdf/robot.xml");
110 const std::string PR2_SRDF = this->
readFileToString(res_path /
"pr2_description/srdf/robot.xml");
134 EXPECT_NEAR(offsetBaseLink[2], 0.656175 / 2, 1e-4);
136 std::vector<double> pr2_aabb;
138 ASSERT_EQ(pr2_aabb.size(), 6);
141 EXPECT_NEAR(pr2_aabb[1], 0.6499, 1e-4);
142 EXPECT_NEAR(pr2_aabb[2], -0.6682 / 2, 1e-4);
143 EXPECT_NEAR(pr2_aabb[3], 0.6682 / 2, 1e-4);
144 EXPECT_NEAR(pr2_aabb[4], 0.0044, 1e-4);
145 EXPECT_NEAR(pr2_aabb[5], 1.6328, 1e-4);
156 EXPECT_NEAR(aabb.center()[0], 0.5394, 1e-4);
157 EXPECT_NEAR(aabb.center()[1], 0.1880, 1e-4);
158 EXPECT_NEAR(aabb.center()[2], 1.1665, 1e-4);
159 EXPECT_NEAR(aabb.sizes()[0], 0.2209, 1e-4);
160 EXPECT_NEAR(aabb.sizes()[1], 0.1201, 1e-4);
161 EXPECT_NEAR(aabb.sizes()[2], 0.2901, 1e-4);
163 #if VISUALIZE_PR2_RVIZ 164 std::cout <<
"Overall bounding box of PR2:" << std::endl;
165 std::string dims[] = {
"x",
"y",
"z" };
166 for (std::size_t i = 0; i < 3; ++i)
168 double dim = pr2_aabb[2 * i + 1] - pr2_aabb[2 * i];
169 double center = dim / 2;
170 std::cout << dims[i] <<
": size=" << dim <<
", offset=" << (pr2_aabb[2 * i + 1] - center) << std::endl;
185 visualization_msgs::Marker msg;
186 msg.header.frame_id = pr2_state.
getRobotModel()->getRootLinkName();
187 msg.type = visualization_msgs::Marker::CUBE;
189 msg.lifetime.sec = 3000;
193 msg.pose.position.x = (pr2_aabb[0] + pr2_aabb[1]) / 2;
194 msg.pose.position.y = (pr2_aabb[2] + pr2_aabb[3]) / 2;
195 msg.pose.position.z = (pr2_aabb[4] + pr2_aabb[5]) / 2;
196 msg.pose.orientation.x = msg.pose.orientation.y = msg.pose.orientation.z = 0;
197 msg.pose.orientation.w = 1;
198 msg.scale.x = pr2_aabb[1] - pr2_aabb[0];
199 msg.scale.y = pr2_aabb[3] - pr2_aabb[2];
200 msg.scale.z = pr2_aabb[5] - pr2_aabb[4];
204 std::vector<const moveit::core::LinkModel*> links = pr2_state.
getRobotModel()->getLinkModelsWithCollisionGeometry();
205 for (std::size_t i = 0; i < links.size(); ++i)
208 const Eigen::Vector3d& extents = links[i]->getShapeExtentsAtOrigin();
209 transform.translate(links[i]->getCenteredBoundingBoxOffset());
214 msg.ns = links[i]->getName();
215 msg.pose.position.x = transform.translation()[0];
216 msg.pose.position.y = transform.translation()[1];
217 msg.pose.position.z = transform.translation()[2];
218 msg.pose.orientation.x = msg.pose.orientation.y = msg.pose.orientation.z = 0;
219 msg.pose.orientation.w = 1;
222 msg.scale.x = aabb.sizes()[0];
223 msg.scale.y = aabb.sizes()[1];
224 msg.scale.z = aabb.sizes()[2];
229 msg.pose.position.x = transform.translation()[0];
230 msg.pose.position.y = transform.translation()[1];
231 msg.pose.position.z = transform.translation()[2];
232 msg.scale.x = extents[0];
233 msg.scale.y = extents[1];
234 msg.scale.z = extents[2];
237 Eigen::Quaterniond q(transform.linear());
238 msg.pose.orientation.x = q.x();
239 msg.pose.orientation.y = q.y();
240 msg.pose.orientation.z = q.z();
241 msg.pose.orientation.w = q.w();
242 pub_obb.publish(msg);
246 std::vector<const moveit::core::AttachedBody*> attached_bodies;
248 for (std::vector<const moveit::core::AttachedBody*>::const_iterator it = attached_bodies.begin();
249 it != attached_bodies.end(); ++it)
252 const std::vector<shapes::ShapeConstPtr>&
shapes = (*it)->getShapes();
253 for (std::size_t i = 0; i < transforms.size(); ++i)
260 msg.ns = (*it)->getName() + boost::lexical_cast<std::string>(i);
261 msg.pose.position.x = transforms[i].translation()[0];
262 msg.pose.position.y = transforms[i].translation()[1];
263 msg.pose.position.z = transforms[i].translation()[2];
264 msg.pose.orientation.x = msg.pose.orientation.y = msg.pose.orientation.z = 0;
265 msg.pose.orientation.w = 1;
268 msg.scale.x = aabb.sizes()[0];
269 msg.scale.y = aabb.sizes()[1];
270 msg.scale.z = aabb.sizes()[2];
275 msg.pose.position.x = transforms[i].translation()[0];
276 msg.pose.position.y = transforms[i].translation()[1];
277 msg.pose.position.z = transforms[i].translation()[2];
278 msg.scale.x = extents[0];
279 msg.scale.y = extents[1];
280 msg.scale.z = extents[2];
283 Eigen::Quaterniond q(transforms[i].linear());
284 msg.pose.orientation.x = q.x();
285 msg.pose.orientation.y = q.y();
286 msg.pose.orientation.z = q.z();
287 msg.pose.orientation.w = q.w();
288 pub_obb.publish(msg);
298 const std::string SIMPLE_URDF =
299 "<?xml version='1.0' ?>" 300 "<robot name='simple'>" 301 " <link name='base_link'>" 303 " <origin rpy='0 0 0' xyz='0 0 0'/>" 305 " <mesh filename='package://moveit_resources/pr2_description/urdf/meshes/base_v0/base_L.stl'/>" 309 " <link name='base_footprint'>" 311 " <origin rpy='0 0 0' xyz='0 0 0.071'/>" 313 " <box size='0.001 0.001 0.001'/>" 317 " <joint name='base_footprint_joint' type='fixed'>" 318 " <origin rpy='0 0 0' xyz='0 0 0.051'/>" 319 " <child link='base_link'/>" 320 " <parent link='base_footprint'/>" 324 const std::string SIMPLE_SRDF =
325 "<?xml version='1.0'?>" 326 "<robot name='simple'> " 327 " <virtual_joint name='world_joint' type='planar' parent_frame='odom_combined' child_link='base_footprint'/> " 328 " <group name='base'>" 329 " <joint name='world_joint'/>" 335 std::vector<double> simple_aabb;
338 ASSERT_EQ(simple_aabb.size(), 6);
340 EXPECT_NEAR(simple_aabb[1], 0.6682 / 2, 1e-4);
341 EXPECT_NEAR(simple_aabb[2], -0.6682 / 2, 1e-4);
342 EXPECT_NEAR(simple_aabb[3], 0.6682 / 2, 1e-4);
343 EXPECT_NEAR(simple_aabb[4], 0.0510, 1e-4);
344 EXPECT_NEAR(simple_aabb[5], 0.7071, 1e-4);
351 const std::string COMPLEX_URDF =
"<?xml version='1.0' ?>" 352 "<robot name='complex'>" 353 " <link name='base_link'>" 355 " <origin rpy='0 0 1.5708' xyz='5.0 0 1.0'/>" 357 " <box size='1.0 0.1 0.1' />" 361 " <origin rpy='0 0 1.5708' xyz='4.0 0 1.0'/>" 363 " <box size='1.0 0.1 0.1' />" 367 " <link name='base_footprint'>" 369 " <origin rpy='0 1.5708 0' xyz='-5.0 0 -1.0'/>" 371 " <box size='0.1 1.0 0.1' />" 375 " <joint name='base_footprint_joint' type='fixed'>" 376 " <origin rpy='0 0 1.5708' xyz='0 0 1'/>" 377 " <child link='base_link'/>" 378 " <parent link='base_footprint'/>" 382 const std::string COMPLEX_SRDF =
383 "<?xml version='1.0'?>" 384 "<robot name='complex'> " 385 " <virtual_joint name='world_joint' type='planar' parent_frame='odom_combined' child_link='base_footprint'/> " 386 " <group name='base'>" 387 " <joint name='world_joint'/>" 407 std::vector<double> complex_aabb;
410 ASSERT_EQ(complex_aabb.size(), 6);
412 EXPECT_NEAR(complex_aabb[1], 0.5, 1e-4);
413 EXPECT_NEAR(complex_aabb[2], -0.5, 1e-4);
414 EXPECT_NEAR(complex_aabb[3], 5.05, 1e-4);
415 EXPECT_NEAR(complex_aabb[4], -1.05, 1e-4);
416 EXPECT_NEAR(complex_aabb[5], 2.05, 1e-4);
419 int main(
int argc,
char** argv)
421 testing::InitGoogleTest(&argc, argv);
422 return RUN_ALL_TESTS();
void getAttachedBodies(std::vector< const AttachedBody * > &attached_bodies) const
Get all bodies attached to the model corresponding to this state.
std::string readFileToString(boost::filesystem::path path) const
Core components of MoveIt!
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...
void publish(const boost::shared_ptr< M > &message) const
std::vector< Eigen::Affine3d, Eigen::aligned_allocator< Eigen::Affine3d > > vector_Affine3d
const Eigen::Affine3d & getGlobalLinkTransform(const std::string &link_name)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const Eigen::Vector3d & getShapeExtentsAtOrigin() const
Get the extents of the link's geometry (dimensions of axis-aligned bounding box around all shapes tha...
#define EXPECT_NEAR(a, b, prec)
Definition of a kinematic model. This class is not thread safe, however multiple instances can be cre...
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
void computeAABB(std::vector< double > &aabb) const
Compute an axis-aligned bounding box that contains the current state. The format for aabb is (minx...
void update(bool force=false)
Update all transforms.
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void extendWithTransformedBox(const Eigen::Affine3d &transform, const Eigen::Vector3d &box)
Extend with a box transformed by the given transform.
robot_state::RobotState loadModel(const std::string urdf, const std::string srdf)
const RobotModelConstPtr & getRobotModel() const
Get the robot model this state is constructed for.
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
Representation of a robot's state. This includes position, velocity, acceleration and effort...
A link from the robot. Contains the constant transform applied to the link and its geometry...
Eigen::Vector3d computeShapeExtents(const ShapeMsg &shape_msg)
TEST_F(TestAABB, TestPR2)
Represents an axis-aligned bounding box.