Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2016-2019 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 | #include "frc/smartdashboard/SendableRegistry.h" |
| 13 | |
| 14 | using namespace frc; |
| 15 | |
| 16 | AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange, |
| 17 | double offset) |
| 18 | : AnalogPotentiometer(std::make_shared<AnalogInput>(channel), fullRange, |
| 19 | offset) { |
| 20 | SendableRegistry::GetInstance().AddChild(this, m_analog_input.get()); |
| 21 | } |
| 22 | |
| 23 | AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange, |
| 24 | double offset) |
| 25 | : AnalogPotentiometer( |
| 26 | std::shared_ptr<AnalogInput>(input, NullDeleter<AnalogInput>()), |
| 27 | fullRange, 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 | SendableRegistry::GetInstance().AddLW(this, "AnalogPotentiometer", |
| 33 | m_analog_input->GetChannel()); |
| 34 | } |
| 35 | |
| 36 | double AnalogPotentiometer::Get() const { |
| 37 | return (m_analog_input->GetVoltage() / RobotController::GetVoltage5V()) * |
| 38 | m_fullRange + |
| 39 | m_offset; |
| 40 | } |
| 41 | |
| 42 | double AnalogPotentiometer::PIDGet() { return Get(); } |
| 43 | |
| 44 | void AnalogPotentiometer::InitSendable(SendableBuilder& builder) { |
| 45 | m_analog_input->InitSendable(builder); |
| 46 | } |