From 732378048ea8d404c3897fe5889171a65cabe995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Sture?= Date: Fri, 13 Oct 2023 11:50:18 +0200 Subject: [PATCH] Avoid calling DblNormal with invalid standard deviation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Øystein Sture --- src/GaussianNoiseModel.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/GaussianNoiseModel.cc b/src/GaussianNoiseModel.cc index b82684a4..19ef91cc 100644 --- a/src/GaussianNoiseModel.cc +++ b/src/GaussianNoiseModel.cc @@ -87,7 +87,10 @@ void GaussianNoiseModel::Load(const sdf::Noise &_sdf) double biasStdDev = 0; biasMean = _sdf.BiasMean(); biasStdDev = _sdf.BiasStdDev(); - this->dataPtr->bias = math::Rand::DblNormal(biasMean, biasStdDev); + if (biasStdDev > 0.0) + this->dataPtr->bias = math::Rand::DblNormal(biasMean, biasStdDev); + else + this->dataPtr->bias = biasMean; // With equal probability, we pick a negative bias (by convention, // rateBiasMean should be positive, though it would work fine if @@ -108,8 +111,9 @@ void GaussianNoiseModel::Load(const sdf::Noise &_sdf) double GaussianNoiseModel::ApplyImpl(double _in, double _dt) { // Generate independent (uncorrelated) Gaussian noise to each input value. - double whiteNoise = math::Rand::DblNormal( - this->dataPtr->mean, this->dataPtr->stdDev); + double whiteNoise = this->dataPtr->stdDev > 0.0 ? + math::Rand::DblNormal(this->dataPtr->mean, this->dataPtr->stdDev) : + this->dataPtr->mean; // Generate varying (correlated) bias to each input value. // This implementation is based on the one available in Rotors: