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 
36  Logger(const char * new_folder, const char * _dir="/tmp", const char * customName="/stats", bool dateOn=true){
37  init(new_folder, _dir, customName, dateOn);
38  }
39 
40  ~Logger(){
41  if (NULL!=f){
42  fclose(f);
43  }
44  f=NULL;
45 
46  }
47 
54  bool log(const char * format, ...);
55 
56  const char * get_fileName(){
57  return fileName;
58  }
59 
63  static const char * getSystemArchitecture();
64 
65  protected:
66 
73  std::string file_dateTime(const char* custom, char name[80]);
74 
78  void init(const char * new_folder, const char * _dir=NULL, const char * customName="/stats", bool dateOn=false);
79 
80 
81 };
82 
83 
84 
85 namespace debug{
86 
87 template <class T>
88 void print_graph(const T& g, const Disturbance & goal, std::vector <vertexDescriptor>plan, const vertexDescriptor& c){
89  std::stringstream os;
90  auto vs=boost::vertices(g);
91  for (auto vi=vs.first; vi!=vs.second; vi++){
92  auto es=boost::out_edges(*vi, g);
93  if (*vi==c){
94  os<<"!";
95  }
96  for (vertexDescriptor vp:plan){
97  if (*vi==vp){
98  os<<"*";
99  }
100  }
101  os<<*vi<<"-> ";
102  for (auto ei=es.first; ei!=es.second; ei++){
103  if (*ei!=edgeDescriptor()){
104  os<<(*ei).m_target <<"("<<g[(*ei)].probability<<")";
105  }
106  }
107  os<<"\t(x="<<g[*vi].endPose.p.x<<", y= "<<g[*vi].endPose.p.y<<", theta= "<<g[*vi].endPose.q.GetAngle()<<")\n";
108  }
109  std::cout<<os.str();
110 }
111 
112 
113 template <class T>
114 void graph_file(const int &it, const T &g, const Disturbance &goal, std::vector<vertexDescriptor>&plan, const vertexDescriptor &c)
115 {
116  char fileName[50];
117  sprintf(fileName, "/tmp/graph%04i.txt", it);
118  FILE * f=fopen(fileName, "w");
119  auto vs=boost::vertices(g);
120  for (auto vi=vs.first; vi!=vs.second; vi++){
121  auto es=boost::out_edges(*vi, g);
122  if (*vi==c){
123  fprintf(f,"!");
124  }
125  for (vertexDescriptor vp:plan){
126  if (*vi==vp){
127  fprintf(f,"*");
128  }
129  }
130  fprintf(f,"%i -> ", (*vi));
131  for (auto ei=es.first; ei!=es.second; ei++){
132 
133  fprintf(f, "%i (%f) ", (*ei).m_target, g[(*ei)].probability);
134  }
135  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());
136  }
137  fclose(f);
138 }
139 b2Vec2 GetWorldPoints(b2Body*, b2Vec2 );
140 
141 char * print_pose(const b2Transform& p, char * msg=NULL);
142 
143 void print_matrix(const cv::Mat &);
144 
145 std::vector<b2Vec2> GetBodies( b2World*);
146 
147 void print_state_difference(const StateDifference & sd, vertexDescriptor v, vertexDescriptor v1);
148 
149 }
150 
151 
152 
153 #endif
Class used to load data from the configurator.
Definition: debug.h:18
std::string file_dateTime(const char *custom, char name[80])
Creates filename with today's date and time, name in format customdmy_hm.txt.
Definition: debug.cpp:3
void init(const char *new_folder, const char *_dir=NULL, const char *customName="/stats", bool dateOn=false)
Definition: debug.cpp:37
bool log(const char *format,...)
Definition: debug.cpp:22
Logger(const char *new_folder, const char *_dir="/tmp", const char *customName="/stats", bool dateOn=true)
Construct a new Logger object.
Definition: debug.h:36
static const char * getSystemArchitecture()
Returns a string with system architecture.
Definition: debug.cpp:64
Definition: disturbance.h:114
Contains the differences between the contiuous components of two hybrid states.
Definition: graphTools.h:143