blob: 1adb4db73a5cbdab17f0129847d71953b56f9a07 [file] [log] [blame]
Philipp Schrader7861dce2015-02-23 00:27:59 +00001#!/usr/bin/python3
2
3import sys
4import numpy
5import analysis
6import argparse
7
8def ReadPlotDefinitions(filename):
9 """
10 Read a file with plotting definitions.
11
12 A plotting definition is a single line that defines what data to search for
13 in order to plot it. The following in a file would duplicate the default
14 behaviour:
15
16 fridge goal height
17 fridge goal angle
18 fridge goal velocity
19 fridge goal angular_velocity
20 fridge output left_arm
21 fridge output right_arm
22 fridge output left_elevator
23 fridge output right_elevator
24
25 Lines are ignored if they start with a hash mark (i.e. '#').
26
27 Args:
28 filename: The name of the file to read the definitions from.
29
30 Returns:
31 [[str]]: The definitions in the specified file.
32 """
33 defs = []
34 with open(filename) as fd:
35 for line in fd:
36 raw_defs = line.split()
37
38 # Only add to the list of definitions if the line's not empty and it
39 # doesn't start with a hash.
40 if raw_defs and not raw_defs[0].startswith('#'):
41 defs.append(raw_defs)
42
43 return defs
44
45def main():
46 # Parse all command line arguments.
47 arg_parser = argparse.ArgumentParser(description='Log Plotter')
48 arg_parser.add_argument('log_file', metavar='LOG_FILE', type=str, \
49 help='The file from which to read logs and plot.')
50 arg_parser.add_argument('--plot-defs', action='store', type=str, \
51 help='Read the items to plot from this file.')
52
53 args = arg_parser.parse_args(sys.argv[1:])
54
55 p = analysis.Plotter()
56
57 # If the user defines the list of data to plot in a file, read it from there.
58 if args.plot_defs:
59 defs = ReadPlotDefinitions(args.plot_defs)
60 for definition in defs:
61 p.Add(definition[0], definition[1], *definition[2:])
62
63 # Otherwise use a pre-defined set of data to plot.
64 else:
65 p.Add('fridge', 'goal', 'height')
66 p.Add('fridge', 'goal', 'angle')
67 p.Add('fridge', 'goal', 'velocity')
68 p.Add('fridge', 'goal', 'angular_velocity')
69
70 p.Add('fridge', 'output', 'left_arm')
71 p.Add('fridge', 'output', 'right_arm')
72 p.Add('fridge', 'output', 'left_elevator')
73 p.Add('fridge', 'output', 'right_elevator')
74
75 p.PlotFile(args.log_file)
76
77if __name__ == '__main__':
78 main()