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 FARSA_EXPERIMENTS_API 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 
203  Projector m_projector;
204 };
205 
209 class FARSA_EXPERIMENTS_API LinearCameraSensor : public iCubSensor {
210 public:
212  LinearCameraSensor(ConfigurationParameters& params, QString prefix);
217  void save( ConfigurationParameters& params, QString prefix );
219  static void describe( QString type );
221  void update();
223  int size();
229  QMap<WObject*, ImagePoint> m_objectsRetinaPosition;
230 private:
236  void resourceChanged(QString resourceName, ResourceChangeType changeType);
237 
243  int nObjects;
244  int nReceptors;
245  int projectionType;
246  double *receptors; //with size of nReceptors
247  double *xcoors;
248 
249 
254  Projector m_projector;
255 };
256 
261 class FARSA_EXPERIMENTS_API iCubPalmTargetDistSensor : public iCubSensor {
262 public:
267  iCubPalmTargetDistSensor( ConfigurationParameters& params, QString prefix );
274  void save( ConfigurationParameters& params, QString prefix );
276  static void describe( QString type );
278  void update();
280  int size();
281 protected:
287  void resourceChanged(QString resourceName, ResourceChangeType changeType);
289  QString icubPalm;
291  QString targetName;
293  bool isLeft;
295  bool linearize;
297  wVector bbMin;
299  wVector bbMax;
301  wVector palmOffset;
304 };
305 
310 class FARSA_EXPERIMENTS_API iCubPalmTouchSensor : public iCubSensor {
311 public:
316  iCubPalmTouchSensor( ConfigurationParameters& params, QString prefix );
323  void save( ConfigurationParameters& params, QString prefix );
325  static void describe( QString type );
327  void update();
329  int size();
330 protected:
336  void resourceChanged(QString resourceName, ResourceChangeType changeType);
338  QString icubPalm;
342  QVector<WObject*>* objects;
343 };
344 
374 class FARSA_EXPERIMENTS_API iCubHandTouchSensor : public iCubSensor
375 {
376 public:
384  iCubHandTouchSensor(ConfigurationParameters& params, QString prefix);
385 
390 
399  virtual void save(ConfigurationParameters& params, QString prefix);
400 
406  static void describe(QString type);
407 
412  virtual void update();
413 
419  virtual int size();
420 
421 private:
429  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
430 
440  double handPieceCollides(PhyObject* handPiece);
441 
445  QString m_icubHand;
446 
455  bool m_checkAllObjects;
456 
460  World* m_world;
461 
465  QVector<PhyObject*> m_icubArm;
466 
470  QVector<WObject*> m_objects;
471 
475  iCubRobot* m_icub;
476 };
477 
482 class FARSA_EXPERIMENTS_API iCubTorsoJointsSensor : public iCubSensor {
483 public:
488  iCubTorsoJointsSensor( ConfigurationParameters& params, QString prefix );
495  void save( ConfigurationParameters& params, QString prefix );
497  static void describe( QString type );
499  void update();
501  int size();
502 protected:
508  void resourceChanged(QString resourceName, ResourceChangeType changeType);
511 };
512 
517 class FARSA_EXPERIMENTS_API iCubHeadJointsSensor : public iCubSensor {
518 public:
523  iCubHeadJointsSensor( ConfigurationParameters& params, QString prefix );
530  void save( ConfigurationParameters& params, QString prefix );
532  static void describe( QString type );
534  void update();
536  int size();
537 protected:
543  void resourceChanged(QString resourceName, ResourceChangeType changeType);
546 };
547 
552 class FARSA_EXPERIMENTS_API iCubPCHeadJointsSensor : public iCubSensor {
553 public:
558  iCubPCHeadJointsSensor( ConfigurationParameters& params, QString prefix );
565  void save( ConfigurationParameters& params, QString prefix );
567  static void describe( QString type );
569  void update();
571  int size();
572 protected:
579  int nNeurons;
581  bool headDofs[6];
582  double headEncoderValues[6];
583  void resourceChanged(QString resourceName, ResourceChangeType changeType);
586  double neuronActivation(int n, int j); //returns the activation of the nth neuron of the population for the jth joint
587 };
588 
593 class FARSA_EXPERIMENTS_API iCubHandJointsSensor : public iCubSensor {
594 public:
599  iCubHandJointsSensor( ConfigurationParameters& params, QString prefix );
606  void save( ConfigurationParameters& params, QString prefix );
608  static void describe( QString type );
610  void update();
612  int size();
613 protected:
619  void resourceChanged(QString resourceName, ResourceChangeType changeType);
621  QString icubHand;
624 };
625 
626 namespace __PalmAndFingertipTouchSensor_internal {
629 }
630 
666 class FARSA_EXPERIMENTS_API iCubFingertipsTouchSensor : public iCubSensor
667 {
668 public:
676  iCubFingertipsTouchSensor(ConfigurationParameters& params, QString prefix);
677 
682 
691  virtual void save(ConfigurationParameters& params, QString prefix);
692 
698  static void describe(QString type);
699 
704  virtual void update();
705 
711  virtual int size();
712 
713 private:
721  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
722 
732  double handPieceCollides(PhyObject* handPiece, bool isThumb) const;
733 
748  bool goodCollisionPoint(PhyObject* handPiece, const wVector& collisionPoint, bool isThumb) const;
749 
753  QString m_icubHand;
754 
759  bool m_isRight;
760 
769  bool m_checkAllObjects;
770 
776  double m_alpha;
777 
783  double m_h;
784 
788  bool m_drawSensor;
789 
793  World* m_world;
794 
798  QVector<PhyObject*> m_icubArm;
799 
803  QVector<WObject*>* m_objects;
804 
808  iCubRobot* m_icub;
809 
813  QVector<__PalmAndFingertipTouchSensor_internal::FingertipTouchSensorGraphic*> m_graphicalTouchSensors;
814 };
815 
849 class FARSA_EXPERIMENTS_API iCubPalmPatchesTouchSensor : public iCubSensor
850 {
851 public:
858  struct Triangle
859  {
863  wVector a;
864 
868  wVector b;
869 
873  wVector c;
874  };
875 
876 public:
884  iCubPalmPatchesTouchSensor(ConfigurationParameters& params, QString prefix);
885 
890 
899  virtual void save(ConfigurationParameters& params, QString prefix);
900 
906  static void describe(QString type);
907 
912  virtual void update();
913 
919  virtual int size();
920 
921 private:
929  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
930 
941  bool pointInPalmTriangle(const wVector& point, const Triangle& triangle) const;
942 
946  QString m_icubHand;
947 
952  bool m_isRight;
953 
962  bool m_checkAllObjects;
963 
967  bool m_drawSensor;
968 
972  World* m_world;
973 
977  QVector<PhyObject*> m_icubArm;
978 
982  QVector<WObject*>* m_objects;
983 
987  iCubRobot* m_icub;
988 
992  PhyBox* m_handPalm;
993 
997  QVector<Triangle> m_patches;
998 
1003 };
1004 
1027 class FARSA_EXPERIMENTS_API HandObjectVisualOffsetSensor : public iCubSensor
1028 {
1029 public:
1037  HandObjectVisualOffsetSensor(ConfigurationParameters& params, QString prefix);
1038 
1043 
1052  virtual void save(ConfigurationParameters& params, QString prefix);
1053 
1059  static void describe(QString type);
1060 
1065  virtual void update();
1066 
1072  virtual int size();
1073 
1074 private:
1082  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
1083 
1087  QString m_icubHand;
1088 
1092  World* m_world;
1093 
1097  WObject* m_eye;
1098 
1102  WObject* m_hand;
1103 
1108  WObject* m_object;
1109 };
1110 
1111 } // end namespace farsa
1112 
1113 #endif
1114 
1115 #endif