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

@ -16,6 +16,4 @@ public:
~Input();
Mat readFile(String filePath);
Mat readWebcam();
};
};

View File

@ -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";
}

17
lfr.cpp
View File

@ -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<void> 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;
}

5
lfr.h
View File

@ -5,6 +5,7 @@
#include <control_module.h>
#include <interpreter.h>
#include <intersection_handler.h>
#include <future>
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<void> startLoop();
void endLoop();