mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
committed by
GitHub
parent
227084e92e
commit
ac4b0a3118
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user