2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-05 13:55:31 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/Types.h>
|
2021-06-13 16:38:05 -07:00
|
|
|
#include <wpi/sendable/Sendable.h>
|
|
|
|
|
#include <wpi/sendable/SendableHelper.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogTriggerOutput.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2014-06-12 18:07:45 -04:00
|
|
|
class AnalogInput;
|
2019-11-01 23:41:30 -07:00
|
|
|
class DutyCycle;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
class AnalogTrigger : public wpi::Sendable,
|
|
|
|
|
public wpi::SendableHelper<AnalogTrigger> {
|
2015-06-25 15:07:55 -04:00
|
|
|
friend class AnalogTriggerOutput;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
explicit AnalogTrigger(int channel);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct an analog trigger given an analog input.
|
|
|
|
|
*
|
|
|
|
|
* This should be used in the case of sharing an analog channel between the
|
|
|
|
|
* trigger and an analog input object.
|
|
|
|
|
*
|
2021-10-14 18:09:38 -07:00
|
|
|
* @param input The pointer to the existing AnalogInput object
|
2018-05-31 20:47:15 -07:00
|
|
|
*/
|
2021-10-14 18:09:38 -07:00
|
|
|
explicit AnalogTrigger(AnalogInput* input);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2019-11-01 23:41:30 -07:00
|
|
|
/**
|
|
|
|
|
* Construct an analog trigger given a duty cycle input.
|
|
|
|
|
*
|
2021-10-14 18:09:38 -07:00
|
|
|
* @param dutyCycle The pointer to the existing DutyCycle object
|
2019-11-01 23:41:30 -07:00
|
|
|
*/
|
|
|
|
|
explicit AnalogTrigger(DutyCycle* dutyCycle);
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
~AnalogTrigger() override;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2021-05-25 20:54:39 -07:00
|
|
|
AnalogTrigger(AnalogTrigger&&) = default;
|
|
|
|
|
AnalogTrigger& operator=(AnalogTrigger&&) = default;
|
2018-09-24 00:08:25 -07:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void SetLimitsVoltage(double lower, double upper);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2019-11-01 23:41:30 -07:00
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* 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).
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
void SetLimitsRaw(int lower, int upper);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SetAveraged(bool useAveragedValue);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SetFiltered(bool useFilteredValue);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the index of the analog trigger.
|
|
|
|
|
*
|
|
|
|
|
* This is the FPGA index of this analog trigger instance.
|
|
|
|
|
*
|
|
|
|
|
* @return The index of the analog trigger.
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetIndex() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetInWindow();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetTriggerState();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an AnalogTriggerOutput object.
|
|
|
|
|
*
|
|
|
|
|
* Gets an output object that can be used for routing. Caller is responsible
|
|
|
|
|
* for deleting the AnalogTriggerOutput object.
|
|
|
|
|
*
|
|
|
|
|
* @param type An enum of the type of output object to create.
|
|
|
|
|
* @return A pointer to a new AnalogTriggerOutput object.
|
|
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
std::shared_ptr<AnalogTriggerOutput> CreateOutput(
|
|
|
|
|
AnalogTriggerType type) const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
void InitSendable(wpi::SendableBuilder& builder) override;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2021-05-23 19:33:33 -07:00
|
|
|
int GetSourceChannel() const;
|
|
|
|
|
|
2019-08-25 18:42:00 -07:00
|
|
|
hal::Handle<HAL_AnalogTriggerHandle> m_trigger;
|
2016-06-27 21:32:30 -07:00
|
|
|
AnalogInput* m_analogInput = nullptr;
|
2019-11-01 23:41:30 -07:00
|
|
|
DutyCycle* m_dutyCycle = nullptr;
|
2016-06-27 21:32:30 -07:00
|
|
|
bool m_ownsAnalog = false;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|