Merge lp:~vytng/kalmanfilterimpl/gui into lp:kalmanfilterimpl
- gui
- Merge into trunk
Proposed by
Vy Thuy Nguyen
Status: | Merged |
---|---|
Merged at revision: | 1 |
Proposed branch: | lp:~vytng/kalmanfilterimpl/gui |
Merge into: | lp:kalmanfilterimpl |
Diff against target: |
740 lines (+355/-349) 5 files modified
nbproject/project.properties (+7/-1) src/kalmanfilter/KalmanFilter.java (+0/-80) src/kalmanfilter/RunFilter.java (+0/-268) src/kalmanfilter/impl/KalmanFilter.java (+80/-0) src/kalmanfilter/impl/RunFilter.java (+268/-0) |
To merge this branch: | bzr merge lp:~vytng/kalmanfilterimpl/gui |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Vy Nguyen | Approve | ||
Review via email:
|
Commit message
Description of the change
GUI plugins for graphs/charts added
To post a comment you must log in.
lp:~vytng/kalmanfilterimpl/gui
updated
- 6. By vy thuy nguyen(<email address hidden>)
-
GUI plugins for graphing
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'nbproject/project.properties' |
2 | --- nbproject/project.properties 2012-06-26 08:40:46 +0000 |
3 | +++ nbproject/project.properties 2012-06-29 05:34:21 +0000 |
4 | @@ -25,11 +25,17 @@ |
5 | dist.jar=${dist.dir}/KalmanFilter.jar |
6 | dist.javadoc.dir=${dist.dir}/javadoc |
7 | excludes= |
8 | +file.reference.chart.ext.jar=C:\\Users\\VyNguyen\\Downloads\\easycharts_41_eval\\EasyCharts\\chart.ext.jar |
9 | +file.reference.chart.jar=C:\\Users\\VyNguyen\\Downloads\\easycharts_41_eval\\EasyCharts\\chart.jar |
10 | +file.reference.chartServer.jar=C:\\Users\\VyNguyen\\Downloads\\easycharts_41_eval\\EasyCharts\\chartServer.jar |
11 | file.reference.Jama-1.0.2.jar=Jama-1.0.2.jar |
12 | includes=** |
13 | jar.compress=false |
14 | javac.classpath=\ |
15 | - ${file.reference.Jama-1.0.2.jar} |
16 | + ${file.reference.Jama-1.0.2.jar}:\ |
17 | + ${file.reference.chart.ext.jar}:\ |
18 | + ${file.reference.chart.jar}:\ |
19 | + ${file.reference.chartServer.jar} |
20 | # Space-separated list of extra javac options |
21 | javac.compilerargs= |
22 | javac.deprecation=false |
23 | |
24 | === removed file 'src/kalmanfilter/KalmanFilter.java' |
25 | --- src/kalmanfilter/KalmanFilter.java 2012-06-28 02:28:33 +0000 |
26 | +++ src/kalmanfilter/KalmanFilter.java 1970-01-01 00:00:00 +0000 |
27 | @@ -1,80 +0,0 @@ |
28 | -/** |
29 | - * Implementation of the Kalman Filter |
30 | - * Copyright (C) 2012 Vy Nguyen |
31 | - * |
32 | - * This library is free software; you can redistribute it and/or |
33 | - * modify it under the terms of the GNU Library General Public |
34 | - * License as published by the Free Software Foundation; either |
35 | - * version 2 of the License, or (at your option) any later version. |
36 | - * |
37 | - * This library is distributed in the hope that it will be useful, |
38 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
39 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
40 | - * Library General Public License for more details. |
41 | - * |
42 | - * You should have received a copy of the GNU Library General Public |
43 | - * License along with this library; if not, write to the |
44 | - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
45 | - * Boston, MA 02110-1301, USA. |
46 | - */ |
47 | -package kalmanfilter; |
48 | - |
49 | -import Jama.Matrix; |
50 | - |
51 | -/** |
52 | - * Implements the Kalman Filter using Jama's Matrix API |
53 | - * |
54 | - * @author Vy Thao Nguyen |
55 | - */ |
56 | -public class KalmanFilter |
57 | -{ |
58 | - // variable states |
59 | - private Matrix X; // input vector |
60 | - private Matrix P; // state covariance matrix |
61 | - private Matrix Q; // process noise covariance matrix |
62 | - |
63 | - // const states |
64 | - private final Matrix H; // observation matrix |
65 | - private final Matrix I; // the identity matrix |
66 | - private final Matrix A; // state matrix |
67 | - private final Matrix R; // measurement noise covariance matrix |
68 | - private final Matrix B; // control input matrix |
69 | - private final Matrix u; |
70 | - |
71 | - public KalmanFilter(Matrix X, Matrix P, Matrix Q, Matrix H, Matrix A, Matrix R, Matrix B, Matrix u) |
72 | - { |
73 | - this.X = X; |
74 | - this.P = P; |
75 | - this.Q = Q; |
76 | - this.H = H; |
77 | - this.A = A; |
78 | - this.R = R; |
79 | - this.B = B; |
80 | - this.u = u; |
81 | - |
82 | - I = Matrix.identity(P.getRowDimension(), P.getColumnDimension()); |
83 | - } |
84 | - |
85 | - public KalmanFilter timeUpdate() |
86 | - { |
87 | - X = A.times(X).plus(B.times(u)); |
88 | - P = A.times(P).times(A.transpose()).plus(Q); |
89 | - return this; // for easy chaining |
90 | - } |
91 | - |
92 | - public Matrix messurementUpdate(Matrix Xk) |
93 | - { |
94 | - // compute kalman gain |
95 | - //Kk+1 = PkHT(H PkHT + R)-1 |
96 | - Matrix K = P.times(H.transpose()).times((H.times(P).times(H.trace()).plus(R)).inverse()); |
97 | - |
98 | - // update x |
99 | - // xk+1 = xk + K(zk+1 − Hxk ) |
100 | - X = X.plus(K.times((Xk.times(H)).minus(H.times(X)))); |
101 | - |
102 | - // update P |
103 | - P = (I.minus(K.times(H))).times(P); |
104 | - |
105 | - return X; |
106 | - } |
107 | -} |
108 | |
109 | === removed file 'src/kalmanfilter/RunFilter.java' |
110 | --- src/kalmanfilter/RunFilter.java 2012-06-28 04:07:30 +0000 |
111 | +++ src/kalmanfilter/RunFilter.java 1970-01-01 00:00:00 +0000 |
112 | @@ -1,268 +0,0 @@ |
113 | -/** |
114 | - * Implementation of the Kalman Filter |
115 | - * Copyright (C) 2012 Vy Nguyen |
116 | - * |
117 | - * This library is free software; you can redistribute it and/or |
118 | - * modify it under the terms of the GNU Library General Public |
119 | - * License as published by the Free Software Foundation; either |
120 | - * version 2 of the License, or (at your option) any later version. |
121 | - * |
122 | - * This library is distributed in the hope that it will be useful, |
123 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
124 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
125 | - * Library General Public License for more details. |
126 | - * |
127 | - * You should have received a copy of the GNU Library General Public |
128 | - * License along with this library; if not, write to the |
129 | - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
130 | - * Boston, MA 02110-1301, USA. |
131 | - */ |
132 | - |
133 | -package kalmanfilter; |
134 | - |
135 | -import Jama.Matrix; |
136 | -import java.util.ArrayList; |
137 | -import java.util.Arrays; |
138 | -import java.util.Collections; |
139 | -import java.util.List; |
140 | - |
141 | -/** |
142 | - * |
143 | - * @author Vy Thao Nguyen |
144 | - */ |
145 | -public class RunFilter |
146 | -{ |
147 | - /** |
148 | - * Represents a point |
149 | - */ |
150 | - public static class Point implements Comparable<Point> |
151 | - { |
152 | - final double x; // x coord |
153 | - final double y; // y coord |
154 | - final double t; // time coord |
155 | - final double vx; // instant x-velocity |
156 | - final double vy; // instant y-velocity |
157 | - final double ax; // instant x-acceleration |
158 | - final double ay; // instant y-acceleration |
159 | - |
160 | - /** |
161 | - * |
162 | - * @param x |
163 | - * @param y |
164 | - * @param t |
165 | - * @param vx |
166 | - * @param vy |
167 | - * @param ax |
168 | - * @param ay |
169 | - */ |
170 | - public Point(double x, double y, double t, double vx, double vy, double ax, double ay) |
171 | - { |
172 | - this.x = x; |
173 | - this.y = y; |
174 | - this.t = t; |
175 | - this.vx = vx; |
176 | - this.vy = vy; |
177 | - this.ax = ax; |
178 | - this.ay = ay; |
179 | - } |
180 | - |
181 | - @Override |
182 | - public int compareTo(Point o) |
183 | - { |
184 | - return Double.compare(t, o.t); |
185 | - } |
186 | - } |
187 | - |
188 | - /** |
189 | - * |
190 | - * @param inputs |
191 | - * @param sensorNoise |
192 | - * @return |
193 | - */ |
194 | - public static List<Point> filter(List<Point> inputs, double sensorNoise) |
195 | - { |
196 | - // sort the points in time order |
197 | - Collections.sort(inputs); |
198 | - |
199 | - List<Point> output = new ArrayList<>(inputs.size()); |
200 | - |
201 | - //(Matrix X, Matrix P, Matrix Q, Matrix H, Matrix A, Matrix R) |
202 | - KalmanFilter filter = new KalmanFilter(createX(inputs, 0), |
203 | - getP0(), |
204 | - getQ(), |
205 | - getH(), |
206 | - createA(inputs, 0), |
207 | - createR(sensorNoise), |
208 | - createB(), |
209 | - createU()); |
210 | - |
211 | - for (int n = 1; n < inputs.size(); ++n) |
212 | - { |
213 | - Matrix corrected = filter.timeUpdate().messurementUpdate(createX(inputs, n)); |
214 | - output.add(decodeX(corrected, inputs.get(n).t)); |
215 | - } |
216 | - |
217 | - return output; |
218 | - } |
219 | - |
220 | - /** |
221 | - * TODO: correctly decode the state matrix into a point. |
222 | - * (that is, retrieve a and v) |
223 | - * |
224 | - * @param X the corrected state matrix |
225 | - * @return the corrected value of (x,y,t) |
226 | - */ |
227 | - private static Point decodeX(Matrix X, double t) |
228 | - { |
229 | - //return new Point(X.get(0, 0), X.get(0, 1), t, 0, 0); |
230 | - throw new UnsupportedOperationException(); |
231 | - } |
232 | - |
233 | - /** |
234 | - * TODO: correctly encode the point (velocity, acceleration, etc.) into a matrix. |
235 | - * |
236 | - * Vector x = {x, y, vx , vy , ax, ay} |
237 | - * |
238 | - * @param points |
239 | - * @param currentIndex index of the point the filter is currently looking at |
240 | - * @return the input vector X |
241 | - */ |
242 | - private static Matrix createX(List<Point> points, int currentIndex) |
243 | - { |
244 | - Matrix x = new Matrix(1, 6); |
245 | - |
246 | - List<Point> updatedPoints = computeVAndA(points); |
247 | - |
248 | - x.set(0, 0, updatedPoints.get(currentIndex).x); |
249 | - x.set(0, 1, updatedPoints.get(currentIndex).y); |
250 | - x.set(0, 2, updatedPoints.get(currentIndex).vx); |
251 | - x.set(0, 3, updatedPoints.get(currentIndex).vy); |
252 | - x.set(0, 4, updatedPoints.get(currentIndex).ax); |
253 | - x.set(0, 5, updatedPoints.get(currentIndex).ay); |
254 | - |
255 | - return x; |
256 | - } |
257 | - |
258 | - /** |
259 | - * Compute the instant velocity and acceleration of each point |
260 | - * <b>This method makes the following assumptions:</b> |
261 | - * 1. Acceleration of a Point object is constant and was properly set in the constructor. |
262 | - * 2. The velocity of the first point is either 0 or has already been correctly calculated. |
263 | - * |
264 | - * TODO: take variable acceleration into account. |
265 | - * |
266 | - * @param points |
267 | - * @return list of point with correct v and a |
268 | - */ |
269 | - private static List<Point> computeVAndA(List<Point> points) |
270 | - { |
271 | - int size = points.size(); |
272 | - double vx_0 = points.get(0).vx; |
273 | - double vy_0 = points.get(0).vy; |
274 | - double ax_0 = points.get(0).ax; |
275 | - double ay_0 = points.get(0).ay; |
276 | - |
277 | - List<Point> result = new ArrayList<Point> (size); |
278 | - result.add(points.get(0)); |
279 | - |
280 | - for (int i = 1; i < size; ++i) |
281 | - { |
282 | - double dt = points.get(i).t - points.get(0).t; |
283 | - double vx = vx_0 + ax_0 * dt; |
284 | - double vy = vy_0 + ay_0 * dt; |
285 | - |
286 | - result.add(new Point(points.get(i).x, |
287 | - points.get(i).y, |
288 | - points.get(i).t, |
289 | - vx, |
290 | - vy, |
291 | - points.get(i).ax, |
292 | - points.get(i).ay |
293 | - )); |
294 | - } |
295 | - |
296 | - return result; |
297 | - } |
298 | - |
299 | - /** |
300 | - * TODO: |
301 | - * Same as createX(...)'s |
302 | - * |
303 | - * @param inputs |
304 | - * @param currentIndex |
305 | - * @return the state matrix A based on the the current and past position |
306 | - */ |
307 | - private static Matrix createA(List<Point> inputs, int currentIndex) |
308 | - { |
309 | - throw new UnsupportedOperationException(); |
310 | - } |
311 | - |
312 | - /** |
313 | - * |
314 | - * @param error the sensor's error |
315 | - * @return the measurement noise covariance matrix |
316 | - */ |
317 | - private static Matrix createR (double error) |
318 | - { |
319 | - Matrix R = new Matrix(1,1); |
320 | - R.set(0, 0, error); |
321 | - return R; |
322 | - } |
323 | - /** |
324 | - * |
325 | - * @return the initial P matrix, which contains all zeroes |
326 | - */ |
327 | - private static Matrix getP0() |
328 | - { |
329 | - double m6x6[][] = new double[VARS_COUNT][VARS_COUNT]; |
330 | - |
331 | - for (int n = 0; n < VARS_COUNT; ++n) |
332 | - Arrays.fill(m6x6[n], 0); |
333 | - |
334 | - return Matrix.constructWithCopy(m6x6); |
335 | - } |
336 | - |
337 | - /** |
338 | - * TODO: |
339 | - * correctly determine this |
340 | - * |
341 | - * @return the process noise covariance matrix |
342 | - */ |
343 | - private static Matrix getQ() |
344 | - { |
345 | - throw new UnsupportedOperationException(); |
346 | - } |
347 | - |
348 | - /** |
349 | - * |
350 | - * @return the [1 by n] observation matrix: [1 0 0 0 .... 0 ] |
351 | - */ |
352 | - private static Matrix getH() |
353 | - { |
354 | - Matrix H = new Matrix(1,6); |
355 | - H.set(0, 0, 1); |
356 | - return H; |
357 | - } |
358 | - |
359 | - /** |
360 | - * TODO: determine the value of B |
361 | - * (could take an argument) |
362 | - * @return |
363 | - */ |
364 | - private static Matrix createB() |
365 | - { |
366 | - throw new UnsupportedOperationException(); |
367 | - } |
368 | - |
369 | - /** |
370 | - * TODO: similar to B |
371 | - * |
372 | - * @return |
373 | - */ |
374 | - private static Matrix createU() |
375 | - { |
376 | - throw new UnsupportedOperationException(); |
377 | - } |
378 | - |
379 | - private static final int VARS_COUNT = 6; |
380 | -} |
381 | |
382 | === added directory 'src/kalmanfilter/gui' |
383 | === added directory 'src/kalmanfilter/impl' |
384 | === added file 'src/kalmanfilter/impl/KalmanFilter.java' |
385 | --- src/kalmanfilter/impl/KalmanFilter.java 1970-01-01 00:00:00 +0000 |
386 | +++ src/kalmanfilter/impl/KalmanFilter.java 2012-06-29 05:34:21 +0000 |
387 | @@ -0,0 +1,80 @@ |
388 | +/** |
389 | + * Implementation of the Kalman Filter |
390 | + * Copyright (C) 2012 Vy Nguyen |
391 | + * |
392 | + * This library is free software; you can redistribute it and/or |
393 | + * modify it under the terms of the GNU Library General Public |
394 | + * License as published by the Free Software Foundation; either |
395 | + * version 2 of the License, or (at your option) any later version. |
396 | + * |
397 | + * This library is distributed in the hope that it will be useful, |
398 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
399 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
400 | + * Library General Public License for more details. |
401 | + * |
402 | + * You should have received a copy of the GNU Library General Public |
403 | + * License along with this library; if not, write to the |
404 | + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
405 | + * Boston, MA 02110-1301, USA. |
406 | + */ |
407 | +package kalmanfilter.impl; |
408 | + |
409 | +import Jama.Matrix; |
410 | + |
411 | +/** |
412 | + * Implements the Kalman Filter using Jama's Matrix API |
413 | + * |
414 | + * @author Vy Thao Nguyen |
415 | + */ |
416 | +public class KalmanFilter |
417 | +{ |
418 | + // variable states |
419 | + private Matrix X; // input vector |
420 | + private Matrix P; // state covariance matrix |
421 | + private Matrix Q; // process noise covariance matrix |
422 | + |
423 | + // const states |
424 | + private final Matrix H; // observation matrix |
425 | + private final Matrix I; // the identity matrix |
426 | + private final Matrix A; // state matrix |
427 | + private final Matrix R; // measurement noise covariance matrix |
428 | + private final Matrix B; // control input matrix |
429 | + private final Matrix u; |
430 | + |
431 | + public KalmanFilter(Matrix X, Matrix P, Matrix Q, Matrix H, Matrix A, Matrix R, Matrix B, Matrix u) |
432 | + { |
433 | + this.X = X; |
434 | + this.P = P; |
435 | + this.Q = Q; |
436 | + this.H = H; |
437 | + this.A = A; |
438 | + this.R = R; |
439 | + this.B = B; |
440 | + this.u = u; |
441 | + |
442 | + I = Matrix.identity(P.getRowDimension(), P.getColumnDimension()); |
443 | + } |
444 | + |
445 | + public KalmanFilter timeUpdate() |
446 | + { |
447 | + X = A.times(X).plus(B.times(u)); |
448 | + P = A.times(P).times(A.transpose()).plus(Q); |
449 | + return this; // for easy chaining |
450 | + } |
451 | + |
452 | + public Matrix messurementUpdate(Matrix Xk) |
453 | + { |
454 | + // compute kalman gain |
455 | + //Kk+1 = PkHT(H PkHT + R)-1 |
456 | + Matrix K = P.times(H.transpose()).times((H.times(P).times(H.trace()).plus(R)).inverse()); |
457 | + |
458 | + // update x |
459 | + // xk+1 = xk + K(zk+1 − Hxk ) |
460 | + X = X.plus(K.times((Xk.times(H)).minus(H.times(X)))); |
461 | + |
462 | + // update P |
463 | + P = (I.minus(K.times(H))).times(P); |
464 | + |
465 | + return X; |
466 | + } |
467 | +} |
468 | |
469 | === added file 'src/kalmanfilter/impl/RunFilter.java' |
470 | --- src/kalmanfilter/impl/RunFilter.java 1970-01-01 00:00:00 +0000 |
471 | +++ src/kalmanfilter/impl/RunFilter.java 2012-06-29 05:34:21 +0000 |
472 | @@ -0,0 +1,268 @@ |
473 | +/** |
474 | + * Implementation of the Kalman Filter |
475 | + * Copyright (C) 2012 Vy Nguyen |
476 | + * |
477 | + * This library is free software; you can redistribute it and/or |
478 | + * modify it under the terms of the GNU Library General Public |
479 | + * License as published by the Free Software Foundation; either |
480 | + * version 2 of the License, or (at your option) any later version. |
481 | + * |
482 | + * This library is distributed in the hope that it will be useful, |
483 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
484 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
485 | + * Library General Public License for more details. |
486 | + * |
487 | + * You should have received a copy of the GNU Library General Public |
488 | + * License along with this library; if not, write to the |
489 | + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
490 | + * Boston, MA 02110-1301, USA. |
491 | + */ |
492 | + |
493 | +package kalmanfilter.impl; |
494 | + |
495 | +import Jama.Matrix; |
496 | +import java.util.ArrayList; |
497 | +import java.util.Arrays; |
498 | +import java.util.Collections; |
499 | +import java.util.List; |
500 | + |
501 | +/** |
502 | + * |
503 | + * @author Vy Thao Nguyen |
504 | + */ |
505 | +public class RunFilter |
506 | +{ |
507 | + /** |
508 | + * Represents a point |
509 | + */ |
510 | + public static class Point implements Comparable<Point> |
511 | + { |
512 | + final double x; // x coord |
513 | + final double y; // y coord |
514 | + final double t; // time coord |
515 | + final double vx; // instant x-velocity |
516 | + final double vy; // instant y-velocity |
517 | + final double ax; // instant x-acceleration |
518 | + final double ay; // instant y-acceleration |
519 | + |
520 | + /** |
521 | + * |
522 | + * @param x |
523 | + * @param y |
524 | + * @param t |
525 | + * @param vx |
526 | + * @param vy |
527 | + * @param ax |
528 | + * @param ay |
529 | + */ |
530 | + public Point(double x, double y, double t, double vx, double vy, double ax, double ay) |
531 | + { |
532 | + this.x = x; |
533 | + this.y = y; |
534 | + this.t = t; |
535 | + this.vx = vx; |
536 | + this.vy = vy; |
537 | + this.ax = ax; |
538 | + this.ay = ay; |
539 | + } |
540 | + |
541 | + @Override |
542 | + public int compareTo(Point o) |
543 | + { |
544 | + return Double.compare(t, o.t); |
545 | + } |
546 | + } |
547 | + |
548 | + /** |
549 | + * |
550 | + * @param inputs |
551 | + * @param sensorNoise |
552 | + * @return |
553 | + */ |
554 | + public static List<Point> filter(List<Point> inputs, double sensorNoise) |
555 | + { |
556 | + // sort the points in time order |
557 | + Collections.sort(inputs); |
558 | + |
559 | + List<Point> output = new ArrayList<>(inputs.size()); |
560 | + |
561 | + //(Matrix X, Matrix P, Matrix Q, Matrix H, Matrix A, Matrix R) |
562 | + KalmanFilter filter = new KalmanFilter(createX(inputs, 0), |
563 | + getP0(), |
564 | + getQ(), |
565 | + getH(), |
566 | + createA(inputs, 0), |
567 | + createR(sensorNoise), |
568 | + createB(), |
569 | + createU()); |
570 | + |
571 | + for (int n = 1; n < inputs.size(); ++n) |
572 | + { |
573 | + Matrix corrected = filter.timeUpdate().messurementUpdate(createX(inputs, n)); |
574 | + output.add(decodeX(corrected, inputs.get(n).t)); |
575 | + } |
576 | + |
577 | + return output; |
578 | + } |
579 | + |
580 | + /** |
581 | + * TODO: correctly decode the state matrix into a point. |
582 | + * (that is, retrieve a and v) |
583 | + * |
584 | + * @param X the corrected state matrix |
585 | + * @return the corrected value of (x,y,t) |
586 | + */ |
587 | + private static Point decodeX(Matrix X, double t) |
588 | + { |
589 | + //return new Point(X.get(0, 0), X.get(0, 1), t, 0, 0); |
590 | + throw new UnsupportedOperationException(); |
591 | + } |
592 | + |
593 | + /** |
594 | + * TODO: correctly encode the point (velocity, acceleration, etc.) into a matrix. |
595 | + * |
596 | + * Vector x = {x, y, vx , vy , ax, ay} |
597 | + * |
598 | + * @param points |
599 | + * @param currentIndex index of the point the filter is currently looking at |
600 | + * @return the input vector X |
601 | + */ |
602 | + private static Matrix createX(List<Point> points, int currentIndex) |
603 | + { |
604 | + Matrix x = new Matrix(1, 6); |
605 | + |
606 | + List<Point> updatedPoints = computeVAndA(points); |
607 | + |
608 | + x.set(0, 0, updatedPoints.get(currentIndex).x); |
609 | + x.set(0, 1, updatedPoints.get(currentIndex).y); |
610 | + x.set(0, 2, updatedPoints.get(currentIndex).vx); |
611 | + x.set(0, 3, updatedPoints.get(currentIndex).vy); |
612 | + x.set(0, 4, updatedPoints.get(currentIndex).ax); |
613 | + x.set(0, 5, updatedPoints.get(currentIndex).ay); |
614 | + |
615 | + return x; |
616 | + } |
617 | + |
618 | + /** |
619 | + * Compute the instant velocity and acceleration of each point |
620 | + * <b>This method makes the following assumptions:</b> |
621 | + * 1. Acceleration of a Point object is constant and was properly set in the constructor. |
622 | + * 2. The velocity of the first point is either 0 or has already been correctly calculated. |
623 | + * |
624 | + * TODO: take variable acceleration into account. |
625 | + * |
626 | + * @param points |
627 | + * @return list of point with correct v and a |
628 | + */ |
629 | + private static List<Point> computeVAndA(List<Point> points) |
630 | + { |
631 | + int size = points.size(); |
632 | + double vx_0 = points.get(0).vx; |
633 | + double vy_0 = points.get(0).vy; |
634 | + double ax_0 = points.get(0).ax; |
635 | + double ay_0 = points.get(0).ay; |
636 | + |
637 | + List<Point> result = new ArrayList<Point> (size); |
638 | + result.add(points.get(0)); |
639 | + |
640 | + for (int i = 1; i < size; ++i) |
641 | + { |
642 | + double dt = points.get(i).t - points.get(0).t; |
643 | + double vx = vx_0 + ax_0 * dt; |
644 | + double vy = vy_0 + ay_0 * dt; |
645 | + |
646 | + result.add(new Point(points.get(i).x, |
647 | + points.get(i).y, |
648 | + points.get(i).t, |
649 | + vx, |
650 | + vy, |
651 | + points.get(i).ax, |
652 | + points.get(i).ay |
653 | + )); |
654 | + } |
655 | + |
656 | + return result; |
657 | + } |
658 | + |
659 | + /** |
660 | + * TODO: |
661 | + * Same as createX(...)'s |
662 | + * |
663 | + * @param inputs |
664 | + * @param currentIndex |
665 | + * @return the state matrix A based on the the current and past position |
666 | + */ |
667 | + private static Matrix createA(List<Point> inputs, int currentIndex) |
668 | + { |
669 | + throw new UnsupportedOperationException(); |
670 | + } |
671 | + |
672 | + /** |
673 | + * |
674 | + * @param error the sensor's error |
675 | + * @return the measurement noise covariance matrix |
676 | + */ |
677 | + private static Matrix createR (double error) |
678 | + { |
679 | + Matrix R = new Matrix(1,1); |
680 | + R.set(0, 0, error); |
681 | + return R; |
682 | + } |
683 | + /** |
684 | + * |
685 | + * @return the initial P matrix, which contains all zeroes |
686 | + */ |
687 | + private static Matrix getP0() |
688 | + { |
689 | + double m6x6[][] = new double[VARS_COUNT][VARS_COUNT]; |
690 | + |
691 | + for (int n = 0; n < VARS_COUNT; ++n) |
692 | + Arrays.fill(m6x6[n], 0); |
693 | + |
694 | + return Matrix.constructWithCopy(m6x6); |
695 | + } |
696 | + |
697 | + /** |
698 | + * TODO: |
699 | + * correctly determine this |
700 | + * |
701 | + * @return the process noise covariance matrix |
702 | + */ |
703 | + private static Matrix getQ() |
704 | + { |
705 | + throw new UnsupportedOperationException(); |
706 | + } |
707 | + |
708 | + /** |
709 | + * |
710 | + * @return the [1 by n] observation matrix: [1 0 0 0 .... 0 ] |
711 | + */ |
712 | + private static Matrix getH() |
713 | + { |
714 | + Matrix H = new Matrix(1,6); |
715 | + H.set(0, 0, 1); |
716 | + return H; |
717 | + } |
718 | + |
719 | + /** |
720 | + * TODO: determine the value of B |
721 | + * (could take an argument) |
722 | + * @return |
723 | + */ |
724 | + private static Matrix createB() |
725 | + { |
726 | + throw new UnsupportedOperationException(); |
727 | + } |
728 | + |
729 | + /** |
730 | + * TODO: similar to B |
731 | + * |
732 | + * @return |
733 | + */ |
734 | + private static Matrix createU() |
735 | + { |
736 | + throw new UnsupportedOperationException(); |
737 | + } |
738 | + |
739 | + private static final int VARS_COUNT = 6; |
740 | +} |
This is merged.