ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
sensorcapture_def.hpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2021, STEREOLABS.
4 //
5 // All rights reserved.
6 //
7 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
8 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
9 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
10 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
11 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
14 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
15 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
16 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
17 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 //
20 
21 #ifndef SENSORCAPTURE_DEF_HPP
22 #define SENSORCAPTURE_DEF_HPP
23 
24 #define DEFAULT_GRAVITY (9.8189f)
25 #define ACC_SCALE (DEFAULT_GRAVITY*(8.0f/32768.0f))
26 #define GYRO_SCALE (1000.0f/32768.0f)
27 #define MAG_SCALE (1.0f/16.0f)
28 #define TEMP_SCALE (0.01f)
29 #define PRESS_SCALE_NEW (0.0001f) // FM >= V3.9
30 #define PRESS_SCALE_OLD (0.01f) // FW < v3.9
31 #define HUMID_SCALE_NEW (0.01f) // FM >= V3.9
32 #define HUMID_SCALE_OLD (1.0f/1024.0f) // FW < v3.9
33 
34 #define TS_SCALE (39062.5f)
35 #define TEMP_NOT_VALID (-27315)
36 
37 #include "defines.hpp"
38 
39 namespace sl_oc {
40 
41 namespace sensors {
42 
43 namespace usb {
44 
48 typedef enum CUSTOMHID_REPORT_ID {
49  // Input Reports
51 
52  // Generic commands
54 
55  // OV580
57 
58  // Features Reports
60 
62 
66 typedef enum CUSTOMHID_REQUEST_ID {
67  RQ_CMD_PING = 0xF2,
68  RQ_CMD_RST = 0xE1,
69  OV580_CMD_RESET = 0x02
71 
72 #pragma pack(push) // push current alignment to stack
73 #pragma pack(1) // set alignment to 1 byte boundary
74 
78 typedef struct RawData {
79  uint8_t struct_id;
80  uint8_t imu_not_valid;
81  uint64_t timestamp;
82  int16_t gX;
83  int16_t gY;
84  int16_t gZ;
85  int16_t aX;
86  int16_t aY;
87  int16_t aZ;
88  uint8_t frame_sync;
90  uint32_t frame_sync_count;
91  int16_t imu_temp;
92  uint8_t mag_valid;
93  int16_t mX;
94  int16_t mY;
95  int16_t mZ;
96  uint8_t camera_moving;
98  uint8_t camera_falling;
100  uint8_t env_valid;
101  int16_t temp;
102  uint32_t press;
103  uint32_t humid;
104  int16_t temp_cam_left;
105  int16_t temp_cam_right;
107 
111 typedef struct StreamStatus {
112  uint8_t struct_id;
113  uint8_t stream_status;
115 
119 typedef struct _ov580_cmd_struct {
120  uint8_t struct_id;
121  uint8_t cmd;
122  uint16_t info;
124 
125 #pragma pack(pop) // Restore previous saved alignment
126 
127 }
128 
129 // ----> FW versions
130 enum class ZED_M_FW {
131  FW_2_2 = 514,
132  FW_2_3 = 515,
133  FW_2_4 = 516,
134  FW_2_5 = 517,
135  LAST
136 };
137 
138 enum class ZED_2_FW {
139  FW_3_4 = 772,
140  FW_3_5 = 773,
141  FW_3_6 = 774,
142  FW_3_7 = 775,
143  FW_3_8 = 776,
144  FW_3_9 = 777,
145  FW_3_10 = 778
146 };
147 
154 inline bool atLeast(const int &version_current, const ZED_2_FW &version_required) {
155  return (version_current >= static_cast<int>(version_required));
156 }
157 
164 inline bool atLeast(const int &version_current, const ZED_M_FW &version_required) {
165  return (version_current >= static_cast<int>(version_required));
166 }
167 // <---- FW versions
168 
169 
170 #define NTP_ADJUST_CT 1
171 const size_t TS_SHIFT_VAL_COUNT = 50;
172 
173 }
174 
175 }
176 
182 inline std::string wstr2str( const wchar_t* wstr)
183 {
184  if(wstr==NULL)
185  return std::string();
186 
187  try
188  {
189  std::wstring ws( wstr );
190  std::string str( ws.begin(), ws.end() );
191  return str;
192  }
193  catch(...)
194  {
195  std::cerr << "Failure reading USB data. Please install the udev rules available in the `udev` folder" << std::endl;
196  exit(-1);
197  }
198 
199  return std::string();
200 }
201 
202 
203 
204 #endif // SENSORCAPTURE_DEF_HPP
CUSTOMHID_REQUEST_ID
USB HID requests IDs.
@ RQ_CMD_PING
Command to ping the MCU to communicate that host is alive.
@ OV580_CMD_RESET
Command to reset the OV580 using the MCU.
@ RQ_CMD_RST
Command to reset the MCU.
struct sl_oc::sensors::usb::_ov580_cmd_struct OV580CmdStruct
OV580 control using the MCU.
CUSTOMHID_REPORT_ID
USB HID communication report IDs.
@ REP_ID_SENSOR_STREAM_STATUS
Stream Status report ID.
@ REP_ID_OV580_CMD
OV580 control request.
@ REP_ID_REQUEST_SET
USB Request report ID.
@ REP_ID_SENSOR_DATA
Sensor data report ID.
struct sl_oc::sensors::usb::StreamStatus StreamStatus
Status of the usb data streaming.
struct sl_oc::sensors::usb::RawData RawData
The RAW sensor data structure retrieved from camera MCU by USB.
const size_t TS_SHIFT_VAL_COUNT
Number of sensor data to use to update timestamp scaling.
bool atLeast(const int &version_current, const ZED_2_FW &version_required)
Check firmware version for ZED2 camera.
@ FW_2_3
ZED Mini v2.3.
@ FW_2_2
ZED Mini v2.2.
@ FW_2_4
ZED Mini v2.4 (not released)
@ FW_2_5
ZED Mini v2.5.
std::string wstr2str(const wchar_t *wstr)
Convert a wchar array to std::string.
uint8_t cmd
command to be sent to OV580: OV580_RESET
uint8_t struct_id
struct identifier for HID comm
The RAW sensor data structure retrieved from camera MCU by USB.
int16_t imu_temp
Temperature from the IMU sensor [0.01 °C].
int16_t temp
Temperature [0.01 °C].
int16_t aX
Raw Accelerometer X.
uint64_t timestamp
Data timestamp (from IMU sensor) [usec/39].
int16_t gX
Raw Gyroscope X.
int16_t temp_cam_left
Temperature of the left camera sensor [0.01 °C].
uint8_t camera_moving
Indicate if the camera is moving (uses BMI internal HW)
int16_t aY
Raw Accelerometer Y.
uint32_t press
Pressure [0.01 hPa].
uint32_t frame_sync_count
Counts the number of synced frames.
int16_t temp_cam_right
Temperature of the right camera sensor [0.01 °C].
uint8_t sync_capabilities
Indicates if frame synchronization is active.
uint32_t humid
Relative humidity [1.0/1024.0 rH].
uint8_t imu_not_valid
Indicate if IMU data are valid [0->valid, 1->not_valid].
uint8_t frame_sync
Indicates if data are synced to a camera frame.
uint32_t camera_moving_count
Counts the number of camera moving interrupts.
uint8_t struct_id
Struct identifier, it matches the USB HID Report ID.
int16_t mZ
Raw Magnetometer Z.
int16_t mX
Raw Magnetometer X.
uint32_t camera_falling_count
Counts the number of camera falling interrupts.
int16_t aZ
Raw Accelerometer Z.
int16_t gZ
Raw Gyroscope Z.
int16_t gY
Raw Gyroscope Y.
uint8_t camera_falling
Indicate if the camera is free falling (uses BMI internal HW)
uint8_t env_valid
Indicate if Environmental data are valid (put to ENV_SENS_NOT_PRESENT if no environmental sensor is p...
uint8_t mag_valid
Indicates if Magnetometer data are valid (put to 0 if no magnetometer is present)
int16_t mY
Raw Magnetometer Y.
Status of the usb data streaming.
uint8_t stream_status
Status of the USB streaming.
uint8_t struct_id
Struct identifier, it matches the USB HID Report ID.