Dampening Gs

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Hello guys. I am using this to calculate the acceleration of a given vessel:

Code:
VECTOR3 F, W, A;
GetForceVector(F);
GetWeightVector(W);
A = (F-W)/oapiGetMass(GetHandle());

The problem is that there is a lot of oscillation, and the values suddenly spike up a lot in events such as touchdowns or dockings. It may be normal to have those values in a rigid touchdown, but they trigger the execution of the damage code. I have tried averaging:

Code:
class LPFILTER
{
public:
    LPFILTER()
    {
        fcThresh = 20;
    }
    LPFILTER(unsigned long fc)
    {
        fcThresh=fc;
    }
    int input(double d)
    {
        if (data.size()>fcThresh){
            data.clear();
        }
        data.push_back(d);
        return data.size();
    }
    double avg()
    {
        double sum = 0;
        for (int i = 0; i < data.size(); i++)
        {
            sum+=data[i];
        }
        return (sum/data.size());
    }
    std::vector<double> data;
    unsigned long       fcThresh;
};

But that doesn't help much. What's worse, if the sampling threshold is high enough, the system spits out insane values at the start of a simulation session and it takes it time depending on the threshold to settle down to more realistic values. Any suggestions?
 

Ursus

Rocket Tinker
Addon Developer
Joined
Oct 20, 2007
Messages
176
Reaction score
2
Points
18
Location
46N 123W
I would've suggested averaging if you hadn't said you'd tried that already.

Perhaps if you wait a couple time steps before you start taking samplings?
 

Imagineer

New member
Joined
Feb 11, 2008
Messages
47
Reaction score
0
Points
0
Location
N42 2.9 W 91 35.4
Computerex.

You are computing acceleration correctly. With "stiff" objects you will get impulsive forces whenever you "collide" with something. This is why aircraft have springs, shock absorbers, and inflated tires on their landing gear.

However in my experience it is very hard to simulate an aircraft suspension since it tends to have a high bandwidth (especially tire compression). Unless you can guarantee at least 250 frames per second it's not going to work.

So, you need to compromise. Here are a couple of things you can try:

1) As your craft approaches landing or docking start ramping down the relative acceleration ahead of time to reduce the discontinuity in velocity at contact to a manageable level.

2) Delay the damage until some small time interval after the spike in acceleration. If a landing or docking occurred during the interval then ignore the spike for damage purposes.

3) Use a low pass filter to moderate the spikes. The low pass filter you have is a good first try, but there is no substitute for some real filter theory in the design of your filter.

If you have access to MatLab or equivalent, you could look at their examples of using the tool for low pass filter design. You can also simulate your filter and see if it does what you need.

The moving average you have implemented probably does not behave the way you expect. First, such filters are designed using a fixed time step while Orbiter uses a variable time step. Also, a moving average does not have the frequency response that you want. It has secondary peaks at higher frequencies.

Take a look at the Wikipedia article on low-pass filters. Toward the end it has an example of a digital implementation of a low pass filter. There are other ways to do it as well. Note, that you don't actually store a vector of output values. The code shown processes "n" samples in an array. You only need to store the previous output.

Hope that helps.

Dean
 

Tschachim

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Feb 7, 2008
Messages
300
Reaction score
0
Points
16
Location
nassp.sf.net
Website
nassp.sf.net
Hi computerex,

if you do the acceleration calculaton in clbkPreStep, try clbkPostStep instead, that seems to be much more stable. Also, for unkown reasons, I experienced higher stability if I use the average of the weight vector of the current and the last time step.

Cheers
Tschachim
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Thanks for the suggestions guys. I combined all of the suggestions to make it now very acceptable. :)
 

spcefrk

AeroEng
Donator
Joined
Feb 11, 2008
Messages
175
Reaction score
0
Points
16
Location
California
Sorry

I have to say this, it's a common mistake, but it's a pet peeve:

Nothing in vibrations or oscillatory mechanics is dampened (that means physically damp as in soaked with water). Things like spring deflection, forces, etc..., damp or are damped to a steady state.
 
Top