-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed ParseMultiRobotPose to be a launch substitution class
Signed-off-by: Tanner, Gilbert <[email protected]>
- Loading branch information
1 parent
ca8c1e7
commit 9b31d75
Showing
3 changed files
with
195 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ | |
'HasNodeParams', | ||
'RewrittenYaml', | ||
'ReplaceString', | ||
'ParseMultiRobotPose', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright (c) 2023 LG Electronics. | ||
# | ||
# 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 typing import Dict, Text | ||
|
||
import yaml | ||
from launch.launch_context import LaunchContext | ||
import launch | ||
|
||
|
||
class ParseMultiRobotPose(launch.Substitution): | ||
""" | ||
A custom substitution to parse the robots argument for multi-robot poses. | ||
Expects input in the format: | ||
robots:="robot1={x: 1.0, y: 1.0, yaw: 0.0}; robot2={x: 2.0, y: 2.0, yaw: 1.5707}" | ||
""" | ||
|
||
def __init__(self, robots_argument: launch.SomeSubstitutionsType) -> None: | ||
super().__init__() | ||
self.__robots_argument = robots_argument | ||
|
||
def describe(self) -> Text: | ||
"""Return a description of this substitution as a string.""" | ||
return '' | ||
|
||
def perform(self, context: LaunchContext) -> Dict: | ||
""" | ||
Resolve and parse the robots argument string into a dictionary. | ||
""" | ||
robots_str = self.__robots_argument.perform(context) | ||
if not robots_str: | ||
return {} | ||
|
||
multirobots = {} | ||
for robot_entry in robots_str.split(";"): | ||
key_val = robot_entry.strip().split("=") | ||
if len(key_val) != 2: | ||
continue | ||
|
||
robot_name, pose_str = key_val[0].strip(), key_val[1].strip() | ||
robot_pose = yaml.safe_load(pose_str) | ||
# Set default values if not provided | ||
robot_pose.setdefault("x", 0.0) | ||
robot_pose.setdefault("y", 0.0) | ||
robot_pose.setdefault("z", 0.0) | ||
robot_pose.setdefault("roll", 0.0) | ||
robot_pose.setdefault("pitch", 0.0) | ||
robot_pose.setdefault("yaw", 0.0) | ||
multirobots[robot_name] = robot_pose | ||
return multirobots |