2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
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
|
|
|
|
2017-06-25 09:05:49 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include <memory>
|
2016-09-05 13:55:31 -07:00
|
|
|
#include <string>
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
#include "HAL/Types.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "LiveWindow/LiveWindowSendable.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "PIDSource.h"
|
|
|
|
|
#include "SensorBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
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.
|
2016-05-20 17:30:37 -07:00
|
|
|
* 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, but get more
|
|
|
|
|
* stable values.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class AnalogInput : public SensorBase,
|
|
|
|
|
public PIDSource,
|
|
|
|
|
public LiveWindowSendable {
|
2016-06-27 21:32:30 -07:00
|
|
|
friend class AnalogTrigger;
|
2016-07-07 21:31:45 -07:00
|
|
|
friend class AnalogGyro;
|
2016-06-27 21:32:30 -07:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
2016-09-06 00:01:45 -07:00
|
|
|
static const int kAccumulatorModuleNumber = 1;
|
|
|
|
|
static const int kAccumulatorNumChannels = 2;
|
|
|
|
|
static const int kAccumulatorChannels[kAccumulatorNumChannels];
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
explicit AnalogInput(int channel);
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual ~AnalogInput();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetValue() const;
|
|
|
|
|
int GetAverageValue() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetVoltage() const;
|
|
|
|
|
double GetAverageVoltage() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetChannel() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
void SetAverageBits(int bits);
|
|
|
|
|
int GetAverageBits() const;
|
|
|
|
|
void SetOversampleBits(int bits);
|
|
|
|
|
int GetOversampleBits() const;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetLSBWeight() const;
|
|
|
|
|
int 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();
|
2016-09-06 00:01:45 -07:00
|
|
|
void SetAccumulatorCenter(int center);
|
|
|
|
|
void SetAccumulatorDeadband(int deadband);
|
2015-06-25 15:07:55 -04:00
|
|
|
int64_t GetAccumulatorValue() const;
|
2016-07-12 10:45:14 -07:00
|
|
|
int64_t GetAccumulatorCount() const;
|
|
|
|
|
void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
|
2014-05-02 17:54:01 -04:00
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
static void SetSampleRate(double samplesPerSecond);
|
|
|
|
|
static double GetSampleRate();
|
2014-07-21 16:32:36 -04:00
|
|
|
|
Revert changes preventing old user code from compiling.
I'm not 100% sure whether we want these, but they are a quick
find and replace to do.
Basically, there are two primary things that we have done
this summer that break existing user code:
-Changing GetInstance() calls to return references instead
of pointers. This forces users to change from doing something
like LiveWindow::GetInstance()->AddSensor() to LiveWindow::GetInstance().AddSensor().
-Making PIDGet() and related calls const, forcing users to change
the function signatures wherever they override them.
The GetInstance() calls don't really matter to me either way,
especially since there are no real ownership issues going on there,
unlike the rest of the smart pointer-related changes.
For the const stuff, it is certainly more correct to mandate that
user PIDGet() functions be const and the such, but at the same time,
I'm not sure that there is any strong need for it, and the errors
generated are not the most helpful. While this wouldn't necessarily
be an issue for more experienced teams or completely new teams (who
don't have any old code to be reusing), it may cause issues for more
average teams who aren't familiar with the intricacies of C++ anything.
Change-Id: I6e7007982069292ea70e6d0fc8ca40203340df1b
2015-07-24 19:19:40 -04:00
|
|
|
double PIDGet() 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;
|
2015-07-29 16:48:04 -04:00
|
|
|
void InitTable(std::shared_ptr<ITable> subTable) override;
|
|
|
|
|
std::shared_ptr<ITable> GetTable() const override;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2016-09-06 00:01:45 -07:00
|
|
|
int m_channel;
|
2016-05-20 17:30:37 -07:00
|
|
|
// TODO: Adjust HAL to avoid use of raw pointers.
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_AnalogInputHandle m_port;
|
2015-06-25 15:07:55 -04:00
|
|
|
int64_t m_accumulatorOffset;
|
2014-05-02 17:54:01 -04:00
|
|
|
|
2015-11-23 00:46:05 -08:00
|
|
|
std::shared_ptr<ITable> m_table;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|