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

Example of how to use the SensorCapture class to get the raw sensors data at the maximum available frequency.

//
// Copyright (c) 2021, STEREOLABS.
//
// All rights reserved.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ----> Includes
#include <unistd.h> // for usleep
#include <iostream>
#include <iomanip>
// <---- Includes
// The main function
int main(int argc, char *argv[])
{
// ----> Silence unused warning
(void)argc;
(void)argv;
// <---- Silence unused warning
// Set the verbose level
// Create a SensorCapture object
// ----> Get a list of available camera with sensor
std::vector<int> devs = sens.getDeviceList();
if( devs.size()==0 )
{
std::cerr << "No available ZED Mini or ZED2 cameras" << std::endl;
return EXIT_FAILURE;
}
// <---- Get a list of available camera with sensor
// ----> Inizialize the sensors
if( !sens.initializeSensors( devs[0] ) )
{
std::cerr << "Connection failed" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Sensor Capture connected to camera sn: " << sens.getSerialNumber() << std::endl;
// <---- Inizialize the sensors
// ----> Get FW version information
uint16_t fw_maior;
uint16_t fw_minor;
sens.getFirmwareVersion( fw_maior, fw_minor );
std::cout << " * Firmware version: " << std::to_string(fw_maior) << "." << std::to_string(fw_minor) << std::endl;
// <---- Get FW version information
// ----> Variables to calculate sensors frequencies
uint64_t last_imu_ts = 0;
uint64_t last_mag_ts = 0;
uint64_t last_env_ts = 0;
uint64_t last_cam_temp_ts = 0;
// <---- Variables to calculate sensors frequencies
// Lets grab 4000 sensors data (about 10 seconds
int count = 0;
while(++count<4000)
{
// ----> Get IMU data with a timeout of 5 millisecods
const sl_oc::sensors::data::Imu imuData = sens.getLastIMUData(5000);
{
std::cout << "**** New IMU data ****" << std::endl;
std::cout << " * Timestamp: " << imuData.timestamp << " nsec" << std::endl;
if(last_imu_ts!=0)
{
std::cout << " * Frequency: " << 1e9/static_cast<float>(imuData.timestamp-last_imu_ts) << " Hz" << std::endl;
}
last_imu_ts = imuData.timestamp;
std::cout << " * Accelerations [m/s²]: " << imuData.aX << " " << imuData.aY << " " << imuData.aZ << std::endl;
std::cout << " * Angular Velocities [°/s]: " << imuData.gX << " " << imuData.gY << " " << imuData.gZ << std::endl;
}
// <---- Get IMU data with a timeout of 5 millisecods
// ----> Get Magnetometer data with a timeout of 100 microseconds to not slow down fastest data (IMU)
{
std::cout << "**** New Magnetometer data ****" << std::endl;
std::cout << " * Timestamp: " << magData.timestamp << " nsec" << std::endl;
if(last_mag_ts!=0)
{
std::cout << " * Frequency: " << 1e9/static_cast<float>(magData.timestamp-last_mag_ts) << " Hz" << std::endl;
}
last_mag_ts = magData.timestamp;
std::cout << " * Magnetic field [uT]: " << magData.mX << " " << magData.mY << " " << magData.mZ << std::endl;
}
// <---- Get Magnetometer data with a timeout of 100 microseconds to not slow down fastest data (IMU)
// ----> Get Environment data with a timeout of 100 microseconds to not slow down fastest data (IMU)
{
std::cout << "**** New Environment data ****" << std::endl;
std::cout << " * Timestamp: " << envData.timestamp << " nsec" << std::endl;
if(last_env_ts!=0)
{
std::cout << " * Frequency: " << 1e9/static_cast<float>(envData.timestamp-last_env_ts) << " Hz" << std::endl;
}
last_env_ts = envData.timestamp;
std::cout << " * Pressure [hPa]: " << envData.press << std::endl;
std::cout << " * Temperature [°C]: " << envData.temp << std::endl;
std::cout << " * Relative Humidity [%rH]: " << envData.humid << std::endl;
}
// <---- Get Environment data with a timeout of 100 microseconds to not slow down fastest data (IMU)
// ----> Get Temperature data with a timeout of 100 microseconds to not slow down fastest data (IMU)
{
std::cout << "**** New Camera Sensors Temperature data ****" << std::endl;
std::cout << " * Timestamp: " << tempData.timestamp << " nsec" << std::endl;
if(last_cam_temp_ts!=0)
{
std::cout << " * Frequency: " << 1e9/static_cast<float>(tempData.timestamp-last_cam_temp_ts) << " Hz" << std::endl;
}
last_cam_temp_ts = tempData.timestamp;
std::cout << " * Left Camera [°C]: " << tempData.temp_left << std::endl;
std::cout << " * Right Camera [°C]: " << tempData.temp_right << std::endl;
}
// <---- Get Temperature data with a timeout of 100 microseconds to not slow down fastest data (IMU)
}
return EXIT_SUCCESS;
}
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[])