AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
prints.cpp
1 #include "header/prints.h"
2 
3 int PRT::printRotMatrix_tf(tf::Transform transform){
4 
5  std::cout <<"\n\n"<< transform.getBasis().getColumn(0).getX() << "\t"
6  << transform.getBasis().getColumn(1).getX() << "\t"
7  << transform.getBasis().getColumn(2).getX() << "\n"
8  << transform.getBasis().getColumn(0).getY() << "\t"
9  << transform.getBasis().getColumn(1).getY() << "\t"
10  << transform.getBasis().getColumn(2).getY() << "\n"
11  << transform.getBasis().getColumn(0).getZ() << "\t"
12  << transform.getBasis().getColumn(1).getZ() << "\t"
13  << transform.getBasis().getColumn(2).getZ() << "\n\n";
14  return 0;
15 
16 }
17 
18 int PRT::printMatrix3x3_tf(tf::Matrix3x3 matrix){
19 
20  std::cout <<"\n\n"<< matrix.getColumn(0).getX() << "\t"
21  << matrix.getColumn(1).getX() << "\t"
22  << matrix.getColumn(2).getX() << "\n"
23  << matrix.getColumn(0).getY() << "\t"
24  << matrix.getColumn(1).getY() << "\t"
25  << matrix.getColumn(2).getY() << "\n"
26  << matrix.getColumn(0).getZ() << "\t"
27  << matrix.getColumn(1).getZ() << "\t"
28  << matrix.getColumn(2).getZ() << "\n\n";
29  return 0;
30 
31 }
32 
34 int PRT::createDirectory(std::string pathDirectory) {
35 
36  boost::filesystem::path path(pathDirectory);
37  if(boost::filesystem::create_directories(path)){
38  std::cout << "[PRT] folder created : " << path << "\n";
39  }
40 }
41 
42 int PRT::matrixCmat2file(std::string pathName, CMAT::Matrix mat){
43  std::ofstream file;
44  file.open(pathName, std::ios_base::app);
45 
46  for (int j=1; j<=mat.GetNumRows(); ++j){
47 
48  for (int i = 1; i<=mat.GetNumColumns(); ++i){
49  file << mat(j,i) << " ";
50  }
51  file << std::endl;
52  }
53  file << std::endl;
54 
55  file.close();
56 }
57 
58 int PRT::matrixEigen2file(std::string pathName, Eigen::MatrixXd mat){
59  std::ofstream file;
60  file.open(pathName, std::ios_base::app);
61 
62  for (int j=0; j<mat.rows(); ++j){
63 
64  for (int i = 0; i<mat.cols(); ++i){
65  file << mat(j,i) << " ";
66  }
67  file << std::endl;
68  }
69  file << std::endl;
70 
71 
72  file.close();
73 
74 }
75 
76 
77 int PRT::vectorStd2file(std::string path, std::vector<double> vect){
78 
79  std::ofstream file;
80  file.open(path, std::ios_base::app);
81 
82  for(int i=0; i<vect.size(); i++){
83  file << vect.at(i) << std::endl;
84  }
85  file << std::endl;
86 
87 
88  file.close();
89 
90 
91 }
92 
93 void PRT::double2file(std::string path, double scalar){
94  std::ofstream file;
95  file.open(path, std::ios_base::app);
96 
97  file << scalar << std::endl;
98 
99  file << std::endl;
100 
101 
102  file.close();
103 }
104 
105 
106 std::string PRT::getCurrentDateFormatted() {
107  std::time_t t = std::time(NULL);
108  char mbstr[20];
109  std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d_%H-%M-%S", std::localtime(&t));
110  std::string currentDate(mbstr);
111 
112  return currentDate;
113 }