|
| 1 | +# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES |
| 2 | +# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +# SPDX-License-Identifier: Apache-2.0 |
| 17 | + |
| 18 | +import os |
| 19 | + |
| 20 | +from isaac_ros_launch_utils.all_types import * |
| 21 | +import isaac_ros_launch_utils as lu |
| 22 | +import isaac_ros_perceptor_constants as pc |
| 23 | + |
| 24 | + |
| 25 | +def create_imager_pipeline(stereo_camera_name: str, identifier: str, |
| 26 | + args: lu.ArgumentContainer) -> list[Action]: |
| 27 | + stereo_camera_config = getattr(args, stereo_camera_name) |
| 28 | + |
| 29 | + actions: list[Action] = [] |
| 30 | + |
| 31 | + rectify_composable_node = ComposableNode( |
| 32 | + name='rectify_node', |
| 33 | + package='isaac_ros_image_proc', |
| 34 | + plugin='nvidia::isaac_ros::image_proc::RectifyNode', |
| 35 | + namespace=f'{stereo_camera_name}/{identifier}', |
| 36 | + parameters=[{ |
| 37 | + 'output_width': pc.HAWK_IMAGE_WIDTH, |
| 38 | + 'output_height': pc.HAWK_IMAGE_HEIGHT, |
| 39 | + }], |
| 40 | + ) |
| 41 | + rectify_condition = IfCondition(lu.has_substring(stereo_camera_config, 'rectify')) |
| 42 | + actions.append( |
| 43 | + lu.load_composable_nodes( |
| 44 | + args.container_name, |
| 45 | + [rectify_composable_node], |
| 46 | + condition=rectify_condition, |
| 47 | + )) |
| 48 | + |
| 49 | + return actions |
| 50 | + |
| 51 | + |
| 52 | +def create_hawk_pipeline(stereo_camera_name: str, args: lu.ArgumentContainer) -> list[Action]: |
| 53 | + actions = [] |
| 54 | + |
| 55 | + # Load the configuration for the stereo camera |
| 56 | + stereo_camera_config = getattr(args, stereo_camera_name) |
| 57 | + run_ess_light = lu.has_substring(stereo_camera_config, 'ess_light') |
| 58 | + run_ess_full = lu.has_substring(stereo_camera_config, 'ess_full') |
| 59 | + run_ess = OrSubstitution(run_ess_light, run_ess_full) |
| 60 | + |
| 61 | + actions.append( |
| 62 | + lu.assert_condition( |
| 63 | + 'Camera config invalid. Can not run ess_light and ess_full at the same time.', |
| 64 | + IfCondition(AndSubstitution(run_ess_light, run_ess_full))), |
| 65 | + ) |
| 66 | + engine_file_path = lu.if_else_substitution(run_ess_light, args.ess_light_engine_file_path, |
| 67 | + args.ess_full_engine_file_path) |
| 68 | + actions.append(lu.assert_path_exists( |
| 69 | + engine_file_path, |
| 70 | + condition=IfCondition(run_ess), |
| 71 | + )) |
| 72 | + ess_skip_frames = lu.has_substring(stereo_camera_config, 'ess_skip_frames') |
| 73 | + throttler_skip = lu.if_else_substitution(ess_skip_frames, args.ess_number_of_frames_to_skip, |
| 74 | + '0') |
| 75 | + |
| 76 | + # Run the left/right imager pipelines (rectify) |
| 77 | + actions.extend(create_imager_pipeline(stereo_camera_name, 'left', args)) |
| 78 | + actions.extend(create_imager_pipeline(stereo_camera_name, 'right', args)) |
| 79 | + |
| 80 | + # Run the depth estimation |
| 81 | + ess_composable_node = ComposableNode( |
| 82 | + name='ess_node', |
| 83 | + package='isaac_ros_ess', |
| 84 | + plugin='nvidia::isaac_ros::dnn_stereo_depth::ESSDisparityNode', |
| 85 | + namespace=stereo_camera_name, |
| 86 | + parameters=[{ |
| 87 | + 'engine_file_path': engine_file_path, |
| 88 | + 'threshold': 0.4, |
| 89 | + 'throttler_skip': throttler_skip, |
| 90 | + }], |
| 91 | + remappings=[ |
| 92 | + ('left/camera_info', 'left/camera_info_rect'), |
| 93 | + ('left/image_raw', 'left/image_rect'), |
| 94 | + ('right/camera_info', 'right/camera_info_rect'), |
| 95 | + ('right/image_raw', 'right/image_rect'), |
| 96 | + ], |
| 97 | + ) |
| 98 | + disparity_composable_node = ComposableNode( |
| 99 | + name='disparity_to_depth', |
| 100 | + package='isaac_ros_stereo_image_proc', |
| 101 | + plugin='nvidia::isaac_ros::stereo_image_proc::DisparityToDepthNode', |
| 102 | + namespace=stereo_camera_name, |
| 103 | + ) |
| 104 | + depth_action = lu.load_composable_nodes( |
| 105 | + args.container_name, [ess_composable_node, disparity_composable_node], |
| 106 | + condition=IfCondition(run_ess)) |
| 107 | + actions.append(depth_action) |
| 108 | + |
| 109 | + return actions |
| 110 | + |
| 111 | + |
| 112 | +def generate_launch_description() -> LaunchDescription: |
| 113 | + args = lu.ArgumentContainer() |
| 114 | + |
| 115 | + # Config strings for all stereo cameras. |
| 116 | + # The config string must be a subset of: |
| 117 | + # - driver,rectify,resize,ess_full,ess_light,ess_skip_frames,cuvslam,nvblox |
| 118 | + args.add_arg('front_stereo_camera') |
| 119 | + args.add_arg('back_stereo_camera') |
| 120 | + args.add_arg('left_stereo_camera') |
| 121 | + args.add_arg('right_stereo_camera') |
| 122 | + |
| 123 | + # Additional arguments |
| 124 | + args.add_arg('container_name', 'nova_container') |
| 125 | + args.add_arg('ess_number_of_frames_to_skip', 1) |
| 126 | + args.add_arg('ess_full_engine_file_path', |
| 127 | + lu.get_isaac_ros_ws_path() + |
| 128 | + '/isaac_ros_assets/models/dnn_stereo_disparity/dnn_stereo_disparity_v4.0.0/ess.engine') |
| 129 | + args.add_arg('ess_light_engine_file_path', |
| 130 | + lu.get_isaac_ros_ws_path() + |
| 131 | + '/isaac_ros_assets/models/dnn_stereo_disparity/dnn_stereo_disparity_v4.0.0/light_ess.engine') |
| 132 | + |
| 133 | + # Create pipelines for each camera according to the camera config |
| 134 | + actions = args.get_launch_actions() |
| 135 | + actions.extend(create_hawk_pipeline('front_stereo_camera', args)) |
| 136 | + actions.extend(create_hawk_pipeline('back_stereo_camera', args)) |
| 137 | + actions.extend(create_hawk_pipeline('left_stereo_camera', args)) |
| 138 | + actions.extend(create_hawk_pipeline('right_stereo_camera', args)) |
| 139 | + |
| 140 | + return LaunchDescription(actions) |
0 commit comments