iCub-main
emotionInterfaceModule.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2007 Alex Bernardino
5  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
6  *
7  */
8 
9 
10 
11 #ifndef __EMOTIONINTERFACEMODULE__
12 #define __EMOTIONINTERFACEMODULE__
13 
14 
15  // std
16 #include <cstdio>
17 #include <string>
18 #include <iostream>
19 
20 
21 // yarp
22 #include <yarp/os/all.h>
23 #include <yarp/dev/PolyDriver.h>
24 #include <yarp/dev/IPositionControl.h>
25 #include <yarp/sig/all.h>
26 
27 using namespace yarp::os;
28 using namespace yarp::sig;
29 using namespace std;
30 
31 #include "emotionInterface.h"
32 
33 namespace iCub {
34  namespace contrib {
35  class EmotionInitReport;
37  }
38 }
39 
40 using namespace iCub::contrib;
41 
42 typedef struct
43 {
44  char name[3];
45  char leb[2];
46  char reb[2];
47  char mou[2];
48  char eli[2];
49 
50 } EM_CODE;
51 
52 
53 class iCub::contrib::EmotionInitReport : public PortReport
54 {
55 private:
57 
58 public:
60  virtual void report(const PortInfo &info);
61 };
62 
70 class iCub::contrib::EmotionInterfaceModule : public RFModule,
71  public IEmotionInterface {
72 
73 private:
74 
75  // input command port
76  Port _inputPort;
77 
78  // reporter put on the init emotion
79  EmotionInitReport emotionInitReport;
80 
81  // output command port
82  BufferedPort<Bottle> _outputPort;
83 
84  // number of high level emotions
85  size_t _highlevelemotions{};
86  size_t _numberOfColors{};
87  size_t _eyebrowmaskemotions{};
88  size_t _mouthmaskemotions{};
89 
90  // table with the setting for each emotion - from config file
91  EM_CODE* _emotion_table{};
92  std::map<std::string, std::string > _bitmask_emotion_table;
93  std::map<std::string, std::string > _color_table;
94 
95  //Time variables for automatic expression switching
96  bool _auto{};
97  double _lasttime{};
98  double _period{};
99  int _initEmotionTrigger{};
100 
101  // PolyDriver and interface to command the eyelids in the rfe robots
102  yarp::dev::PolyDriver _poly;
103  yarp::dev::IPositionControl* _iPos{ nullptr };
104  double _min{ 0.0 }, _max{ 0.0 };
105  size_t _joint_eylids{ 0 };
106 
107 
108 
109  int getIndex(std::string cmd);
110  bool writePort(const char* cmd);
111  double getEyelidsTarget(const char eli0, const char eli1);
112 
113 public:
114 
116  ~EmotionInterfaceModule() override = default;
117 
118  bool configure(ResourceFinder& config) override;//virtual bool open(Searchable& config);
119  bool close() override;
120  bool interruptModule() override;
121  bool updateModule() override;
122  double getPeriod() override;
123  bool respond(const Bottle &command,Bottle &reply)override;
124  void initEmotion();
125 
126  // interface functions
127  bool setLeftEyebrow(const std::string cmd) override;
128  bool setRightEyebrow(const std::string cmd) override;
129  bool setEyelids(const std::string cmd) override;
130  bool setMouth(const std::string cmd) override;
131  bool setAll(const std::string cmd) override;
132  bool setRaw(const std::string cmd) override;
133 
134  bool setColor(const string& cmd);
135  bool setBrightness(const string& cmd);
136  bool setMask(const Bottle& cmd);
137 };
138 
139 
140 #endif
EmotionInitReport(EmotionInterfaceModule *_emo)
~EmotionInterfaceModule() override=default
Interface for the Facial Expressions.
cmd
Definition: dataTypes.h:30
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.