Bratmobile
tracker.h
1 #include "sensor.h"
2 
8 class Tracker{
9  protected:
10  ThresholdLearner *learner=NULL;
11  public:
12  Threshold threshold=Threshold();
13 
14  Tracker(){}
15 
16  Threshold * get_threshold(){
17  return &threshold;
18  }
19 
20  void register_learner(ThresholdLearner * l){
21  learner=l;
22  }
29  virtual b2Transform get_transform(const Task &t, const CoordinateContainer &pts, Disturbance * observed_disturbance, std::vector <BodyFeatures> & objects)=0;
30 
40  virtual b2Transform track(Task &t, const CoordinateContainer &pts, std::vector <BodyFeatures> & objects)=0;
41  //void adjust_task(const vertexDescriptor&, TransitionSystem &, Task*, const b2Transform &);
42 
48  virtual void on_new_task(Task *task=NULL)=0;
49 
55  virtual void on_new_reading(Task * task=NULL)=0;
56 
57  virtual void init(Task * goal)=0;
58 
62  void make_log();
63 
64  protected:
65 
66 
67  void log_thresholds(){
68  FILE *f= fopen("/tmp/thresholds.txt", "a");
69  fprintf(f, "%f\t%f\t%f\t%f\t%f\n", threshold.for_Di().get_x(),
70  threshold.for_Di().get_y(),
71  threshold.for_Di().get_angle(),
72  threshold.for_Di().get_width(),
73  threshold.for_Di().get_length());
74  fclose(f);
75  }
76 
77 
78 };
79 
84 class DeadReckoner: public Tracker{
85  public:
86  DeadReckoner(){}
87 
88  b2Transform get_transform(const Task &t, const CoordinateContainer &pts, Disturbance * observed_disturbance, std::vector <BodyFeatures> & objects){
89  return t.getAction().getTransform(LIDAR_SAMPLING_RATE);
90  }
91 
92  b2Transform track(Task &t, const CoordinateContainer &pts, std::vector <BodyFeatures> & objects);
93 
94  void on_new_task(Task *task=NULL){} //does nothing
95 
96  void on_new_reading(Task * task=NULL){};
97 
98  void init(Task * goal){}
99 
100 
101 };
102 
108  Disturbance tracked_disturbance; //disturbance to be tracked as at task start, kept in memory when task is changed
109  b2PolygonShape attention_window; //a box drawn at the beginning of task which bounds the robot and the goal
110  public:
111 
113 
114  // ClosedLoop_Tracker(Task * goal){
115  // attention_window=sensor_box(Robot::get_vertices(),b2Transform_zero, goal->get_disturbance());
116  // }
117 
126  b2Transform get_transform(const Task &t, const CoordinateContainer &pts, Disturbance * observed_disturbance, std::vector <BodyFeatures> & objects);
127 
128  b2Transform track(Task &t, const CoordinateContainer &pts, std::vector <BodyFeatures> & objects);
129 
133  cv::Rect2f real_world_focus(const Task * );
134 
135  Disturbance * get_tracked_disturbance(){
136  return &tracked_disturbance;
137  }
138 
139  void set_tracked_disturbance(const Disturbance & d){
140  tracked_disturbance=d;
141  }
142 
150  std::vector <BodyFeatures>::iterator find_disturbance(std::vector <BodyFeatures> & objects, const BodyFeatures & dist, b2Transform t, float * _least_square=NULL);
151 
157  void on_new_task(Task *task=NULL);
158 
164  void on_new_reading(Task * goal=NULL);
165 
166  void set_attention(b2PolygonShape ps){
167  attention_window=ps;
168  }
169 
170  void init(Task * goal){
171  attention_window=sensor_box(Robot::get_vertices(),b2Transform_zero, goal->get_disturbance_ptr());
172 
173  }
174 
175  private:
176 
180  float window_area();
181 
182 
183 };
Definition: disturbance.h:45
Tracks task execution by observing changes in tracked disturbance.
Definition: tracker.h:107
b2Transform get_transform(const Task &t, const CoordinateContainer &pts, Disturbance *observed_disturbance, std::vector< BodyFeatures > &objects)
returns 2d transformation matrix between one scan and the next based on the displacement of disturban...
Definition: tracker.cpp:38
cv::Rect2f real_world_focus(const Task *)
returns an upright rectangle which represents a focus of attention for finding points corresponding t...
Definition: tracker.cpp:23
b2Transform track(Task &t, const CoordinateContainer &pts, std::vector< BodyFeatures > &objects)
Tracks task execution.
Definition: tracker.cpp:13
std::vector< BodyFeatures >::iterator find_disturbance(std::vector< BodyFeatures > &objects, const BodyFeatures &dist, b2Transform t, float *_least_square=NULL)
Get disturbance to be tracked among the worldbuilder objects.
Definition: tracker.cpp:81
void on_new_reading(Task *goal=NULL)
Updates the attention window at each sensor reading.
Definition: tracker.cpp:136
void on_new_task(Task *task=NULL)
Uses the goal to reset tracked disturbance at each task.
Definition: tracker.cpp:129
Tracks task execution through dead reckoning.
Definition: tracker.h:84
void on_new_reading(Task *task=NULL)
Called every time asensor reading is available.
Definition: tracker.h:96
void on_new_task(Task *task=NULL)
Called every time a new task is created.
Definition: tracker.h:94
b2Transform get_transform(const Task &t, const CoordinateContainer &pts, Disturbance *observed_disturbance, std::vector< BodyFeatures > &objects)
Definition: tracker.h:88
b2Transform track(Task &t, const CoordinateContainer &pts, std::vector< BodyFeatures > &objects)
Tracks task execution.
Definition: tracker.cpp:3
Definition: task.h:19
Disturbance * get_disturbance_ptr()
Get a pointer to the disturbance.
Definition: task.h:311
Definition: threshold.h:149
Definition: threshold.h:91
Bundle for_Di() const
Returns a bundle of thresholds for the initial disturbance.
Definition: threshold.h:114
Tracking interface: Bridge between the real world and the simulation. Is used for tracking execution ...
Definition: tracker.h:8
virtual void on_new_task(Task *task=NULL)=0
Called every time a new task is created.
virtual void on_new_reading(Task *task=NULL)=0
Called every time asensor reading is available.
void make_log()
opens file where all the data is dumped
Definition: tracker.cpp:73
virtual b2Transform track(Task &t, const CoordinateContainer &pts, std::vector< BodyFeatures > &objects)=0
Tracks task execution.
virtual b2Transform get_transform(const Task &t, const CoordinateContainer &pts, Disturbance *observed_disturbance, std::vector< BodyFeatures > &objects)=0
Definition: disturbance.h:112