Skip to content

Revert to use of cos^2 in LiftDrag plugin #2273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/systems/lift_drag/LiftDrag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class gz::sim::systems::LiftDragPrivate
/// \brief Coefficient of Moment / alpha slope.
/// Moment = C_M * q * S
/// where q (dynamic pressure) = 0.5 * rho * v^2
public: double cma = 0.01;
public: double cma = 0.0;

/// \brief angle of attach when airfoil stalls
public: double alphaStall = GZ_PI_2;
Expand Down Expand Up @@ -327,8 +327,9 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm)
double sinSweepAngle = math::clamp(
spanwiseI.Dot(velI), minRatio, maxRatio);

// get cos from trig identity
double cosSweepAngle = sqrt(1.0 - sinSweepAngle * sinSweepAngle);
// The sweep adjustment depends on the velocity component normal to the wing leading
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter seems unhappy about these lines.

// edge which appears quadratically in the dynamic pressure, so scale by cos^2 .
double cos2SweepAngle = 1.0 - sinSweepAngle * sinSweepAngle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frede791 will this break your models?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, shouldn't be an issue for the PX4 models.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is fine.

double sweep = std::asin(sinSweepAngle);

// truncate sweep to within +/-90 deg
Expand Down Expand Up @@ -390,20 +391,20 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm)
{
cl = (this->cla * this->alphaStall +
this->claStall * (alpha - this->alphaStall)) *
cosSweepAngle;
cos2SweepAngle;
// make sure cl is still great than 0
cl = std::max(0.0, cl);
}
else if (alpha < -this->alphaStall)
{
cl = (-this->cla * this->alphaStall +
this->claStall * (alpha + this->alphaStall))
* cosSweepAngle;
* cos2SweepAngle;
// make sure cl is still less than 0
cl = std::min(0.0, cl);
}
else
cl = this->cla * alpha * cosSweepAngle;
cl = this->cla * alpha * cos2SweepAngle;

// modify cl per control joint value
if (controlJointPosition && !controlJointPosition->Data().empty())
Expand All @@ -421,16 +422,16 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm)
{
cd = (this->cda * this->alphaStall +
this->cdaStall * (alpha - this->alphaStall))
* cosSweepAngle;
* cos2SweepAngle;
}
else if (alpha < -this->alphaStall)
{
cd = (-this->cda * this->alphaStall +
this->cdaStall * (alpha + this->alphaStall))
* cosSweepAngle;
* cos2SweepAngle;
}
else
cd = (this->cda * alpha) * cosSweepAngle;
cd = (this->cda * alpha) * cos2SweepAngle;

// make sure drag is positive
cd = std::fabs(cd);
Expand All @@ -444,20 +445,20 @@ void LiftDragPrivate::Update(EntityComponentManager &_ecm)
{
cm = (this->cma * this->alphaStall +
this->cmaStall * (alpha - this->alphaStall))
* cosSweepAngle;
* cos2SweepAngle;
// make sure cm is still great than 0
cm = std::max(0.0, cm);
}
else if (alpha < -this->alphaStall)
{
cm = (-this->cma * this->alphaStall +
this->cmaStall * (alpha + this->alphaStall))
* cosSweepAngle;
* cos2SweepAngle;
// make sure cm is still less than 0
cm = std::min(0.0, cm);
}
else
cm = this->cma * alpha * cosSweepAngle;
cm = this->cma * alpha * cos2SweepAngle;

// Take into account the effect of control surface deflection angle to cm
if (controlJointPosition && !controlJointPosition->Data().empty())
Expand Down