Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix align_depth + add test #2825

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions realsense2_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ if(BUILD_TESTING)
test
test/templates
test/rosbag
test/post_processing_filters
)
foreach(test_folder ${_pytest_folders})
file(GLOB files "${test_folder}/test_*.py")
Expand Down
2 changes: 1 addition & 1 deletion realsense2_camera/include/ros_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace realsense2_camera
template<class T>
bool is() const
{
return (dynamic_cast<const T*> (&(*this)));
return rs2::sensor::is<T>();
}

private:
Expand Down
89 changes: 89 additions & 0 deletions realsense2_camera/test/post_processing_filters/test_align_depth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright 2023 Intel Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os
import sys
import subprocess
import time

import pytest
from launch import LaunchDescription
import launch_ros.actions
import launch_pytest
import rclpy
from rclpy import qos
from rclpy.node import Node
from sensor_msgs.msg import Image as msg_Image
from sensor_msgs.msg import Imu as msg_Imu

sys.path.append(os.path.abspath(os.path.dirname(__file__)+"/../utils"))
import pytest_rs_utils
from pytest_rs_utils import launch_descr_with_yaml
from pytest_rs_utils import get_rosbag_file_path


'''
This test imitates the ros2 launch rs_launch.py realsense2_camera with the given parameters below
Full command to reproduce locally
ros2 launch rs_launch.py realsense2_camera camera_name:=camera enable_color:=true \
enable_depth:=true rgb_camera.profile:=1280x720x30 depth_module.profile:=640x480x30 \
align_depth.enable:true rosbag_filename:=`realpath outdoors_1color.bag`

Then we check if these topics exist:
/camera/color/image_raw
/camera/depth/image_rect_raw
/camera/aligned_depth_to_color/image_raw

Also we check that the recieved frames of each topic are in the right width and height
'''
test_params = {
"rosbag_filename":get_rosbag_file_path("outdoors_1color.bag"),
'camera_name': 'camera',
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to use a unique name for camera. If there are many tests in one py file, the test may run in parallel and it may influence each other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

'enable_color': 'true',
'enable_depth': 'true',
'depth_module.profile': '1280x720x30',
'rgb_camera.profile': '640x480x30',
'align_depth.enable': 'true',
}


@pytest.mark.rosbag
@pytest.mark.launch(fixture=pytest_rs_utils.launch_descr_with_yaml)
@pytest.mark.parametrize("launch_descr_with_yaml", [test_params],indirect=True)
class TestBasicAlignDepthEnable(pytest_rs_utils.RsTestBaseClass):
def test_camera_1(self, launch_descr_with_yaml):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please us a valid unique test name that indicates the test functionality. This helps running the test using test name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

params = launch_descr_with_yaml[1]
data = pytest_rs_utils.ImageDepthGetData(params["rosbag_filename"])
Copy link
Contributor

Choose a reason for hiding this comment

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

The data can be passed to the themes, the process_data will compare, if it's available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the data, as in this basic test I just want to test topics and sizes of each topic message

themes = [
{'topic': '/'+params['camera_name']+'/color/image_raw', 'msg_type': msg_Image,
'expected_data_chunks': 1, 'width': 640, 'height': 480},
{'topic': '/'+params['camera_name']+'/depth/image_rect_raw', 'msg_type': msg_Image,
'expected_data_chunks': 1, 'width': 1280, 'height': 720},
{'topic': '/'+params['camera_name']+'/aligned_depth_to_color/image_raw', 'msg_type': msg_Image,
'expected_data_chunks': 1, 'width': 640, 'height': 480}
]
try:
'''
initialize, run and check the data
'''
self.init_test('RsTest'+params['camera_name'])
ret = self.run_test(themes)
assert ret[0], ret[1]
assert self.process_data(themes)
finally:
self.shutdown()

def process_data(self, themes):
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this if you are not overriding it. The sample tests are meant to show how to override.

Copy link
Contributor Author

@SamerKhshiboun SamerKhshiboun Jul 26, 2023

Choose a reason for hiding this comment

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

Removed.

return super().process_data(themes)