2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
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
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
#include <wpi/sendable/Sendable.h>
|
|
|
|
|
#include <wpi/sendable/SendableHelper.h>
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/AnalogInput.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2014-06-13 17:45:10 -04:00
|
|
|
/**
|
2014-07-22 18:04:00 -04:00
|
|
|
* Handle operation of an analog accelerometer.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The accelerometer reads acceleration directly through the sensor. Many
|
2016-05-20 17:30:37 -07:00
|
|
|
* sensors have multiple axis and can be treated as multiple devices. Each is
|
|
|
|
|
* calibrated by finding the center value over a period of time.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2021-06-13 16:38:05 -07:00
|
|
|
class AnalogAccelerometer : public wpi::Sendable,
|
|
|
|
|
public wpi::SendableHelper<AnalogAccelerometer> {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Create a new instance of an accelerometer.
|
|
|
|
|
*
|
|
|
|
|
* The constructor allocates desired analog input.
|
|
|
|
|
*
|
|
|
|
|
* @param channel The channel number for the analog input the accelerometer is
|
|
|
|
|
* connected to
|
|
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
explicit AnalogAccelerometer(int channel);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new instance of Accelerometer from an existing AnalogInput.
|
|
|
|
|
*
|
|
|
|
|
* Make a new instance of accelerometer given an AnalogInput. This is
|
|
|
|
|
* particularly useful if the port is going to be read as an analog channel as
|
|
|
|
|
* well as through the Accelerometer class.
|
|
|
|
|
*
|
|
|
|
|
* @param channel The existing AnalogInput object for the analog input the
|
|
|
|
|
* accelerometer is connected to
|
|
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
explicit AnalogAccelerometer(AnalogInput* channel);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new instance of Accelerometer from an existing AnalogInput.
|
|
|
|
|
*
|
|
|
|
|
* Make a new instance of accelerometer given an AnalogInput. This is
|
|
|
|
|
* particularly useful if the port is going to be read as an analog channel as
|
|
|
|
|
* well as through the Accelerometer class.
|
|
|
|
|
*
|
|
|
|
|
* @param channel The existing AnalogInput object for the analog input the
|
|
|
|
|
* accelerometer is connected to
|
|
|
|
|
*/
|
2015-07-29 16:48:04 -04:00
|
|
|
explicit AnalogAccelerometer(std::shared_ptr<AnalogInput> channel);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
~AnalogAccelerometer() override = default;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
AnalogAccelerometer(AnalogAccelerometer&&) = default;
|
|
|
|
|
AnalogAccelerometer& operator=(AnalogAccelerometer&&) = default;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Return the acceleration in Gs.
|
|
|
|
|
*
|
|
|
|
|
* The acceleration is returned units of Gs.
|
|
|
|
|
*
|
|
|
|
|
* @return The current acceleration of the sensor in Gs.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetAcceleration() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the accelerometer sensitivity.
|
|
|
|
|
*
|
|
|
|
|
* This sets the sensitivity of the accelerometer used for calculating the
|
|
|
|
|
* acceleration. The sensitivity varies by accelerometer model. There are
|
|
|
|
|
* constants defined for various models.
|
|
|
|
|
*
|
|
|
|
|
* @param sensitivity The sensitivity of accelerometer in Volts per G.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void SetSensitivity(double sensitivity);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the voltage that corresponds to 0 G.
|
|
|
|
|
*
|
|
|
|
|
* The zero G voltage varies by accelerometer model. There are constants
|
|
|
|
|
* defined for various models.
|
|
|
|
|
*
|
|
|
|
|
* @param zero The zero G voltage.
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
void SetZero(double zero);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
void InitSendable(wpi::SendableBuilder& builder) override;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Common function for initializing the accelerometer.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void InitAccelerometer();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<AnalogInput> m_analogInput;
|
2016-11-20 07:25:03 -08:00
|
|
|
double m_voltsPerG = 1.0;
|
|
|
|
|
double m_zeroGVoltage = 2.5;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|