icubmotors.h
1 /********************************************************************************
2  * FARSA Experimentes Library *
3  * Copyright (C) 2007-2013 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the Free Software *
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
22  ********************************************************************************/
23 
24 #ifndef ICUBMOTORS_H
25 #define ICUBMOTORS_H
26 
27 #ifdef FARSA_USE_YARP_AND_ICUB
28 
29 #include "experimentsconfig.h"
30 #include "neuroninterfaces.h"
31 #include "musclepair.h"
32 #include "robots.h"
33 #include "motors.h"
34 
35 namespace farsa {
36 
37 class MultiMotorController;
38 
57 class FARSA_EXPERIMENTS_API iCubMotor : public Motor
58 {
59 public:
70  iCubMotor(ConfigurationParameters& params, QString prefix);
71 
75  virtual ~iCubMotor();
76 
85  virtual void save(ConfigurationParameters& params, QString prefix);
86 
93  static void describe(QString type);
94 
95 protected:
103  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
104 
108  QString icubResource;
109 
115 };
116 
122 class FARSA_EXPERIMENTS_API iCubArmRandomMotor : public iCubMotor {
123 public:
128  iCubArmRandomMotor( ConfigurationParameters& params, QString prefix );
135  void save( ConfigurationParameters& params, QString prefix );
137  static void describe( QString type );
139  void update();
141  int size();
142 protected:
148  void resourceChanged(QString resourceName, ResourceChangeType changeType);
150  QString icubArm;
157 };
158 
166 class FARSA_EXPERIMENTS_API iCubArmPosToPostureMotor : public iCubMotor {
167 public:
172  iCubArmPosToPostureMotor( ConfigurationParameters& params, QString prefix );
179  void save( ConfigurationParameters& params, QString prefix );
181  static void describe( QString type );
183  void update();
185  int size();
186 protected:
192  void resourceChanged(QString resourceName, ResourceChangeType changeType);
194  QString icubArm;
202  bool is7Dof;
203 };
204 
212 class FARSA_EXPERIMENTS_API iCubTorsoPosToPostureMotor : public iCubMotor {
213 public:
218  iCubTorsoPosToPostureMotor( ConfigurationParameters& params, QString prefix );
225  void save( ConfigurationParameters& params, QString prefix );
227  static void describe( QString type );
229  void update();
231  int size();
232 protected:
238  void resourceChanged(QString resourceName, ResourceChangeType changeType);
244  bool torsoDofs[3];
245 };
246 
251 class FARSA_EXPERIMENTS_API iCubArmMusclesMotor : public iCubMotor {
252 public:
257  iCubArmMusclesMotor( ConfigurationParameters& params, QString prefix );
264  void save( ConfigurationParameters& params, QString prefix );
266  static void describe( QString type );
268  void update();
270  int size();
271 protected:
277  void resourceChanged(QString resourceName, ResourceChangeType changeType);
281  QString icubArm;
286 };
287 
292 class FARSA_EXPERIMENTS_API iCubHandMusclesMotor : public iCubMotor {
293 public:
298  iCubHandMusclesMotor( ConfigurationParameters& params, QString prefix );
305  void save( ConfigurationParameters& params, QString prefix );
307  static void describe( QString type );
309  void update();
311  int size();
312 protected:
318  void resourceChanged(QString resourceName, ResourceChangeType changeType);
322  QString icubHand;
327 };
328 
333 class FARSA_EXPERIMENTS_API iCubTorsoMusclesMotor : public iCubMotor {
334 public:
339  iCubTorsoMusclesMotor( ConfigurationParameters& params, QString prefix );
346  void save( ConfigurationParameters& params, QString prefix );
348  static void describe( QString type );
350  void update();
352  int size();
353 protected:
359  void resourceChanged(QString resourceName, ResourceChangeType changeType);
366 };
367 
372 class FARSA_EXPERIMENTS_API iCubHeadMusclesMotor : public iCubMotor {
373 public:
378  iCubHeadMusclesMotor( ConfigurationParameters& params, QString prefix );
385  void save( ConfigurationParameters& params, QString prefix );
387  static void describe( QString type );
389  void update();
391  int size();
392 protected:
398  void resourceChanged(QString resourceName, ResourceChangeType changeType);
405 };
406 
426 class FARSA_EXPERIMENTS_API iCubPosToVelMotor : public iCubMotor
427 {
428 public:
438  iCubPosToVelMotor(ConfigurationParameters& params, QString prefix);
439 
443  virtual ~iCubPosToVelMotor();
444 
453  virtual void save(ConfigurationParameters& params, QString prefix);
454 
461  static void describe(QString type);
462 
470  const ProportionalController& proportionalController() const
471  {
472  return m_proportionalController;
473  }
474 
481  real getK() const
482  {
483  return m_proportionalController.getK();
484  }
485 
492  void setK(real k)
493  {
494  m_proportionalController.setK(k);
495  }
496 
503  real getMaxVelocity() const
504  {
505  return m_proportionalController.getMaxVelocity();
506  }
507 
514  void setMaxVelocity(real maxVelocity)
515  {
516  m_proportionalController.setMaxVelocity(maxVelocity);
517  }
518 
519 private:
524  ProportionalController m_proportionalController;
525 };
526 
531 class FARSA_EXPERIMENTS_API iCubArmPosToVelMotor : public iCubPosToVelMotor {
532 public:
537  iCubArmPosToVelMotor( ConfigurationParameters& params, QString prefix );
544  void save( ConfigurationParameters& params, QString prefix );
546  static void describe( QString type );
548  void update();
550  int size();
551 protected:
557  void resourceChanged(QString resourceName, ResourceChangeType changeType);
559  QString icubArm;
564 };
565 
570 class FARSA_EXPERIMENTS_API iCubTorsoPosToVelMotor : public iCubPosToVelMotor {
571 public:
576  iCubTorsoPosToVelMotor( ConfigurationParameters& params, QString prefix );
583  void save( ConfigurationParameters& params, QString prefix );
585  static void describe( QString type );
587  void update();
589  int size();
590 protected:
596  void resourceChanged(QString resourceName, ResourceChangeType changeType);
602  bool torsoDofs[3];
603 };
604 
609 class FARSA_EXPERIMENTS_API iCubHeadPosToVelMotor : public iCubPosToVelMotor {
610 public:
615  iCubHeadPosToVelMotor( ConfigurationParameters& params, QString prefix );
622  void save( ConfigurationParameters& params, QString prefix );
624  static void describe( QString type );
626  void update();
628  int size();
629 protected:
635  void resourceChanged(QString resourceName, ResourceChangeType changeType);
641  bool headDofs[6];
642 
643 };
644 
685 class FARSA_EXPERIMENTS_API iCubConfigurableHandPosToVelMotor : public iCubPosToVelMotor
686 {
687 public:
696 
701 
710  virtual void save(ConfigurationParameters& params, QString prefix);
711 
717  static void describe(QString type);
718 
723  virtual void update();
724 
730  virtual int size();
731 
732 private:
740  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
741 
745  QString m_icubHand;
746 
753  QVector<QVector<int> > m_jointsGroups;
754 
761  double m_maxClosure;
762 
766  MultiMotorController* m_armController;
767 
772  ProportionalController m_pcontrol;
773 };
774 
790 class FARSA_EXPERIMENTS_API iCubHeadVelocityMotor : public iCubMotor
791 {
792 public:
800  iCubHeadVelocityMotor(ConfigurationParameters& params, QString prefix);
801 
806 
815  virtual void save(ConfigurationParameters& params, QString prefix);
816 
822  static void describe(QString type);
823 
828  virtual void update();
829 
835  virtual int size();
836 
837 private:
846  virtual void resourceChanged(QString resourceName, ResourceChangeType changeType);
847 
851  MultiMotorController* m_headNeckController;
852 };
853 
859 class FARSA_EXPERIMENTS_API iCubArmVelocityMotor : public iCubMotor {
860 public:
865  iCubArmVelocityMotor( ConfigurationParameters& params, QString prefix );
872  void save( ConfigurationParameters& params, QString prefix );
874  static void describe( QString type );
876  void update();
878  int size();
879 protected:
885  void resourceChanged(QString resourceName, ResourceChangeType changeType);
887  QString icubArm;
895  bool is7Dof;
897  double maxVelocity;
898 };
899 
905 class FARSA_EXPERIMENTS_API iCubTorsoVelocityMotor : public iCubMotor {
906 public:
911  iCubTorsoVelocityMotor( ConfigurationParameters& params, QString prefix );
918  void save( ConfigurationParameters& params, QString prefix );
920  static void describe( QString type );
922  void update();
924  int size();
925 protected:
931  void resourceChanged(QString resourceName, ResourceChangeType changeType);
937  bool torsoDofs[3];
939  double maxVelocity;
940 };
941 
942 } // end namespace farsa
943 
944 #endif
945 
946 #endif