Revision 1236
plot.rb | ||
---|---|---|
8 | 8 |
puts "Paste output from station here please" |
9 | 9 |
|
10 | 10 |
while a=gets |
11 |
a.chomp!
|
|
12 |
a.strip!
|
|
11 |
a.chomp!
|
|
12 |
a.strip!
|
|
13 | 13 |
|
14 |
if a!="" && !(a =~ /^#/) |
|
15 |
if a =~ /^data encoder (0|1) (forward|backward) (.*)$/ |
|
16 |
num=$1 |
|
17 |
dir=$2 |
|
18 |
data=$3 |
|
14 |
if a!="" && !(a =~ /^#/) |
|
15 |
if a =~ /^data encoder (0|1) (forward|backward) (.*)$/ |
|
16 |
num=$1; dir=$2; data=$3 |
|
19 | 17 |
|
20 |
if (num=="0" && dir=="forward" ); points=points0f
|
|
21 |
elsif (num=="0" && dir=="backward"); points=points0b
|
|
22 |
elsif (num=="1" && dir=="forward" ); points=points1f
|
|
23 |
elsif (num=="1" && dir=="backward"); points=points1b
|
|
24 |
else ; points=[]
|
|
25 |
end
|
|
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
|
|
26 | 24 |
|
27 |
data.split(' ').each { |pair| point=pair.split('/'); points<<point }
|
|
28 |
end
|
|
29 |
end
|
|
25 |
data.split(' ').each { |pair| point=pair.split('/'); points<<point }
|
|
26 |
end
|
|
27 |
end
|
|
30 | 28 |
end |
31 | 29 |
|
32 | 30 |
def write_points(filename, points) |
33 |
File.open(filename, 'w') { |f|
|
|
34 |
points.sort { |a,b|
|
|
35 |
a[0].to_i <=> b[0].to_i
|
|
36 |
}.each { |point|
|
|
37 |
puts "#{point[0]} #{point[1]}"
|
|
38 |
f.puts "#{point[0]} #{point[1]}"
|
|
39 |
}
|
|
40 |
}
|
|
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 |
}
|
|
41 | 39 |
end |
42 | 40 |
|
43 | 41 |
write_points(file0, points0f+points0b) |
44 | 42 |
write_points(file1, points1f+points1b) |
45 | 43 |
|
46 | 44 |
IO.popen('gnuplot', 'w') { |p| |
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 |
p.puts("set xlabel 'Station encoders'")
|
|
50 |
p.puts("set ylabel 'Robot encoders'")
|
|
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'")
|
|
51 | 49 |
|
52 |
p.puts("pause -1"); |
|
50 |
#p.puts ("set terminal postscript color landscape"); |
|
51 |
#p.puts ("set output 'test.ps'"); |
|
52 |
#p.puts ("replot"); |
|
53 | 53 |
|
54 |
while (1) |
|
55 |
end |
|
54 |
p.puts("pause -1"); |
|
55 |
|
|
56 |
while (1) |
|
57 |
end |
|
56 | 58 |
} |
57 | 59 |
|
58 | 60 |
# Never reached |
59 | 61 |
#File.delete('data0.tmp', 'data1.tmp') |
60 |
|
|
61 |
|
Also available in: Unified diff