robots.h
Go to the documentation of this file.
1 /*
2  * This file is part of Laustracker.
3  *
4  * Copyright (C) 2013 Christian Jann <christian.jann@ymail.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef HEADER_LAUSTRACKER_ROBOTS_H_INCLUDED
21 #define HEADER_LAUSTRACKER_ROBOTS_H_INCLUDED
22 
28 #include <opencv2/core/core.hpp>
29 #include <opencv2/imgproc/imgproc.hpp>
30 #include <opencv2/highgui/highgui.hpp>
31 #include <iostream>
32 #include <list>
33 #include <laustracker/map.h>
34 
35 using namespace std;
36 using namespace cv;
37 
39 typedef enum ColorEnum { c_red, c_blue, c_green, c_yellow, c_white } ColorType;
40 
42 typedef struct led_t
43 {
45  Point2f center;
46 
48  float radius;
49 
52 } led_t;
53 
55 typedef struct robot_t
56 {
59 
62 
64  Point center;
65 
67  float radius;
68 
70  Point field_idx;
71 
74  Point2f relative_pos;
75 
78  Point2f absolut_pos_px;
79 
82  Point2f absolut_pos_cm;
83 
85  float angle;
86 
90 
92  string name;
93 
96 
99 
102  float ratio;
103 
106 
109 
112 
114  long long last_seen;
115 
118 
119 } robot_t;
120 
126 {
127 private:
128 
130  Scalar redmin1, redmax1, redmin2, redmax2, greenmin, greenmax,
131  yellowmin, yellowmax, bluemin, bluemax, whitemin, whitemax;
132 
135 
137  long long frameNum;
138 
141 
143  vector <Point> rob_labyrinth_pos;
144 
147 
150 
152  Point center_points[8][8];
153 
156 
158  void update_center_points();
159 
160  vector<String> robot_names;
161  vector<float> robot_ratios;
162  float max_ratio_diff;
163 
165  bool fastmode;
166 
167 public:
168 
170  list< robot_t> robots;
171 
178  RobotTracker();
179 
186  ~RobotTracker();
187 
194  bool load_robots_conf(string filename);
195 
196 
201  bool processNewFrame(Mat image);
202 
204  void getListOfRobots();
205 
210  void draw_robots(Mat& image);
211 
216  void setDebug(int level);
217 
222  string toString();
223 
228  bool fromString(string robots_str);
229 
234  void setLabyrinthPos(vector <Point> labyrinth_pos);
235 
241  void setLabyrinthPos(vector <Point> labyrinth_pos, Mat image);
242 
243  bool setRobotNames(vector<String> names, vector<float> ratios, float max_diff);
244 
252  String ratio2name(float ratio, int debuglevel);
253 
259  void setFastMode(bool state);
260 };
261 
268 String dist2name(float dist_blue_white, float dist_red_white);
269 
270 #endif
Stores information about a robot.
Definition: robots.h:55
int field_width_px
Field width in pixels.
Definition: robots.h:140
Point2f center
LED position in pixels.
Definition: robots.h:45
led_t led_red
The red LED at right front position.
Definition: robots.h:61
int tmp_value
To store temporary information about a robot, e.g. within loops.
Definition: robots.h:117
enum PosEnum PosType
Possible positions within a field.
float angle
Orientation angle of the robot in degree.
Definition: robots.h:85
Mat labyrinth_image
Clean image of the labyrinth at normal exposure time.
Definition: robots.h:146
long long frameNum
Frame counter.
Definition: robots.h:137
led_t led_blue
The blue LED at left front position.
Definition: robots.h:58
float ratio
Definition: robots.h:102
PosType direction
Definition: robots.h:89
Contains information about a LED.
Definition: robots.h:42
bool labyrinth_pos_ready
Is the labyrinth position already known.
Definition: robots.h:155
Point2f absolut_pos_px
Definition: robots.h:78
struct robot_t robot_t
Stores information about a robot.
list< robot_t > robots
A list of all robots.
Definition: robots.h:170
Point2f relative_pos
Definition: robots.h:74
enum ColorEnum ColorType
Possible colors of a LED.
ColorType color
Color of the LED.
Definition: robots.h:51
struct led_t led_t
Contains information about a LED.
float dist_blue_white
Distance from the blue LED to the white LED.
Definition: robots.h:105
bool third_led_found
Whether a third white LED was found.
Definition: robots.h:95
A class to locate robots.
Definition: robots.h:125
string name
Name of the robot.
Definition: robots.h:92
Scalar redmin1
Color thresholds.
Definition: robots.h:130
String dist2name(float dist_blue_white, float dist_red_white)
Find the corresponding robot name from a list of robots and distances.
int debuglevel
Show corresponding debug information.
Definition: robots.h:134
Point center_last_frame
Position f the robot within the last frame.
Definition: robots.h:111
Point2f absolut_pos_cm
Definition: robots.h:82
vector< Point > rob_labyrinth_pos
Labyrinth position (used to calculate robot positions)
Definition: robots.h:143
Point field_idx
The index of the nearest field to the robot.
Definition: robots.h:70
led_t led_white
The third white LED to distinguish different robots.
Definition: robots.h:98
float dist_red_white
Distance from the red LED to the white LED.
Definition: robots.h:108
float radius
Radius/size of the LED.
Definition: robots.h:48
ColorEnum
Possible colors of a LED.
Definition: robots.h:39
The class LabyrinthMap contains complete information about the labyrinth structure.
Point center
The center position of the robot in pixels.
Definition: robots.h:64
float radius
The radius of a circle around the robot.
Definition: robots.h:67
bool have_labyrinth_image
We have a clean image of the labyrinth at normal exposure time.
Definition: robots.h:149
bool fastmode
Skip not really necessary operations to get a higher FPS.
Definition: robots.h:165
long long last_seen
Number of the frame where the robot was last found.
Definition: robots.h:114