Bratmobile
tracker.h
1 #ifndef TRACKER_H
2 #define TRACKER_H
3 #include "sensor.h"
4 
6  b2Transform displacement=b2Transform_zero; //estimated displacement
7  Disturbance observed_disturbance; //the disturbance as observed at the current time step
8 
9  TrackingResult()=default;
10 
11  TrackingResult(const Disturbance& d, const b2Transform & tr=b2Transform_zero): displacement(tr), observed_disturbance(d){}
12 };
13 
19 class Tracker{
20  protected:
21  friend Configurator;
22  ThresholdLearner *learner=NULL;
23  b2Transform deltaTransform=b2Transform_zero;
24  Threshold threshold=Threshold();
25 
26  public:
27 
28  Tracker(){}
29 
30  virtual Threshold get_threshold(const State &s){
31  return threshold;
32  }
33 
34  void register_learner(ThresholdLearner * l){
35  learner=l;
36  }
37 
38  b2Transform getDeltaTransform(){return deltaTransform;}
45  virtual TrackingResult get_transform(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects);
55  virtual TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects)=0;
56  //void adjust_task(const vertexDescriptor&, TransitionSystem &, Task*, const b2Transform &);
57 
63  virtual void on_new_task(const Task &task, const Task & goal)=0;
64 
71  virtual void on_new_reading(const Task & goal,const Task &task ){}
72 
73  virtual void init(const Task & goal)=0;
74 
75  virtual bool hasTaskEnded(Task & t);
76 
77 
81  void make_log();
82 
83  protected:
84 
85 
86  void log_thresholds(){
87  FILE *f= fopen("/tmp/thresholds.txt", "a");
88  fprintf(f, "%f\t%f\t%f\t%f\t%f\n", threshold.for_Di().get_x(),
89  threshold.for_Di().get_y(),
90  threshold.for_Di().get_angle(),
91  threshold.for_Di().get_width(),
92  threshold.for_Di().get_length());
93  fclose(f);
94  }
95 
96 
97 };
98 
103 class DeadReckoner: public Tracker{
104  public:
105  DeadReckoner(){}
106 
107  TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects);
108 
109  void on_new_task(const Task &task, const Task & goal)override{} //does nothing
110 
111  void init(const Task & goal){}
112 
113 
114 };
115 
121  protected:
122  Disturbance tracked_disturbance; //disturbance to be tracked as at task start, kept in memory when task is changed
123  b2PolygonShape attention_window; //a box drawn at the beginning of task which bounds the robot and the goal
124  bool hasReading=false; //has the disturbance's actual position been found with a scan
128  float window_area();
129 
130  public:
131 
133 
134  // ClosedLoop_Tracker(Task * goal){
135  // attention_window=sensor_box(Robot::get_vertices(),b2Transform_zero, goal->get_disturbance());
136  // }
137 
147  TrackingResult get_transform(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects)override;
148 
149  TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector <BodyFeatures> & objects);
150 
154  cv::Rect2f real_world_focus(const Task * );
155 
163  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);
164 
170  void correctAngle(BodyFeatures & found, const BodyFeatures & dist);
177  void on_new_task(const Task &task, const Task & goal)override;
178 
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 //same as CL Tracker but creates custom threshold based on state
204  protected:
205  Threshold get_threshold(const State &s){
206  float distance=std::max(Threshold::FIXED_ENDPOSE, s.distance()/2);
207  return Threshold(distance, Threshold::FIXED_ANGLE, Threshold::FIXED_DISTPOS, Threshold::FIXED_AFFORDANCE, Threshold::FIXED_DIMENSIONS);
208  }
209 
210 };
211 #endif
Definition: tracker.h:203
Tracks task execution by observing changes in tracked disturbance.
Definition: tracker.h:120
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:55
void on_new_task(const Task &task, const Task &goal) override
Uses the goal to reset tracked disturbance at each task.
Definition: tracker.cpp:134
void makeAttentionWindow(const Task &goal, const Task &currentTask)
Updates the attention window at each sensor reading.
Definition: tracker.cpp:153
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:40
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:93
TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects)
Tracks task execution.
Definition: tracker.cpp:29
void correctAngle(BodyFeatures &found, const BodyFeatures &dist)
Sets angle to be smallest possible increment compared to dist.
Definition: tracker.cpp:123
float window_area()
gets the area of the attention window (for debugging)
Definition: tracker.cpp:145
Definition: configurator.h:17
Tracks task execution through dead reckoning.
Definition: tracker.h:103
TrackingResult track(const Task &t, const CoordinateContainer &pts, const std::vector< BodyFeatures > &objects)
Tracks task execution.
Definition: tracker.cpp:23
void on_new_task(const Task &task, const Task &goal) override
Called every time a new task is created.
Definition: tracker.h:109
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:47
Definition: threshold.h:155
Definition: threshold.h:91
Bundle for_Di() const
Returns a bundle of thresholds for the initial disturbance.
Definition: threshold.h:119
Tracking interface: Bridge between the real world and the simulation. Is used for tracking execution ...
Definition: tracker.h:19
void make_log()
opens file where all the data is dumped
Definition: tracker.cpp:85
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.
virtual void on_new_reading(const Task &goal, const Task &task)
Called every time a new reading is available.
Definition: tracker.h:71
Given points, makes rotated bounding box.
std::set< Pointf > CoordinateContainer
container for LIDAR coordinates
Definition: sensor.h:61
Definition: disturbance.h:47
Definition: disturbance.h:113
Hybrid states in the transition system.
Definition: graphTools.h:69
Definition: tracker.h:5