55 #include "FGAccelerations.h" 56 #include "FGFDMExec.h" 57 #include "input_output/FGPropertyManager.h" 63 IDENT(IdSrc,
"$Id: FGAccelerations.cpp,v 1.29 2016/05/22 10:28:23 bcoconni Exp $");
64 IDENT(IdHdr,ID_ACCELERATIONS);
74 Name =
"FGAccelerations";
78 vPQRidot.InitMatrix();
79 vUVWidot.InitMatrix();
81 vGravAccel.InitMatrix();
82 vBodyAccel.InitMatrix();
99 if (!FGModel::InitModel())
return false;
101 vPQRidot.InitMatrix();
102 vUVWidot.InitMatrix();
103 vUVWdot.InitMatrix();
104 vGravAccel.InitMatrix();
105 vBodyAccel.InitMatrix();
118 if (Holding)
return false;
124 ResolveFrictionForces(in.
DeltaT * rate);
144 void FGAccelerations::CalculatePQRdot(
void)
153 in.
Moment += (3.0 * in.
GAccel * invRadius) * (R * (in.
J * R));
163 vPQRdot.InitMatrix();
189 void FGAccelerations::CalculateUVWdot(
void)
191 if (FDMExec->
GetHoldDown() && !FDMExec->GetTrimStatus())
192 vBodyAccel.InitMatrix();
218 vUVWdot.InitMatrix();
221 vUVWdot += in.
Ti2b * vGravAccel;
222 vUVWidot = in.
Tb2i * vBodyAccel + vGravAccel;
232 vUVWdot.InitMatrix();
234 vPQRdot.InitMatrix();
251 void FGAccelerations::ResolveFrictionForces(
double dt)
253 const double invMass = 1.0 / in.
Mass;
257 size_t n = multipliers.size();
259 vFrictionForces.InitMatrix();
260 vFrictionMoments.InitMatrix();
265 vector<double> a(n*n);
266 vector<double> rhs(n);
269 for (
unsigned int i=0; i < n; i++) {
273 for (
unsigned int j=0; j < i; j++)
275 for (
unsigned int j=i; j < n; j++)
276 a[i*n+j] = DotProduct(v1, multipliers[j]->ForceJacobian)
277 + DotProduct(v2, multipliers[j]->MomentJacobian);
296 for (
unsigned int i=0; i < n; i++) {
297 double d = 1.0 / a[i*n+i];
299 rhs[i] = -(DotProduct(multipliers[i]->ForceJacobian, vdot)
300 +DotProduct(multipliers[i]->MomentJacobian, wdot))*d;
301 for (
unsigned int j=0; j < n; j++)
306 for (
int iter=0; iter < 50; iter++) {
309 for (
unsigned int i=0; i < n; i++) {
310 double lambda0 = multipliers[i]->value;
311 double dlambda = rhs[i];
313 for (
unsigned int j=0; j < n; j++)
314 dlambda -= a[i*n+j]*multipliers[j]->value;
316 multipliers[i]->value =
Constrain(multipliers[i]->Min, lambda0+dlambda, multipliers[i]->Max);
317 dlambda = multipliers[i]->value - lambda0;
319 norm += fabs(dlambda);
322 if (norm < 1E-5)
break;
327 for (
unsigned int i=0; i< n; i++) {
328 double lambda = multipliers[i]->value;
329 vFrictionForces += lambda * multipliers[i]->ForceJacobian;
330 vFrictionMoments += lambda * multipliers[i]->MomentJacobian;
338 vUVWidot += in.
Tb2i * accel;
340 vPQRidot += omegadot;
350 ResolveFrictionForces(0.);
355 void FGAccelerations::bind(
void)
360 PropertyManager->
Tie(
"accelerations/qdot-rad_sec2",
this, eQ, (PMF)&FGAccelerations::GetPQRdot);
361 PropertyManager->
Tie(
"accelerations/rdot-rad_sec2",
this, eR, (PMF)&FGAccelerations::GetPQRdot);
364 PropertyManager->
Tie(
"accelerations/vdot-ft_sec2",
this, eV, (PMF)&FGAccelerations::GetUVWdot);
365 PropertyManager->
Tie(
"accelerations/wdot-ft_sec2",
this, eW, (PMF)&FGAccelerations::GetUVWdot);
367 PropertyManager->
Tie(
"accelerations/gravity-ft_sec2",
this, &FGAccelerations::GetGravAccelMagnitude);
368 PropertyManager->
Tie(
"simulation/gravity-model", &gravType);
369 PropertyManager->
Tie(
"simulation/gravitational-torque", &gravTorque);
370 PropertyManager->
Tie(
"forces/fbx-weight-lbs",
this, eX, (PMF)&FGAccelerations::GetWeight);
371 PropertyManager->
Tie(
"forces/fby-weight-lbs",
this, eY, (PMF)&FGAccelerations::GetWeight);
372 PropertyManager->
Tie(
"forces/fbz-weight-lbs",
this, eZ, (PMF)&FGAccelerations::GetWeight);
374 PropertyManager->
Tie(
"forces/fbx-total-lbs",
this, eX, (PMF)&FGAccelerations::GetForces);
375 PropertyManager->
Tie(
"forces/fby-total-lbs",
this, eY, (PMF)&FGAccelerations::GetForces);
376 PropertyManager->
Tie(
"forces/fbz-total-lbs",
this, eZ, (PMF)&FGAccelerations::GetForces);
377 PropertyManager->
Tie(
"moments/l-total-lbsft",
this, eL, (PMF)&FGAccelerations::GetMoments);
378 PropertyManager->
Tie(
"moments/m-total-lbsft",
this, eM, (PMF)&FGAccelerations::GetMoments);
379 PropertyManager->
Tie(
"moments/n-total-lbsft",
this, eN, (PMF)&FGAccelerations::GetMoments);
381 PropertyManager->
Tie(
"moments/l-gear-lbsft",
this, eL, (PMF)&FGAccelerations::GetGroundMoments);
382 PropertyManager->
Tie(
"moments/m-gear-lbsft",
this, eM, (PMF)&FGAccelerations::GetGroundMoments);
383 PropertyManager->
Tie(
"moments/n-gear-lbsft",
this, eN, (PMF)&FGAccelerations::GetGroundMoments);
384 PropertyManager->
Tie(
"forces/fbx-gear-lbs",
this, eX, (PMF)&FGAccelerations::GetGroundForces);
385 PropertyManager->
Tie(
"forces/fby-gear-lbs",
this, eY, (PMF)&FGAccelerations::GetGroundForces);
386 PropertyManager->
Tie(
"forces/fbz-gear-lbs",
this, eZ, (PMF)&FGAccelerations::GetGroundForces);
408 void FGAccelerations::Debug(
int from)
410 if (debug_lvl <= 0)
return;
417 if (debug_lvl & 2 ) {
418 if (from == 0) cout <<
"Instantiated: FGAccelerations" << endl;
419 if (from == 1) cout <<
"Destroyed: FGAccelerations" << endl;
421 if (debug_lvl & 4 ) {
423 if (debug_lvl & 8 && from == 2) {
425 if (debug_lvl & 16) {
427 if (debug_lvl & 64) {
429 cout << IdSrc << endl;
430 cout << IdHdr << endl;
bool Run(bool Holding)
Runs the state propagation model; called by the Executive Can pass in a value indicating if the execu...
static double Constrain(double min, double value, double max)
Constrain a value between a minimum and a maximum value.
Evaluate gravity using WGS84 formulas that take the Earth oblateness into account.
const FGColumnVector3 & GetUVWdot(void) const
Retrieves the body axis acceleration.
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
void InitializeDerivatives(void)
Initializes the FGAccelerations class prior to a new execution.
Base class for all scheduled JSBSim models.
This class implements a 3 element column vector.
bool InitModel(void)
Initializes the FGAccelerations class after instantiation and prior to first execution.
Evaluate gravity using Newton's classical formula assuming the Earth is spherical.
Handles the calculation of accelerations.
Handles matrix math operations.
double Magnitude(void) const
Length of the vector.
const FGColumnVector3 & GetPQRdot(void) const
Retrieves the body axis angular acceleration vector.
~FGAccelerations()
Destructor.
void SetHoldDown(bool hd)
Sets the property forces/hold-down.
Encapsulates the JSBSim simulation executive.
bool GetHoldDown(void) const
Gets the value of the property forces/hold-down.