ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
zed_oc_sensors_example.cpp
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 // ----> Includes
22 #include "sensorcapture.hpp"
23 
24 #include <unistd.h> // for usleep
25 #include <iostream>
26 #include <iomanip>
27 // <---- Includes
28 
29 // The main function
30 int main(int argc, char *argv[])
31 {
32  // ----> Silence unused warning
33  (void)argc;
34  (void)argv;
35  // <---- Silence unused warning
36 
37  // Set the verbose level
39 
40  // Create a SensorCapture object
41  sl_oc::sensors::SensorCapture sens(verbose);
42 
43  // ----> Get a list of available camera with sensor
44  std::vector<int> devs = sens.getDeviceList();
45 
46  if( devs.size()==0 )
47  {
48  std::cerr << "No available ZED Mini or ZED2 cameras" << std::endl;
49  return EXIT_FAILURE;
50  }
51  // <---- Get a list of available camera with sensor
52 
53  // ----> Inizialize the sensors
54  if( !sens.initializeSensors( devs[0] ) )
55  {
56  std::cerr << "Connection failed" << std::endl;
57  return EXIT_FAILURE;
58  }
59 
60  std::cout << "Sensor Capture connected to camera sn: " << sens.getSerialNumber() << std::endl;
61  // <---- Inizialize the sensors
62 
63  // ----> Get FW version information
64  uint16_t fw_maior;
65  uint16_t fw_minor;
66 
67  sens.getFirmwareVersion( fw_maior, fw_minor );
68 
69  std::cout << " * Firmware version: " << std::to_string(fw_maior) << "." << std::to_string(fw_minor) << std::endl;
70  // <---- Get FW version information
71 
72  // ----> Variables to calculate sensors frequencies
73  uint64_t last_imu_ts = 0;
74  uint64_t last_mag_ts = 0;
75  uint64_t last_env_ts = 0;
76  uint64_t last_cam_temp_ts = 0;
77  // <---- Variables to calculate sensors frequencies
78 
79  // Lets grab 4000 sensors data (about 10 seconds
80  int count = 0;
81  while(++count<4000)
82  {
83  // ----> Get IMU data with a timeout of 5 millisecods
84  const sl_oc::sensors::data::Imu imuData = sens.getLastIMUData(5000);
86  {
87  std::cout << "**** New IMU data ****" << std::endl;
88  std::cout << " * Timestamp: " << imuData.timestamp << " nsec" << std::endl;
89  if(last_imu_ts!=0)
90  {
91  std::cout << " * Frequency: " << 1e9/static_cast<float>(imuData.timestamp-last_imu_ts) << " Hz" << std::endl;
92  }
93  last_imu_ts = imuData.timestamp;
94  std::cout << " * Accelerations [m/s²]: " << imuData.aX << " " << imuData.aY << " " << imuData.aZ << std::endl;
95  std::cout << " * Angular Velocities [°/s]: " << imuData.gX << " " << imuData.gY << " " << imuData.gZ << std::endl;
96  }
97  // <---- Get IMU data with a timeout of 5 millisecods
98 
99  // ----> Get Magnetometer data with a timeout of 100 microseconds to not slow down fastest data (IMU)
102  {
103  std::cout << "**** New Magnetometer data ****" << std::endl;
104  std::cout << " * Timestamp: " << magData.timestamp << " nsec" << std::endl;
105  if(last_mag_ts!=0)
106  {
107  std::cout << " * Frequency: " << 1e9/static_cast<float>(magData.timestamp-last_mag_ts) << " Hz" << std::endl;
108  }
109  last_mag_ts = magData.timestamp;
110  std::cout << " * Magnetic field [uT]: " << magData.mX << " " << magData.mY << " " << magData.mZ << std::endl;
111  }
112  // <---- Get Magnetometer data with a timeout of 100 microseconds to not slow down fastest data (IMU)
113 
114  // ----> Get Environment data with a timeout of 100 microseconds to not slow down fastest data (IMU)
117  {
118  std::cout << "**** New Environment data ****" << std::endl;
119  std::cout << " * Timestamp: " << envData.timestamp << " nsec" << std::endl;
120  if(last_env_ts!=0)
121  {
122  std::cout << " * Frequency: " << 1e9/static_cast<float>(envData.timestamp-last_env_ts) << " Hz" << std::endl;
123  }
124  last_env_ts = envData.timestamp;
125  std::cout << " * Pressure [hPa]: " << envData.press << std::endl;
126  std::cout << " * Temperature [°C]: " << envData.temp << std::endl;
127  std::cout << " * Relative Humidity [%rH]: " << envData.humid << std::endl;
128  }
129  // <---- Get Environment data with a timeout of 100 microseconds to not slow down fastest data (IMU)
130 
131  // ----> Get Temperature data with a timeout of 100 microseconds to not slow down fastest data (IMU)
134  {
135  std::cout << "**** New Camera Sensors Temperature data ****" << std::endl;
136  std::cout << " * Timestamp: " << tempData.timestamp << " nsec" << std::endl;
137  if(last_cam_temp_ts!=0)
138  {
139  std::cout << " * Frequency: " << 1e9/static_cast<float>(tempData.timestamp-last_cam_temp_ts) << " Hz" << std::endl;
140  }
141  last_cam_temp_ts = tempData.timestamp;
142  std::cout << " * Left Camera [°C]: " << tempData.temp_left << std::endl;
143  std::cout << " * Right Camera [°C]: " << tempData.temp_right << std::endl;
144  }
145  // <---- Get Temperature data with a timeout of 100 microseconds to not slow down fastest data (IMU)
146  }
147 
148  return EXIT_SUCCESS;
149 }
The SensorCapture class provides sensor grabbing functions for the Stereolabs ZED Mini and ZED2 camer...
int getSerialNumber()
Retrieve the serial number of the connected camera.
std::vector< int > getDeviceList(bool refresh=false)
Get the list of the serial number of all the available devices.
bool initializeSensors(int sn=-1)
Open a connection to the MCU of a ZED Mini or a ZED2 camera using the specified serial number or sear...
void getFirmwareVersion(uint16_t &fw_major, uint16_t &fw_minor)
Get the MCU firmware version in form [fw_major].[fw_minor].
const data::Imu & getLastIMUData(uint64_t timeout_usec=1500)
Get the last received IMU data.
const data::Magnetometer & getLastMagnetometerData(uint64_t timeout_usec=100)
Get the last received Magnetometer data.
const data::Temperature & getLastCameraTemperatureData(uint64_t timeout_usec=100)
Get the last received camera sensors temperature data.
const data::Environment & getLastEnvironmentData(uint64_t timeout_usec=100)
Get the last received Environment data.
VERBOSITY
Definition: defines.hpp:85
@ INFO
Definition: defines.hpp:89
Contains the acquired Environment data.
float press
Atmospheric pressure in hPa.
float temp
Sensor temperature in °C.
EnvStatus valid
Indicates if Environmental data are valid.
uint64_t timestamp
Timestamp in nanoseconds.
Contains the acquired Imu data.
float gX
Angular velocity around X axis in °/s.
float aX
Acceleration along X axis in m/s²
ImuStatus valid
Indicates if IMU data are valid.
uint64_t timestamp
Timestamp in nanoseconds.
float gZ
Angular velocity around > axis in °/s.
float gY
Angular velocity around Y axis in °/s.
float aY
Acceleration along Y axis in m/s²
float aZ
Acceleration along Z axis in m/s²
Contains the acquired Magnetometer data.
float mY
Acceleration along Y axis in uT.
float mX
Acceleration along X axis in uT.
MagStatus valid
Indicates if Magnetometer data are valid.
uint64_t timestamp
Timestamp in nanoseconds.
float mZ
Acceleration along Z axis in uT.
Contains the acquired Camera Temperature data.
float temp_right
Temperature of the right CMOS camera sensor.
uint64_t timestamp
Timestamp in nanoseconds.
float temp_left
Temperature of the left CMOS camera sensor.
TempStatus valid
Indicates if camera temperature data are valid.
int main(int argc, char *argv[])