2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2014-06-13 17:45:10 -04:00
|
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#include "HAL/HAL.hpp"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "SensorBase.h"
|
|
|
|
|
#include "PIDSource.h"
|
|
|
|
|
#include "LiveWindow/LiveWindowSendable.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-12 18:07:45 -04:00
|
|
|
* Analog input class.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Connected to each analog channel is an averaging and oversampling engine.
|
|
|
|
|
* This engine accumulates
|
|
|
|
|
* the specified ( by SetAverageBits() and SetOversampleBits() ) number of
|
|
|
|
|
* samples before returning a new
|
|
|
|
|
* value. This is not a sliding window average. The only difference between
|
|
|
|
|
* the oversampled samples and
|
|
|
|
|
* the averaged samples is that the oversampled samples are simply accumulated
|
|
|
|
|
* effectively increasing the
|
|
|
|
|
* resolution, while the averaged samples are divided by the number of samples
|
|
|
|
|
* to retain the resolution,
|
2013-12-15 18:30:16 -05:00
|
|
|
* but get more stable values.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class AnalogInput : public SensorBase,
|
|
|
|
|
public PIDSource,
|
|
|
|
|
public LiveWindowSendable {
|
|
|
|
|
public:
|
|
|
|
|
static const uint8_t kAccumulatorModuleNumber = 1;
|
|
|
|
|
static const uint32_t kAccumulatorNumChannels = 2;
|
|
|
|
|
static const uint32_t kAccumulatorChannels[kAccumulatorNumChannels];
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
explicit AnalogInput(uint32_t channel);
|
|
|
|
|
virtual ~AnalogInput();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
int16_t GetValue() const;
|
|
|
|
|
int32_t GetAverageValue() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
float GetVoltage() const;
|
|
|
|
|
float GetAverageVoltage() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
uint32_t GetChannel() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void SetAverageBits(uint32_t bits);
|
|
|
|
|
uint32_t GetAverageBits() const;
|
|
|
|
|
void SetOversampleBits(uint32_t bits);
|
|
|
|
|
uint32_t GetOversampleBits() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
uint32_t GetLSBWeight() const;
|
|
|
|
|
int32_t GetOffset() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
bool IsAccumulatorChannel() const;
|
|
|
|
|
void InitAccumulator();
|
|
|
|
|
void SetAccumulatorInitialValue(int64_t value);
|
|
|
|
|
void ResetAccumulator();
|
|
|
|
|
void SetAccumulatorCenter(int32_t center);
|
|
|
|
|
void SetAccumulatorDeadband(int32_t deadband);
|
|
|
|
|
int64_t GetAccumulatorValue() const;
|
|
|
|
|
uint32_t GetAccumulatorCount() const;
|
|
|
|
|
void GetAccumulatorOutput(int64_t *value, uint32_t *count) const;
|
2014-05-02 17:54:01 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
static void SetSampleRate(float samplesPerSecond);
|
|
|
|
|
static float GetSampleRate();
|
2014-07-21 16:32:36 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
double PIDGet() const override;
|
2014-05-02 17:54:01 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void UpdateTable() override;
|
|
|
|
|
void StartLiveWindowMode() override;
|
|
|
|
|
void StopLiveWindowMode() override;
|
|
|
|
|
std::string GetSmartDashboardType() const override;
|
|
|
|
|
void InitTable(ITable *subTable) override;
|
|
|
|
|
ITable *GetTable() const override;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
|
|
|
|
void InitAnalogInput(uint32_t channel);
|
|
|
|
|
uint32_t m_channel;
|
|
|
|
|
void *m_port;
|
|
|
|
|
int64_t m_accumulatorOffset;
|
2014-05-02 17:54:01 -04:00
|
|
|
|
2015-06-24 01:06:29 -07:00
|
|
|
ITable *m_table = nullptr;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|