These videos are from the first runs, so you can see quite many false detections and what not. By the time I had tweaked the system to my best, I did nt want to record any more videos. But hey something is better than nothing, so here is nothing!
Aaaaah! Research! Oh how much I love thee, and how much I HATE thee!
Khair… I have been trying to understand how actually Kalman filters work for a while now and Believe me when I tell you they aint easy! I went through hell to get the knots in my brain straightened out! I read a book called Introduction to Random Signals and Applied Kalman Filtering in about two days, at least the first 6 chapters! I reference a gazillion papers and other material online, talked to a mathematician, run simulations and what not… the list goes on. Heck I was so frustrated and unsure of myself that I had to relearn my 4th semester signals and systems course (the state spaces part).
Who knew in the end good old fashioned tinkering would make it work. So! I have decided that I would nt let the other people looking for a quick KF fix roam around aimlessly like particles in Brownian motion in the dark…
Ok first thing I learnt was that you need the theory, I read this fairly complicated and annoying book mentioned above… After reading the chapter like 3 times, I was able to grasp (somewhat) what it was trying to say. But the prolem is (I think that the equations dont directly apply for some reason when implementing the damn thing…. Plus most of the time you would be wondering how to calculate and use most of the variables. So yes in short its not the way to go if you are thinking of applying it in the near future.
But the reading part is very necessary, cuz you definitely need to know the why part… for the how, go to this fairly good article on embedded.com. Ok this article also get confusing as it does nt tells you a LOT of things… like how will you be calculating the noise covariances and what is the difference between measurement noise and process noise.
To answer these very relevant questions I m writing this article.
First of I m going to show a very simple example…. nothing complicated… What I m going to do is collect data from a single accelerometer and filter its output rather than the position data calculated from it. This reduces most of our state space matrices to 1. The commonly used system eqs are
x_hat_dot = A_mat * x + B_mat * u + w
y = C_mat * x + z
Ok…. to explain what these are you ll need to read some basic text on state spaces, I would recommend Signals, Systems, and Transforms by C.L.Phillips, J.M.Parr and E.A.Riskin. I am not going to go through that over here… NO CHANCE IN HELL!
So moving on to Kalman filters and our simple filtering app…. What I did was simply record a lot of data from the accelerometer and calculate the mean and variance/standard deviation parameters for the data. There is a small problem where that needs to be address. most sensors give the zero force point by Vcc/2, and since the filter parameters require the mean to be near zero and the SD to be around it, a transformation is in order.The easiest say is to subtract the average and divide by the gravity value. So thats that…. Now we have our sensor data and its parameters. the measurement and process noise are supposed to be different for the system. But while playing around with the values I found that if you Q as SD ^ 2 and R as SD you get an awesomely filtered result. Now dont ask me why the works. But theoretically R should be the SD and Q should be calculated from the A matrix and some other info about the process.
So the simple program that I ran in MATLAB is:
phi_k = 1; H_k = 1; R_k = (7.29738/(3113.08-2131.33)); P_min_k (1) = 0; Q_k = R_k ^ 2; P_k(1) = 1; x_hat (1) = 0; n = size1/NumberOfColumns; for i = 1:n -1 % K_k(i) = P_min_k (i) * H_k * inv(H_k * P_min_k (i) * H_k + R_k); % % x_hat(i) = x_hat_min + K_k(i) * (da1(i,1) - H_k*x_hat_min); % x_hat(i+1) = phi_k * x_hat(i); % % P_k (i) = (1 - K_k(i) * H_k) * P_min_k(i); % P_min_k(i+1) = phi_k * P_k(i) * phi_k + Q_k; K_k(i) = phi_k * P_k (i) * H_k * inv(H_k * P_k (i) * H_k + R_k); x_hat(i+1) = phi_k * x_hat(i) + K_k(i) *(da1(i,1) - H_k*x_hat(i)); P_k(i+1) = phi_k * P_k(i) * phi_k + Q_k - phi_k * P_k(i) * H_k * inv(R_k + P_k(i)) * H_k * P_k(i) * phi_k; end figure; hold on; plot(K_k, '-r'); plot(P_k, '-b'); plot(P_min_k, '-g'); xlabel('Time/sample'); ylabel('Bits'); title(strFileName); figure; hold on; plot(da1(:,1), '-g'); % plot(x_hat_min, '-r'); plot(x_hat, '-b'); xlabel('Time/sample'); ylabel('Bits'); title(strFileName);
phi_k = 1;H_k = 1;R_k = (7.29738/(3113.08-2131.33));P_min_k (1) = 0;Q_k = R_k ^ 2;P_k(1) = 1; x_hat (1) = 0;n = size1/NumberOfColumns; for i = 1:n -1% K_k(i) = P_min_k (i) * H_k * inv(H_k * P_min_k (i) * H_k + R_k);% % x_hat(i) = x_hat_min + K_k(i) * (da1(i,1) - H_k*x_hat_min);% x_hat(i+1) = phi_k * x_hat(i);% % P_k (i) = (1 - K_k(i) * H_k) * P_min_k(i);% P_min_k(i+1) = phi_k * P_k(i) * phi_k + Q_k; K_k(i) = phi_k * P_k (i) * H_k * inv(H_k * P_k (i) * H_k + R_k); x_hat(i+1) = phi_k * x_hat(i) + K_k(i) *(da1(i,1) - H_k*x_hat(i)); P_k(i+1) = phi_k * P_k(i) * phi_k + Q_k - phi_k * P_k(i) * H_k * inv(R_k + P_k(i)) * H_k * P_k(i) * phi_k; end figure;hold on; plot(K_k, '-r');plot(P_k, '-b');plot(P_min_k, '-g');xlabel('Time/sample');ylabel('Bits');title(strFileName); figure;hold on; plot(da1(:,1), '-g');% plot(x_hat_min, '-r');plot(x_hat, '-b');xlabel('Time/sample');ylabel('Bits');title(strFileName);
Keep in mind that the Data was already loaded into the MATLAB workspace. The figure of interest is
Dont ask me how or why though… I m just happy it does!
After a lot of toil and time (or not), I finally got my data from the accelerometers, and it does nt look bad at all! (Maybe good even!). I can now proceed towards analysis and make a scheme out of these. But there is a catch that I see in the preliminary results, I may need a better ADC and a much much better processor than the itty bitty ATMega168 on an Arduino board that I m using currently.
I need to write a report and submit it within this week about my results. Results are pretty much as I expected, I learned that I definitely need to filter my signals, which means computational power, (Kalman Filter maybe?) and that I can give a good estimation of tilt with the current sensors. I have nt been able to see forces, and partly because of the ADC. Forces are very very short in duration and I need a faster sampling to get some good data. Maybe 10, 20 times better sampling rate would give me better results. This would mean new components and new components would in turn mean a learning curve. I m swamped with assignments so I ll be putting this off for a little later, or maybe just slow down my pace so I can compensate.
These days I have nothing much to do about my project, since I have ordered parts and waiting for them to arrive. I have always hated waiting, I m an impatient and impulsive person tending to have more than one obsessive compulsive disorders. But thats not what the post is about, so my current objective is to make a remote unit which can be used to determine the relative position of the user.
Now relative position may mean a lot of things and therefore in this context it means the current position with respect to the previous position. Now what I have decided is to do this use inertial sensors.
What are inertial sensors? They are sensors used to measure the change in inertia applied to the sensor, in lay man’s terms, if you apply a force and the object STARTS or stops to move, these sensors would give a corresponding voltage value. Now this is also not for the complete lay man (Read ouff) but I dont know any way simpler to explain this.
Ok, anyone who’s worked on this stuff would say big deal, This is old old technology and people have been using IMU (inertial Measurement Units) and INS (Inertial Navigation Systems) for a while now so whats new here. Well to tell the truth, nothing is really new here… Hell some people have also used this for smaller applications too like for determining orientation of an object. So there is nothing new to this… So why am I doing this and why the heck am I writing about it? Well I m thinking up a way to do this just by employing accelerometers! I bet this can be done, I m still working out the theoretical details. Now why would I use only accelerometers and not Gyros.
For that let me first explain what are Gyros and What are accelerometers. So the latter first, accelerometers are devices used to calculate translational acceleration, translational means moving from one point to another in a straight line. Now Gyros are more fun, they are used to measure rotational velocities, Now using the two together is usually the method used by everyone. But Gyros are expensive and difficult to get measurements from, plus you need to implement more household circuitry to maintain an output from them. While accelerometer are much more easier to do. So my motivation is simple. To make it easier for myself. But the more I come to think about it the more discouraged I get about this idea. Cuz the maths involved is way out there.
People, Any bright ideas? Please help!!!
I m pretty baffled by the size and scale of my project… And the quantity of expectations that my supervisor has of me and thus the proportional work required of me. He probably think I m some unsung under dog wiz kid outta Karachi who is just about to spread his glorious wings and stun the world. In the words of the Great Danny Crane, He wants me to pull a rabbit outta my hat (or ass, cuz I dont really have a hat).
I was lately studying Multi touch screens, I did a post somewhere here. Dont expect me to make it any easy for you and hyperlink that link here, GET IT YOURSELF!!!!. Now I m working on incorporating Gyroscopes and Accelerometers to give a more engrossing feel to the user carrying this remote unit which would be used in the project. Which is supposed to be somewhat familiar territory
Now previously, before the advent of the acclaimed iPhone, accelerometers (and Gyros) were some obscure sensors which only military used. Hell no body probably did nt even know their name and what they were used for.
So Currently I m making a design and a scheme which is used to to give a relative position (from the previous position) of a remote unit which you can currently think of as a 3-dimensional mouse. The idea I have right now is the combined effort (brain storming) of me with a german dude name Micheal Leigsnering (sorry dude if I mispelled your name). Since the idea is nt mature yet, I ll just keep it to myself and work on it, so that I dont give you guys any reason to call me nerd or geek or stupid.
So why am I writing this post??? Cuz I m on an overdose of sugar (read skittles) and my brain is on overdrive. I m at my lab sitting by my workstation with a bag of skittles. I have a habit of keeping a bag of skittles on me while I m working and write down some of my thoughts and ideas so that I can keep them in perspective and make references. So this post is kinda my reference point at the moment.