summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2022-01-30 23:50:36 +0000
committerGreg Brown <gmb60@cam.ac.uk>2022-01-30 23:51:00 +0000
commitf6ee0e36c9cc075e5f007c44e95dc3aaa7736a57 (patch)
tree0fb6437bf04884ca7da38299d30b37ad6f9b4ee3 /scripts
Initial commit
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/analysis/error-beta.py35
-rwxr-xr-xscripts/analysis/error-time.py24
-rwxr-xr-xscripts/launch-robots.py58
3 files changed, 117 insertions, 0 deletions
diff --git a/scripts/analysis/error-beta.py b/scripts/analysis/error-beta.py
new file mode 100755
index 0000000..c55f240
--- /dev/null
+++ b/scripts/analysis/error-beta.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+
+import matplotlib.pyplot as plt
+import numpy as np
+import pandas as pd
+import sys
+
+def process_file(filename, robots):
+ s = pd.read_csv(filename).to_numpy().reshape((-1, robots, 2, 2))
+ error = s[:,:,1] - s[:,:,0]
+ linear = np.sqrt(error[:,:,0] ** 2 + error[:,:,1] ** 2)
+ return np.median(linear)
+
+def main(filenames, labels, robots):
+ for i, names in enumerate(filenames):
+ errors = [process_file(name, robots[i]) for name in names]
+ plt.plot(labels, errors, marker='o', linestyle=' ', label='{} robots'.format(robots[i]))
+
+ plt.ylabel('Median Error (m)')
+ plt.xlabel('Significance of inter-robot ranging')
+ plt.legend()
+
+ if input('Save? ') == 'y':
+ name = input('name: ')
+ plt.savefig(name)
+
+ plt.show()
+
+if __name__ == '__main__':
+ if len(sys.argv) < 4:
+ sys.exit(1)
+ robots = [int(i) for i in sys.argv[1].split(' ')]
+ labels = sys.argv[2].split(' ')
+ filename_series = map(lambda s: s.split(' '), sys.argv[3:])
+ main(filename_series, labels, robots)
diff --git a/scripts/analysis/error-time.py b/scripts/analysis/error-time.py
new file mode 100755
index 0000000..37f0ece
--- /dev/null
+++ b/scripts/analysis/error-time.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import matplotlib.pyplot as plt
+import numpy as np
+import pandas as pd
+import sys
+
+def main(filename, robots):
+ s = pd.read_csv(filename).to_numpy().reshape((-1, robots, 2, 2))
+ error = s[:,:,1] - s[:,:,0]
+ linear = np.sqrt(error[:,:,0] ** 2 + error[:,:,1] ** 2)
+
+ plt.plot(linear)
+ plt.ylabel('Error (m)')
+ plt.xlabel('Time')
+ plt.show()
+
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ sys.exit(1)
+ filename = sys.argv[1]
+ robots = int(sys.argv[2])
+ main(filename, robots)
diff --git a/scripts/launch-robots.py b/scripts/launch-robots.py
new file mode 100755
index 0000000..8b09e0f
--- /dev/null
+++ b/scripts/launch-robots.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+import math
+import sys
+from typing import Tuple
+
+ORIGIN = [0.0, 0.0]
+DISTANCE = 1.5
+
+TEMPLATE = """
+ <group ns="robot{n}">
+ <param name="tf_prefix" value="robot{n}" />
+ <include file="$(find murl)/launch/one-robot.launch">
+ <arg name="robot_name" value="Robot{n}"/>
+ <arg name="x_pos" value="{x}"/>
+ <arg name="y_pos" value="{y}"/>
+ <arg name="z_pos" value="{z}"/>
+ </include>
+ </group>
+"""
+
+MAGIC_STRING = "<!-- INCLUDE ROBOTS -->"
+
+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)