icub-client
allostaticController.h
Go to the documentation of this file.
1 #ifndef ALLOSTATICCONTROLLER_H
2 #define ALLOSTATICCONTROLLER_H
3 
4 #include <string>
5 #include <iostream>
6 #include <iomanip>
7 #include <yarp/os/all.h>
8 #include <yarp/sig/all.h>
9 #include <yarp/math/Rand.h>
10 #include <map>
12 
13 using namespace std;
14 using namespace yarp::os;
15 using namespace yarp::sig;
16 using namespace yarp::math;
17 using namespace icubclient;
18 
19 
24 
28 struct DriveOutCZ {
29  string name;
31 
32 };
33 
38 
43 {
44 public:
45  string name;
46  bool active, manualMode;
49  Port *homeoPort;
50  BufferedPort<Bottle> *inputSensationPort;
52  Bottle behaviorOverCmd;
53  Bottle sensationOnCmd, sensationOffCmd, beforeTriggerCmd, afterTriggerCmd;
54 
56  manualMode = true;
57  behaviorUnderPort = nullptr;
58  behaviorOverPort = nullptr;
59  homeoPort = nullptr;
60  inputSensationPort = nullptr;
61  active = false;
62  }
63 
67  bool interrupt_ports();
68 
72  bool close_ports();
73 
74  Bottle update(DriveUpdateMode mode);
75 
80  void triggerBehavior(OutCZ mode);
81 };
82 
86 class AllostaticController: public RFModule
87 {
88 private:
89  Bottle drivesList;
90 
91  Port to_homeo_rpc, rpc_in_port, to_behavior_rpc;
92  string moduleName;
93  string homeo_name;
94 
95  double period;
96 
97  map<string, AllostaticDrive> allostaticDrives;
98 
99 
100  vector<double> drivePriorities;
101 
102  vector< yarp::os::BufferedPort<Bottle>* > outputM_ports;
103  vector< yarp::os::BufferedPort<Bottle>* > outputm_ports;
104 
105 
111  void configureAllostatic(yarp::os::ResourceFinder &rf);
112 
118  bool openPorts(string driveName);
119 public:
120  AllostaticController() : period(0.5) {
121  ;
122  }
123 
124  bool configure(yarp::os::ResourceFinder &rf);
125  bool interruptModule();
126 
127  bool close();
128 
129  double getPeriod()
130  {
131  return period;
132  }
133 
134  bool updateModule();
135 
140  bool updateAllostatic();
141 
147  bool Normalize(vector<double>& vec);
148 
153  DriveOutCZ chooseDrive();
154 
155  bool respond(const Bottle& cmd, Bottle& reply);
156 };
157 
158 #endif
DriveUpdateMode
Port * behaviorOverPort
Port to be used when drive hits upper threshold of homeostatic level.
BufferedPort< Bottle > * inputSensationPort
Port from sensationManager.
Bottle behaviorOverCmd
Command to be send to behaviorOverPort when drive hits upper threshold of homeostatic level...
STL namespace.
Port * behaviorUnderPort
Port to be used when drive falls below homeostatic level.
Bottle behaviorUnderCmd
Command to be send to behaviorUnderPort when drive falls below homeostatic level. ...
Port * homeoPort
Port to homeostasis module.
string name
Name of the drive.