sot-core  4.11.8
Hierarchical task solver plug-in for dynamic-graph.
robot-utils.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2019
3  * LAAS-CNRS
4  * A. Del Prete, T. Flayols, O. Stasse, F. Bailly
5  *
6  */
7 
8 #ifndef __sot_core_robot_utils_H__
9 #define __sot_core_robot_utils_H__
10 
11 /* --------------------------------------------------------------------- */
12 /* --- INCLUDE --------------------------------------------------------- */
13 /* --------------------------------------------------------------------- */
14 
15 #include <map>
16 #include <pinocchio/fwd.hpp>
17 // keep pinocchio before boost
18 
19 #include <dynamic-graph/linear-algebra.h>
20 #include <dynamic-graph/logger.h>
21 #include <dynamic-graph/signal-helper.h>
22 
23 #include <boost/assign.hpp>
24 #include <boost/property_tree/ptree.hpp>
26 
27 namespace dynamicgraph {
28 namespace sot {
29 
31  double upper;
32  double lower;
33 
34  JointLimits() : upper(0.0), lower(0.0) {}
35 
36  JointLimits(double l, double u) : upper(u), lower(l) {}
37 };
38 
40 
42  public:
44  ExtractJointMimics(std::string &robot_model);
45 
47  const std::vector<std::string> &get_mimic_joints();
48 
49  private:
50  void go_through(boost::property_tree::ptree &pt, int level, int stage);
51 
52  // Create empty property tree object
53  boost::property_tree::ptree tree_;
54  std::vector<std::string> mimic_joints_;
55  std::string current_joint_name_;
56  void go_through_full();
57 };
58 
60  Eigen::VectorXd upper;
61  Eigen::VectorXd lower;
62 
63  ForceLimits() : upper(Vector6d::Zero()), lower(Vector6d::Zero()) {}
64 
65  ForceLimits(const Eigen::VectorXd &l, const Eigen::VectorXd &u)
66  : upper(u), lower(l) {}
67 
68  void display(std::ostream &os) const;
69 };
70 
72  std::map<Index, ForceLimits> m_force_id_to_limits;
73  std::map<std::string, Index> m_name_to_force_id;
74  std::map<Index, std::string> m_force_id_to_name;
75 
76  Index m_Force_Id_Left_Hand, m_Force_Id_Right_Hand, m_Force_Id_Left_Foot,
78 
79  void set_name_to_force_id(const std::string &name, const Index &force_id);
80 
81  void set_force_id_to_limits(const Index &force_id,
82  const dynamicgraph::Vector &lf,
83  const dynamicgraph::Vector &uf);
84 
85  void create_force_id_to_name_map();
86 
87  Index get_id_from_name(const std::string &name);
88 
89  const std::string &get_name_from_id(Index idx);
90  std::string cp_get_name_from_id(Index idx);
91 
92  const ForceLimits &get_limits_from_id(Index force_id);
93  ForceLimits cp_get_limits_from_id(Index force_id);
94 
95  Index get_force_id_left_hand() { return m_Force_Id_Left_Hand; }
96 
97  void set_force_id_left_hand(Index anId) { m_Force_Id_Left_Hand = anId; }
98 
99  Index get_force_id_right_hand() { return m_Force_Id_Right_Hand; }
100 
101  void set_force_id_right_hand(Index anId) { m_Force_Id_Right_Hand = anId; }
102 
103  Index get_force_id_left_foot() { return m_Force_Id_Left_Foot; }
104 
105  void set_force_id_left_foot(Index anId) { m_Force_Id_Left_Foot = anId; }
106 
107  Index get_force_id_right_foot() { return m_Force_Id_Right_Foot; }
108 
109  void set_force_id_right_foot(Index anId) { m_Force_Id_Right_Foot = anId; }
110 
111  void display(std::ostream &out) const;
112 
113 }; // struct ForceUtil
114 
117  dynamicgraph::Vector m_Right_Foot_Sole_XYZ;
118 
120  dynamicgraph::Vector m_Right_Foot_Force_Sensor_XYZ;
121 
124  void display(std::ostream &os) const;
125 };
126 
130  void display(std::ostream &os) const;
131 };
132 
134  public:
135  RobotUtil();
136 
139 
142 
145 
147  std::vector<Index> m_urdf_to_sot;
148 
150  std::size_t m_nbJoints;
151 
153  std::map<std::string, Index> m_name_to_id;
154 
156  std::map<Index, std::string> m_id_to_name;
157 
159  std::map<Index, JointLimits> m_limits_map;
160 
162  std::string m_imu_joint_name;
163 
167  void create_id_to_name_map();
168 
170  std::string m_urdf_filename;
171 
172  dynamicgraph::Vector m_dgv_urdf_to_sot;
173 
178  const Index &get_id_from_name(const std::string &name);
179 
186  const std::string &get_name_from_id(Index id);
188 
190  void set_name_to_id(const std::string &jointName, const Index &jointId);
191 
193  void set_urdf_to_sot(const std::vector<Index> &urdf_to_sot);
194  void set_urdf_to_sot(const dynamicgraph::Vector &urdf_to_sot);
195 
197  void set_joint_limits_for_id(const Index &idx, const double &lq,
198  const double &uq);
199 
200  bool joints_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot);
201 
202  bool joints_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf);
203 
204  bool velocity_urdf_to_sot(ConstRefVector q_urdf, ConstRefVector v_urdf,
205  RefVector v_sot);
206 
207  bool velocity_sot_to_urdf(ConstRefVector q_urdf, ConstRefVector v_sot,
208  RefVector v_urdf);
209 
210  bool config_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot);
211  bool config_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf);
212 
213  bool base_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot);
214  bool base_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf);
215 
221  const JointLimits &get_joint_limits_from_id(Index id);
222  JointLimits cp_get_joint_limits_from_id(Index id);
223 
226  void sendMsg(const std::string &msg, MsgType t = MSG_TYPE_INFO,
229  const std::string &lineId = "");
230 
232  void setLoggerVerbosityLevel(LoggerVerbosity lv) { logger_.setVerbosity(lv); }
233 
235  LoggerVerbosity getLoggerVerbosityLevel() { return logger_.getVerbosity(); };
236 
237  void display(std::ostream &os) const;
238 
244  template <typename Type>
245  void set_parameter(const std::string &parameter_name,
246  const Type &parameter_value) {
247  try {
248  typedef boost::property_tree::ptree::path_type path;
249  path apath(parameter_name, '/');
250  property_tree_.put<Type>(apath, parameter_value);
251  } catch (const boost::property_tree::ptree_error &e) {
252  std::ostringstream oss;
253  oss << "Robot utils: parameter path is invalid " << '\n'
254  << " for set_parameter(" << parameter_name << ")\n"
255  << e.what() << std::endl;
256  sendMsg(oss.str(), MSG_TYPE_ERROR);
257  return;
258  }
259  }
260 
267  template <typename Type>
268  Type get_parameter(const std::string &parameter_name) {
269  try {
270  boost::property_tree::ptree::path_type apath(parameter_name, '/');
271  const Type &res = property_tree_.get<Type>(apath);
272 
273  return res;
274  } catch (const boost::property_tree::ptree_error &e) {
275  std::ostringstream oss;
276  oss << "Robot utils: parameter path is invalid " << '\n'
277  << " for get_parameter(" << parameter_name << ")\n"
278  << e.what() << std::endl;
279  sendMsg(oss.str(), MSG_TYPE_ERROR);
280  throw;
281  }
282  }
286  boost::property_tree::ptree &get_property_tree();
287 
288  protected:
289  Logger logger_;
290 
292  std::map<std::string, std::string> parameters_strings_;
293 
295  boost::property_tree::ptree property_tree_;
296 }; // struct RobotUtil
297 
299 typedef std::shared_ptr<RobotUtil> RobotUtilShrPtr;
300 
302 RobotUtilShrPtr getRobotUtil(std::string &robotName);
303 bool isNameInRobotUtil(std::string &robotName);
304 RobotUtilShrPtr createRobotUtil(std::string &robotName);
305 std::shared_ptr<std::vector<std::string> > getListOfRobots();
306 
308 
309 } // namespace sot
310 } // namespace dynamicgraph
311 
312 #endif // sot_torque_control_common_h_
dynamicgraph::sot::ForceUtil::get_force_id_left_hand
Index get_force_id_left_hand()
Definition: robot-utils.hh:95
dynamicgraph::sot::RobotUtil::m_id_to_name
std::map< Index, std::string > m_id_to_name
The map between id and name.
Definition: robot-utils.hh:156
dynamicgraph::sot::RobotUtil::m_urdf_to_sot
std::vector< Index > m_urdf_to_sot
Map from the urdf index to the SoT index.
Definition: robot-utils.hh:147
SOT_CORE_EXPORT
#define SOT_CORE_EXPORT
Definition: api.hh:20
dynamicgraph::sot::ForceLimits::upper
Eigen::VectorXd upper
Definition: robot-utils.hh:60
dynamicgraph::sot::createRobotUtil
RobotUtilShrPtr createRobotUtil(std::string &robotName)
dynamicgraph::sot::RobotUtil::m_nbJoints
std::size_t m_nbJoints
Nb of Dofs for the robot.
Definition: robot-utils.hh:150
dynamicgraph::sot::base_se3_to_sot
bool base_se3_to_sot(ConstRefVector pos, ConstRefMatrix R, RefVector q_sot)
dynamicgraph
Definition: abstract-sot-external-interface.hh:17
dynamicgraph::sot::ForceUtil::get_force_id_right_foot
Index get_force_id_right_foot()
Definition: robot-utils.hh:107
dynamicgraph::sot::RobotUtil::property_tree_
boost::property_tree::ptree property_tree_
Property tree.
Definition: robot-utils.hh:295
dynamicgraph::sot::RobotUtil::get_parameter
Type get_parameter(const std::string &parameter_name)
Get a parameter of type string. If parameter_name already exists the value is overwritten....
Definition: robot-utils.hh:268
dynamicgraph::sot::Index
Eigen::VectorXd::Index Index
Definition: robot-utils.hh:39
dynamicgraph::sot::ForceUtil::m_Force_Id_Right_Foot
Index m_Force_Id_Right_Foot
Definition: robot-utils.hh:77
dynamicgraph::sot::FootUtil::m_Right_Foot_Frame_Name
std::string m_Right_Foot_Frame_Name
Definition: robot-utils.hh:123
dynamicgraph::sot::ConstRefMatrix
const typedef Eigen::Ref< const Eigen::MatrixXd > ConstRefMatrix
Definition: matrix-geometry.hh:72
dynamicgraph::sot::ForceUtil
Definition: robot-utils.hh:71
dynamicgraph::sot::RobotUtil::setLoggerVerbosityLevel
void setLoggerVerbosityLevel(LoggerVerbosity lv)
Specify the verbosity level of the logger.
Definition: robot-utils.hh:232
dynamicgraph::sot::ForceUtil::get_force_id_right_hand
Index get_force_id_right_hand()
Definition: robot-utils.hh:99
dynamicgraph::sot::RobotUtil::parameters_strings_
std::map< std::string, std::string > parameters_strings_
Map of the parameters: map of strings.
Definition: robot-utils.hh:292
dynamicgraph::sot::JointLimits::upper
double upper
Definition: robot-utils.hh:31
dynamicgraph::sot::RobotUtil::m_dgv_urdf_to_sot
dynamicgraph::Vector m_dgv_urdf_to_sot
Definition: robot-utils.hh:172
dynamicgraph::sot::RobotUtil::set_parameter
void set_parameter(const std::string &parameter_name, const Type &parameter_value)
Set a parameter of type string. If parameter_name already exists the value is overwritten....
Definition: robot-utils.hh:245
dynamicgraph::sot::ConstRefVector
const typedef Eigen::Ref< const Eigen::VectorXd > & ConstRefVector
Definition: matrix-geometry.hh:70
dynamicgraph::sot::getListOfRobots
std::shared_ptr< std::vector< std::string > > getListOfRobots()
dynamicgraph::sot::ForceUtil::get_force_id_left_foot
Index get_force_id_left_foot()
Definition: robot-utils.hh:103
dynamicgraph::sot::RobotUtilShrPtr
std::shared_ptr< RobotUtil > RobotUtilShrPtr
Accessors - This should be changed to RobotUtilPtrShared.
Definition: robot-utils.hh:299
dynamicgraph::sot::RobotUtil::getLoggerVerbosityLevel
LoggerVerbosity getLoggerVerbosityLevel()
Get the logger's verbosity level.
Definition: robot-utils.hh:235
dynamicgraph::sot::ForceUtil::set_force_id_left_hand
void set_force_id_left_hand(Index anId)
Definition: robot-utils.hh:97
dynamicgraph::sot::RobotUtil::m_limits_map
std::map< Index, JointLimits > m_limits_map
The joint limits map.
Definition: robot-utils.hh:159
dynamicgraph::sot::FootUtil
Definition: robot-utils.hh:115
dynamicgraph::sot::RobotUtil::logger_
Logger logger_
Definition: robot-utils.hh:289
dynamicgraph::sot::ForceLimits::ForceLimits
ForceLimits(const Eigen::VectorXd &l, const Eigen::VectorXd &u)
Definition: robot-utils.hh:65
dynamicgraph::sot::RobotUtil::m_force_util
ForceUtil m_force_util
Forces data.
Definition: robot-utils.hh:138
dynamicgraph::sot::ForceUtil::set_force_id_left_foot
void set_force_id_left_foot(Index anId)
Definition: robot-utils.hh:105
dynamicgraph::sot::ForceLimits::ForceLimits
ForceLimits()
Definition: robot-utils.hh:63
dynamicgraph::sot::RefVoidRobotUtil
RobotUtilShrPtr RefVoidRobotUtil()
dynamicgraph::sot::JointLimits::JointLimits
JointLimits()
Definition: robot-utils.hh:34
dynamicgraph::sot::ForceUtil::m_force_id_to_limits
std::map< Index, ForceLimits > m_force_id_to_limits
Definition: robot-utils.hh:72
dynamicgraph::sot::JointLimits
Definition: robot-utils.hh:30
dynamicgraph::sot::HandUtil
Definition: robot-utils.hh:127
dynamicgraph::sot::ExtractJointMimics
Definition: robot-utils.hh:41
dynamicgraph::sot::HandUtil::m_Right_Hand_Frame_Name
std::string m_Right_Hand_Frame_Name
Definition: robot-utils.hh:129
dynamicgraph::sot::JointLimits::JointLimits
JointLimits(double l, double u)
Definition: robot-utils.hh:36
dynamicgraph::sot::ForceUtil::m_force_id_to_name
std::map< Index, std::string > m_force_id_to_name
Definition: robot-utils.hh:74
dynamicgraph::sot::FootUtil::m_Right_Foot_Force_Sensor_XYZ
dynamicgraph::Vector m_Right_Foot_Force_Sensor_XYZ
Position of the force/torque sensors w.r.t. the frame of the hosting link.
Definition: robot-utils.hh:120
matrix-geometry.hh
dynamicgraph::sot::RefVector
Eigen::Ref< Eigen::VectorXd > RefVector
Definition: matrix-geometry.hh:69
dynamicgraph::sot::RobotUtil::m_hand_util
HandUtil m_hand_util
Hand information.
Definition: robot-utils.hh:144
dynamicgraph::sot::ForceUtil::m_Force_Id_Right_Hand
Index m_Force_Id_Right_Hand
Definition: robot-utils.hh:76
dynamicgraph::sot::getRobotUtil
RobotUtilShrPtr getRobotUtil(std::string &robotName)
dynamicgraph::sot::RobotUtil
Definition: robot-utils.hh:133
dynamicgraph::sot::FootUtil::m_Left_Foot_Frame_Name
std::string m_Left_Foot_Frame_Name
Definition: robot-utils.hh:122
dynamicgraph::sot::JointLimits::lower
double lower
Definition: robot-utils.hh:32
dynamicgraph::sot::ForceUtil::m_name_to_force_id
std::map< std::string, Index > m_name_to_force_id
Definition: robot-utils.hh:73
dynamicgraph::sot::ForceUtil::set_force_id_right_hand
void set_force_id_right_hand(Index anId)
Definition: robot-utils.hh:101
dynamicgraph::sot::RobotUtil::m_imu_joint_name
std::string m_imu_joint_name
The name of the joint IMU is attached to.
Definition: robot-utils.hh:162
dynamicgraph::sot::RobotUtil::m_urdf_filename
std::string m_urdf_filename
URDF file path.
Definition: robot-utils.hh:170
dynamicgraph::sot::RobotUtil::m_name_to_id
std::map< std::string, Index > m_name_to_id
Map from the name to the id.
Definition: robot-utils.hh:153
dynamicgraph::sot::HandUtil::m_Left_Hand_Frame_Name
std::string m_Left_Hand_Frame_Name
Definition: robot-utils.hh:128
dynamicgraph::sot::ForceUtil::set_force_id_right_foot
void set_force_id_right_foot(Index anId)
Definition: robot-utils.hh:109
dynamicgraph::sot::ForceLimits::lower
Eigen::VectorXd lower
Definition: robot-utils.hh:61
dynamicgraph::sot::RobotUtil::m_foot_util
FootUtil m_foot_util
Foot information.
Definition: robot-utils.hh:141
dynamicgraph::sot::ForceLimits
Definition: robot-utils.hh:59
dynamicgraph::sot::FootUtil::m_Right_Foot_Sole_XYZ
dynamicgraph::Vector m_Right_Foot_Sole_XYZ
Position of the foot soles w.r.t. the frame of the foot.
Definition: robot-utils.hh:117
dynamicgraph::sot::isNameInRobotUtil
bool isNameInRobotUtil(std::string &robotName)