NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_behaviour_control.h
1 // Header for unit testing of the Behaviour Control Framework
2 // Author: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
3 
4 // Ensure header is only included once
5 #ifndef TEST_BEHAVIOUR_CONTROL_H
6 #define TEST_BEHAVIOUR_CONTROL_H
7 
8 // Include configurations
9 #ifndef VERBOSE_TEST
10 //#define VERBOSE_TEST // Comment this line out to inhibit printing to console
11 #endif /* VERBOSE_TEST */
12 
13 // Includes
14 #include <iostream>
15 #include <gtest/gtest.h>
16 #include <test_utilities/test_utilities.h>
18 
19 // Behaviour control test namespace
20 namespace behaviourcontroltest
21 {
22  // Namespaces
23  using namespace testutilities;
24  using namespace behaviourcontrol;
25 
26  //
27  // Class declarations
28  //
29 
30  // MyM manager
31  class MyM;
32 
33  // RosIL layer
34  class RosIL;
35  class RosILSM;
36  class RosILAM;
37 
38  // MyL1 layer
39  class MyL1;
40  class MyL1SM;
41  class MyL1AM;
42  class MyB1;
43  class MyB2;
44 
45  // MyL2 layer
46  class MyL2;
47  class MyL2SM;
48  class MyL2AM;
49  class MyB3;
50  class MyB4;
51 
52  //
53  // MyM manager
54  //
55 
56  // MyM class
57  class MyM : public BehaviourManager
58  {
59  public:
60  // Constructors
61  MyM();
62  virtual ~MyM();
63 
64  // Child layers
65  RosIL* IL;
66  MyL1* L1;
67  MyL2* L2;
68 
69  // Function overrides
70  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); initCheckSum = 2*initCheckSum + 1; return RET_OK; }
71  virtual void preStepCallback() { DISPLAY(std::cout << " Pre-step callback in manager '" << name << "'" << std::endl); }
72  virtual void postStepCallback() { DISPLAY(std::cout << " Post-step callback in manager '" << name << "'" << std::endl); }
73 
74  // Error notification function
75  virtual void reportErrorUser(const std::string& msg, bool fatal, const std::string& funcName, const std::string& fileName, int line);
76 
77  // Test variables
78  long long initCheckSum;
79  };
80 
81  //
82  // RosIL layer
83  //
84 
85  // RosIL class
86  class RosIL : public BehaviourLayer
87  {
88  public:
89  // Constructors
90  RosIL(MyM* M);
91  virtual ~RosIL();
92 
93  // Parent manager
94  MyM* const M;
95 
96  // Sensor and actuator managers
97  RosILSM* SM;
98  RosILAM* AM;
99 
100  // Function overrides
101  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); M->initCheckSum = 13*M->initCheckSum + 1; return RET_OK; }
102  virtual void update() { DISPLAY(std::cout << " User-updating layer '" << name << "'" << std::endl); }
103  virtual void postExecuteCallback() { DISPLAY(std::cout << " Post-executing layer '" << name << "'" << std::endl); }
104  };
105 
106  // RosILSM class
107  class RosILSM : public SensorManager
108  {
109  public:
110  // Constructors
111  RosILSM(RosIL* L);
112 
113  // Parent layer and manager
114  RosIL* const L;
115  MyM* const M;
116 
117  // RosIL sensors (the data values read internally from these sensors are published on ROS topics)
118  SensorInt mode;
119  SensorLong count;
120  SensorULong target;
121 
122  // Function overrides
123  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << LBase->name << "SM" << std::endl); M->initCheckSum = 14*M->initCheckSum + 1; return RET_OK; }
124  virtual void writeExternalData();
125  };
126 
127  // RosILAM class
128  class RosILAM : public ActuatorManager
129  {
130  public:
131  // Constructors
132  RosILAM(RosIL* L);
133 
134  // Parent layer and manager
135  RosIL* const L;
136  MyM* const M;
137 
138  // RosIL actuators (the data values read from ROS topics are published internally by these actuators)
139  ActuatorInt mode;
140  ActuatorFloat targetX;
141  ActuatorFloat targetY;
142 
143  // Function overrides
144  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << LBase->name << "AM" << std::endl); M->initCheckSum = 15*M->initCheckSum + 1; return RET_OK; }
145  virtual void readExternalData();
146  };
147 
148  //
149  // MyL1 layer
150  //
151 
152  // MyL1 class
153  class MyL1 : public BehaviourLayer
154  {
155  public:
156  // Constructors
157  MyL1(MyM* M);
158  virtual ~MyL1();
159 
160  // Parent manager
161  MyM* const M;
162 
163  // Child behaviours
164  MyB1* B1;
165  MyB2* B2;
166 
167  // Sensor and actuator managers
168  MyL1SM* SM;
169  MyL1AM* AM;
170 
171  // Function overrides
172  virtual ret_t init();
173  virtual void update() { DISPLAY(std::cout << " User-updating layer '" << name << "'" << std::endl); }
174  virtual void postExecuteCallback() { DISPLAY(std::cout << " Post-executing layer '" << name << "'" << std::endl); }
175  };
176 
177  // MyL1SM class
178  class MyL1SM : public SensorManager
179  {
180  public:
181  // Constructors
182  MyL1SM(MyL1* L);
183 
184  // Parent layer and manager
185  MyL1* const L;
186  MyM* const M;
187 
188  // MyL1 sensors
189  SensorInt mode;
190  SensorFloat targetX;
191  SensorFloat targetY;
192 
193  // Function overrides
194  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << LBase->name << "SM" << std::endl); M->initCheckSum = 9*M->initCheckSum + 1; return RET_OK; }
195  };
196 
197  // MyL1AM class
198  class MyL1AM : public ActuatorManager
199  {
200  public:
201  // Constructors
202  MyL1AM(MyL1* L);
203 
204  // Parent layer and manager
205  MyL1* const L;
206  MyM* const M;
207 
208  // MyL1 actuators
209  ActuatorBool mode;
210  ActuatorInt xgoal;
211  ActuatorDouble vgoal;
212 
213  // Function overrides
214  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << LBase->name << "AM" << std::endl); M->initCheckSum = 10*M->initCheckSum + 1; return RET_OK; }
215  };
216 
217  // MyB1 class
218  class MyB1 : public Behaviour
219  {
220  public:
221  // Constructors
222  MyB1(MyL1* L) : Behaviour(L, "MyB1") , L(L), M(L->M), SM(L->SM), AM(L->AM) {}
223 
224  // Parent layer and manager
225  MyL1* const L;
226  MyM* const M;
227 
228  // Sensor and actuator managers
229  MyL1SM* const SM;
230  MyL1AM* const AM;
231 
232  // Function overrides
233  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); M->initCheckSum = 4*M->initCheckSum + 1; return RET_OK; }
234  virtual void update() { DISPLAY(std::cout << " User-updating behaviour '" << name << "'" << std::endl); }
235  virtual level_t computeActivationLevel() { return 0.6F; }
236  virtual void execute() { AM->vgoal.write(SM->targetX.read() + 5.0, this); AM->xgoal.write(SM->mode.read() + 3, this); DISPLAY(std::cout << " Executing behaviour '" << name << "'" << std::endl); }
237  };
238 
239  // MyB2 class
240  class MyB2 : public Behaviour
241  {
242  public:
243  // Constructors
244  MyB2(MyL1* L) : Behaviour(L, "MyB2") , L(L), M(L->M), SM(L->SM), AM(L->AM) {}
245 
246  // Parent layer and manager
247  MyL1* const L;
248  MyM* const M;
249 
250  // Sensor and actuator managers
251  MyL1SM* const SM;
252  MyL1AM* const AM;
253 
254  // Function overrides
255  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); M->initCheckSum = 5*M->initCheckSum + 1; return RET_OK; }
256  virtual void update() { DISPLAY(std::cout << " User-updating behaviour '" << name << "'" << std::endl); }
257  virtual level_t computeActivationLevel() { return 0.9F; }
258  virtual void execute() { AM->vgoal.write(SM->targetX.read() + 10.0, this); AM->xgoal.write(SM->mode.read() - 7, this); DISPLAY(std::cout << " Executing behaviour '" << name << "'" << std::endl); }
259  };
260 
261  //
262  // MyL2 layer
263  //
264 
265  // MyL2 class
266  class MyL2 : public BehaviourLayer
267  {
268  public:
269  // Constructors
270  MyL2(MyM* M);
271  virtual ~MyL2();
272 
273  // Parent manager
274  MyM* const M;
275 
276  // Child behaviours
277  MyB3* B3;
278  MyB4* B4;
279 
280  // Sensor and actuator managers
281  MyL2SM* SM;
282  MyL2AM* AM;
283 
284  // Function overrides
285  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); M->initCheckSum = 6*M->initCheckSum + 1; return RET_OK; }
286  virtual void update() { DISPLAY(std::cout << " User-updating layer '" << name << "'" << std::endl); }
287  virtual void postExecuteCallback() { DISPLAY(std::cout << " Post-executing layer '" << name << "'" << std::endl); }
288  };
289 
290  // MyL2SM class
291  class MyL2SM : public SensorManager
292  {
293  public:
294  // Constructors
295  MyL2SM(MyL2* L);
296 
297  // Parent layer and manager
298  MyL2* const L;
299  MyM* const M;
300 
301  // MyL2 sensors
302  SensorBool mode;
303  SensorInt xgoal;
304  SensorDouble vgoal;
305 
306  // Function overrides
307  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << LBase->name << "SM" << std::endl); M->initCheckSum = 11*M->initCheckSum + 1; return RET_OK; }
308  };
309 
310  // MyL2AM class
311  class MyL2AM : public ActuatorManager
312  {
313  public:
314  // Constructors
315  MyL2AM(MyL2* L);
316 
317  // Parent layer and manager
318  MyL2* const L;
319  MyM* const M;
320 
321  // MyL2 actuators
322  ActuatorInt mode;
323  ActuatorLong count;
324  ActuatorULong target;
325 
326  // Function overrides
327  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << LBase->name << "AM" << std::endl); M->initCheckSum = 12*M->initCheckSum + 1; return RET_OK; }
328  };
329 
330  // MyB3 class
331  class MyB3 : public Behaviour
332  {
333  public:
334  // Constructors
335  MyB3(MyL2* L) : Behaviour(L, "MyB3") , L(L), M(L->M), SM(L->SM), AM(L->AM) {}
336 
337  // Parent layer and manager
338  MyL2* const L;
339  MyM* const M;
340 
341  // Sensor and actuator managers
342  MyL2SM* const SM;
343  MyL2AM* const AM;
344 
345  // Function overrides
346  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); M->initCheckSum = 7*M->initCheckSum + 1; return RET_OK; }
347  virtual void update() { DISPLAY(std::cout << " User-updating behaviour '" << name << "'" << std::endl); }
348  virtual level_t computeActivationLevel() { return 0.3F; }
349  virtual void execute() { AM->mode.write(SM->mode.read(), this); AM->count.write(SM->xgoal.read()*2, this); AM->target.write(SM->xgoal.read() + 323, this); DISPLAY(std::cout << " Executing behaviour '" << name << "'" << std::endl); }
350  };
351 
352  // MyB4 class
353  class MyB4 : public Behaviour
354  {
355  public:
356  // Constructors
357  MyB4(MyL2* L) : Behaviour(L, "MyB4") , L(L), M(L->M), SM(L->SM), AM(L->AM) {}
358 
359  // Parent layer and manager
360  MyL2* const L;
361  MyM* const M;
362 
363  // Sensor and actuator managers
364  MyL2SM* const SM;
365  MyL2AM* const AM;
366 
367  // Function overrides
368  virtual ret_t init() { DISPLAY(std::cout << " Initialising class " << name << std::endl); M->initCheckSum = 8*M->initCheckSum + 1; return RET_OK; }
369  virtual void update() { DISPLAY(std::cout << " User-updating behaviour '" << name << "'" << std::endl); }
370  virtual level_t computeActivationLevel() { return 0.1F; }
371  virtual void execute() { AM->count.write(SM->xgoal.read()*4, this); AM->target.write(SM->xgoal.read() + 176, this); DISPLAY(std::cout << " Executing behaviour '" << name << "'" << std::endl); }
372  };
373 }
374 
375 #endif /* TEST_BEHAVIOUR_CONTROL_H */
376 // EOF
Implements a single behaviour.
Definition: behaviour.h:26
int ret_t
Used to represent an error code/function return value.
Definition: behaviour_common.h:142
Implements a single behaviour layer.
Definition: behaviour_layer.h:26
Signals successful execution of a function, with no error conditions encountered. ...
Definition: behaviour_common.h:69
Implements a manager of a particular group of actuators.
Definition: behaviour_actuators.h:26
Implements the Behaviour Control Framework.
Implements a single behaviour manager.
Definition: behaviour_manager.h:27
Implements a manager of a particular group of sensors.
Definition: behaviour_sensors.h:26
float level_t
Used to represent an activation level (raw activation levels should always be in the range [0...
Definition: behaviour_common.h:141