Add ADXRS450_Gyro.

This is a digital gyro interfaced via SPI.  Uses the HAL SPI accumulator.

Basic code function successfully tested on a ADXRS453.

Change-Id: Ibc0c7db9964c041fb1e04af4db17e3310ea83c04
This commit is contained in:
Peter Johnson
2015-11-06 14:49:28 -08:00
parent 6851dee3f6
commit bd2a28f597
4 changed files with 371 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "GyroBase.h"
#include "Notifier.h"
#include "SPI.h"
#include "HAL/cpp/priority_mutex.h"
#include <memory>
/**
* Use a rate gyro to return the robots heading relative to a starting position.
* The Gyro class tracks the robots heading based on the starting position. As
* the robot rotates the new heading is computed by integrating the rate of
* rotation returned by the sensor. When the class is instantiated, it does a
* short calibration routine where it samples the gyro while at rest to
* determine the default offset. This is subtracted from each sample to
* determine the heading.
*
* This class is for the digital ADXRS450 gyro sensor that connects via SPI.
*/
class ADXRS450_Gyro : public GyroBase {
public:
ADXRS450_Gyro();
explicit ADXRS450_Gyro(SPI::Port port);
virtual ~ADXRS450_Gyro() = default;
float GetAngle() const override;
double GetRate() const override;
void Reset() override;
void Calibrate() override;
std::string GetSmartDashboardType() const override;
private:
SPI m_spi;
uint16_t ReadRegister(uint8_t reg);
};

View File

@@ -14,6 +14,7 @@
#include "ADXL345_I2C.h"
#include "ADXL345_SPI.h"
#include "ADXL362.h"
#include "ADXRS450_Gyro.h"
#include "AnalogAccelerometer.h"
#include "AnalogGyro.h"
#include "AnalogInput.h"