mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[hal, wpilib] Remove analog accumulator and analog gyro (#7697)
The 2 high level classes were temporarily kept to keep the examples compiling. We will remove those when we have the interface into the built in IMU.
This commit is contained in:
@@ -1,143 +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/AnalogGyro.h"
|
||||
|
||||
#include <climits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <hal/AnalogGyro.h>
|
||||
#include <hal/Errors.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <wpi/NullDeleter.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/AnalogInput.h"
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
AnalogGyro::AnalogGyro(int channel)
|
||||
: AnalogGyro(std::make_shared<AnalogInput>(channel)) {
|
||||
wpi::SendableRegistry::AddChild(this, m_analog.get());
|
||||
}
|
||||
|
||||
AnalogGyro::AnalogGyro(AnalogInput* channel)
|
||||
: AnalogGyro(std::shared_ptr<AnalogInput>(
|
||||
channel, wpi::NullDeleter<AnalogInput>())) {}
|
||||
|
||||
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel)
|
||||
: m_analog(channel) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
InitGyro();
|
||||
Calibrate();
|
||||
}
|
||||
|
||||
AnalogGyro::AnalogGyro(int channel, int center, double offset)
|
||||
: AnalogGyro(std::make_shared<AnalogInput>(channel), center, offset) {
|
||||
wpi::SendableRegistry::AddChild(this, m_analog.get());
|
||||
}
|
||||
|
||||
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
|
||||
double offset)
|
||||
: m_analog(channel) {
|
||||
if (!channel) {
|
||||
throw FRC_MakeError(err::NullParameter, "channel");
|
||||
}
|
||||
InitGyro();
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
|
||||
offset, center, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
Reset();
|
||||
}
|
||||
|
||||
double AnalogGyro::GetAngle() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetRate() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
int AnalogGyro::GetCenter() const {
|
||||
int32_t status = 0;
|
||||
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetOffset() const {
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
return value;
|
||||
}
|
||||
|
||||
void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle,
|
||||
voltsPerDegreePerSecond, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::SetDeadband(double volts) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::Reset() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetAnalogGyro(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::InitGyro() {
|
||||
if (m_gyroHandle == HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_gyroHandle =
|
||||
HAL_InitializeAnalogGyro(m_analog->m_port, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
HAL_SetupAnalogGyro(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel() + 1);
|
||||
|
||||
wpi::SendableRegistry::AddLW(this, "AnalogGyro", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
void AnalogGyro::Calibrate() {
|
||||
int32_t status = 0;
|
||||
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
|
||||
}
|
||||
|
||||
Rotation2d AnalogGyro::GetRotation2d() const {
|
||||
return units::degree_t{-GetAngle()};
|
||||
}
|
||||
|
||||
std::shared_ptr<AnalogInput> AnalogGyro::GetAnalogInput() const {
|
||||
return m_analog;
|
||||
}
|
||||
|
||||
void AnalogGyro::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Gyro");
|
||||
builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr);
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <hal/AnalogAccumulator.h>
|
||||
#include <hal/AnalogInput.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/HALBase.h>
|
||||
@@ -111,70 +110,6 @@ int AnalogInput::GetOffset() const {
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool AnalogInput::IsAccumulatorChannel() const {
|
||||
int32_t status = 0;
|
||||
bool isAccum = HAL_IsAccumulatorChannel(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return isAccum;
|
||||
}
|
||||
|
||||
void AnalogInput::InitAccumulator() {
|
||||
m_accumulatorOffset = 0;
|
||||
int32_t status = 0;
|
||||
HAL_InitAccumulator(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
|
||||
m_accumulatorOffset = initialValue;
|
||||
}
|
||||
|
||||
void AnalogInput::ResetAccumulator() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetAccumulator(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
|
||||
// Wait until the next sample, so the next call to GetAccumulator*()
|
||||
// won't have old values.
|
||||
const double sampleTime = 1.0 / GetSampleRate();
|
||||
const double overSamples = 1 << GetOversampleBits();
|
||||
const double averageSamples = 1 << GetAverageBits();
|
||||
Wait(units::second_t{sampleTime * overSamples * averageSamples});
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorCenter(int center) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorCenter(m_port, center, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
void AnalogInput::SetAccumulatorDeadband(int deadband) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAccumulatorDeadband(m_port, deadband, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
int32_t status = 0;
|
||||
int64_t value = HAL_GetAccumulatorValue(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return value + m_accumulatorOffset;
|
||||
}
|
||||
|
||||
int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
int32_t status = 0;
|
||||
int64_t count = HAL_GetAccumulatorCount(m_port, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
return count;
|
||||
}
|
||||
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
int32_t status = 0;
|
||||
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
|
||||
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
|
||||
value += m_accumulatorOffset;
|
||||
}
|
||||
|
||||
void AnalogInput::SetSampleRate(double samplesPerSecond) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogSampleRate(samplesPerSecond, &status);
|
||||
|
||||
@@ -1,75 +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/simulation/AnalogGyroSim.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <hal/simulation/AnalogGyroData.h>
|
||||
|
||||
#include "frc/AnalogGyro.h"
|
||||
#include "frc/AnalogInput.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
AnalogGyroSim::AnalogGyroSim(const AnalogGyro& gyro)
|
||||
: m_index{gyro.GetAnalogInput()->GetChannel()} {}
|
||||
|
||||
AnalogGyroSim::AnalogGyroSim(int channel) : m_index{channel} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterAngleCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogGyroAngleCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogGyroAngleCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double AnalogGyroSim::GetAngle() const {
|
||||
return HALSIM_GetAnalogGyroAngle(m_index);
|
||||
}
|
||||
|
||||
void AnalogGyroSim::SetAngle(double angle) {
|
||||
HALSIM_SetAnalogGyroAngle(m_index, angle);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterRateCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogGyroRateCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogGyroRateCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double AnalogGyroSim::GetRate() const {
|
||||
return HALSIM_GetAnalogGyroRate(m_index);
|
||||
}
|
||||
|
||||
void AnalogGyroSim::SetRate(double rate) {
|
||||
HALSIM_SetAnalogGyroRate(m_index, rate);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogGyroInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogGyroInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool AnalogGyroSim::GetInitialized() const {
|
||||
return HALSIM_GetAnalogGyroInitialized(m_index);
|
||||
}
|
||||
|
||||
void AnalogGyroSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetAnalogGyroInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
void AnalogGyroSim::ResetData() {
|
||||
HALSIM_ResetAnalogGyroData(m_index);
|
||||
}
|
||||
@@ -86,95 +86,6 @@ void AnalogInputSim::SetVoltage(double voltage) {
|
||||
HALSIM_SetAnalogInVoltage(m_index, voltage);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
AnalogInputSim::RegisterAccumulatorInitializedCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback,
|
||||
&HALSIM_CancelAnalogInAccumulatorInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool AnalogInputSim::GetAccumulatorInitialized() const {
|
||||
return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
|
||||
}
|
||||
|
||||
void AnalogInputSim::SetAccumulatorInitialized(bool accumulatorInitialized) {
|
||||
HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAccumulatorValueCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int64_t AnalogInputSim::GetAccumulatorValue() const {
|
||||
return HALSIM_GetAnalogInAccumulatorValue(m_index);
|
||||
}
|
||||
|
||||
void AnalogInputSim::SetAccumulatorValue(int64_t accumulatorValue) {
|
||||
HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAccumulatorCountCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int64_t AnalogInputSim::GetAccumulatorCount() const {
|
||||
return HALSIM_GetAnalogInAccumulatorCount(m_index);
|
||||
}
|
||||
|
||||
void AnalogInputSim::SetAccumulatorCount(int64_t accumulatorCount) {
|
||||
HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
AnalogInputSim::RegisterAccumulatorCenterCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int AnalogInputSim::GetAccumulatorCenter() const {
|
||||
return HALSIM_GetAnalogInAccumulatorCenter(m_index);
|
||||
}
|
||||
|
||||
void AnalogInputSim::SetAccumulatorCenter(int accumulatorCenter) {
|
||||
HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
AnalogInputSim::RegisterAccumulatorDeadbandCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
|
||||
store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
int AnalogInputSim::GetAccumulatorDeadband() const {
|
||||
return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
|
||||
}
|
||||
|
||||
void AnalogInputSim::SetAccumulatorDeadband(int accumulatorDeadband) {
|
||||
HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
|
||||
}
|
||||
|
||||
void AnalogInputSim::ResetData() {
|
||||
HALSIM_ResetAnalogInData(m_index);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <hal/AnalogGyro.h>
|
||||
#include <hal/Types.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
@@ -33,19 +32,13 @@ class AnalogInput;
|
||||
class AnalogGyro : public wpi::Sendable,
|
||||
public wpi::SendableHelper<AnalogGyro> {
|
||||
public:
|
||||
static constexpr int kOversampleBits = 10;
|
||||
static constexpr int kAverageBits = 0;
|
||||
static constexpr double kSamplesPerSecond = 50.0;
|
||||
static constexpr double kCalibrationSampleTime = 5.0;
|
||||
static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
|
||||
/**
|
||||
* %Gyro constructor using the Analog Input channel number.
|
||||
*
|
||||
* @param channel The analog channel the gyro is connected to. Gyros can only
|
||||
* be used on on-board Analog Inputs 0-1.
|
||||
*/
|
||||
explicit AnalogGyro(int channel);
|
||||
explicit AnalogGyro(int channel) {}
|
||||
|
||||
/**
|
||||
* Gyro constructor with a precreated AnalogInput object.
|
||||
@@ -59,7 +52,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* @param channel A pointer to the AnalogInput object that the gyro is
|
||||
* connected to.
|
||||
*/
|
||||
explicit AnalogGyro(AnalogInput* channel);
|
||||
explicit AnalogGyro(AnalogInput* channel) {}
|
||||
|
||||
/**
|
||||
* %Gyro constructor with a precreated AnalogInput object.
|
||||
@@ -71,7 +64,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* @param channel A pointer to the AnalogInput object that the gyro is
|
||||
* connected to.
|
||||
*/
|
||||
explicit AnalogGyro(std::shared_ptr<AnalogInput> channel);
|
||||
explicit AnalogGyro(std::shared_ptr<AnalogInput> channel) {}
|
||||
|
||||
/**
|
||||
* %Gyro constructor using the Analog Input channel number with parameters for
|
||||
@@ -83,7 +76,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* value.
|
||||
* @param offset Preset uncalibrated value to use as the gyro offset.
|
||||
*/
|
||||
AnalogGyro(int channel, int center, double offset);
|
||||
AnalogGyro(int channel, int center, double offset) {}
|
||||
|
||||
/**
|
||||
* %Gyro constructor with a precreated AnalogInput object and calibrated
|
||||
@@ -99,7 +92,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* value.
|
||||
* @param offset Preset uncalibrated value to use as the gyro offset.
|
||||
*/
|
||||
AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
|
||||
AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset) {}
|
||||
|
||||
AnalogGyro(AnalogGyro&& rhs) = default;
|
||||
AnalogGyro& operator=(AnalogGyro&& rhs) = default;
|
||||
@@ -118,7 +111,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* @return The current heading of the robot in degrees. This heading is based
|
||||
* on integration of the returned rate from the gyro.
|
||||
*/
|
||||
double GetAngle() const;
|
||||
double GetAngle() const { return 0; }
|
||||
|
||||
/**
|
||||
* Return the rate of rotation of the gyro
|
||||
@@ -127,7 +120,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
*
|
||||
* @return the current rate in degrees per second
|
||||
*/
|
||||
double GetRate() const;
|
||||
double GetRate() const { return 0; }
|
||||
|
||||
/**
|
||||
* Return the gyro center value. If run after calibration,
|
||||
@@ -135,7 +128,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
*
|
||||
* @return the current center value
|
||||
*/
|
||||
virtual int GetCenter() const;
|
||||
virtual int GetCenter() const { return 0; }
|
||||
|
||||
/**
|
||||
* Return the gyro offset value. If run after calibration,
|
||||
@@ -143,7 +136,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
*
|
||||
* @return the current offset value
|
||||
*/
|
||||
virtual double GetOffset() const;
|
||||
virtual double GetOffset() const { return 0; }
|
||||
|
||||
/**
|
||||
* Set the gyro sensitivity.
|
||||
@@ -154,7 +147,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
*
|
||||
* @param voltsPerDegreePerSecond The sensitivity in Volts/degree/second
|
||||
*/
|
||||
void SetSensitivity(double voltsPerDegreePerSecond);
|
||||
void SetSensitivity(double voltsPerDegreePerSecond) {}
|
||||
|
||||
/**
|
||||
* Set the size of the neutral zone.
|
||||
@@ -165,7 +158,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
*
|
||||
* @param volts The size of the deadband in volts
|
||||
*/
|
||||
void SetDeadband(double volts);
|
||||
void SetDeadband(double volts) {}
|
||||
|
||||
/**
|
||||
* Reset the gyro.
|
||||
@@ -174,14 +167,14 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* significant drift in the gyro and it needs to be recalibrated after it has
|
||||
* been running.
|
||||
*/
|
||||
void Reset();
|
||||
void Reset() {}
|
||||
|
||||
/**
|
||||
* Initialize the gyro.
|
||||
*
|
||||
* Calibration is handled by Calibrate().
|
||||
*/
|
||||
void InitGyro();
|
||||
void InitGyro() {}
|
||||
|
||||
/**
|
||||
* Calibrate the gyro by running for a number of samples and computing the
|
||||
@@ -193,7 +186,7 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* robot is first turned on while it's sitting at rest before the competition
|
||||
* starts.
|
||||
*/
|
||||
void Calibrate();
|
||||
void Calibrate() {}
|
||||
|
||||
/**
|
||||
* Return the heading of the robot as a Rotation2d.
|
||||
@@ -208,20 +201,16 @@ class AnalogGyro : public wpi::Sendable,
|
||||
* @return the current heading of the robot as a Rotation2d. This heading is
|
||||
* based on integration of the returned rate from the gyro.
|
||||
*/
|
||||
Rotation2d GetRotation2d() const;
|
||||
Rotation2d GetRotation2d() const { return {}; }
|
||||
|
||||
/**
|
||||
* Gets the analog input for the gyro.
|
||||
*
|
||||
* @return AnalogInput
|
||||
*/
|
||||
std::shared_ptr<AnalogInput> GetAnalogInput() const;
|
||||
std::shared_ptr<AnalogInput> GetAnalogInput() const { return nullptr; }
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AnalogInput> m_analog;
|
||||
hal::Handle<HAL_GyroHandle, HAL_FreeAnalogGyro> m_gyroHandle;
|
||||
void InitSendable(wpi::SendableBuilder& builder) override {}
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -31,15 +31,10 @@ class DMASample;
|
||||
class AnalogInput : public wpi::Sendable,
|
||||
public wpi::SendableHelper<AnalogInput> {
|
||||
friend class AnalogTrigger;
|
||||
friend class AnalogGyro;
|
||||
friend class DMA;
|
||||
friend class DMASample;
|
||||
|
||||
public:
|
||||
static constexpr int kAccumulatorModuleNumber = 1;
|
||||
static constexpr int kAccumulatorNumChannels = 2;
|
||||
static constexpr int kAccumulatorChannels[kAccumulatorNumChannels] = {0, 1};
|
||||
|
||||
/**
|
||||
* Construct an analog input.
|
||||
*
|
||||
@@ -182,81 +177,6 @@ class AnalogInput : public wpi::Sendable,
|
||||
*/
|
||||
int GetOffset() const;
|
||||
|
||||
/**
|
||||
* Is the channel attached to an accumulator.
|
||||
*
|
||||
* @return The analog input is attached to an accumulator.
|
||||
*/
|
||||
bool IsAccumulatorChannel() const;
|
||||
|
||||
/**
|
||||
* Initialize the accumulator.
|
||||
*/
|
||||
void InitAccumulator();
|
||||
|
||||
/**
|
||||
* Set an initial value for the accumulator.
|
||||
*
|
||||
* This will be added to all values returned to the user.
|
||||
*
|
||||
* @param value The value that the accumulator should start from when reset.
|
||||
*/
|
||||
void SetAccumulatorInitialValue(int64_t value);
|
||||
|
||||
/**
|
||||
* Resets the accumulator to the initial value.
|
||||
*/
|
||||
void ResetAccumulator();
|
||||
|
||||
/**
|
||||
* Set the center value of the accumulator.
|
||||
*
|
||||
* The center value is subtracted from each A/D value before it is added to
|
||||
* the accumulator. This is used for the center value of devices like gyros
|
||||
* and accelerometers to take the device offset into account when integrating.
|
||||
*
|
||||
* This center value is based on the output of the oversampled and averaged
|
||||
* source from the accumulator channel. Because of this, any non-zero
|
||||
* oversample bits will affect the size of the value for this field.
|
||||
*/
|
||||
void SetAccumulatorCenter(int center);
|
||||
|
||||
/**
|
||||
* Set the accumulator's deadband.
|
||||
*/
|
||||
void SetAccumulatorDeadband(int deadband);
|
||||
|
||||
/**
|
||||
* Read the accumulated value.
|
||||
*
|
||||
* Read the value that has been accumulating.
|
||||
* The accumulator is attached after the oversample and average engine.
|
||||
*
|
||||
* @return The 64-bit value accumulated since the last Reset().
|
||||
*/
|
||||
int64_t GetAccumulatorValue() const;
|
||||
|
||||
/**
|
||||
* Read the number of accumulated values.
|
||||
*
|
||||
* Read the count of the accumulated values since the accumulator was last
|
||||
* Reset().
|
||||
*
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
int64_t GetAccumulatorCount() const;
|
||||
|
||||
/**
|
||||
* Read the accumulated value and the number of accumulated values atomically.
|
||||
*
|
||||
* This function reads the value and count from the FPGA atomically.
|
||||
* This can be used for averaging.
|
||||
*
|
||||
* @param value Reference to the 64-bit accumulated output.
|
||||
* @param count Reference to the number of accumulation cycles.
|
||||
*/
|
||||
void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
|
||||
|
||||
/**
|
||||
* Set the sample rate per channel for all analog channels.
|
||||
*
|
||||
@@ -286,7 +206,6 @@ class AnalogInput : public wpi::Sendable,
|
||||
private:
|
||||
int m_channel;
|
||||
hal::Handle<HAL_AnalogInputHandle, HAL_FreeAnalogInputPort> m_port;
|
||||
int64_t m_accumulatorOffset;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -1,121 +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 <memory>
|
||||
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class AnalogGyro;
|
||||
|
||||
namespace sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog gyro.
|
||||
*/
|
||||
class AnalogGyroSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs from an AnalogGyro object.
|
||||
*
|
||||
* @param gyro AnalogGyro to simulate
|
||||
*/
|
||||
explicit AnalogGyroSim(const AnalogGyro& gyro);
|
||||
|
||||
/**
|
||||
* Constructs from an analog input channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
explicit AnalogGyroSim(int channel);
|
||||
|
||||
/**
|
||||
* Register a callback on the angle.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the angle changes
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterAngleCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the current angle of the gyro.
|
||||
*
|
||||
* @return the angle measured by the gyro
|
||||
*/
|
||||
double GetAngle() const;
|
||||
|
||||
/**
|
||||
* Change the angle measured by the gyro.
|
||||
*
|
||||
* @param angle the new value
|
||||
*/
|
||||
void SetAngle(double angle);
|
||||
|
||||
/**
|
||||
* Register a callback on the rate.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the rate changes
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterRateCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the rate of angle change on this gyro.
|
||||
*
|
||||
* @return the rate
|
||||
*/
|
||||
double GetRate() const;
|
||||
|
||||
/**
|
||||
* Change the rate of the gyro.
|
||||
*
|
||||
* @param rate the new rate
|
||||
*/
|
||||
void SetRate(double rate);
|
||||
|
||||
/**
|
||||
* Register a callback on whether the gyro is initialized.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the gyro is
|
||||
* initialized
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if the gyro is initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetInitialized() const;
|
||||
|
||||
/**
|
||||
* Set whether this gyro is initialized.
|
||||
*
|
||||
* @param initialized the new value
|
||||
*/
|
||||
void SetInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Reset all simulation data for this object.
|
||||
*/
|
||||
void ResetData();
|
||||
|
||||
private:
|
||||
int m_index;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -137,136 +137,6 @@ class AnalogInputSim {
|
||||
*/
|
||||
void SetVoltage(double voltage);
|
||||
|
||||
/**
|
||||
* Register a callback on whether the accumulator is initialized.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the accumulator
|
||||
* is initialized
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if the accumulator has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetAccumulatorInitialized() const;
|
||||
|
||||
/**
|
||||
* Change whether the accumulator has been initialized.
|
||||
*
|
||||
* @param accumulatorInitialized the new value
|
||||
*/
|
||||
void SetAccumulatorInitialized(bool accumulatorInitialized);
|
||||
|
||||
/**
|
||||
* Register a callback on the accumulator value.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the accumulator
|
||||
* value is changed
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the accumulator value.
|
||||
*
|
||||
* @return the accumulator value
|
||||
*/
|
||||
int64_t GetAccumulatorValue() const;
|
||||
|
||||
/**
|
||||
* Change the accumulator value.
|
||||
*
|
||||
* @param accumulatorValue the new value
|
||||
*/
|
||||
void SetAccumulatorValue(int64_t accumulatorValue);
|
||||
|
||||
/**
|
||||
* Register a callback on the accumulator count.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the accumulator
|
||||
* count is changed
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the accumulator count.
|
||||
*
|
||||
* @return the accumulator count.
|
||||
*/
|
||||
int64_t GetAccumulatorCount() const;
|
||||
|
||||
/**
|
||||
* Change the accumulator count.
|
||||
*
|
||||
* @param accumulatorCount the new count.
|
||||
*/
|
||||
void SetAccumulatorCount(int64_t accumulatorCount);
|
||||
|
||||
/**
|
||||
* Register a callback on the accumulator center.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the accumulator
|
||||
* center is changed
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the accumulator center.
|
||||
*
|
||||
* @return the accumulator center
|
||||
*/
|
||||
int GetAccumulatorCenter() const;
|
||||
|
||||
/**
|
||||
* Change the accumulator center.
|
||||
*
|
||||
* @param accumulatorCenter the new center
|
||||
*/
|
||||
void SetAccumulatorCenter(int accumulatorCenter);
|
||||
|
||||
/**
|
||||
* Register a callback on the accumulator deadband.
|
||||
*
|
||||
* @param callback the callback that will be called whenever the accumulator
|
||||
* deadband is changed
|
||||
* @param initialNotify if true, the callback will be run on the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the accumulator deadband.
|
||||
*
|
||||
* @return the accumulator deadband
|
||||
*/
|
||||
int GetAccumulatorDeadband() const;
|
||||
|
||||
/**
|
||||
* Change the accumulator deadband.
|
||||
*
|
||||
* @param accumulatorDeadband the new deadband
|
||||
*/
|
||||
void SetAccumulatorDeadband(int accumulatorDeadband);
|
||||
|
||||
/**
|
||||
* Reset all simulation data for this object.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user