summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2022-01-31 00:17:58 +0000
committerGreg Brown <gmb60@cam.ac.uk>2022-01-31 00:17:58 +0000
commit1678bf6e4f607658fe504f4870fd213d0bdf5f6a (patch)
treea809b40d8ac6ca4543046856167c44c13f1c2cbf
parentf6ee0e36c9cc075e5f007c44e95dc3aaa7736a57 (diff)
Add a launch file for gazebo.
-rwxr-xr-xlaunch-robots.py (renamed from scripts/launch-robots.py)20
-rw-r--r--launch/gazebo.launch9
2 files changed, 22 insertions, 7 deletions
diff --git a/scripts/launch-robots.py b/launch-robots.py
index 8b09e0f..7cc7e16 100755
--- a/scripts/launch-robots.py
+++ b/launch-robots.py
@@ -1,6 +1,9 @@
#!/usr/bin/env python3
+import argparse
import math
+from shutil import which
+import subprocess
import sys
from typing import Tuple
@@ -46,13 +49,16 @@ def splice_robots(text : str, n : int) -> str:
def main(filename : str, n : int):
- with open(filename, 'r') as f:
- print(splice_robots(f.read(), n))
+ 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__':
- if len(sys.argv) != 3:
- sys.exit(1)
- filename = sys.argv[1]
- robots = int(sys.argv[2])
- main(filename, robots)
+ 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 @@
+<launch>
+ <arg name="robots" />
+ <arg name="template" default="$(find murl)/launch/all-robots.launch.in" />
+ <node pkg="murl"
+ type="launch-robots.py"
+ name="launch_robots"
+ args="--template=$(arg template) --robots=$(arg robots)"
+ output="screen"/>
+</launch>