Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "frc/AnalogPotentiometer.h" |
| 9 | |
| 10 | #include "frc/RobotController.h" |
| 11 | #include "frc/smartdashboard/SendableBuilder.h" |
| 12 | |
| 13 | using namespace frc; |
| 14 | |
| 15 | AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange, |
| 16 | double offset) |
| 17 | : m_analog_input(std::make_shared<AnalogInput>(channel)), |
| 18 | m_fullRange(fullRange), |
| 19 | m_offset(offset) { |
| 20 | AddChild(m_analog_input); |
| 21 | } |
| 22 | |
| 23 | AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange, |
| 24 | double offset) |
| 25 | : m_analog_input(input, NullDeleter<AnalogInput>()), |
| 26 | m_fullRange(fullRange), |
| 27 | m_offset(offset) {} |
| 28 | |
| 29 | AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input, |
| 30 | double fullRange, double offset) |
| 31 | : m_analog_input(input), m_fullRange(fullRange), m_offset(offset) {} |
| 32 | |
| 33 | double AnalogPotentiometer::Get() const { |
| 34 | return (m_analog_input->GetVoltage() / RobotController::GetVoltage5V()) * |
| 35 | m_fullRange + |
| 36 | m_offset; |
| 37 | } |
| 38 | |
| 39 | double AnalogPotentiometer::PIDGet() { return Get(); } |
| 40 | |
| 41 | void AnalogPotentiometer::InitSendable(SendableBuilder& builder) { |
| 42 | m_analog_input->InitSendable(builder); |
| 43 | } |