ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Functions
zed_oc_sensors_example.cpp File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
zed_oc_sensors_example.cpp.

Definition at line 30 of file zed_oc_sensors_example.cpp.

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)
100  const sl_oc::sensors::data::Magnetometer magData = sens.getLastMagnetometerData(100);
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)
115  const sl_oc::sensors::data::Environment envData = sens.getLastEnvironmentData(100);
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)
132  const sl_oc::sensors::data::Temperature tempData = sens.getLastCameraTemperatureData(100);
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...
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.

References sl_oc::sensors::data::Imu::aX, sl_oc::sensors::data::Imu::aY, sl_oc::sensors::data::Imu::aZ, sl_oc::sensors::SensorCapture::getDeviceList(), sl_oc::sensors::SensorCapture::getFirmwareVersion(), sl_oc::sensors::SensorCapture::getLastCameraTemperatureData(), sl_oc::sensors::SensorCapture::getLastEnvironmentData(), sl_oc::sensors::SensorCapture::getLastIMUData(), sl_oc::sensors::SensorCapture::getLastMagnetometerData(), sl_oc::sensors::SensorCapture::getSerialNumber(), sl_oc::sensors::data::Imu::gX, sl_oc::sensors::data::Imu::gY, sl_oc::sensors::data::Imu::gZ, sl_oc::sensors::data::Environment::humid, sl_oc::INFO, sl_oc::sensors::SensorCapture::initializeSensors(), sl_oc::sensors::data::Magnetometer::mX, sl_oc::sensors::data::Magnetometer::mY, sl_oc::sensors::data::Magnetometer::mZ, sl_oc::sensors::data::Imu::NEW_VAL, sl_oc::sensors::data::Magnetometer::NEW_VAL, sl_oc::sensors::data::Environment::NEW_VAL, sl_oc::sensors::data::Temperature::NEW_VAL, sl_oc::sensors::data::Environment::press, sl_oc::sensors::data::Environment::temp, sl_oc::sensors::data::Temperature::temp_left, sl_oc::sensors::data::Temperature::temp_right, sl_oc::sensors::data::Imu::timestamp, sl_oc::sensors::data::Magnetometer::timestamp, sl_oc::sensors::data::Environment::timestamp, sl_oc::sensors::data::Temperature::timestamp, sl_oc::sensors::data::Imu::valid, sl_oc::sensors::data::Magnetometer::valid, sl_oc::sensors::data::Environment::valid, and sl_oc::sensors::data::Temperature::valid.