WPILibC++ 2025.3.2
Loading...
Searching...
No Matches
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/AnalogTrigger.h>
10#include <hal/Types.h>
13
15
16namespace frc {
17
18class AnalogInput;
19class DutyCycle;
20
22 public wpi::SendableHelper<AnalogTrigger> {
23 friend class AnalogTriggerOutput;
24
25 public:
26 /**
27 * Constructor for an analog trigger given a channel number.
28 *
29 * @param channel The channel number on the roboRIO to represent. 0-3 are
30 * on-board 4-7 are on the MXP port.
31 */
32 explicit AnalogTrigger(int channel);
33
34 /**
35 * Construct an analog trigger using an existing analog input.
36 *
37 * This should be used in the case of sharing an analog channel between the
38 * trigger and an analog input object.
39 *
40 * @param input A reference to the existing AnalogInput object
41 */
42 explicit AnalogTrigger(AnalogInput& input);
43
44 /**
45 * Construct an analog trigger using an existing analog input.
46 *
47 * This should be used in the case of sharing an analog channel between the
48 * trigger and an analog input object.
49 *
50 * @param input A pointer to the existing AnalogInput object
51 */
52 explicit AnalogTrigger(AnalogInput* input);
53
54 /**
55 * Construct an analog trigger using an existing analog input.
56 *
57 * This should be used in the case of sharing an analog channel between the
58 * trigger and an analog input object.
59 *
60 * @param input A shared_ptr to the existing AnalogInput object
61 */
62 explicit AnalogTrigger(std::shared_ptr<AnalogInput> input);
63
64 /**
65 * Construct an analog trigger using an existing duty cycle input.
66 *
67 * @param dutyCycle A reference to the existing DutyCycle object
68 */
69 explicit AnalogTrigger(DutyCycle& dutyCycle);
70
71 /**
72 * Construct an analog trigger using an existing duty cycle input.
73 *
74 * @param dutyCycle A pointer to the existing DutyCycle object
75 */
76 explicit AnalogTrigger(DutyCycle* dutyCycle);
77
78 /**
79 * Construct an analog trigger using an existing duty cycle input.
80 *
81 * @param dutyCycle A shared_ptr to the existing DutyCycle object
82 */
83 explicit AnalogTrigger(std::shared_ptr<DutyCycle> dutyCycle);
84
87
88 ~AnalogTrigger() override = default;
89
90 /**
91 * Set the upper and lower limits of the analog trigger.
92 *
93 * The limits are given as floating point voltage values.
94 *
95 * @param lower The lower limit of the trigger in Volts.
96 * @param upper The upper limit of the trigger in Volts.
97 */
98 void SetLimitsVoltage(double lower, double upper);
99
100 /**
101 * Set the upper and lower duty cycle limits of the analog trigger.
102 *
103 * The limits are given as floating point values between 0 and 1.
104 *
105 * @param lower The lower limit of the trigger in percentage.
106 * @param upper The upper limit of the trigger in percentage.
107 */
108 void SetLimitsDutyCycle(double lower, double upper);
109
110 /**
111 * Set the upper and lower limits of the analog trigger.
112 *
113 * The limits are given in ADC codes. If oversampling is used, the units must
114 * be scaled appropriately.
115 *
116 * @param lower The lower limit of the trigger in ADC codes (12-bit values).
117 * @param upper The upper limit of the trigger in ADC codes (12-bit values).
118 */
119 void SetLimitsRaw(int lower, int upper);
120
121 /**
122 * Configure the analog trigger to use the averaged vs. raw values.
123 *
124 * If the value is true, then the averaged value is selected for the analog
125 * trigger, otherwise the immediate value is used.
126 *
127 * @param useAveragedValue If true, use the Averaged value, otherwise use the
128 * instantaneous reading
129 */
130 void SetAveraged(bool useAveragedValue);
131
132 /**
133 * Configure the analog trigger to use a filtered value.
134 *
135 * The analog trigger will operate with a 3 point average rejection filter.
136 * This is designed to help with 360 degree pot applications for the period
137 * where the pot crosses through zero.
138 *
139 * @param useFilteredValue If true, use the 3 point rejection filter,
140 * otherwise use the unfiltered value
141 */
142 void SetFiltered(bool useFilteredValue);
143
144 /**
145 * Return the index of the analog trigger.
146 *
147 * This is the FPGA index of this analog trigger instance.
148 *
149 * @return The index of the analog trigger.
150 */
151 int GetIndex() const;
152
153 /**
154 * Return the InWindow output of the analog trigger.
155 *
156 * True if the analog input is between the upper and lower limits.
157 *
158 * @return True if the analog input is between the upper and lower limits.
159 */
161
162 /**
163 * Return the TriggerState output of the analog trigger.
164 *
165 * True if above upper limit.
166 * False if below lower limit.
167 * If in Hysteresis, maintain previous state.
168 *
169 * @return True if above upper limit. False if below lower limit. If in
170 * Hysteresis, maintain previous state.
171 */
173
174 /**
175 * Creates an AnalogTriggerOutput object.
176 *
177 * @param type An enum of the type of output object to create.
178 * @return A pointer to a new AnalogTriggerOutput object.
179 */
180 std::shared_ptr<AnalogTriggerOutput> CreateOutput(
181 AnalogTriggerType type) const;
182
183 void InitSendable(wpi::SendableBuilder& builder) override;
184
185 private:
186 int GetSourceChannel() const;
187
188 std::shared_ptr<AnalogInput> m_analogInput;
189 std::shared_ptr<DutyCycle> m_dutyCycle;
191 bool m_ownsAnalog = false;
192};
193
194} // namespace frc
Analog input class.
Definition AnalogInput.h:32
Definition AnalogTrigger.h:22
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(DutyCycle &dutyCycle)
Construct an analog trigger using an existing duty cycle input.
AnalogTrigger(AnalogInput *input)
Construct an analog trigger using an existing analog input.
AnalogTrigger(AnalogInput &input)
Construct an analog trigger using an existing analog input.
void SetFiltered(bool useFilteredValue)
Configure the analog trigger to use a filtered value.
AnalogTrigger(std::shared_ptr< AnalogInput > input)
Construct an analog trigger using an existing analog input.
AnalogTrigger(AnalogTrigger &&)=default
AnalogTrigger(DutyCycle *dutyCycle)
Construct an analog trigger using an existing duty cycle input.
int GetIndex() const
Return the index of the analog trigger.
bool GetInWindow()
Return the InWindow output of the analog trigger.
~AnalogTrigger() override=default
AnalogTrigger(std::shared_ptr< DutyCycle > dutyCycle)
Construct an analog trigger using an existing duty cycle input.
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:32
A move-only C++ wrapper around a HAL handle.
Definition Types.h:96
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:21
Interface for Sendable objects.
Definition Sendable.h:16
Definition CAN.h:11
AnalogTriggerType
Defines the state in which the AnalogTrigger triggers.
Definition AnalogTriggerType.h:10