-
Notifications
You must be signed in to change notification settings - Fork 45
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 conversion and commands #177
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
927dbe2
spherical coords conversion
chapulina 00df67b
codecheck
chapulina c11ebb3
Print warnings
chapulina b64edb8
Support spawning and moving in spherical coordinates
chapulina 9ca5628
Merge branch 'main' into chapulina/8/spherical_coords
chapulina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,27 @@ namespace ignition | |
pose); | ||
} | ||
|
||
///////////////////////////////////////////// | ||
math::SphericalCoordinates Convert(const msgs::SphericalCoordinates &_sc) | ||
{ | ||
math::SphericalCoordinates out; | ||
if (_sc.surface_model() == msgs::SphericalCoordinates::EARTH_WGS84) | ||
{ | ||
out.SetSurface(math::SphericalCoordinates::EARTH_WGS84); | ||
} | ||
else | ||
{ | ||
std::cerr << "Unrecognized spherical surface type [" | ||
<< _sc.surface_model() | ||
<< "]. Using default." << std::endl; | ||
} | ||
out.SetLatitudeReference(IGN_DTOR(_sc.latitude_deg())); | ||
out.SetLongitudeReference(IGN_DTOR(_sc.longitude_deg())); | ||
out.SetElevationReference(_sc.elevation()); | ||
out.SetHeadingOffset(IGN_DTOR(_sc.heading_deg())); | ||
return out; | ||
} | ||
|
||
///////////////////////////////////////////// | ||
math::AxisAlignedBox Convert(const msgs::AxisAlignedBox &_b) | ||
{ | ||
|
@@ -278,6 +299,14 @@ namespace ignition | |
return result; | ||
} | ||
|
||
///////////////////////////////////////////// | ||
msgs::SphericalCoordinates Convert(const math::SphericalCoordinates &_sc) | ||
{ | ||
msgs::SphericalCoordinates result; | ||
msgs::Set(&result, _sc); | ||
return result; | ||
} | ||
|
||
///////////////////////////////////////////// | ||
msgs::PlaneGeom Convert(const ignition::math::Planed &_p) | ||
{ | ||
|
@@ -433,6 +462,26 @@ namespace ignition | |
msgs::Set(_i->mutable_pose(), _m.Pose()); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void Set(msgs::SphericalCoordinates *_sc, | ||
const math::SphericalCoordinates &_m) | ||
{ | ||
if (_m.Surface() == math::SphericalCoordinates::EARTH_WGS84) | ||
{ | ||
_sc->set_surface_model(msgs::SphericalCoordinates::EARTH_WGS84); | ||
} | ||
else | ||
{ | ||
std::cerr << "Unrecognized spherical surface type [" | ||
<< _m.Surface() | ||
<< "]. Not populating message field." << std::endl; | ||
} | ||
_sc->set_latitude_deg(_m.LatitudeReference().Degree()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my previous comment about unsuported surface model. |
||
_sc->set_longitude_deg(_m.LongitudeReference().Degree()); | ||
_sc->set_elevation(_m.ElevationReference()); | ||
_sc->set_heading_deg(_m.HeadingOffset().Degree()); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void Set(msgs::StringMsg *_p, const std::string &_v) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to continue doing the conversion if the
surface_model
isn't supported? I think we shouldn't do it as the values will be probably incorrect.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ign-math
class is populated with default values, so the caller wouldn't know if we're populating the message or leaving the default values. So instead of skipping the rest of the message, I'm printing a warning on c11ebb3.For the messages, the field is left empty, and I also printed a warning, but still populated the rest of the function.
I think that ultimately, it shouldn't be the conversion function's responsibility to decide what are valid combinations. It should convert as much as possible and the caller should be the one deciding what is acceptable. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Practically speaking I don't see any problems right now because we only have one surface type in Ignition Msgs, so it's impossible to receive an unsupported type. I agree that potentially receiving a default
math::SphericalCoordinates
is ambiguous but returning amath::SphericalCoordinates
with default surface type (WGS_84
) but potentially lat/lon, heading and elevation references coming from a different surface type could be hard to debug. The error message definitely helps.I'm approving but as an idea, we could create a new type in
ignition::math::SurfaceType
that isUnsupported
or similar. We could use this type in this conversion for example, when we detect an unsupported type set inignition::msgs::SphericalCoordinates
. This way, after callingconvert()
we can programmatically check if the conversion was right.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, makes sense. Ticketed gazebosim/gz-math#237.