[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:
Thad House
2025-01-17 12:58:31 -08:00
committed by GitHub
parent 92f0a3c961
commit f80874dd4b
76 changed files with 33 additions and 3886 deletions

View File

@@ -1,109 +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 "hal/AnalogAccumulator.h"
#include "AnalogInternal.h"
#include "mockdata/AnalogInDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeAnalogAccumulator() {}
} // namespace hal::init
extern "C" {
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
for (int32_t i = 0; i < kNumAccumulators; i++) {
if (port->channel == kAccumulatorChannels[i]) {
return true;
}
}
return false;
}
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (!HAL_IsAccumulatorChannel(analogPortHandle, status)) {
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
return;
}
SimAnalogInData[port->channel].accumulatorInitialized = true;
}
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogInData[port->channel].accumulatorCenter = 0;
SimAnalogInData[port->channel].accumulatorCount = 0;
SimAnalogInData[port->channel].accumulatorValue = 0;
}
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogInData[port->channel].accumulatorCenter = center;
}
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogInData[port->channel].accumulatorDeadband = deadband;
}
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return SimAnalogInData[port->channel].accumulatorValue;
}
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return SimAnalogInData[port->channel].accumulatorCount;
}
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
*count = SimAnalogInData[port->channel].accumulatorCount;
*value = SimAnalogInData[port->channel].accumulatorValue;
}
} // extern "C"

View File

@@ -1,151 +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 "hal/AnalogGyro.h"
#include <string>
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/AnalogAccumulator.h"
#include "hal/Errors.h"
#include "hal/handles/IndexedHandleResource.h"
#include "mockdata/AnalogGyroDataInternal.h"
namespace {
struct AnalogGyro {
HAL_AnalogInputHandle handle;
uint8_t index;
std::string previousAllocation;
};
} // namespace
using namespace hal;
static IndexedHandleResource<HAL_GyroHandle, AnalogGyro, kNumAccumulators,
HAL_HandleEnum::AnalogGyro>* analogGyroHandles;
namespace hal::init {
void InitializeAnalogGyro() {
static IndexedHandleResource<HAL_GyroHandle, AnalogGyro, kNumAccumulators,
HAL_HandleEnum::AnalogGyro>
agH;
analogGyroHandles = &agH;
}
} // namespace hal::init
extern "C" {
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle,
const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();
// Handle will be type checked by HAL_IsAccumulatorChannel
int16_t channel = getHandleIndex(analogHandle);
if (!HAL_IsAccumulatorChannel(analogHandle, status)) {
if (*status == 0) {
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Gyro",
0, kNumAccumulators, channel);
}
return HAL_kInvalidHandle;
}
HAL_GyroHandle handle;
auto gyro = analogGyroHandles->Allocate(channel, &handle, status);
if (*status != 0) {
if (gyro) {
hal::SetLastErrorPreviouslyAllocated(status, "Analog Gyro", channel,
gyro->previousAllocation);
} else {
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Analog Gyro",
0, kNumAccumulators, channel);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}
gyro->handle = analogHandle;
gyro->index = channel;
SimAnalogGyroData[channel].initialized = true;
gyro->previousAllocation = allocationLocation ? allocationLocation : "";
return handle;
}
void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
// No op
}
void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {
auto gyro = analogGyroHandles->Get(handle);
analogGyroHandles->Free(handle);
if (gyro == nullptr) {
return;
}
SimAnalogGyroData[gyro->index].initialized = false;
}
void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
double voltsPerDegreePerSecond, double offset,
int32_t center, int32_t* status) {
// No op
}
void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle,
double voltsPerDegreePerSecond,
int32_t* status) {
// No op
}
void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles->Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogGyroData[gyro->index].angle = 0.0;
}
void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
// Just do a reset
HAL_ResetAnalogGyro(handle, status);
}
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts,
int32_t* status) {
// No op
}
double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles->Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return SimAnalogGyroData[gyro->index].angle;
}
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
auto gyro = analogGyroHandles->Get(handle);
if (gyro == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return SimAnalogGyroData[gyro->index].rate;
}
double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) {
return 0.0;
}
int32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status) {
return 0;
}
} // extern "C"

View File

@@ -8,7 +8,6 @@
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/AnalogAccumulator.h"
#include "hal/handles/HandlesInternal.h"
#include "mockdata/AnalogInDataInternal.h"
@@ -46,14 +45,9 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
}
analog_port->channel = static_cast<uint8_t>(channel);
if (HAL_IsAccumulatorChannel(handle, status)) {
analog_port->isAccumulator = true;
} else {
analog_port->isAccumulator = false;
}
analog_port->isAccumulator = false;
SimAnalogInData[channel].initialized = true;
SimAnalogInData[channel].accumulatorInitialized = false;
SimAnalogInData[channel].simDevice = 0;
analog_port->previousAllocation =
@@ -69,7 +63,6 @@ void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
return;
}
SimAnalogInData[port->channel].initialized = false;
SimAnalogInData[port->channel].accumulatorInitialized = false;
}
HAL_Bool HAL_CheckAnalogModule(int32_t module) {

View File

@@ -68,7 +68,6 @@ namespace hal::init {
void InitializeHAL() {
InitializeAccelerometerData();
InitializeAddressableLEDData();
InitializeAnalogGyroData();
InitializeAnalogInData();
InitializeAnalogTriggerData();
InitializeCanData();
@@ -87,8 +86,6 @@ void InitializeHAL() {
InitializeSimDeviceData();
InitializeAccelerometer();
InitializeAddressableLED();
InitializeAnalogAccumulator();
InitializeAnalogGyro();
InitializeAnalogInput();
InitializeAnalogInternal();
InitializeAnalogTrigger();

View File

@@ -18,7 +18,6 @@ inline void CheckInit() {
extern void InitializeAccelerometerData();
extern void InitializeAddressableLEDData();
extern void InitializeAnalogGyroData();
extern void InitializeAnalogInData();
extern void InitializeAnalogTriggerData();
extern void InitializeCanData();
@@ -38,8 +37,6 @@ extern void InitializeRoboRioData();
extern void InitializeSimDeviceData();
extern void InitializeAccelerometer();
extern void InitializeAddressableLED();
extern void InitializeAnalogAccumulator();
extern void InitializeAnalogGyro();
extern void InitializeAnalogInput();
extern void InitializeAnalogInternal();
extern void InitializeAnalogTrigger();

View File

@@ -13,9 +13,6 @@ void InitializePorts() {}
} // namespace hal::init
extern "C" {
int32_t HAL_GetNumAccumulators(void) {
return kNumAccumulators;
}
int32_t HAL_GetNumAnalogTriggers(void) {
return kNumAnalogTriggers;
}

View File

@@ -1,48 +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 "../PortsInternal.h"
#include "AnalogGyroDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeAnalogGyroData() {
static AnalogGyroData agd[kNumAccumulators];
::hal::SimAnalogGyroData = agd;
}
} // namespace hal::init
AnalogGyroData* hal::SimAnalogGyroData;
void AnalogGyroData::ResetData() {
angle.Reset(0.0);
rate.Reset(0.0);
initialized.Reset(false);
}
extern "C" {
void HALSIM_ResetAnalogGyroData(int32_t index) {
SimAnalogGyroData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogGyro##CAPINAME, \
SimAnalogGyroData, LOWERNAME)
DEFINE_CAPI(double, Angle, angle)
DEFINE_CAPI(double, Rate, rate)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
#define REGISTER(NAME) \
SimAnalogGyroData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterAnalogGyroAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
REGISTER(angle);
REGISTER(rate);
REGISTER(initialized);
}
} // extern "C"

View File

@@ -1,25 +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 "hal/simulation/AnalogGyroData.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class AnalogGyroData {
HAL_SIMDATAVALUE_DEFINE_NAME(Angle)
HAL_SIMDATAVALUE_DEFINE_NAME(Rate)
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
public:
SimDataValue<double, HAL_MakeDouble, GetAngleName> angle{0.0};
SimDataValue<double, HAL_MakeDouble, GetRateName> rate{0.0};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
false};
virtual void ResetData();
};
extern AnalogGyroData* SimAnalogGyroData;
} // namespace hal

View File

@@ -21,11 +21,6 @@ void AnalogInData::ResetData() {
averageBits.Reset(7);
oversampleBits.Reset(0);
voltage.Reset(0.0);
accumulatorInitialized.Reset(false);
accumulatorValue.Reset(0);
accumulatorCount.Reset(0);
accumulatorCenter.Reset(0);
accumulatorDeadband.Reset(0);
}
extern "C" {
@@ -45,11 +40,6 @@ DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(int32_t, AverageBits, averageBits)
DEFINE_CAPI(int32_t, OversampleBits, oversampleBits)
DEFINE_CAPI(double, Voltage, voltage)
DEFINE_CAPI(HAL_Bool, AccumulatorInitialized, accumulatorInitialized)
DEFINE_CAPI(int64_t, AccumulatorValue, accumulatorValue)
DEFINE_CAPI(int64_t, AccumulatorCount, accumulatorCount)
DEFINE_CAPI(int32_t, AccumulatorCenter, accumulatorCenter)
DEFINE_CAPI(int32_t, AccumulatorDeadband, accumulatorDeadband)
#define REGISTER(NAME) \
SimAnalogInData[index].NAME.RegisterCallback(callback, param, initialNotify)
@@ -61,10 +51,5 @@ void HALSIM_RegisterAnalogInAllCallbacks(int32_t index,
REGISTER(averageBits);
REGISTER(oversampleBits);
REGISTER(voltage);
REGISTER(accumulatorInitialized);
REGISTER(accumulatorValue);
REGISTER(accumulatorCount);
REGISTER(accumulatorCenter);
REGISTER(accumulatorDeadband);
}
} // extern "C"

View File

@@ -13,11 +13,6 @@ class AnalogInData {
HAL_SIMDATAVALUE_DEFINE_NAME(AverageBits)
HAL_SIMDATAVALUE_DEFINE_NAME(OversampleBits)
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorInitialized)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorValue)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorCount)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorCenter)
HAL_SIMDATAVALUE_DEFINE_NAME(AccumulatorDeadband)
public:
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
@@ -26,16 +21,6 @@ class AnalogInData {
SimDataValue<int32_t, HAL_MakeInt, GetAverageBitsName> averageBits{7};
SimDataValue<int32_t, HAL_MakeInt, GetOversampleBitsName> oversampleBits{0};
SimDataValue<double, HAL_MakeDouble, GetVoltageName> voltage{0.0};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetAccumulatorInitializedName>
accumulatorInitialized{false};
SimDataValue<int64_t, HAL_MakeLong, GetAccumulatorValueName> accumulatorValue{
0};
SimDataValue<int64_t, HAL_MakeLong, GetAccumulatorCountName> accumulatorCount{
0};
SimDataValue<int32_t, HAL_MakeInt, GetAccumulatorCenterName>
accumulatorCenter{0};
SimDataValue<int32_t, HAL_MakeInt, GetAccumulatorDeadbandName>
accumulatorDeadband{0};
virtual void ResetData();
};

View File

@@ -4,7 +4,6 @@
#include <hal/simulation/AccelerometerData.h>
#include <hal/simulation/AddressableLEDData.h>
#include <hal/simulation/AnalogGyroData.h>
#include <hal/simulation/AnalogInData.h>
#include <hal/simulation/AnalogTriggerData.h>
#include <hal/simulation/CTREPCMData.h>
@@ -32,10 +31,6 @@ extern "C" void HALSIM_ResetAllSimData(void) {
HALSIM_ResetAddressableLEDData(i);
}
for (int32_t i = 0; i < hal::kNumAccumulators; i++) {
HALSIM_ResetAnalogGyroData(i);
}
for (int32_t i = 0; i < hal::kNumAnalogInputs; i++) {
HALSIM_ResetAnalogInData(i);
}