worldsim/include/sensorcontrollers.h

00001 /********************************************************************************
00002  *  FARSA Experimentes Library                                                  *
00003  *  Copyright (C) 2007-2012                                                     *
00004  *  Gianluca Massera <emmegian@yahoo.it>                                        *
00005  *  Stefano Nolfi <stefano.nolfi@istc.cnr.it>                                   *
00006  *  Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it>                         *
00007  *                                                                              *
00008  *  This program is free software; you can redistribute it and/or modify        *
00009  *  it under the terms of the GNU General Public License as published by        *
00010  *  the Free Software Foundation; either version 2 of the License, or           *
00011  *  (at your option) any later version.                                         *
00012  *                                                                              *
00013  *  This program is distributed in the hope that it will be useful,             *
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00016  *  GNU General Public License for more details.                                *
00017  *                                                                              *
00018  *  You should have received a copy of the GNU General Public License           *
00019  *  along with this program; if not, write to the Free Software                 *
00020  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00021  ********************************************************************************/
00022 
00023 #ifndef SENSORCONTROLLERS_H
00024 #define SENSORCONTROLLERS_H
00025 
00026 #include "world.h"
00027 #include "ownable.h"
00028 #include "phyobject.h"
00029 
00030 namespace farsa {
00031 
00042 class FARSA_WSIM_API SensorController : public Ownable
00043 {
00044 public:
00050     SensorController(World* world);
00051 
00055     virtual ~SensorController();
00056 
00063     virtual void update() = 0;
00064 
00071     bool isEnabled()
00072     {
00073         return m_enabled;
00074     }
00075 
00082     void setEnabled(bool b)
00083     {
00084         m_enabled = b;
00085     }
00086 
00092     World* world()
00093     {
00094         return m_world;
00095     }
00096 
00097 private:
00101     World* m_world;
00102 
00106     bool m_enabled;
00107 
00113     SensorController(const SensorController& other);
00114 
00120     SensorController& operator=(const SensorController& other);
00121 };
00122 
00131 class FARSA_WSIM_API IRSensorController : public SensorController
00132 {
00133 public:
00140     IRSensorController(World* world, unsigned int numSensors);
00141 
00145     virtual ~IRSensorController();
00146 
00150     int nSensors() const
00151     {
00152         return m_activations.size();
00153     }
00154 
00162     double activation(int i) const
00163     {
00164         return m_activations[i];
00165     }
00166 
00167 protected:
00171     QVector<double> m_activations;
00172 };
00173 
00174 namespace __SingleIR_internal {
00175     class SingleIRGraphic;
00176 }
00177 
00191 class FARSA_WSIM_API SingleIR
00192 {
00193 public:
00200     SingleIR();
00201 
00215     SingleIR(WObject* obj, wMatrix mtr, double minDist, double maxDist, double aperture, unsigned int numRays);
00216 
00222     SingleIR(const SingleIR& other);
00223 
00230     SingleIR& operator=(const SingleIR& other);
00231 
00235     ~SingleIR();
00236 
00243     void update();
00244 
00257     const RayCastHit& getRayCastHit() const
00258     {
00259         return m_rayCastHit;
00260     }
00261 
00275     void set(WObject* obj, wMatrix mtr, double minDist, double maxDist, double aperture, unsigned int numRays);
00276 
00287     void setGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
00288 
00294     const WObject* getObject() const
00295     {
00296         return m_object;
00297     }
00298 
00306     const wMatrix& getTransformation() const
00307     {
00308         return m_transformation;
00309     }
00310 
00316     double getMinDistance() const
00317     {
00318         return m_minDist;
00319     }
00320 
00326     double getMaxDistance() const
00327     {
00328         return m_maxDist;
00329     }
00330 
00336     double getAperture() const
00337     {
00338         return m_aperture;
00339     }
00340 
00346     unsigned int getNumRays() const
00347     {
00348         return m_numRays;
00349     }
00350 
00356     bool isValid() const
00357     {
00358         return ((m_object != NULL) && (m_numRays != 0));
00359     }
00360 
00361 private:
00368     void computeRayPoints();
00369 
00374     void updateGraphicalRepresentation();
00375 
00379     WObject* m_object;
00380 
00385     wMatrix m_transformation;
00386 
00390     double m_minDist;
00391 
00395     double m_maxDist;
00396 
00400     double m_aperture;
00401 
00405     unsigned int m_numRays;
00406 
00410     bool m_drawSensor;
00411 
00415     bool m_drawRay;
00416 
00421     bool m_drawRealRay;
00422 
00429     QVector<wVector> m_startingRayPoints;
00430 
00437     QVector<wVector> m_endingRayPoints;
00438 
00446     RayCastHit m_rayCastHit;
00447 
00451     __SingleIR_internal::SingleIRGraphic* m_sensorGraphics;
00452 };
00453 
00461 class FARSA_WSIM_API SimulatedIRProximitySensorController : public IRSensorController
00462 {
00463 public:
00470     SimulatedIRProximitySensorController(World* world, const QVector<SingleIR>& sensors);
00471 
00475     ~SimulatedIRProximitySensorController();
00476 
00480     virtual void update();
00481 
00491     void setGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
00492 
00493 private:
00497     QVector<SingleIR> m_sensors;
00498 };
00499 
00509 class FARSA_WSIM_API SimulatedIRGroundSensorController : public IRSensorController
00510 {
00511 public:
00518     SimulatedIRGroundSensorController(World* world, const QVector<SingleIR>& sensors);
00519 
00523     ~SimulatedIRGroundSensorController();
00524 
00528     virtual void update();
00529 
00539     void setGraphicalProperties(bool drawSensor, bool drawRay = false, bool drawRealRay = false);
00540 
00541 private:
00545     QVector<SingleIR> m_sensors;
00546 };
00547 
00548 } // end namespace farsa
00549 
00550 #endif