Privacy
An open-source, flexible 3D physical simulation framework
sensor_bases.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011, 2012, DFKI GmbH Robotics Innovation Center
3  *
4  * This file is part of the MARS simulation framework.
5  *
6  * MARS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3
9  * of the License, or (at your option) any later version.
10  *
11  * MARS 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 Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with MARS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef MARS_INTERFACES_SENSOR_BASES_H
22 #define MARS_INTERFACES_SENSOR_BASES_H
23 
24 #ifdef _PRINT_HEADER_
25  #warning "sensor_bases.h"
26 #endif
27 
28 #include "core_objects_exchange.h"
29 
30 #include <configmaps/ConfigData.h>
31 #include <mars/utils/Quaternion.h>
32 #include <mars/utils/Vector.h>
33 
34 #include <vector>
35 #include <limits>
36 
37 
38 namespace mars {
39 
40  namespace interfaces {
41 
42  class ControlCenter;
43 
44  class BaseConfig {
45  public:
47  virtual ~BaseConfig() {}
48  std::string name;
49  unsigned long id;
50  unsigned long updateRate;
51  }; // end of class BaseConfig
52 
53  class BaseSensor {
54  public:
56  {
57  id = 0;
58  name = "UNKNOWN";
59  updateRate = 10;
60  }
61  virtual ~BaseSensor(){}
62 
63  BaseSensor(unsigned long id, std::string name):
64  id(id),
65  name(name)
66  {
67  }
68 
69  unsigned long getID() const{
70  return id;
71  };
72 
73  const std::string getName() const{
74  return name;
75  }
76 
77  virtual int getSensorData(double **data) const{
78  return 0;
79  };
80 
81  virtual int getAsciiData(char *data) const{
82  return 0;
83  }
84 
86  obj->index = id;
87  obj->name = name;
88  }
89 
90  /*
91  static BaseConfig parseConfig(QDomElement *elementNode){
92  return BaseConfig();
93  }
94 
95  virtual QDomElement createConfig() {return QDomElement();}
96  */
97 
99  configmaps::ConfigMap *config) {
100  return new BaseConfig();
101  }
102 
104  return configmaps::ConfigMap();
105  }
106 
107  //Should be proteted due to compability of old code currently direct accessable
108  unsigned long id;
109  std::string name; //Todo naming bei mehreren robotern
110  unsigned long updateRate;
111 
112  protected:
113 
114  }; // end of class BaseSensor
115 
116 
117  class BaseNodeSensor : public BaseSensor {
118  public:
119  BaseNodeSensor(unsigned long id, std::string name)
120  : BaseSensor(id,name)
121  {
122  calcAcceletaion = false;
123  calcSpeed = false;
124  calcPosition = false;
125  calcRotationSpeed = false;
126  calcOrientation = false;
127  acceleration.setZero();
128  speed.setZero();
129  position.setZero();
130  rotationSpeed.setZero();
131  orientation.setIdentity();
132  attached_node = 0;
133  }
134  virtual ~BaseNodeSensor(){}
135 
137  return orientation;
138  }
139 
140  unsigned long getAttachedNode(){
141  return attached_node;
142  }
143 
144  protected:
145  unsigned long attached_node;
146  bool calcAcceletaion, calcSpeed, calcPosition,calcRotationSpeed,calcOrientation;
152 
153  }; // end of class BaseNodeSensor
154 
155 
156  template <class T>
158  public:
159  BaseArraySensor(int cols, int rows, int channels=1)
160  : cols(cols),
161  rows(rows),
162  channels(channels)
163  {
164  data.resize(rows*cols*channels);
165  }
166 
167  virtual ~BaseArraySensor(){}
168 
169  const std::vector<T> getData() const{
170  return data;
171  }
172  const int& getCols() const{
173  return cols;
174  }
175  const int& getRows() const{
176  return rows;
177  }
178  const int& getChannels() const{
179  return channels;
180  }
181 
182  T &operator[](const int &index){
183  assert(index >= 0 && index < (int)data.size());
184  return data[index];
185  }
186  virtual void resize(int cols, int rows, int channels=1){
187  this->cols = cols;
188  this->rows = rows;
189  this->channels = channels;
190  data.resize(rows*cols*channels);
191  }
192 
193 
194  protected:
195  int cols;
196  int rows;
197  int channels;
198  std::vector<T> data;
199 
200  }; // end of class BaseArraySensor
201 
202 
203  template <class T>
204  class BaseCameraSensor : public BaseArraySensor<T> {
205  public:
206  BaseCameraSensor(unsigned long id, std::string name, int cols, int rows, int nChannels, bool depthImage):
207  BaseArraySensor<T>(cols,rows,nChannels),
208  depthImage(depthImage),
209  id(id),
210  name(name)
211  {
212  }
213 
214  virtual ~BaseCameraSensor(){}
215 
216  bool isDepthImage(){
217  return depthImage;
218  }
219 
220 
221  protected:
223  unsigned long id;
224  std::string name;
225 
226  }; // end of BaseCameraSensor
227 
228 
230  public BaseArraySensor<double> {
231  public:
232  BasePolarIntersectionSensor(unsigned long id, std::string name, int cols, int rows, double angleX, double angleY, double maxDistance= std::numeric_limits<double>::infinity()):
233  BaseNodeSensor(id,name),
234  BaseArraySensor<double>(cols,rows),
235  maxDistance(maxDistance)
236  {
237  if(cols == 1) stepX = 0;
238  else stepX = angleX / (cols-1);
239  if(rows == 1) stepY = 0;
240  else stepY = angleY / (rows-1);
241 
242  //Must Remain true for correct calculation in Physics
243  calcOrientation = true;
244 
245  }
247 
248  virtual int getSensorData(double **data) const{
249  (*data) = (new double[this->data.size()]);
250  memcpy((*data),&this->data[0],sizeof(double)*this->data.size());
251  return this->data.size();
252  };
253 
254 
255 
256  double stepX;
257  double stepY;
258  double maxDistance;
259  protected:
260 
261  }; // end of class BasePolarIntersectionSensor
262 
263 
265  public BaseArraySensor<double> {
266  public:
267  BaseGridIntersectionSensor(unsigned long id, std::string name, int cols, int rows, double stepX, double stepY, double maxDistance= std::numeric_limits<double>::infinity()):
268  BaseNodeSensor(id,name),
269  BaseArraySensor<double>(cols,rows),
270  stepX(stepX),
271  stepY(stepY),
272  maxDistance(maxDistance)
273  {
274  }
276 
277 
278  double stepX;
279  double stepY;
280  double maxDistance;
281  protected:
282 
283  }; // end of class BaseGridIntersectionSensor
284 
285  } // end of namespace interfaces
286 
287 } // end of namespace mars
288 
289 #endif // MARS_INTERFACES_SENSOR_BASES_H
virtual int getAsciiData(char *data) const
Definition: sensor_bases.h:81
BaseGridIntersectionSensor(unsigned long id, std::string name, int cols, int rows, double stepX, double stepY, double maxDistance=std::numeric_limits< double >::infinity())
Definition: sensor_bases.h:267
std::string name
The name of the object.
const std::vector< T > getData() const
Definition: sensor_bases.h:169
The declaration of the ControlCenter.
Definition: ControlCenter.h:82
const int & getChannels() const
Definition: sensor_bases.h:178
static BaseConfig * parseConfig(ControlCenter *control, configmaps::ConfigMap *config)
Definition: sensor_bases.h:98
virtual void resize(int cols, int rows, int channels=1)
Definition: sensor_bases.h:186
BaseSensor(unsigned long id, std::string name)
Definition: sensor_bases.h:63
utils::Quaternion getOrientation() const
Definition: sensor_bases.h:136
virtual configmaps::ConfigMap createConfig() const
Definition: sensor_bases.h:103
core_objects_exchange is a struct to exchange core objects information between the modules of the sim...
BasePolarIntersectionSensor(unsigned long id, std::string name, int cols, int rows, double angleX, double angleY, double maxDistance=std::numeric_limits< double >::infinity())
Definition: sensor_bases.h:232
unsigned long getID() const
Definition: sensor_bases.h:69
BaseNodeSensor(unsigned long id, std::string name)
Definition: sensor_bases.h:119
void getCoreExchange(core_objects_exchange *obj) const
Definition: sensor_bases.h:85
Copyright 2012, DFKI GmbH Robotics Innovation Center.
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector
Definition: Vector.h:43
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
Definition: Quaternion.h:56
virtual int getSensorData(double **data) const
Definition: sensor_bases.h:77
BaseArraySensor(int cols, int rows, int channels=1)
Definition: sensor_bases.h:159
BaseCameraSensor(unsigned long id, std::string name, int cols, int rows, int nChannels, bool depthImage)
Definition: sensor_bases.h:206
const std::string getName() const
Definition: sensor_bases.h:73
T & operator[](const int &index)
Definition: sensor_bases.h:182
virtual int getSensorData(double **data) const
Definition: sensor_bases.h:248
unsigned long index
The unique id of the object.