diff --git a/Input/input.h b/Input/input.h index c0211c9..888ba60 100644 --- a/Input/input.h +++ b/Input/input.h @@ -16,6 +16,4 @@ public: ~Input(); Mat readFile(String filePath); Mat readWebcam(); -}; - - +}; \ No newline at end of file diff --git a/autonomous_mode_main.cpp b/autonomous_mode_main.cpp index 92a29b2..5760d0e 100644 --- a/autonomous_mode_main.cpp +++ b/autonomous_mode_main.cpp @@ -1,9 +1,11 @@ #include "lfr.h" - + int main(void) { - //Mat image1 = input.readFile("C:\\Line-Following-Robot\\Test_data\\*.jpeg"); - LFR lfr; + //todo: Future will block leaving the scope of startLoop(). You will have to think of a way to break the loop properly. lfr.startLoop(); + std::cout<<"AutonomousMode: Loop started\n"; + lfr.endLoop(); + std::cout<<"AutonomousMode: Loop ended\n"; } \ No newline at end of file diff --git a/lfr.cpp b/lfr.cpp index 655ef0b..05ca96a 100644 --- a/lfr.cpp +++ b/lfr.cpp @@ -8,12 +8,14 @@ LFR::LFR() : iAmLooping(false), input(), processing(), controlModule(), interpre LFR::~LFR() { - + if(iAmLooping) + { + this->endLoop(); + } } void LFR::loop() { - //Give it 10 loops while async processing is not supported. //while(iAmLooping) for(int i = 0; i < 3; i++) { @@ -22,15 +24,18 @@ void LFR::loop() imshow("Display window", image); waitKey(0); } - iAmLooping = false; } -void LFR::startLoop() +std::future LFR::startLoop() { - this->loop(); + iAmLooping = true; + std::cout<<"Loop start\n"; + return std::async(&LFR::loop, this); } void LFR::endLoop() { - std::cout<<"The loop has been started. You may not dare to tell it to stop."; + iAmLooping = false; + std::cout<<"loop ende\n"; + return; } \ No newline at end of file diff --git a/lfr.h b/lfr.h index 69483fa..0471bd1 100644 --- a/lfr.h +++ b/lfr.h @@ -5,6 +5,7 @@ #include #include #include +#include using namespace cv; @@ -15,7 +16,7 @@ class LFR ControlModule controlModule; Interpreter interpreter; IntersectionHandler intersectionHandler; - bool iAmLooping; + volatile bool iAmLooping; void loop(); public: @@ -23,7 +24,7 @@ public: LFR(); ~LFR(); - void startLoop(); + std::future startLoop(); void endLoop();