openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sensor.h
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2006-2011 Rosen Diankov <rosen.diankov@gmail.com>
3 //
4 // This file is part of OpenRAVE.
5 // OpenRAVE is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef OPENRAVE_SENSOR_H
23 #define OPENRAVE_SENSOR_H
24 
25 namespace OpenRAVE {
26 
31 {
32 public:
34  {
35  ST_Invalid=0,
36  ST_Laser=1,
37  ST_Camera=2,
38  ST_JointEncoder=3,
39  ST_Force6D=4,
40  ST_IMU=5,
41  ST_Odometry=6,
42  ST_Tactile=7,
43  ST_Actuator=8,
44  ST_NumberofSensorTypes=8
45  };
46 
48 
51  {
52 public:
53  virtual ~SensorData() {
54  }
55  virtual SensorType GetType() = 0;
56 
58  virtual bool serialize(std::ostream& O) const;
59 
60  uint64_t __stamp;
62  };
63  typedef boost::shared_ptr<SensorBase::SensorData> SensorDataPtr;
64  typedef boost::shared_ptr<SensorBase::SensorData const> SensorDataConstPtr;
65 
67  {
68 public:
69  virtual SensorType GetType() {
70  return ST_Laser;
71  }
72 
78  std::vector<RaveVector<dReal> > positions;
79  std::vector<RaveVector<dReal> > ranges;
80  std::vector<dReal> intensity;
81 
82  virtual bool serialize(std::ostream& O) const;
83  };
85  {
86 public:
87  virtual SensorType GetType() {
88  return ST_Camera;
89  }
90  std::vector<uint8_t> vimagedata;
91  virtual bool serialize(std::ostream& O) const;
92  };
93 
96  {
97 public:
98  virtual SensorType GetType() {
99  return ST_JointEncoder;
100  }
101  std::vector<dReal> encoderValues;
102  std::vector<dReal> encoderVelocity;
103  };
104 
107  {
108 public:
109  virtual SensorType GetType() {
110  return ST_Force6D;
111  }
114  };
115 
118  {
119 public:
120  virtual SensorType GetType() {
121  return ST_IMU;
122  }
126  boost::array<dReal,9> rotation_covariance;
127  boost::array<dReal,9> angular_velocity_covariance;
128  boost::array<dReal,9> linear_acceleration_covariance;
129  };
130 
133  {
134 public:
135  virtual SensorType GetType() {
136  return ST_Odometry;
137  }
139  Vector linear_velocity, angular_velocity;
140  boost::array<dReal,36> pose_covariance;
141  boost::array<dReal,36> velocity_covariance;
142  };
143 
146  {
147 public:
148  virtual SensorType GetType() {
149  return ST_Tactile;
150  }
151  std::vector<Vector> forces;
152  boost::array<dReal,9> force_covariance;
153  };
154 
157  {
158 public:
161  AS_Undefined=0,
162  AS_Idle=1,
163  AS_Moving=2,
164  AS_Stalled=3,
165  AS_Braked=4,
166  };
167 
168  ActuatorSensorData() : state(AS_Undefined), measuredcurrent(0), measuredtemperature(0), appliedcurrent(0) {
169  }
170  virtual SensorType GetType() {
171  return ST_Actuator;
172  }
173 
178  };
179 
182  {
183 public:
184  virtual ~SensorGeometry() {
185  }
186  virtual SensorType GetType() = 0;
187  };
188  typedef boost::shared_ptr<SensorBase::SensorGeometry> SensorGeometryPtr;
189  typedef boost::shared_ptr<SensorBase::SensorGeometry const> SensorGeometryConstPtr;
190 
192  {
193 public:
194  LaserGeomData() : min_range(0), max_range(0), time_increment(0), time_scan(0) {
195  min_angle[0] = min_angle[1] = max_angle[0] = max_angle[1] = resolution[0] = resolution[1] = 0;
196  }
197  virtual SensorType GetType() {
198  return ST_Laser;
199  }
200  boost::array<dReal,2> min_angle;
201  boost::array<dReal,2> max_angle;
202  boost::array<dReal,2> resolution;
203  dReal min_range, max_range;
206  };
208  {
209 public:
210  CameraGeomData() : width(0), height(0) {
211  }
212  virtual SensorType GetType() {
213  return ST_Camera;
214  }
216  int width, height;
217  };
219  {
220 public:
221  JointEncoderGeomData() : resolution(0) {
222  }
223  virtual SensorType GetType() {
224  return ST_JointEncoder;
225  }
226  std::vector<dReal> resolution;
227  };
229  {
230 public:
231  virtual SensorType GetType() {
232  return ST_Force6D;
233  }
234  };
236  {
237 public:
238  virtual SensorType GetType() {
239  return ST_IMU;
240  }
242  };
244  {
245 public:
246  virtual SensorType GetType() {
247  return ST_Odometry;
248  }
249  std::string targetid;
250  };
251 
253  {
254 public:
255  virtual SensorType GetType() {
256  return ST_Tactile;
257  }
258 
260  struct Friction
261  {
266  };
267  std::vector<Vector> positions;
269 
270  std::map<std::string, Friction> _mapfriction;
271  };
272 
274  {
275 public:
276  virtual SensorType GetType() {
277  return ST_Actuator;
278  }
287  };
288 
289  SensorBase(EnvironmentBasePtr penv) : InterfaceBase(PT_Sensor, penv) {
290  }
291  virtual ~SensorBase() {
292  }
293 
295  static inline InterfaceType GetInterfaceTypeStatic() {
296  return PT_Sensor;
297  }
298 
301  {
302  CC_PowerOn=0x10,
303  CC_PowerOff=0x11,
304  CC_PowerCheck=0x12,
305  CC_RenderDataOn=0x20,
306  CC_RenderDataOff=0x21,
307  CC_RenderDataCheck=0x23,
308  CC_RenderGeometryOn=0x30,
309  CC_RenderGeometryOff=0x31,
310  CC_RenderGeometryCheck=0x32,
311  };
312 
318  virtual int Configure(ConfigureCommand command, bool blocking=false) = 0;
319 
323  virtual bool SimulationStep(dReal fTimeElapsed) OPENRAVE_DUMMY_IMPLEMENTATION;
324 
329  virtual SensorGeometryPtr GetSensorGeometry(SensorType type=ST_Invalid) = 0;
330 
335  virtual SensorDataPtr CreateSensorData(SensorType type=ST_Invalid) = 0;
336 
342  virtual bool GetSensorData(SensorDataPtr psensordata) = 0;
343 
345  virtual bool Supports(SensorType type) = 0;
346 
351  virtual void SetTransform(const Transform& trans) = 0;
352 
354  virtual Transform GetTransform() = 0;
355 
360  virtual UserDataPtr RegisterDataCallback(SensorType type, const boost::function<void(SensorDataConstPtr)>& callback) OPENRAVE_DUMMY_IMPLEMENTATION;
361 
363  virtual const std::string& GetName() const {
364  return _name;
365  }
366  virtual void SetName(const std::string& newname) {
367  _name = newname;
368  }
369 
370 protected:
371  std::string _name;
372 
373 private:
374  virtual const char* GetHash() const {
375  return OPENRAVE_SENSOR_HASH;
376  }
377 };
378 
379 } // end namespace OpenRAVE
380 
381 #endif