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