summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/localization/src/matlab/script_run_profile.m
blob: 44ce3aa8c536e48d9c125a0ee43d0c732f5e1ee4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
function script_run_profile(dataDir, resultDir, type, common, toolDir)

path(path, common);
file = fopen([dataDir, '/1.txt'], 'r');
full = fscanf(file,'%f');
elapsed = zeros(1,2);

rows = full(2);
cols = full(1);
fid = zeros(rows, cols);

k = 3;
for i=1:rows
    for j =1:cols
        fid(i,j) = full(k);
        k = k+1;
    end
end

fclose(file);

n=1000;

gyroTimeInterval=0.01;
acclTimeInterval=0.01;

STDDEV_GPSVel=0.5;

STDDEV_ODOVel=0.1;
STDDEV_ACCL=1;
M_STDDEV_GYRO=0.1;
M_STDDEV_POS=0.1;
M_STDDEV_VEL=0.02;

if(strcmp(type,'test'))
        n = 3;
        gyroTimeInterval = 0.1;
        acclTimeInterval = 0.1;
        M_STDDEV_VEL = 0.2;
    
elseif(strcmp(type, 'sim_fast'))
        n = 3;
elseif(strcmp(type, 'sim'))
        n = 10;
elseif(strcmp(type, 'sqcif'))
        n = 800;
elseif(strcmp(type, 'qcif'))
        n = 500;
elseif(strcmp(type, 'vga'))
        n = 2000;
elseif(strcmp(type, 'wuxga'))
        n = 3000;
end

fprintf(1,'Input size\t\t- (%dx%dx%d)\n', rows, cols,n);
pos=zeros(n,3);

vel=zeros(n,3) + randWrapper(n,3)*STDDEV_ODOVel;
pi = 3.1416;

eul1 = eul2quat([zeros(n,2), randWrapper(n,1)*2*pi]);
eul2 = eul2quat([pi, 0, 0]);
quat=quatMul(eul1, eul2);

i=0;
index = 0;
resultMat = zeros(3,rows);

while 1
    i=i+1;
    [tStamp, sType, sData, isEOF, index] = readSensorData(index, fid);

    start = photonStartTiming;

    if(sType==2)


        %Motion model
        gyro = sData(1, 1:3);
        randnWrapper_mat = randnWrapper(n,3);    % KVS: We do not have function implementation for randnWrapper()
        gyro=ones(n,1)*gyro+randnWrapper_mat*M_STDDEV_GYRO;

        abc = gyro.^2;
        abcd = sumCol(abc);
        norm_gyro = sqrt(abcd);
%        norm_gyro=sqrt(sum(gyro.^2,2));
        angleAlpha=norm_gyro*gyroTimeInterval;
        quatDelta=[cos(angleAlpha/2), gyro./(norm_gyro*ones(1,3)+0.00000001).*(sin(angleAlpha/2)*ones(1,3))];
        quat=quatMul(quat, quatDelta);

    end

    if(sType==4)
        %Observation
        STDDEV_GPSPos=[sData(1,7), 0, 0; 0, sData(1,8), 0; 0, 0, 15];
        Opos=sData(1,1:3);

        %Initialize
        
        randnWrapper_mat = randnWrapper(n,3);
        if sum(sum(pos))==0
            pos=ones(n,1) * Opos + randnWrapper_mat*STDDEV_GPSPos;
        else 
           rows = size(STDDEV_GPSPos, 1);
           cols = size(STDDEV_GPSPos, 2);

            temp_STDDEV_GPSPos = ones(rows,cols);
            for mnrows=1:rows                                 % KVS" Photon rejects this loop becasue of too many nestings ??
                for mncols=1:cols
                    temp_STDDEV_GPSPos(mnrows, mncols) = power(STDDEV_GPSPos(mnrows,mncols),-1);
                end
            end
           [temp, w]=mcl(pos, Opos , temp_STDDEV_GPSPos);
           [quat, vel, pos]=generateSample(w, quat, vel, pos, M_STDDEV_VEL, M_STDDEV_POS);
       end

       %compare direction
       Ovel=sData(1,4:6);

%        KVS: We do not have function for norm() yet! So replacing this operating with OvelNorm
  
%        OvelNorm=norm(Ovel);                               
       OvelNorm= 2.0;  %1.1169e+09;
       
       if (OvelNorm>0.5)
       
           % KVS: Similar here: No impln of norm(), so replacing
           % norm(Ovel) with OvelNorm value
           
           Ovel=Ovel/OvelNorm;
           %trick
           %quat=addEulNoise(quat, STDDEV_GPSVel);
           qConj = quatConj(quat);
            orgWorld=quatRot([1, 0, 0],qConj);
            eye3 = [1,0,0;0,1,0;0,0,1];
            [temp, w]=mcl(orgWorld, Ovel, eye3./STDDEV_GPSVel);
            [quat, vel, pos]=generateSample(w, quat, vel, pos, M_STDDEV_VEL, M_STDDEV_POS);
       end
 
   end
   
   if(sType==1)

       %Observation
       Ovel=sData(1,1);
       [temp, w]=mcl(sqrt(vel(:,1).^2+vel(:,2).^2+vel(:,3).^2), Ovel, 1/(STDDEV_ODOVel));

       [quat vel pos]=generateSample(w, quat, vel, pos, M_STDDEV_VEL, M_STDDEV_POS);
   end
   
   if(sType==3)
       %Observation
       accl=sData(1,1:3);
       
       gtemp = ones(n,1) * [0 0 -9.8];
       
       gravity=quatRot(gtemp, quat);
        eye3 = [1,0,0;0,1,0;0,0,1];
        [gravity, w]=mcl(gravity, accl, eye3./(STDDEV_ACCL));

        [quat, vel, pos]=generateSample(w, quat, vel, pos, M_STDDEV_VEL, M_STDDEV_POS);

        %Motion model
        accl=ones(n,1)*accl;
        accl=accl-gravity;
        pos=pos+quatRot(vel,quatConj(quat))*acclTimeInterval ...
            +1/2*quatRot(accl,quatConj(quat))*acclTimeInterval^2 ...
            +randnWrapper(n,3)*M_STDDEV_POS;
        vel=vel+accl*acclTimeInterval+randnWrapper(n,3)*M_STDDEV_VEL;

   end
   
    stop = photonEndTiming;
    
    temp = photonReportTiming(start, stop);
    elapsed(1) = elapsed(1) + temp(1);
    elapsed(2) = elapsed(2) + temp(2);

    % Self check

    quatOut = 0;
    posOut = 0;
    velOut = 0;

    for ij=1:(size(quat,1)*size(quat,2))
        quatOut = quatOut + quat(ij);
    end

    for ij=1:(size(vel,1)*size(vel,2))
        velOut = velOut + vel(ij);
    end

    for ij=1:(size(pos,1)*size(pos,2))
        posOut = posOut + pos(ij);
    end

    resultMat(:, i) = [quatOut, velOut, posOut];

    if (isEOF == 1)
        break;
    end
end

%% Timing
photonPrintTiming(elapsed);

%% Self checking %%
fWriteMatrix(resultMat,dataDir);