Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix PR comments and add unit test
  • Loading branch information
noacoohen committed Jul 10, 2024
commit 5f151f24f06efaeddf0e2d191e08024d24dfe07f
5 changes: 2 additions & 3 deletions include/librealsense2/h/rs_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ extern "C" {

/**
* Set the device to be used in the pipline.
* The function is used to assign the device, ensuring the pipeline maintains the sensitivity values configured for
* this device by the user.
* \param[in] pipe the pipeline
* The function is used to assign the device, useful when the user wish to set controls that cannot be set while streaming.
* \param[in] pipe the pipeline.
* \param[in] device the device to be used in the pipline.
*/
void rs2_pipeline_set_device( rs2_pipeline * pipe, rs2_device * device, rs2_error ** error );
Comment thread
noacoohen marked this conversation as resolved.
Expand Down
2 changes: 1 addition & 1 deletion include/librealsense2/hpp/rs_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ namespace rs2

/**
* Set the device to be used in the pipline.
* The function is used to assign the device, ensuring the pipeline maintains the sensitivity values configured for this device by the user.
* The function is used to assign the device, useful when the user wish to set controls that cannot be set while streaming.
* \param[in] device the device to be used in the pipline.
*/
void set_device( rs2::device* device )
Expand Down
7 changes: 3 additions & 4 deletions src/pipeline/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ namespace librealsense
return unsafe_get_active_profile();
}

void pipeline::set_device(
std::shared_ptr< librealsense::device_interface > device_interface )
void pipeline::set_device( std::shared_ptr< librealsense::device_interface > device_interface )
{
_device_interface = device_interface;
_device = device_interface;
}

std::shared_ptr< librealsense::device_interface > pipeline::get_device()
{
return _device_interface;
return _device;
}

std::shared_ptr<profile> pipeline::get_active_profile() const
Expand Down
4 changes: 1 addition & 3 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2201,9 +2201,7 @@ void rs2_pipeline_stop(rs2_pipeline* pipe, rs2_error ** error) BEGIN_API_CALL
}
HANDLE_EXCEPTIONS_AND_RETURN(, pipe)

void rs2_pipeline_set_device( rs2_pipeline * pipe,
rs2_device * device,
rs2_error ** error ) BEGIN_API_CALL
void rs2_pipeline_set_device( rs2_pipeline * pipe, rs2_device * device, rs2_error ** error ) BEGIN_API_CALL
{
VALIDATE_NOT_NULL( pipe );
VALIDATE_NOT_NULL( device );
Expand Down
33 changes: 33 additions & 0 deletions unit-tests/live/d400/test-pipeline-set-device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# License: Apache 2.0. See LICENSE file in root directory.
Comment thread
noacoohen marked this conversation as resolved.
# Copyright(c) 2024 Intel Corporation. All Rights Reserved.

# LibCI doesn't have D435i so //test:device D435I// is disabled for now
# test:device D455

import pyrealsense2 as rs
from rspy import test

gyro_sensitivity_value = 4.0

with test.closure("pipeline - set device"):
cfg = rs.config()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, now I see, why not declare before usage? it's C++ :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's python :)
Same comment but that's OK for now.
In the future, with C++ and python it is better to declare the variable right before usage.
This way if you remove the usage in the future, you will remember to remove the declaration too

ctx = rs.context()

dev = test.find_first_device_or_exit()
Comment thread
Nir-Az marked this conversation as resolved.
motion_sensor = dev.first_motion_sensor()
pipe = rs.pipeline(ctx)
pipe.set_device(dev)

motion_sensor.set_option(rs.option.gyro_sensitivity, 4)
Comment thread
noacoohen marked this conversation as resolved.
Outdated

cfg.enable_stream(rs.stream.accel, rs.format.motion_xyz32f, 200)
cfg.enable_stream(rs.stream.gyro, rs.format.motion_xyz32f, 200)

profile = pipe.start(cfg)
device_from_profile = profile.get_device()
sensor = device_from_profile.first_motion_sensor()
sensor_gyro_sensitivity_value = sensor.get_option(rs.option.gyro_sensitivity)
test.check_equal(gyro_sensitivity_value, sensor_gyro_sensitivity_value)
pipe.stop()

test.print_results_and_exit()
5 changes: 4 additions & 1 deletion wrappers/python/pyrs_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ void init_pipeline(py::module &m) {
auto success = self.try_wait_for_frames(&fs, timeout_ms);
return std::make_tuple(success, fs);
}, "timeout_ms"_a = 5000, py::call_guard<py::gil_scoped_release>())
.def("get_active_profile", &rs2::pipeline::get_active_profile); // No docstring in C++
.def("get_active_profile", &rs2::pipeline::get_active_profile) // No docstring in C++
.def( "set_device", &rs2::pipeline::set_device,
"The function is used to assign the device, useful when the user wish to set controls that cannot be set while streaming. ",
"device"_a );
/** end rs_pipeline.hpp **/
}