Skip to content

NavSat::ToElement() method#1585

Merged
azeey merged 5 commits intogazebosim:sdf16from
ntfshard:NavSatToElement-sdf16
Mar 3, 2026
Merged

NavSat::ToElement() method#1585
azeey merged 5 commits intogazebosim:sdf16from
ntfshard:NavSatToElement-sdf16

Conversation

@ntfshard
Copy link
Copy Markdown
Contributor

@ntfshard ntfshard commented Sep 2, 2025

🦟 Bug fix

Fixes #

Summary

sdf::NavSat didn't have a ToElement() method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:

  • Introduce sdf::NavSat::ToElement() method
  • Added this method call to dispatcher in Sensor::ToElement()
  • Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
  • And message was w/o trailing new_line symbol which makes console output harder to read
  • Added test for new ToElement() method; valgrind is happy
  • Couple of typos fixed

This PR was developed on top of sdf15 and retargeted to sdf16 due to sdf16 do not have dev packages.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • 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
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
Comment thread include/sdf/NavSat.hh
Comment on lines +138 to +139
/// Note that parameter passing functionality is not captured with this
/// function.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I copied this text from similar method of other class (at least it consistent)

Comment thread src/NavSat.cc
@azeey
Copy link
Copy Markdown
Collaborator

azeey commented Sep 2, 2025

Have you seen #1538?

@ntfshard
Copy link
Copy Markdown
Contributor Author

ntfshard commented Sep 3, 2025

Have you seen #1538?

No

UPD: I tried to use python bindings to generate sdf files and got error msg, which bring me to missing implementation. Now I see this PR is duplicates implementation of already opened PR

@ntfshard
Copy link
Copy Markdown
Contributor Author

ntfshard commented Dec 8, 2025

Have you seen #1538?

What would you suggest to do in this case? Fortunately we rewrote sdf generation on a pure python and don't constrained by this PR, but I'd like to wrap up this topic in any way.

@ntfshard
Copy link
Copy Markdown
Contributor Author

@azeey could you please elaborate

Copy link
Copy Markdown
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Looks good. I'd just ask that you add the version that takes an sdf::Error. I'll close #1538 since it's no longer active and this PR has tests.

Comment thread src/NavSat.cc
}

/////////////////////////////////////////////////
sdf::ElementPtr NavSat::ToElement() const
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We've been adding an implementation that takes an sdf:Error (see

sdf::ElementPtr Noise::ToElement(sdf::Errors &_errors) const
). Can you add that please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Still I'm quite curious how we can get a error status (except invalid tag as a parameter). I mean, when parsing a user's input, error is not something unexpected, but here we are constructing tag from scratch basically.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is possible for there to be errors in the spec (e.g., navsat.sdf), especially if the user modified it in their own copy of libsdformat. It's also more consistent if all the ToElement functions have the same signature.

@ntfshard ntfshard force-pushed the NavSatToElement-sdf16 branch from 9712064 to 0442b6e Compare February 23, 2026 17:00
@ntfshard ntfshard requested a review from azeey February 23, 2026 17:27
Comment thread src/Sensor.cc
if (this->Type() == sdf::SensorType::AIR_PRESSURE)
{
sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure");
airPressureElem->Copy(this->dataPtr->airPressure->ToElement());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just realized, in this function mix of functions is used. _error passed only in 3 functions above and code below only writing in else branch of dispatcher.

Also GetAttribute seems should have version with error parameter to match GetElement. But maybe I'm not right in a big picture.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I may have missed some in my review. If there are any more functions that accept _error, we should definitely be using them. Please feel free to create a follow up PR.

Comment thread src/NavSat.cc
}

/////////////////////////////////////////////////
sdf::ElementPtr NavSat::ToElement() const
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is possible for there to be errors in the spec (e.g., navsat.sdf), especially if the user modified it in their own copy of libsdformat. It's also more consistent if all the ToElement functions have the same signature.

Comment thread src/NavSat.cc Outdated
sdf::ElementPtr NavSat::ToElement(sdf::Errors &_errors) const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("navsat.sdf", elem);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
sdf::initFile("navsat.sdf", elem);
sdf::initFile("navsat.sdf", ParserConfig::GlobalConfig(), elem, _errors);

Comment thread src/NavSat.cc Outdated
{
auto el = elem->GetElement("position_sensing", _errors)->
GetElement("horizontal", _errors)->GetElement("noise", _errors);
el->Copy(this->dataPtr->horizontalPositionNoise.ToElement(), _errors);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
el->Copy(this->dataPtr->horizontalPositionNoise.ToElement(), _errors);
el->Copy(this->dataPtr->horizontalPositionNoise.ToElement(_errors), _errors);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you

Comment thread src/NavSat.cc Outdated
{
auto el = elem->GetElement("position_sensing", _errors)->
GetElement("vertical", _errors)->GetElement("noise", _errors);
el->Copy(this->dataPtr->verticalPositionNoise.ToElement(), _errors);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
el->Copy(this->dataPtr->verticalPositionNoise.ToElement(), _errors);
el->Copy(this->dataPtr->verticalPositionNoise.ToElement(_errors), _errors);

Comment thread src/NavSat.cc Outdated
{
auto el = elem->GetElement("velocity_sensing", _errors)->
GetElement("horizontal", _errors)->GetElement("noise", _errors);
el->Copy(this->dataPtr->horizontalVelocityNoise.ToElement(), _errors);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
el->Copy(this->dataPtr->horizontalVelocityNoise.ToElement(), _errors);
el->Copy(this->dataPtr->horizontalVelocityNoise.ToElement(_errors), _errors);

Comment thread src/NavSat.cc Outdated
{
auto el = elem->GetElement("velocity_sensing", _errors)->
GetElement("vertical", _errors)->GetElement("noise", _errors);
el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(), _errors);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(), _errors);
el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(_errors), _errors);

@ntfshard ntfshard force-pushed the NavSatToElement-sdf16 branch from bbc87d2 to 34e0c17 Compare February 24, 2026 01:25
Comment thread src/Sensor.cc
// camera, depth, thermal, segmentation
else if (this->CameraSensor())
{
// TODO(anyone) use ToElement with sdf::Error when it available
Copy link
Copy Markdown
Contributor Author

@ntfshard ntfshard Feb 24, 2026

Choose a reason for hiding this comment

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

If I already touched structure of this function, added _error where it was obvious and compiler not angry

@ntfshard ntfshard force-pushed the NavSatToElement-sdf16 branch from 34e0c17 to 9da3507 Compare February 24, 2026 01:45
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
@ntfshard ntfshard force-pushed the NavSatToElement-sdf16 branch from 9da3507 to 3371f31 Compare February 24, 2026 01:53
@ntfshard ntfshard requested a review from azeey February 24, 2026 16:17
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
@ntfshard
Copy link
Copy Markdown
Contributor Author

ntfshard commented Mar 3, 2026

@azeey is it OK now?

Comment thread src/Sensor.cc
if (this->Type() == sdf::SensorType::AIR_PRESSURE)
{
sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure");
airPressureElem->Copy(this->dataPtr->airPressure->ToElement());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I may have missed some in my review. If there are any more functions that accept _error, we should definitely be using them. Please feel free to create a follow up PR.

@github-project-automation github-project-automation Bot moved this from Inbox to In review in Core development Mar 3, 2026
@azeey azeey merged commit 8ccc60c into gazebosim:sdf16 Mar 3, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in Core development Mar 3, 2026
@azeey
Copy link
Copy Markdown
Collaborator

azeey commented Mar 3, 2026

@Mergifyio backport main sdf12 sdf14 sdf15

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Mar 3, 2026

backport main sdf12 sdf14 sdf15

✅ Backports have been created

Details

Cherry-pick of 8ccc60c has failed:

On branch mergify/bp/sdf12/pr-1585
Your branch is up to date with 'origin/sdf12'.

You are currently cherry-picking commit 8ccc60cd.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   include/sdf/Error.hh
	modified:   include/sdf/NavSat.hh
	modified:   src/Geometry.cc
	modified:   src/NavSat.cc
	modified:   src/NavSat_TEST.cc
	modified:   src/ScopedGraph.hh

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Sensor.cc
	both modified:   src/Surface.cc

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of 8ccc60c has failed:

On branch mergify/bp/sdf14/pr-1585
Your branch is up to date with 'origin/sdf14'.

You are currently cherry-picking commit 8ccc60cd.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   include/sdf/Error.hh
	modified:   include/sdf/NavSat.hh
	modified:   src/Geometry.cc
	modified:   src/NavSat.cc
	modified:   src/NavSat_TEST.cc
	modified:   src/ScopedGraph.hh

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Sensor.cc
	both modified:   src/Surface.cc

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of 8ccc60c has failed:

On branch mergify/bp/sdf15/pr-1585
Your branch is up to date with 'origin/sdf15'.

You are currently cherry-picking commit 8ccc60cd.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   include/sdf/Error.hh
	modified:   include/sdf/NavSat.hh
	modified:   src/Geometry.cc
	modified:   src/NavSat.cc
	modified:   src/NavSat_TEST.cc
	modified:   src/ScopedGraph.hh
	modified:   src/Sensor.cc

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Surface.cc

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

mergify Bot pushed a commit that referenced this pull request Mar 3, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)
mergify Bot pushed a commit that referenced this pull request Mar 3, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)

# Conflicts:
#	src/Sensor.cc
#	src/Surface.cc
mergify Bot pushed a commit that referenced this pull request Mar 3, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)

# Conflicts:
#	src/Sensor.cc
#	src/Surface.cc
mergify Bot pushed a commit that referenced this pull request Mar 3, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)

# Conflicts:
#	src/Surface.cc
@ntfshard ntfshard deleted the NavSatToElement-sdf16 branch March 15, 2026 10:31
scpeters pushed a commit that referenced this pull request Apr 17, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)
scpeters pushed a commit that referenced this pull request Apr 17, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)
scpeters pushed a commit that referenced this pull request Apr 17, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)
scpeters pushed a commit that referenced this pull request Apr 17, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)
scpeters pushed a commit that referenced this pull request Apr 17, 2026
`sdf::NavSat` didn't have a `ToElement()` method which prevent to convert sensor-specific information back to sdf format.

This PR include such changes:
* Introduce `sdf::NavSat::ToElement()` method
* Added this method call to dispatcher in `Sensor::ToElement()`
* Also same dispatcher had misleading error msg: if user tried to convert sensor w/o sensor-specific information it will get error message about lack of this feature, but actually it's not correct. Dispatcher logic changed to avoid such misleading (split apart type check and pointer check)
* And message was w/o trailing new_line symbol which makes console output harder to read
* Added test for new ToElement() method; valgrind is happy
* Couple of typos fixed

---------

Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
(cherry picked from commit 8ccc60c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🪵 jetty Gazebo Jetty

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants