WPILibC++  2020.3.2-60-g3011ebe
AnalogAccelerometer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 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 
12 #include "frc/AnalogInput.h"
13 #include "frc/ErrorBase.h"
14 #include "frc/PIDSource.h"
15 #include "frc/smartdashboard/Sendable.h"
16 #include "frc/smartdashboard/SendableHelper.h"
17 
18 namespace frc {
19 
20 class SendableBuilder;
21 
30  public PIDSource,
31  public Sendable,
32  public SendableHelper<AnalogAccelerometer> {
33  public:
42  explicit AnalogAccelerometer(int channel);
43 
54  explicit AnalogAccelerometer(AnalogInput* channel);
55 
66  explicit AnalogAccelerometer(std::shared_ptr<AnalogInput> channel);
67 
68  ~AnalogAccelerometer() override = default;
69 
71  AnalogAccelerometer& operator=(AnalogAccelerometer&&) = default;
72 
80  double GetAcceleration() const;
81 
91  void SetSensitivity(double sensitivity);
92 
101  void SetZero(double zero);
102 
108  double PIDGet() override;
109 
110  void InitSendable(SendableBuilder& builder) override;
111 
112  private:
116  void InitAccelerometer();
117 
118  std::shared_ptr<AnalogInput> m_analogInput;
119  double m_voltsPerG = 1.0;
120  double m_zeroGVoltage = 2.5;
121 };
122 
123 } // namespace frc
frc::PIDSource
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
frc::AnalogAccelerometer
Handle operation of an analog accelerometer.
Definition: AnalogAccelerometer.h:29
frc::AnalogAccelerometer::PIDGet
double PIDGet() override
Get the Acceleration for the PID Source parent.
frc::AnalogAccelerometer::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
frc::AnalogAccelerometer::SetSensitivity
void SetSensitivity(double sensitivity)
Set the accelerometer sensitivity.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::AnalogAccelerometer::SetZero
void SetZero(double zero)
Set the voltage that corresponds to 0 G.
frc::AnalogInput
Analog input class.
Definition: AnalogInput.h:37
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::AnalogAccelerometer::AnalogAccelerometer
AnalogAccelerometer(int channel)
Create a new instance of an accelerometer.
frc::AnalogAccelerometer::GetAcceleration
double GetAcceleration() const
Return the acceleration in Gs.
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23