Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
ArucoGenerateTagsThreaded Class Reference

This class inherits the AutonomyThread interface and implements the threaded container methods. It also utilizes the ability to create a thread pool of subroutines and the ability to parallelize loops. More...

#include <ArucoGenerateTags.hpp>

Inheritance diagram for ArucoGenerateTagsThreaded:
Collaboration diagram for ArucoGenerateTagsThreaded:

Public Member Functions

void SetNumTagsToGenerate (const int nNumTags)
 Mutator for the Num Tags To Generate private member. Given number must not exceed the dictionary type limit.
 
void AddTagDictionaryType (const cv::aruco::PredefinedDictionaryType eDictionary)
 Mutator for the Tag Dictionary Type private member.
 
- Public Member Functions inherited from AutonomyThread< void >
 AutonomyThread ()
 Construct a new Autonomy Thread object.
 
virtual ~AutonomyThread ()
 Destroy the Autonomy Thread object. If the parent object or main thread is destroyed or exited while this thread is still running, a race condition will occur. Stopping and joining the thread here insures that the main program can't exit if the user forgot to stop and join the thread.
 
void Start ()
 When this method is called, it starts a new thread that runs the code within the ThreadedContinuousCode method. This is the users main code that will run the important and continuous code for the class.
 
void RequestStop ()
 Signals threads to stop executing user code, terminate. DOES NOT JOIN. This method will not force the thread to exit, if the user code is not written properly and contains WHILE statement or any other long-executing or blocking code, then the thread will not exit until the next iteration.
 
void Join ()
 Waits for thread to finish executing and then closes thread. This method will block the calling code until thread is finished.
 
bool Joinable () const
 Check if the code within the thread and all pools created by it are finished executing and the thread is ready to be closed.
 
AutonomyThreadState GetThreadState () const
 Accessor for the Threads State private member.
 
IPSGetIPS ()
 Accessor for the Frame I P S private member.
 

Private Member Functions

void ThreadedContinuousCode () override
 This code will run in a separate thread. This is the main code.
 
void PooledLinearCode () override
 Any highly parallelizable code that can be used in the main thread goes here.
 

Private Attributes

int m_nNumTagsToGenerate = 0
 
std::vector< cv::aruco::PredefinedDictionaryTypem_vDictionaries
 
std::mutex m_muDictMutex
 

Additional Inherited Members

- Public Types inherited from AutonomyThread< void >
enum  AutonomyThreadState
 
- Protected Member Functions inherited from AutonomyThread< void >
void RunPool (const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
 When this method is called, it starts/adds tasks to a thread pool that runs nNumTasksToQueue copies of the code within the PooledLinearCode() method using nNumThreads number of threads. This is meant to be used as an internal utility of the child class to further improve parallelization. Default value for nNumThreads is 2.
 
void RunDetachedPool (const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
 When this method is called, it starts a thread pool full of threads that don't return std::futures (like a placeholder for the thread return type). This means the thread will not have a return type and there is no way to determine if the thread has finished other than calling the Join() method. Only use this if you want to 'set and forget'. It will be faster as it doesn't return futures. Runs PooledLinearCode() method code. This is meant to be used as an internal utility of the child class to further improve parallelization.
 
void ParallelizeLoop (const int nNumThreads, const N tTotalIterations, F &&tLoopFunction)
 Given a ref-qualified looping function and an arbitrary number of iterations, this method will divide up the loop and run each section in a thread pool. This function must not return anything. This method will block until the loop has completed.
 
void ClearPoolQueue ()
 Clears any tasks waiting to be ran in the queue, tasks currently running will remain running.
 
void JoinPool ()
 Waits for pool to finish executing tasks. This method will block the calling code until thread is finished.
 
bool PoolJoinable () const
 Check if the internal pool threads are done executing code and the queue is empty.
 
void SetMainThreadIPSLimit (int nMaxIterationsPerSecond=0)
 Mutator for the Main Thread Max I P S private member.
 
int GetPoolNumOfThreads ()
 Accessor for the Pool Num Of Threads private member.
 
int GetPoolQueueLength ()
 Accessor for the Pool Queue Size private member.
 
std::vector< void > GetPoolResults ()
 Accessor for the Pool Results private member. The action of getting results will destroy and remove them from this object. This method blocks if the thread is not finished, so no need to call JoinPool() before getting results.
 
int GetMainThreadMaxIPS () const
 Accessor for the Main Thread Max I P S private member.
 
- Protected Attributes inherited from AutonomyThread< void >
IPS m_IPS
 

Detailed Description

This class inherits the AutonomyThread interface and implements the threaded container methods. It also utilizes the ability to create a thread pool of subroutines and the ability to parallelize loops.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-27

Member Function Documentation

◆ ThreadedContinuousCode()

void ArucoGenerateTagsThreaded::ThreadedContinuousCode ( )
inlineoverrideprivatevirtual

This code will run in a separate thread. This is the main code.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-23

Implements AutonomyThread< void >.

48 {
49 // Start thread pool. Run detached since the threads aren't returning anything.
50 // This is much faster than the normal RunPool function.
51 this->RunDetachedPool(m_vDictionaries.size(), m_vDictionaries.size());
52
53 // Wait for pool tasks to finish.
54 this->JoinPool();
55
56 // Stop threaded code.
57 this->RequestStop();
58 }
void RequestStop()
Signals threads to stop executing user code, terminate. DOES NOT JOIN. This method will not force the...
Definition AutonomyThread.hpp:164
void RunDetachedPool(const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
When this method is called, it starts a thread pool full of threads that don't return std::futures (l...
Definition AutonomyThread.hpp:336
void JoinPool()
Waits for pool to finish executing tasks. This method will block the calling code until thread is fin...
Definition AutonomyThread.hpp:439
Here is the call graph for this function:

◆ PooledLinearCode()

void ArucoGenerateTagsThreaded::PooledLinearCode ( )
inlineoverrideprivatevirtual

Any highly parallelizable code that can be used in the main thread goes here.

This is not required and is only used at the users convenience.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-25

Implements AutonomyThread< void >.

71 {
72 // Acquire resource lock for dictionary vector.
73 std::unique_lock<std::mutex> lock(m_muDictMutex);
74 // Get dictionary enum from back of dictionary vector.
75 cv::aruco::PredefinedDictionaryType cvDictType = m_vDictionaries.back();
76 m_vDictionaries.pop_back();
77 // Release resource lock.
78 lock.unlock();
79
81 // Change this bool to test the two different
82 // blocks of code!
84 bool bUseParallelLoop = false;
85 if (bUseParallelLoop)
86 {
88 // This code splits the loop into parts and
89 // completes it in different threads.
91 this->ParallelizeLoop(50,
92 m_nNumTagsToGenerate,
93 [&cvDictType](const int a, const int b)
94 {
95 // Loop through and generate each of the tags.
96 for (int i = a; i < b; ++i)
97 GenerateOpenCVArucoMarker(cvDictType, i);
98 });
99 }
100 else
101 {
103 // This code linearly runs through every tag.
105 for (int i = 0; i < m_nNumTagsToGenerate; ++i)
106 {
107 GenerateOpenCVArucoMarker(cvDictType, i);
108 }
109 }
110 }
void GenerateOpenCVArucoMarker(cv::aruco::PredefinedDictionaryType eDictionary, unsigned short sMarker)
Generate an ArUco Tag.
Definition TagGenerator.hpp:25
void ParallelizeLoop(const int nNumThreads, const N tTotalIterations, F &&tLoopFunction)
Given a ref-qualified looping function and an arbitrary number of iterations, this method will divide...
Definition AutonomyThread.hpp:404
PredefinedDictionaryType
Here is the call graph for this function:

◆ SetNumTagsToGenerate()

void ArucoGenerateTagsThreaded::SetNumTagsToGenerate ( const int  nNumTags)
inline

Mutator for the Num Tags To Generate private member. Given number must not exceed the dictionary type limit.

Parameters
nNumTags- The number of tags to generate.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-23
125{ m_nNumTagsToGenerate = nNumTags; }
Here is the caller graph for this function:

◆ AddTagDictionaryType()

void ArucoGenerateTagsThreaded::AddTagDictionaryType ( const cv::aruco::PredefinedDictionaryType  eDictionary)
inline

Mutator for the Tag Dictionary Type private member.

Parameters
eDictionary- The dictionary type to use for generation.
Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-07-23
135{ m_vDictionaries.emplace_back(eDictionary); }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: