Browse Source

Started working on parallel execution

pull/1/head
Tim Zeuner 2 years ago
parent
commit
68416a8a9a
4 changed files with 20 additions and 14 deletions
  1. 1
    3
      Input/input.h
  2. 5
    3
      autonomous_mode_main.cpp
  3. 11
    6
      lfr.cpp
  4. 3
    2
      lfr.h

+ 1
- 3
Input/input.h View File

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


};

+ 5
- 3
autonomous_mode_main.cpp 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";
}

+ 11
- 6
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;
}

+ 3
- 2
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();



Loading…
Cancel
Save