int main(int argc, char **argv) { LibLogger::init(); Logger* logger = new ConsoleLogger(); signal(SIGINT, signal_handler); LocalBlackBoard *lbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE); BlackBoard* bb = lbb; Opi* own; vector<Opi*> foreign; Opi* output; try { cout << "Opening interfaces.. " << flush; own = bb->open_for_writing<Opi>("OmniBall"); for (int i = 1; i <= 5; i++) { stringstream stream; stream << "WM Ball "; stream << i; string id = stream.str(); Opi* opi = bb->open_for_writing<Opi>(id.c_str()); foreign.push_back(opi); } output = bb->open_for_reading<Opi>("WM Ball"); cout << "done" << endl; } catch (Exception &e) { cout << "failed! Aborting" << endl; e.print_trace(); exit(1); } test1(logger, bb, own, foreign, output); test2(logger, bb, own, foreign, output); test3(logger, bb, own, foreign, output); cout << "Closing interfaces.. " << flush; bb->close(own); for (vector<Opi*>::iterator it = foreign.begin(); it != foreign.end(); ++it) { Opi* opi = *it; bb->close(opi); } cout << "done" << endl; cout << "Deleting blackboard.. " << flush; delete bb; cout << "done" << endl; cout << "Finalizing logger.. " << flush; LibLogger::finalize(); cout << "done" << endl; }
int main(int argc, char** argv) { //initialization and calibration of new blackBoard BlackBoard* blackBoard = new BlackBoard(); blackBoard->Init(); PathFinder* allRed = new PathFinderAllRed(blackBoard); PathFinder* maxSquare = new PathFinderMaxSquare(blackBoard); PathFinder* fitLine = new PathFinderFitLine(blackBoard); blackBoard->desktopDrawer->setPathFinder(allRed); cout << "Ovladanie:\n"; cout << "ESC quit\n"; cout << "c clear desktop\n"; cout << "1 PathFinderAllRed\n"; cout << "2 PathFinderMaxSquare\n"; cout << "3 PathFinderFitLine\n"; //update desktop view bool run = 1; while (blackBoard->update() && run) { char c = cvWaitKey(33); switch(c){ case 27: run = 0; break; //ESC case 'c': blackBoard->desktopDrawer->clear(); break; case '1': blackBoard->desktopDrawer->setPathFinder(allRed); break; case '2': blackBoard->desktopDrawer->setPathFinder(maxSquare); break; case '3': blackBoard->desktopDrawer->setPathFinder(fitLine); break; } } delete blackBoard; delete allRed; delete maxSquare; delete fitLine; return 0; }
void try_localize(const std::string &host, unsigned short int port, std::string &interface_id, std::string frame, double translation[3], double rotation[4], double covariance[36]) { FawkesNetworkClient *c = new FawkesNetworkClient(host.c_str(), port); c->connect(); if (frame == "") { NetworkConfiguration *netconf = NULL; try { netconf = new NetworkConfiguration(c); frame = netconf->get_string("/frames/fixed"); } catch (Exception &e) { printf("WARNING: no frame set and failed to get frame from remote.\n"); e.print_trace(); } delete netconf; } BlackBoard *bb = new RemoteBlackBoard(c); LocalizationInterface *loc_if = bb->open_for_reading<LocalizationInterface>(interface_id.c_str()); if (! loc_if->has_writer()) { bb->close(loc_if); delete bb; throw Exception("No writer for interface %s, aborting", loc_if->uid()); } LocalizationInterface::SetInitialPoseMessage *ipm = new LocalizationInterface::SetInitialPoseMessage(); ipm->set_frame(frame.c_str()); ipm->set_translation(translation); ipm->set_rotation(rotation); ipm->set_covariance(covariance); loc_if->msgq_enqueue(ipm); // allow for some time so message is actually sent usleep(500000); bb->close(loc_if); delete bb; delete c; }
int main(int argc, char **argv) { LibLogger::init(); Thread::init_main(); //RemoteBlackBoard *bb = new RemoteBlackBoard("localhost", 1910); BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE); QaBBEventListener qabbel; TestInterface *ti_writer_1; TestInterface *ti_writer_2; TestInterface *ti_writer_3; TestInterface *ti_writer_4; TestInterface *ti_writer_5; TestInterface *ti_writer_6; TestInterface *ti_reader_1; TestInterface *ti_reader_2; try { cout << "Opening interfaces.. (SomeID *)" << endl; ti_writer_1 = bb->open_for_writing<TestInterface>("SomeID 1"); ti_reader_1 = bb->open_for_reading<TestInterface>("SomeID 1"); ti_writer_2 = bb->open_for_writing<TestInterface>("SomeID 2"); ti_reader_2 = bb->open_for_reading<TestInterface>("SomeID reader 1"); qabbel.add_interface(ti_writer_1); qabbel.add_interface(ti_writer_2); qabbel.add_interface(ti_reader_2); bb->register_listener(&qabbel, BlackBoard::BBIL_FLAG_ALL); bb->register_observer(&qabbel, BlackBoard::BBIO_FLAG_ALL); cout << "Opening interfaces.. (SomeID 3, should NOT trigger BBIO)" << endl; ti_writer_3 = bb->open_for_writing<TestInterface>("SomeID 3"); cout << "Opening interfaces.. (AnotherID *, SHOULD trigger BBIO)" << endl; ti_writer_4 = bb->open_for_writing<TestInterface>("AnotherID 1"); ti_writer_5 = bb->open_for_writing<TestInterface>("AnotherID 2"); ti_writer_6 = bb->open_for_writing<TestInterface>("AnotherID 3"); cout << "success" << endl; } catch (Exception &e) { cout << "failed! Aborting" << endl; e.print_trace(); exit(1); } usleep(100000); std::list<TestInterface *> readers = bb->open_multiple_for_reading<TestInterface>(); usleep(100000); for (std::list<TestInterface *>::iterator i = readers.begin(); i != readers.end(); ++i) { printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type()); bb->close(*i); } usleep(100000); const char* pattern = "AnotherID *"; readers = bb->open_multiple_for_reading<TestInterface>(pattern); printf("Found %zu interfaces with pattern \"%s\"\n", readers.size(), pattern); for (std::list<TestInterface *>::iterator i = readers.begin(); i != readers.end(); ++i) { printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type()); bb->close(*i); } usleep(100000); printf("Sending a message to test message received event\n"); TestInterface::SetTestIntMessage *m = new TestInterface::SetTestIntMessage(27); unsigned int msg_id = ti_reader_1->msgq_enqueue(m); printf("Message ID = %u, enqueued messages: %u\n", msg_id, ti_writer_1->msgq_size()); printf("Removing writer 1. No BBIL output should appear\n"); bb->close(ti_writer_1); bb->unregister_listener(&qabbel); usleep(100000); printf("Removing other writers. No warning should appear.\n"); bb->close(ti_writer_2); bb->close(ti_writer_3); bb->close(ti_writer_4); bb->close(ti_writer_5); bb->close(ti_writer_6); bb->close(ti_reader_1); bb->close(ti_reader_2); usleep(100000); delete bb; Thread::destroy_main(); LibLogger::finalize(); }
int main(int argc, char **argv) { signal(SIGINT, signal_handler); LocalBlackBoard *lbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE); BlackBoard *bb = lbb; TestInterface *ti_writer; TestInterface *ti_reader; try { cout << "Opening interfaces.. " << flush; ti_writer = bb->open_for_writing<TestInterface>("SomeID"); ti_reader = bb->open_for_reading<TestInterface>("SomeID"); cout << "success, " << "writer hash=" << ti_writer->hash_printable() << " reader hash=" << ti_reader->hash_printable() << endl; } catch (Exception &e) { cout << "failed! Aborting" << endl; e.print_trace(); exit(1); } cout << endl << endl << "Running data tests ==================================================" << endl; cout << "Writing initial value (" << TestInterface::TEST_CONSTANT << ") into interface as TestInt" << endl; ti_writer->set_test_int(TestInterface::TEST_CONSTANT); try { ti_writer->write(); } catch (InterfaceWriteDeniedException &e) { cout << "BUG: caught write denied exception" << endl; e.print_trace(); } cout << "Reading value from reader interface.. " << flush; ti_reader->read(); int val = ti_reader->test_int(); if (val == TestInterface::TEST_CONSTANT) { cout << " success, value is " << ti_reader->test_int() << " as expected" << endl; } else { cout << " failure, value is " << ti_reader->test_int() << ", expected " << TestInterface::TEST_CONSTANT << endl; } cout << "Resizing buffer.. " << flush; try { ti_reader->resize_buffers(1); ti_reader->copy_private_to_buffer(0); } catch (Exception &e) { cout << "ERROR: Resizing failed, exception follows" << endl; e.print_trace(); throw; } cout << "Testing buffers, use Ctrl-C to interrupt" << endl << "If you do not see any output everything is fine" << endl; while (!quit) { //cout << "Writing value " << expval // << " into interface as TestInt" << endl; ti_writer->set_test_int(ti_writer->test_int() + 1); try { ti_writer->write(); } catch (InterfaceWriteDeniedException &e) { cout << "BUG: caught write denied exception" << endl; e.print_trace(); } //cout << "Reading value from reader interface.. " << flush; ti_reader->read(); int rval = ti_reader->test_int(); int wval = ti_writer->test_int(); ti_reader->read_from_buffer(0); int bval = ti_reader->test_int(); if (rval != wval) { cout << " failure, reader value is " << rval << ", writer has " << wval << endl; } if (rval != bval + 1) { cout << " failure, reader value is " << rval << ", buffer has " << bval << endl; } // could to copy_shared as well, but that is a little less predictable in // the case of concurrent writers, hence we want people to copy and paste // this version. ti_reader->read(); ti_reader->copy_private_to_buffer(0); usleep(10); } cout << "Tests done" << endl; bb->close(ti_reader); bb->close(ti_writer); delete bb; }
int main(int argc, char **argv) { signal(SIGINT, signal_handler); LocalBlackBoard *llbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE); BlackBoard *lbb = llbb; FawkesNetworkServerThread *fns = new FawkesNetworkServerThread(1910); fns->start(); llbb->start_nethandler(fns); BlackBoard *rbb = new RemoteBlackBoard("localhost", 1910); InterfaceInfoList *infl = rbb->list_all(); for (InterfaceInfoList::iterator i = infl->begin(); i != infl->end(); ++i) { const unsigned char *hash = (*i).hash(); char phash[__INTERFACE_HASH_SIZE * 2 + 1]; memset(phash, 0, sizeof(phash)); for (unsigned int j = 0; j < __INTERFACE_HASH_SIZE; ++j) { sprintf(&phash[j * 2], "%02x", hash[j]); } printf("%s::%s (%s), w:%i r:%u s:%u\n", (*i).type(), (*i).id(), phash, (*i).has_writer(), (*i).num_readers(), (*i).serial()); } delete infl; //TestInterface *ti_writer; TestInterface *ti_reader; TestInterface *ti_writer; try { cout << "Opening interfaces.. " << flush; ti_writer = rbb->open_for_writing<TestInterface>("SomeID"); ti_reader = rbb->open_for_reading<TestInterface>("SomeID"); cout << "success, " << "writer hash=" << ti_writer->hash_printable() << " reader hash=" << ti_reader->hash_printable() << endl; } catch (Exception &e) { cout << "failed! Aborting" << endl; e.print_trace(); exit(1); } try { cout << "Trying to open second writer.. " << flush; TestInterface *ti_writer_two; ti_writer_two = rbb->open_for_writing<TestInterface>("SomeID"); cout << "BUG: Detection of second writer did NOT work!" << endl; exit(2); } catch (BlackBoardWriterActiveException &e) { cout << "exception caught as expected, detected and prevented second writer!" << endl; } try { cout << "Trying to open third writer.. " << flush; TestInterface *ti_writer_three; ti_writer_three = rbb->open_for_writing<TestInterface>("AnotherID"); cout << "No exception as expected, different ID ok!" << endl; rbb->close(ti_writer_three); } catch (BlackBoardWriterActiveException &e) { cout << "BUG: Third writer with different ID detected as another writer!" << endl; exit(3); } cout << endl << endl << "Running data tests ==================================================" << endl; cout << "Writing initial value (" << TestInterface::TEST_CONSTANT << ") into interface as TestInt" << endl; ti_writer->set_test_int( TestInterface::TEST_CONSTANT ); try { ti_writer->write(); } catch (InterfaceWriteDeniedException &e) { cout << "BUG: caught write denied exception" << endl; e.print_trace(); } cout << "Giving some time to have value processed" << endl; usleep(100000); cout << "Reading value from reader interface.. " << flush; ti_reader->read(); int val = ti_reader->test_int(); if ( val == TestInterface::TEST_CONSTANT ) { cout << " success, value is " << ti_reader->test_int() << " as expected" << endl; } else { cout << " failure, value is " << ti_reader->test_int() << ", expected " << TestInterface::TEST_CONSTANT << endl; } cout << "Closing interfaces.. " << flush; try { rbb->close(ti_reader); rbb->close(ti_writer); cout << "done" << endl; } catch (Exception &e) { cout << "failed" << endl; e.print_trace(); } cout << endl << endl << "Starting MESSAGING tests" << endl << "Press Ctrl-C to continue with next test" << endl << endl; ti_writer = lbb->open_for_writing<TestInterface>("Messaging"); ti_reader = rbb->open_for_reading<TestInterface>("Messaging"); printf("Writer serial: %u shifted: %u\n", ti_writer->serial(), ti_writer->serial() << 16); printf("Reader serial: %u shifted: %u\n", ti_reader->serial(), ti_reader->serial() << 16); test_messaging(ti_reader, ti_writer); rbb->close(ti_reader); lbb->close(ti_writer); cout << endl << endl << "Starting MESSAGING tests, doing repeater scenario" << endl << "Press Ctrl-C to continue with next test" << endl << endl; quit = false; delete rbb; LocalBlackBoard *repllbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE); FawkesNetworkServerThread *repfns = new FawkesNetworkServerThread(1911); repfns->start(); repllbb->start_nethandler(repfns); BlackBoard *rep_rbb = new RemoteBlackBoard("localhost", 1911); rbb = new RemoteBlackBoard("localhost", 1911); TestInterface *rep_reader; TestInterface *rep_writer; ti_writer = rbb->open_for_writing<TestInterface>("Messaging"); ti_reader = lbb->open_for_reading<TestInterface>("Messaging"); rep_reader = rep_rbb->open_for_reading<TestInterface>("Messaging"); rep_writer = lbb->open_for_writing<TestInterface>("Messaging"); printf("Writer serial: %u shifted: %u\n", ti_writer->serial(), ti_writer->serial() << 16); printf("Reader serial: %u shifted: %u\n", ti_reader->serial(), ti_reader->serial() << 16); SyncInterfaceListener *sil = new SyncInterfaceListener(rep_reader, rep_writer, rep_rbb, lbb); test_messaging(ti_reader, ti_writer); delete sil; lbb->close(ti_reader); rbb->close(ti_writer); rep_rbb->close(rep_reader); lbb->close(rep_writer); delete repllbb; delete rep_rbb; cout << "Tests done" << endl; delete rbb; delete llbb; delete fns; }