WPILibC++ 2024.3.2
AnalogTriggerOutput.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
9
10#include "frc/DigitalSource.h"
11
12namespace frc {
13
14class AnalogTrigger;
15
16/**
17 * Class to represent a specific output from an analog trigger.
18 *
19 * This class is used to get the current output value and also as a
20 * DigitalSource to provide routing of an output to digital subsystems on the
21 * FPGA such as Counter, Encoder, and Interrupt.
22 *
23 * The TriggerState output indicates the primary output value of the trigger.
24 * If the analog signal is less than the lower limit, the output is false. If
25 * the analog value is greater than the upper limit, then the output is true.
26 * If the analog value is in between, then the trigger output state maintains
27 * its most recent value.
28 *
29 * The InWindow output indicates whether or not the analog signal is inside the
30 * range defined by the limits.
31 *
32 * The RisingPulse and FallingPulse outputs detect an instantaneous transition
33 * from above the upper limit to below the lower limit, and vice versa. These
34 * pulses represent a rollover condition of a sensor and can be routed to an up
35 * / down counter or to interrupts. Because the outputs generate a pulse, they
36 * cannot be read directly. To help ensure that a rollover condition is not
37 * missed, there is an average rejection filter available that operates on the
38 * upper 8 bits of a 12 bit number and selects the nearest outlyer of 3 samples.
39 * This will reject a sample that is (due to averaging or sampling) errantly
40 * between the two limits. This filter will fail if more than one sample in a
41 * row is errantly in between the two limits. You may see this problem if
42 * attempting to use this feature with a mechanical rollover sensor, such as a
43 * 360 degree no-stop potentiometer without signal conditioning, because the
44 * rollover transition is not sharp / clean enough. Using the averaging engine
45 * may help with this, but rotational speeds of the sensor will then be limited.
46 */
48 public wpi::Sendable,
49 public wpi::SendableHelper<AnalogTriggerOutput> {
50 friend class AnalogTrigger;
51
52 public:
53 /**
54 * Get the state of the analog trigger output.
55 *
56 * @return The state of the analog trigger output.
57 */
58 bool Get() const;
59
60 // DigitalSource interface
61 /**
62 * @return The HAL Handle to the specified source.
63 */
65
66 /**
67 * @return The type of analog trigger output to be used.
68 */
70
71 /**
72 * Is source an AnalogTrigger
73 */
74 bool IsAnalogTrigger() const override;
75
76 /**
77 * @return The channel of the source.
78 */
79 int GetChannel() const override;
80
81 void InitSendable(wpi::SendableBuilder& builder) override;
82
83 protected:
84 /**
85 * Create an object that represents one of the four outputs from an analog
86 * trigger.
87 *
88 * Because this class derives from DigitalSource, it can be passed into
89 * routing functions for Counter, Encoder, etc.
90 *
91 * @param trigger A pointer to the trigger for which this is an output.
92 * @param outputType An enum that specifies the output on the trigger to
93 * represent.
94 */
96 AnalogTriggerType outputType);
97
98 private:
99 // Uses pointer rather than smart pointer because a user can not construct
100 // an AnalogTriggerOutput themselves and because the AnalogTriggerOutput
101 // should always be in scope at the same time as an AnalogTrigger.
102 const AnalogTrigger* m_trigger;
103 AnalogTriggerType m_outputType;
104};
105
106} // namespace frc
Definition: AnalogTrigger.h:21
Class to represent a specific output from an analog trigger.
Definition: AnalogTriggerOutput.h:49
AnalogTriggerOutput(const AnalogTrigger &trigger, AnalogTriggerType outputType)
Create an object that represents one of the four outputs from an analog trigger.
bool IsAnalogTrigger() const override
Is source an AnalogTrigger.
HAL_Handle GetPortHandleForRouting() const override
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
int GetChannel() const override
bool Get() const
Get the state of the analog trigger output.
AnalogTriggerType GetAnalogTriggerTypeForRouting() const override
DigitalSource Interface.
Definition: DigitalSource.h:22
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
int32_t HAL_Handle
Definition: Types.h:17
Definition: AprilTagPoseEstimator.h:15
AnalogTriggerType
Defines the state in which the AnalogTrigger triggers.
Definition: AnalogTriggerType.h:10