blob: 1372d846208f86a6e5a96347c1823ce87a712f7d [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001#include "AnalogPotentiometer.h"
2#include "ControllerPower.h"
3
4/**
5 * Construct an Analog Potentiometer object from a channel number.
6 * @param channel The channel number on the roboRIO to represent. 0-3 are
7 * on-board 4-7 are on the MXP port.
8 * @param fullRange The angular value (in desired units) representing the full
9 * 0-5V range of the input.
10 * @param offset The angular value (in desired units) representing the angular
11 * output at 0V.
12 */
13AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
14 double offset)
15 : m_analog_input(std::make_unique<AnalogInput>(channel)),
16 m_fullRange(fullRange),
17 m_offset(offset) {}
18
19/**
20 * Construct an Analog Potentiometer object from an existing Analog Input
21 * pointer.
22 * @param channel The existing Analog Input pointer
23 * @param fullRange The angular value (in desired units) representing the full
24 * 0-5V range of the input.
25 * @param offset The angular value (in desired units) representing the angular
26 * output at 0V.
27 */
28AnalogPotentiometer::AnalogPotentiometer(AnalogInput *input, double fullRange,
29 double offset)
30 : m_analog_input(input, NullDeleter<AnalogInput>()),
31 m_fullRange(fullRange),
32 m_offset(offset) {}
33
34/**
35 * Construct an Analog Potentiometer object from an existing Analog Input
36 * pointer.
37 * @param channel The existing Analog Input pointer
38 * @param fullRange The angular value (in desired units) representing the full
39 * 0-5V range of the input.
40 * @param offset The angular value (in desired units) representing the angular
41 * output at 0V.
42 */
43AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
44 double fullRange, double offset)
45 : m_analog_input(input), m_fullRange(fullRange), m_offset(offset) {}
46
47/**
48 * Get the current reading of the potentiometer.
49 *
50 * @return The current position of the potentiometer (in the units used for
51 * fullRaneg and offset).
52 */
53double AnalogPotentiometer::Get() const {
54 return (m_analog_input->GetVoltage() / ControllerPower::GetVoltage5V()) *
55 m_fullRange +
56 m_offset;
57}
58
59/**
60 * Implement the PIDSource interface.
61 *
62 * @return The current reading.
63 */
64double AnalogPotentiometer::PIDGet() { return Get(); }
65
66/**
67 * @return the Smart Dashboard Type
68 */
69std::string AnalogPotentiometer::GetSmartDashboardType() const {
70 return "Analog Input";
71}
72
73/**
74 * Live Window code, only does anything if live window is activated.
75 */
76void AnalogPotentiometer::InitTable(std::shared_ptr<ITable> subtable) {
77 m_table = subtable;
78 UpdateTable();
79}
80
81void AnalogPotentiometer::UpdateTable() {
82 if (m_table != nullptr) {
83 m_table->PutNumber("Value", Get());
84 }
85}
86
87std::shared_ptr<ITable> AnalogPotentiometer::GetTable() const { return m_table; }