Press enter to stop the infinite while loop

This commit is contained in:
ackimixs
2024-01-19 17:24:01 +01:00
parent c64a19fa74
commit 4e1d9d4255
3 changed files with 32 additions and 1 deletions

View File

@@ -1,5 +1,18 @@
#include "utils/ArucoDetector.h"
#include <iostream>
#include <thread>
#include <atomic>
std::atomic<bool> stopRequested(false);
void userInputThread() {
// Wait for the user to press Enter
std::cout << "Press Enter to stop the program..." << std::endl;
std::cin.ignore();
stopRequested = true;
}
int main(int argc, char *argv[])
{
// Settup argument parser
@@ -32,6 +45,8 @@ int main(int argc, char *argv[])
// End argument parser
std::thread userInput(userInputThread);
const auto robotPose = Type::RobotPose{cv::Point3f(0, 0, 0), CV_PI/2};
ArucoDetector detector(robotPose, calibrationPath, BLUE, cameraId, headless);
@@ -60,7 +75,15 @@ int main(int argc, char *argv[])
ArucoDetector::solarPanelDetector(p.first, p.second.first, p.second.first, robotPose);
}
}
if (stopRequested)
{
break;
}
}
// Wait for the user input thread to finish
userInput.join();
return 0;
}