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
CameraHandler Class Reference

The CameraHandler class is responsible for managing all of the camera feeds that Autonomy_Software uses for computer vision. Whether it be a USB webcam, a MJPEG stream, or a ZED camera, this class is responsible for initializing that camera and configuring it. More...

#include <CameraHandler.h>

Public Types

enum class  ZEDCamName { ZEDCAM_START , eHeadMainCam , eRearCam , ZEDCAM_END }
 
enum class  BasicCamName { BASICCAM_START , BASICCAM_END }
 

Public Member Functions

 CameraHandler ()
 Construct a new Camera Handler Thread:: Camera Handler Thread object.
 
 ~CameraHandler ()
 Destroy the Camera Handler Thread:: Camera Handler Thread object.
 
void StartAllCameras ()
 Signals all cameras to start their threads.
 
void StartRecording ()
 Signal the RecordingHandler to start recording video feeds from the CameraHandler.
 
void StopAllCameras ()
 Signals all cameras to stop their threads.
 
void StopRecording ()
 Signal the RecordingHandler to stop recording video feeds from the CameraHandler.
 
std::shared_ptr< ZEDCameraGetZED (ZEDCamName eCameraName)
 Accessor for ZED cameras.
 
std::shared_ptr< BasicCameraGetBasicCam (BasicCamName eCameraName)
 Accessor for Basic cameras.
 

Private Attributes

std::shared_ptr< ZEDCameram_pMainCam
 
std::shared_ptr< ZEDCameram_pRearCam
 
std::unique_ptr< RecordingHandlerm_pRecordingHandler
 

Detailed Description

The CameraHandler class is responsible for managing all of the camera feeds that Autonomy_Software uses for computer vision. Whether it be a USB webcam, a MJPEG stream, or a ZED camera, this class is responsible for initializing that camera and configuring it.

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

Member Enumeration Documentation

◆ ZEDCamName

enum class CameraHandler::ZEDCamName
strong
50 {
51 ZEDCAM_START,
52 eHeadMainCam,
53 eRearCam,
54 ZEDCAM_END
55 };

◆ BasicCamName

enum class CameraHandler::BasicCamName
strong
58 {
59 BASICCAM_START,
60 // eExampleBasicCam, // Uncomment and change name if basic cam needed.
61 BASICCAM_END
62 };

Constructor & Destructor Documentation

◆ CameraHandler()

CameraHandler::CameraHandler ( )

Construct a new Camera Handler Thread:: Camera Handler Thread object.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-08-17
26{
27 // Check if we are in simulation mode.
28 if (!constants::MODE_SIM)
29 {
30 // Initialize main ZED camera.
31 m_pMainCam = std::make_shared<ZEDCam>(constants::ZED_MAINCAM_RESOLUTIONX,
32 constants::ZED_MAINCAM_RESOLUTIONY,
33 constants::ZED_MAINCAM_FPS,
34 constants::ZED_MAINCAM_HORIZONTAL_FOV,
35 constants::ZED_MAINCAM_VERTICAL_FOV,
36 constants::ZED_MAINCAM_ENABLE_RECORDING,
37 constants::ZED_MAINCAM_EXPORT_SVO_RECORDING,
38 constants::ZED_DEFAULT_MINIMUM_DISTANCE,
39 constants::ZED_DEFAULT_MAXIMUM_DISTANCE,
40 constants::ZED_MAINCAM_USE_GPU_MAT,
41 constants::ZED_MAINCAM_USE_HALF_PRECISION_DEPTH,
42 constants::ZED_MAINCAM_FRAME_RETRIEVAL_THREADS,
43 constants::ZED_MAINCAM_SERIAL);
44
45 // Additional setup for main ZED camera.
46 if (constants::ZED_MAINCAM_EXPORT_SPATIAL_MAP)
47 {
48 m_pMainCam->EnableSpatialMapping();
49 }
50
51 // Initialize rear ZED camera.
52 m_pRearCam = std::make_shared<ZEDCam>(constants::ZED_REARCAM_RESOLUTIONX,
53 constants::ZED_REARCAM_RESOLUTIONY,
54 constants::ZED_REARCAM_FPS,
55 constants::ZED_REARCAM_HORIZONTAL_FOV,
56 constants::ZED_REARCAM_VERTICAL_FOV,
57 constants::ZED_REARCAM_ENABLE_RECORDING,
58 constants::ZED_REARCAM_EXPORT_SVO_RECORDING,
59 constants::ZED_DEFAULT_MINIMUM_DISTANCE,
60 constants::ZED_DEFAULT_MAXIMUM_DISTANCE,
61 constants::ZED_REARCAM_USE_GPU_MAT,
62 constants::ZED_REARCAM_USE_HALF_PRECISION_DEPTH,
63 constants::ZED_REARCAM_FRAME_RETRIEVAL_THREADS,
64 constants::ZED_REARCAM_SERIAL);
65
66 // Additional setup for rear ZED camera.
67 if (constants::ZED_REARCAM_EXPORT_SPATIAL_MAP)
68 {
69 m_pRearCam->EnableSpatialMapping();
70 }
71 }
72 else
73 {
74 m_pMainCam =
75 std::make_shared<SIMZEDCam>("ws://" + constants::SIM_IP_ADDRESS + ":" + std::to_string(constants::SIM_WEBSOCKET_PORT) + "/" + constants::SIM_MAINCAM_NAME,
76 constants::ZED_MAINCAM_RESOLUTIONX,
77 constants::ZED_MAINCAM_RESOLUTIONY,
78 constants::ZED_MAINCAM_FPS,
79 constants::ZED_MAINCAM_HORIZONTAL_FOV,
80 constants::ZED_MAINCAM_VERTICAL_FOV,
81 constants::ZED_MAINCAM_ENABLE_RECORDING,
82 constants::ZED_MAINCAM_FRAME_RETRIEVAL_THREADS,
83 constants::ZED_MAINCAM_SERIAL);
84
85 m_pRearCam =
86 std::make_shared<SIMZEDCam>("ws://" + constants::SIM_IP_ADDRESS + ":" + std::to_string(constants::SIM_WEBSOCKET_PORT) + "/" + constants::SIM_REARCAM_NAME,
87 constants::ZED_REARCAM_RESOLUTIONX,
88 constants::ZED_REARCAM_RESOLUTIONY,
89 constants::ZED_REARCAM_FPS,
90 constants::ZED_REARCAM_HORIZONTAL_FOV,
91 constants::ZED_REARCAM_VERTICAL_FOV,
92 constants::ZED_REARCAM_ENABLE_RECORDING,
93 constants::ZED_REARCAM_FRAME_RETRIEVAL_THREADS,
94 constants::ZED_REARCAM_SERIAL);
95 }
96
97 // Set the position offsets of the main camera.
98 m_pMainCam->SetCameraPoseOffset(constants::ZED_MAINCAM_EASTING_OFFSET,
99 constants::ZED_MAINCAM_NORTHING_OFFSET,
100 constants::ZED_MAINCAM_ALTITUDE_OFFSET,
101 constants::ZED_MAINCAM_QUATERNION_OFFSET_X,
102 constants::ZED_MAINCAM_QUATERNION_OFFSET_Y,
103 constants::ZED_MAINCAM_QUATERNION_OFFSET_Z,
104 constants::ZED_MAINCAM_QUATERNION_OFFSET_W);
105
106 // Set the position offsets of the rear camera.
107 m_pRearCam->SetCameraPoseOffset(constants::ZED_REARCAM_EASTING_OFFSET,
108 constants::ZED_REARCAM_NORTHING_OFFSET,
109 constants::ZED_REARCAM_ALTITUDE_OFFSET,
110 constants::ZED_REARCAM_QUATERNION_OFFSET_X,
111 constants::ZED_REARCAM_QUATERNION_OFFSET_Y,
112 constants::ZED_REARCAM_QUATERNION_OFFSET_Z,
113 constants::ZED_REARCAM_QUATERNION_OFFSET_W);
114
115 // Set the thread priorities for the cameras. This is important to ensure that the cameras are able to retrieve frames at their full FPS and don't get starved of CPU
116 // time by other threads.
117 m_pMainCam->SetMainThreadPriority(AutonomyThread<void>::AutonomyThreadPriority::eHighest);
118 m_pMainCam->SetPoolThreadPriority(AutonomyThread<void>::AutonomyThreadPriority::eHigh);
119 m_pRearCam->SetMainThreadPriority(AutonomyThread<void>::AutonomyThreadPriority::eHighest);
120 m_pRearCam->SetPoolThreadPriority(AutonomyThread<void>::AutonomyThreadPriority::eHigh);
121
122 // Initialize recording handler for cameras.
123 m_pRecordingHandler = std::make_unique<RecordingHandler>(RecordingHandler::RecordingMode::eCameraHandler);
124}
Interface class used to easily multithread a child class.
Definition AutonomyThread.hpp:40

◆ ~CameraHandler()

CameraHandler::~CameraHandler ( )

Destroy the Camera Handler Thread:: Camera Handler Thread object.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
134{
135 // Signal and wait for cameras to stop.
136 this->StopAllCameras();
137}
void StopAllCameras()
Signals all cameras to stop their threads.
Definition CameraHandler.cpp:173
Here is the call graph for this function:

Member Function Documentation

◆ StartAllCameras()

void CameraHandler::StartAllCameras ( )

Signals all cameras to start their threads.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-09-09
147{
148 // Start ZED cams.
149 m_pMainCam->Start();
150 m_pRearCam->Start();
151}
Here is the caller graph for this function:

◆ StartRecording()

void CameraHandler::StartRecording ( )

Signal the RecordingHandler to start recording video feeds from the CameraHandler.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-12-31
161{
162 // Start recording handler.
163 m_pRecordingHandler->Start();
164}
Here is the caller graph for this function:

◆ StopAllCameras()

void CameraHandler::StopAllCameras ( )

Signals all cameras to stop their threads.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-10-03
174{
175 // Stop recording handler.
176 m_pRecordingHandler->RequestStop();
177 m_pRecordingHandler->Join();
178
179 // Stop main ZED cam.
180 m_pMainCam->RequestStop();
181 m_pMainCam->Join();
182
183 // Stop rear ZED cam.
184 m_pRearCam->RequestStop();
185 m_pRearCam->Join();
186
187 // Stop basic cam.
188 // m_pBasicCam->RequestStop();
189 // m_pBasicCam->Join();
190}
Here is the caller graph for this function:

◆ StopRecording()

void CameraHandler::StopRecording ( )

Signal the RecordingHandler to stop recording video feeds from the CameraHandler.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-01-01
200{
201 // Stop recording handler.
202 m_pRecordingHandler->RequestStop();
203 m_pRecordingHandler->Join();
204}

◆ GetZED()

std::shared_ptr< ZEDCamera > CameraHandler::GetZED ( ZEDCamName  eCameraName)

Accessor for ZED cameras.

Parameters
eCameraName- The name of the camera to retrieve. An enum defined in and specific to this class.
Returns
std::shared_ptr<ZEDCamera> - A pointer to the zed camera pertaining to the given name.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-09-01
216{
217 // Determine which camera should be returned.
218 switch (eCameraName)
219 {
220 case ZEDCamName::eHeadMainCam: return m_pMainCam; break; // Return the main ZEDCam in the autonomy head.
221 case ZEDCamName::eRearCam: return m_pRearCam; break; // Return the rear ZedCam.
222 default: return m_pMainCam; break;
223 }
224}
Here is the caller graph for this function:

◆ GetBasicCam()

std::shared_ptr< BasicCamera > CameraHandler::GetBasicCam ( BasicCamName  eCameraName)

Accessor for Basic cameras.

Parameters
eCameraName- The name of the camera to retrieve. An enum defined in and specific to this class.
Returns
std::shared_ptr<BasicCamera> - A pointer to the basic camera pertaining to the given name.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om), Sam Hajdukiewicz (saman.nosp@m.thah.nosp@m.ajduk.nosp@m.iewi.nosp@m.cz@gm.nosp@m.ail..nosp@m.com)
Date
2023-09-01
236{
237 // Determine which camera should be returned.
238 switch (eCameraName)
239 {
240 default: return nullptr; break;
241 }
242}
Here is the caller graph for this function:

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