experiments/include/icubsensors.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 ICUBSENSORS_H
00024 #define ICUBSENSORS_H
00025 
00026 #ifdef FARSA_USE_YARP_AND_ICUB
00027 
00028 #include "experimentsconfig.h"
00029 #include "neuroninterfaces.h"
00030 #include "projector.h"
00031 #include "world.h"
00032 #include "robots.h"
00033 #include "phybox.h"
00034 #include "phycylinder.h"
00035 
00036 namespace farsa {
00037 
00038 class MultiMotorController;
00039 
00059 class iCubSensor : public Sensor
00060 {
00061 public:
00072     iCubSensor(ConfigurationParameters& params, QString prefix);
00073 
00077     virtual ~iCubSensor();
00078 
00087     virtual void save(ConfigurationParameters& params, QString prefix);
00088 
00095     static void describe(QString type);
00096 
00097 protected:
00105     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00106 
00110     QString icubResource;
00111 
00116     QString neuronsIteratorResource;
00117 };
00118 
00124 class FARSA_EXPERIMENTS_API iCubArmJointsSensor : public iCubSensor {
00125 public:
00130     iCubArmJointsSensor( ConfigurationParameters& params, QString prefix );
00132     ~iCubArmJointsSensor();
00137     void save( ConfigurationParameters& params, QString prefix );
00139     static void describe( QString type );
00141     void update();
00143     int size();
00144 protected:
00150     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00152     QString icubArm;
00154     MultiMotorController* icubMotors;
00155 };
00156 
00162 class FARSA_EXPERIMENTS_API ColorCameraSensor : public iCubSensor {
00163 public:
00165     ColorCameraSensor(ConfigurationParameters& params, QString prefix);
00170     void save( ConfigurationParameters& params, QString prefix );
00172     static void describe( QString type );
00174     void update();
00176     int size();
00182     QMap<WObject*, ImagePoint> m_objectsRetinaPosition;
00183 private:
00189     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00190 
00196     int nObjects;
00197 
00202     Projector m_projector;
00203 };
00204 
00209 class FARSA_EXPERIMENTS_API iCubPalmTargetDistSensor : public iCubSensor {
00210 public:
00215     iCubPalmTargetDistSensor( ConfigurationParameters& params, QString prefix );
00217     ~iCubPalmTargetDistSensor();
00222     void save( ConfigurationParameters& params, QString prefix );
00224     static void describe( QString type );
00226     void update();
00228     int size();
00229 protected:
00235     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00237     QString icubPalm;
00239     QString targetName;
00241     bool isLeft;
00243     bool linearize;
00245     wVector bbMin;
00247     wVector bbMax;
00249     wVector palmOffset;
00251     bool addPalmOffset;
00252 };
00253 
00258 class FARSA_EXPERIMENTS_API iCubPalmTouchSensor : public iCubSensor {
00259 public:
00264     iCubPalmTouchSensor( ConfigurationParameters& params, QString prefix );
00266     ~iCubPalmTouchSensor();
00271     void save( ConfigurationParameters& params, QString prefix );
00273     static void describe( QString type );
00275     void update();
00277     int size();
00278 protected:
00284     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00286     QString icubPalm;
00288     WObject* wPalm;
00290     QVector<WObject*>* objects;
00291 };
00292 
00322 class FARSA_EXPERIMENTS_API iCubHandTouchSensor : public iCubSensor
00323 {
00324 public:
00332     iCubHandTouchSensor(ConfigurationParameters& params, QString prefix);
00333 
00337     ~iCubHandTouchSensor();
00338 
00347     virtual void save(ConfigurationParameters& params, QString prefix);
00348 
00354     static void describe(QString type);
00355 
00360     virtual void update();
00361 
00367     virtual int size();
00368 
00369 private:
00377     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00378 
00388     double handPieceCollides(PhyObject* handPiece);
00389 
00393     QString m_icubHand;
00394 
00403     bool m_checkAllObjects;
00404 
00408     World* m_world;
00409 
00413     QVector<PhyObject*> m_icubArm;
00414 
00418     QVector<WObject*> m_objects;
00419 
00423     iCubRobot* m_icub;
00424 };
00425 
00430 class FARSA_EXPERIMENTS_API iCubTorsoJointsSensor : public iCubSensor {
00431 public:
00436     iCubTorsoJointsSensor( ConfigurationParameters& params, QString prefix );
00438     ~iCubTorsoJointsSensor();
00443     void save( ConfigurationParameters& params, QString prefix );
00445     static void describe( QString type );
00447     void update();
00449     int size();
00450 protected:
00456     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00458     MultiMotorController* icubMotors;
00459 };
00460 
00465 class FARSA_EXPERIMENTS_API iCubHeadJointsSensor : public iCubSensor {
00466 public:
00471     iCubHeadJointsSensor( ConfigurationParameters& params, QString prefix );
00473     ~iCubHeadJointsSensor();
00478     void save( ConfigurationParameters& params, QString prefix );
00480     static void describe( QString type );
00482     void update();
00484     int size();
00485 protected:
00491     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00493     MultiMotorController* icubMotors;
00494 };
00495 
00500 class FARSA_EXPERIMENTS_API iCubHandJointsSensor : public iCubSensor {
00501 public:
00506     iCubHandJointsSensor( ConfigurationParameters& params, QString prefix );
00508     ~iCubHandJointsSensor();
00513     void save( ConfigurationParameters& params, QString prefix );
00515     static void describe( QString type );
00517     void update();
00519     int size();
00520 protected:
00526     void resourceChanged(QString resourceName, ResourceChangeType changeType);
00528     QString icubHand;
00530     MultiMotorController* icubMotors;
00531 };
00532 
00533 namespace __PalmAndFingertipTouchSensor_internal {
00534     class FingertipTouchSensorGraphic;
00535     class PalmPatchesTouchSensorGraphic;
00536 }
00537 
00573 class FARSA_EXPERIMENTS_API iCubFingertipsTouchSensor : public iCubSensor
00574 {
00575 public:
00583     iCubFingertipsTouchSensor(ConfigurationParameters& params, QString prefix);
00584 
00588     ~iCubFingertipsTouchSensor();
00589 
00598     virtual void save(ConfigurationParameters& params, QString prefix);
00599 
00605     static void describe(QString type);
00606 
00611     virtual void update();
00612 
00618     virtual int size();
00619 
00620 private:
00628     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00629 
00639     double handPieceCollides(PhyObject* handPiece, bool isThumb) const;
00640 
00655     bool goodCollisionPoint(PhyObject* handPiece, const wVector& collisionPoint, bool isThumb) const;
00656 
00660     QString m_icubHand;
00661 
00666     bool m_isRight;
00667 
00676     bool m_checkAllObjects;
00677 
00683     double m_alpha;
00684 
00690     double m_h;
00691 
00695     bool m_drawSensor;
00696 
00700     World* m_world;
00701 
00705     QVector<PhyObject*> m_icubArm;
00706 
00710     QVector<WObject*>* m_objects;
00711 
00715     iCubRobot* m_icub;
00716 
00720     QVector<__PalmAndFingertipTouchSensor_internal::FingertipTouchSensorGraphic*> m_graphicalTouchSensors;
00721 };
00722 
00756 class FARSA_EXPERIMENTS_API iCubPalmPatchesTouchSensor : public iCubSensor
00757 {
00758 public:
00765     struct Triangle
00766     {
00770         wVector a;
00771 
00775         wVector b;
00776 
00780         wVector c;
00781     };
00782 
00783 public:
00791     iCubPalmPatchesTouchSensor(ConfigurationParameters& params, QString prefix);
00792 
00796     ~iCubPalmPatchesTouchSensor();
00797 
00806     virtual void save(ConfigurationParameters& params, QString prefix);
00807 
00813     static void describe(QString type);
00814 
00819     virtual void update();
00820 
00826     virtual int size();
00827 
00828 private:
00836     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00837 
00848     bool pointInPalmTriangle(const wVector& point, const Triangle& triangle) const;
00849 
00853     QString m_icubHand;
00854 
00859     bool m_isRight;
00860 
00869     bool m_checkAllObjects;
00870 
00874     bool m_drawSensor;
00875 
00879     World* m_world;
00880 
00884     QVector<PhyObject*> m_icubArm;
00885 
00889     QVector<WObject*>* m_objects;
00890 
00894     iCubRobot* m_icub;
00895 
00899     PhyBox* m_handPalm;
00900 
00904     QVector<Triangle> m_patches;
00905 
00909     __PalmAndFingertipTouchSensor_internal::PalmPatchesTouchSensorGraphic* m_graphicalTouchSensor;
00910 };
00911 
00934 class HandObjectVisualOffsetSensor : public iCubSensor
00935 {
00936 public:
00944     HandObjectVisualOffsetSensor(ConfigurationParameters& params, QString prefix);
00945 
00949     ~HandObjectVisualOffsetSensor();
00950 
00959     virtual void save(ConfigurationParameters& params, QString prefix);
00960 
00966     static void describe(QString type);
00967 
00972     virtual void update();
00973 
00979     virtual int size();
00980 
00981 private:
00989     virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
00990 
00994     QString m_icubHand;
00995 
00999     World* m_world;
01000 
01004     WObject* m_eye;
01005 
01009     WObject* m_hand;
01010 
01015     WObject* m_object;
01016 };
01017 
01018 } // end namespace farsa
01019 
01020 #endif
01021 
01022 #endif