Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions nav2_common/nav2_common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2025 Open Navigation LLC
#
# 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.

from . import launch

__all__ = [
'launch',
]
15 changes: 15 additions & 0 deletions nav2_common/nav2_common/launch/has_node_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Sequence

import launch
import yaml


@launch.frontend.expose_substitution('has-node-params')
class HasNodeParams(launch.Substitution):
"""
Substitution that checks if a param file contains parameters for a node.
Expand All @@ -41,6 +44,18 @@ def __init__(
normalize_to_list_of_substitutions(source_file)
self.__node_name = node_name

@classmethod
def parse(cls, data: Sequence[launch.SomeSubstitutionsType]):
num_args = len(data)
if num_args != 2:
raise TypeError(
f'has-node-params substitution takes 2 arguments, got {num_args}')
kwargs = {
'source_file': data[0],
'node_name': data[1],
}
return cls, kwargs

@property
def name(self) -> list[launch.Substitution]:
"""Getter for name."""
Expand Down
13 changes: 13 additions & 0 deletions nav2_common/nav2_common/launch/launch_config_as_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Sequence

import launch
from launch import LaunchContext
from launch.substitutions import LaunchConfiguration
from launch.utilities import perform_substitutions


@launch.frontend.expose_substitution('as-bool')
class LaunchConfigAsBool(launch.Substitution):
"""
Converts a LaunchConfiguration value into a normalized boolean string: 'true' or 'false'.
Expand All @@ -30,6 +33,16 @@ def __init__(self, name: str) -> None:
super().__init__()
self._config = LaunchConfiguration(name)

@classmethod
def parse(cls, data: Sequence[launch.SomeSubstitutionsType]):
if len(data) != 1:
raise TypeError(f'as-bool substitution takes 1 arg, got {len(data)}')
kwargs = {
'name': data[0]
}
return cls, kwargs


def perform(self, context: LaunchContext) -> str:
value = perform_substitutions(context, [self._config])
if value.strip().lower() in ['true', '1', 'yes', 'on']:
Expand Down
7 changes: 6 additions & 1 deletion nav2_common/nav2_common/launch/replace_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.

import tempfile
from typing import IO, Optional
from typing import IO, Optional, Sequence

import launch


@launch.frontend.expose_substitution('replace-string')
class ReplaceString(launch.Substitution):
"""
Substitution that replaces strings on a given file.
Expand Down Expand Up @@ -46,6 +47,10 @@ def __init__(
)
self.__condition = condition

@classmethod
def parse(cls, data: Sequence[launch.SomeSubstitutionsType]):
raise NotImplementedError()

@property
def name(self) -> list[launch.Substitution]:
"""Getter for name."""
Expand Down
7 changes: 6 additions & 1 deletion nav2_common/nav2_common/launch/rewritten_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from collections.abc import Generator
import tempfile
from typing import Optional, TypeAlias, Union
from typing import Optional, TypeAlias, Union, Sequence

import launch
import yaml
Expand All @@ -35,6 +35,7 @@ def setValue(self, value: YamlValue) -> None:
self.dictionary[self.dictKey] = value


@launch.frontend.expose_substitution('rewritten-yaml')
class RewrittenYaml(launch.Substitution):
"""
Substitution that modifies the given YAML file.
Expand Down Expand Up @@ -90,6 +91,10 @@ def __init__(
if root_key is not None:
self.__root_key = normalize_to_list_of_substitutions(root_key)

@classmethod
def parse(cls, data: Sequence[launch.SomeSubstitutionsType]):
raise NotImplementedError()

@property
def name(self) -> list[launch.Substitution]:
"""Getter for name."""
Expand Down
3 changes: 3 additions & 0 deletions nav2_common/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
launch.frontend.launch_extension:
nav2_common = nav2_common
Loading