/* * This Software is the original work of Daniel TUNG * This Software is submitted in partial fulfillment of the * requirements for the degree of BCSE. * Dept. Computer Science, Monash University 2000 * * Copyright (c) 2000 beetung@cs.monash.edu.au * beetung@geocities.com */ #ifndef NAVBRAIN #define NAVBRAIN #include "car.h" #include "streamer.h" #include "xwin.h" #include "fastbuf.h" //// //// //// //// ///////////////////////////////////////////////// class NavBrain { ///////////////////////////////////////////////// private: Car& aCar; Streamer& aStreamer; Xwin& aXwin; Fastbuf *iCCD; public: //------------------------------------------- NavBrain(Car& c, Streamer& s, Xwin& x) : aCar(c), aStreamer(s), aXwin(x) //------------------------------------------- { Timer dt; dt.start(); int centerPrev =-1; // until our Xwindow is closed // while (aXwin) { if (! aXwin.isSettingNode ) { iCCD = aStreamer.grab1Frame(); // obtain 1 frame // aStreamer.isReady(); // block till ready aXwin.setBaseFrame(iCCD); // set the baseFrame to current buffer iCCD->swimNodes(); // allow nodes to swim iCCD->drawNodes(); // draw onto the buffer space { int a;cin >> a; } int center =iCCD->getNodeCenter(); // get the center X position { int a;cin >> a; } aXwin.setBaseFrame(iCCD); // set the baseFrame to current buffer { int a;cin >> a; } aXwin.drawBaseFrame(); // draw it on screen { int a;cin >> a; } aXwin.markPoint( 120, center , 0xff0000); // aCar.steerOn( iCCD->nodesAverage() ); // #define WAIT_TIME (0.67) if ( center != 0 ) { // no center found, no nodes initialized yet? if (dt > WAIT_TIME) { dt.reset(); #define WINSIZE (50) if ( center < 128 + WINSIZE) { // go left cout << " go left : " <
256 -WINSIZE) { // go right cout << " go right : " <
WAIT_TIME) { cout << "no center yet : " << center << endl; centerPrev = center; dt.reset(); aCar.steerOn( CarOp::HALT); dt.start(); cout.flush(); } } } else { Timer t(0.5); // zzz for 500 mSec t.block(); } } } }; #endif