constrained_ik_utils.cpp
Go to the documentation of this file.
00001 
00026 #include <constrained_ik/constrained_ik_utils.h>
00027 #include <ros/ros.h>
00028 
00029 namespace constrained_ik
00030 {
00031   ConstrainedIKConfiguration convertToConstrainedIKConfiguration(CLIKDynamicConfig &config)
00032   {
00033     ConstrainedIKConfiguration c;
00034     c.debug_mode = config.debug_mode;
00035     c.allow_joint_convergence = config.allow_joint_convergence;
00036     c.allow_primary_normalization = config.allow_primary_normalization;
00037     c.allow_auxiliary_nomalization = config.allow_auxiliary_nomalization;
00038     c.limit_primary_motion = config.limit_primary_motion;
00039     c.limit_auxiliary_motion = config.limit_auxiliary_motion;
00040     c.limit_auxiliary_interations = config.limit_auxiliary_interations;
00041     c.solver_max_iterations = config.solver_max_iterations;
00042     c.solver_min_iterations = config.solver_min_iterations;
00043     c.auxiliary_max_iterations = config.auxiliary_max_iterations;
00044     c.primary_max_motion = config.primary_max_motion;
00045     c.auxiliary_max_motion = config.auxiliary_max_motion;
00046     c.primary_norm = config.primary_norm;
00047     c.auxiliary_norm = config.auxiliary_norm;
00048     c.primary_gain = config.primary_gain;
00049     c.auxiliary_gain = config.auxiliary_gain;
00050     c.joint_convergence_tol = config.joint_convergence_tol;
00051     return c;
00052   }
00053 
00054   bool getParam(XmlRpc::XmlRpcValue& config, const std::string& key, double& value)
00055   {
00056     if (!config.hasMember(key))
00057     {
00058       ROS_ERROR("XmlRpcValue does not contain key %s.", key.c_str());
00059       return false;
00060     }
00061     XmlRpc::XmlRpcValue param = config[key];
00062     if (param.getType() != XmlRpc::XmlRpcValue::TypeDouble &&
00063         param.getType() != XmlRpc::XmlRpcValue::TypeInt)
00064     {
00065       return false;
00066     }
00067     value = param;
00068     return true;
00069   }
00070 
00071   bool getParam(XmlRpc::XmlRpcValue& config, const std::string& key, std::vector<double>& double_array)
00072   {
00073     if (!config.hasMember(key))
00074     {
00075       ROS_ERROR("XmlRpcValue does not contain key %s.", key.c_str());
00076       return false;
00077     }
00078 
00079     XmlRpc::XmlRpcValue d_array_xml = config[key];
00080 
00081     if (d_array_xml.getType() != XmlRpc::XmlRpcValue::TypeArray)
00082     {
00083       ROS_ERROR("XmlRpcValue is not of type array.");
00084       return false;
00085     }
00086 
00087     double_array.clear();
00088     for (int i=0; i<d_array_xml.size(); ++i)
00089     {
00090       if (d_array_xml[i].getType() != XmlRpc::XmlRpcValue::TypeDouble &&
00091           d_array_xml[i].getType() != XmlRpc::XmlRpcValue::TypeInt)
00092       {
00093         ROS_ERROR("XmlRpcValue is neither a double nor a integer array.");
00094         return false;
00095       }
00096       double value = 0.0;
00097       if (d_array_xml[i].getType() == XmlRpc::XmlRpcValue::TypeInt)
00098       {
00099         value = static_cast<double>(static_cast<int>(d_array_xml[i]));
00100       }
00101       else
00102       {
00103         value = static_cast<double>(d_array_xml[i]);
00104       }
00105       double_array.push_back(value);
00106     }
00107 
00108     return true;
00109   }
00110 
00111   bool getParam(XmlRpc::XmlRpcValue& config, const std::string& key, Eigen::VectorXd& eigen_vector)
00112   {
00113     std::vector<double> double_array;
00114 
00115     if(!getParam(config, key, double_array))
00116       return false;
00117 
00118     eigen_vector = Eigen::VectorXd::Map(double_array.data(), double_array.size());
00119     return true;
00120   }
00121 
00122   bool getParam(XmlRpc::XmlRpcValue& config, const std::string& key, bool& value)
00123   {
00124     if (!config.hasMember(key))
00125     {
00126       ROS_ERROR("XmlRpcValue does not contain key %s.", key.c_str());
00127       return false;
00128     }
00129 
00130     XmlRpc::XmlRpcValue param = config[key];
00131     if (param.getType() != XmlRpc::XmlRpcValue::TypeBoolean)
00132       return false;
00133 
00134     value = param;
00135     return true;
00136   }
00137 
00138   bool getParam(XmlRpc::XmlRpcValue& config, const std::string& key, std::vector<std::string>& string_array)
00139   {
00140     if (!config.hasMember(key))
00141     {
00142       ROS_ERROR("XmlRpcValue does not contain key %s.", key.c_str());
00143       return false;
00144     }
00145 
00146     XmlRpc::XmlRpcValue s_array_xml = config[key];
00147 
00148     if (s_array_xml.getType() != XmlRpc::XmlRpcValue::TypeArray)
00149     {
00150       ROS_ERROR("XmlRpcValue is not of type array.");
00151       return false;
00152     }
00153 
00154     string_array.clear();
00155     for (int i=0; i<s_array_xml.size(); ++i)
00156     {
00157       if (s_array_xml[i].getType() != XmlRpc::XmlRpcValue::TypeString)
00158       {
00159         ROS_ERROR("XmlRpcValue is not a string array.");
00160         return false;
00161       }
00162       else
00163       {
00164         string_array.push_back(s_array_xml[i]);
00165       }
00166     }
00167 
00168     return true;
00169   }
00170 }


constrained_ik
Author(s): Chris Lewis , Jeremy Zoss , Dan Solomon
autogenerated on Sat Jun 8 2019 19:23:45