Bratmobile
debug.h
1 #ifndef DEBUG_H
2 #define DEBUG_H
3 
4 #include "worldbuilder.h"
5 #include <fstream>
6 #include <bits/stdc++.h>
7 #include <fstream>
8 #include <iostream>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #include <string>
12 #include <dirent.h>
13 
18 class Logger{
19  protected:
20  char fileName[60];
21  FILE *f=NULL;
22  int fileCount=0;//files with the same name
23 
24  public:
25 
26  Logger(){}
27 
35  Logger(const char * new_folder, const char * _dir="/tmp", const char * customName="/stats"){
36  init(new_folder, _dir, customName);
37  }
38 
39  ~Logger(){
40  if (NULL!=f){
41  fclose(f);
42  }
43  f=NULL;
44 
45  }
46 
53  bool log(const char * format, ...);
54 
55  const char * get_fileName(){
56  return fileName;
57  }
58 
62  static const char * getSystemArchitecture();
63 
64  protected:
65 
72  std::string file_dateTime(const char* custom, char name[80], const char * addOn=NULL);
73 
74  void init(const char * new_folder, const char * _dir=NULL, const char * customName="/stats");
75 
76 
77 };
78 
79 
80 
81 namespace debug{
82 
83 template <class T>
84 void print_graph(const T& g, const Disturbance & goal, std::vector <vertexDescriptor>plan, const vertexDescriptor& c){
85  std::stringstream os;
86  auto vs=boost::vertices(g);
87  for (auto vi=vs.first; vi!=vs.second; vi++){
88  auto es=boost::out_edges(*vi, g);
89  if (*vi==c){
90  os<<"!";
91  }
92  for (vertexDescriptor vp:plan){
93  if (*vi==vp){
94  os<<"*";
95  }
96  }
97  os<<*vi<<"-> ";
98  for (auto ei=es.first; ei!=es.second; ei++){
99  if (*ei!=edgeDescriptor()){
100  os<<(*ei).m_target <<"("<<g[(*ei)].probability<<")";
101  }
102  }
103  os<<"\t(x="<<g[*vi].endPose.p.x<<", y= "<<g[*vi].endPose.p.y<<", theta= "<<g[*vi].endPose.q.GetAngle()<<")\n";
104  }
105  std::cout<<os.str();
106 }
107 
108 
109 template <class T>
110 void graph_file(const int &it, const T &g, const Disturbance &goal, std::vector<vertexDescriptor>&plan, const vertexDescriptor &c)
111 {
112  char fileName[50];
113  sprintf(fileName, "/tmp/graph%04i.txt", it);
114  FILE * f=fopen(fileName, "w");
115  auto vs=boost::vertices(g);
116  for (auto vi=vs.first; vi!=vs.second; vi++){
117  auto es=boost::out_edges(*vi, g);
118  if (*vi==c){
119  fprintf(f,"!");
120  }
121  for (vertexDescriptor vp:plan){
122  if (*vi==vp){
123  fprintf(f,"*");
124  }
125  }
126  fprintf(f,"%i -> ", (*vi));
127  for (auto ei=es.first; ei!=es.second; ei++){
128 
129  fprintf(f, "%i (%f) ", (*ei).m_target, g[(*ei)].probability);
130  }
131  fprintf(f, "\t(x=%.3f, y= %.3f, theta= %.3f)\n", g[*vi].endPose.p.x, g[*vi].endPose.p.y, g[*vi].endPose.q.GetAngle());
132  }
133  fclose(f);
134 }
135 b2Vec2 GetWorldPoints(b2Body*, b2Vec2 );
136 
137 char * print_pose(const b2Transform& p, char * msg=NULL);
138 
139 void print_matrix(const cv::Mat &);
140 
141 std::vector<b2Vec2> GetBodies( b2World*);
142 
143 void print_state_difference(const StateDifference & sd, vertexDescriptor v, vertexDescriptor v1);
144 
145 }
146 
147 
148 
149 #endif
Class used to load data from the configurator.
Definition: debug.h:18
std::string file_dateTime(const char *custom, char name[80], const char *addOn=NULL)
Creates filename name in format customdmy_hm.txt.
Definition: debug.cpp:3
bool log(const char *format,...)
Definition: debug.cpp:22
static const char * getSystemArchitecture()
Returns a string with system architecture.
Definition: debug.cpp:52
Logger(const char *new_folder, const char *_dir="/tmp", const char *customName="/stats")
Construct a new Logger object.
Definition: debug.h:35
Definition: disturbance.h:112
Contains the differences between the contiuous components of two hybrid states.
Definition: graphTools.h:142