From 1678bf6e4f607658fe504f4870fd213d0bdf5f6a Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Mon, 31 Jan 2022 00:17:58 +0000 Subject: Add a launch file for gazebo. --- launch-robots.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ launch/gazebo.launch | 9 +++++++ scripts/launch-robots.py | 58 ------------------------------------------- 3 files changed, 73 insertions(+), 58 deletions(-) create mode 100755 launch-robots.py create mode 100644 launch/gazebo.launch delete mode 100755 scripts/launch-robots.py diff --git a/launch-robots.py b/launch-robots.py new file mode 100755 index 0000000..7cc7e16 --- /dev/null +++ b/launch-robots.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +import argparse +import math +from shutil import which +import subprocess +import sys +from typing import Tuple + +ORIGIN = [0.0, 0.0] +DISTANCE = 1.5 + +TEMPLATE = """ + + + + + + + + + +""" + +MAGIC_STRING = "" + +def get_pose(i : int, n : int) -> Tuple[float, float, float]: + angle = 2 * math.pi * i / n + x = ORIGIN[0] + DISTANCE * math.cos(angle) + y = ORIGIN[1] + DISTANCE * math.sin(angle) + z = 0.0 + return (x , y , z) + + +def make_robot_groups(n : int) -> str: + output = "" + for i in range(n): + x , y , z = get_pose(i, n) + output += TEMPLATE.format( + n = i, + x = round(x, 3), + y = round(y, 3), + z = round(z, 3)) + return output + + +def splice_robots(text : str, n : int) -> str: + return text.replace(MAGIC_STRING, make_robot_groups(n)) + + +def main(filename : str, n : int): + out = None + with open(filename, 'r') as fd: + out = splice_robots(fd.read(), n) + + subprocess.run([which('roslaunch'), '-'], input=out, text=True) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Launches gazebo') + parser.add_argument('--template', action='store', type=str, help='Template launch file.') + parser.add_argument('--robots', action='store', type=int, help='Number of robots.') + args, unknown = parser.parse_known_args() + main(args.template, args.robots) diff --git a/launch/gazebo.launch b/launch/gazebo.launch new file mode 100644 index 0000000..85f1829 --- /dev/null +++ b/launch/gazebo.launch @@ -0,0 +1,9 @@ + + + + + diff --git a/scripts/launch-robots.py b/scripts/launch-robots.py deleted file mode 100755 index 8b09e0f..0000000 --- a/scripts/launch-robots.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 - -import math -import sys -from typing import Tuple - -ORIGIN = [0.0, 0.0] -DISTANCE = 1.5 - -TEMPLATE = """ - - - - - - - - - -""" - -MAGIC_STRING = "" - -def get_pose(i : int, n : int) -> Tuple[float, float, float]: - angle = 2 * math.pi * i / n - x = ORIGIN[0] + DISTANCE * math.cos(angle) - y = ORIGIN[1] + DISTANCE * math.sin(angle) - z = 0.0 - return (x , y , z) - - -def make_robot_groups(n : int) -> str: - output = "" - for i in range(n): - x , y , z = get_pose(i, n) - output += TEMPLATE.format( - n = i, - x = round(x, 3), - y = round(y, 3), - z = round(z, 3)) - return output - - -def splice_robots(text : str, n : int) -> str: - return text.replace(MAGIC_STRING, make_robot_groups(n)) - - -def main(filename : str, n : int): - with open(filename, 'r') as f: - print(splice_robots(f.read(), n)) - - -if __name__ == '__main__': - if len(sys.argv) != 3: - sys.exit(1) - filename = sys.argv[1] - robots = int(sys.argv[2]) - main(filename, robots) -- cgit v1.2.3