Skip to content
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

Lift Drag Bug Fix #2189

Merged
merged 10 commits into from
Oct 9, 2023
Merged

Lift Drag Bug Fix #2189

merged 10 commits into from
Oct 9, 2023

Conversation

frede791
Copy link
Contributor

@frede791 frede791 commented Oct 3, 2023

🦟 Bug fix

Fixes #2188

Summary

This PR fixes a bug in the liftdrag plugin that prevented the moment coefficient (cm) from being correctly calculated. The reason for this bug is an mathematical error that calculated cos^2 rather than cos for the cosSweepAngle. Using this updated value, I added in missing calculations from the liftdrag plugin in gazebo-classic, so that the two are now identical in functionality. I also took the opportunity to update the header file to the current formatting and fixed a spelling mistake I found. I also added in the cm_delta parameter that was not present in the current version of the liftdrag plugin but is used by some drones (such as the tailsitter) and may thus find use in the future.

In addition, wind has also been added as a parameter to be considered in calculations, bringing in line with what is present in the gazebo-classic lift drag plugin.

Checklist

  • Signed all commits for DCO
  • Updated documentation (as needed)

Signed-off-by: frederik <[email protected]>
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Oct 3, 2023
src/systems/lift_drag/LiftDrag.cc Outdated Show resolved Hide resolved
src/systems/lift_drag/LiftDrag.hh Outdated Show resolved Hide resolved
@frede791 frede791 requested a review from ahcorde October 3, 2023 13:42
@frede791
Copy link
Contributor Author

frede791 commented Oct 3, 2023

Added in the wind velocity as a factor from the original liftdrag plugin.

Copy link
Contributor

@arjo129 arjo129 left a comment

Choose a reason for hiding this comment

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

Run make codecheck .

See here: https://gazebosim.org/docs/harmonic/contributing

Remove trailing spaces as pointed out by the linter here: https://github.com/gazebosim/gz-sim/actions/runs/6396048528/job/17419401043?pr=2189

src/systems/lift_drag/LiftDrag.hh Outdated Show resolved Hide resolved
@frede791
Copy link
Contributor Author

frede791 commented Oct 5, 2023

Removed long lines and fixed trailing white spaces.

@frede791 frede791 requested a review from arjo129 October 5, 2023 11:22
Copy link
Contributor

@arjo129 arjo129 left a comment

Choose a reason for hiding this comment

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

Currently this plugin causes a segfault in the tests - I think its because you access components without checking if they exist.
To test your plugin doesnt break current integration tests run the following steps:

  • colcon build
  • . install/setup.bash
  • run build/gz-sim7/bin/INTEGRATION_lift_drag_system

src/systems/lift_drag/LiftDrag.cc Outdated Show resolved Hide resolved
src/systems/lift_drag/LiftDrag.cc Outdated Show resolved Hide resolved
src/systems/lift_drag/LiftDrag.cc Show resolved Hide resolved
src/systems/lift_drag/LiftDrag.cc Outdated Show resolved Hide resolved
src/systems/lift_drag/LiftDrag.cc Outdated Show resolved Hide resolved
@frede791
Copy link
Contributor Author

frede791 commented Oct 6, 2023

Improved based on comments. Integration tests and codecheck both pass. Commented feedback needs a reply if possible.

@frede791 frede791 requested a review from arjo129 October 6, 2023 12:14
Copy link
Contributor

@arjo129 arjo129 left a comment

Choose a reason for hiding this comment

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

Thanks for iterating on this so quickly. LGTM!

@ahcorde ahcorde merged commit 2881041 into gazebosim:gz-sim7 Oct 9, 2023
3 of 8 checks passed
@frede791 frede791 deleted the lift_drag_improvement branch November 9, 2023 12:00
srmainwaring added a commit to srmainwaring/gz-sim that referenced this pull request Dec 21, 2023
@srmainwaring
Copy link
Contributor

@ahcorde, I did not spot this change before it was merged into Harmonic, but have now tested with some of the models set up for ArduPilot and have some questions:

Sweep angle calculation

I think the calculation for the sweep angle adjustment should not include the square root. In the original Gazebo classic version of the plugin the variable was named cosSweepAngle2 (i.e. squared).

It was change to cosSweepAngle in:

I cannot find the PR corresponding to the change, so it's not clear why it was renamed.

The argument for using the square of the angle is that the sweep angle correction arises from using the velocity normal to the leading edge of the wing in the lift calculation, rather than the free stream velocity. As the velocity appears quadratically in the dynamic pressure the correction requires cos(sweep_angle)^2 not cos(sweep_angle). The adjustment is then applied as a correction to the lift coefficient rather than the velocity used in the dynamic pressure calculation which is possibly where the confusion arises, as it appears that it's taking a component of the resultant force, not the input velocity.

Unfortunately there is no reference provided to the source of the calculations used in the original derivation of the plugin, so it's hard to confirm the formula forming the basis for the calculations.

Moment calculation

This calculation is not enabled in the Gazebo classic version:

There is not much explanation aside from it not being checked. I think this term is supposed to account for the movement of the centre of pressure with velocity, and allows the lift and drag coefficients to be calculated and applied at the quarter chord point rather than the unknown centre of pressure (so the cp parameter might be better named quarter chord?).

In any case there are a few models that will not work with this calculation enabled. The Zephyr is one of them: https://app.gazebosim.org/OpenRobotics/fuel/models/Zephyr%20Delta%20Wing. The solution to get this model working again is to zero <cma>0.0</cma> so the adjustment is zero. It should not affect any PX4 mdoels as AFAICT they all set the parameter to zero. The models used with ArduPilot are being updated to also zero this adjustment (which is backwards compatible with Garden).

An announcement that this change may break some models would be helpful.

@arjo129
Copy link
Contributor

arjo129 commented Dec 21, 2023 via email

@srmainwaring
Copy link
Contributor

On another note perhaps we should not allow any changes into existing plugins on the release branches. i.e. A change like this should target main so that errors get caught during the tutorial party

Maybe, although in this case the changes looked reasonable because of the variable naming. Btw I'm still not 100% certain of the intended sweep angle calculation. If someone has a good reference that would settle it that would be great. From what I understand the original motivation for swept wings arose to reduce the effective stream velocity over the wings in transonic / supersonic flight (so argument for taking components of the velocity). Either way a comment above the calculation about the intention would make things clearer, and we could revert the variable name back to it's original cosSweepAngle2 if we decide that's the correct value. It does affect the lift and drag forces as well as the moment, so there should be a test to catch that.

<cma> does default to zero, the regression occurs for models where it is set to a non-zero value (overriding the default). In Garden the parameter was ignored, in Harmonic it isn't. I don't think it affects many models, as it appears in most cases to be set to zero anyway.

@arjo129
Copy link
Contributor

arjo129 commented Dec 26, 2023

No <cma> currently does not default to zero. And our documentation does not seem to have been updated for it.

I dont know about cos vs cos2 @frede791 is there a reason why you'd use cos over cos2 otherwise I'll revert that change.

arjo129 added a commit that referenced this pull request Dec 26, 2023
The changes in #2189 have caused a regression for our upstream users.
This fix disables moment calculations by defaulting Cma to zero. It
should help mitigate some of the regression. There is also an [ongoing
discussion](#2189 (comment)) as to whether the cos term should be cos^2 or cos.

Signed-off-by: Arjo Chakravarty <[email protected]>
@srmainwaring
Copy link
Contributor

No <cma> currently does not default to zero.

You're right - I misread that. Thanks for the the PR defaulting <cma> to zero, that'll provide consistency between major versions.

@srmainwaring
Copy link
Contributor

I dont know about cos vs cos2 @frede791 is there a reason why you'd use cos over cos2 otherwise I'll revert that change.

Reference for simple sweep theory: https://web.archive.org/web/20060727083150/http://www.desktopaero.com/appliedaero/potential3d/sweeptheory.html

Should relabel variable to cosSweepAngle2 and revert change.

arjo129 added a commit that referenced this pull request Dec 27, 2023
In response to #2189 (comment)

As suggested by @srmainwaring I also renamed cosSweepAngle ->
cos2SweepAngle to prevent further confusion.

Signed-off-by: Arjo Chakravarty <[email protected]>
arjo129 added a commit that referenced this pull request Dec 27, 2023
* Default CMA in LiftDrag pluginto zero

The changes in #2189 have caused a regression for our upstream users.
This fix disables moment calculations by defaulting Cma to zero. It
should help mitigate some of the regression. There is also an [ongoing
discussion](#2189 (comment)) as to whether the cos term should be cos^2 or cos.

Signed-off-by: Arjo Chakravarty <[email protected]>

* remove cos change to address one problem at a time

Signed-off-by: Arjo Chakravarty <[email protected]>

---------

Signed-off-by: Arjo Chakravarty <[email protected]>
@frede791
Copy link
Contributor Author

frede791 commented Jan 3, 2024

@arjo129 Thanks for catching this.

mjcarroll pushed a commit that referenced this pull request Jan 8, 2024
The changes in #2189 have caused a regression for our upstream users.
This fix disables moment calculations by defaulting Cma to zero. It
should help mitigate some of the regression. There is also an [ongoing
discussion](#2189 (comment)) as to whether the cos term should be cos^2 or cos.


Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Co-authored-by: Rhys Mainwaring <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Missing coefficients in LiftDrag Plugin
4 participants