GaussMarkovProcess.cc
Go to the documentation of this file.
1 // Copyright (c) 2016 The UUV Simulator Authors.
2 // All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
17 
19 
20 namespace gazebo
21 {
24 {
25  this->mean = 0;
26  this->min = -1;
27  this->max = 1;
28  this->mu = 0;
29  this->noiseAmp = 0;
30  this->Reset();
31  std::srand(std::time(NULL));
32 }
33 
36 {
37  this->var = this->mean;
38 }
39 
41 bool GaussMarkovProcess::SetMean(double _mean)
42 {
43  if (this->min > _mean || this->max < _mean)
44  return false;
45 
46  this->mean = _mean;
47  this->Reset();
48  return true;
49 }
50 
52 bool GaussMarkovProcess::SetModel(double _mean, double _min, double _max,
53  double _mu, double _noise)
54 {
55  if (_min >= _max)
56  return false;
57  if (_min > _mean || _max < _mean)
58  return false;
59  if (_noise < 0)
60  return false;
61  if (_mu < 0 || _mu > 1)
62  return false;
63  this->mean = _mean;
64  this->min = _min;
65  this->max = _max;
66  this->mu = _mu;
67  this->noiseAmp = _noise;
68 
69  this->Reset();
70  return true;
71 }
72 
74 double GaussMarkovProcess::Update(double _time)
75 {
76  double step = _time - this->lastUpdate;
77  double random = static_cast<double>(static_cast<double>(rand()) / RAND_MAX)
78  - 0.5;
79  this->var = (1 - step * this->mu) * this->var + this->noiseAmp * random;
80  if (this->var >= this->max)
81  this->var = this->max;
82  if (this->var <= this->min)
83  this->var = this->min;
84  this->lastUpdate = _time;
85  return this->var;
86 }
87 
90 {
91  gzmsg << "\tMean = " << this->mean << std::endl
92  << "\tMin. Limit = " << this->min << std::endl
93  << "\tMax. Limit = " << this->max << std::endl
94  << "\tMu = " << this->mu << std::endl
95  << "\tNoise Amp. = " << this->noiseAmp << std::endl;
96 }
97 }
GaussMarkovProcess()
Class constructor.
Implementation of a Gauss-Markov process model.
double min
Minimum limit for the process variable.
double Update(double _time)
Update function for a new time stamp.
double noiseAmp
Gaussian white noise amplitude.
void Print()
Print current model paramters.
void Reset()
Resets the process parameters.
bool SetMean(double _mean)
Set mean process value.
bool SetModel(double _mean, double _min, double _max, double _mu=0, double _noise=0)
Sets all the necessary parameters for the computation.
double mean
Mean process value.
double max
Maximum limit for the process variable.
double var
Process variable.
double mu
Process constant, if zero, process becomes a random walk.
double lastUpdate
Timestamp for the last update.


uuv_world_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Mon Jul 1 2019 19:39:31