root / trunk / code / projects / diagnostic_station / tools / plot.rb @ 1272
History | View | Annotate | Download (1.79 KB)
1 | 1229 | deffi | #!/usr/bin/env ruby
|
---|---|---|---|
2 | |||
3 | 1231 | deffi | file0='/tmp/data0.tmp'
|
4 | file1='/tmp/data1.tmp'
|
||
5 | |||
6 | 1235 | deffi | points0f=[]; points0b=[]; points1f=[]; points1b=[] |
7 | 1229 | deffi | |
8 | puts "Paste output from station here please"
|
||
9 | |||
10 | while a=gets
|
||
11 | 1236 | deffi | a.chomp! |
12 | a.strip! |
||
13 | 1229 | deffi | |
14 | 1236 | deffi | if a!="" && !(a =~ /^#/) |
15 | if a =~ /^data encoder (0|1) (forward|backward) (.*)$/ |
||
16 | num=$1; dir=$2; data=$3 |
||
17 | 1229 | deffi | |
18 | 1236 | deffi | if (num=="0" && dir=="forward" ); points=points0f |
19 | elsif (num=="0" && dir=="backward"); points=points0b |
||
20 | elsif (num=="1" && dir=="forward" ); points=points1f |
||
21 | elsif (num=="1" && dir=="backward"); points=points1b |
||
22 | else ; points=[]
|
||
23 | end
|
||
24 | 1229 | deffi | |
25 | 1236 | deffi | data.split(' ').each { |pair| point=pair.split('/'); points<<point } |
26 | end
|
||
27 | end
|
||
28 | 1229 | deffi | end
|
29 | |||
30 | 1235 | deffi | def write_points(filename, points) |
31 | 1236 | deffi | File.open(filename, 'w') { |f| |
32 | points.sort { |a,b| |
||
33 | a[0].to_i <=> b[0].to_i |
||
34 | }.each { |point| |
||
35 | puts "#{point[0]} #{point[1]}"
|
||
36 | f.puts "#{point[0]} #{point[1]}"
|
||
37 | } |
||
38 | } |
||
39 | 1235 | deffi | end
|
40 | 1229 | deffi | |
41 | 1235 | deffi | write_points(file0, points0f+points0b) |
42 | write_points(file1, points1f+points1b) |
||
43 | 1229 | deffi | |
44 | IO.popen('gnuplot', 'w') { |p| |
||
45 | 1236 | deffi | p.puts("set xlabel 'Station encoders'")
|
46 | p.puts("set ylabel 'Robot encoders'")
|
||
47 | p.puts("plot '#{file0}' using 1:2 with linespoints title 'Left'")
|
||
48 | p.puts("replot '#{file1}' using 1:2 with linespoints title 'Right'")
|
||
49 | 1229 | deffi | |
50 | 1236 | deffi | #p.puts ("set terminal postscript color landscape");
|
51 | #p.puts ("set output 'test.ps'");
|
||
52 | #p.puts ("replot");
|
||
53 | 1229 | deffi | |
54 | 1236 | deffi | p.puts("pause -1");
|
55 | |||
56 | while (1) |
||
57 | end
|
||
58 | 1229 | deffi | } |
59 | |||
60 | # Never reached
|
||
61 | #File.delete('data0.tmp', 'data1.tmp') |