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

🌐 Spherical coordinates: bug fix, docs and sanity checks #235

Merged
merged 11 commits into from
Sep 16, 2021

Conversation

chapulina
Copy link
Contributor

🦟 Bug fix

Fixes gazebosim/gazebo-classic#2022
Part of gazebosim/gz-sim#981

Summary

I believe that gazebosim/gazebo-classic#2022 is only an issue with the *FromLocal* functions. While the heading rotation from GLOBAL to LOCAL seems to be correct, the rotation from LOCAL to GLOBAL was not the inverse of that, which resulted in incoherent behaviour.

In order to preserve behaviour on version 6, which is being used by a lot of people who compensate for the bug, I introduced a new frame, LOCAL2, which can be used to get the correct calculation.

I also added several tests with sanity checks (i.e. higher latitude means further North...).

It's my first time playing with this class, so I'd appreciate it if people paid close attention to the math and test cases, in case I'm misunderstanding something.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸

@chapulina chapulina added the bug Something isn't working label Sep 3, 2021
@github-actions github-actions bot added Gazebo 1️1️ Dependency of Gazebo classic version 11 🏢 edifice Ignition Edifice 🏯 fortress Ignition Fortress 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome labels Sep 3, 2021
Signed-off-by: Louise Poubel <[email protected]>
@codecov
Copy link

codecov bot commented Sep 3, 2021

Codecov Report

Merging #235 (b447b94) into ign-math6 (0d884db) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head b447b94 differs from pull request most recent head c64b173. Consider uploading reports for the commit c64b173 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           ign-math6     #235   +/-   ##
==========================================
  Coverage      99.39%   99.40%           
==========================================
  Files             66       66           
  Lines           6162     6185   +23     
==========================================
+ Hits            6125     6148   +23     
  Misses            37       37           
Impacted Files Coverage Δ
src/SphericalCoordinates.cc 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d884db...c64b173. Read the comment docs.

Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Louise Poubel <[email protected]>
EXPECT_GT(xyzOrigin.Y(), xyz.Y());
}

// Decrease longitude == go West == go -X (and a bit -Y)
Copy link
Member

Choose a reason for hiding this comment

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

it seems weird that a change to longitude in either direction causes Y to decrease slightly. I would have thought it would be linearized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also surprised to see this, I assumed it was an artifact of the projection and didn't look further into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so I spent some time looking into this and I think I understand what's happening. This image should help:

image

Note that the ENU plane is tangent to the ellipsoid.

What this test is doing is changing lambda while keeping phi fixed. As you do that, the projection of the point onto the plane will only move on a straight line if you're exactly on the equator. If you're on the northern hemisphere, it goes further North (+Y) and if you're in the southern hemisphere, like on the test, it goes further South (-Y).

Here's a handy way of visualizing it, see how the projection of the blue line is not linear:

image

https://demonstrations.wolfram.com/TangentPlaneToASphere/

src/SphericalCoordinates_TEST.cc Outdated Show resolved Hide resolved
src/SphericalCoordinates_TEST.cc Outdated Show resolved Hide resolved
@chapulina chapulina added the beta Targeting beta release of upcoming collection label Sep 8, 2021
Copy link
Contributor

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

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

Maybe consider adding +/- altitude tests as well for completeness.

src/SphericalCoordinates_TEST.cc Outdated Show resolved Hide resolved
Signed-off-by: Louise Poubel <[email protected]>
@chapulina
Copy link
Contributor Author

Maybe consider adding +/- altitude tests as well for completeness.

Done in a8933ca

@scpeters scpeters merged commit 46d5324 into ign-math6 Sep 16, 2021
@scpeters scpeters deleted the chapulina/6/spherical branch September 16, 2021 18:34
arjo129 pushed a commit that referenced this pull request Sep 20, 2021
* Migration guide and LOCAL2

Signed-off-by: Louise Poubel <[email protected]>

Co-authored-by: Carlos Agüero <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Comment on lines +100 to +101
/// There's a known bug with this computation that can't be fixed on
/// version 6 to avoid behaviour changes. Directly call
Copy link
Contributor

Choose a reason for hiding this comment

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

@scpeters The comments indicate that the behavior was only intended to be kept for gz-math6. However, it slipped through to gz-math7. Is there some will to straighten this up in 8, or will we live with this forever?

Copy link
Member

Choose a reason for hiding this comment

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

sure, we can fix it in gz-math8

can you open an issue or pull request to main?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good, I'll try the PR.

I've noticed another discrepancy in the interface: SphericalFromLocalPosition returns spherical coordinates in degrees, while PositionTransform uses radians. Shouldn't this be also united to using degrees everywhere? Or was there a reason for keeping it this way?

Copy link
Member

Choose a reason for hiding this comment

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

I think consistency would be preferred; it was probably oversight in the first place that caused them to diverge. A std::vector<math::Angle> type would handle the units more clearly but it a little more overhead than Vector3d

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I've sent the PRs: #596, #597.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection bug Something isn't working 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome 🏢 edifice Ignition Edifice 🏯 fortress Ignition Fortress Gazebo 1️1️ Dependency of Gazebo classic version 11
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default SphericalCoordinates frame should be East-North-Up (ENU)
5 participants