26 #include <blackboard/local.h> 27 #include <blackboard/exceptions.h> 28 #include <blackboard/bbconfig.h> 30 #include <interfaces/ObjectPositionInterface.h> 32 #include <core/exceptions/system.h> 33 #include <utils/logging/liblogger.h> 34 #include <utils/logging/logger.h> 35 #include <utils/logging/console.h> 47 #include "../fuser.cpp" 48 #include "../objpos_majority.cpp" 57 signal_handler(
int signum)
67 Opi* own,
const vector<Opi*>& foreign, Opi* output)
69 cout << endl << endl <<
"Test #1:" << endl;
79 for (vector<Opi*>::const_iterator it = foreign.begin();
80 it != foreign.end(); ++it) {
83 opi->set_flags(Opi::FLAG_HAS_WORLD);
84 opi->set_visible(
true);
87 opi->set_world_z(0.0);
98 cout <<
" Set foreign " << opi->id() <<
" world " <<
99 "(" << opi->world_x() <<
", " << opi->world_y() <<
")" << endl;
103 own->set_valid(
true);
104 own->set_flags(Opi::FLAG_HAS_WORLD
105 | Opi::FLAG_HAS_RELATIVE_CARTESIAN
106 | Opi::FLAG_HAS_RELATIVE_POLAR);
107 own->set_visible(
true);
108 own->set_world_x(2.0);
109 own->set_world_y(2.0);
110 own->set_world_z(0.0);
111 own->set_bearing(0.5);
112 own->set_distance(1.5);
113 own->set_relative_x(1.7);
114 own->set_relative_y(0.7);
116 cout <<
" Set own " << own->id() <<
" world " <<
117 "(" << own->world_x() <<
", " << own->world_y() <<
")" << endl;
121 cout <<
" Reading output interface.. " << flush;
123 cout <<
"(" << output->world_x() <<
", " << output->world_y() <<
")";
126 float expected_x = (3.2f + 3.3f + 3.4f) / 3;
127 float expected_y = (3.2f + 3.3f + 3.4f) / 3;
128 if (output->world_x() != expected_x ||
129 output->world_y() != expected_y) {
130 throw Exception(
"Should have averaged interfaces 2, 3, 4 "\
131 "(starting from 0).");
137 Opi* own,
const vector<Opi*>& foreign, Opi* output)
139 cout << endl << endl <<
"Test #2:" << endl;
149 for (vector<Opi*>::const_iterator it = foreign.begin();
150 it != foreign.end(); ++it) {
152 opi->set_valid(
true);
153 opi->set_flags(Opi::FLAG_HAS_WORLD);
154 opi->set_visible(
true);
157 opi->set_world_z(0.0);
168 cout <<
" Set foreign " << opi->id() <<
" world " <<
169 "(" << opi->world_x() <<
", " << opi->world_y() <<
")" << endl;
173 own->set_valid(
true);
174 own->set_flags(Opi::FLAG_HAS_WORLD
175 | Opi::FLAG_HAS_RELATIVE_CARTESIAN
176 | Opi::FLAG_HAS_RELATIVE_POLAR
178 own->set_visible(
true);
179 own->set_world_x(2.0);
180 own->set_world_y(2.0);
181 own->set_world_z(0.0);
182 own->set_bearing(0.5);
183 own->set_distance(1.5);
184 own->set_relative_x(1.7);
185 own->set_relative_y(0.7);
187 cout <<
" Set own " << own->id() <<
" world " <<
188 "(" << own->world_x() <<
", " << own->world_y() <<
")" << endl;
192 cout <<
" Reading output interface.. " << flush;
194 cout <<
"(" << output->world_x() <<
", " << output->world_y() <<
")";
197 if (output->world_x() != own->world_x() ||
198 output->world_y() != own->world_y()) {
199 throw Exception(
"Should have copied own interface because "\
200 "no majority was found.");
205 Opi* own,
const vector<Opi*>& foreign, Opi* output)
207 cout << endl << endl <<
"Test #3:" << endl;
217 for (vector<Opi*>::const_iterator it = foreign.begin();
218 it != foreign.end(); ++it) {
220 opi->set_valid(
true);
221 opi->set_flags(Opi::FLAG_HAS_WORLD);
222 opi->set_visible(
true);
225 opi->set_world_z(0.0);
236 cout <<
" Set foreign " << opi->id() <<
" world " <<
237 "(" << opi->world_x() <<
", " << opi->world_y() <<
")" << endl;
241 own->set_valid(
true);
242 own->set_flags(Opi::FLAG_HAS_WORLD
243 | Opi::FLAG_HAS_RELATIVE_CARTESIAN
244 | Opi::FLAG_HAS_RELATIVE_POLAR
246 own->set_visible(
true);
247 own->set_world_x(2.0);
248 own->set_world_y(2.0);
249 own->set_world_z(0.0);
250 own->set_bearing(0.5);
251 own->set_distance(0.5);
252 own->set_relative_x(0.7);
253 own->set_relative_y(0.7);
255 cout <<
" Set own " << own->id() <<
" world " <<
256 "(" << own->world_x() <<
", " << own->world_y() <<
")" << endl;
260 cout <<
" Reading output interface.. " << flush;
262 cout <<
"(" << output->world_x() <<
", " << output->world_y() <<
")";
265 if (output->world_x() != own->world_x() ||
266 output->world_y() != own->world_y()) {
267 throw Exception(
"Should have copied own interface because "\
273 main(
int argc,
char **argv)
278 signal(SIGINT, signal_handler);
286 vector<Opi*> foreign;
290 cout <<
"Opening interfaces.. " << flush;
292 for (
int i = 1; i <= 5; i++) {
294 stream <<
"WM Ball ";
296 string id = stream.str();
298 foreign.push_back(opi);
301 cout <<
"done" << endl;
303 cout <<
"failed! Aborting" << endl;
308 test1(logger, bb, own, foreign, output);
309 test2(logger, bb, own, foreign, output);
310 test3(logger, bb, own, foreign, output);
312 cout <<
"Closing interfaces.. " << flush;
314 for (vector<Opi*>::iterator it = foreign.begin();
315 it != foreign.end(); ++it) {
319 cout <<
"done" << endl;
321 cout <<
"Deleting blackboard.. " << flush;
323 cout <<
"done" << endl;
324 cout <<
"Finalizing logger.. " << flush;
325 LibLogger::finalize();
326 cout <<
"done" << endl;
ObjectPositionInterface Fawkes BlackBoard Interface.
Interface for logging to stderr.
Fawkes library namespace.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier)=0
Open interface for writing.
ObjectPositionInterface majority fuser.
Base class for exceptions in Fawkes.
void print_trace()
Prints trace to stderr.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier)=0
Open interface for reading.
The BlackBoard abstract class.
virtual void close(Interface *interface)=0
Close interface.