Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
has_node_params.py
1 # Copyright (c) 2021 PAL Robotics S.L.
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 from typing import List
16 from typing import Text
17 
18 import yaml
19 import launch
20 
21 import sys # delete this
22 
23 class HasNodeParams(launch.Substitution):
24  """
25  Substitution that checks if a param file contains parameters for a node
26 
27  Used in launch system
28  """
29 
30  def __init__(self,
31  source_file: launch.SomeSubstitutionsType,
32  node_name: Text) -> None:
33  super().__init__()
34  """
35  Construct the substitution
36 
37  :param: source_file the parameter YAML file
38  :param: node_name the name of the node to check
39  """
40 
41  from launch.utilities import normalize_to_list_of_substitutions # import here to avoid loop
42  self.__source_file__source_file = normalize_to_list_of_substitutions(source_file)
43  self.__node_name__node_name = node_name
44 
45  @property
46  def name(self) -> List[launch.Substitution]:
47  """Getter for name."""
48  return self.__source_file__source_file
49 
50  def describe(self) -> Text:
51  """Return a description of this substitution as a string."""
52  return ''
53 
54  def perform(self, context: launch.LaunchContext) -> Text:
55  yaml_filename = launch.utilities.perform_substitutions(context, self.namename)
56  data = yaml.safe_load(open(yaml_filename, 'r'))
57 
58  if self.__node_name__node_name in data.keys():
59  return "True"
60  return "False"