sensor_sim: Expose the seed for the pot noise.
Somewhere in handing this off to others this got hard-coded to zero.
Change-Id: If32e78872b2892b930bfca93622005fdfee1aa07
diff --git a/frc971/control_loops/position_sensor_sim.cc b/frc971/control_loops/position_sensor_sim.cc
index 5141327..caa383e 100644
--- a/frc971/control_loops/position_sensor_sim.cc
+++ b/frc971/control_loops/position_sensor_sim.cc
@@ -29,15 +29,15 @@
* index pulse
*/
-PositionSensorSimulator::PositionSensorSimulator(double index_diff)
- : index_diff_(index_diff),
- pot_noise_(0, 0.0) {
+PositionSensorSimulator::PositionSensorSimulator(double index_diff,
+ unsigned int noise_seed)
+ : index_diff_(index_diff), pot_noise_(noise_seed, 0.0) {
Initialize(0.0, 0.0);
}
void PositionSensorSimulator::Initialize(double start_position,
double pot_noise_stddev,
- double known_index_pos/* = 0*/) {
+ double known_index_pos /* = 0*/) {
// We're going to make the index pulse we know "segment zero".
cur_index_segment_ = floor((start_position - known_index_pos) / index_diff_);
known_index_pos_ = known_index_pos;
@@ -51,8 +51,8 @@
void PositionSensorSimulator::MoveTo(double new_pos) {
// Compute which index segment we're in. In other words, compute between
// which two index pulses we are.
- const int new_index_segment = floor((new_pos - known_index_pos_)
- / index_diff_);
+ const int new_index_segment =
+ floor((new_pos - known_index_pos_) / index_diff_);
if (new_index_segment < cur_index_segment_) {
// We've crossed an index pulse in the negative direction. That means the
diff --git a/frc971/control_loops/position_sensor_sim.h b/frc971/control_loops/position_sensor_sim.h
index 19a9112..6c1884d 100644
--- a/frc971/control_loops/position_sensor_sim.h
+++ b/frc971/control_loops/position_sensor_sim.h
@@ -15,8 +15,10 @@
// index_diff: The interval between index pulses. This is measured in SI
// units. For example, if an index pulse hits every 5cm on the
// elevator, set this to 0.05.
+ // noise_seed: The seed to feed into the random number generator for the
+ // potentiometer values.
// TODO(danielp): Allow for starting with a non-zero encoder value.
- PositionSensorSimulator(double index_diff);
+ PositionSensorSimulator(double index_diff, unsigned int noise_seed = 0);
// Set new parameters for the sensors. This is useful for unit tests to change
// the simulated sensors' behavior on the fly.