mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +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,97 +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 "AnalogGyroSimGui.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <glass/hardware/AnalogGyro.h>
|
||||
#include <glass/other/DeviceTree.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/Value.h>
|
||||
#include <hal/simulation/AnalogGyroData.h>
|
||||
|
||||
#include "HALDataSource.h"
|
||||
#include "HALSimGui.h"
|
||||
#include "SimDeviceGui.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
namespace {
|
||||
HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(AnalogGyroAngle, "AGyro Angle");
|
||||
HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(AnalogGyroRate, "AGyro Rate");
|
||||
|
||||
class AnalogGyroSimModel : public glass::AnalogGyroModel {
|
||||
public:
|
||||
explicit AnalogGyroSimModel(int32_t index)
|
||||
: m_index{index}, m_angle{index}, m_rate{index} {}
|
||||
|
||||
void Update() override {}
|
||||
|
||||
bool Exists() override { return HALSIM_GetAnalogGyroInitialized(m_index); }
|
||||
|
||||
glass::DoubleSource* GetAngleData() override { return &m_angle; }
|
||||
glass::DoubleSource* GetRateData() override { return &m_rate; }
|
||||
|
||||
void SetAngle(double val) override {
|
||||
HALSIM_SetAnalogGyroAngle(m_index, val);
|
||||
}
|
||||
void SetRate(double val) override { HALSIM_SetAnalogGyroRate(m_index, val); }
|
||||
|
||||
private:
|
||||
int32_t m_index;
|
||||
AnalogGyroAngleSource m_angle;
|
||||
AnalogGyroRateSource m_rate;
|
||||
};
|
||||
|
||||
class AnalogGyrosSimModel : public glass::AnalogGyrosModel {
|
||||
public:
|
||||
AnalogGyrosSimModel() : m_models(HAL_GetNumAccumulators()) {}
|
||||
|
||||
void Update() override;
|
||||
|
||||
bool Exists() override { return true; }
|
||||
|
||||
void ForEachAnalogGyro(
|
||||
wpi::function_ref<void(glass::AnalogGyroModel& model, int index)> func)
|
||||
override;
|
||||
|
||||
private:
|
||||
// indexed by channel
|
||||
std::vector<std::unique_ptr<AnalogGyroSimModel>> m_models;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void AnalogGyrosSimModel::Update() {
|
||||
for (int32_t i = 0, iend = static_cast<int32_t>(m_models.size()); i < iend;
|
||||
++i) {
|
||||
auto& model = m_models[i];
|
||||
if (HALSIM_GetAnalogGyroInitialized(i)) {
|
||||
if (!model) {
|
||||
model = std::make_unique<AnalogGyroSimModel>(i);
|
||||
}
|
||||
} else {
|
||||
model.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogGyrosSimModel::ForEachAnalogGyro(
|
||||
wpi::function_ref<void(glass::AnalogGyroModel& model, int index)> func) {
|
||||
for (int32_t i = 0, iend = static_cast<int32_t>(m_models.size()); i < iend;
|
||||
++i) {
|
||||
if (auto model = m_models[i].get()) {
|
||||
func(*model, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogGyroSimGui::Initialize() {
|
||||
SimDeviceGui::GetDeviceTree().Add(
|
||||
std::make_unique<AnalogGyrosSimModel>(), [](glass::Model* model) {
|
||||
glass::DisplayAnalogGyrosDevice(
|
||||
static_cast<AnalogGyrosSimModel*>(model));
|
||||
});
|
||||
}
|
||||
@@ -1,14 +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
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
class AnalogGyroSimGui {
|
||||
public:
|
||||
static void Initialize();
|
||||
};
|
||||
|
||||
} // namespace halsimgui
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <glass/View.h>
|
||||
#include <glass/hardware/AnalogInput.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/simulation/AnalogGyroData.h>
|
||||
#include <hal/simulation/AnalogInData.h>
|
||||
#include <hal/simulation/SimDeviceData.h>
|
||||
|
||||
@@ -31,11 +30,6 @@ class AnalogInputSimModel : public glass::AnalogInputModel {
|
||||
|
||||
bool Exists() override { return HALSIM_GetAnalogInInitialized(m_index); }
|
||||
|
||||
bool IsGyro() const override {
|
||||
return m_index < HAL_GetNumAccumulators() &&
|
||||
HALSIM_GetAnalogGyroInitialized(m_index);
|
||||
}
|
||||
|
||||
const char* GetSimDevice() const override {
|
||||
if (auto simDevice = HALSIM_GetAnalogInSimDevice(m_index)) {
|
||||
return HALSIM_GetSimDeviceName(simDevice);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include "AccelerometerSimGui.h"
|
||||
#include "AddressableLEDGui.h"
|
||||
#include "AnalogGyroSimGui.h"
|
||||
#include "AnalogInputSimGui.h"
|
||||
#include "DIOSimGui.h"
|
||||
#include "DriverStationGui.h"
|
||||
@@ -76,7 +75,6 @@ __declspec(dllexport)
|
||||
|
||||
AccelerometerSimGui::Initialize();
|
||||
AddressableLEDGui::Initialize();
|
||||
AnalogGyroSimGui::Initialize();
|
||||
AnalogInputSimGui::Initialize();
|
||||
DIOSimGui::Initialize();
|
||||
NetworkTablesSimGui::Initialize();
|
||||
|
||||
@@ -132,11 +132,6 @@ The basic analog input just reads a voltage. An analog input can also be configu
|
||||
| ``"<avg_bits"`` | Integer | The number of averaging bits |
|
||||
| ``"<oversample_bits"`` | Integer | The number of oversampling bits |
|
||||
| ``">voltage"`` | Float | Input voltage, in volts |
|
||||
| ``"<accum_init"`` | Boolean | If the accumulator is initialized in the robot program |
|
||||
| ``">accum_value"`` | Integer | The accumulated value |
|
||||
| ``">accum_count"`` | Integer | The number of accumulated values |
|
||||
| ``"<accum_center"`` | Integer | The center value of the accumulator |
|
||||
| ``"<accum_deadband"`` | Integer | The accumulator's deadband |
|
||||
|
||||
#### Analog Output ("AO")
|
||||
|
||||
|
||||
@@ -170,21 +170,6 @@ components:
|
||||
">voltage":
|
||||
type: number
|
||||
description: "Input voltage, in volts"
|
||||
"<accum_init":
|
||||
type: boolean
|
||||
description: "If the accumulator is initialized in the robot program"
|
||||
">accum_value":
|
||||
type: integer
|
||||
description: "The accumulated value"
|
||||
">accum_count":
|
||||
type: integer
|
||||
description: "The number of accumulated values"
|
||||
"<accum_center":
|
||||
type: integer
|
||||
description: "The center value of the accumulator"
|
||||
"<accum_deadband":
|
||||
type: integer
|
||||
description: "The accumulator's deadband"
|
||||
|
||||
aoData:
|
||||
type: object
|
||||
|
||||
@@ -16,15 +16,6 @@
|
||||
}, \
|
||||
this, true)
|
||||
|
||||
#define REGISTER_AIN_ACCUM(halsim, jsonid, ctype, haltype) \
|
||||
HALSIM_RegisterAnalogInAccumulator##halsim##Callback( \
|
||||
m_channel, \
|
||||
[](const char* name, void* param, const struct HAL_Value* value) { \
|
||||
static_cast<HALSimWSProviderAnalogIn*>(param)->ProcessHalCallback( \
|
||||
{{jsonid, static_cast<ctype>(value->data.v_##haltype)}}); \
|
||||
}, \
|
||||
this, true)
|
||||
|
||||
namespace wpilibws {
|
||||
|
||||
void HALSimWSProviderAnalogIn::Initialize(WSRegisterFunc webRegisterFunc) {
|
||||
@@ -42,17 +33,6 @@ void HALSimWSProviderAnalogIn::RegisterCallbacks() {
|
||||
m_oversampleCbKey =
|
||||
REGISTER_AIN(OversampleBits, "<oversample_bits", int32_t, int);
|
||||
m_voltageCbKey = REGISTER_AIN(Voltage, ">voltage", double, double);
|
||||
|
||||
m_accumInitCbKey =
|
||||
REGISTER_AIN_ACCUM(Initialized, "<accum_init", bool, boolean);
|
||||
m_accumValueCbKey = REGISTER_AIN_ACCUM(Value, ">accum_value", int64_t,
|
||||
long); // NOLINT(runtime/int)
|
||||
m_accumCountCbKey = REGISTER_AIN_ACCUM(Count, ">accum_count", int64_t,
|
||||
long); // NOLINT(runtime/int)
|
||||
m_accumCenterCbKey =
|
||||
REGISTER_AIN_ACCUM(Center, "<accum_center", int32_t, int);
|
||||
m_accumDeadbandCbKey =
|
||||
REGISTER_AIN_ACCUM(Deadband, "<accum_deadband", int32_t, int);
|
||||
}
|
||||
|
||||
void HALSimWSProviderAnalogIn::CancelCallbacks() {
|
||||
@@ -65,24 +45,12 @@ void HALSimWSProviderAnalogIn::DoCancelCallbacks() {
|
||||
HALSIM_CancelAnalogInAverageBitsCallback(m_channel, m_avgbitsCbKey);
|
||||
HALSIM_CancelAnalogInOversampleBitsCallback(m_channel, m_oversampleCbKey);
|
||||
HALSIM_CancelAnalogInVoltageCallback(m_channel, m_voltageCbKey);
|
||||
HALSIM_CancelAnalogInAccumulatorInitializedCallback(m_channel,
|
||||
m_accumInitCbKey);
|
||||
HALSIM_CancelAnalogInAccumulatorValueCallback(m_channel, m_accumValueCbKey);
|
||||
HALSIM_CancelAnalogInAccumulatorCountCallback(m_channel, m_accumCountCbKey);
|
||||
HALSIM_CancelAnalogInAccumulatorCenterCallback(m_channel, m_accumCenterCbKey);
|
||||
HALSIM_CancelAnalogInAccumulatorDeadbandCallback(m_channel,
|
||||
m_accumDeadbandCbKey);
|
||||
|
||||
// Reset callback IDs
|
||||
m_initCbKey = 0;
|
||||
m_avgbitsCbKey = 0;
|
||||
m_oversampleCbKey = 0;
|
||||
m_voltageCbKey = 0;
|
||||
m_accumInitCbKey = 0;
|
||||
m_accumValueCbKey = 0;
|
||||
m_accumCountCbKey = 0;
|
||||
m_accumCenterCbKey = 0;
|
||||
m_accumDeadbandCbKey = 0;
|
||||
}
|
||||
|
||||
void HALSimWSProviderAnalogIn::OnNetValueChanged(const wpi::json& json) {
|
||||
@@ -90,12 +58,6 @@ void HALSimWSProviderAnalogIn::OnNetValueChanged(const wpi::json& json) {
|
||||
if ((it = json.find(">voltage")) != json.end()) {
|
||||
HALSIM_SetAnalogInVoltage(m_channel, it.value());
|
||||
}
|
||||
if ((it = json.find(">accum_value")) != json.end()) {
|
||||
HALSIM_SetAnalogInAccumulatorValue(m_channel, it.value());
|
||||
}
|
||||
if ((it = json.find(">accum_count")) != json.end()) {
|
||||
HALSIM_SetAnalogInAccumulatorCount(m_channel, it.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wpilibws
|
||||
|
||||
@@ -29,11 +29,6 @@ class HALSimWSProviderAnalogIn : public HALSimWSHalChanProvider {
|
||||
int32_t m_avgbitsCbKey = 0;
|
||||
int32_t m_oversampleCbKey = 0;
|
||||
int32_t m_voltageCbKey = 0;
|
||||
int32_t m_accumInitCbKey = 0;
|
||||
int32_t m_accumValueCbKey = 0;
|
||||
int32_t m_accumCountCbKey = 0;
|
||||
int32_t m_accumCenterCbKey = 0;
|
||||
int32_t m_accumDeadbandCbKey = 0;
|
||||
};
|
||||
|
||||
} // namespace wpilibws
|
||||
|
||||
Reference in New Issue
Block a user