Skip to content

Instantly share code, notes, and snippets.

@UnaNancyOwen
Last active December 16, 2018 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UnaNancyOwen/4667cd86d7079eacd6da55baafaa3ad4 to your computer and use it in GitHub Desktop.
Save UnaNancyOwen/4667cd86d7079eacd6da55baafaa3ad4 to your computer and use it in GitHub Desktop.
/*
DESCRIPTION:
query_motion_devices() is returns a list of all devices that have motion sensors.
HOWTOUSE:
std::vector<rs2::device> motion_devices;
query_motion_devices( motion_devices );
if( motion_devices.empty ){
throw std::runtime_error( "could not find devices that have motion sensors." );
return -1;
}
rs2::config config;
const std::string serial_number = devices.front().get_info( rs2_camera_info::RS2_CAMERA_INFO_SERIAL_NUMBER );
config.enable_device( serial_number );
rs2::pipeline pipeline;
pipeline.start( config );
*/
#ifndef __QUERY_MOTION_DEVICES__
#define __QUERY_MOTION_DEVICES__
#include <librealsense2/rs.hpp>
#include <vector>
void query_motion_devices( std::vector<rs2::device>& motion_devices )
{
rs2::context context;
const rs2::device_list device_list = context.query_devices( RS2_PRODUCT_LINE_ANY_INTEL );
for( const rs2::device& device : device_list ){
const std::vector<rs2::sensor> sensors = device.query_sensors();
for( const rs2::sensor& sensor : sensors ){
const std::vector<rs2::stream_profile> profiles = sensor.get_stream_profiles();
for( const rs2::stream_profile& profile : profiles ){
if( profile.is<rs2::motion_stream_profile>() ){
motion_devices.push_back( device );
}
}
}
}
}
#endif // __QUERY_MOTION_DEVICES__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment