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