WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
AnalogInput.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 <stdint.h>
8
10#include "wpi/hal/Types.hpp"
13
14namespace wpi {
15
16/**
17 * Analog input class.
18 *
19 * Connected to each analog channel is an averaging and oversampling engine.
20 * This engine accumulates the specified ( by SetAverageBits() and
21 * SetOversampleBits() ) number of samples before returning a new value. This is
22 * not a sliding window average. The only difference between the oversampled
23 * samples and the averaged samples is that the oversampled samples are simply
24 * accumulated effectively increasing the resolution, while the averaged samples
25 * are divided by the number of samples to retain the resolution, but get more
26 * stable values.
27 */
29 public wpi::util::SendableHelper<AnalogInput> {
30 public:
31 /**
32 * Construct an analog input.
33 *
34 * @param channel The SmartIO channel to use.
35 */
36 explicit AnalogInput(int channel);
37
40
41 ~AnalogInput() override = default;
42
43 /**
44 * Get a sample straight from this channel.
45 *
46 * The sample is a 12-bit value representing the 0V to 3.3V range of the A/D
47 * converter in the module. The units are in A/D converter codes. Use
48 * GetVoltage() to get the analog value in calibrated units.
49 *
50 * @return A sample straight from this channel.
51 */
52 int GetValue() const;
53
54 /**
55 * Get a scaled sample straight from this channel.
56 *
57 * The value is scaled to units of Volts.
58 *
59 * @return A scaled sample straight from this channel.
60 */
61 double GetVoltage() const;
62
63 /**
64 * Get the channel number.
65 *
66 * @return The channel number.
67 */
68 int GetChannel() const;
69
70 /**
71 * Indicates this input is used by a simulated device.
72 *
73 * @param device simulated device handle
74 */
76
78
79 private:
80 int m_channel;
82};
83
84} // namespace wpi
AnalogInput(int channel)
Construct an analog input.
AnalogInput & operator=(AnalogInput &&)=default
int GetChannel() const
Get the channel number.
int GetValue() const
Get a sample straight from this channel.
~AnalogInput() override=default
void SetSimDevice(HAL_SimDeviceHandle device)
Indicates this input is used by a simulated device.
double GetVoltage() const
Get a scaled sample straight from this channel.
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
AnalogInput(AnalogInput &&)=default
A move-only C++ wrapper around a HAL handle.
Definition Types.hpp:16
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
HAL_Handle HAL_SimDeviceHandle
Definition Types.h:45
Definition CvSource.hpp:15