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