View Full Version : Lateral g force measurement in vehicle
08-09-2005, 07:10 AM
To anyone who is willing to help:
I'm a mechanical engineer experimenting with BASIC stamps for the first time so please bear with me.· I'm trying to measure the lateral g force in a vehicle while the vehicle is in a turn.· I've managed to get the accelerometer and the display working very well.· I'm only intrested in the highest g force experienced by the vehicle, therefore, my program is written to display only the highest g force seen during a given test run.· A problem arises when the vehicle hits a bump in the turn.· For a split second the accelerometer and the vehicle experience a g force higher than the car would normally see if the bump wasn't there.· Since the accelerometer is so fast it records the high acceleration.· I don't want that reading.· I want the reading that the car pulls in the turn.· Is there a way to filter out shock loads seen by the accelerometer?· Perhaps there is a way to filter·that type of loading·out by the time the accelerometer·experiences· a given g force.· In other words, if the accelerometer records an acceleration of .6 g's for only 2 milliseconds then I could tell the display not to display that value.· I could use the time variable in that case to filter out the shock loads.· I'm not sure how to write this into the program.· Any help would be greatly appreciated.· Thanks.
08-09-2005, 08:27 AM
Can your program incorporate some max delta between measurements? Assuming a car enters a corner somewhat smoothely there should be a smooth transition from one reading to the next; if that "smooth" threshold (you'll probably have to determine empircally) is exceeded the new value (spike) could be tossed.
Applications Engineer, Parallax
08-09-2005, 09:01 AM
I'd also incorporate a tight series of WRITE statements into your program to store all of this in the EEPROM. Retrieve it using READ and DEBUG, then copy it from the DEBUG terminal into Excel so you can do some analysis before you decide what kinds of values you'd like to exclude. This might really help. Or, you can throw a laptop into the car and hook up a Stamp to the serial port and use the Excel StampDAQ to get it dropped right into the spreadsheet. Sometimes the pictures and charts you can draw explain the situation in a superior fashion, making the return to coding easier since you'll be equipped with MIN, MAX and other parameters.
10-05-2005, 10:48 PM
Your problem made me think "low-pass filter," but since I don't know how to implement one beyond grabbing the appropriate block in Simulink, I asked a buddy of mine.· Here's what he wrote:
You can simulate a LPF pretty easily using the equation
filtered_output = a * last_filtered_output + b * ( current_input + last_input )
a = (r - 1)/(r + 1)
b = r/(r + 1)
r = fs/fc
fs = sampling frequency (Hz)
fc = cutoff frequency
note that fs >> 2fc
You can see that the output is a weighted average of the last output plus the last inputs. The constants a and b determine how much you will use of the last output and how much of the current input will be used.
You always need an analog filter, however, to pre-filter the sensor before going into the digital controller to avoid aliasing unless you can guarantee the frequency content of the input signal will not exceed fs/2, impossible if there is any noise!
This is often called an anti-aliasing filter. Other-wise high frequency components that are a multiple of the sample frequency will appear in the output! The analog filter should have a cutoff frequency = fs/2 to avoid this. You can then filter more in the digital domain but you will be limited to fs/2.
10-05-2005, 11:44 PM
A "median" filter is often an effective way to filter out impulse noise and is a good first stage filter. It is effective because extreme input values do not effect the output at all, in contrast to parametric filters like the average or lowpass, for which every input value affects the output.
To implement a median filter, you need to set aside an array of RAM locations (size to be determined by available ram, sampling rate, duration of expected "bumps"). Initialize the array by filling it with the first sample value. Then treat it as a circular buffer where each new reading replaces the oldest reading. Then an algorithm uses a hash table or some technique to sort the array in numerical order and locate the middle value, so that half are less and half are greater. The output of the filter is that middle value. There is one middle value output for each new value input.
One note about implementation of a LPF (lowpass (exponential) filter) on a processor with integer or fixed point math. Because of the division inherent in computing the terms a = (r-1)/(r+1) and b = r/(r+1), there are strange numerical effects that occur. (I discovered that the hard way!) To minimize those effects, the numbers on input should be multiplied by a factor of at least 10 or 16 before they go into the computation. That in effect gives the computation an extra significant figure of precision to work with.
10-06-2005, 08:02 PM
I've done this sort of thing when measuring RPM from a sensor. Averaging a series of ten readings smooths things out a bit, or as suggested above you discard any reading which are more than some value different from the previous.
If the highs are caused by a bump, could not use a vertical G sensor, and use this to know when to discard readings ?
Perhaps post collection analysis is best here where 'bumps' will be more obvious once you have all the data, rather than trying to decide what is a bump before you can see the next event.