blob: 7eb3163867478ba29bb6dfbd12c3fb99e18b2b86 [file] [log] [blame]
Parker Schuhd3b7a8872018-02-19 16:42:27 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#pragma once
9
Austin Schuhf6b94632019-02-02 22:11:27 -080010#include "hal/AnalogTrigger.h"
Parker Schuhd3b7a8872018-02-19 16:42:27 -080011#include "frc971/wpilib/ahal/DigitalSource.h"
12
13namespace frc {
14
15class AnalogTrigger;
16
17/**
18 * Class to represent a specific output from an analog trigger.
19 *
20 * This class is used to get the current output value and also as a
21 * DigitalSource to provide routing of an output to digital subsystems on the
22 * FPGA such as Counter, Encoder, and Interrupt.
23 *
24 * The TriggerState output indicates the primary output value of the trigger.
25 * If the analog signal is less than the lower limit, the output is false. If
26 * the analog value is greater than the upper limit, then the output is true.
27 * If the analog value is in between, then the trigger output state maintains
28 * its most recent value.
29 *
30 * The InWindow output indicates whether or not the analog signal is inside the
31 * range defined by the limits.
32 *
33 * The RisingPulse and FallingPulse outputs detect an instantaneous transition
34 * from above the upper limit to below the lower limit, and vise versa. These
35 * pulses represent a rollover condition of a sensor and can be routed to an up
36 * / down counter or to interrupts. Because the outputs generate a pulse, they
37 * cannot be read directly. To help ensure that a rollover condition is not
38 * missed, there is an average rejection filter available that operates on the
39 * upper 8 bits of a 12 bit number and selects the nearest outlyer of 3 samples.
40 * This will reject a sample that is (due to averaging or sampling) errantly
41 * between the two limits. This filter will fail if more than one sample in a
42 * row is errantly in between the two limits. You may see this problem if
43 * attempting to use this feature with a mechanical rollover sensor, such as a
44 * 360 degree no-stop potentiometer without signal conditioning, because the
45 * rollover transition is not sharp / clean enough. Using the averaging engine
46 * may help with this, but rotational speeds of the sensor will then be limited.
47 */
48class AnalogTriggerOutput : public DigitalSource {
49 friend class AnalogTrigger;
50
51 public:
52 virtual ~AnalogTriggerOutput();
53 bool Get() const;
54
55 // DigitalSource interface
56 HAL_Handle GetPortHandleForRouting() const override;
57 AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
58 bool IsAnalogTrigger() const override;
59 int GetChannel() const override;
60
61 protected:
62 AnalogTriggerOutput(const AnalogTrigger &trigger,
63 AnalogTriggerType outputType);
64
65 private:
66 // Uses reference rather than smart pointer because a user can not construct
67 // an AnalogTriggerOutput themselves and because the AnalogTriggerOutput
68 // should always be in scope at the same time as an AnalogTrigger.
69 const AnalogTrigger &m_trigger;
70 AnalogTriggerType m_outputType;
71};
72
73} // namespace frc