WPILibC++  unspecified
AnalogAccelerometer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2017 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 
13 #include "AnalogInput.h"
14 #include "LiveWindow/LiveWindowSendable.h"
15 #include "PIDSource.h"
16 #include "SensorBase.h"
17 #include "networktables/NetworkTableEntry.h"
18 
19 namespace frc {
20 
28  public PIDSource,
29  public LiveWindowSendable {
30  public:
31  explicit AnalogAccelerometer(int channel);
32  explicit AnalogAccelerometer(AnalogInput* channel);
33  explicit AnalogAccelerometer(std::shared_ptr<AnalogInput> channel);
34  virtual ~AnalogAccelerometer() = default;
35 
36  double GetAcceleration() const;
37  void SetSensitivity(double sensitivity);
38  void SetZero(double zero);
39  double PIDGet() override;
40 
41  void UpdateTable() override;
42  void StartLiveWindowMode() override;
43  void StopLiveWindowMode() override;
44  std::string GetSmartDashboardType() const override;
45  void InitTable(std::shared_ptr<nt::NetworkTable> subTable) override;
46 
47  private:
48  void InitAccelerometer();
49 
50  std::shared_ptr<AnalogInput> m_analogInput;
51  double m_voltsPerG = 1.0;
52  double m_zeroGVoltage = 2.5;
53 
54  nt::NetworkTableEntry m_valueEntry;
55 };
56 
57 } // namespace frc
Definition: Timer.cpp:18
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: AnalogAccelerometer.cpp:119
void SetSensitivity(double sensitivity)
Set the accelerometer sensitivity.
Definition: AnalogAccelerometer.cpp:98
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
Base class for all sensors.
Definition: SensorBase.h:20
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: AnalogAccelerometer.cpp:123
double GetAcceleration() const
Return the acceleration in Gs.
Definition: AnalogAccelerometer.cpp:85
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:19
void InitTable(std::shared_ptr< nt::NetworkTable > subTable) override
Initializes a table for this sendable object.
Definition: AnalogAccelerometer.cpp:131
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: AnalogAccelerometer.cpp:125
AnalogAccelerometer(int channel)
Create a new instance of an accelerometer.
Definition: AnalogAccelerometer.cpp:35
Handle operation of an analog accelerometer.
Definition: AnalogAccelerometer.h:27
std::string GetSmartDashboardType() const override
Definition: AnalogAccelerometer.cpp:127
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
double PIDGet() override
Get the Acceleration for the PID Source parent.
Definition: AnalogAccelerometer.cpp:117
void SetZero(double zero)
Set the voltage that corresponds to 0 G.
Definition: AnalogAccelerometer.cpp:110
Analog input class.
Definition: AnalogInput.h:36