WPILibC++ 2024.1.1-beta-4
AnalogTrigger.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
9#include <hal/Types.h>
12
14
15namespace frc {
16
17class AnalogInput;
18class DutyCycle;
19
21 public wpi::SendableHelper<AnalogTrigger> {
22 friend class AnalogTriggerOutput;
23
24 public:
25 /**
26 * Constructor for an analog trigger given a channel number.
27 *
28 * @param channel The channel number on the roboRIO to represent. 0-3 are
29 * on-board 4-7 are on the MXP port.
30 */
31 explicit AnalogTrigger(int channel);
32
33 /**
34 * Construct an analog trigger given an analog input.
35 *
36 * This should be used in the case of sharing an analog channel between the
37 * trigger and an analog input object.
38 *
39 * @param input The pointer to the existing AnalogInput object
40 */
41 explicit AnalogTrigger(AnalogInput* input);
42
43 /**
44 * Construct an analog trigger given a duty cycle input.
45 *
46 * @param dutyCycle The pointer to the existing DutyCycle object
47 */
48 explicit AnalogTrigger(DutyCycle* dutyCycle);
49
50 ~AnalogTrigger() override;
51
54
55 /**
56 * Set the upper and lower limits of the analog trigger.
57 *
58 * The limits are given as floating point voltage values.
59 *
60 * @param lower The lower limit of the trigger in Volts.
61 * @param upper The upper limit of the trigger in Volts.
62 */
63 void SetLimitsVoltage(double lower, double upper);
64
65 /**
66 * Set the upper and lower duty cycle limits of the analog trigger.
67 *
68 * The limits are given as floating point values between 0 and 1.
69 *
70 * @param lower The lower limit of the trigger in percentage.
71 * @param upper The upper limit of the trigger in percentage.
72 */
73 void SetLimitsDutyCycle(double lower, double upper);
74
75 /**
76 * Set the upper and lower limits of the analog trigger.
77 *
78 * The limits are given in ADC codes. If oversampling is used, the units must
79 * be scaled appropriately.
80 *
81 * @param lower The lower limit of the trigger in ADC codes (12-bit values).
82 * @param upper The upper limit of the trigger in ADC codes (12-bit values).
83 */
84 void SetLimitsRaw(int lower, int upper);
85
86 /**
87 * Configure the analog trigger to use the averaged vs. raw values.
88 *
89 * If the value is true, then the averaged value is selected for the analog
90 * trigger, otherwise the immediate value is used.
91 *
92 * @param useAveragedValue If true, use the Averaged value, otherwise use the
93 * instantaneous reading
94 */
95 void SetAveraged(bool useAveragedValue);
96
97 /**
98 * Configure the analog trigger to use a filtered value.
99 *
100 * The analog trigger will operate with a 3 point average rejection filter.
101 * This is designed to help with 360 degree pot applications for the period
102 * where the pot crosses through zero.
103 *
104 * @param useFilteredValue If true, use the 3 point rejection filter,
105 * otherwise use the unfiltered value
106 */
107 void SetFiltered(bool useFilteredValue);
108
109 /**
110 * Return the index of the analog trigger.
111 *
112 * This is the FPGA index of this analog trigger instance.
113 *
114 * @return The index of the analog trigger.
115 */
116 int GetIndex() const;
117
118 /**
119 * Return the InWindow output of the analog trigger.
120 *
121 * True if the analog input is between the upper and lower limits.
122 *
123 * @return True if the analog input is between the upper and lower limits.
124 */
126
127 /**
128 * Return the TriggerState output of the analog trigger.
129 *
130 * True if above upper limit.
131 * False if below lower limit.
132 * If in Hysteresis, maintain previous state.
133 *
134 * @return True if above upper limit. False if below lower limit. If in
135 * Hysteresis, maintain previous state.
136 */
138
139 /**
140 * Creates an AnalogTriggerOutput object.
141 *
142 * Gets an output object that can be used for routing. Caller is responsible
143 * for deleting the AnalogTriggerOutput object.
144 *
145 * @param type An enum of the type of output object to create.
146 * @return A pointer to a new AnalogTriggerOutput object.
147 */
148 std::shared_ptr<AnalogTriggerOutput> CreateOutput(
149 AnalogTriggerType type) const;
150
151 void InitSendable(wpi::SendableBuilder& builder) override;
152
153 private:
154 int GetSourceChannel() const;
155
157 AnalogInput* m_analogInput = nullptr;
158 DutyCycle* m_dutyCycle = nullptr;
159 bool m_ownsAnalog = false;
160};
161
162} // namespace frc
Analog input class.
Definition: AnalogInput.h:31
Definition: AnalogTrigger.h:21
~AnalogTrigger() override
void SetLimitsVoltage(double lower, double upper)
Set the upper and lower limits of the analog trigger.
void SetLimitsDutyCycle(double lower, double upper)
Set the upper and lower duty cycle limits of the analog trigger.
bool GetTriggerState()
Return the TriggerState output of the analog trigger.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
AnalogTrigger(AnalogInput *input)
Construct an analog trigger given an analog input.
void SetFiltered(bool useFilteredValue)
Configure the analog trigger to use a filtered value.
AnalogTrigger(AnalogTrigger &&)=default
AnalogTrigger(DutyCycle *dutyCycle)
Construct an analog trigger given a duty cycle input.
int GetIndex() const
Return the index of the analog trigger.
bool GetInWindow()
Return the InWindow output of the analog trigger.
std::shared_ptr< AnalogTriggerOutput > CreateOutput(AnalogTriggerType type) const
Creates an AnalogTriggerOutput object.
AnalogTrigger & operator=(AnalogTrigger &&)=default
void SetLimitsRaw(int lower, int upper)
Set the upper and lower limits of the analog trigger.
void SetAveraged(bool useAveragedValue)
Configure the analog trigger to use the averaged vs.
AnalogTrigger(int channel)
Constructor for an analog trigger given a channel number.
Class to represent a specific output from an analog trigger.
Definition: AnalogTriggerOutput.h:49
Class to read a duty cycle PWM input.
Definition: DutyCycle.h:31
Definition: SendableBuilder.h:18
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
type
Definition: core.h:556
Definition: AprilTagPoseEstimator.h:15
AnalogTriggerType
Definition: AnalogTriggerType.h:9