NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
field_model.h
1 // Model for the soccer field
2 // Author: Max Schwarz <max.schwarz@uni-bonn.de>
3 
4 #ifndef FIELD_MODEL_H
5 #define FIELD_MODEL_H
6 
7 #include <vector>
8 
9 #include <Eigen/Core>
10 #include <Eigen/StdVector>
11 #include <config_server/parameter.h>
12 
13 namespace field_model
14 {
15 
20 {
21 public:
23  enum Type
24  {
34  NumTypes
35  };
36 
37  typedef std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d> > PointsType;
38 
39  WorldObject(Type type, const Eigen::Vector3d& pose);
40  WorldObject(Type type, double x, double y, double t = 0.0);
41  WorldObject(Type type, const PointsType& points);
42 
43  WorldObject mirrorX() const;
44  WorldObject mirrorY() const;
45 
47  inline Eigen::Vector3d pose() const { return m_pos; }
48 
50  inline const PointsType& points() const { return m_points; }
51 
53  inline Type type() const { return m_type; }
54 
55 protected:
56  void setPose(const Eigen::Vector3d& pose);
57 
58 private:
59  friend class FieldModel;
60 
61  WorldObject() {}
62 
63  Type m_type;
64  Eigen::Vector3d m_pos;
65  PointsType m_points;
66 };
67 
74 {
75 public:
76  static FieldModel* getInstance();
77 
78  enum FieldType
79  {
80  UnknownField = 0,
81  TeenSizeField,
82  KidSizeField,
83  BonnField,
84  NumFieldTypes
85  };
86  static const std::string FieldTypeName[NumFieldTypes];
87  static const std::string& fieldTypeName(FieldType type) { if(type >= UnknownField && type < NumFieldTypes) return FieldTypeName[type]; else return FieldTypeName[UnknownField]; }
88 
90  inline FieldType type() const
91  { return m_type; }
92 
94  inline const std::string& typeName() const
95  { return fieldTypeName(m_type); }
96 
98  inline double width() const
99  { return m_width; }
100 
102  inline double length() const
103  { return m_length; }
104 
106  inline double boundary() const
107  { return m_boundary; }
108 
110  inline double goalWidth() const
111  { return m_goalWidth; }
112 
114  inline double goalAreaWidth() const
115  { return m_goalAreaWidth; }
116 
118  inline double goalAreaDepth() const
119  { return m_goalAreaDepth; }
120 
121  inline double centerCircleDiameter() const
122  { return m_centerCircleDiameter; }
123 
125  inline double penaltyMarkerDist() const
126  { return m_penaltyMarkerDist; }
127 
129  inline double ballDiameter() const
130  { return m_ballDiameter; }
131 
133  inline double borderTop() const
134  { return m_borderTop; }
135 
137  inline double borderBottom() const
138  { return m_borderBottom; }
139 
141  inline double borderLeft() const
142  { return m_borderLeft; }
143 
145  inline double borderRight() const
146  { return m_borderRight; }
147 
149  inline const std::vector<WorldObject>& objects(WorldObject::Type type) const
150  { return m_objects[type]; }
151 
152  void setMagneticHeading(double heading);
153  double magneticHeading() const;
154 
155 private:
156  FieldModel();
157 
158  enum MirrorFlag
159  {
160  NoMirror = 0,
161  MirrorX = (1 << 0),
162  MirrorY = (1 << 1),
163  MirrorAll = MirrorX | MirrorY
164  };
165  WorldObject* addObject(WorldObject::Type type, double x, double y, double t, int flags = MirrorX | MirrorY);
166  void addLine(const WorldObject::PointsType& points, int flags = MirrorX | MirrorY);
167 
168  static FieldModel* m_instance;
169 
170  FieldType m_type;
171  double m_width;
172  double m_length;
173  double m_boundary;
174  double m_goalWidth;
175  double m_goalAreaWidth;
176  double m_goalAreaDepth;
177  double m_centerCircleDiameter;
178  double m_penaltyMarkerDist;
179  double m_ballDiameter;
180  double m_borderTop;
181  double m_borderBottom;
182  double m_borderLeft;
183  double m_borderRight;
184 
185  std::vector<WorldObject> m_objects[WorldObject::NumTypes];
186 
187  WorldObject* m_magneticHeading;
188  void updateMagneticHeading();
189  config_server::Parameter<float> m_attEstMagCalibX;
190  config_server::Parameter<float> m_attEstMagCalibY;
191  double m_heading;
192 };
193 
194 }
195 
196 #endif
double goalWidth() const
Goal width.
Definition: field_model.h:110
double borderBottom() const
Border for the bottom(negative) part of the field.
Definition: field_model.h:137
Magnetic heading towards X+.
Definition: field_model.h:33
const PointsType & points() const
Points belonging to the object (e.g. line start and end)
Definition: field_model.h:50
double goalAreaWidth() const
Width of the penalty area before each goal.
Definition: field_model.h:114
Definition: field_model.h:19
Model of the soccer field.
Definition: field_model.h:73
FieldType type() const
Field type.
Definition: field_model.h:90
L-crossing of two lines.
Definition: field_model.h:32
Type type() const
Object type.
Definition: field_model.h:53
double ballDiameter() const
Diameter of the ball.
Definition: field_model.h:129
Goal (center position)
Definition: field_model.h:26
X-crossing of two lines.
Definition: field_model.h:31
const std::string & typeName() const
Field type name.
Definition: field_model.h:94
double goalAreaDepth() const
Depth of the penalty area before each goal.
Definition: field_model.h:118
One of the two penalty markers.
Definition: field_model.h:28
A single goal post.
Definition: field_model.h:27
Type
Object type.
Definition: field_model.h:23
double boundary() const
Field boundary (amount of green outside the field boundary)
Definition: field_model.h:106
Center circle.
Definition: field_model.h:25
T-crossing of two lines.
Definition: field_model.h:30
const std::vector< WorldObject > & objects(WorldObject::Type type) const
Objects for a specific WorldObject::Type.
Definition: field_model.h:149
Eigen::Vector3d pose() const
Object pose (x, y, theta)
Definition: field_model.h:47
Field line.
Definition: field_model.h:29
double borderRight() const
Border for the right(when looking to positive goal) part of the field.
Definition: field_model.h:145
double width() const
Field width (inside the lines)
Definition: field_model.h:98
double borderTop() const
Border for the top(positive) part of the field.
Definition: field_model.h:133
double penaltyMarkerDist() const
Distance from the goal line to the penalty marker.
Definition: field_model.h:125
double borderLeft() const
Border for the left(when looking to positive goal) part of the field.
Definition: field_model.h:141
double length() const
Field length (inside the lines)
Definition: field_model.h:102