sensorcontrollers.h
1 /********************************************************************************
2  * FARSA Experimentes Library *
3  * Copyright (C) 2007-2012 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21  ********************************************************************************/
22 
23 #ifndef SENSORCONTROLLERS_H
24 #define SENSORCONTROLLERS_H
25 
26 #include "world.h"
27 #include "ownable.h"
28 #include "phyobject.h"
29 #include "phyfixed.h"
30 
31 namespace farsa {
32 
43 class FARSA_WSIM_API SensorController : public Ownable
44 {
45 public:
51  SensorController(World* world);
52 
56  virtual ~SensorController();
57 
64  virtual void update() = 0;
65 
72  bool isEnabled()
73  {
74  return m_enabled;
75  }
76 
83  void setEnabled(bool b)
84  {
85  m_enabled = b;
86  }
87 
93  World* world()
94  {
95  return m_world;
96  }
97 
98 private:
102  World* m_world;
103 
107  bool m_enabled;
108 
114  SensorController(const SensorController& other);
115 
121  SensorController& operator=(const SensorController& other);
122 };
123 
132 class FARSA_WSIM_API IRSensorController : public SensorController
133 {
134 public:
141  IRSensorController(World* world, unsigned int numSensors);
142 
146  virtual ~IRSensorController();
147 
151  int nSensors() const
152  {
153  return m_activations.size();
154  }
155 
163  double activation(int i) const
164  {
165  return m_activations[i];
166  }
167 
168 protected:
172  QVector<double> m_activations;
173 };
174 
175 namespace __SingleIR_internal {
176  class SingleIRGraphic;
177 }
178 
192 class FARSA_WSIM_API SingleIR
193 {
194 public:
201  SingleIR();
202 
216  SingleIR(WObject* obj, wMatrix mtr, double minDist, double maxDist, double aperture, unsigned int numRays);
217 
223  SingleIR(const SingleIR& other);
224 
231  SingleIR& operator=(const SingleIR& other);
232 
236  ~SingleIR();
237 
244  void update();
245 
258  const RayCastHit& getRayCastHit() const
259  {
260  return m_rayCastHit;
261  }
262 
276  void set(WObject* obj, wMatrix mtr, double minDist, double maxDist, double aperture, unsigned int numRays);
277 
288  void setGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
289 
295  const WObject* getObject() const
296  {
297  return m_object;
298  }
299 
307  const wMatrix& getTransformation() const
308  {
309  return m_transformation;
310  }
311 
317  double getMinDistance() const
318  {
319  return m_minDist;
320  }
321 
327  double getMaxDistance() const
328  {
329  return m_maxDist;
330  }
331 
337  double getAperture() const
338  {
339  return m_aperture;
340  }
341 
347  unsigned int getNumRays() const
348  {
349  return m_numRays;
350  }
351 
357  bool isValid() const
358  {
359  return ((m_object != NULL) && (m_numRays != 0));
360  }
361 
362 private:
369  void computeRayPoints();
370 
375  void updateGraphicalRepresentation();
376 
380  WObject* m_object;
381 
386  wMatrix m_transformation;
387 
391  double m_minDist;
392 
396  double m_maxDist;
397 
401  double m_aperture;
402 
406  unsigned int m_numRays;
407 
411  bool m_drawSensor;
412 
416  bool m_drawRay;
417 
422  bool m_drawRealRay;
423 
430  QVector<wVector> m_startingRayPoints;
431 
438  QVector<wVector> m_endingRayPoints;
439 
447  RayCastHit m_rayCastHit;
448 
452  __SingleIR_internal::SingleIRGraphic* m_sensorGraphics;
453 };
454 
463 {
464 public:
471  SimulatedIRProximitySensorController(World* world, const QVector<SingleIR>& sensors);
472 
477 
481  virtual void update();
482 
492  void setGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
493 
494 private:
498  QVector<SingleIR> m_sensors;
499 };
500 
511 {
512 public:
519  SimulatedIRGroundSensorController(World* world, const QVector<SingleIR>& sensors);
520 
525 
529  virtual void update();
530 
540  void setGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
541 
542 private:
546  QVector<SingleIR> m_sensors;
547 };
548 
555 class FARSA_WSIM_API TractionSensorController : public SensorController
556 {
557 public:
564  TractionSensorController(World* world, const PhyFixed& j);
565 
570 
574  virtual void update();
575 
581  wVector traction() const;
582 
583 private:
587  const PhyFixed& m_joint;
588 };
589 
590 } // end namespace farsa
591 
592 #endif