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
ZEDCamera.hpp
Go to the documentation of this file.
1
11#ifndef ZEDCAMERA_HPP
12#define ZEDCAMERA_HPP
13
14#include "../AutonomyLogging.h"
15#include "../util/GeospatialOperations.hpp"
16#include "Camera.hpp"
17
19#include <sl/Camera.hpp>
20#include <sl/Fusion.hpp>
21
23
24
32class ZEDCamera : public Camera<cv::Mat>
33{
34 public:
36 // Declare public structs that are specific to and used within this class.
38
39
49 {
50 private:
51 // Declare and define private struct member variables.
52 std::string szObjectUUID = sl::generate_unique_id().get(); // This will automatically generate a guaranteed unique id so the object is traceable.
53
54 public:
55 // Declare and define public struct member variables.
56 cv::Rect2d cvBoundingBox; // The bounding box of the object in the image.
57 int nClassNumber; // This info is passed through from your detection algorithm and will improve tracking be ensure the type of object remains the
58 float fConfidence; // This info is passed through from your detection algorithm and will help improve tracking by throwing out bad detections.
59 // Whether of not this object remains on the floor plane. This parameter can't be changed for a given object tracking ID, it's advised to set it by class
60 // to avoid issues.
61 bool bObjectRemainsOnFloorPlane = false;
62
63 // Declare and define public struct getters.
64 std::string GetObjectUUID() { return szObjectUUID; };
65 };
66
67
76 struct Pose
77 {
78 private:
79 // Declare struct for storing translation values.
81 {
82 public:
83 double dX; // Translation in ZED_MEASURE_UNITS on the x-axis.
84 double dY; // Translation in ZED_MEASURE_UNITS on the y-axis.
85 double dZ; // Translation in ZED_MEASURE_UNITS on the z-axis.
86 };
87
88 // Declare struct for storing rotation values.
90 {
91 public:
92 double dXO; // Rotation in degrees around the x-axis.
93 double dYO; // Rotation in degrees around the y-axis.
94 double dZO; // Rotation in degrees around the z-axis.
95 };
96
97 public:
98 // Declare struct public member variables.
99 Translation stTranslation;
100 EulerAngles stEulerAngles;
101
102
115 Pose(const double dX = 0.0, const double dY = 0.0, const double dZ = 0.0, const double dXO = 0.0, const double dYO = 0.0, const double dZO = 0.0)
116 {
117 // Initialize member variables.
118 stTranslation.dX = dX;
119 stTranslation.dY = dY;
120 stTranslation.dZ = dZ;
121 stEulerAngles.dXO = dXO;
122 stEulerAngles.dYO = dYO;
123 stEulerAngles.dZO = dZO;
124 }
125 };
126
128 // Declare public methods and member variables.
130
131
150 ZEDCamera(const int nPropResolutionX,
151 const int nPropResolutionY,
152 const int nPropFramesPerSecond,
153 const double dPropHorizontalFOV,
154 const double dPropVerticalFOV,
155 const bool bEnableRecordingFlag,
156 const bool bMemTypeGPU,
157 const bool bUseHalfDepthPrecision,
158 const int nNumFrameRetrievalThreads,
159 const unsigned int unCameraSerialNumber) :
160 Camera(nPropResolutionX,
161 nPropResolutionY,
162 nPropFramesPerSecond,
163 PIXEL_FORMATS::eZED,
164 dPropHorizontalFOV,
165 dPropVerticalFOV,
166 bEnableRecordingFlag,
167 nNumFrameRetrievalThreads)
168 {
169 // Initialize member variables. Some parameters are not used.
170 (void) bMemTypeGPU;
171 (void) bUseHalfDepthPrecision;
172 m_unCameraSerialNumber = unCameraSerialNumber;
173 }
174
175
182 virtual ~ZEDCamera() = default;
183
184
195 std::future<bool> RequestFrameCopy(cv::Mat& cvFrame) override = 0;
196
197
206 virtual std::future<bool> RequestFrameCopy(cv::cuda::GpuMat& cvGPUFrame)
207 {
208 // Create instance variables.
209 (void) cvGPUFrame;
210 std::promise<bool> pmPromise;
211 std::future<bool> fuFuture = pmPromise.get_future();
212
213 // Immediately set the promise to false.
214 pmPromise.set_value(false);
215
216 // Submit logger message.
217 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestFrameCopy(cv::cuda::GpuMat& cvGPUFrame) not implemented. If SIM_MODE use cv::Mat version instead.");
218
219 return fuFuture;
220 }
221
222
232 virtual std::future<bool> RequestDepthCopy(cv::Mat& cvDepth, const bool bRetrieveMeasure = true) = 0;
233
234
244 virtual std::future<bool> RequestDepthCopy(cv::cuda::GpuMat& cvGPUDepth, const bool bRetrieveMeasure = true)
245 {
246 // Initialize instance variables.
247 (void) cvGPUDepth;
248 (void) bRetrieveMeasure;
249 std::promise<bool> pmPromise;
250
251 // Immediately set the promise to false.
252 pmPromise.set_value(false);
253
254 // Submit logger message.
255 LOG_ERROR(logging::g_qSharedLogger,
256 "ZEDCamera::RequestDepthCopy(cv::cuda::GpuMat& cvGPUDepth, const bool bRetrieveMeasure = true) not implemented. If SIM_MODE use cv::Mat version "
257 "instead.");
258
259 return pmPromise.get_future();
260 }
261
262
271 virtual std::future<bool> RequestPointCloudCopy(cv::Mat& cvPointCloud) = 0;
272
273
282 virtual std::future<bool> RequestPointCloudCopy(cv::cuda::GpuMat& cvGPUPointCloud)
283 {
284 // Initialize instance variables.
285 (void) cvGPUPointCloud;
286 std::promise<bool> pmPromise;
287
288 // Immediately set the promise to false.
289 pmPromise.set_value(false);
290
291 // Submit logger message.
292 LOG_ERROR(logging::g_qSharedLogger,
293 "ZEDCamera::RequestPointCloudCopy(cv::cuda::GpuMat& cvGPUPointCloud) not implemented. If SIM_MODE use cv::Mat version instead.");
294
295 return pmPromise.get_future();
296 }
297
298
307 virtual std::future<bool> RequestPositionalPoseCopy(Pose& stPose) = 0;
308
309
318 virtual std::future<bool> RequestFloorPlaneCopy(sl::Plane& slFloorPlane)
319 {
320 // Initialize instance variables.
321 (void) slFloorPlane;
322 std::promise<bool> pmPromise;
323
324 // Immediately set the promise to false.
325 pmPromise.set_value(false);
326
327 // Submit logger message.
328 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestFloorPlaneCopy(sl::Plane& slFloorPlane) not implemented.");
329
330 return pmPromise.get_future();
331 }
332
333
342 virtual std::future<bool> RequestSensorsCopy(sl::SensorsData& slSensorsData)
343 {
344 // Initialize instance variables.
345 (void) slSensorsData;
346 std::promise<bool> pmPromise;
347
348 // Immediately set the promise to false.
349 pmPromise.set_value(false);
350
351 // Submit logger message.
352 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestSensorsCopy(sl::SensorsData& slSensorsData) not implemented.");
353
354 return pmPromise.get_future();
355 }
356
357
366 virtual std::future<bool> RequestObjectsCopy(std::vector<sl::ObjectData>& vObjectData)
367 {
368 // Initialize instance variables.
369 (void) vObjectData;
370 std::promise<bool> pmPromise;
371
372 // Immediately set the promise to false.
373 pmPromise.set_value(false);
374
375 // Submit logger message.
376 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestObjectsCopy(std::vector<sl::ObjectData>& vObjectData) not implemented.");
377
378 return pmPromise.get_future();
379 }
380
381
390 virtual std::future<bool> RequestBatchedObjectsCopy(std::vector<sl::ObjectsBatch>& vBatchedObjectData)
391 {
392 // Initialize instance variables.
393 (void) vBatchedObjectData;
394 std::promise<bool> pmPromise;
395
396 // Immediately set the promise to false.
397 pmPromise.set_value(false);
398
399 // Submit logger message.
400 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestBatchedObjectsCopy(std::vector<sl::ObjectsBatch>& vBatchedObjectData) not implemented.");
401
402 return pmPromise.get_future();
403 }
404
405
413 virtual sl::ERROR_CODE ResetPositionalTracking() = 0;
414
415
424 virtual sl::ERROR_CODE TrackCustomBoxObjects(std::vector<ZedObjectData>& vCustomObjects)
425 {
426 // Initialize instance variables.
427 (void) vCustomObjects;
428
429 // Submit logger message.
430 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::TrackCustomBoxObjects(const std::vector<ZedObjectData>& vCustomObjects) not implemented.");
431
432 return sl::ERROR_CODE::FAILURE;
433 }
434
435
443 virtual sl::ERROR_CODE RebootCamera() = 0;
444
446 // Setters for class member variables.
448
449
458 virtual sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance = constants::ZED_DEFAULT_FLOOR_PLANE_ERROR) = 0;
459
460
467 virtual void DisablePositionalTracking() = 0;
468
469
482 virtual void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO) = 0;
483
484
492 virtual sl::ERROR_CODE EnableSpatialMapping()
493 {
494 // Submit logger message.
495 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::EnableSpatialMapping() not implemented.");
496
497 return sl::ERROR_CODE::FAILURE;
498 }
499
500
508 {
509 // Submit logger message.
510 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::DisableSpatialMapping() not implemented.");
511 }
512
513
522 virtual sl::ERROR_CODE EnableObjectDetection(const bool bEnableBatching = false)
523 {
524 // Initialize instance variables.
525 (void) bEnableBatching;
526
527 // Submit logger message.
528 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::EnableObjectDetection(const bool bEnableBatching = false) not implemented.");
529
530 return sl::ERROR_CODE::FAILURE;
531 }
532
533
541 {
542 // Submit logger message.
543 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::DisableObjectDetection() not implemented.");
544 }
545
547 // Accessors for class member variables.
549
550
559 virtual bool GetUsingGPUMem() const { return false; }
560
561
569 virtual std::string GetCameraModel() = 0;
570
571
579 virtual unsigned int GetCameraSerial() { return m_unCameraSerialNumber; };
580
581
591
592
600 virtual sl::PositionalTrackingStatus GetPositionalTrackingState()
601 {
602 // Initialize instance variable.
603 sl::PositionalTrackingStatus stStatus;
604
605 // Submit logger message.
606 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::GetPositionalTrackingState() not implemented.");
607
608 return stStatus;
609 }
610
611
619 virtual sl::SPATIAL_MAPPING_STATE GetSpatialMappingState() { return sl::SPATIAL_MAPPING_STATE::NOT_ENABLED; }
620
621
630 virtual sl::SPATIAL_MAPPING_STATE ExtractSpatialMapAsync(std::future<sl::Mesh>& fuMeshFuture)
631 {
632 // Initialize instance variables.
633 (void) fuMeshFuture;
634
635 // Submit logger message.
636 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::ExtractSpatialMapAsync(std::future<sl::Mesh>& fuMeshFuture) not implemented.");
637
638 return sl::SPATIAL_MAPPING_STATE::NOT_ENABLED;
639 }
640
641
650 virtual bool GetObjectDetectionEnabled() { return false; }
651
652 protected:
654 // Declare class constants.
656
657 const std::memory_order ATOMIC_MEMORY_ORDER_METHOD = std::memory_order_relaxed;
658
660 // Declare protected member variables.
662
663 // ZED Camera specific.
664 unsigned int m_unCameraSerialNumber;
665
666 private:
668 // Declare private member variables.
670};
671
672#endif
Defines the Camera base interface class.
This interface class serves as a base for all other classes that will implement and interface with a ...
Definition Camera.hpp:34
This class serves as a middle inheritor between the Camera interface and the ZEDCam class....
Definition ZEDCamera.hpp:33
virtual sl::SPATIAL_MAPPING_STATE ExtractSpatialMapAsync(std::future< sl::Mesh > &fuMeshFuture)
Puts a Mesh pointer into a queue so a copy of a spatial mapping mesh from the camera can be written t...
Definition ZEDCamera.hpp:630
virtual unsigned int GetCameraSerial()
Accessor for the Camera Serial private member.
Definition ZEDCamera.hpp:579
virtual sl::ERROR_CODE RebootCamera()=0
Reboots the camera.
virtual std::future< bool > RequestBatchedObjectsCopy(std::vector< sl::ObjectsBatch > &vBatchedObjectData)
Puts a vector of ObjectsBatch pointers into a queue so a copy of a vector of ObjectsBatch from the ca...
Definition ZEDCamera.hpp:390
virtual std::future< bool > RequestObjectsCopy(std::vector< sl::ObjectData > &vObjectData)
Puts a vector of ObjectData pointers into a queue so a copy of a vector of ObjectData from the camera...
Definition ZEDCamera.hpp:366
virtual void DisablePositionalTracking()=0
Disables the position tracking of the camera.
virtual std::future< bool > RequestDepthCopy(cv::Mat &cvDepth, const bool bRetrieveMeasure=true)=0
Puts a frame pointer into a queue so a copy of a depth frame from the camera can be written to it.
virtual void DisableSpatialMapping()
Disables spatial mapping.
Definition ZEDCamera.hpp:507
ZEDCamera(const int nPropResolutionX, const int nPropResolutionY, const int nPropFramesPerSecond, const double dPropHorizontalFOV, const double dPropVerticalFOV, const bool bEnableRecordingFlag, const bool bMemTypeGPU, const bool bUseHalfDepthPrecision, const int nNumFrameRetrievalThreads, const unsigned int unCameraSerialNumber)
Construct a new ZEDCamera object.
Definition ZEDCamera.hpp:150
virtual std::future< bool > RequestFloorPlaneCopy(sl::Plane &slFloorPlane)
Puts a FloorPlane pointer into a queue so a copy of a FloorPlane from the camera can be written to it...
Definition ZEDCamera.hpp:318
virtual ~ZEDCamera()=default
Destroy the ZEDCamera object.
virtual sl::PositionalTrackingStatus GetPositionalTrackingState()
Accessor for the Positional Tracking State private member.
Definition ZEDCamera.hpp:600
virtual sl::ERROR_CODE EnableObjectDetection(const bool bEnableBatching=false)
Enables object detection.
Definition ZEDCamera.hpp:522
virtual sl::ERROR_CODE EnableSpatialMapping()
Enables spatial mapping.
Definition ZEDCamera.hpp:492
virtual void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO)=0
Mutator for the Positional Pose private member.
virtual std::future< bool > RequestDepthCopy(cv::cuda::GpuMat &cvGPUDepth, const bool bRetrieveMeasure=true)
Puts a frame pointer into a queue so a copy of a depth frame from the camera can be written to it.
Definition ZEDCamera.hpp:244
virtual bool GetUsingGPUMem() const
Accessor for the Using G P U Memory private member.
Definition ZEDCamera.hpp:559
virtual sl::ERROR_CODE TrackCustomBoxObjects(std::vector< ZedObjectData > &vCustomObjects)
Tracks custom bounding boxes in the camera's field of view.
Definition ZEDCamera.hpp:424
virtual sl::ERROR_CODE ResetPositionalTracking()=0
Resets the positional tracking of the camera.
virtual std::string GetCameraModel()=0
Accessor for the Camera Model private member.
virtual bool GetPositionalTrackingEnabled()=0
Accessor for the Positional Tracking Enabled private member.
virtual sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance=constants::ZED_DEFAULT_FLOOR_PLANE_ERROR)=0
Enables the position tracking of the camera.
virtual std::future< bool > RequestFrameCopy(cv::cuda::GpuMat &cvGPUFrame)
Puts a frame pointer into a queue so a copy of a frame from the camera can be written to it.
Definition ZEDCamera.hpp:206
virtual std::future< bool > RequestPositionalPoseCopy(Pose &stPose)=0
Puts a Pose pointer into a queue so a copy of a Pose from the camera can be written to it.
virtual std::future< bool > RequestPointCloudCopy(cv::Mat &cvPointCloud)=0
Puts a frame pointer into a queue so a copy of a point cloud from the camera can be written to it.
virtual std::future< bool > RequestPointCloudCopy(cv::cuda::GpuMat &cvGPUPointCloud)
Puts a frame pointer into a queue so a copy of a point cloud from the camera can be written to it.
Definition ZEDCamera.hpp:282
virtual std::future< bool > RequestSensorsCopy(sl::SensorsData &slSensorsData)
Puts a SensorsData pointer into a queue so a copy of a SensorsData from the camera can be written to ...
Definition ZEDCamera.hpp:342
virtual void DisableObjectDetection()
Disables object detection.
Definition ZEDCamera.hpp:540
virtual bool GetObjectDetectionEnabled()
Accessor for the Object Detection Enabled private member.
Definition ZEDCamera.hpp:650
std::future< bool > RequestFrameCopy(cv::Mat &cvFrame) override=0
virtual sl::SPATIAL_MAPPING_STATE GetSpatialMappingState()
Accessor for the Spatial Mapping State private member.
Definition ZEDCamera.hpp:619
Definition ZEDCamera.hpp:90
Definition ZEDCamera.hpp:81
This struct is used within the ZEDCam class to store the camera pose with high precision....
Definition ZEDCamera.hpp:77
Pose(const double dX=0.0, const double dY=0.0, const double dZ=0.0, const double dXO=0.0, const double dYO=0.0, const double dZO=0.0)
Construct a new Pose object.
Definition ZEDCamera.hpp:115
This struct is part of the ZEDCam class and is used as a container for all bounding box data that is ...
Definition ZEDCamera.hpp:49