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
Camera.hpp
Go to the documentation of this file.
1
11#ifndef CAMERA_HPP
12#define CAMERA_HPP
13
14#include "../util/vision/FetchContainers.hpp"
15#include "./AutonomyThread.hpp"
16
18#include <atomic>
19#include <future>
20#include <shared_mutex>
21
23
24
32template<class T>
33class Camera : public AutonomyThread<void>
34{
35 public:
37 // Declare public structs specific to this class.
39
40
47 struct Pose
48 {
49 public:
50 double dPosX; // Position X in meters.
51 double dPosY; // Position Y in meters.
52 double dPosZ; // Position Z in meters.
53 double dQX; // Quaternion X.
54 double dQY; // Quaternion Y.
55 double dQZ; // Quaternion Z.
56 double dQW; // Quaternion W.
57 };
58
60 // Declare public methods and member variables.
62
76 Camera(const int nPropResolutionX,
77 const int nPropResolutionY,
78 const int nPropFramesPerSecond,
79 const PIXEL_FORMATS ePropPixelFormat,
80 const double dPropHorizontalFOV,
81 const double dPropVerticalFOV,
82 const bool bEnableRecordingFlag,
83 const int nNumFrameRetrievalThreads = 5)
84
85 {
86 // Initialize member variables.
87 m_nPropResolutionX = nPropResolutionX;
88 m_nPropResolutionY = nPropResolutionY;
89 m_nPropFramesPerSecond = nPropFramesPerSecond;
90 m_ePropPixelFormat = ePropPixelFormat;
91 m_dPropHorizontalFOV = dPropHorizontalFOV;
92 m_dPropVerticalFOV = dPropVerticalFOV;
93 m_bEnableRecordingFlag = bEnableRecordingFlag;
94 m_nNumFrameRetrievalThreads = nNumFrameRetrievalThreads;
95 m_stCameraPoseOffset = Pose{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
96 }
97
98
105 virtual ~Camera() {}
106
107
115 void SetEnableRecordingFlag(const bool bEnableRecordingFlag) { m_bEnableRecordingFlag = bEnableRecordingFlag; }
116
117
125 void SetCameraPoseOffset(const Pose& stPoseOffset) { m_stCameraPoseOffset = stPoseOffset; }
126
127
141 void SetCameraPoseOffset(const double dPosX, const double dPosY, const double dPosZ, const double dQX, const double dQY, const double dQZ, const double dQW)
142 {
143 // Update member variable.
144 m_stCameraPoseOffset.dPosX = dPosX;
145 m_stCameraPoseOffset.dPosY = dPosY;
146 m_stCameraPoseOffset.dPosZ = dPosZ;
147 m_stCameraPoseOffset.dQX = dQX;
148 m_stCameraPoseOffset.dQY = dQY;
149 m_stCameraPoseOffset.dQZ = dQZ;
150 m_stCameraPoseOffset.dQW = dQW;
151 }
152
153
161 cv::Size GetPropResolution() const { return cv::Size(m_nPropResolutionX, m_nPropResolutionY); }
162
163
171 int GetPropFramesPerSecond() const { return m_nPropFramesPerSecond; }
172
173
182 PIXEL_FORMATS GetPropPixelFormat() const { return m_ePropPixelFormat; }
183
184
192 double GetPropHorizontalFOV() const { return m_dPropHorizontalFOV; }
193
194
202 double GetPropVerticalFOV() const { return m_dPropVerticalFOV; }
203
204
213 bool GetEnableRecordingFlag() const { return m_bEnableRecordingFlag; }
214
215
223 Pose GetCameraPoseOffset() const { return m_stCameraPoseOffset; }
224
225
234 virtual bool GetCameraIsOpen() = 0; // This is where the code to check if the camera is currently open goes.
235
236 protected:
237 // Declare protected methods and member variables.
238 int m_nPropResolutionX;
239 int m_nPropResolutionY;
240 int m_nPropFramesPerSecond;
241 int m_nNumFrameRetrievalThreads;
242 PIXEL_FORMATS m_ePropPixelFormat;
243 double m_dPropHorizontalFOV;
244 double m_dPropVerticalFOV;
245 Pose m_stCameraPoseOffset;
246 std::atomic_bool m_bEnableRecordingFlag;
247
248 // Queues and mutexes for scheduling and copying camera frames and data to other threads.
249 std::queue<containers::FrameFetchContainer<T>> m_qFrameCopySchedule;
250 std::shared_mutex m_muPoolScheduleMutex;
251 std::shared_mutex m_muFrameCopyMutex;
252
253 // Declare interface class pure virtual functions. (These must be overriden by inheritor.)
254 virtual std::future<bool> RequestFrameCopy(T& tFrame) = 0; // This is where the code to retrieve an image from the camera is put.
255
256 private:
257 // Declare private methods and member variables.
258};
259#endif
This interface defines the base functions needed to multi-thread a class in Autonomy_Software....
Interface class used to easily multithread a child class.
Definition AutonomyThread.hpp:40
This interface class serves as a base for all other classes that will implement and interface with a ...
Definition Camera.hpp:34
void SetEnableRecordingFlag(const bool bEnableRecordingFlag)
Mutator for the Enable Recording Flag private member.
Definition Camera.hpp:115
Camera(const int nPropResolutionX, const int nPropResolutionY, const int nPropFramesPerSecond, const PIXEL_FORMATS ePropPixelFormat, const double dPropHorizontalFOV, const double dPropVerticalFOV, const bool bEnableRecordingFlag, const int nNumFrameRetrievalThreads=5)
Construct a new Camera object.
Definition Camera.hpp:76
void SetCameraPoseOffset(const Pose &stPoseOffset)
Mutator for the Camera Pose Offset private member.
Definition Camera.hpp:125
Pose GetCameraPoseOffset() const
Accessor for the Camera Pose Offset private member.
Definition Camera.hpp:223
cv::Size GetPropResolution() const
Accessor for the Prop Resolution private member.
Definition Camera.hpp:161
void SetCameraPoseOffset(const double dPosX, const double dPosY, const double dPosZ, const double dQX, const double dQY, const double dQZ, const double dQW)
Mutator for the Camera Pose Offset private member.
Definition Camera.hpp:141
virtual ~Camera()
Destroy the Camera object.
Definition Camera.hpp:105
int GetPropFramesPerSecond() const
Accessor for the Prop Frames Per Second private member.
Definition Camera.hpp:171
bool GetEnableRecordingFlag() const
Accessor for the Enable Recording Flag private member.
Definition Camera.hpp:213
virtual bool GetCameraIsOpen()=0
Accessor for the Camera Is Open private member.
double GetPropVerticalFOV() const
Accessor for the Prop Vertical F O V private member.
Definition Camera.hpp:202
PIXEL_FORMATS GetPropPixelFormat() const
Accessor for the Prop Pixel Format private member.
Definition Camera.hpp:182
double GetPropHorizontalFOV() const
Accessor for the Prop Horizontal F O V private member.
Definition Camera.hpp:192
Size2i Size
Defines a simple struct to hold pose data.
Definition Camera.hpp:48