Merge lp:~vytng/kalmanfilterimpl/supportVelocity into lp:kalmanfilterimpl

Proposed by Vy Thuy Nguyen
Status: Merged
Approved by: Vy Nguyen
Approved revision: 7
Merged at revision: 5
Proposed branch: lp:~vytng/kalmanfilterimpl/supportVelocity
Merge into: lp:kalmanfilterimpl
Diff against target: 152 lines (+91/-9)
1 file modified
src/kalmanfilter/RunFilter.java (+91/-9)
To merge this branch: bzr merge lp:~vytng/kalmanfilterimpl/supportVelocity
Reviewer Review Type Date Requested Status
Vy Nguyen Approve
Review via email: mp+112481@code.launchpad.net

Description of the change

- add computeVAndA()
- implement createX()

To post a comment you must log in.
6. By vy thuy nguyen(<email address hidden>)

Fix thinkos in computeVAndA()

7. By vy thuy nguyen(<email address hidden>)

More thinkos

Revision history for this message
Vy Nguyen (oontvoo) wrote :

Looks great! Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/kalmanfilter/RunFilter.java'
2--- src/kalmanfilter/RunFilter.java 2012-06-28 02:28:33 +0000
3+++ src/kalmanfilter/RunFilter.java 2012-06-28 04:10:24 +0000
4@@ -32,17 +32,40 @@
5 */
6 public class RunFilter
7 {
8+ /**
9+ * Represents a point
10+ */
11 public static class Point implements Comparable<Point>
12 {
13 final double x; // x coord
14 final double y; // y coord
15 final double t; // time coord
16- public Point(double x, double y, double t)
17+ final double vx; // instant x-velocity
18+ final double vy; // instant y-velocity
19+ final double ax; // instant x-acceleration
20+ final double ay; // instant y-acceleration
21+
22+ /**
23+ *
24+ * @param x
25+ * @param y
26+ * @param t
27+ * @param vx
28+ * @param vy
29+ * @param ax
30+ * @param ay
31+ */
32+ public Point(double x, double y, double t, double vx, double vy, double ax, double ay)
33 {
34 this.x = x;
35 this.y = y;
36 this.t = t;
37+ this.vx = vx;
38+ this.vy = vy;
39+ this.ax = ax;
40+ this.ay = ay;
41 }
42+
43 @Override
44 public int compareTo(Point o)
45 {
46@@ -50,6 +73,12 @@
47 }
48 }
49
50+ /**
51+ *
52+ * @param inputs
53+ * @param sensorNoise
54+ * @return
55+ */
56 public static List<Point> filter(List<Point> inputs, double sensorNoise)
57 {
58 // sort the points in time order
59@@ -77,32 +106,85 @@
60 }
61
62 /**
63+ * TODO: correctly decode the state matrix into a point.
64+ * (that is, retrieve a and v)
65 *
66 * @param X the corrected state matrix
67 * @return the corrected value of (x,y,t)
68 */
69 private static Point decodeX(Matrix X, double t)
70 {
71- return new Point(X.get(0, 0), X.get(0, 1), t);
72+ //return new Point(X.get(0, 0), X.get(0, 1), t, 0, 0);
73+ throw new UnsupportedOperationException();
74 }
75
76 /**
77- * TODO:
78- * calculate the instance velocity v_x, v_y, a_x and a_y based on
79- * the current and past positions
80+ * TODO: correctly encode the point (velocity, acceleration, etc.) into a matrix.
81 *
82 * Vector x = {x, y, vx , vy , ax, ay}
83 *
84- * @param inputs set of points
85- * @param currentIndex
86+ * @param points
87+ * @param currentIndex index of the point the filter is currently looking at
88 * @return the input vector X
89 */
90- private static Matrix createX(List<Point> inputs, int currentIndex)
91+ private static Matrix createX(List<Point> points, int currentIndex)
92 {
93- throw new UnsupportedOperationException();
94+ Matrix x = new Matrix(1, 6);
95+
96+ List<Point> updatedPoints = computeVAndA(points);
97+
98+ x.set(0, 0, updatedPoints.get(currentIndex).x);
99+ x.set(0, 1, updatedPoints.get(currentIndex).y);
100+ x.set(0, 2, updatedPoints.get(currentIndex).vx);
101+ x.set(0, 3, updatedPoints.get(currentIndex).vy);
102+ x.set(0, 4, updatedPoints.get(currentIndex).ax);
103+ x.set(0, 5, updatedPoints.get(currentIndex).ay);
104+
105+ return x;
106 }
107
108 /**
109+ * Compute the instant velocity and acceleration of each point
110+ * <b>This method makes the following assumptions:</b>
111+ * 1. Acceleration of a Point object is constant and was properly set in the constructor.
112+ * 2. The velocity of the first point is either 0 or has already been correctly calculated.
113+ *
114+ * TODO: take variable acceleration into account.
115+ *
116+ * @param points
117+ * @return list of point with correct v and a
118+ */
119+ private static List<Point> computeVAndA(List<Point> points)
120+ {
121+ int size = points.size();
122+ double vx_0 = points.get(0).vx;
123+ double vy_0 = points.get(0).vy;
124+ double ax_0 = points.get(0).ax;
125+ double ay_0 = points.get(0).ay;
126+
127+ List<Point> result = new ArrayList<Point> (size);
128+ result.add(points.get(0));
129+
130+ for (int i = 1; i < size; ++i)
131+ {
132+ double dt = points.get(i).t - points.get(0).t;
133+ double vx = vx_0 + ax_0 * dt;
134+ double vy = vy_0 + ay_0 * dt;
135+
136+ result.add(new Point(points.get(i).x,
137+ points.get(i).y,
138+ points.get(i).t,
139+ vx,
140+ vy,
141+ points.get(i).ax,
142+ points.get(i).ay
143+ ));
144+ }
145+
146+ return result;
147+ }
148+
149+ /**
150 * TODO:
151 * Same as createX(...)'s
152 *

Subscribers

People subscribed via source and target branches

to all changes: