Moby
URDFReader.h
1 /****************************************************************************
2  * Copyright 2013 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _URDF_READER_H
8 #define _URDF_READER_H
9 
10 #ifdef USE_OSG
11 #include <osg/Node>
12 #endif
13 #include <map>
14 #include <string>
15 #include <queue>
16 #include <vector>
17 #include <boost/shared_ptr.hpp>
18 #include <Ravelin/VectorNd.h>
19 #include <Ravelin/MatrixNd.h>
20 
21 namespace Moby {
22 
23 class BoxPrimitive;
24 class SpherePrimitive;
25 class CylinderPrimitive;
26 class TriangleMeshPrimitive;
27 class Simulator;
28 class RigidBody;
29 class RCArticulatedBody;
30 class MCArticulatedBody;
31 class Primitive;
32 
35 {
36  public:
37  static bool read(const std::string& fname, std::string& name, std::vector<RigidBodyPtr>& links, std::vector<JointPtr>& joints);
38 
39  private:
40  class URDFData
41  {
42  public:
43  ~URDFData()
44  {
45  #ifdef USE_OSG
46  for (std::map<RigidBodyPtr, void*>::const_iterator i = visual_transform_nodes.begin(); i != visual_transform_nodes.end(); i++)
47  ((osg::Node*) i->second)->unref();
48  #endif
49  }
50 
51  std::map<RigidBodyPtr, void*> visual_transform_nodes;
52  std::map<JointPtr, RigidBodyPtr> joint_parent, joint_child;
53  std::map<std::string, std::pair<Ravelin::VectorNd, std::string> > materials;
54  std::map<RigidBodyPtr, boost::shared_ptr<Ravelin::Pose3d> > visualization_poses;
55  std::map<CollisionGeometryPtr, boost::shared_ptr<Ravelin::Pose3d> > collision_poses;
56  std::map<RigidBodyPtr, boost::shared_ptr<Ravelin::Pose3d> > inertial_poses;
57  };
58 
59  static void find_outboards(const URDFData& data, RigidBodyPtr link, std::vector<std::pair<JointPtr, RigidBodyPtr> >& outboards, std::map<RigidBodyPtr, RigidBodyPtr>& parents);
60  static void output_data(const URDFData& data, RigidBodyPtr link);
61  static JointPtr find_joint(const URDFData& data, RigidBodyPtr outboard_link);
62  static void find_children(const URDFData& data, RigidBodyPtr link, std::queue<RigidBodyPtr>& q, std::map<RigidBodyPtr, RigidBodyPtr>& parents);
63  static bool read_texture(boost::shared_ptr<const XMLTree> node, URDFData& data, std::string& fname);
64  static bool read_color(boost::shared_ptr<const XMLTree> node, URDFData& data, Ravelin::VectorNd& color);
65  static void read_material(boost::shared_ptr<const XMLTree> node, URDFData& data, void* osg_node);
66  static PrimitivePtr read_primitive(boost::shared_ptr<const XMLTree> node, URDFData& data);
67 // static boost::shared_ptr<TriangleMeshPrimitive> read_trimesh(boost::shared_ptr<const XMLTree> node, URDFData& data);
68  static boost::shared_ptr<SpherePrimitive> read_sphere(boost::shared_ptr<const XMLTree> node, URDFData& data);
69  static boost::shared_ptr<BoxPrimitive> read_box(boost::shared_ptr<const XMLTree> node, URDFData& data);
70  static boost::shared_ptr<CylinderPrimitive> read_cylinder(boost::shared_ptr<const XMLTree> node, URDFData& data);
71  static Ravelin::Matrix3d read_inertia(boost::shared_ptr<const XMLTree> node, URDFData& data);
72  static double read_mass(boost::shared_ptr<const XMLTree> node, URDFData& data);
73  static Ravelin::Pose3d read_origin(boost::shared_ptr<const XMLTree> node, URDFData& data);
74  static void read_collision(boost::shared_ptr<const XMLTree> node, URDFData& data, RigidBodyPtr link);
75  static void read_visual(boost::shared_ptr<const XMLTree> node, URDFData& data, RigidBodyPtr link);
76  static void read_inertial(boost::shared_ptr<const XMLTree> node, URDFData& data, RigidBodyPtr link);
77  static void read_safety_controller(boost::shared_ptr<const XMLTree> node, URDFData& data, JointPtr joint);
78  static void read_calibration(boost::shared_ptr<const XMLTree> node, URDFData& data, JointPtr joint);
79  static void read_limits(boost::shared_ptr<const XMLTree> node, URDFData& data, JointPtr joint);
80  static void read_dynamics(boost::shared_ptr<const XMLTree> node, URDFData& data, JointPtr joint);
81  static void read_axis(boost::shared_ptr<const XMLTree> node, URDFData& data, JointPtr joint);
82  static RigidBodyPtr read_parent(boost::shared_ptr<const XMLTree> node, URDFData& data, const std::vector<RigidBodyPtr>& links);
83  static RigidBodyPtr read_child(boost::shared_ptr<const XMLTree> node, URDFData& data, const std::vector<RigidBodyPtr>& links);
84  static void read_joint(boost::shared_ptr<const XMLTree> node, URDFData& data, const std::vector<RigidBodyPtr>& links, std::vector<JointPtr>& joints);
85  static void read_joints(boost::shared_ptr<const XMLTree> node, URDFData& data, const std::vector<RigidBodyPtr>& links, std::vector<JointPtr>& joints);
86  static void read_links(boost::shared_ptr<const XMLTree> node, URDFData& data, std::vector<RigidBodyPtr>& links);
87  static void read_link(boost::shared_ptr<const XMLTree> node, URDFData& data, std::vector<RigidBodyPtr>& links);
88  static bool read_robot(boost::shared_ptr<const XMLTree> node, URDFData& data, std::string& name, std::vector<RigidBodyPtr>& links, std::vector<JointPtr>& joints);
89 }; // end class
90 } // end namespace
91 
92 #endif
93 
boost::shared_ptr< Primitive > PrimitivePtr
Primitive smart pointer.
Definition: Types.h:80
Used to read the simulator state from URDF.
Definition: URDFReader.h:34
boost::shared_ptr< RigidBody > RigidBodyPtr
Rigid body smart pointer.
Definition: Types.h:62
static bool read(const std::string &fname, std::string &name, std::vector< RigidBodyPtr > &links, std::vector< JointPtr > &joints)
Reads an XML file and constructs all read objects.
Definition: URDFReader.cpp:65
boost::shared_ptr< Joint > JointPtr
Reduced-coordinate articulated body joint smart pointer.
Definition: Types.h:74