Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / diagnostic_station / tools / plot.rb @ 1232

History | View | Annotate | Download (1.4 KB)

1
#!/usr/bin/env ruby
2

    
3
file0='/tmp/data0.tmp'
4
file1='/tmp/data1.tmp'
5

    
6
points0f=[]
7
points0b=[]
8
points1f=[]
9
points1b=[]
10

    
11
puts "Paste output from station here please"
12

    
13
while a=gets
14
        a.chomp!
15
        a.strip!
16

    
17
        if a!="" && !(a =~ /^#/)
18
                if a =~ /^data encoder (0|1) (forward|backward) (.*)$/
19
                        num=$1
20
                        dir=$2
21
                        data=$3
22

    
23
                        if (num=="0" && dir=="forward")
24
                                points=points0f
25
                        elsif (num=="0" && dir=="backward")
26
                                points=points0b
27
                        elsif (num=="1" && dir=="forward")
28
                                points=points1f
29
                        elsif (num=="1" && dir=="backward")
30
                                points=points1b
31
                        else
32
                                points=[]
33
                        end
34

    
35
                        data.split(' ').each { |pair|
36
                                point=pair.split('/');
37
                                points<<point
38
                        }
39
                end
40
        end
41
end
42

    
43
#(points0f+points0b).each { |p|
44
#        puts "#{p[0]} #{p[1]}"
45
#}
46

    
47
points0=points0f+points0b
48
points1=points1f+points1b
49

    
50
File.open(file0, 'w') { |f|
51
        points0.sort { |a,b|
52
                a[0].to_i <=> b[0].to_i
53
        }.each { |point|
54
                puts "#{point[0]} #{point[1]}"
55
                f.puts "#{point[0]} #{point[1]}"
56
        }
57
}
58

    
59
File.open(file1, 'w') { |f|
60
        points1.sort { |a,b|
61
                a[0].to_i <=> b[0].to_i
62
        }.each { |point|
63
                f.puts "#{point[0]} #{point[1]}"
64
        }
65
}
66

    
67
IO.popen('gnuplot', 'w') { |p|
68
        p.puts("plot   '#{file0}' using 1:2 with linespoints title 'Left'")
69
        p.puts("replot '#{file1}' using 1:2 with linespoints title 'Right'")
70
        p.puts("set xlabel 'Station encoders'")
71
        p.puts("set ylabel 'Robot encoders'")
72

    
73
        p.puts("pause -1");
74

    
75
        while (1)
76
        end
77
}
78

    
79
# Never reached
80
#File.delete('data0.tmp', 'data1.tmp')
81

    
82