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 // Declare a private struct for holding point data.
55
63 struct Corner
64 {
65 public:
66 // Declare public struct member variables.
67 unsigned int nX;
68 unsigned int nY;
69 };
70
71 public:
72 // Declare and define public struct member variables.
73 Corner CornerTL; // The top left corner of the bounding box.
74 Corner CornerTR; // The top right corner of the bounding box.
75 Corner CornerBL; // The bottom left corner of the bounding box.
76 Corner CornerBR; // The bottom right corner of bounding box.
77 int nClassNumber; // This info is passed through from your detection algorithm and will improve tracking be ensure the type of object remains the
78 float fConfidence; // This info is passed through from your detection algorithm and will help improve tracking by throwing out bad detections.
79 // 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
80 // to avoid issues.
81 bool bObjectRemainsOnFloorPlane = false;
82
83 // Declare and define public struct getters.
84 std::string GetObjectUUID() { return szObjectUUID; };
85 };
86
87
96 struct Pose
97 {
98 private:
99 // Declare struct for storing translation values.
101 {
102 public:
103 double dX; // Translation in ZED_MEASURE_UNITS on the x-axis.
104 double dY; // Translation in ZED_MEASURE_UNITS on the y-axis.
105 double dZ; // Translation in ZED_MEASURE_UNITS on the z-axis.
106 };
107
108 // Declare struct for storing rotation values.
110 {
111 public:
112 double dXO; // Rotation in degrees around the x-axis.
113 double dYO; // Rotation in degrees around the y-axis.
114 double dZO; // Rotation in degrees around the z-axis.
115 };
116
117 public:
118 // Declare struct public member variables.
119 Translation stTranslation;
120 EulerAngles stEulerAngles;
121
122
135 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)
136 {
137 // Initialize member variables.
138 stTranslation.dX = dX;
139 stTranslation.dY = dY;
140 stTranslation.dZ = dZ;
141 stEulerAngles.dXO = dXO;
142 stEulerAngles.dYO = dYO;
143 stEulerAngles.dZO = dZO;
144 }
145 };
146
148 // Declare public methods and member variables.
150
151
171 ZEDCamera(const int nPropResolutionX,
172 const int nPropResolutionY,
173 const int nPropFramesPerSecond,
174 const double dPropHorizontalFOV,
175 const double dPropVerticalFOV,
176 const bool bEnableRecordingFlag,
177 const bool bMemTypeGPU,
178 const bool bUseHalfDepthPrecision,
179 const bool bEnableFusionMaster,
180 const int nNumFrameRetrievalThreads,
181 const unsigned int unCameraSerialNumber) :
182 Camera(nPropResolutionX,
183 nPropResolutionY,
184 nPropFramesPerSecond,
185 PIXEL_FORMATS::eZED,
186 dPropHorizontalFOV,
187 dPropVerticalFOV,
188 bEnableRecordingFlag,
189 nNumFrameRetrievalThreads)
190 {
191 // Initialize member variables. Some parameters are not used.
192 (void) bMemTypeGPU;
193 (void) bUseHalfDepthPrecision;
194 (void) bEnableFusionMaster;
195 m_bCameraIsFusionMaster = bEnableFusionMaster;
196 m_unCameraSerialNumber = unCameraSerialNumber;
197 }
198
199
206 virtual ~ZEDCamera() = default;
207
208
219 std::future<bool> RequestFrameCopy(cv::Mat& cvFrame) override = 0;
220
221
230 virtual std::future<bool> RequestFrameCopy(cv::cuda::GpuMat& cvGPUFrame)
231 {
232 // Create instance variables.
233 (void) cvGPUFrame;
234 std::promise<bool> pmPromise;
235 std::future<bool> fuFuture = pmPromise.get_future();
236
237 // Immediately set the promise to false.
238 pmPromise.set_value(false);
239
240 // Submit logger message.
241 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestFrameCopy(cv::cuda::GpuMat& cvGPUFrame) not implemented. If SIM_MODE use cv::Mat version instead.");
242
243 return fuFuture;
244 }
245
246
256 virtual std::future<bool> RequestDepthCopy(cv::Mat& cvDepth, const bool bRetrieveMeasure = true) = 0;
257
258
268 virtual std::future<bool> RequestDepthCopy(cv::cuda::GpuMat& cvGPUDepth, const bool bRetrieveMeasure = true)
269 {
270 // Initialize instance variables.
271 (void) cvGPUDepth;
272 (void) bRetrieveMeasure;
273 std::promise<bool> pmPromise;
274
275 // Immediately set the promise to false.
276 pmPromise.set_value(false);
277
278 // Submit logger message.
279 LOG_ERROR(logging::g_qSharedLogger,
280 "ZEDCamera::RequestDepthCopy(cv::cuda::GpuMat& cvGPUDepth, const bool bRetrieveMeasure = true) not implemented. If SIM_MODE use cv::Mat version "
281 "instead.");
282
283 return pmPromise.get_future();
284 }
285
286
295 virtual std::future<bool> RequestPointCloudCopy(cv::Mat& cvPointCloud) = 0;
296
297
306 virtual std::future<bool> RequestPointCloudCopy(cv::cuda::GpuMat& cvGPUPointCloud)
307 {
308 // Initialize instance variables.
309 (void) cvGPUPointCloud;
310 std::promise<bool> pmPromise;
311
312 // Immediately set the promise to false.
313 pmPromise.set_value(false);
314
315 // Submit logger message.
316 LOG_ERROR(logging::g_qSharedLogger,
317 "ZEDCamera::RequestPointCloudCopy(cv::cuda::GpuMat& cvGPUPointCloud) not implemented. If SIM_MODE use cv::Mat version instead.");
318
319 return pmPromise.get_future();
320 }
321
322
330 virtual sl::ERROR_CODE ResetPositionalTracking() = 0;
331
332
341 virtual sl::ERROR_CODE TrackCustomBoxObjects(std::vector<ZedObjectData>& vCustomObjects)
342 {
343 // Initialize instance variables.
344 (void) vCustomObjects;
345
346 // Submit logger message.
347 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::TrackCustomBoxObjects(const std::vector<ZedObjectData>& vCustomObjects) not implemented.");
348
349 return sl::ERROR_CODE::FAILURE;
350 }
351
352
360 virtual sl::ERROR_CODE RebootCamera() = 0;
361
362
371 virtual sl::FUSION_ERROR_CODE SubscribeFusionToCameraUUID(sl::CameraIdentifier& slCameraUUID) = 0;
372
373
381 virtual sl::CameraIdentifier PublishCameraToFusion() = 0;
382
383
392 virtual sl::FUSION_ERROR_CODE IngestGPSDataToFusion(geoops::GPSCoordinate stNewGPSLocation)
393 {
394 // Initialize instance variables.
395 (void) stNewGPSLocation;
396
397 // Submit logger message.
398 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::IngestGPSDataToFusion(geoops::GPSCoordinate stNewGPSLocation) not implemented.");
399
400 return sl::FUSION_ERROR_CODE::FAILURE;
401 }
402
404 // Setters for class member variables.
406
407
416 virtual sl::ERROR_CODE EnablePositionalTracking(const float fExpectedCameraHeightFromFloorTolerance = constants::ZED_DEFAULT_FLOOR_PLANE_ERROR) = 0;
417
418
425 virtual void DisablePositionalTracking() = 0;
426
427
440 virtual void SetPositionalPose(const double dX, const double dY, const double dZ, const double dXO, const double dYO, const double dZO) = 0;
441
442
450 virtual sl::ERROR_CODE EnableSpatialMapping()
451 {
452 // Submit logger message.
453 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::EnableSpatialMapping() not implemented.");
454
455 return sl::ERROR_CODE::FAILURE;
456 }
457
458
466 {
467 // Submit logger message.
468 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::DisableSpatialMapping() not implemented.");
469 }
470
471
480 virtual sl::ERROR_CODE EnableObjectDetection(const bool bEnableBatching = false)
481 {
482 // Initialize instance variables.
483 (void) bEnableBatching;
484
485 // Submit logger message.
486 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::EnableObjectDetection(const bool bEnableBatching = false) not implemented.");
487
488 return sl::ERROR_CODE::FAILURE;
489 }
490
491
499 {
500 // Submit logger message.
501 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::DisableObjectDetection() not implemented.");
502 }
503
505 // Accessors for class member variables.
507
508
517 virtual bool GetUsingGPUMem() const { return false; }
518
519
528 virtual bool GetIsFusionMaster() const { return m_bCameraIsFusionMaster; }
529
530
538 virtual std::string GetCameraModel() = 0;
539
540
548 virtual unsigned int GetCameraSerial() { return m_unCameraSerialNumber; };
549
550
559 virtual std::future<bool> RequestPositionalPoseCopy(Pose& stPose) = 0;
560
561
570 virtual std::future<bool> RequestFusionGeoPoseCopy(sl::GeoPose& slGeoPose) = 0;
571
572
581 virtual std::future<bool> RequestFloorPlaneCopy(sl::Plane& slFloorPlane)
582 {
583 // Initialize instance variables.
584 (void) slFloorPlane;
585 std::promise<bool> pmPromise;
586
587 // Immediately set the promise to false.
588 pmPromise.set_value(false);
589
590 // Submit logger message.
591 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestFloorPlaneCopy(sl::Plane& slFloorPlane) not implemented.");
592
593 return pmPromise.get_future();
594 }
595
596
606
607
615 virtual sl::PositionalTrackingStatus GetPositionalTrackingState()
616 {
617 // Initialize instance variable.
618 sl::PositionalTrackingStatus stStatus;
619
620 // Submit logger message.
621 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::GetPositionalTrackingState() not implemented.");
622
623 return stStatus;
624 }
625
626
634 virtual sl::FusedPositionalTrackingStatus GetFusedPositionalTrackingState()
635 {
636 // Initialize instance variable.
637 sl::FusedPositionalTrackingStatus stStatus;
638
639 // Submit logger message.
640 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::GetFusedPositionalTrackingState() not implemented.");
641
642 return stStatus;
643 }
644
645
653 virtual sl::SPATIAL_MAPPING_STATE GetSpatialMappingState() { return sl::SPATIAL_MAPPING_STATE::NOT_ENABLED; }
654
655
664 virtual sl::SPATIAL_MAPPING_STATE ExtractSpatialMapAsync(std::future<sl::Mesh>& fuMeshFuture)
665 {
666 // Initialize instance variables.
667 (void) fuMeshFuture;
668
669 // Submit logger message.
670 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::ExtractSpatialMapAsync(std::future<sl::Mesh>& fuMeshFuture) not implemented.");
671
672 return sl::SPATIAL_MAPPING_STATE::NOT_ENABLED;
673 }
674
675
684 virtual bool GetObjectDetectionEnabled() { return false; }
685
686
695 virtual std::future<bool> RequestObjectsCopy(std::vector<sl::ObjectData>& vObjectData)
696 {
697 // Initialize instance variables.
698 (void) vObjectData;
699 std::promise<bool> pmPromise;
700
701 // Immediately set the promise to false.
702 pmPromise.set_value(false);
703
704 // Submit logger message.
705 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestObjectsCopy(std::vector<sl::ObjectData>& vObjectData) not implemented.");
706
707 return pmPromise.get_future();
708 }
709
710
719 virtual std::future<bool> RequestBatchedObjectsCopy(std::vector<sl::ObjectsBatch>& vBatchedObjectData)
720 {
721 // Initialize instance variables.
722 (void) vBatchedObjectData;
723 std::promise<bool> pmPromise;
724
725 // Immediately set the promise to false.
726 pmPromise.set_value(false);
727
728 // Submit logger message.
729 LOG_ERROR(logging::g_qSharedLogger, "ZEDCamera::RequestBatchedObjectsCopy(std::vector<sl::ObjectsBatch>& vBatchedObjectData) not implemented.");
730
731 return pmPromise.get_future();
732 }
733
734 protected:
736 // Declare class constants.
738
739 const std::memory_order ATOMIC_MEMORY_ORDER_METHOD = std::memory_order_relaxed;
740
742 // Declare protected member variables.
744
745 // ZED Camera specific.
746 unsigned int m_unCameraSerialNumber;
747 bool m_bCameraIsFusionMaster;
748
749 private:
751 // Declare private member variables.
753};
754
755#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:664
virtual unsigned int GetCameraSerial()
Accessor for the Camera Serial private member.
Definition ZEDCamera.hpp:548
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:719
virtual sl::CameraIdentifier PublishCameraToFusion()=0
Publishes the camera to the fusion object.
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:695
virtual bool GetIsFusionMaster() const
Accessor for if this ZED is running a fusion instance.
Definition ZEDCamera.hpp:528
virtual void DisablePositionalTracking()=0
Disables the position tracking of the camera.
virtual sl::FUSION_ERROR_CODE SubscribeFusionToCameraUUID(sl::CameraIdentifier &slCameraUUID)=0
Subscribes the fusion object to the camera with the given UUID.
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:465
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:581
virtual ~ZEDCamera()=default
Destroy the ZEDCamera object.
virtual sl::PositionalTrackingStatus GetPositionalTrackingState()
Accessor for the Positional Tracking State private member.
Definition ZEDCamera.hpp:615
virtual sl::ERROR_CODE EnableObjectDetection(const bool bEnableBatching=false)
Enables object detection.
Definition ZEDCamera.hpp:480
virtual sl::ERROR_CODE EnableSpatialMapping()
Enables spatial mapping.
Definition ZEDCamera.hpp:450
virtual sl::FUSION_ERROR_CODE IngestGPSDataToFusion(geoops::GPSCoordinate stNewGPSLocation)
Ingests GPS data into the fusion object.
Definition ZEDCamera.hpp:392
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:268
virtual bool GetUsingGPUMem() const
Accessor for the Using G P U Memory private member.
Definition ZEDCamera.hpp:517
virtual sl::ERROR_CODE TrackCustomBoxObjects(std::vector< ZedObjectData > &vCustomObjects)
Tracks custom bounding boxes in the camera's field of view.
Definition ZEDCamera.hpp:341
virtual std::future< bool > RequestFusionGeoPoseCopy(sl::GeoPose &slGeoPose)=0
Puts a GeoPose pointer into a queue so a copy of a GeoPose from the camera can be written to it.
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:230
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 bool bEnableFusionMaster, const int nNumFrameRetrievalThreads, const unsigned int unCameraSerialNumber)
Construct a new ZEDCamera object.
Definition ZEDCamera.hpp:171
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:306
virtual void DisableObjectDetection()
Disables object detection.
Definition ZEDCamera.hpp:498
virtual bool GetObjectDetectionEnabled()
Accessor for the Object Detection Enabled private member.
Definition ZEDCamera.hpp:684
std::future< bool > RequestFrameCopy(cv::Mat &cvFrame) override=0
virtual sl::FusedPositionalTrackingStatus GetFusedPositionalTrackingState()
Accessor for the Fused Positional Tracking State private member.
Definition ZEDCamera.hpp:634
virtual sl::SPATIAL_MAPPING_STATE GetSpatialMappingState()
Accessor for the Spatial Mapping State private member.
Definition ZEDCamera.hpp:653
Definition ZEDCamera.hpp:110
Definition ZEDCamera.hpp:101
This struct is used within the ZEDCam class to store the camera pose with high precision....
Definition ZEDCamera.hpp:97
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:135
This struct is internal to the ZedObjectData struct is used to store an X and Y value for the corners...
Definition ZEDCamera.hpp:64
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
This struct stores/contains information about a GPS data.
Definition GeospatialOperations.hpp:148