blob: 7b7b12a8c50b8b3755dd0c69dc58da2be7f7d7ab [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001#include "AnalogInput.h"
2#include "interfaces/Potentiometer.h"
3#include "LiveWindow/LiveWindowSendable.h"
4
5#include <memory>
6
7/**
8 * Class for reading analog potentiometers. Analog potentiometers read
9 * in an analog voltage that corresponds to a position. The position is
10 * in whichever units you choose, by way of the scaling and offset
11 * constants passed to the constructor.
12 *
13 * @author Alex Henning
14 * @author Colby Skeggs (rail voltage)
15 */
16class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
17 public:
18 /**
19 * AnalogPotentiometer constructor.
20 *
21 * Use the fullRange and offset values so that the output produces
22 * meaningful values. I.E: you have a 270 degree potentiometer and
23 * you want the output to be degrees with the halfway point as 0
24 * degrees. The fullRange value is 270.0(degrees) and the offset is
25 * -135.0 since the halfway point after scaling is 135 degrees.
26 *
27 * This will calculate the result from the fullRange times the
28 * fraction of the supply voltage, plus the offset.
29 *
30 * @param channel The analog channel this potentiometer is plugged into.
31 * @param fullRange The scaling to multiply the voltage by to get a meaningful
32 * unit.
33 * @param offset The offset to add to the scaled value for controlling the
34 * zero value
35 */
36 explicit AnalogPotentiometer(int channel, double fullRange = 1.0,
37 double offset = 0.0);
38
39 explicit AnalogPotentiometer(AnalogInput *input, double fullRange = 1.0,
40 double offset = 0.0);
41
42 explicit AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
43 double fullRange = 1.0, double offset = 0.0);
44
45 virtual ~AnalogPotentiometer() = default;
46
47 /**
48 * Get the current reading of the potentiomer.
49 *
50 * @return The current position of the potentiometer.
51 */
52 virtual double Get() const override;
53
54 /**
55 * Implement the PIDSource interface.
56 *
57 * @return The current reading.
58 */
59 virtual double PIDGet() override;
60
61 /*
62 * Live Window code, only does anything if live window is activated.
63 */
64 virtual std::string GetSmartDashboardType() const override;
65 virtual void InitTable(std::shared_ptr<ITable> subtable) override;
66 virtual void UpdateTable() override;
67 virtual std::shared_ptr<ITable> GetTable() const override;
68
69 /**
70 * AnalogPotentiometers don't have to do anything special when entering the
71 * LiveWindow.
72 */
73 virtual void StartLiveWindowMode() override {}
74
75 /**
76 * AnalogPotentiometers don't have to do anything special when exiting the
77 * LiveWindow.
78 */
79 virtual void StopLiveWindowMode() override {}
80
81 private:
82 std::shared_ptr<AnalogInput> m_analog_input;
83 double m_fullRange, m_offset;
84 std::shared_ptr<ITable> m_table;
85};