Bratmobile
tracker.h
1 #include "sensor.h"
2 
4  b2Transform displacement=b2Transform_zero; //estimated displacement
5  Disturbance observed_disturbance; //the disturbance as observed at the current time step
6 
7  TrackingResult()=default;
8 
9  TrackingResult(const Disturbance& d, const b2Transform & tr=b2Transform_zero): displacement(tr), observed_disturbance(d){}
10 };
11 
17 class Tracker{
18  protected:
19  friend Configurator;
20  ThresholdLearner *learner=NULL;
21  b2Transform deltaTransform=b2Transform_zero;
22  public:
23  Threshold threshold=Threshold();
24 
25  Tracker(){}
26 
27  Threshold * get_threshold(){
28  return &threshold;
29  }
30 
31  void register_learner(ThresholdLearner * l){
32  learner=l;
33  }
34 
35  b2Transform getDeltaTransform(){return deltaTransform;}
42  virtual TrackingResult get_transform(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects);
52  virtual TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects)=0;
53  //void adjust_task(const vertexDescriptor&, TransitionSystem &, Task*, const b2Transform &);
54 
60  virtual void on_new_task(const Task &task, const Task & goal)=0;
61 
67  virtual void on_new_reading(const Task & goal, const Task &currentTask)=0;
68 
69  virtual void init(const Task & goal)=0;
70 
71  virtual bool hasTaskEnded(Task & t);
72 
73 
77  void make_log();
78 
79  protected:
80 
81 
82  void log_thresholds(){
83  FILE *f= fopen("/tmp/thresholds.txt", "a");
84  fprintf(f, "%f\t%f\t%f\t%f\t%f\n", threshold.for_Di().get_x(),
85  threshold.for_Di().get_y(),
86  threshold.for_Di().get_angle(),
87  threshold.for_Di().get_width(),
88  threshold.for_Di().get_length());
89  fclose(f);
90  }
91 
92 
93 };
94 
99 class DeadReckoner: public Tracker{
100  public:
101  DeadReckoner(){}
102 
103  TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects);
104 
105  void on_new_task(const Task &task, const Task & goal)override{} //does nothing
106 
107  virtual void on_new_reading(const Task & goal, const Task &currentTask)override{};
108 
109  void init(const Task & goal){}
110 
111 
112 };
113 
119  protected:
120  Disturbance tracked_disturbance; //disturbance to be tracked as at task start, kept in memory when task is changed
121  b2PolygonShape attention_window; //a box drawn at the beginning of task which bounds the robot and the goal
122 
126  float window_area();
127 
128  public:
129 
131 
132  // ClosedLoop_Tracker(Task * goal){
133  // attention_window=sensor_box(Robot::get_vertices(),b2Transform_zero, goal->get_disturbance());
134  // }
135 
145  TrackingResult get_transform(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects)override;
146 
147  TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects);
148 
152  cv::Rect2f real_world_focus(const Task * );
153 
161  virtual std::vector <BodyFeatures>::const_iterator find_disturbance(std::vector <BodyFeatures>::const_iterator objects_begin, std::vector <BodyFeatures>::const_iterator objects_end, const BodyFeatures & dist, b2Transform t, float * _least_square=NULL);
162 
168  void correctAngle(BodyFeatures & found, const BodyFeatures & dist);
175  void on_new_task(const Task &task, const Task & goal)override;
176 
177 
178  virtual void on_new_reading(const Task & goal, const Task &currentTask)override{}
179 
180  void set_attention(b2PolygonShape ps){
181  attention_window=ps;
182  }
183 
184  void init(const Task & goal){
185  attention_window=sensor_box(Robot::get_vertices(),b2Transform_zero, goal.get_disturbance());
186 
187  }
188 
189  virtual bool hasTaskEnded(Task & t);
190 
196  void makeAttentionWindow(const Task &goal, const Task & currentTask);
197 
198 
199 
200 
201 
202 };
Definition: disturbance.h:47
Tracks task execution by observing changes in tracked disturbance.
Definition: tracker.h:118
TrackingResult get_transform(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects) override
returns 2d transformation matrix between one scan and the next based on the displacement of disturban...
Definition: tracker.cpp:48
void on_new_task(const Task &task, const Task &goal) override
Uses the goal to reset tracked disturbance at each task.
Definition: tracker.cpp:136
virtual void on_new_reading(const Task &goal, const Task &currentTask) override
Called every time asensor reading is available.
Definition: tracker.h:178
void makeAttentionWindow(const Task &goal, const Task &currentTask)
Updates the attention window at each sensor reading.
Definition: tracker.cpp:152
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:33
virtual std::vector< BodyFeatures >::const_iterator find_disturbance(std::vector< BodyFeatures >::const_iterator objects_begin, std::vector< BodyFeatures >::const_iterator objects_end, const BodyFeatures &dist, b2Transform t, float *_least_square=NULL)
Get disturbance to be tracked among the worldbuilder objects.
Definition: tracker.cpp:86
TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects)
Tracks task execution.
Definition: tracker.cpp:26
void correctAngle(BodyFeatures &found, const BodyFeatures &dist)
Sets angle to be smallest possible increment compared to dist.
Definition: tracker.cpp:116
float window_area()
gets the area of the attention window (for debugging)
Definition: tracker.cpp:144
Definition: configurator.h:17
Tracks task execution through dead reckoning.
Definition: tracker.h:99
TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects)
Tracks task execution.
Definition: tracker.cpp:20
void on_new_task(const Task &task, const Task &goal) override
Called every time a new task is created.
Definition: tracker.h:105
virtual void on_new_reading(const Task &goal, const Task &currentTask) override
Called every time asensor reading is available.
Definition: tracker.h:107
static std::vector< b2Vec2 > get_vertices()
Returns vertices in local frame. Order: bl, br, tl, tr.
Definition: robot.h:52
A closed hybrid control loop. It has an initial disturbance representing the continuous state and a d...
Definition: task.h:45
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:17
void make_log()
opens file where all the data is dumped
Definition: tracker.cpp:78
virtual void on_new_reading(const Task &goal, const Task &currentTask)=0
Called every time asensor reading is available.
virtual TrackingResult get_transform(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects)
Definition: tracker.cpp:3
virtual void on_new_task(const Task &task, const Task &goal)=0
Called every time a new task is created.
virtual TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects)=0
Tracks task execution.
Given points, makes rotated bounding box.
std::set< Pointf > CoordinateContainer
container for LIDAR coordinates
Definition: sensor.h:61
Definition: disturbance.h:114
Definition: tracker.h:3