|
| 1 | +# Copyright 2024 Stereolabs |
| 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 | + |
| 15 | +import os |
| 16 | +import yaml |
| 17 | + |
| 18 | +from ament_index_python.packages import get_package_share_directory |
| 19 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
| 20 | + |
| 21 | +from launch import LaunchDescription |
| 22 | +from launch.actions import ( |
| 23 | + DeclareLaunchArgument, |
| 24 | + OpaqueFunction, |
| 25 | + IncludeLaunchDescription, |
| 26 | + LogInfo |
| 27 | +) |
| 28 | +from launch.substitutions import ( |
| 29 | + LaunchConfiguration, |
| 30 | + TextSubstitution |
| 31 | +) |
| 32 | +from launch_ros.actions import ( |
| 33 | + ComposableNodeContainer, |
| 34 | + LoadComposableNodes |
| 35 | +) |
| 36 | + |
| 37 | +from launch_ros.descriptions import ( |
| 38 | + ComposableNode |
| 39 | +) |
| 40 | +# Enable colored output |
| 41 | +os.environ["RCUTILS_COLORIZED_OUTPUT"] = "1" |
| 42 | + |
| 43 | + |
| 44 | +def launch_setup(context, *args, **kwargs): |
| 45 | + |
| 46 | + # Get the path to the camera configuration file |
| 47 | + camera_config_override_path = os.path.join( |
| 48 | + get_package_share_directory('zed_isaac_ros_april_tag'), |
| 49 | + 'config', |
| 50 | + 'zed_params.yaml' |
| 51 | + ) |
| 52 | + |
| 53 | + # Get the path to the AprilTag configuration file |
| 54 | + apriltag_config_path = os.path.join( |
| 55 | + get_package_share_directory('zed_isaac_ros_april_tag'), |
| 56 | + 'config', |
| 57 | + 'zed_isaac_ros_april_tag.yaml' |
| 58 | + ) |
| 59 | + |
| 60 | + # List of actions to be launched |
| 61 | + actions = [] |
| 62 | + |
| 63 | + namespace_val = 'zed_isaac' |
| 64 | + disable_tf = LaunchConfiguration('disable_tf') |
| 65 | + camera_model = LaunchConfiguration('camera_model') |
| 66 | + |
| 67 | + disable_tf_val = disable_tf.perform(context) |
| 68 | + |
| 69 | + # ROS 2 Component Container |
| 70 | + container_name = 'zed_container' |
| 71 | + info = '* Starting Composable node container: ' + namespace_val + '/' + container_name |
| 72 | + actions.append(LogInfo(msg=TextSubstitution(text=info))) |
| 73 | + |
| 74 | + # Note: It is crucial that the 'executable' field is set to be 'component_container_mt' |
| 75 | + # so that the created nodes can be started and communicated correctly within the same process. |
| 76 | + |
| 77 | + zed_container = ComposableNodeContainer( |
| 78 | + name=container_name, |
| 79 | + namespace=namespace_val, |
| 80 | + package='rclcpp_components', |
| 81 | + executable='component_container_mt', |
| 82 | + arguments=['--ros-args', '--log-level', 'info'], |
| 83 | + output='screen', |
| 84 | + ) |
| 85 | + actions.append(zed_container) |
| 86 | + |
| 87 | + |
| 88 | + # ZED Wrapper launch file |
| 89 | + zed_wrapper_launch = IncludeLaunchDescription( |
| 90 | + launch_description_source=PythonLaunchDescriptionSource([ |
| 91 | + get_package_share_directory('zed_wrapper'), |
| 92 | + '/launch/zed_camera.launch.py' |
| 93 | + ]), |
| 94 | + launch_arguments={ |
| 95 | + 'camera_model': camera_model, |
| 96 | + 'container_name': container_name, |
| 97 | + 'namespace': namespace_val, |
| 98 | + 'enable_ipc': 'false', |
| 99 | + 'ros_params_override_path': camera_config_override_path |
| 100 | + }.items() |
| 101 | + ) |
| 102 | + actions.append(zed_wrapper_launch) |
| 103 | + |
| 104 | + # Read the resolution from the ZED parameters file |
| 105 | + with open(camera_config_override_path, 'r') as f: |
| 106 | + configuration = yaml.safe_load(f) |
| 107 | + print(f'Loaded configuration: {configuration}') |
| 108 | + resolution = configuration["/**"]["ros__parameters"]["general"]["grab_resolution"] |
| 109 | + pub_resolution = configuration["/**"]["ros__parameters"]["general"]["pub_resolution"] |
| 110 | + pub_downscale_factor = configuration["/**"]["ros__parameters"]["general"]["pub_downscale_factor"] |
| 111 | + if pub_resolution == 'CUSTOM': |
| 112 | + rescale = pub_downscale_factor |
| 113 | + else: |
| 114 | + rescale = 1.0 |
| 115 | + |
| 116 | + if resolution == 'HD2K': |
| 117 | + image_width = 2208 |
| 118 | + image_height = 1242 |
| 119 | + elif resolution == 'HD1200': |
| 120 | + image_width = 1280 |
| 121 | + image_height = 720 |
| 122 | + elif resolution == 'HD1080': |
| 123 | + image_width = 1920 |
| 124 | + image_height = 1080 |
| 125 | + elif resolution == 'HD720': |
| 126 | + image_width = 1280 |
| 127 | + image_height = 720 |
| 128 | + elif resolution == 'SVGA': |
| 129 | + image_width = 960 |
| 130 | + image_height = 600 |
| 131 | + elif resolution == 'VGA': |
| 132 | + image_width = 672 |
| 133 | + image_height = 376 |
| 134 | + |
| 135 | + # Isaac ROS Node to convert from ZED BGRA8 image to BGR8 required by AprilTag |
| 136 | + isaac_converter_node = ComposableNode( |
| 137 | + package='isaac_ros_image_proc', |
| 138 | + plugin='nvidia::isaac_ros::image_proc::ImageFormatConverterNode', |
| 139 | + name='zed_image_converter', |
| 140 | + namespace=namespace_val, |
| 141 | + parameters=[ |
| 142 | + { |
| 143 | + 'image_width': int(image_width / rescale), |
| 144 | + 'image_height': int(image_height / rescale), |
| 145 | + 'encoding_desired': 'bgr8', |
| 146 | + 'num_blocks': 40 |
| 147 | + } |
| 148 | + ], |
| 149 | + remappings=[ |
| 150 | + ('image_raw', 'zed/rgb/image_rect_color'), |
| 151 | + ('image', 'zed/rgb/image_rect_color_bgr8') |
| 152 | + ] |
| 153 | + ) |
| 154 | + |
| 155 | + # add parameters for conversion node -> https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_image_pipeline/isaac_ros_image_proc/index.html#imageformatconverternode |
| 156 | + |
| 157 | + # AprilTag detection node |
| 158 | + isac_apriltag_node = ComposableNode( |
| 159 | + package='isaac_ros_apriltag', |
| 160 | + plugin='nvidia::isaac_ros::apriltag::AprilTagNode', |
| 161 | + name='apriltag', |
| 162 | + namespace=namespace_val, |
| 163 | + remappings=[ |
| 164 | + ('image', 'zed/rgb/image_rect_color_bgr8'), |
| 165 | + ('camera_info', 'zed/rgb/camera_info') |
| 166 | + ], |
| 167 | + parameters=[apriltag_config_path] |
| 168 | + ) |
| 169 | + |
| 170 | + container_full_name = namespace_val + '/' + container_name |
| 171 | + # Load the Converter node into the container |
| 172 | + load_converter_node = LoadComposableNodes( |
| 173 | + composable_node_descriptions=[isaac_converter_node], |
| 174 | + target_container=container_full_name |
| 175 | + ) |
| 176 | + actions.append(load_converter_node) |
| 177 | + |
| 178 | + # Load the AprilTag node into the container |
| 179 | + load_april_tag_node = LoadComposableNodes( |
| 180 | + composable_node_descriptions=[isac_apriltag_node], |
| 181 | + target_container=container_full_name |
| 182 | + ) |
| 183 | + actions.append(load_april_tag_node) |
| 184 | + |
| 185 | + return actions |
| 186 | + |
| 187 | +def generate_launch_description(): |
| 188 | + return LaunchDescription( |
| 189 | + [ |
| 190 | + DeclareLaunchArgument( |
| 191 | + 'camera_model', |
| 192 | + description='[REQUIRED] The model of the camera. Using a wrong camera model can disable camera features.', |
| 193 | + choices=['zed', 'zedm', 'zed2', 'zed2i', 'zedx', 'zedxm', 'virtual', 'zedxonegs', 'zedxone4k']), |
| 194 | + DeclareLaunchArgument( |
| 195 | + 'disable_tf', |
| 196 | + default_value='False', |
| 197 | + description='If `True` disable TF broadcasting for all the cameras in order to fuse visual odometry information externally.'), |
| 198 | + OpaqueFunction(function=launch_setup) |
| 199 | + ] |
| 200 | + ) |
0 commit comments