WPILibC++ 2024.3.2
AnalogPotentiometer.h
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
11
12#include "frc/AnalogInput.h"
13
14namespace frc {
15
16/**
17 * Class for reading analog potentiometers. Analog potentiometers read in an
18 * analog voltage that corresponds to a position. The position is in whichever
19 * units you choose, by way of the scaling and offset constants passed to the
20 * constructor.
21 */
23 public wpi::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 Analog Input channel number on the roboRIO the
38 * potentiometer is plugged into. 0-3 are on-board and 4-7
39 * are on the MXP port.
40 * @param fullRange The value (in desired units) representing the full
41 * 0-5V range of the input.
42 * @param offset The value (in desired units) representing the
43 * angular output at 0V.
44 */
45 explicit AnalogPotentiometer(int channel, double fullRange = 1.0,
46 double offset = 0.0);
47
48 /**
49 * Construct an Analog Potentiometer object from an existing Analog Input
50 * pointer.
51 *
52 * Use the fullRange and offset values so that the output produces meaningful
53 * values. I.E: you have a 270 degree potentiometer and you want the output to
54 * be degrees with the halfway point as 0 degrees. The fullRange value is
55 * 270.0 degrees and the offset is -135.0 since the halfway point after
56 * scaling is 135 degrees.
57 *
58 * This will calculate the result from the fullRange times the fraction of the
59 * supply voltage, plus the offset.
60 *
61 * @param input The existing Analog Input pointer
62 * @param fullRange The value (in desired units) representing the full
63 * 0-5V range of the input.
64 * @param offset The value (in desired units) representing the
65 * angular output at 0V.
66 */
67 explicit AnalogPotentiometer(AnalogInput* input, double fullRange = 1.0,
68 double offset = 0.0);
69
70 /**
71 * Construct an Analog Potentiometer object from an existing Analog Input
72 * pointer.
73 *
74 * Use the fullRange and offset values so that the output produces meaningful
75 * values. I.E: you have a 270 degree potentiometer and you want the output to
76 * be degrees with the halfway point as 0 degrees. The fullRange value is
77 * 270.0 degrees and the offset is -135.0 since the halfway point after
78 * scaling is 135 degrees.
79 *
80 * This will calculate the result from the fullRange times the fraction of the
81 * supply voltage, plus the offset.
82 *
83 * @param input The existing Analog Input pointer
84 * @param fullRange The value (in desired units) representing the full
85 * 0-5V range of the input.
86 * @param offset The value (in desired units) representing the
87 * angular output at 0V.
88 */
89 explicit AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
90 double fullRange = 1.0, double offset = 0.0);
91
92 ~AnalogPotentiometer() override = default;
93
96
97 /**
98 * Get the current reading of the potentiometer.
99 *
100 * @return The current position of the potentiometer (in the units used for
101 * fullRange and offset).
102 */
103 double Get() const;
104
105 void InitSendable(wpi::SendableBuilder& builder) override;
106
107 private:
108 std::shared_ptr<AnalogInput> m_analog_input;
109 double m_fullRange, m_offset;
110};
111
112} // namespace frc
Analog input class.
Definition: AnalogInput.h:31
Class for reading analog potentiometers.
Definition: AnalogPotentiometer.h:23
AnalogPotentiometer(AnalogPotentiometer &&)=default
double Get() const
Get the current reading of the potentiometer.
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.
AnalogPotentiometer(int channel, double fullRange=1.0, double offset=0.0)
Construct an Analog Potentiometer object from a channel number.
~AnalogPotentiometer() override=default
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
AnalogPotentiometer & operator=(AnalogPotentiometer &&)=default
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.h:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
Definition: AprilTagPoseEstimator.h:15