Started working on parallel execution

This commit is contained in:
Tim Zeuner 2022-11-03 11:18:18 +01:00
parent 36b65fdf07
commit 68416a8a9a
4 changed files with 20 additions and 14 deletions

View File

@ -17,5 +17,3 @@ public:
Mat readFile(String filePath); Mat readFile(String filePath);
Mat readWebcam(); Mat readWebcam();
}; };

View File

@ -2,8 +2,10 @@
int main(void) int main(void)
{ {
//Mat image1 = input.readFile("C:\\Line-Following-Robot\\Test_data\\*.jpeg");
LFR lfr; 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(); lfr.startLoop();
std::cout<<"AutonomousMode: Loop started\n";
lfr.endLoop();
std::cout<<"AutonomousMode: Loop ended\n";
} }

17
lfr.cpp
View File

@ -8,12 +8,14 @@ LFR::LFR() : iAmLooping(false), input(), processing(), controlModule(), interpre
LFR::~LFR() LFR::~LFR()
{ {
if(iAmLooping)
{
this->endLoop();
}
} }
void LFR::loop() void LFR::loop()
{ {
//Give it 10 loops while async processing is not supported.
//while(iAmLooping) //while(iAmLooping)
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
@ -22,15 +24,18 @@ void LFR::loop()
imshow("Display window", image); imshow("Display window", image);
waitKey(0); waitKey(0);
} }
iAmLooping = false;
} }
void LFR::startLoop() std::future<void> LFR::startLoop()
{ {
this->loop(); iAmLooping = true;
std::cout<<"Loop start\n";
return std::async(&LFR::loop, this);
} }
void LFR::endLoop() 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;
} }

5
lfr.h
View File

@ -5,6 +5,7 @@
#include <control_module.h> #include <control_module.h>
#include <interpreter.h> #include <interpreter.h>
#include <intersection_handler.h> #include <intersection_handler.h>
#include <future>
using namespace cv; using namespace cv;
@ -15,7 +16,7 @@ class LFR
ControlModule controlModule; ControlModule controlModule;
Interpreter interpreter; Interpreter interpreter;
IntersectionHandler intersectionHandler; IntersectionHandler intersectionHandler;
bool iAmLooping; volatile bool iAmLooping;
void loop(); void loop();
public: public:
@ -23,7 +24,7 @@ public:
LFR(); LFR();
~LFR(); ~LFR();
void startLoop(); std::future<void> startLoop();
void endLoop(); void endLoop();