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
ZEDCam.h
Go to the documentation of this file.
1
11#ifndef ZEDCAM_H
12#define ZEDCAM_H
13
14#include "../../interfaces/ZEDCamera.hpp"
15
17
19
20
30class ZEDCam : public ZEDCamera
31{
32 public:
34 // Declare public methods and member variables.
36
37 ZEDCam(const int nPropResolutionX,
38 const int nPropResolutionY,
39 const int nPropFramesPerSecond,
40 const double dPropHorizontalFOV,
41 const double dPropVerticalFOV,
42 const bool bEnableRecordingFlag = false,
43 const bool bExportSVORecordingFlag = false,
44 const float fMinSenseDistance = constants::ZED_DEFAULT_MINIMUM_DISTANCE,
45 const float fMaxSenseDistance = constants::ZED_DEFAULT_MAXIMUM_DISTANCE,
46 const bool bMemTypeGPU = false,
47 const bool bUseHalfDepthPrecision = false,
48 const int nNumFrameRetrievalThreads = 10,
49 const unsigned int unCameraSerialNumber = 0);
50 ~ZEDCam();
51 std::future<bool> RequestFrameCopy(cv::Mat& cvFrame) override;
52 std::future<bool> RequestFrameCopy(cv::cuda::GpuMat& cvGPUFrame) override;
53 std::future<bool> RequestDepthCopy(cv::Mat& cvDepth, const bool bRetrieveMeasure = true) override;
54 std::future<bool> RequestDepthCopy(cv::cuda::GpuMat& cvGPUDepth, const bool bRetrieveMeasure = true) override;
55 std::future<bool> RequestPointCloudCopy(cv::Mat& cvPointCloud) override;
56 std::future<bool> RequestPointCloudCopy(cv::cuda::GpuMat& cvGPUPointCloud) override;
57 std::future<bool> RequestPositionalPoseCopy(Pose& stPose) override;
58 std::future<bool> RequestFloorPlaneCopy(sl::Plane& slPlane) override;
59 std::future<bool> RequestSensorsCopy(sl::SensorsData& slSensorsData) override;
60 std::future<bool> RequestObjectsCopy(std::vector<sl::ObjectData>& vObjectData) override;
61 std::future<bool> RequestBatchedObjectsCopy(std::vector<sl::ObjectsBatch>& vBatchedObjectData) override;
62 sl::ERROR_CODE ResetPositionalTracking() override;
63 sl::ERROR_CODE TrackCustomBoxObjects(std::vector<ZedObjectData>& vCustomObjects) override;
64 sl::ERROR_CODE RebootCamera() override;
65
67 // Setters for class member variables.
69
70 sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance = constants::ZED_DEFAULT_FLOOR_PLANE_ERROR) override;
71 void DisablePositionalTracking() override;
72 void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO) override;
73 sl::ERROR_CODE EnableSpatialMapping() override;
74 void DisableSpatialMapping() override;
75 sl::ERROR_CODE EnableObjectDetection(const bool bEnableBatching = false) override;
76 void DisableObjectDetection() override;
77
79 // Getters.
81
82 bool GetCameraIsOpen() override;
83 bool GetUsingGPUMem() const override;
84 std::string GetCameraModel() override;
85 unsigned int GetCameraSerial() override;
86 bool GetPositionalTrackingEnabled() override;
87 sl::PositionalTrackingStatus GetPositionalTrackingState() override;
88 sl::SPATIAL_MAPPING_STATE GetSpatialMappingState() override;
89 sl::SPATIAL_MAPPING_STATE ExtractSpatialMapAsync(std::future<sl::Mesh>& fuMeshFuture) override;
90 bool GetObjectDetectionEnabled() override;
91
92 private:
94 // Declare private member variables.
96
97 // ZED Camera specific.
98
99 sl::Camera m_slCamera;
100 std::shared_mutex m_muCameraMutex;
101 sl::InitParameters m_slCameraParams;
102 sl::RuntimeParameters m_slRuntimeParams;
103 sl::RecordingParameters m_slRecordingParams;
104 sl::MEASURE m_slDepthMeasureType;
105 sl::PositionalTrackingParameters m_slPoseTrackingParams;
106 sl::Pose m_slCameraPose;
107 sl::Plane m_slFloorPlane;
108 sl::Transform m_slFloorTrackingTransform;
109 sl::SensorsData m_slSensorsData;
110 sl::SpatialMappingParameters m_slSpatialMappingParams;
111 sl::ObjectDetectionParameters m_slObjectDetectionParams;
112 sl::BatchParameters m_slObjectDetectionBatchParams;
113 sl::Objects m_slDetectedObjects;
114 std::vector<sl::ObjectsBatch> m_slDetectedObjectsBatched;
115 sl::MEM m_slMemoryType;
116 sl::MODEL m_slCameraModel;
117 float m_fExpectedCameraHeightFromFloorTolerance;
118 bool m_bCameraReopenAlreadyChecked;
119
120 // Track if we should turn on features during camera replug.
121 bool m_bEnablePositionalTrackingFlag;
122 bool m_bEnableSpatialMappingFlag;
123 bool m_bEnableObjectDetectionFlag;
124
125 // Pose tracking offsets. (ZEDSDK is broken and can't handle large translations internally)
126
127 double m_dPoseOffsetX;
128 double m_dPoseOffsetY;
129 double m_dPoseOffsetZ;
130 double m_dPoseOffsetXO;
131 double m_dPoseOffsetYO;
132 double m_dPoseOffsetZO;
133
134 // Data from NavBoard.
135
136 geoops::GPSCoordinate m_stCurrentGPSBasedPosition;
137
138 // Mats for storing frames and measures.
139
140 sl::Mat m_slFrame;
141 sl::Mat m_slDepthImage;
142 sl::Mat m_slDepthMeasure;
143 sl::Mat m_slPointCloud;
144
145 // Queues and mutexes for scheduling and copying camera frames and data to other threads.
146
147 std::queue<containers::FrameFetchContainer<cv::cuda::GpuMat>> m_qGPUFrameCopySchedule;
148 std::queue<containers::DataFetchContainer<std::vector<ZedObjectData>>> m_qCustomBoxIngestSchedule;
149 std::queue<containers::DataFetchContainer<Pose>> m_qPoseCopySchedule;
150 std::queue<containers::DataFetchContainer<sl::Plane>> m_qFloorCopySchedule;
151 std::queue<containers::DataFetchContainer<sl::SensorsData>> m_qSensorsCopySchedule;
152 std::queue<containers::DataFetchContainer<std::vector<sl::ObjectData>>> m_qObjectDataCopySchedule;
153 std::queue<containers::DataFetchContainer<std::vector<sl::ObjectsBatch>>> m_qObjectBatchedDataCopySchedule;
154
155 // Mutexes for copying frames from the ZEDSDK to the OpenCV Mats.
156
157 std::shared_mutex m_muCustomBoxIngestMutex;
158 std::shared_mutex m_muPoseCopyMutex;
159 std::shared_mutex m_muFloorCopyMutex;
160 std::shared_mutex m_muSensorsCopyMutex;
161 std::shared_mutex m_muObjectDataCopyMutex;
162 std::shared_mutex m_muObjectBatchedDataCopyMutex;
163
164 // Atomic flags for checking if data is queued.
165
166 bool m_bQueueTogglesAlreadyReset;
167 std::atomic<bool> m_bNormalFramesQueued;
168 std::atomic<bool> m_bDepthFramesQueued;
169 std::atomic<bool> m_bPointCloudsQueued;
170 std::atomic<bool> m_bPosesQueued;
171 std::atomic<bool> m_bFloorsQueued;
172 std::atomic<bool> m_bSensorsQueued;
173 std::atomic<bool> m_bObjectsQueued;
174 std::atomic<bool> m_bBatchedObjectsQueued;
175
177 // Declare private methods.
179
180 void ThreadedContinuousCode() override;
181 void PooledLinearCode() override;
182};
183#endif
This class implements and interfaces with the most common ZEDSDK cameras and features....
Definition ZEDCam.h:31
std::future< bool > RequestDepthCopy(cv::Mat &cvDepth, const bool bRetrieveMeasure=true) override
Requests a depth measure or image from the camera. Puts a frame pointer into a queue so a copy of a f...
Definition ZEDCam.cpp:937
void DisableSpatialMapping() override
Disabled the spatial mapping feature of the camera.
Definition ZEDCam.cpp:1662
void DisablePositionalTracking() override
Disable to positional tracking functionality of the camera.
Definition ZEDCam.cpp:1533
~ZEDCam()
Destroy the Zed Cam:: Zed Cam object.
Definition ZEDCam.cpp:210
sl::ERROR_CODE TrackCustomBoxObjects(std::vector< ZedObjectData > &vCustomObjects) override
A vector containing CustomBoxObjectData objects. These objects simply store information about your de...
Definition ZEDCam.cpp:1419
sl::ERROR_CODE RebootCamera() override
Performs a hardware reset of the ZED2 or ZED2i camera.
Definition ZEDCam.cpp:1478
void ThreadedContinuousCode() override
The code inside this private method runs in a separate thread, but still has access to this*....
Definition ZEDCam.cpp:235
sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance=constants::ZED_DEFAULT_FLOOR_PLANE_ERROR) override
Enable the positional tracking functionality of the camera.
Definition ZEDCam.cpp:1496
sl::ERROR_CODE EnableSpatialMapping() override
Enabled the spatial mapping feature of the camera. Pose tracking will be enabled if it is not already...
Definition ZEDCam.cpp:1593
bool GetPositionalTrackingEnabled() override
Accessor for if the positional tracking functionality of the camera has been enabled and functioning.
Definition ZEDCam.cpp:1814
sl::ERROR_CODE EnableObjectDetection(const bool bEnableBatching=false) override
Enables the object detection and tracking feature of the camera.
Definition ZEDCam.cpp:1680
std::future< bool > RequestPositionalPoseCopy(Pose &stPose) override
Requests the current pose of the camera relative to it's start pose or the origin of the set pose....
Definition ZEDCam.cpp:1109
unsigned int GetCameraSerial() override
Accessor for the camera's serial number.
Definition ZEDCam.cpp:1798
sl::SPATIAL_MAPPING_STATE ExtractSpatialMapAsync(std::future< sl::Mesh > &fuMeshFuture) override
Retrieve the built spatial map from the camera. Spatial mapping must be enabled. This method takes in...
Definition ZEDCam.cpp:1866
std::future< bool > RequestObjectsCopy(std::vector< sl::ObjectData > &vObjectData) override
Requests a current copy of the tracked objects from the camera. Puts a pointer to a vector containing...
Definition ZEDCam.cpp:1260
void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO) override
Sets the pose of the positional tracking of the camera. XYZ will point in their respective directions...
Definition ZEDCam.cpp:1569
std::future< bool > RequestBatchedObjectsCopy(std::vector< sl::ObjectsBatch > &vBatchedObjectData) override
If batching is enabled, this requests the normal objects and passes them to the the internal batching...
Definition ZEDCam.cpp:1322
bool GetUsingGPUMem() const override
Accessor for if this ZED is storing it's frames in GPU memory.
Definition ZEDCam.cpp:1754
sl::SPATIAL_MAPPING_STATE GetSpatialMappingState() override
Accessor for the current state of the camera's spatial mapping feature.
Definition ZEDCam.cpp:1845
std::future< bool > RequestPointCloudCopy(cv::Mat &cvPointCloud) override
Requests a point cloud image from the camera. This image has the same resolution as a normal image bu...
Definition ZEDCam.cpp:1028
std::future< bool > RequestFrameCopy(cv::Mat &cvFrame) override
Requests a regular BGRA image from the LEFT eye of the zed camera. Puts a frame pointer into a queue ...
Definition ZEDCam.cpp:864
sl::PositionalTrackingStatus GetPositionalTrackingState() override
Accessor for the current positional tracking status of the camera.
Definition ZEDCam.cpp:1830
bool GetCameraIsOpen() override
Accessor for the current status of the camera.
Definition ZEDCam.cpp:1738
void PooledLinearCode() override
This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method....
Definition ZEDCam.cpp:603
std::future< bool > RequestFloorPlaneCopy(sl::Plane &slPlane) override
Requests the current floor plane of the camera relative to it's current pose. Puts a Plane pointer in...
Definition ZEDCam.cpp:1168
void DisableObjectDetection() override
Disables the object detection and tracking feature of the camera.
Definition ZEDCam.cpp:1719
std::future< bool > RequestSensorsCopy(sl::SensorsData &slSensorsData) override
Requests the most up to date sensors data from the camera. This data include IMU pose and raw values,...
Definition ZEDCam.cpp:1226
bool GetObjectDetectionEnabled() override
Accessor for if the cameras object detection and tracking feature is enabled.
Definition ZEDCam.cpp:1933
sl::ERROR_CODE ResetPositionalTracking() override
Resets the cameras X,Y,Z translation and Roll,Pitch,Yaw orientation back to 0. THINK CAREFULLY!...
Definition ZEDCam.cpp:1379
std::string GetCameraModel() override
Accessor for the model enum from the ZEDSDK and represents the camera model as a string.
Definition ZEDCam.cpp:1769
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 stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:100