blob: ad6d6ddf63ef1861fc611cbedd91aeb21d2975ba [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7#pragma once
8
9#include "AnalogInput.h"
10#include "SensorBase.h"
11#include "PIDSource.h"
12#include "LiveWindow/LiveWindowSendable.h"
13
14#include <memory>
15
16/**
17 * Handle operation of an analog accelerometer.
18 * The accelerometer reads acceleration directly through the sensor. Many
19 * sensors have
20 * multiple axis and can be treated as multiple devices. Each is calibrated by
21 * finding
22 * the center value over a period of time.
23 */
24class AnalogAccelerometer : public SensorBase,
25 public PIDSource,
26 public LiveWindowSendable {
27 public:
28 explicit AnalogAccelerometer(int32_t channel);
29 explicit AnalogAccelerometer(AnalogInput *channel);
30 explicit AnalogAccelerometer(std::shared_ptr<AnalogInput> channel);
31 virtual ~AnalogAccelerometer() = default;
32
33 float GetAcceleration() const;
34 void SetSensitivity(float sensitivity);
35 void SetZero(float zero);
36 double PIDGet() override;
37
38 void UpdateTable() override;
39 void StartLiveWindowMode() override;
40 void StopLiveWindowMode() override;
41 std::string GetSmartDashboardType() const override;
42 void InitTable(std::shared_ptr<ITable> subTable) override;
43 std::shared_ptr<ITable> GetTable() const override;
44
45 private:
46 void InitAccelerometer();
47
48 std::shared_ptr<AnalogInput> m_analogInput;
49 float m_voltsPerG = 1.0;
50 float m_zeroGVoltage = 2.5;
51
52 std::shared_ptr<ITable> m_table;
53};