Kalman Filter - Page 1
Forum section: electronics / beginners

author: troush18
author_rank: Newbie
timestamp: May 10, 2015, 10:04:46 pm
content: Last semester in college I created a GoPro mount that was mounted to a servo with a gyro on it to be mounted on RC cars that tilts the camera angle up or down based on if you are on a hill or not. I turned the project in and the professor suggested using Kalman Filtering to take instability out of the gyro and make it more stable. I did some research but I can not seem to find any helpful resources online for how to go about programming the filter. I was hoping someone would be able to give me some advice on how I can do this. I am using a Basic Stamp 2 for reading the gyro and controlling the servo. Am I able to use this same stamp for the filter or would I need a different chip and/or programming language? Any help would be greatly appreciated. I am not sure if this was the appropriate place to post this question.

author: troush18
author_rank: Newbie
timestamp: May 10, 2015, 10:25:22 pm
content: The gyro is the only sensor being used in the project. It is mounted flat on in a box on the RC car frame and based on the data sent to the BS2 the Servo turns based on that. Currently the servo is real jittery and shakes all over the place. How could I go about making the servo smoother and not so jumpy? I will upload the video I took of it working on youtube and copy a link into this post.

author: dom0
author_rank: Super Contributor
timestamp: May 10, 2015, 10:27:42 pm
content: Quote from: troush18 on May 10, 2015, 10:25:22 pmControl theory. Make that controller/amplifier stable and it will stop oscillating. Then you can start tweaking the response of the system...

author: troush18
author_rank: Newbie
timestamp: May 10, 2015, 10:58:22 pm
content: @Mechatrommer The following is the link to the GoPro video of the project in action:Sorry for the poor resolution I uploaded in the lowest settings so it would upload quicker.

author: ignator
author_rank: Regular Contributor
timestamp: May 11, 2015, 01:59:32 am
content: Kalman filters are used where you have an extremely good NOISE model for the signal you are processing. In your case, you have random noise from the wheels running on uneven terrain. You really can't model that, your knobby tires are part of the mix. So you really have chaos.Also, the camera is operating on all this vehicle vibration. You need a very fancy camera stabilization platform, something they use for helicopter shots. I doubt if you can find a cheap shock mount for the camera.To just solve the angle issue, a low pass filter should remove the noise from what I assume is an accelerometer (gyro) giving you platform angular attitude (pitch). You need to low pass the noise from this sensor, so that uneven ground has no affect, and only a change in pitch to change camera angle for the average vehicle pitch to what I assume is measured via a normal gravity accelerometer.I'm assuming an analog system. Are you doing this via a processor and digital signal from the accelerometer?Digital controls can quickly have 180 degree phase reversals, because you can't process fast enough. Also the sensors (analog or digital) have delay in their output.You may be bandwidth limited with either digital or analog system.

author: Rerouter
author_rank: Super Contributor
timestamp: May 11, 2015, 03:25:05 am
content: something also to keep track of is gyro drift, you could make it so that whenever the rc car is static (e.g. no driving) it does a quick little calibration check to trim in the gyro, but yes i agree a kalman filter is the wrong thing for this application, and having attempted implementing one on a rc helicopter, you really need a firm understanding of university level maths (well beyond me still)

author: IanB
author_rank: Super Contributor
timestamp: May 11, 2015, 03:46:58 am
content: Quote from: troush18 on May 10, 2015, 10:04:46 pmA Kalman filter usually requires a significant amount of computation. You might need more processing power than a Basic Stamp to implement one.The concept of a Kalman filter is very simple. If you have a dynamic system, for example something with inertia that can be modeled with differential equations, then if you can sense the inputs to that system (the forces due to acceleration that tend to make it move), then you can integrate the differential equations and determine the change in position/orientation. However, there will be error in the predicted position due to measurement uncertainty and unmeasured inputs. On the other hand, maybe you have other measurements that correlate to the actual position (for example magnetic field sensing or gravitational field sensing). A Kalman filter is a statistical approach that combines the predictions of the model with other sensed information to come up with a best estimate of the state of the system at any given instant. Kalman filters are commonly used in inertial navigation and guidance systems, which is why your professor might have suggested it.You should be able to find books and other references that introduce you to the theory. Beware, however, it will be a bit math heavy.

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: May 11, 2015, 06:46:52 am
content: If you do not have a model for your system, and if you have a single measurement, or not related measures (this is equivalent to not having a model), you can have a simple filter by just taking a running average of your data.This can be easily implemented in any MCU.Assuming N is the number of data on which you average,TX[1:N] is an array where you store your last N measures, and y is the output measure at time t, thenthe output measure y' at time t+his obtained from the data x' at time t+h as y'=NextMeasure[x'] with (in some programming language)function NextMeasure[x,N]{save y, TX;y =y +(x-TX)/N;// then you update the array of N last measuresfor k = 1 to N-1{TX=TX[k+1];};TX=x;return (y);};You need of course a small initialisation by varying N from 1 to N at the beginning.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 11, 2015, 06:47:04 am
content: Well your mount doesn't seem to be doing any favors... if I didn't know any better, I'd simply assume you had mounted the damn camera on a dampened spring, resulting in an only slightly smoother but much, much sloppier video!So I'm guessing it needs some work. Which I'm guessing is at least partly why you're here. So that answers itself.What's the cutoff frequency of your loop (gyro and servos)? To produce that effect, I'm guessing it's rather slow. So that's a big problem right there. You need it to be fast enough to stabilize all those little shocks and bumps, which will be in the 100s Hz range of bandwidth. On a small platform like that, there will be plenty of energy up in the kHz range, but it won't amount to much displacement (if it were a full size car, the chassis roll-off might be <10Hz instead!). Which means the loop cutoff needs to be several times higher still (~1kHz), in order to have any loop gain at the frequencies where it's needed.Agree on the filter thing: Kalman is used to combine sources, as far as I know. I don't know much more, because all references I've seen on the damned thing are uselessly abstract.A very simple way to combine an accelerometer with a gyro would be merely using a crossover filter, so you get the high frequency information from the quicker accelerometer and the low frequency information from the more accurate (over longer time scales) gyro. (Assuming a real gyro of course -- laser, acoustic and accelerometer-based "gyros" are either much too fast, or just faking it.)In this project, it should be sufficient to simply attenuate the loop gain towards DC, so the servos default to a fixed resting position (a setpoint which can be varied if adjustable camera tracking is desired!). If you needed some absolute reference (like the stupidly fancy camera stabilizers that go in balls and fly on helicopters and such), a gyro might be a desirable addition. The other Wikipedia effect. Namely: the article is useless to you if you're already familiar with the subject, because you don't learn anything new. The article is useless to you if you aren't familiar with the subject, because it's just jibberish otherwise. Wikipedians (and most academics, in general) are wonderful at explaining things in their own terms, and abominable at explaining them in useful terms. *Heavy rolling of the eyes*So, yeah. This should still be solvable with simple linear control theory stuff, at least within the limits of your components. But like I said, you need damn fast servos to do it; it might be worth using long throw linear actuators (aka, tear down some woofers or hard drives and use the voice coils!) to drive the camera instead.Tim

author: babysitter
author_rank: Frequent Contributor
timestamp: May 11, 2015, 07:18:59 am
content: You are doing it wrong! The gyro doesn't have to control a servo electronically, attach a gyro (e.g. a fan with some heavy weight on the blades) mechanically to the Camera. used that in the past to stabilize a handheld camera a bit.

author: FreddyVictor
author_rank: Regular Contributor
timestamp: May 11, 2015, 07:35:59 am
content: some nice infohereon Kalma Filter, by a member on this forum I believebut as already mentioned by others, this isn't really what you wantone problem with servos is they have a limited max speed so cannot compensate for sudden movements as evidenced by your video.the rc world has moved over to brushless gimbals:controller board&motorwhich are far more effective

author: janoc
author_rank: Super Contributor
timestamp: May 11, 2015, 12:31:02 pm
content: Quote from: Mechatrommer on May 10, 2015, 10:15:21 pmKalman filter can be used to reduce the noise in the system. If the system is linear, it is even an optimal filter than can be designed. This is, in fact, its original purpose, as published in the early 1960s by Kalman and others.That it could be used to do sensor fusion (i.e. to mix data from several sensors based on their quality/noise model) is only one of many possible uses.So yeah, the prof was not an idiot and it is possible to use Kalman filters to do that assignment, just probably not using that hardware (Basic Stamp? Eeew). It would be just a little bit of an overkill in this case because it is basically only an adaptive low pass filter in this application to smooth out the gyro data.Also, as others said already, the servo will not work for this - it is way too slow. The gyros are used because they have a very fast response even to small movements, so, in this application, they could make them be compensated rapidly. However, that needs a lot beefier/faster motor. Most likely a brushless motor or a at least a DC motor and your own servo loop, using PID or some other control algorithm.