root / trunk / code / projects / diagnostic_station / tools / plot.rb @ 1236
History | View | Annotate | Download (1.79 KB)
1 |
#!/usr/bin/env ruby
|
---|---|
2 |
|
3 |
file0='/tmp/data0.tmp'
|
4 |
file1='/tmp/data1.tmp'
|
5 |
|
6 |
points0f=[]; points0b=[]; points1f=[]; points1b=[] |
7 |
|
8 |
puts "Paste output from station here please"
|
9 |
|
10 |
while a=gets
|
11 |
a.chomp! |
12 |
a.strip! |
13 |
|
14 |
if a!="" && !(a =~ /^#/) |
15 |
if a =~ /^data encoder (0|1) (forward|backward) (.*)$/ |
16 |
num=$1; dir=$2; data=$3 |
17 |
|
18 |
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 |
|
25 |
data.split(' ').each { |pair| point=pair.split('/'); points<<point } |
26 |
end
|
27 |
end
|
28 |
end
|
29 |
|
30 |
def write_points(filename, points) |
31 |
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 |
end
|
40 |
|
41 |
write_points(file0, points0f+points0b) |
42 |
write_points(file1, points1f+points1b) |
43 |
|
44 |
IO.popen('gnuplot', 'w') { |p| |
45 |
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 |
|
50 |
#p.puts ("set terminal postscript color landscape");
|
51 |
#p.puts ("set output 'test.ps'");
|
52 |
#p.puts ("replot");
|
53 |
|
54 |
p.puts("pause -1");
|
55 |
|
56 |
while (1) |
57 |
end
|
58 |
} |
59 |
|
60 |
# Never reached
|
61 |
#File.delete('data0.tmp', 'data1.tmp')
|