Skip to content

Commit

Permalink
adding error parameters to Altimiter function calls
Browse files Browse the repository at this point in the history
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
  • Loading branch information
Marco A. Gutierrez committed Oct 3, 2022
1 parent 87acca9 commit 624d7dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
8 changes: 8 additions & 0 deletions include/sdf/Altimeter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ namespace sdf
/// \return SDF element pointer with updated sensor values.
public: sdf::ElementPtr ToElement() const;

/// \brief Create and return an SDF element filled with data from this
/// altimeter sensor.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \param[out] _errors Vector of errors.
/// \return SDF element pointer with updated sensor values.
public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;

/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
46 changes: 35 additions & 11 deletions src/Altimeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>
#include "sdf/Altimeter.hh"
#include "sdf/parser.hh"
#include "Utils.hh"

using namespace sdf;

Expand Down Expand Up @@ -60,16 +61,24 @@ Errors Altimeter::Load(ElementPtr _sdf)
// Load the noise values.
if (_sdf->HasElement("vertical_position"))
{
sdf::ElementPtr elem = _sdf->GetElement("vertical_position");
sdf::ElementPtr elem = _sdf->GetElement("vertical_position", errors);
if (elem->HasElement("noise"))
this->dataPtr->verticalPositionNoise.Load(elem->GetElement("noise"));
{
sdf::Errors noiseErrors = this->dataPtr->verticalPositionNoise.Load(
elem->GetElement("noise", errors));
errors.insert(errors.end(), noiseErrors.begin(), noiseErrors.end());
}
}

if (_sdf->HasElement("vertical_velocity"))
{
sdf::ElementPtr elem = _sdf->GetElement("vertical_velocity");
sdf::ElementPtr elem = _sdf->GetElement("vertical_velocity", errors);
if (elem->HasElement("noise"))
this->dataPtr->verticalVelocityNoise.Load(elem->GetElement("noise"));
{
sdf::Errors noiseErrors = this->dataPtr->verticalVelocityNoise.Load(
elem->GetElement("noise", errors));
errors.insert(errors.end(), noiseErrors.begin(), noiseErrors.end());
}
}

return errors;
Expand Down Expand Up @@ -131,17 +140,32 @@ bool Altimeter::operator==(const Altimeter &_alt) const

/////////////////////////////////////////////////
sdf::ElementPtr Altimeter::ToElement() const
{
sdf::Errors errors;
auto result = this->ToElement(errors);
sdf::throwOrPrintErrors(errors);
return result;
}

/////////////////////////////////////////////////
sdf::ElementPtr Altimeter::ToElement(sdf::Errors &_errors) const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("altimeter.sdf", elem);

sdf::ElementPtr verticalPosElem = elem->GetElement("vertical_position");
sdf::ElementPtr verticalPosNoiseElem = verticalPosElem->GetElement("noise");
verticalPosNoiseElem->Copy(this->dataPtr->verticalPositionNoise.ToElement());

sdf::ElementPtr verticalVelElem = elem->GetElement("vertical_velocity");
sdf::ElementPtr verticalVelNoiseElem = verticalVelElem->GetElement("noise");
verticalVelNoiseElem->Copy(this->dataPtr->verticalVelocityNoise.ToElement());
sdf::ElementPtr verticalPosElem = elem->GetElement(
"vertical_position", _errors);
sdf::ElementPtr verticalPosNoiseElem = verticalPosElem->GetElement(
"noise", _errors);
verticalPosNoiseElem->Copy(
this->dataPtr->verticalPositionNoise.ToElement(_errors), _errors);

sdf::ElementPtr verticalVelElem = elem->GetElement(
"vertical_velocity", _errors);
sdf::ElementPtr verticalVelNoiseElem = verticalVelElem->GetElement(
"noise", _errors);
verticalVelNoiseElem->Copy(this->dataPtr->verticalVelocityNoise.ToElement(
_errors), _errors);

return elem;
}

0 comments on commit 624d7dc

Please sign in to comment.