DART  6.10.1
DartLoader.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_UTILS_URDF_DARTLOADER_HPP_
34 #define DART_UTILS_URDF_DARTLOADER_HPP_
35 
36 #include <map>
37 #include <string>
38 #include <Eigen/Core>
39 #include <Eigen/Geometry>
40 
43 #include "dart/common/Uri.hpp"
45 #include "dart/dynamics/Joint.hpp"
50 
51 namespace urdf {
52 class ModelInterface;
53 class Link;
54 class Joint;
55 class Pose;
56 class Vector3;
57 } // namespace urdf
58 
59 namespace dart {
60 
61 namespace dynamics {
62 class Skeleton;
63 class BodyNode;
64 class Joint;
65 class Shape;
66 } // namespace dynamics
67 namespace simulation {
68 class World;
69 }
70 
71 namespace utils {
72 
77 {
78 public:
80  enum Flags
81  {
82  NONE = 0,
83 
86  FIXED_BASE_LINK = 1 << 1,
87 
90  };
91 
93  DartLoader();
94 
114  void addPackageDirectory(
115  const std::string& _packageName, const std::string& _packageDirectory);
116 
119  const common::Uri& _uri,
120  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr,
121  unsigned int flags = DEFAULT);
122 
125  const std::string& _urdfString,
126  const common::Uri& _baseUri,
127  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr,
128  unsigned int flags = DEFAULT);
129 
132  const common::Uri& _uri,
133  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr,
134  unsigned int flags = DEFAULT);
135 
138  const std::string& _urdfString,
139  const common::Uri& _baseUri,
140  const common::ResourceRetrieverPtr& _resourceRetriever = nullptr,
141  unsigned int flags = DEFAULT);
142 
143 private:
144  typedef std::shared_ptr<dynamics::BodyNode::Properties> BodyPropPtr;
145  typedef std::shared_ptr<dynamics::Joint::Properties> JointPropPtr;
146 
149  const urdf::ModelInterface* model,
150  const common::Uri& baseUri,
151  const common::ResourceRetrieverPtr& resourceRetriever,
152  unsigned int flags);
153 
154  static bool createSkeletonRecursive(
155  const urdf::ModelInterface* model,
157  const urdf::Link* lk,
158  dynamics::BodyNode* parent,
159  const common::Uri& baseUri,
160  const common::ResourceRetrieverPtr& _resourceRetriever,
161  unsigned int flags);
162 
163  static bool addMimicJointsRecursive(
164  const urdf::ModelInterface* model,
165  dynamics::SkeletonPtr _skel,
166  const urdf::Link* _lk);
167 
168  template <class VisualOrCollision>
170  const VisualOrCollision* _vizOrCol,
171  const common::Uri& _baseUri,
172  const common::ResourceRetrieverPtr& _resourceRetriever);
173 
175  const urdf::Joint* _jt,
176  const dynamics::BodyNode::Properties& _body,
177  dynamics::BodyNode* _parent,
178  dynamics::SkeletonPtr _skeleton,
179  unsigned int flgas);
180 
181  static bool createDartNodeProperties(
182  const urdf::Link* _lk,
184  const common::Uri& _baseUri,
185  const common::ResourceRetrieverPtr& _resourceRetriever);
186 
187  static bool createShapeNodes(
188  const urdf::ModelInterface* model,
189  const urdf::Link* lk,
190  dynamics::BodyNode* bodyNode,
191  const common::Uri& baseUri,
192  const common::ResourceRetrieverPtr& resourceRetriever);
193 
195  const common::ResourceRetrieverPtr& _resourceRetriever);
196 
197  static Eigen::Isometry3d toEigen(const urdf::Pose& _pose);
198  static Eigen::Vector3d toEigen(const urdf::Vector3& _vector);
199 
200  static bool readFileToString(
201  const common::ResourceRetrieverPtr& _resourceRetriever,
202  const common::Uri& _uri,
203  std::string& _output);
204 
208 };
209 
210 } // namespace utils
211 } // namespace dart
212 
213 #endif // DART_UTILS_URDF_DARTLOADER_HPP_
BodyPropPtr properties
Definition: SdfParser.cpp:80
Definition: CompositeData.hpp:186
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:79
Definition: DartLoader.hpp:77
utils::CompositeResourceRetrieverPtr mRetriever
Definition: DartLoader.hpp:207
static dynamics::ShapePtr createShape(const VisualOrCollision *_vizOrCol, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
@function createShape
Definition: DartLoader.cpp:666
static Eigen::Isometry3d toEigen(const urdf::Pose &_pose)
@function pose2Affine3d
Definition: DartLoader.cpp:751
Flags
Flags for specifying URDF file parsing policies.
Definition: DartLoader.hpp:81
@ NONE
Definition: DartLoader.hpp:82
@ DEFAULT
The default flgas.
Definition: DartLoader.hpp:89
@ FIXED_BASE_LINK
Parser the root link's joint type to be "fixed" joint when not specified.
Definition: DartLoader.hpp:86
static dart::dynamics::SkeletonPtr modelInterfaceToSkeleton(const urdf::ModelInterface *model, const common::Uri &baseUri, const common::ResourceRetrieverPtr &resourceRetriever, unsigned int flags)
Parses the ModelInterface and spits out a Skeleton object.
Definition: DartLoader.cpp:206
void addPackageDirectory(const std::string &_packageName, const std::string &_packageDirectory)
Specify the directory of a ROS package.
Definition: DartLoader.cpp:75
dart::simulation::WorldPtr parseWorldString(const std::string &_urdfString, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr, unsigned int flags=DEFAULT)
Parse a text string to produce a World.
Definition: DartLoader.cpp:148
common::ResourceRetrieverPtr getResourceRetriever(const common::ResourceRetrieverPtr &_resourceRetriever)
Definition: DartLoader.cpp:730
static bool createSkeletonRecursive(const urdf::ModelInterface *model, dynamics::SkeletonPtr skel, const urdf::Link *lk, dynamics::BodyNode *parent, const common::Uri &baseUri, const common::ResourceRetrieverPtr &_resourceRetriever, unsigned int flags)
Definition: DartLoader.cpp:263
static bool addMimicJointsRecursive(const urdf::ModelInterface *model, dynamics::SkeletonPtr _skel, const urdf::Link *_lk)
Definition: DartLoader.cpp:313
common::LocalResourceRetrieverPtr mLocalRetriever
Definition: DartLoader.hpp:205
std::shared_ptr< dynamics::Joint::Properties > JointPropPtr
Definition: DartLoader.hpp:145
static dynamics::BodyNode * createDartJointAndNode(const urdf::Joint *_jt, const dynamics::BodyNode::Properties &_body, dynamics::BodyNode *_parent, dynamics::SkeletonPtr _skeleton, unsigned int flgas)
@function createDartJoint
Definition: DartLoader.cpp:408
dart::simulation::WorldPtr parseWorld(const common::Uri &_uri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr, unsigned int flags=DEFAULT)
Parse a file to produce a World.
Definition: DartLoader.cpp:133
static bool readFileToString(const common::ResourceRetrieverPtr &_resourceRetriever, const common::Uri &_uri, std::string &_output)
@function readXml
Definition: DartLoader.cpp:365
std::shared_ptr< dynamics::BodyNode::Properties > BodyPropPtr
Definition: DartLoader.hpp:144
static bool createShapeNodes(const urdf::ModelInterface *model, const urdf::Link *lk, dynamics::BodyNode *bodyNode, const common::Uri &baseUri, const common::ResourceRetrieverPtr &resourceRetriever)
Definition: DartLoader.cpp:612
dynamics::SkeletonPtr parseSkeleton(const common::Uri &_uri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr, unsigned int flags=DEFAULT)
Parse a file to produce a Skeleton.
Definition: DartLoader.cpp:81
dynamics::SkeletonPtr parseSkeletonString(const std::string &_urdfString, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever=nullptr, unsigned int flags=DEFAULT)
Parse a text string to produce a Skeleton.
Definition: DartLoader.cpp:106
DartLoader()
Constructor with the default ResourceRetriever.
Definition: DartLoader.cpp:65
static bool createDartNodeProperties(const urdf::Link *_lk, dynamics::BodyNode::Properties &properties, const common::Uri &_baseUri, const common::ResourceRetrieverPtr &_resourceRetriever)
@function createDartNode
Definition: DartLoader.cpp:551
utils::PackageResourceRetrieverPtr mPackageRetriever
Definition: DartLoader.hpp:206
::fcl::Vec3f Vector3
Definition: BackwardCompatibility.hpp:148
std::shared_ptr< ResourceRetriever > ResourceRetrieverPtr
Definition: ResourceRetriever.hpp:76
std::shared_ptr< LocalResourceRetriever > LocalResourceRetrieverPtr
Definition: LocalResourceRetriever.hpp:58
std::shared_ptr< Shape > ShapePtr
Definition: SmartPointer.hpp:81
std::shared_ptr< Skeleton > SkeletonPtr
Definition: SmartPointer.hpp:60
std::shared_ptr< World > WorldPtr
Definition: SmartPointer.hpp:41
std::shared_ptr< CompositeResourceRetriever > CompositeResourceRetrieverPtr
Definition: CompositeResourceRetriever.hpp:91
std::shared_ptr< PackageResourceRetriever > PackageResourceRetrieverPtr
Definition: PackageResourceRetriever.hpp:112
Definition: BulletCollisionDetector.cpp:65
Definition: DartLoader.hpp:51
The Uri struct provides URI parsing and merging functionality based on RFC 3986.
Definition: Uri.hpp:87