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