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