yaml.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <RBDyn/MultiBody.h>
9 #include <RBDyn/MultiBodyGraph.h>
10 #include <RBDyn/parsers/common.h>
11 
12 namespace YAML
13 {
14 class Node;
15 }
16 
17 namespace rbd
18 {
19 
20 namespace parsers
21 {
22 
24 {
25 public:
26  RBDynFromYAML(const std::string & input,
27  ParserInput input_type = ParserInput::File,
28  bool fixed = true,
29  const std::vector<std::string> & filtered_links = {},
30  bool transform_inertia = true,
31  const std::string & base_link = "",
32  bool with_virtual_links = true,
33  const std::string & spherical_suffix = "_spherical",
34  bool remove_filtered_links = true);
35 
37  {
38  return res;
39  }
40 
41  operator std::tuple<rbd::MultiBody &, rbd::MultiBodyConfig &, rbd::MultiBodyGraph &>()
42  {
43  return std::tie(res.mb, res.mbc, res.mbg);
44  }
45 
46 private:
47  ParserResult res;
48  bool verbose_;
49  bool transform_inertia_;
50  bool angles_in_degrees_;
51  std::string base_link_;
52  size_t link_idx_;
53  size_t joint_idx_;
54  std::map<std::string, rbd::Joint::Type> joint_types_;
55  std::vector<std::string> filtered_links_;
56  bool remove_filtered_links_;
57  bool with_virtual_links_;
58  const std::string & spherical_suffix_;
59  std::unordered_map<std::string, Material> materials_;
60  std::vector<std::string> fixed_links_;
61  std::vector<std::string> removed_links_;
62 
63  Eigen::Matrix3d makeInertia(double ixx, double iyy, double izz, double iyz, double ixz, double ixy);
64 
65  Eigen::Matrix3d MatrixFromRPY(double r, double p, double y);
66 
67  void parseFrame(const YAML::Node & frame, const std::string & name, Eigen::Vector3d & xyz, Eigen::Vector3d & rpy);
68 
69  void parseInertia(const YAML::Node & inertia, Eigen::Matrix3d & inertia_mat);
70 
71  void parseInertial(const YAML::Node & inertial,
72  const std::string & name,
73  double & mass,
74  Eigen::Vector3d & xyz,
75  Eigen::Vector3d & rpy,
76  Eigen::Matrix3d & inertia);
77 
78  bool parseGeometry(const YAML::Node & geometry, Geometry & data);
79 
80  void parseVisuals(const YAML::Node & visuals,
81  std::map<std::string, std::vector<Visual>> & data,
82  const std::string & name);
83 
85  void parseMaterial(const YAML::Node & material);
86 
91  void parseMaterial(const YAML::Node & material, Material & out, bool cache = true);
92 
93  void parseLink(const YAML::Node & link);
94 
95  bool parseJointType(const YAML::Node & type,
96  const std::string & name,
97  rbd::Joint::Type & joint_type,
98  std::string & type_name,
99  bool force_fixed);
100 
101  void parseJointAxis(const YAML::Node & axis, const std::string & name, Eigen::Vector3d & joint_axis);
102 
103  void parseJointLimits(const YAML::Node & limits,
104  const std::string & name,
105  const rbd::Joint & joint,
106  bool is_continuous);
107 
108  void parseJoint(const YAML::Node & joint);
109 };
110 
111 RBDYN_PARSERS_DLLAPI ParserResult from_yaml(const std::string & content,
112  bool fixed = true,
113  const std::vector<std::string> & filteredLinksIn = {},
114  bool transformInertia = true,
115  const std::string & baseLinkIn = "",
116  bool withVirtualLinks = true,
117  const std::string & sphericalSuffix = "_spherical");
118 
119 RBDYN_PARSERS_DLLAPI ParserResult from_yaml_file(const std::string & file_path,
120  bool fixed = true,
121  const std::vector<std::string> & filteredLinksIn = {},
122  bool transformInertia = true,
123  const std::string & baseLinkIn = "",
124  bool withVirtualLinks = true,
125  const std::string & sphericalSuffix = "_spherical");
126 
127 RBDYN_PARSERS_DLLAPI ParserResult from_yaml(const std::string & content, const ParserParameters & params);
128 
129 RBDYN_PARSERS_DLLAPI ParserResult from_yaml_file(const std::string & file_path, const ParserParameters & params);
130 
131 RBDYN_PARSERS_DLLAPI std::string to_yaml(const ParserResult & res);
132 
133 } // namespace parsers
134 
135 } // namespace rbd
rbd::parsers::Geometry
Definition: common.h:41
rbd::Joint::Type
Type
Joint type.
Definition: Joint.h:39
rbd::parsers::from_yaml
RBDYN_PARSERS_DLLAPI ParserResult from_yaml(const std::string &content, bool fixed=true, const std::vector< std::string > &filteredLinksIn={}, bool transformInertia=true, const std::string &baseLinkIn="", bool withVirtualLinks=true, const std::string &sphericalSuffix="_spherical")
rbd::parsers::RBDynFromYAML::result
ParserResult & result()
Definition: yaml.h:36
rbd::parsers::from_yaml_file
RBDYN_PARSERS_DLLAPI ParserResult from_yaml_file(const std::string &file_path, bool fixed=true, const std::vector< std::string > &filteredLinksIn={}, bool transformInertia=true, const std::string &baseLinkIn="", bool withVirtualLinks=true, const std::string &sphericalSuffix="_spherical")
rbd::parsers::ParserInput::File
@ File
YAML
Definition: yaml.h:12
rbd::Joint
Definition: Joint.h:35
rbd::parsers::ParserResult
Definition: common.h:228
RBDYN_PARSERS_DLLAPI
#define RBDYN_PARSERS_DLLAPI
Definition: api.h:43
MultiBodyConfig.h
rbd::parsers::RBDynFromYAML
Definition: yaml.h:23
rbd::parsers::Material
Definition: common.h:105
rbd
Definition: common.h:20
MultiBodyGraph.h
common.h
MultiBody.h
rbd::parsers::ParserInput
ParserInput
Definition: common.h:26
rbd::parsers::to_yaml
RBDYN_PARSERS_DLLAPI std::string to_yaml(const ParserResult &res)