NavSat::ToElement() method#1585
Conversation
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
| /// Note that parameter passing functionality is not captured with this | ||
| /// function. |
There was a problem hiding this comment.
I copied this text from similar method of other class (at least it consistent)
|
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 |
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. |
|
@azeey could you please elaborate |
| } | ||
|
|
||
| ///////////////////////////////////////////////// | ||
| sdf::ElementPtr NavSat::ToElement() const |
There was a problem hiding this comment.
We've been adding an implementation that takes an sdf:Error (see
Line 265 in dcd3c2d
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
9712064 to
0442b6e
Compare
| if (this->Type() == sdf::SensorType::AIR_PRESSURE) | ||
| { | ||
| sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure"); | ||
| airPressureElem->Copy(this->dataPtr->airPressure->ToElement()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| ///////////////////////////////////////////////// | ||
| sdf::ElementPtr NavSat::ToElement() const |
There was a problem hiding this comment.
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.
| sdf::ElementPtr NavSat::ToElement(sdf::Errors &_errors) const | ||
| { | ||
| sdf::ElementPtr elem(new sdf::Element); | ||
| sdf::initFile("navsat.sdf", elem); |
There was a problem hiding this comment.
| sdf::initFile("navsat.sdf", elem); | |
| sdf::initFile("navsat.sdf", ParserConfig::GlobalConfig(), elem, _errors); |
| { | ||
| auto el = elem->GetElement("position_sensing", _errors)-> | ||
| GetElement("horizontal", _errors)->GetElement("noise", _errors); | ||
| el->Copy(this->dataPtr->horizontalPositionNoise.ToElement(), _errors); |
There was a problem hiding this comment.
| el->Copy(this->dataPtr->horizontalPositionNoise.ToElement(), _errors); | |
| el->Copy(this->dataPtr->horizontalPositionNoise.ToElement(_errors), _errors); |
There was a problem hiding this comment.
Good catch, thank you
| { | ||
| auto el = elem->GetElement("position_sensing", _errors)-> | ||
| GetElement("vertical", _errors)->GetElement("noise", _errors); | ||
| el->Copy(this->dataPtr->verticalPositionNoise.ToElement(), _errors); |
There was a problem hiding this comment.
| el->Copy(this->dataPtr->verticalPositionNoise.ToElement(), _errors); | |
| el->Copy(this->dataPtr->verticalPositionNoise.ToElement(_errors), _errors); |
| { | ||
| auto el = elem->GetElement("velocity_sensing", _errors)-> | ||
| GetElement("horizontal", _errors)->GetElement("noise", _errors); | ||
| el->Copy(this->dataPtr->horizontalVelocityNoise.ToElement(), _errors); |
There was a problem hiding this comment.
| el->Copy(this->dataPtr->horizontalVelocityNoise.ToElement(), _errors); | |
| el->Copy(this->dataPtr->horizontalVelocityNoise.ToElement(_errors), _errors); |
| { | ||
| auto el = elem->GetElement("velocity_sensing", _errors)-> | ||
| GetElement("vertical", _errors)->GetElement("noise", _errors); | ||
| el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(), _errors); |
There was a problem hiding this comment.
| el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(), _errors); | |
| el->Copy(this->dataPtr->verticalVelocityNoise.ToElement(_errors), _errors); |
bbc87d2 to
34e0c17
Compare
| // camera, depth, thermal, segmentation | ||
| else if (this->CameraSensor()) | ||
| { | ||
| // TODO(anyone) use ToElement with sdf::Error when it available |
There was a problem hiding this comment.
If I already touched structure of this function, added _error where it was obvious and compiler not angry
34e0c17 to
9da3507
Compare
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
9da3507 to
3371f31
Compare
Signed-off-by: Maksim Derbasov <ntfs.hard@gmail.com>
|
@azeey is it OK now? |
| if (this->Type() == sdf::SensorType::AIR_PRESSURE) | ||
| { | ||
| sdf::ElementPtr airPressureElem = elem->GetElement("air_pressure"); | ||
| airPressureElem->Copy(this->dataPtr->airPressure->ToElement()); |
There was a problem hiding this comment.
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.
|
@Mergifyio backport main sdf12 sdf14 sdf15 |
✅ Backports have been createdDetails
Cherry-pick of 8ccc60c has failed: 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: 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: 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 |
`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)
`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
`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
`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
`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)
`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)
`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)
`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)
`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)
🦟 Bug fix
Fixes #
Summary
sdf::NavSatdidn't have aToElement()method which prevent to convert sensor-specific information back to sdf format.This PR include such changes:
sdf::NavSat::ToElement()methodSensor::ToElement()This PR was developed on top of sdf15 and retargeted to sdf16 due to sdf16 do not have dev packages.
Checklist
codecheckpassed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.