matrix_parser.cpp
Go to the documentation of this file.
2 
4 {
7 
8 bool MatrixParser::parseMatrixData(Eigen::MatrixXd &M,
9  const std::string param_name,
10  const ros::NodeHandle &n)
11 {
12  std::vector<double> vals;
13  if (n.hasParam(param_name.c_str()))
14  {
15  if (n.hasParam((param_name + std::string("/data").c_str())))
16  {
17  n.getParam((param_name + std::string("/data")).c_str(), vals);
18  initializeEigenMatrix(M, vals);
19  }
20  else
21  {
22  ROS_ERROR_STREAM("MatrixParser: Matrix definition "
23  << param_name << " has no data values (" << param_name
24  << "/data)! Shutting down...");
25  return false;
26  }
27  }
28  else
29  {
30  ROS_ERROR_STREAM("MatrixParser: Configuration name " << param_name
31  << " does not exist");
32  return false;
33  }
34 
35  return true;
36 }
37 
38 void MatrixParser::initializeEigenMatrix(Eigen::MatrixXd &M,
39  const std::vector<double> &vals)
40 {
41  double size_f, frac_part, discard;
42  int size;
43 
44  size_f = std::sqrt(vals.size());
45  frac_part = std::modf(size_f, &discard);
46 
47  size = (int)size_f;
48  if (frac_part != 0.0)
49  {
50  std::stringstream errMsg;
51  errMsg << "MatrixParser: Tried to initialize a square matrix with a "
52  "non-square (got: "
53  << vals.size() << ") number of values";
54  throw std::logic_error(errMsg.str().c_str());
55  }
56 
57  ROS_DEBUG("MatrixParser: filling matrix");
58 
59  M = Eigen::MatrixXd(size, size);
60 
61  for (int i = 0; i < size; i++)
62  {
63  for (int j = 0; j < size; j++)
64  {
65  M(i, j) = vals[i * size + j];
66  }
67  }
68 }
69 
70 Eigen::Matrix3d MatrixParser::computeSkewSymmetric(const Eigen::Vector3d &v)
71 {
72  Eigen::Matrix3d S;
73 
74  S << 0, -v(2), v(1), v(2), 0, -v(0), -v(1), v(0), 0;
75 
76  return S;
77 }
78 } // namespace generic_control_toolbox
static Eigen::Matrix3d computeSkewSymmetric(const Eigen::Vector3d &v)
static void initializeEigenMatrix(Eigen::MatrixXd &M, const std::vector< double > &vals)
static bool parseMatrixData(Eigen::MatrixXd &M, const std::string param_name, const ros::NodeHandle &n)
bool getParam(const std::string &key, std::string &s) const
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)
#define ROS_DEBUG(...)


generic_control_toolbox
Author(s): diogo
autogenerated on Thu Jun 6 2019 19:54:44