icub-basic-demos
acquireData.m
1 function [in,out]=acquireData(dataLogFileLeft,dataLogFileRight,dataLogFileHead)
2 % This function returns the formatted data to learn the network upon.
3 % The three input files are the ones logged through yarpdatadumper.
4 
5 % import raw data from log files
6 dataL=dlmread(dataLogFileLeft);
7 dataR=dlmread(dataLogFileRight);
8 dataH=dlmread(dataLogFileHead);
9 
10 % remove the first column
11 dataL(:,1)=[];
12 dataR(:,1)=[];
13 dataH(:,1)=[];
14 
15 % harmonize the starting acquisition time
16 t0=min([dataL(1,1) dataR(1,1) dataH(1,1)]);
17 dataL(:,1)=dataL(:,1)-t0;
18 dataR(:,1)=dataR(:,1)-t0;
19 dataH(:,1)=dataH(:,1)-t0;
20 
21 % remove the likelihood column (not used)
22 dataL(:,5)=[];
23 dataR(:,5)=[];
24 
25 % select only the rows corresponding
26 % to object in visibility
27 dataL=dataL(dataL(:,7)~=0,1:6);
28 dataR=dataR(dataR(:,7)~=0,1:6);
29 
30 % the data format is now as:
31 % 1 2 3 4 5 6
32 % t x y z u v
33 
34 % go on with the left/right data synchronization
35 % use the left data as pivot
36 tL=dataL(:,1);
37 tR=dataR(:,1);
38 tH=dataH(:,1);
39 L=length(tL);
40 
41 % form input data as:
42 % 1 2 3 4 5 6 7
43 % tilt pan ver ul vl ur vr
44 in=zeros(L,7);
45 
46 % form the output data as:
47 % 1 2 3
48 % x y z
49 out=dataL(:,2:4);
50 
51 % fill the input data
52 for i=1:L
53  [~,jR]=min(abs(tR-tL(i)));
54  [~,jH]=min(abs(tH-tL(i)));
55  in(i,1:3)=dataH(jH,5:7);
56  in(i,4)=dataL(i,5);
57  in(i,5)=dataL(i,6);
58  in(i,6)=dataR(jR,5);
59  in(i,7)=dataR(jR,6);
60 end
61 
62 figure('Color','w');
63 global ha;
64 
65 subplot(521),hold('on'),grid,stairs(in(:,1));
66 ha{1}=gca;title('tilt');
67 set(zoom,'ActionPostCallback',@mypostcallback);
68 set(pan,'ActionPostCallback',@mypostcallback);
69 
70 subplot(523),hold('on'),grid,stairs(in(:,2));
71 ha{2}=gca;title('pan');
72 set(zoom,'ActionPostCallback',@mypostcallback);
73 set(pan,'ActionPostCallback',@mypostcallback);
74 
75 subplot(525),hold('on'),grid,stairs(in(:,3));
76 ha{3}=gca;title('ver');
77 set(zoom,'ActionPostCallback',@mypostcallback);
78 set(pan,'ActionPostCallback',@mypostcallback);
79 
80 subplot(527),hold('on'),grid,stairs(in(:,[4 6]));
81 ha{4}=gca;title('[ul ur]');
82 set(zoom,'ActionPostCallback',@mypostcallback);
83 set(pan,'ActionPostCallback',@mypostcallback);
84 
85 subplot(529),hold('on'),grid,stairs(in(:,[5 7]));
86 ha{5}=gca;title('[vl vr]');
87 set(zoom,'ActionPostCallback',@mypostcallback);
88 set(pan,'ActionPostCallback',@mypostcallback);
89 
90 subplot(524),hold('on'),grid,stairs(out(:,1));
91 ha{6}=gca;title('eye-x');
92 set(zoom,'ActionPostCallback',@mypostcallback);
93 set(pan,'ActionPostCallback',@mypostcallback);
94 
95 subplot(526),hold('on'),grid,stairs(out(:,2));
96 ha{7}=gca;title('eye-y');
97 set(zoom,'ActionPostCallback',@mypostcallback);
98 set(pan,'ActionPostCallback',@mypostcallback);
99 
100 subplot(528),hold('on'),grid,stairs(out(:,3));
101 ha{8}=gca;title('eye-z');
102 set(zoom,'ActionPostCallback',@mypostcallback);
103 set(pan,'ActionPostCallback',@mypostcallback);
104 
105 
106 %--------------------------------------------------------------------------
107 function mypostcallback(obj,evd) %#ok<INUSL>
108 
109 global ha;
110 
111 newLim=get(evd.Axes,'XLim');
112 
113 for i=1:length(ha)
114  xlim(ha{i},newLim);
115 end
116 
117