ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
UtilsEigen.h
Go to the documentation of this file.
1 #ifndef __ROSEE_UTILS_EIGEN__
2 #define __ROSEE_UTILS_EIGEN__
3 
4 #include <Eigen/Dense>
5 #include <std_msgs/Float32MultiArray.h>
6 
7 namespace ROSEE
8 {
9 
10 namespace Utils
11 {
12 
19 static std_msgs::Float32MultiArray eigenMatrixToFloat32MultiArray (Eigen::MatrixXd eigenMatrix) {
20 
21  std_msgs::Float32MultiArray rosMatrix;
22 
23  unsigned int nRow = eigenMatrix.rows();
24  unsigned int nCol = eigenMatrix.cols();
25  unsigned int size = nRow*nCol;
26 
27  if (size == 0){ //no reason to continue
28  std::cerr << "[Utils::eigenMatrixToFloat32MultiArray] eigenMatrix passed has size 0" << std::endl;
29  return rosMatrix;
30  }
31 
32  rosMatrix.layout.dim.push_back(std_msgs::MultiArrayDimension());
33  rosMatrix.layout.dim.push_back(std_msgs::MultiArrayDimension());
34  rosMatrix.layout.dim[0].label = "column";
35  rosMatrix.layout.dim[0].size = nCol;
36  rosMatrix.layout.dim[0].stride = nCol*nRow;
37 
38  rosMatrix.layout.dim[1].label = "row";
39  rosMatrix.layout.dim[1].size = nRow;
40  rosMatrix.layout.dim[1].stride = nRow;
41 
42  rosMatrix.layout.data_offset = 0;
43 
44  rosMatrix.data.resize(size);
45  int posRow = 0;
46  for (int iCol=0; iCol<nCol; iCol++){
47  for (int iRow=0; iRow<nRow; iRow++){
48  posRow = iCol*nRow;
49  rosMatrix.data.at(posRow + iRow) = eigenMatrix(iRow,iCol);
50  }
51  }
52 
53  return rosMatrix;
54 
55 
56 }
57 
58 static std::vector<float> eigenVectorToStdVector (Eigen::VectorXd eigenVector) {
59 
60  std::vector<float> stdVect(eigenVector.data(), eigenVector.data() + eigenVector.size());
61 
62  return stdVect;
63 }
64 
65 }} //namespaces
66 
67 #endif // __ROSEE_UTILS_EIGEN__
static std::vector< float > eigenVectorToStdVector(Eigen::VectorXd eigenVector)
Definition: UtilsEigen.h:58
static std_msgs::Float32MultiArray eigenMatrixToFloat32MultiArray(Eigen::MatrixXd eigenMatrix)
Utility to fill the Float32MultiArray ROS message from an eigen matrix.
Definition: UtilsEigen.h:19