WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
AnalogPotentiometer.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8
12
13namespace wpi {
14
15/**
16 * Class for reading analog potentiometers. Analog potentiometers read in an
17 * analog voltage that corresponds to a position. The position is in whichever
18 * units you choose, by way of the scaling and offset constants passed to the
19 * constructor.
20 */
22 : public wpi::util::Sendable,
23 public wpi::util::SendableHelper<AnalogPotentiometer> {
24 public:
25 /**
26 * Construct an Analog Potentiometer object from a channel number.
27 *
28 * Use the fullRange and offset values so that the output produces meaningful
29 * values. I.E: you have a 270 degree potentiometer and you want the output to
30 * be degrees with the halfway point as 0 degrees. The fullRange value is
31 * 270.0 degrees and the offset is -135.0 since the halfway point after
32 * scaling is 135 degrees.
33 *
34 * This will calculate the result from the fullRange times the fraction of the
35 * supply voltage, plus the offset.
36 *
37 * @param channel The SmartIO channel this potentiometer is plugged into.
38 * @param fullRange The value (in desired units) representing the full
39 * 0-3.3V range of the input.
40 * @param offset The value (in desired units) representing the
41 * angular output at 0V.
42 */
43 explicit AnalogPotentiometer(int channel, double fullRange = 1.0,
44 double offset = 0.0);
45
46 /**
47 * Construct an Analog Potentiometer object from an existing Analog Input
48 * pointer.
49 *
50 * Use the fullRange and offset values so that the output produces meaningful
51 * values. I.E: you have a 270 degree potentiometer and you want the output to
52 * be degrees with the halfway point as 0 degrees. The fullRange value is
53 * 270.0 degrees and the offset is -135.0 since the halfway point after
54 * scaling is 135 degrees.
55 *
56 * This will calculate the result from the fullRange times the fraction of the
57 * supply voltage, plus the offset.
58 *
59 * @param input The existing Analog Input pointer
60 * @param fullRange The value (in desired units) representing the full
61 * 0-3.3V range of the input.
62 * @param offset The value (in desired units) representing the
63 * angular output at 0V.
64 */
65 explicit AnalogPotentiometer(AnalogInput* input, double fullRange = 1.0,
66 double offset = 0.0);
67
68 /**
69 * Construct an Analog Potentiometer object from an existing Analog Input
70 * pointer.
71 *
72 * Use the fullRange and offset values so that the output produces meaningful
73 * values. I.E: you have a 270 degree potentiometer and you want the output to
74 * be degrees with the halfway point as 0 degrees. The fullRange value is
75 * 270.0 degrees and the offset is -135.0 since the halfway point after
76 * scaling is 135 degrees.
77 *
78 * This will calculate the result from the fullRange times the fraction of the
79 * supply voltage, plus the offset.
80 *
81 * @param input The existing Analog Input pointer
82 * @param fullRange The value (in desired units) representing the full
83 * 0-3.3V range of the input.
84 * @param offset The value (in desired units) representing the
85 * angular output at 0V.
86 */
87 explicit AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
88 double fullRange = 1.0, double offset = 0.0);
89
90 ~AnalogPotentiometer() override = default;
91
94
95 /**
96 * Get the current reading of the potentiometer.
97 *
98 * @return The current position of the potentiometer (in the units used for
99 * fullRange and offset).
100 */
101 double Get() const;
102
104
105 private:
106 std::shared_ptr<AnalogInput> m_analog_input;
107 double m_fullRange, m_offset;
108};
109
110} // namespace wpi
Analog input class.
Definition AnalogInput.hpp:29
AnalogPotentiometer & operator=(AnalogPotentiometer &&)=default
~AnalogPotentiometer() override=default
double Get() const
Get the current reading of the potentiometer.
AnalogPotentiometer(AnalogPotentiometer &&)=default
AnalogPotentiometer(int channel, double fullRange=1.0, double offset=0.0)
Construct an Analog Potentiometer object from a channel number.
AnalogPotentiometer(std::shared_ptr< AnalogInput > input, double fullRange=1.0, double offset=0.0)
Construct an Analog Potentiometer object from an existing Analog Input pointer.
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
AnalogPotentiometer(AnalogInput *input, double fullRange=1.0, double offset=0.0)
Construct an Analog Potentiometer object from an existing Analog Input pointer.
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.hpp:21
Interface for Sendable objects.
Definition Sendable.hpp:16
Definition CvSource.hpp:15