Skip to content

Commit

Permalink
PR #13734 from OhadMeir: Fix examples for D555
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir authored Feb 3, 2025
2 parents d25d198 + d0f24d2 commit 818c156
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
5 changes: 3 additions & 2 deletions examples/C/depth/rs-depth.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ float get_depth_unit_value(const rs2_device* const dev)
int num_of_sensors = rs2_get_sensors_count(sensor_list, &e);
check_error(e);

float depth_scale = 0;
float depth_scale = 0.001f; // Default to mm
int is_depth_sensor_found = 0;
int i;
for (i = 0; i < num_of_sensors; ++i)
Expand All @@ -50,7 +50,8 @@ float get_depth_unit_value(const rs2_device* const dev)

if (1 == is_depth_sensor_found)
{
depth_scale = rs2_get_option((const rs2_options*)sensor, RS2_OPTION_DEPTH_UNITS, &e);
if( rs2_supports_option((const rs2_options*)sensor, RS2_OPTION_DEPTH_UNITS, &e) )
depth_scale = rs2_get_option((const rs2_options*)sensor, RS2_OPTION_DEPTH_UNITS, &e);
check_error(e);
rs2_delete_sensor(sensor);
break;
Expand Down
53 changes: 39 additions & 14 deletions examples/motion/rs-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ class rotation_estimator
}
};


bool check_imu_is_supported()
bool check_accel_gyro_are_supported()
{
bool found_gyro = false;
bool found_accel = false;
Expand All @@ -218,13 +217,48 @@ bool check_imu_is_supported()
return found_gyro && found_accel;
}

bool check_combined_motion_is_supported()
{
rs2::context ctx;

for (auto dev : ctx.query_devices())
{
for (auto sensor : dev.query_sensors())
{
for (auto profile : sensor.get_stream_profiles())
{
if (profile.stream_type() == RS2_STREAM_MOTION)
return true;
}
}
}

return false;
}

int main(int argc, char * argv[]) try
{
// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
// Create a configuration for configuring the pipeline with a non default profile
rs2::config cfg;

// Before running the example, check that a device supporting IMU is connected
if (!check_imu_is_supported())
if (check_accel_gyro_are_supported())
{
// Add streams of gyro and accelerometer to configuration
cfg.enable_stream(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
cfg.enable_stream(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);
}
else if (check_combined_motion_is_supported())
{
std::cerr << "Device supporting IMU not found";
return EXIT_FAILURE;
// Add combined gyro and accelerometer to configuration
cfg.enable_stream(RS2_STREAM_MOTION, RS2_FORMAT_COMBINED_MOTION);
}
else
{
std::cerr << "Device supporting IMU not found";
return EXIT_FAILURE;
}

// Initialize window for rendering
Expand All @@ -234,15 +268,6 @@ int main(int argc, char * argv[]) try
// Register callbacks to allow manipulation of the view state
register_glfw_callbacks(app, app_state);

// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
// Create a configuration for configuring the pipeline with a non default profile
rs2::config cfg;

// Add streams of gyro and accelerometer to configuration
cfg.enable_stream(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F);
cfg.enable_stream(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F);

// Declare object for rendering camera motion
camera_renderer camera;
// Declare object that handles camera pose calculations
Expand Down
19 changes: 16 additions & 3 deletions examples/sensor-control/api_how_to.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,16 @@ class how_to
std::cout << " Description : " << description << std::endl;

// Get the current value of the option
float current_value = sensor.get_option(option_type);
std::cout << " Current Value : " << current_value << std::endl;

if (option_type != RS2_OPTION_REGION_OF_INTEREST)
{
float current_value = sensor.get_option(option_type);
std::cout << " Current Value : " << current_value << std::endl;
}
else
{
rs2_option_rect current_value = sensor.get_option_value(option_type)->as_rect;
std::cout << " Current Value : [(" << current_value.x1 << "," << current_value.y1 << "), (" << current_value.x2 << "," << current_value.y2 << ")]" << std::endl;
}
//To change the value of an option, please follow the change_sensor_option() function
}
else
Expand Down Expand Up @@ -307,6 +314,12 @@ class how_to
return;
}

if (option_type == RS2_OPTION_REGION_OF_INTEREST)
{
std::cerr << "Setting ROI is not demonstrated in this example. Check `set_region_of_interest` API" << std::endl;
return;
}

// Each option provides its rs2::option_range to provide information on how it can be changed
// To get the supported range of an option we do the following:

Expand Down

0 comments on commit 818c156

Please sign in to comment.