rs_single_camera_launch.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright 2023 Intel Corporation. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # DESCRIPTION #
  15. # ----------- #
  16. # Use this launch file to launch 2 devices.
  17. # The Parameters available for definition in the command line for each camera are described in rs_launch.configurable_parameters
  18. # For each device, the parameter name was changed to include an index.
  19. # For example: to set camera_name for device1 set parameter camera_name1.
  20. # command line example:
  21. # ros2 launch realsense2_camera rs_multi_camera_launch.py camera_name1:=D400 device_type2:=l5. device_type1:=d4..
  22. """Launch realsense2_camera node."""
  23. import copy
  24. from launch import LaunchDescription, LaunchContext
  25. import launch_ros.actions
  26. from launch.actions import IncludeLaunchDescription, OpaqueFunction
  27. from launch.substitutions import LaunchConfiguration, ThisLaunchFileDir
  28. from launch.launch_description_sources import PythonLaunchDescriptionSource
  29. import sys
  30. import pathlib
  31. sys.path.append(str(pathlib.Path(__file__).parent.absolute()))
  32. import rs_launch
  33. local_parameters = [{'name': 'camera_name1', 'default': 'cam_left_wrist', 'description': 'camera1 unique name'},
  34. {'name': 'camera_namespace1', 'default': 'cam_left_wrist', 'description': 'camera1 namespace'},
  35. {'name': 'serial_no1', 'default': "'218622275899'", 'description': 'choose device1 by serial number'},
  36. ]
  37. def set_configurable_parameters(local_params):
  38. return dict([(param['original_name'], LaunchConfiguration(param['name'])) for param in local_params])
  39. def duplicate_params(general_params, posix):
  40. local_params = copy.deepcopy(general_params)
  41. for param in local_params:
  42. param['original_name'] = param['name']
  43. param['name'] += posix
  44. return local_params
  45. def launch_static_transform_publisher_node(context : LaunchContext):
  46. # dummy static transformation from camera1 to camera2
  47. node = launch_ros.actions.Node(
  48. package = "tf2_ros",
  49. executable = "static_transform_publisher",
  50. arguments = ["0", "0", "0", "0", "0", "0",
  51. context.launch_configurations['camera_name1'] + "_link",
  52. ]
  53. )
  54. return [node]
  55. def generate_launch_description():
  56. params1 = duplicate_params(rs_launch.configurable_parameters, '1')
  57. return LaunchDescription(
  58. rs_launch.declare_configurable_parameters(local_parameters) +
  59. rs_launch.declare_configurable_parameters(params1) +
  60. [
  61. OpaqueFunction(function=rs_launch.launch_setup,
  62. kwargs = {'params' : set_configurable_parameters(params1),
  63. 'param_name_suffix': '1'}),
  64. OpaqueFunction(function=launch_static_transform_publisher_node)
  65. ])