icubsensors.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 ICUBSENSORS_H
24 #define ICUBSENSORS_H
25 
26 #ifdef FARSA_USE_YARP_AND_ICUB
27 
28 #include "experimentsconfig.h"
29 #include "neuroninterfaces.h"
30 #include "projector.h"
31 #include "world.h"
32 #include "robots.h"
33 #include "phybox.h"
34 #include "phycylinder.h"
35 
36 namespace farsa {
37 
38 class MultiMotorController;
39 
59 class iCubSensor : public Sensor
60 {
61 public:
72  iCubSensor(ConfigurationParameters& params, QString prefix);
73 
77  virtual ~iCubSensor();
78 
87  virtual void save(ConfigurationParameters& params, QString prefix);
88 
95  static void describe(QString type);
96 
97 protected:
105  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
106 
110  QString icubResource;
111 
117 };
118 
124 class FARSA_EXPERIMENTS_API iCubArmJointsSensor : public iCubSensor {
125 public:
130  iCubArmJointsSensor( ConfigurationParameters& params, QString prefix );
137  void save( ConfigurationParameters& params, QString prefix );
139  static void describe( QString type );
141  void update();
143  int size();
144 protected:
150  void resourceChanged(QString resourceName, ResourceChangeType changeType);
152  QString icubArm;
155 };
156 
162 class FARSA_EXPERIMENTS_API ColorCameraSensor : public iCubSensor {
163 public:
165  ColorCameraSensor(ConfigurationParameters& params, QString prefix);
170  void save( ConfigurationParameters& params, QString prefix );
172  static void describe( QString type );
174  void update();
176  int size();
182  QMap<WObject*, ImagePoint> m_objectsRetinaPosition;
183 private:
189  void resourceChanged(QString resourceName, ResourceChangeType changeType);
190 
196  int nObjects;
197 
202  Projector m_projector;
203 };
204 
209 class FARSA_EXPERIMENTS_API iCubPalmTargetDistSensor : public iCubSensor {
210 public:
215  iCubPalmTargetDistSensor( ConfigurationParameters& params, QString prefix );
222  void save( ConfigurationParameters& params, QString prefix );
224  static void describe( QString type );
226  void update();
228  int size();
229 protected:
235  void resourceChanged(QString resourceName, ResourceChangeType changeType);
237  QString icubPalm;
239  QString targetName;
241  bool isLeft;
243  bool linearize;
245  wVector bbMin;
247  wVector bbMax;
249  wVector palmOffset;
252 };
253 
258 class FARSA_EXPERIMENTS_API iCubPalmTouchSensor : public iCubSensor {
259 public:
264  iCubPalmTouchSensor( ConfigurationParameters& params, QString prefix );
271  void save( ConfigurationParameters& params, QString prefix );
273  static void describe( QString type );
275  void update();
277  int size();
278 protected:
284  void resourceChanged(QString resourceName, ResourceChangeType changeType);
286  QString icubPalm;
290  QVector<WObject*>* objects;
291 };
292 
322 class FARSA_EXPERIMENTS_API iCubHandTouchSensor : public iCubSensor
323 {
324 public:
332  iCubHandTouchSensor(ConfigurationParameters& params, QString prefix);
333 
338 
347  virtual void save(ConfigurationParameters& params, QString prefix);
348 
354  static void describe(QString type);
355 
360  virtual void update();
361 
367  virtual int size();
368 
369 private:
377  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
378 
388  double handPieceCollides(PhyObject* handPiece);
389 
393  QString m_icubHand;
394 
403  bool m_checkAllObjects;
404 
408  World* m_world;
409 
413  QVector<PhyObject*> m_icubArm;
414 
418  QVector<WObject*> m_objects;
419 
423  iCubRobot* m_icub;
424 };
425 
430 class FARSA_EXPERIMENTS_API iCubTorsoJointsSensor : public iCubSensor {
431 public:
436  iCubTorsoJointsSensor( ConfigurationParameters& params, QString prefix );
443  void save( ConfigurationParameters& params, QString prefix );
445  static void describe( QString type );
447  void update();
449  int size();
450 protected:
456  void resourceChanged(QString resourceName, ResourceChangeType changeType);
459 };
460 
465 class FARSA_EXPERIMENTS_API iCubHeadJointsSensor : public iCubSensor {
466 public:
471  iCubHeadJointsSensor( ConfigurationParameters& params, QString prefix );
478  void save( ConfigurationParameters& params, QString prefix );
480  static void describe( QString type );
482  void update();
484  int size();
485 protected:
491  void resourceChanged(QString resourceName, ResourceChangeType changeType);
494 };
495 
500 class FARSA_EXPERIMENTS_API iCubHandJointsSensor : public iCubSensor {
501 public:
506  iCubHandJointsSensor( ConfigurationParameters& params, QString prefix );
513  void save( ConfigurationParameters& params, QString prefix );
515  static void describe( QString type );
517  void update();
519  int size();
520 protected:
526  void resourceChanged(QString resourceName, ResourceChangeType changeType);
528  QString icubHand;
531 };
532 
533 namespace __PalmAndFingertipTouchSensor_internal {
536 }
537 
573 class FARSA_EXPERIMENTS_API iCubFingertipsTouchSensor : public iCubSensor
574 {
575 public:
583  iCubFingertipsTouchSensor(ConfigurationParameters& params, QString prefix);
584 
589 
598  virtual void save(ConfigurationParameters& params, QString prefix);
599 
605  static void describe(QString type);
606 
611  virtual void update();
612 
618  virtual int size();
619 
620 private:
628  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
629 
639  double handPieceCollides(PhyObject* handPiece, bool isThumb) const;
640 
655  bool goodCollisionPoint(PhyObject* handPiece, const wVector& collisionPoint, bool isThumb) const;
656 
660  QString m_icubHand;
661 
666  bool m_isRight;
667 
676  bool m_checkAllObjects;
677 
683  double m_alpha;
684 
690  double m_h;
691 
695  bool m_drawSensor;
696 
700  World* m_world;
701 
705  QVector<PhyObject*> m_icubArm;
706 
710  QVector<WObject*>* m_objects;
711 
715  iCubRobot* m_icub;
716 
720  QVector<__PalmAndFingertipTouchSensor_internal::FingertipTouchSensorGraphic*> m_graphicalTouchSensors;
721 };
722 
756 class FARSA_EXPERIMENTS_API iCubPalmPatchesTouchSensor : public iCubSensor
757 {
758 public:
765  struct Triangle
766  {
770  wVector a;
771 
775  wVector b;
776 
780  wVector c;
781  };
782 
783 public:
791  iCubPalmPatchesTouchSensor(ConfigurationParameters& params, QString prefix);
792 
797 
806  virtual void save(ConfigurationParameters& params, QString prefix);
807 
813  static void describe(QString type);
814 
819  virtual void update();
820 
826  virtual int size();
827 
828 private:
836  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
837 
848  bool pointInPalmTriangle(const wVector& point, const Triangle& triangle) const;
849 
853  QString m_icubHand;
854 
859  bool m_isRight;
860 
869  bool m_checkAllObjects;
870 
874  bool m_drawSensor;
875 
879  World* m_world;
880 
884  QVector<PhyObject*> m_icubArm;
885 
889  QVector<WObject*>* m_objects;
890 
894  iCubRobot* m_icub;
895 
899  PhyBox* m_handPalm;
900 
904  QVector<Triangle> m_patches;
905 
910 };
911 
935 {
936 public:
944  HandObjectVisualOffsetSensor(ConfigurationParameters& params, QString prefix);
945 
950 
959  virtual void save(ConfigurationParameters& params, QString prefix);
960 
966  static void describe(QString type);
967 
972  virtual void update();
973 
979  virtual int size();
980 
981 private:
989  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
990 
994  QString m_icubHand;
995 
999  World* m_world;
1000 
1004  WObject* m_eye;
1005 
1009  WObject* m_hand;
1010 
1015  WObject* m_object;
1016 };
1017 
1018 } // end namespace farsa
1019 
1020 #endif
1021 
1022 #endif