15 #ifdef BOOST_MPL_LIMIT_VECTOR_SIZE    16 #pragma push_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")    17 #undef BOOST_MPL_LIMIT_VECTOR_SIZE    18 #include <boost/property_tree/ptree.hpp>    19 #include <boost/property_tree/xml_parser.hpp>    20 #pragma pop_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")    22 #include <boost/property_tree/ptree.hpp>    23 #include <boost/property_tree/xml_parser.hpp>    26 #include <dynamic-graph/factory.h>    35 namespace dg = ::dynamicgraph;
    36 namespace pt = boost::property_tree;
    45   return std::shared_ptr<RobotUtil>(
nullptr);
    50   std::istringstream iss(robot_model);
    52   boost::property_tree::read_xml(iss, tree_);
    63   current_joint_name_ = 
"";
    64   go_through(tree_, 0, 0);
    72     if (stage == 3) current_joint_name_ = pt.data();
    76       int new_stage = stage;
    79       if (
pos.first == 
"joint")
    82       else if (
pos.first == 
"<xmlattr>") {
    85         if (stage == 1) new_stage = 2;
    89       else if (
pos.first == 
"name") {
    90         if (stage == 2) new_stage = 3;
    94       else if (
pos.first == 
"mimic") {
    98           mimic_joints_.push_back(current_joint_name_);
   103       go_through(
pos.second, level + 1, new_stage);
   109   os << 
"Lower limits:" << std::endl;
   110   os << lower << std::endl;
   111   os << 
"Upper Limits:" << std::endl;
   112   os << upper << std::endl;
   118   os << 
"Right Foot Sole XYZ " << std::endl;
   119   os << m_Right_Foot_Sole_XYZ << std::endl;
   120   os << 
"Left Foot Frame Name:" << m_Left_Foot_Frame_Name << std::endl;
   121   os << 
"Right Foot Frame Name:" << m_Right_Foot_Frame_Name << std::endl;
   127   os << 
"Left Hand Frame Name:" << m_Left_Hand_Frame_Name << std::endl;
   128   os << 
"Right Hand Frame Name:" << m_Right_Hand_Frame_Name << std::endl;
   134                                      const Index &force_id) {
   135   m_name_to_force_id[
name] = (
Index)force_id;
   136   create_force_id_to_name_map();
   138     set_force_id_right_foot(m_name_to_force_id[name]);
   139   else if (name == 
"lf")
   140     set_force_id_left_foot(m_name_to_force_id[name]);
   141   else if (name == 
"lh")
   142     set_force_id_left_hand(m_name_to_force_id[name]);
   143   else if (name == 
"rh")
   144     set_force_id_right_hand(m_name_to_force_id[name]);
   150   m_force_id_to_limits[(
Index)force_id].lower = lf;
   151   m_force_id_to_limits[(
Index)force_id].upper = uf;
   155   std::map<std::string, Index>::const_iterator it;
   156   it = m_name_to_force_id.find(name);
   157   if (it != m_name_to_force_id.end()) 
return it->second;
   165   std::map<Index, std::string>::const_iterator it;
   166   it = m_force_id_to_name.find(idx);
   167   if (it != m_force_id_to_name.end()) 
return it->second;
   172   const std::string &default_rtn = get_name_from_id(idx);
   176   std::map<std::string, Index>::const_iterator it;
   177   for (it = m_name_to_force_id.begin(); it != m_name_to_force_id.end(); it++)
   178     m_force_id_to_name[it->second] = it->first;
   182   std::map<Index, ForceLimits>::const_iterator iter =
   183       m_force_id_to_limits.find(force_id);
   184   if (iter == m_force_id_to_limits.end())
   185     return VoidForceLimits;  
   190   std::map<Index, ForceLimits>::const_iterator iter =
   191       m_force_id_to_limits.find(force_id);
   192   if (iter == m_force_id_to_limits.end())
   193     return VoidForceLimits;  
   198   os << 
"Force Id to limits " << std::endl;
   199   for (std::map<Index, ForceLimits>::const_iterator it =
   200            m_force_id_to_limits.begin();
   201        it != m_force_id_to_limits.end(); ++it) {
   202     it->second.display(os);
   205   os << 
"Name to force id:" << std::endl;
   206   for (std::map<std::string, Index>::const_iterator it =
   207            m_name_to_force_id.begin();
   208        it != m_name_to_force_id.end(); ++it) {
   209     os << 
"(" << it->first << 
"," << it->second << 
") ";
   213   os << 
"Force id to Name:" << std::endl;
   214   for (std::map<Index, std::string>::const_iterator it =
   215            m_force_id_to_name.begin();
   216        it != m_force_id_to_name.end(); ++it) {
   217     os << 
"(" << it->first << 
"," << it->second << 
") ";
   221   os << 
"Index for force sensors:" << std::endl;
   222   os << 
"Left Hand (" << m_Force_Id_Left_Hand << 
") ,"   223      << 
"Right Hand (" << m_Force_Id_Right_Hand << 
") ,"   224      << 
"Left Foot (" << m_Force_Id_Left_Foot << 
") ,"   225      << 
"Right Foot (" << m_Force_Id_Right_Foot << 
") " << std::endl;
   237   std::map<Index, JointLimits>::const_iterator iter = m_limits_map.find(
id);
   238   if (iter == m_limits_map.end()) 
return VoidJointLimits;
   242   const JointLimits &rtn = get_joint_limits_from_id(
id);
   247                                const Index &jointId) {
   248   m_name_to_id[jointName] = (
Index)jointId;
   249   create_id_to_name_map();
   253   std::map<std::string, Index>::const_iterator it;
   254   for (it = m_name_to_id.begin(); it != m_name_to_id.end(); it++)
   255     m_id_to_name[it->second] = it->first;
   259   std::map<std::string, Index>::const_iterator it = m_name_to_id.find(name);
   260   if (it == m_name_to_id.end()) 
return VoidIndex;
   265   std::map<Index, std::string>::const_iterator iter = m_id_to_name.find(
id);
   271   m_nbJoints = urdf_to_sot.size();
   272   m_urdf_to_sot.resize(urdf_to_sot.size());
   273   m_dgv_urdf_to_sot.resize(urdf_to_sot.size());
   274   for (std::size_t idx = 0; idx < urdf_to_sot.size(); idx++) {
   275     m_urdf_to_sot[(
Index)idx] = urdf_to_sot[(
Index)idx];
   276     m_dgv_urdf_to_sot[(
Index)idx] =
   277         static_cast<double>(urdf_to_sot[(
Index)idx]);
   282   m_nbJoints = urdf_to_sot.size();
   283   m_urdf_to_sot.resize(urdf_to_sot.size());
   284   for (
unsigned int idx = 0; idx < urdf_to_sot.size(); idx++) {
   285     m_urdf_to_sot[idx] = (
unsigned int)urdf_to_sot[idx];
   287   m_dgv_urdf_to_sot = urdf_to_sot;
   291   if (m_nbJoints == 0) {
   298   for (
unsigned int idx = 0; idx < m_nbJoints; idx++)
   299     q_sot[m_urdf_to_sot[idx]] = q_urdf[idx];
   307   if (m_nbJoints == 0) {
   312   for (
unsigned int idx = 0; idx < m_nbJoints; idx++)
   313     q_urdf[idx] = q_sot[m_urdf_to_sot[idx]];
   323   if (m_nbJoints == 0) {
   327   const Eigen::Quaterniond 
q(q_urdf(6), q_urdf(3), q_urdf(4), q_urdf(5));
   328   Eigen::Matrix3d oRb = q.toRotationMatrix();
   329   v_sot.head<3>() = oRb * v_urdf.head<3>();
   330   v_sot.segment<3>(3) = oRb * v_urdf.segment<3>(3);
   332   joints_urdf_to_sot(v_urdf.tail(m_nbJoints), v_sot.tail(m_nbJoints));
   342   if (m_nbJoints == 0) {
   347   const Eigen::Quaterniond 
q(q_urdf(6), q_urdf(3), q_urdf(4), q_urdf(5));
   348   Eigen::Matrix3d oRb = q.toRotationMatrix();
   349   v_urdf.head<3>() = oRb.transpose() * v_sot.head<3>();
   350   v_urdf.segment<3>(3) = oRb.transpose() * v_sot.segment<3>(3);
   352   joints_sot_to_urdf(v_sot.tail(m_nbJoints), v_urdf.tail(m_nbJoints));
   357   assert(q_urdf.size() == 7);
   358   assert(q_sot.size() == 6);
   361   const double W = q_urdf[6];
   362   const double X = q_urdf[3];
   363   const double Y = q_urdf[4];
   364   const double Z = q_urdf[5];
   365   const Eigen::Matrix3d 
R = Eigen::Quaterniond(W, X, Y, Z).toRotationMatrix();
   370   assert(q_urdf.size() == 7);
   371   assert(q_sot.size() == 6);
   373   const double r = q_sot[3];
   374   const double p = q_sot[4];
   375   const double y = q_sot[5];
   376   const Eigen::AngleAxisd rollAngle(r, Eigen::Vector3d::UnitX());
   377   const Eigen::AngleAxisd pitchAngle(p, Eigen::Vector3d::UnitY());
   378   const Eigen::AngleAxisd yawAngle(y, Eigen::Vector3d::UnitZ());
   379   const Eigen::Quaternion<double> 
quat = yawAngle * pitchAngle * rollAngle;
   381   q_urdf[0] = q_sot[0];  
   382   q_urdf[1] = q_sot[1];
   383   q_urdf[2] = q_sot[2];
   384   q_urdf[3] = quat.x();
   385   q_urdf[4] = quat.y();
   386   q_urdf[5] = quat.z();
   387   q_urdf[6] = quat.w();
   397   joints_urdf_to_sot(q_urdf.tail(m_nbJoints), q_sot.tail(m_nbJoints));
   406   joints_sot_to_urdf(q_sot.tail(m_nbJoints), q_urdf.tail(m_nbJoints));
   410   m_force_util.display(os);
   411   m_foot_util.display(os);
   412   m_hand_util.display(os);
   413   os << 
"Nb of joints: " << m_nbJoints << std::endl;
   414   os << 
"Urdf file name: " << m_urdf_filename << std::endl;
   417   os << 
"Map from urdf index to the Sot Index " << std::endl;
   418   for (
unsigned int i = 0; 
i < m_urdf_to_sot.size(); 
i++)
   419     os << 
"(" << 
i << 
" : " << m_urdf_to_sot[
i] << 
") ";
   422   os << 
"Joint name to joint id:" << std::endl;
   423   for (std::map<std::string, Index>::const_iterator it = m_name_to_id.begin();
   424        it != m_name_to_id.end(); ++it) {
   425     os << 
"(" << it->first << 
"," << it->second << 
") ";
   429   os << 
"Joint id to joint Name:" << std::endl;
   430   for (std::map<Index, std::string>::const_iterator it = m_id_to_name.begin();
   431        it != m_id_to_name.end(); ++it) {
   432     os << 
"(" << it->first << 
"," << it->second << 
") ";
   436   boost::property_tree::write_xml(os, property_tree_);
   440                         const std::string &lineId) {
   441   logger_.stream(t, lineId) << 
"[RobotUtil]" << msg << 
'\n';
   445   assert(q_sot.size() == 6);
   446   assert(pos.size() == 3);
   447   assert(R.rows() == 3);
   448   assert(R.cols() == 3);
   451   m = sqrt(R(2, 1) * R(2, 1) + R(2, 2) * R(2, 2));
   452   p = atan2(-R(2, 0), m);
   453   if (fabs(fabs(p) - 
M_PI / 2) < 0.001) {
   455     y = -atan2(R(0, 1), R(1, 1));
   457     y = atan2(R(1, 0), R(0, 0));
   458     r = atan2(R(2, 1), R(2, 2));
   471   assert(q_urdf.size() == 7);
   472   assert(q_sot.size() == 6);
   474   const double W = q_urdf[6];
   475   const double X = q_urdf[3];
   476   const double Y = q_urdf[4];
   477   const double Z = q_urdf[5];
   478   const Eigen::Matrix3d 
R = Eigen::Quaterniond(W, X, Y, Z).toRotationMatrix();
   483   assert(q_urdf.size() == 7);
   484   assert(q_sot.size() == 6);
   486   const double r = q_sot[3];
   487   const double p = q_sot[4];
   488   const double y = q_sot[5];
   489   const Eigen::AngleAxisd rollAngle(r, Eigen::Vector3d::UnitX());
   490   const Eigen::AngleAxisd pitchAngle(p, Eigen::Vector3d::UnitY());
   491   const Eigen::AngleAxisd yawAngle(y, Eigen::Vector3d::UnitZ());
   492   const Eigen::Quaternion<double> 
quat = yawAngle * pitchAngle * rollAngle;
   494   q_urdf[0] = q_sot[0];  
   495   q_urdf[1] = q_sot[1];
   496   q_urdf[2] = q_sot[2];
   497   q_urdf[3] = quat.x();
   498   q_urdf[4] = quat.y();
   499   q_urdf[5] = quat.z();
   500   q_urdf[6] = quat.w();
   508   std::shared_ptr<std::vector<std::string> > 
res =
   509       std::make_shared<std::vector<std::string> >();
   511   std::map<std::string, RobotUtilShrPtr>::iterator it =
   512       sgl_map_name_to_robot_util.begin();
   513   while (it != sgl_map_name_to_robot_util.end()) {
   514     res->push_back(it->first);
   522   std::map<std::string, RobotUtilShrPtr>::iterator it =
   523       sgl_map_name_to_robot_util.find(robotName);
   524   if (it != sgl_map_name_to_robot_util.end()) 
return it->second;
   529   std::map<std::string, RobotUtilShrPtr>::iterator it =
   530       sgl_map_name_to_robot_util.find(robotName);
   531   if (it != sgl_map_name_to_robot_util.end()) 
return true;
   536   std::map<std::string, RobotUtilShrPtr>::iterator it =
   537       sgl_map_name_to_robot_util.find(robotName);
   538   if (it == sgl_map_name_to_robot_util.end()) {
   539     sgl_map_name_to_robot_util[robotName] = std::make_shared<RobotUtil>();
   540     it = sgl_map_name_to_robot_util.find(robotName);
 void set_urdf_to_sot(const std::vector< Index > &urdf_to_sot)
Set the map between urdf index and sot index. 
bool base_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf)
const Eigen::Ref< const Eigen::VectorXd > & ConstRefVector
bool joints_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf)
const JointLimits & get_joint_limits_from_id(Index id)
bool base_se3_to_sot(ConstRefVector pos, ConstRefMatrix R, RefVector q_sot)
Eigen::VectorXd::Index Index
ForceLimits VoidForceLimits
RobotUtilShrPtr createRobotUtil(std::string &robotName)
const ForceLimits & get_limits_from_id(Index force_id)
void set_name_to_id(const std::string &jointName, const Index &jointId)
Set relation between the name and the SoT id. 
bool base_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot)
void sendMsg(const std::string &msg, MsgType t=MSG_TYPE_INFO, const std::string &lineId="")
Send messages msg with level t. Add string file and line to message. 
bool joints_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot)
const Index & get_id_from_name(const std::string &name)
std::shared_ptr< std::vector< std::string > > getListOfRobots()
const Eigen::Ref< const Eigen::MatrixXd > ConstRefMatrix
void display(std::ostream &os) const
std::string force_default_rtn("Force name not found")
void create_force_id_to_name_map()
void set_name_to_force_id(const std::string &name, const Index &force_id)
const std::string & get_name_from_id(Index idx)
std::shared_ptr< RobotUtil > RobotUtilShrPtr
Accessors - This should be changed to RobotUtilPtrShared. 
bool velocity_sot_to_urdf(ConstRefVector q_urdf, ConstRefVector v_sot, RefVector v_urdf)
void create_id_to_name_map()
void set_force_id_to_limits(const Index &force_id, const dynamicgraph::Vector &lf, const dynamicgraph::Vector &uf)
#define SEND_MSG(msg, type)
bool config_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot)
RobotUtilShrPtr RefVoidRobotUtil()
ForceLimits cp_get_limits_from_id(Index force_id)
std::string cp_get_name_from_id(Index idx)
void display(std::ostream &out) const
RobotUtilShrPtr getRobotUtil(std::string &robotName)
const std::string & get_name_from_id(Index id)
Get the joint name from its index. 
void display(std::ostream &os) const
Index get_id_from_name(const std::string &name)
bool base_urdf_to_sot(ConstRefVector q_urdf, RefVector q_sot)
bool config_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf)
bool velocity_urdf_to_sot(ConstRefVector q_urdf, ConstRefVector v_urdf, RefVector v_sot)
JointLimits VoidJointLimits
static std::map< std::string, RobotUtilShrPtr > sgl_map_name_to_robot_util
void display(std::ostream &os) const
std::string joint_default_rtn("Joint name not found")
Eigen::Ref< Eigen::VectorXd > RefVector
JointLimits cp_get_joint_limits_from_id(Index id)
void set_joint_limits_for_id(const Index &idx, const double &lq, const double &uq)
Set the limits (lq,uq) for joint idx. 
bool base_sot_to_urdf(ConstRefVector q_sot, RefVector q_urdf)
bool isNameInRobotUtil(std::string &robotName)