blob: a784df05cfb2645b5d85a96343c9c8fc9f7f293b [file] [log] [blame]
Daniel Petti339f88a2015-02-07 22:51:20 -08001#ifndef FRC971_CONTROL_LOOPS_GAUSSIAN_NOISE_H_
2#define FRC971_CONTROL_LOOPS_GAUSSIAN_NOISE_H_
3
4#include <unistd.h>
5
6#include <memory>
7#include <random>
8
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -08009namespace frc971::control_loops {
Daniel Petti339f88a2015-02-07 22:51:20 -080010
11class GaussianNoise {
12 public:
13 // seed: The seed for the random number generator.
14 // stddev: The standard deviation of the distribution.
15 GaussianNoise(unsigned int seed, double stddev);
16
17 // Returns a version of the sample with gaussian noise added in.
18 double AddNoiseToSample(double sample);
19
20 // Sets the standard deviation of the gaussian noise.
Philipp Schrader790cb542023-07-05 21:06:52 -070021 inline void set_standard_deviation(double stddev) { stddev_ = stddev; }
Daniel Petti339f88a2015-02-07 22:51:20 -080022
23 private:
24 double stddev_;
25
26 std::default_random_engine generator_;
27 std::normal_distribution<double> distribution_;
28};
29
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080030} // namespace frc971::control_loops
Daniel Petti339f88a2015-02-07 22:51:20 -080031
32#endif // FRC971_CONTROL_LOOPS_GAUSSIAN_NOISE_H_