matrix_parser.cpp
Go to the documentation of this file.
00001 #include <generic_control_toolbox/matrix_parser.hpp>
00002 
00003 namespace generic_control_toolbox
00004 {
00005 MatrixParser::MatrixParser() {}
00006 MatrixParser::~MatrixParser() {}
00007 
00008 bool MatrixParser::parseMatrixData(Eigen::MatrixXd &M,
00009                                    const std::string param_name,
00010                                    const ros::NodeHandle &n)
00011 {
00012   std::vector<double> vals;
00013   if (n.hasParam(param_name.c_str()))
00014   {
00015     if (n.hasParam((param_name + std::string("/data").c_str())))
00016     {
00017       n.getParam((param_name + std::string("/data")).c_str(), vals);
00018       initializeEigenMatrix(M, vals);
00019     }
00020     else
00021     {
00022       ROS_ERROR_STREAM("MatrixParser: Matrix definition "
00023                        << param_name << " has no data values (" << param_name
00024                        << "/data)! Shutting down...");
00025       return false;
00026     }
00027   }
00028   else
00029   {
00030     ROS_ERROR_STREAM("MatrixParser: Configuration name " << param_name
00031                                                          << " does not exist");
00032     return false;
00033   }
00034 
00035   return true;
00036 }
00037 
00038 void MatrixParser::initializeEigenMatrix(Eigen::MatrixXd &M,
00039                                          const std::vector<double> &vals)
00040 {
00041   double size_f, frac_part, discard;
00042   int size;
00043 
00044   size_f = std::sqrt(vals.size());
00045   frac_part = std::modf(size_f, &discard);
00046 
00047   size = (int)size_f;
00048   if (frac_part != 0.0)
00049   {
00050     std::stringstream errMsg;
00051     errMsg << "MatrixParser: Tried to initialize a square matrix with a "
00052               "non-square (got: "
00053            << vals.size() << ") number of values";
00054     throw std::logic_error(errMsg.str().c_str());
00055   }
00056 
00057   ROS_DEBUG("MatrixParser: filling matrix");
00058 
00059   M = Eigen::MatrixXd(size, size);
00060 
00061   for (int i = 0; i < size; i++)
00062   {
00063     for (int j = 0; j < size; j++)
00064     {
00065       M(i, j) = vals[i * size + j];
00066     }
00067   }
00068 }
00069 
00070 Eigen::Matrix3d MatrixParser::computeSkewSymmetric(const Eigen::Vector3d &v)
00071 {
00072   Eigen::Matrix3d S;
00073 
00074   S << 0, -v(2), v(1), v(2), 0, -v(0), -v(1), v(0), 0;
00075 
00076   return S;
00077 }
00078 }  // namespace generic_control_toolbox


generic_control_toolbox
Author(s): diogo
autogenerated on Thu Jun 6 2019 18:02:57