[wpilib] AnalogPotentiometer: Use average voltage (#2583)

Using GetAverageVoltage will reduce the noise in potentiometer reading. Potentiometers are unlikely to be used where the minimal lag averaging introduces would impact control loop stability.
This commit is contained in:
Prateek Machiraju
2020-07-10 00:29:23 -04:00
committed by GitHub
parent 227084e92e
commit ac4b0a3118
2 changed files with 6 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -34,7 +34,8 @@ AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
}
double AnalogPotentiometer::Get() const {
return (m_analog_input->GetVoltage() / RobotController::GetVoltage5V()) *
return (m_analog_input->GetAverageVoltage() /
RobotController::GetVoltage5V()) *
m_fullRange +
m_offset;
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -122,7 +122,8 @@ public class AnalogPotentiometer implements Potentiometer, Sendable, AutoCloseab
if (m_analogInput == null) {
return m_offset;
}
return (m_analogInput.getVoltage() / RobotController.getVoltage5V()) * m_fullRange + m_offset;
return (m_analogInput.getAverageVoltage() / RobotController.getVoltage5V())
* m_fullRange + m_offset;
}
@Override