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
SIMZEDCam.h
Go to the documentation of this file.
1
11#ifndef SIMZEDCAM_H
12#define SIMZEDCAM_H
13
14#include "../../../interfaces/AutonomyThread.hpp"
15#include "../../../interfaces/ZEDCamera.hpp"
16#include "WebRTC.h"
17
19#include <opencv2/opencv.hpp>
20
22
23
33class SIMZEDCam : public ZEDCamera
34{
35 public:
37 // Declare public methods and member variables.
39
40 SIMZEDCam(const std::string szCameraPath,
41 const int nPropResolutionX,
42 const int nPropResolutionY,
43 const int nPropFramesPerSecond,
44 const double dPropHorizontalFOV,
45 const double dPropVerticalFOV,
46 const bool bEnableRecordingFlag,
47 const int nNumFrameRetrievalThreads = 10,
48 const unsigned int unCameraSerialNumber = 0);
49 ~SIMZEDCam();
50 std::future<bool> RequestFrameCopy(cv::Mat& cvFrame) override;
51 std::future<bool> RequestDepthCopy(cv::Mat& cvDepth, const bool bRetrieveMeasure = true);
52 std::future<bool> RequestPointCloudCopy(cv::Mat& cvPointCloud);
53 std::future<bool> RequestPositionalPoseCopy(Pose& stPose) override;
54 std::future<bool> RequestFusionGeoPoseCopy(sl::GeoPose& slGeoPose) override;
55 std::future<bool> RequestSensorsCopy(sl::SensorsData& slSensorsData) override;
56 sl::ERROR_CODE ResetPositionalTracking() override;
57 sl::ERROR_CODE RebootCamera() override;
58 sl::FUSION_ERROR_CODE SubscribeFusionToCameraUUID(sl::CameraIdentifier& slCameraUUID) override;
59 sl::CameraIdentifier PublishCameraToFusion() override;
60
62 // Setters for class member variables.
64
65 sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance = constants::ZED_DEFAULT_FLOOR_PLANE_ERROR) override;
66 void DisablePositionalTracking() override;
67 void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO) override;
68
70 // Getters.
72
73 bool GetCameraIsOpen() override;
74 bool GetUsingGPUMem() const override;
75 std::string GetCameraModel() override;
76 bool GetPositionalTrackingEnabled() override;
77
78 private:
80 // Declare private methods.
82
83 void ThreadedContinuousCode() override;
84 void PooledLinearCode() override;
85 void SetCallbacks();
86 void EstimateDepthMeasure(const cv::Mat& cvDepthImage, cv::Mat& cvDepthMeasure);
87 void CalculatePointCloud(const cv::Mat& cvDepthMeasure, cv::Mat& cvPointCloud);
88
90 // Declare private member variables.
92
93 // ZED Camera specific.
94
95 std::string m_szCameraPath;
96 std::atomic<bool> m_bCameraPositionalTrackingEnabled;
97
98 // Simulated IMU Data from the SIM.
99 sl::SensorsData m_stIMUData;
100
101 // WebRTC connections for each camera stream from the RoveSoSimulator.
102
103 std::unique_ptr<WebRTC> m_pRGBStream;
104 std::unique_ptr<WebRTC> m_pDepthImageStream;
105
106 // Pose tracking offsets. (ZEDSDK is broken and can't handle large translations internally as it uses float32.)
107
108 double m_dPoseOffsetX;
109 double m_dPoseOffsetY;
110 double m_dPoseOffsetZ;
111 double m_dPoseOffsetXO;
112 double m_dPoseOffsetYO;
113 double m_dPoseOffsetZO;
114
115 // Data from NavBoard.
116
117 geoops::RoverPose m_stCurrentRoverPose;
118 std::shared_mutex m_muCurrentRoverPoseMutex;
119
120 // Mats for storing frames.
121
122 cv::Mat m_cvFrame;
123 cv::Mat m_cvDepthImageBuffer;
124 cv::Mat m_cvDepthImage;
125 cv::Mat m_cvDepthMeasure;
126 cv::Mat m_cvPointCloud;
127
128 std::queue<containers::DataFetchContainer<Pose>> m_qPoseCopySchedule;
129 std::queue<containers::DataFetchContainer<sl::GeoPose>> m_qGeoPoseCopySchedule;
130 std::queue<containers::DataFetchContainer<sl::SensorsData>> m_qSensorsCopySchedule;
131
132 // Mutexes for copying frames from the WebRTC connection to the OpenCV Mats.
133
134 std::shared_mutex m_muWebRTCRGBImageCopyMutex;
135 std::shared_mutex m_muWebRTCDepthImageCopyMutex;
136
137 // Mutexes for copying frames from the ZEDSDK to the OpenCV Mats in PoolLinearCode.
138 std::shared_mutex m_muPoseCopyMutex;
139 std::shared_mutex m_muGeoPoseCopyMutex;
140 std::shared_mutex m_muSensorsCopyMutex;
141
142 // Atomic flags for checking if data is queued.
143
144 std::atomic<bool> m_bPosesQueued;
145 std::atomic<bool> m_bGeoPosesQueued;
146 std::atomic<bool> m_bSensorsQueued;
147};
148#endif
This class implements and interfaces with the SIM cameras and data. It is designed in such a way that...
Definition SIMZEDCam.h:34
void CalculatePointCloud(const cv::Mat &cvDepthMeasure, cv::Mat &cvPointCloud)
This method calculates a point cloud from the decoded depth measure use some simple trig and the came...
Definition SIMZEDCam.cpp:202
void EstimateDepthMeasure(const cv::Mat &cvDepthImage, cv::Mat &cvDepthMeasure)
This method estimates the depth measure from the depth image.
Definition SIMZEDCam.cpp:155
std::future< bool > RequestDepthCopy(cv::Mat &cvDepth, const bool bRetrieveMeasure=true)
Requests a depth measure or image from the camera. Puts a frame pointer into a queue so a copy of a f...
Definition SIMZEDCam.cpp:544
~SIMZEDCam()
Destroy the SIM Cam:: SIM Cam object.
Definition SIMZEDCam.cpp:91
sl::FUSION_ERROR_CODE SubscribeFusionToCameraUUID(sl::CameraIdentifier &slCameraUUID) override
This method is used to subscribe the sl::Fusion object to the camera with the given UUID....
Definition SIMZEDCam.cpp:798
void ThreadedContinuousCode() override
The code inside this private method runs in a separate thread, but still has access to this*....
Definition SIMZEDCam.cpp:254
std::future< bool > RequestFusionGeoPoseCopy(sl::GeoPose &slGeoPose) override
Puts a sl::GeoPose pointer into a queue so a copy of a GeoPose from the camera can be written to it.
Definition SIMZEDCam.cpp:655
sl::ERROR_CODE RebootCamera() override
This method is used to reboot the camera. This method will stop the camera thread,...
Definition SIMZEDCam.cpp:764
sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance=constants::ZED_DEFAULT_FLOOR_PLANE_ERROR) override
This method is used to enable positional tracking on the camera. Since this is a simulation camera,...
Definition SIMZEDCam.cpp:831
std::future< bool > RequestFrameCopy(cv::Mat &cvFrame) override
Puts a frame pointer into a queue so a copy of a frame from the camera can be written to it....
Definition SIMZEDCam.cpp:513
void SetCallbacks()
This method sets the callbacks for the WebRTC connections.
Definition SIMZEDCam.cpp:115
std::string GetCameraModel() override
Accessor for the name of this model of camera.
Definition SIMZEDCam.cpp:920
sl::CameraIdentifier PublishCameraToFusion() override
This method is used to publish the camera to the sl::Fusion object. Since this is a simulation camera...
Definition SIMZEDCam.cpp:815
std::future< bool > RequestPositionalPoseCopy(Pose &stPose) override
Puts a sl::GeoPose pointer into a queue so a copy of a GeoPose from the camera can be written to it.
Definition SIMZEDCam.cpp:605
std::future< bool > RequestPointCloudCopy(cv::Mat &cvPointCloud)
Requests a point cloud image from the camera. This image has the same resolution as a normal image bu...
Definition SIMZEDCam.cpp:580
sl::ERROR_CODE ResetPositionalTracking() override
This method is used to reset the positional tracking of the camera. Because this is a simulation came...
Definition SIMZEDCam.cpp:739
bool GetUsingGPUMem() const override
Returns if the camera is using GPU memory. This is a simulation camera, so this method will always re...
Definition SIMZEDCam.cpp:907
bool GetPositionalTrackingEnabled() override
Accessor for the if the camera's positional tracking is enabled. Since this is a simulation camera,...
Definition SIMZEDCam.cpp:935
void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO) override
This method is used to set the positional pose of the camera. Since this is a simulation camera,...
Definition SIMZEDCam.cpp:869
bool GetCameraIsOpen() override
Accessor for the camera open status.
Definition SIMZEDCam.cpp:892
void DisablePositionalTracking() override
This method is used to disable positional tracking on the camera. Since this is a simulation camera,...
Definition SIMZEDCam.cpp:849
void PooledLinearCode() override
This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method....
Definition SIMZEDCam.cpp:347
std::future< bool > RequestSensorsCopy(sl::SensorsData &slSensorsData) override
Requests a copy of the sensors data from the camera.
Definition SIMZEDCam.cpp:706
This class serves as a middle inheritor between the Camera interface and the ZEDCam class....
Definition ZEDCamera.hpp:33
This struct is used within the ZEDCam class to store the camera pose with high precision....
Definition ZEDCamera.hpp:77
This struct is used by the WaypointHandler to provide an easy way to store all pose data about the ro...
Definition GeospatialOperations.hpp:677