Skip to content

Commit

Permalink
adding errors parameter to 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 43687f4 commit 87acca9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
8 changes: 8 additions & 0 deletions include/sdf/Noise.hh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ namespace sdf
/// \return SDF element pointer with updated noise values.
public: sdf::ElementPtr ToElement() const;

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

/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
52 changes: 33 additions & 19 deletions src/Noise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "sdf/Noise.hh"
#include "sdf/parser.hh"
#include "sdf/Types.hh"
#include "Utils.hh"

using namespace sdf;

Expand Down Expand Up @@ -78,7 +79,8 @@ Errors Noise::Load(ElementPtr _sdf)
return errors;
}

std::pair<std::string, bool> type = _sdf->Get<std::string>("type", "none");
std::pair<std::string, bool> type =
_sdf->Get<std::string>(errors, "type", "none");
if (!type.second)
{
errors.push_back({ErrorCode::ELEMENT_MISSING,
Expand All @@ -102,26 +104,26 @@ Errors Noise::Load(ElementPtr _sdf)
this->dataPtr->type = NoiseType::NONE;
}

this->dataPtr->mean = _sdf->Get<double>("mean",
this->dataPtr->mean = _sdf->Get<double>(errors, "mean",
this->dataPtr->mean).first;

this->dataPtr->stdDev = _sdf->Get<double>("stddev",
this->dataPtr->stdDev = _sdf->Get<double>(errors, "stddev",
this->dataPtr->stdDev).first;

this->dataPtr->biasMean = _sdf->Get<double>("bias_mean",
this->dataPtr->biasMean = _sdf->Get<double>(errors, "bias_mean",
this->dataPtr->biasMean).first;

this->dataPtr->biasStdDev = _sdf->Get<double>("bias_stddev",
this->dataPtr->biasStdDev = _sdf->Get<double>(errors, "bias_stddev",
this->dataPtr->biasStdDev).first;

this->dataPtr->precision = _sdf->Get<double>("precision",
this->dataPtr->precision = _sdf->Get<double>(errors, "precision",
this->dataPtr->precision).first;

this->dataPtr->dynamicBiasStdDev = _sdf->Get<double>("dynamic_bias_stddev",
this->dataPtr->dynamicBiasStdDev).first;
this->dataPtr->dynamicBiasStdDev = _sdf->Get<double>(
errors, "dynamic_bias_stddev", this->dataPtr->dynamicBiasStdDev).first;

this->dataPtr->dynamicBiasCorrelationTime = _sdf->Get<double>(
"dynamic_bias_correlation_time",
errors, "dynamic_bias_correlation_time",
this->dataPtr->dynamicBiasCorrelationTime).first;

return errors;
Expand Down Expand Up @@ -252,6 +254,15 @@ bool Noise::operator==(const Noise &_noise) const

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

/////////////////////////////////////////////////
sdf::ElementPtr Noise::ToElement(sdf::Errors &_errors) const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("noise.sdf", elem);
Expand All @@ -271,18 +282,21 @@ sdf::ElementPtr Noise::ToElement() const
default:
noiseType = "none";
}
elem->GetAttribute("type")->Set<std::string>(noiseType);
elem->GetElement("mean")->Set<double>(this->Mean());
elem->GetElement("stddev")->Set<double>(this->StdDev());
elem->GetAttribute("type")->Set<std::string>(noiseType, _errors);
elem->GetElement("mean", _errors)->Set<double>(this->Mean(), _errors);
elem->GetElement("stddev", _errors)->Set<double>(this->StdDev(), _errors);

// camera and lidar <noise> does not have the sdf params below
elem->GetElement("bias_mean")->Set<double>(this->BiasMean());
elem->GetElement("bias_stddev")->Set<double>(this->BiasStdDev());
elem->GetElement("dynamic_bias_stddev")->Set<double>(
this->DynamicBiasStdDev());
elem->GetElement("dynamic_bias_correlation_time")->Set<double>(
this->DynamicBiasCorrelationTime());
elem->GetElement("precision")->Set<double>(this->Precision());
elem->GetElement("bias_mean", _errors)->Set<double>(
this->BiasMean(), _errors);
elem->GetElement("bias_stddev", _errors)->Set<double>(
this->BiasStdDev(), _errors);
elem->GetElement("dynamic_bias_stddev", _errors)->Set<double>(
this->DynamicBiasStdDev(), _errors);
elem->GetElement("dynamic_bias_correlation_time", _errors)->Set<double>(
this->DynamicBiasCorrelationTime(), _errors);
elem->GetElement("precision", _errors)->Set<double>(
this->Precision(), _errors);

return elem;
}

0 comments on commit 87acca9

Please sign in to comment.