[wpilib] Remove GyroBase

This commit is contained in:
Peter Johnson
2021-03-12 15:52:02 -08:00
parent 6b168ab0c8
commit 687066af3d
12 changed files with 78 additions and 73 deletions

View File

@@ -8,6 +8,7 @@
#include "frc/DriverStation.h"
#include "frc/Timer.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -134,3 +135,9 @@ void ADXRS450_Gyro::Calibrate() {
int ADXRS450_Gyro::GetPort() const {
return m_port;
}
void ADXRS450_Gyro::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Gyro");
builder.AddDoubleProperty(
"Value", [=]() { return GetAngle(); }, nullptr);
}

View File

@@ -15,6 +15,7 @@
#include "frc/Base.h"
#include "frc/Timer.h"
#include "frc/WPIErrors.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -180,3 +181,9 @@ void AnalogGyro::Calibrate() {
std::shared_ptr<AnalogInput> AnalogGyro::GetAnalogInput() const {
return m_analog;
}
void AnalogGyro::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Gyro");
builder.AddDoubleProperty(
"Value", [=]() { return GetAngle(); }, nullptr);
}

View File

@@ -1,16 +0,0 @@
// 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.
#include "frc/GyroBase.h"
#include "frc/WPIErrors.h"
#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
void GyroBase::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Gyro");
builder.AddDoubleProperty(
"Value", [=]() { return GetAngle(); }, nullptr);
}

View File

@@ -4,6 +4,8 @@
#include "frc/romi/RomiGyro.h"
#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
RomiGyro::RomiGyro() : m_simDevice("Gyro:RomiGyro") {
@@ -87,3 +89,9 @@ void RomiGyro::Reset() {
m_angleZOffset = m_simAngleZ.Get();
}
}
void RomiGyro::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Gyro");
builder.AddDoubleProperty(
"Value", [=]() { return GetAngle(); }, nullptr);
}

View File

@@ -8,8 +8,11 @@
#include <hal/SimDevice.h>
#include "frc/GyroBase.h"
#include "frc/ErrorBase.h"
#include "frc/SPI.h"
#include "frc/interfaces/Gyro.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -26,7 +29,10 @@ namespace frc {
* This class is for the digital ADXRS450 gyro sensor that connects via SPI.
* Only one instance of an ADXRS Gyro is supported.
*/
class ADXRS450_Gyro : public GyroBase {
class ADXRS450_Gyro : public Gyro,
public ErrorBase,
public Sendable,
public SendableHelper<ADXRS450_Gyro> {
public:
/**
* Gyro constructor on onboard CS0.
@@ -96,6 +102,8 @@ class ADXRS450_Gyro : public GyroBase {
*/
int GetPort() const;
void InitSendable(SendableBuilder& builder) override;
private:
SPI m_spi;
SPI::Port m_port;

View File

@@ -8,7 +8,8 @@
#include <hal/Types.h>
#include "frc/GyroBase.h"
#include "frc/ErrorBase.h"
#include "frc/interfaces/Gyro.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
@@ -29,7 +30,10 @@ class AnalogInput;
*
* This class is for gyro sensors that connect to an analog input.
*/
class AnalogGyro : public GyroBase {
class AnalogGyro : public Gyro,
public ErrorBase,
public Sendable,
public SendableHelper<AnalogGyro> {
public:
static constexpr int kOversampleBits = 10;
static constexpr int kAverageBits = 0;
@@ -190,6 +194,8 @@ class AnalogGyro : public GyroBase {
*/
std::shared_ptr<AnalogInput> GetAnalogInput() const;
void InitSendable(SendableBuilder& builder) override;
protected:
std::shared_ptr<AnalogInput> m_analog;

View File

@@ -1,30 +0,0 @@
// 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.
#pragma once
#include "frc/ErrorBase.h"
#include "frc/interfaces/Gyro.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
/**
* GyroBase is the common base class for Gyro implementations such as
* AnalogGyro.
*/
class GyroBase : public Gyro,
public ErrorBase,
public Sendable,
public SendableHelper<GyroBase> {
public:
GyroBase() = default;
GyroBase(GyroBase&&) = default;
GyroBase& operator=(GyroBase&&) = default;
void InitSendable(SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -6,7 +6,10 @@
#include <hal/SimDevice.h>
#include "frc/GyroBase.h"
#include "frc/ErrorBase.h"
#include "frc/interfaces/Gyro.h"
#include "frc/smartdashboard/Sendable.h"
#include "frc/smartdashboard/SendableHelper.h"
namespace frc {
@@ -16,7 +19,10 @@ namespace frc {
* This class is for the Romi onboard gyro, and will only work in
* simulation/Romi mode. Only one instance of a RomiGyro is supported.
*/
class RomiGyro : public GyroBase {
class RomiGyro : public Gyro,
public ErrorBase,
public Sendable,
public SendableHelper<RomiGyro> {
public:
RomiGyro();
@@ -84,6 +90,8 @@ class RomiGyro : public GyroBase {
*/
void Reset() override;
void InitSendable(SendableBuilder& builder) override;
private:
hal::SimDevice m_simDevice;
hal::SimDouble m_simRateX;

View File

@@ -9,6 +9,8 @@ import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -24,7 +26,7 @@ import java.nio.ByteOrder;
* an ADXRS Gyro is supported.
*/
@SuppressWarnings({"TypeName", "AbbreviationAsWordInName", "PMD.UnusedPrivateField"})
public class ADXRS450_Gyro extends GyroBase {
public class ADXRS450_Gyro implements Gyro, Sendable {
private static final double kSamplePeriod = 0.0005;
private static final double kCalibrationSampleTime = 5.0;
private static final double kDegreePerSecondPerLSB = 0.0125;
@@ -206,4 +208,10 @@ public class ADXRS450_Gyro extends GyroBase {
}
return m_spi.getAccumulatorLastValue() * kDegreePerSecondPerLSB;
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Gyro");
builder.addDoubleProperty("Value", this::getAngle, null);
}
}

View File

@@ -9,6 +9,8 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.hal.AnalogGyroJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
@@ -20,7 +22,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
*
* <p>This class is for gyro sensors that connect to an analog input.
*/
public class AnalogGyro extends GyroBase {
public class AnalogGyro implements Gyro, Sendable {
private static final double kDefaultVoltsPerDegreePerSecond = 0.007;
protected AnalogInput m_analog;
private boolean m_channelAllocated;
@@ -188,4 +190,10 @@ public class AnalogGyro extends GyroBase {
public AnalogInput getAnalogInput() {
return m_analog;
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Gyro");
builder.addDoubleProperty("Value", this::getAngle, null);
}
}

View File

@@ -1,17 +0,0 @@
// 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.
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
/** GyroBase is the common base class for Gyro implementations such as AnalogGyro. */
public abstract class GyroBase implements Gyro, Sendable {
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Gyro");
builder.addDoubleProperty("Value", this::getAngle, null);
}
}

View File

@@ -7,9 +7,11 @@ package edu.wpi.first.wpilibj.romi;
import edu.wpi.first.hal.SimDevice;
import edu.wpi.first.hal.SimDevice.Direction;
import edu.wpi.first.hal.SimDouble;
import edu.wpi.first.wpilibj.GyroBase;
import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.interfaces.Gyro;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
public class RomiGyro extends GyroBase {
public class RomiGyro implements Gyro, Sendable {
private final SimDevice m_simDevice;
private SimDouble m_simRateX;
private SimDouble m_simRateY;
@@ -146,4 +148,10 @@ public class RomiGyro extends GyroBase {
m_simDevice.close();
}
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Gyro");
builder.addDoubleProperty("Value", this::getAngle, null);
}
}