From f80874dd4b89c0a155b2c800ebdc9e2b1f723c21 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 17 Jan 2025 12:58:31 -0800 Subject: [PATCH] [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. --- .../lib/native/cpp/hardware/AnalogGyro.cpp | 41 --- .../lib/native/cpp/hardware/AnalogInput.cpp | 6 +- .../include/glass/hardware/AnalogGyro.h | 33 --- .../include/glass/hardware/AnalogInput.h | 1 - .../edu/wpi/first/hal/AccumulatorResult.java | 29 -- .../java/edu/wpi/first/hal/AnalogGyroJNI.java | 132 --------- .../java/edu/wpi/first/hal/AnalogJNI.java | 89 +----- .../java/edu/wpi/first/hal/DMAJNISample.java | 23 -- .../main/java/edu/wpi/first/hal/PortsJNI.java | 8 - .../hal/simulation/AnalogGyroDataJNI.java | 42 --- .../first/hal/simulation/AnalogInDataJNI.java | 45 ---- hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp | 196 -------------- hal/src/main/native/cpp/jni/AnalogJNI.cpp | 124 --------- hal/src/main/native/cpp/jni/HALUtil.cpp | 11 - hal/src/main/native/cpp/jni/HALUtil.h | 3 - hal/src/main/native/cpp/jni/PortsJNI.cpp | 13 - .../cpp/jni/simulation/AnalogGyroDataJNI.cpp | 177 ------------ .../cpp/jni/simulation/AnalogInDataJNI.cpp | 255 ------------------ .../native/include/hal/AnalogAccumulator.h | 120 --------- hal/src/main/native/include/hal/AnalogGyro.h | 149 ---------- hal/src/main/native/include/hal/HAL.h | 2 - hal/src/main/native/include/hal/Ports.h | 7 - .../include/hal/simulation/AnalogGyroData.h | 44 --- .../include/hal/simulation/AnalogInData.h | 42 --- hal/src/main/native/sim/AnalogAccumulator.cpp | 109 -------- hal/src/main/native/sim/AnalogGyro.cpp | 151 ----------- hal/src/main/native/sim/AnalogInput.cpp | 9 +- hal/src/main/native/sim/HAL.cpp | 3 - hal/src/main/native/sim/HALInitializer.h | 3 - hal/src/main/native/sim/Ports.cpp | 3 - .../native/sim/mockdata/AnalogGyroData.cpp | 48 ---- .../sim/mockdata/AnalogGyroDataInternal.h | 25 -- .../main/native/sim/mockdata/AnalogInData.cpp | 15 -- .../sim/mockdata/AnalogInDataInternal.h | 15 -- hal/src/main/native/sim/mockdata/Reset.cpp | 5 - .../native/systemcore/AnalogAccumulator.cpp | 65 ----- hal/src/main/native/systemcore/AnalogGyro.cpp | 92 ------- .../main/native/systemcore/AnalogInput.cpp | 1 - hal/src/main/native/systemcore/DMA.cpp | 2 - hal/src/main/native/systemcore/HAL.cpp | 2 - .../main/native/systemcore/HALInitializer.h | 2 - hal/src/main/native/systemcore/Ports.cpp | 4 - .../systemcore/mockdata/AnalogGyroData.cpp | 23 -- .../systemcore/mockdata/AnalogInData.cpp | 5 - .../src/main/native/cpp/AnalogGyroSimGui.cpp | 97 ------- .../src/main/native/cpp/AnalogGyroSimGui.h | 14 - .../src/main/native/cpp/AnalogInputSimGui.cpp | 6 - .../halsim_gui/src/main/native/cpp/main.cpp | 2 - .../halsim_ws_core/doc/hardware_ws_api.md | 5 - simulation/halsim_ws_core/doc/wpilib-ws.yaml | 15 -- .../src/main/native/cpp/WSProvider_Analog.cpp | 38 --- .../main/native/include/WSProvider_Analog.h | 5 - wpilibc/src/main/native/cpp/AnalogGyro.cpp | 143 ---------- wpilibc/src/main/native/cpp/AnalogInput.cpp | 65 ----- .../native/cpp/simulation/AnalogGyroSim.cpp | 75 ------ .../native/cpp/simulation/AnalogInputSim.cpp | 89 ------ .../src/main/native/include/frc/AnalogGyro.h | 45 ++-- .../src/main/native/include/frc/AnalogInput.h | 81 ------ .../include/frc/simulation/AnalogGyroSim.h | 121 --------- .../include/frc/simulation/AnalogInputSim.h | 130 --------- .../cpp/simulation/AnalogGyroSimTest.cpp | 88 ------ .../cpp/simulation/AnalogInputSimTest.cpp | 93 ------- .../cpp/simulation/SimInitializationTest.cpp | 2 - .../cpp/Drivetrain.cpp | 2 +- .../include/Drivetrain.h | 2 - .../cpp/Drivetrain.cpp | 2 +- .../include/Drivetrain.h | 2 - .../edu/wpi/first/wpilibj/AnalogGyro.java | 48 +--- .../edu/wpi/first/wpilibj/AnalogInput.java | 127 --------- .../wpilibj/simulation/AnalogGyroSim.java | 127 --------- .../wpilibj/simulation/AnalogInputSim.java | 156 ----------- .../edu/wpi/first/wpilibj/AnalogGyroTest.java | 38 --- .../wpilibj/simulation/AnalogGyroSimTest.java | 97 ------- .../simulation/AnalogInputSimTest.java | 22 -- .../Drivetrain.java | 4 +- .../Drivetrain.java | 4 +- 76 files changed, 33 insertions(+), 3886 deletions(-) delete mode 100644 glass/src/lib/native/cpp/hardware/AnalogGyro.cpp delete mode 100644 glass/src/lib/native/include/glass/hardware/AnalogGyro.h delete mode 100644 hal/src/main/java/edu/wpi/first/hal/AccumulatorResult.java delete mode 100644 hal/src/main/java/edu/wpi/first/hal/AnalogGyroJNI.java delete mode 100644 hal/src/main/java/edu/wpi/first/hal/simulation/AnalogGyroDataJNI.java delete mode 100644 hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp delete mode 100644 hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp delete mode 100644 hal/src/main/native/include/hal/AnalogAccumulator.h delete mode 100644 hal/src/main/native/include/hal/AnalogGyro.h delete mode 100644 hal/src/main/native/include/hal/simulation/AnalogGyroData.h delete mode 100644 hal/src/main/native/sim/AnalogAccumulator.cpp delete mode 100644 hal/src/main/native/sim/AnalogGyro.cpp delete mode 100644 hal/src/main/native/sim/mockdata/AnalogGyroData.cpp delete mode 100644 hal/src/main/native/sim/mockdata/AnalogGyroDataInternal.h delete mode 100644 hal/src/main/native/systemcore/AnalogAccumulator.cpp delete mode 100644 hal/src/main/native/systemcore/AnalogGyro.cpp delete mode 100644 hal/src/main/native/systemcore/mockdata/AnalogGyroData.cpp delete mode 100644 simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.cpp delete mode 100644 simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.h delete mode 100644 wpilibc/src/main/native/cpp/AnalogGyro.cpp delete mode 100644 wpilibc/src/main/native/cpp/simulation/AnalogGyroSim.cpp delete mode 100644 wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h delete mode 100644 wpilibc/src/test/native/cpp/simulation/AnalogGyroSimTest.cpp delete mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java delete mode 100644 wpilibj/src/test/java/edu/wpi/first/wpilibj/AnalogGyroTest.java delete mode 100644 wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSimTest.java diff --git a/glass/src/lib/native/cpp/hardware/AnalogGyro.cpp b/glass/src/lib/native/cpp/hardware/AnalogGyro.cpp deleted file mode 100644 index 259539fc2bf..00000000000 --- a/glass/src/lib/native/cpp/hardware/AnalogGyro.cpp +++ /dev/null @@ -1,41 +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 "glass/hardware/AnalogGyro.h" - -#include - -#include "glass/DataSource.h" -#include "glass/other/DeviceTree.h" - -using namespace glass; - -void glass::DisplayAnalogGyroDevice(AnalogGyroModel* model, int index) { - char name[32]; - wpi::format_to_n_c_str(name, sizeof(name), "AnalogGyro[{}]", index); - - if (BeginDevice(name)) { - // angle - if (auto angleData = model->GetAngleData()) { - double value = angleData->GetValue(); - if (DeviceDouble("Angle", false, &value, angleData)) { - model->SetAngle(value); - } - } - - // rate - if (auto rateData = model->GetRateData()) { - double value = rateData->GetValue(); - if (DeviceDouble("Rate", false, &value, rateData)) { - model->SetRate(value); - } - } - EndDevice(); - } -} - -void glass::DisplayAnalogGyrosDevice(AnalogGyrosModel* model) { - model->ForEachAnalogGyro( - [&](AnalogGyroModel& gyro, int i) { DisplayAnalogGyroDevice(&gyro, i); }); -} diff --git a/glass/src/lib/native/cpp/hardware/AnalogInput.cpp b/glass/src/lib/native/cpp/hardware/AnalogInput.cpp index 8c45f011386..97f0d45c210 100644 --- a/glass/src/lib/native/cpp/hardware/AnalogInput.cpp +++ b/glass/src/lib/native/cpp/hardware/AnalogInput.cpp @@ -30,11 +30,7 @@ void glass::DisplayAnalogInput(AnalogInputModel* model, int index) { wpi::format_to_n_c_str(label, sizeof(label), "In[{}]###name", index); } - if (model->IsGyro()) { - ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255)); - ImGui::LabelText(label, "AnalogGyro[%d]", index); - ImGui::PopStyleColor(); - } else if (auto simDevice = model->GetSimDevice()) { + if (auto simDevice = model->GetSimDevice()) { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255)); ImGui::LabelText(label, "%s", simDevice); ImGui::PopStyleColor(); diff --git a/glass/src/lib/native/include/glass/hardware/AnalogGyro.h b/glass/src/lib/native/include/glass/hardware/AnalogGyro.h deleted file mode 100644 index 39db0e83ad7..00000000000 --- a/glass/src/lib/native/include/glass/hardware/AnalogGyro.h +++ /dev/null @@ -1,33 +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 - -#include "glass/Model.h" - -namespace glass { - -class DoubleSource; - -class AnalogGyroModel : public Model { - public: - virtual DoubleSource* GetAngleData() = 0; - virtual DoubleSource* GetRateData() = 0; - - virtual void SetAngle(double val) = 0; - virtual void SetRate(double val) = 0; -}; - -class AnalogGyrosModel : public Model { - public: - virtual void ForEachAnalogGyro( - wpi::function_ref func) = 0; -}; - -void DisplayAnalogGyroDevice(AnalogGyroModel* model, int index); -void DisplayAnalogGyrosDevice(AnalogGyrosModel* model); - -} // namespace glass diff --git a/glass/src/lib/native/include/glass/hardware/AnalogInput.h b/glass/src/lib/native/include/glass/hardware/AnalogInput.h index f0079c7f7b1..eed4eff4e9b 100644 --- a/glass/src/lib/native/include/glass/hardware/AnalogInput.h +++ b/glass/src/lib/native/include/glass/hardware/AnalogInput.h @@ -16,7 +16,6 @@ class DoubleSource; class AnalogInputModel : public Model { public: - virtual bool IsGyro() const = 0; virtual const char* GetSimDevice() const = 0; virtual DoubleSource* GetVoltageData() = 0; diff --git a/hal/src/main/java/edu/wpi/first/hal/AccumulatorResult.java b/hal/src/main/java/edu/wpi/first/hal/AccumulatorResult.java deleted file mode 100644 index 569c94b00ae..00000000000 --- a/hal/src/main/java/edu/wpi/first/hal/AccumulatorResult.java +++ /dev/null @@ -1,29 +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.hal; - -/** Structure for holding the values stored in an accumulator. */ -@SuppressWarnings("MemberName") -public class AccumulatorResult { - /** The total value accumulated. */ - public long value; - - /** The number of sample value was accumulated over. */ - public long count; - - /** Constructs an AccumulatorResult. */ - public AccumulatorResult() {} - - /** - * Set the value and count. - * - * @param value The total value accumulated. - * @param count The number of samples accumulated. - */ - public void set(long value, long count) { - this.value = value; - this.count = count; - } -} diff --git a/hal/src/main/java/edu/wpi/first/hal/AnalogGyroJNI.java b/hal/src/main/java/edu/wpi/first/hal/AnalogGyroJNI.java deleted file mode 100644 index f1a4c5ecf2c..00000000000 --- a/hal/src/main/java/edu/wpi/first/hal/AnalogGyroJNI.java +++ /dev/null @@ -1,132 +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.hal; - -/** - * Analog Gyro JNI Functions. - * - * @see "hal/AnalogGyro.h" - */ -public class AnalogGyroJNI extends JNIWrapper { - /** - * Initializes an analog gyro. - * - * @param halAnalogInputHandle handle to the analog input port - * @return the initialized gyro handle - * @see "HAL_InitializeAnalogGyro" - */ - public static native int initializeAnalogGyro(int halAnalogInputHandle); - - /** - * Sets up an analog gyro with the proper offsets and settings for the KOP analog gyro. - * - * @param handle the gyro handle - * @see "HAL_SetupAnalogGyro" - */ - public static native void setupAnalogGyro(int handle); - - /** - * Frees an analog gyro. - * - * @param handle the gyro handle - * @see "HAL_FreeAnalogGyro" - */ - public static native void freeAnalogGyro(int handle); - - /** - * Sets the analog gyro parameters to the specified values. - * - *

This is meant to be used if you want to reuse the values from a previous calibration. - * - * @param handle the gyro handle - * @param voltsPerDegreePerSecond the gyro volts scaling - * @param offset the gyro offset - * @param center the gyro center - * @see "HAL_SetAnalogGyroParameters" - */ - public static native void setAnalogGyroParameters( - int handle, double voltsPerDegreePerSecond, double offset, int center); - - /** - * Sets the analog gyro volts per degrees per second scaling. - * - * @param handle the gyro handle - * @param voltsPerDegreePerSecond the gyro volts scaling - * @see "HAL_SetAnalogGyroVoltsPerDegreePerSecond" - */ - public static native void setAnalogGyroVoltsPerDegreePerSecond( - int handle, double voltsPerDegreePerSecond); - - /** - * Resets the analog gyro value to 0. - * - * @param handle the gyro handle - * @see "HAL_ResetAnalogGyro" - */ - public static native void resetAnalogGyro(int handle); - - /** - * Calibrates the analog gyro. - * - *

This happens by calculating the average value of the gyro over 5 seconds, and setting that - * as the center. Note that this call blocks for 5 seconds to perform this. - * - * @param handle the gyro handle - * @see "HAL_CalibrateAnalogGyro" - */ - public static native void calibrateAnalogGyro(int handle); - - /** - * Sets the deadband of the analog gyro. - * - * @param handle the gyro handle - * @param volts the voltage deadband - * @see "HAL_SetAnalogGyroDeadband" - */ - public static native void setAnalogGyroDeadband(int handle, double volts); - - /** - * Gets the gyro angle in degrees. - * - * @param handle the gyro handle - * @return the gyro angle in degrees - * @see "HAL_GetAnalogGyroAngle" - */ - public static native double getAnalogGyroAngle(int handle); - - /** - * Gets the gyro rate in degrees/second. - * - * @param handle the gyro handle - * @return the gyro rate in degrees/second - * @see "HAL_GetAnalogGyroRate" - */ - public static native double getAnalogGyroRate(int handle); - - /** - * Gets the calibrated gyro offset. - * - *

Can be used to not repeat a calibration but reconstruct the gyro object. - * - * @param handle the gyro handle - * @return the gyro offset - * @see "HAL_GetAnalogGyroOffset" - */ - public static native double getAnalogGyroOffset(int handle); - - /** - * Gets the calibrated gyro center. - * - *

Can be used to not repeat a calibration but reconstruct the gyro object. - * - * @param handle the gyro handle - * @return the gyro center - * @see "HAL_GetAnalogGyroCenter" - */ - public static native int getAnalogGyroCenter(int handle); - - /** Utility class. */ - private AnalogGyroJNI() {} -} diff --git a/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java b/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java index 9398deb8ead..9c97cab286d 100644 --- a/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/AnalogJNI.java @@ -5,10 +5,9 @@ package edu.wpi.first.hal; /** - * Analog Input / Output / Accumulator / Trigger JNI Functions. + * Analog Input / Output / Trigger JNI Functions. * * @see "hal/AnalogInput.h" - * @see "hal/AnalogAccumulator.h" * @see "hal/AnalogTrigger.h" */ public class AnalogJNI extends JNIWrapper { @@ -249,92 +248,6 @@ public interface AnalogTriggerType { */ public static native int getAnalogOffset(int analogPortHandle); - /** - * Is the channel attached to an accumulator. - * - * @param analogPortHandle Handle to the analog port. - * @return The analog channel is attached to an accumulator. - * @see "HAL_IsAccumulatorChannel" - */ - public static native boolean isAccumulatorChannel(int analogPortHandle); - - /** - * Initialize the accumulator. - * - * @param analogPortHandle Handle to the analog port. - * @see "HAL_InitAccumulator" - */ - public static native void initAccumulator(int analogPortHandle); - - /** - * Resets the accumulator to the initial value. - * - * @param analogPortHandle Handle to the analog port. - * @see "HAL_ResetAccumulator" - */ - public static native void resetAccumulator(int analogPortHandle); - - /** - * 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 make integration - * work and to take the device offset into account when integrating. - * - *

This center value is based on the output of the oversampled and averaged source from channel - * 1. Because of this, any non-zero oversample bits will affect the size of the value for this - * field. - * - * @param analogPortHandle Handle to the analog port. - * @param center The center value of the accumulator. - * @see "HAL_SetAccumulatorCenter" - */ - public static native void setAccumulatorCenter(int analogPortHandle, int center); - - /** - * Set the accumulator's deadband. - * - * @param analogPortHandle Handle to the analog port. - * @param deadband The deadband of the accumulator. - * @see "HAL_SetAccumulatorDeadband" - */ - public static native void setAccumulatorDeadband(int analogPortHandle, int deadband); - - /** - * Read the accumulated value. - * - *

Read the value that has been accumulating on channel 1. The accumulator is attached after - * the oversample and average engine. - * - * @param analogPortHandle Handle to the analog port. - * @return The 64-bit value accumulated since the last Reset(). - * @see "HAL_GetAccumulatorValue" - */ - public static native long getAccumulatorValue(int analogPortHandle); - - /** - * Read the number of accumulated values. - * - *

Read the count of the accumulated values since the accumulator was last Reset(). - * - * @param analogPortHandle Handle to the analog port. - * @return The number of times samples from the channel were accumulated. - * @see "HAL_GetAccumulatorCount" - */ - public static native int getAccumulatorCount(int analogPortHandle); - - /** - * 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 analogPortHandle Handle to the analog port. - * @param result Accumulator result. - * @see "HAL_GetAccumulatorOutput" - */ - public static native void getAccumulatorOutput(int analogPortHandle, AccumulatorResult result); - /** * Initializes an analog trigger. * diff --git a/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java b/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java index df66c558b0c..50631ff2785 100644 --- a/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java +++ b/hal/src/main/java/edu/wpi/first/hal/DMAJNISample.java @@ -137,29 +137,6 @@ public int getAnalogInputAveraged(int analogInputHandle) { return readValue(data.m_valueType + 2, data.m_index); } - public void getAnalogAccumulator(int analogInputHandle, AccumulatorResult result) { - BaseStore data = m_propertyMap.get(analogInputHandle); - if (data == null) { - data = addSensorInternal(analogInputHandle); - } - - if (data.m_index == 0) { - int val0 = readValue(kEnable_Accumulator0, 0); - int val1 = readValue(kEnable_Accumulator0, 1); - int val2 = readValue(kEnable_Accumulator0, 2); - result.count = val2; - result.value = ((long) val1 << 32) | val0; - } else if (data.m_index == 1) { - int val0 = readValue(kEnable_Accumulator1, 0); - int val1 = readValue(kEnable_Accumulator1, 1); - int val2 = readValue(kEnable_Accumulator1, 2); - result.count = val2; - result.value = ((long) val1 << 32) | val0; - } else { - throw new RuntimeException("Resource not found in DMA capture"); - } - } - public int getDutyCycleOutput(int dutyCycleHandle) { BaseStore data = m_propertyMap.get(dutyCycleHandle); if (data == null) { diff --git a/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java b/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java index 57ee0fdd2d4..3841af6c6a6 100644 --- a/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/PortsJNI.java @@ -10,14 +10,6 @@ * @see "hal/Ports.h" */ public class PortsJNI extends JNIWrapper { - /** - * Gets the number of analog accumulators in the current system. - * - * @return the number of analog accumulators - * @see "HAL_GetNumAccumulators" - */ - public static native int getNumAccumulators(); - /** * Gets the number of analog triggers in the current system. * diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogGyroDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogGyroDataJNI.java deleted file mode 100644 index b369dcda15a..00000000000 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogGyroDataJNI.java +++ /dev/null @@ -1,42 +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.hal.simulation; - -import edu.wpi.first.hal.JNIWrapper; - -/** JNI for analog gyro data. */ -public class AnalogGyroDataJNI extends JNIWrapper { - public static native int registerAngleCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAngleCallback(int index, int uid); - - public static native double getAngle(int index); - - public static native void setAngle(int index, double angle); - - public static native int registerRateCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelRateCallback(int index, int uid); - - public static native double getRate(int index); - - public static native void setRate(int index, double rate); - - public static native int registerInitializedCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelInitializedCallback(int index, int uid); - - public static native boolean getInitialized(int index); - - public static native void setInitialized(int index, boolean initialized); - - public static native void resetData(int index); - - /** Utility class. */ - private AnalogGyroDataJNI() {} -} diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogInDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogInDataJNI.java index b3dde0e176a..9c63471a140 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogInDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/AnalogInDataJNI.java @@ -44,51 +44,6 @@ public static native int registerVoltageCallback( public static native void setVoltage(int index, double voltage); - public static native int registerAccumulatorInitializedCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAccumulatorInitializedCallback(int index, int uid); - - public static native boolean getAccumulatorInitialized(int index); - - public static native void setAccumulatorInitialized(int index, boolean accumulatorInitialized); - - public static native int registerAccumulatorValueCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAccumulatorValueCallback(int index, int uid); - - public static native long getAccumulatorValue(int index); - - public static native void setAccumulatorValue(int index, long accumulatorValue); - - public static native int registerAccumulatorCountCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAccumulatorCountCallback(int index, int uid); - - public static native long getAccumulatorCount(int index); - - public static native void setAccumulatorCount(int index, long accumulatorCount); - - public static native int registerAccumulatorCenterCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAccumulatorCenterCallback(int index, int uid); - - public static native int getAccumulatorCenter(int index); - - public static native void setAccumulatorCenter(int index, int AccumulatorCenter); - - public static native int registerAccumulatorDeadbandCallback( - int index, NotifyCallback callback, boolean initialNotify); - - public static native void cancelAccumulatorDeadbandCallback(int index, int uid); - - public static native int getAccumulatorDeadband(int index); - - public static native void setAccumulatorDeadband(int index, int AccumulatorDeadband); - public static native void resetData(int index); /** Utility class. */ diff --git a/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp b/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp deleted file mode 100644 index f630c29da38..00000000000 --- a/hal/src/main/native/cpp/jni/AnalogGyroJNI.cpp +++ /dev/null @@ -1,196 +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 - -#include - -#include - -#include "HALUtil.h" -#include "edu_wpi_first_hal_AnalogGyroJNI.h" -#include "hal/AnalogGyro.h" -#include "hal/handles/HandlesInternal.h" - -using namespace hal; - -extern "C" { -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: initializeAnalogGyro - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_initializeAnalogGyro - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - auto stack = wpi::java::GetJavaStackTrace(env, "edu.wpi.first"); - HAL_GyroHandle handle = HAL_InitializeAnalogGyro((HAL_AnalogInputHandle)id, - stack.c_str(), &status); - // Analog input does range checking, so we don't need to do so. - CheckStatusForceThrow(env, status); - return (jint)handle; -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: setupAnalogGyro - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_setupAnalogGyro - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_SetupAnalogGyro((HAL_GyroHandle)id, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: freeAnalogGyro - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_freeAnalogGyro - (JNIEnv* env, jclass, jint id) -{ - if (id != HAL_kInvalidHandle) { - HAL_FreeAnalogGyro((HAL_GyroHandle)id); - } -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: setAnalogGyroParameters - * Signature: (IDDI)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_setAnalogGyroParameters - (JNIEnv* env, jclass, jint id, jdouble vPDPS, jdouble offset, jint center) -{ - int32_t status = 0; - HAL_SetAnalogGyroParameters((HAL_GyroHandle)id, vPDPS, offset, center, - &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: setAnalogGyroVoltsPerDegreePerSecond - * Signature: (ID)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_setAnalogGyroVoltsPerDegreePerSecond - (JNIEnv* env, jclass, jint id, jdouble vPDPS) -{ - int32_t status = 0; - HAL_SetAnalogGyroVoltsPerDegreePerSecond((HAL_GyroHandle)id, vPDPS, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: resetAnalogGyro - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_resetAnalogGyro - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_ResetAnalogGyro((HAL_GyroHandle)id, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: calibrateAnalogGyro - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_calibrateAnalogGyro - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_CalibrateAnalogGyro((HAL_GyroHandle)id, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: setAnalogGyroDeadband - * Signature: (ID)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_setAnalogGyroDeadband - (JNIEnv* env, jclass, jint id, jdouble deadband) -{ - int32_t status = 0; - HAL_SetAnalogGyroDeadband((HAL_GyroHandle)id, deadband, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: getAnalogGyroAngle - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_getAnalogGyroAngle - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jdouble value = HAL_GetAnalogGyroAngle((HAL_GyroHandle)id, &status); - CheckStatus(env, status); - return value; -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: getAnalogGyroRate - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_getAnalogGyroRate - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jdouble value = HAL_GetAnalogGyroRate((HAL_GyroHandle)id, &status); - CheckStatus(env, status); - return value; -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: getAnalogGyroOffset - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_getAnalogGyroOffset - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jdouble value = HAL_GetAnalogGyroOffset((HAL_GyroHandle)id, &status); - CheckStatus(env, status); - return value; -} - -/* - * Class: edu_wpi_first_hal_AnalogGyroJNI - * Method: getAnalogGyroCenter - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_AnalogGyroJNI_getAnalogGyroCenter - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jint value = HAL_GetAnalogGyroCenter((HAL_GyroHandle)id, &status); - CheckStatus(env, status); - return value; -} - -} // extern "C" diff --git a/hal/src/main/native/cpp/jni/AnalogJNI.cpp b/hal/src/main/native/cpp/jni/AnalogJNI.cpp index b911104dab5..0312ea0aa87 100644 --- a/hal/src/main/native/cpp/jni/AnalogJNI.cpp +++ b/hal/src/main/native/cpp/jni/AnalogJNI.cpp @@ -10,7 +10,6 @@ #include "HALUtil.h" #include "edu_wpi_first_hal_AnalogJNI.h" -#include "hal/AnalogAccumulator.h" #include "hal/AnalogInput.h" #include "hal/AnalogTrigger.h" #include "hal/Ports.h" @@ -306,129 +305,6 @@ Java_edu_wpi_first_hal_AnalogJNI_getAnalogOffset return returnValue; } -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: isAccumulatorChannel - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_AnalogJNI_isAccumulatorChannel - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - - jboolean returnValue = - HAL_IsAccumulatorChannel((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: initAccumulator - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_initAccumulator - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_InitAccumulator((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: resetAccumulator - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_resetAccumulator - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - HAL_ResetAccumulator((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAccumulatorCenter - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAccumulatorCenter - (JNIEnv* env, jclass, jint id, jint center) -{ - int32_t status = 0; - HAL_SetAccumulatorCenter((HAL_AnalogInputHandle)id, center, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: setAccumulatorDeadband - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_setAccumulatorDeadband - (JNIEnv* env, jclass, jint id, jint deadband) -{ - int32_t status = 0; - HAL_SetAccumulatorDeadband((HAL_AnalogInputHandle)id, deadband, &status); - CheckStatus(env, status); -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAccumulatorValue - * Signature: (I)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAccumulatorValue - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jlong returnValue = - HAL_GetAccumulatorValue((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - - return returnValue; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAccumulatorCount - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAccumulatorCount - (JNIEnv* env, jclass, jint id) -{ - int32_t status = 0; - jint returnValue = - HAL_GetAccumulatorCount((HAL_AnalogInputHandle)id, &status); - CheckStatus(env, status); - return returnValue; -} - -/* - * Class: edu_wpi_first_hal_AnalogJNI - * Method: getAccumulatorOutput - * Signature: (ILjava/lang/Object;)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_AnalogJNI_getAccumulatorOutput - (JNIEnv* env, jclass, jint id, jobject accumulatorResult) -{ - int32_t status = 0; - int64_t value = 0; - int64_t count = 0; - HAL_GetAccumulatorOutput((HAL_AnalogInputHandle)id, &value, &count, &status); - SetAccumulatorResultObject(env, accumulatorResult, value, count); - CheckStatus(env, status); -} - /* * Class: edu_wpi_first_hal_AnalogJNI * Method: initializeAnalogTrigger diff --git a/hal/src/main/native/cpp/jni/HALUtil.cpp b/hal/src/main/native/cpp/jni/HALUtil.cpp index 31b40efc57b..8afd008a130 100644 --- a/hal/src/main/native/cpp/jni/HALUtil.cpp +++ b/hal/src/main/native/cpp/jni/HALUtil.cpp @@ -51,7 +51,6 @@ static JClass powerDistributionVersionCls; static JClass pwmConfigDataResultCls; static JClass canStatusCls; static JClass matchInfoDataCls; -static JClass accumulatorResultCls; static JClass canDataCls; static JClass canStreamMessageCls; static JClass halValueCls; @@ -65,7 +64,6 @@ static const JClassInit classes[] = { {"edu/wpi/first/hal/PWMConfigDataResult", &pwmConfigDataResultCls}, {"edu/wpi/first/hal/can/CANStatus", &canStatusCls}, {"edu/wpi/first/hal/MatchInfoData", &matchInfoDataCls}, - {"edu/wpi/first/hal/AccumulatorResult", &accumulatorResultCls}, {"edu/wpi/first/hal/CANData", &canDataCls}, {"edu/wpi/first/hal/CANStreamMessage", &canStreamMessageCls}, {"edu/wpi/first/hal/HALValue", &halValueCls}, @@ -306,15 +304,6 @@ void SetMatchInfoObject(JNIEnv* env, jobject matchStatus, static_cast(matchInfo.matchType)); } -void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult, - int64_t value, int64_t count) { - static jmethodID func = - env->GetMethodID(accumulatorResultCls, "set", "(JJ)V"); - - env->CallVoidMethod(accumulatorResult, func, static_cast(value), - static_cast(count)); -} - jbyteArray SetCANDataObject(JNIEnv* env, jobject canData, int32_t length, uint64_t timestamp) { static jmethodID func = env->GetMethodID(canDataCls, "setData", "(IJ)[B"); diff --git a/hal/src/main/native/cpp/jni/HALUtil.h b/hal/src/main/native/cpp/jni/HALUtil.h index b64238bf217..ca4bd959f03 100644 --- a/hal/src/main/native/cpp/jni/HALUtil.h +++ b/hal/src/main/native/cpp/jni/HALUtil.h @@ -75,9 +75,6 @@ void SetCanStatusObject(JNIEnv* env, jobject canStatus, void SetMatchInfoObject(JNIEnv* env, jobject matchStatus, const HAL_MatchInfo& matchInfo); -void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult, - int64_t value, int64_t count); - jbyteArray SetCANDataObject(JNIEnv* env, jobject canData, int32_t length, uint64_t timestamp); diff --git a/hal/src/main/native/cpp/jni/PortsJNI.cpp b/hal/src/main/native/cpp/jni/PortsJNI.cpp index 1042de6db4a..c3d153a8959 100644 --- a/hal/src/main/native/cpp/jni/PortsJNI.cpp +++ b/hal/src/main/native/cpp/jni/PortsJNI.cpp @@ -13,19 +13,6 @@ using namespace hal; extern "C" { -/* - * Class: edu_wpi_first_hal_PortsJNI - * Method: getNumAccumulators - * Signature: ()I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_PortsJNI_getNumAccumulators - (JNIEnv* env, jclass) -{ - jint value = HAL_GetNumAccumulators(); - return value; -} - /* * Class: edu_wpi_first_hal_PortsJNI * Method: getNumAnalogTriggers diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp deleted file mode 100644 index 6a916f5cfdd..00000000000 --- a/hal/src/main/native/cpp/jni/simulation/AnalogGyroDataJNI.cpp +++ /dev/null @@ -1,177 +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 - -#include "CallbackStore.h" -#include "edu_wpi_first_hal_simulation_AnalogGyroDataJNI.h" -#include "hal/simulation/AnalogGyroData.h" - -using namespace hal; - -extern "C" { - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: registerAngleCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_registerAngleCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback(env, index, callback, initialNotify, - &HALSIM_RegisterAnalogGyroAngleCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: cancelAngleCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_cancelAngleCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogGyroAngleCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: getAngle - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_getAngle - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogGyroAngle(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: setAngle - * Signature: (ID)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_setAngle - (JNIEnv*, jclass, jint index, jdouble value) -{ - HALSIM_SetAnalogGyroAngle(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: registerRateCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_registerRateCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback(env, index, callback, initialNotify, - &HALSIM_RegisterAnalogGyroRateCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: cancelRateCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_cancelRateCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogGyroRateCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: getRate - * Signature: (I)D - */ -JNIEXPORT jdouble JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_getRate - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogGyroRate(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: setRate - * Signature: (ID)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_setRate - (JNIEnv*, jclass, jint index, jdouble value) -{ - HALSIM_SetAnalogGyroRate(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: registerInitializedCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_registerInitializedCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback(env, index, callback, initialNotify, - &HALSIM_RegisterAnalogGyroInitializedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: cancelInitializedCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_cancelInitializedCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogGyroInitializedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: getInitialized - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_getInitialized - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogGyroInitialized(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: setInitialized - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_setInitialized - (JNIEnv*, jclass, jint index, jboolean value) -{ - HALSIM_SetAnalogGyroInitialized(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogGyroDataJNI - * Method: resetData - * Signature: (I)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogGyroDataJNI_resetData - (JNIEnv*, jclass, jint index) -{ - HALSIM_ResetAnalogGyroData(index); -} - -} // extern "C" diff --git a/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp index 336c0f41c78..bdb6e387da8 100644 --- a/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/AnalogInDataJNI.cpp @@ -212,261 +212,6 @@ Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_setVoltage HALSIM_SetAnalogInVoltage(index, value); } -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: registerAccumulatorInitializedCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_registerAccumulatorInitializedCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInAccumulatorInitializedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: cancelAccumulatorInitializedCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_cancelAccumulatorInitializedCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback( - env, handle, index, &HALSIM_CancelAnalogInAccumulatorInitializedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: getAccumulatorInitialized - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_getAccumulatorInitialized - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInAccumulatorInitialized(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: setAccumulatorInitialized - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_setAccumulatorInitialized - (JNIEnv*, jclass, jint index, jboolean value) -{ - HALSIM_SetAnalogInAccumulatorInitialized(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: registerAccumulatorValueCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_registerAccumulatorValueCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInAccumulatorValueCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: cancelAccumulatorValueCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_cancelAccumulatorValueCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogInAccumulatorValueCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: getAccumulatorValue - * Signature: (I)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_getAccumulatorValue - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInAccumulatorValue(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: setAccumulatorValue - * Signature: (IJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_setAccumulatorValue - (JNIEnv*, jclass, jint index, jlong value) -{ - HALSIM_SetAnalogInAccumulatorValue(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: registerAccumulatorCountCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_registerAccumulatorCountCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInAccumulatorCountCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: cancelAccumulatorCountCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_cancelAccumulatorCountCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogInAccumulatorCountCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: getAccumulatorCount - * Signature: (I)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_getAccumulatorCount - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInAccumulatorCount(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: setAccumulatorCount - * Signature: (IJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_setAccumulatorCount - (JNIEnv*, jclass, jint index, jlong value) -{ - HALSIM_SetAnalogInAccumulatorCount(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: registerAccumulatorCenterCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_registerAccumulatorCenterCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInAccumulatorCenterCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: cancelAccumulatorCenterCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_cancelAccumulatorCenterCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogInAccumulatorCenterCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: getAccumulatorCenter - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_getAccumulatorCenter - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInAccumulatorCenter(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: setAccumulatorCenter - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_setAccumulatorCenter - (JNIEnv*, jclass, jint index, jint value) -{ - HALSIM_SetAnalogInAccumulatorCenter(index, value); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: registerAccumulatorDeadbandCallback - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_registerAccumulatorDeadbandCallback - (JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify) -{ - return sim::AllocateCallback( - env, index, callback, initialNotify, - &HALSIM_RegisterAnalogInAccumulatorDeadbandCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: cancelAccumulatorDeadbandCallback - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_cancelAccumulatorDeadbandCallback - (JNIEnv* env, jclass, jint index, jint handle) -{ - return sim::FreeCallback(env, handle, index, - &HALSIM_CancelAnalogInAccumulatorDeadbandCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: getAccumulatorDeadband - * Signature: (I)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_getAccumulatorDeadband - (JNIEnv*, jclass, jint index) -{ - return HALSIM_GetAnalogInAccumulatorDeadband(index); -} - -/* - * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI - * Method: setAccumulatorDeadband - * Signature: (II)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_hal_simulation_AnalogInDataJNI_setAccumulatorDeadband - (JNIEnv*, jclass, jint index, jint value) -{ - HALSIM_SetAnalogInAccumulatorDeadband(index, value); -} - /* * Class: edu_wpi_first_hal_simulation_AnalogInDataJNI * Method: resetData diff --git a/hal/src/main/native/include/hal/AnalogAccumulator.h b/hal/src/main/native/include/hal/AnalogAccumulator.h deleted file mode 100644 index c0c928df81d..00000000000 --- a/hal/src/main/native/include/hal/AnalogAccumulator.h +++ /dev/null @@ -1,120 +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 - -#include "hal/Types.h" - -/** - * @defgroup hal_analogaccumulator Analog Accumulator Functions - * @ingroup hal_capi - * @{ - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Is the channel attached to an accumulator. - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[out] status Error status variable. 0 on success. - * @return The analog channel is attached to an accumulator. - */ -HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * Initialize the accumulator. - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[out] status Error status variable. 0 on success. - */ -void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * Resets the accumulator to the initial value. - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[out] status Error status variable. 0 on success. - */ -void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * 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 make integration work and to take the device offset into - * account when integrating. - * - * This center value is based on the output of the oversampled and averaged - * source from channel 1. Because of this, any non-zero oversample bits will - * affect the size of the value for this field. - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[in] center The center value of the accumulator. - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle, - int32_t center, int32_t* status); - -/** - * Set the accumulator's deadband. - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[in] deadband The deadband of the accumulator. - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle, - int32_t deadband, int32_t* status); - -/** - * Read the accumulated value. - * - * Read the value that has been accumulating on channel 1. - * The accumulator is attached after the oversample and average engine. - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[out] status Error status variable. 0 on success. - * @return The 64-bit value accumulated since the last Reset(). - */ -int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * Read the number of accumulated values. - * - * Read the count of the accumulated values since the accumulator was last - * Reset(). - * - * @param[in] analogPortHandle Handle to the analog port. - * @param[out] status Error status variable. 0 on success. - * @return The number of times samples from the channel were accumulated. - */ -int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle, - int32_t* status); - -/** - * 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[in] analogPortHandle Handle to the analog port. - * @param[in] value Pointer to the 64-bit accumulated output. - * @param[in] count Pointer to the number of accumulation cycles. - * @param[out] status Error status variable. 0 on success. - */ -void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle, - int64_t* value, int64_t* count, int32_t* status); -#ifdef __cplusplus -} // extern "C" -#endif -/** @} */ diff --git a/hal/src/main/native/include/hal/AnalogGyro.h b/hal/src/main/native/include/hal/AnalogGyro.h deleted file mode 100644 index 14753e80e70..00000000000 --- a/hal/src/main/native/include/hal/AnalogGyro.h +++ /dev/null @@ -1,149 +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 - -#include "hal/Types.h" - -/** - * @defgroup hal_analoggyro Analog Gyro Functions - * @ingroup hal_capi - * @{ - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Initializes an analog gyro. - * - * @param[in] handle handle to the analog input port - * @param[in] allocationLocation the location where the allocation is occurring - * (can be null) - * @param[out] status the error code, or 0 for success - * @return the initialized gyro handle - */ -HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle handle, - const char* allocationLocation, - int32_t* status); - -/** - * Sets up an analog gyro with the proper offsets and settings for the KOP - * analog gyro. - * - * @param[in] handle the gyro handle - * @param[out] status the error code, or 0 for success - */ -void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status); - -/** - * Frees an analog gyro. - * - * @param handle the gyro handle - */ -void HAL_FreeAnalogGyro(HAL_GyroHandle handle); - -/** - * Sets the analog gyro parameters to the specified values. - * - * This is meant to be used if you want to reuse the values from a previous - * calibration. - * - * @param[in] handle the gyro handle - * @param[in] voltsPerDegreePerSecond the gyro volts scaling - * @param[in] offset the gyro offset - * @param[in] center the gyro center - * @param[out] status the error code, or 0 for success - */ -void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle, - double voltsPerDegreePerSecond, double offset, - int32_t center, int32_t* status); - -/** - * Sets the analog gyro volts per degrees per second scaling. - * - * @param[in] handle the gyro handle - * @param[in] voltsPerDegreePerSecond the gyro volts scaling - * @param[out] status the error code, or 0 for success - */ -void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle, - double voltsPerDegreePerSecond, - int32_t* status); - -/** - * Resets the analog gyro value to 0. - * - * @param[in] handle the gyro handle - * @param[out] status the error code, or 0 for success - */ -void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status); - -/** - * Calibrates the analog gyro. - * - * This happens by calculating the average value of the gyro over 5 seconds, and - * setting that as the center. Note that this call blocks for 5 seconds to - * perform this. - * - * @param[in] handle the gyro handle - * @param[out] status Error status variable. 0 on success. - */ -void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status); - -/** - * Sets the deadband of the analog gyro. - * - * @param[in] handle the gyro handle - * @param[in] volts the voltage deadband - * @param[out] status Error status variable. 0 on success. - */ -void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts, - int32_t* status); - -/** - * Gets the gyro angle in degrees. - * - * @param[in] handle the gyro handle - * @param[out] status Error status variable. 0 on success. - * @return the gyro angle in degrees - */ -double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status); - -/** - * Gets the gyro rate in degrees/second. - * - * @param[in] handle the gyro handle - * @param[out] status Error status variable. 0 on success. - * @return the gyro rate in degrees/second - */ -double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status); - -/** - * Gets the calibrated gyro offset. - * - * Can be used to not repeat a calibration but reconstruct the gyro object. - * - * @param[in] handle the gyro handle - * @param[out] status Error status variable. 0 on success. - * @return the gyro offset - */ -double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status); - -/** - * Gets the calibrated gyro center. - * - * Can be used to not repeat a calibration but reconstruct the gyro object. - * - * @param[in] handle the gyro handle - * @param[out] status Error status variable. 0 on success. - * @return the gyro center - */ -int32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status); -#ifdef __cplusplus -} // extern "C" -#endif -/** @} */ diff --git a/hal/src/main/native/include/hal/HAL.h b/hal/src/main/native/include/hal/HAL.h index 614e757c177..041fdd93024 100644 --- a/hal/src/main/native/include/hal/HAL.h +++ b/hal/src/main/native/include/hal/HAL.h @@ -7,8 +7,6 @@ #include #include "hal/Accelerometer.h" -#include "hal/AnalogAccumulator.h" -#include "hal/AnalogGyro.h" #include "hal/AnalogInput.h" #include "hal/AnalogTrigger.h" #include "hal/CAN.h" diff --git a/hal/src/main/native/include/hal/Ports.h b/hal/src/main/native/include/hal/Ports.h index edc47d9680b..1d4b385b699 100644 --- a/hal/src/main/native/include/hal/Ports.h +++ b/hal/src/main/native/include/hal/Ports.h @@ -16,13 +16,6 @@ extern "C" { #endif -/** - * Gets the number of analog accumulators in the current system. - * - * @return the number of analog accumulators - */ -int32_t HAL_GetNumAccumulators(void); - /** * Gets the number of analog triggers in the current system. * diff --git a/hal/src/main/native/include/hal/simulation/AnalogGyroData.h b/hal/src/main/native/include/hal/simulation/AnalogGyroData.h deleted file mode 100644 index 9527140148e..00000000000 --- a/hal/src/main/native/include/hal/simulation/AnalogGyroData.h +++ /dev/null @@ -1,44 +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/Types.h" -#include "hal/simulation/NotifyListener.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void HALSIM_ResetAnalogGyroData(int32_t index); -int32_t HALSIM_RegisterAnalogGyroAngleCallback(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogGyroAngleCallback(int32_t index, int32_t uid); -double HALSIM_GetAnalogGyroAngle(int32_t index); -void HALSIM_SetAnalogGyroAngle(int32_t index, double angle); - -int32_t HALSIM_RegisterAnalogGyroRateCallback(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogGyroRateCallback(int32_t index, int32_t uid); -double HALSIM_GetAnalogGyroRate(int32_t index); -void HALSIM_SetAnalogGyroRate(int32_t index, double rate); - -int32_t HALSIM_RegisterAnalogGyroInitializedCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogGyroInitializedCallback(int32_t index, int32_t uid); -HAL_Bool HALSIM_GetAnalogGyroInitialized(int32_t index); -void HALSIM_SetAnalogGyroInitialized(int32_t index, HAL_Bool initialized); - -void HALSIM_RegisterAnalogGyroAllCallbacks(int32_t index, - HAL_NotifyCallback callback, - void* param, HAL_Bool initialNotify); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/hal/src/main/native/include/hal/simulation/AnalogInData.h b/hal/src/main/native/include/hal/simulation/AnalogInData.h index 2e2d8be9d35..6d305ae22da 100644 --- a/hal/src/main/native/include/hal/simulation/AnalogInData.h +++ b/hal/src/main/native/include/hal/simulation/AnalogInData.h @@ -45,48 +45,6 @@ void HALSIM_CancelAnalogInVoltageCallback(int32_t index, int32_t uid); double HALSIM_GetAnalogInVoltage(int32_t index); void HALSIM_SetAnalogInVoltage(int32_t index, double voltage); -int32_t HALSIM_RegisterAnalogInAccumulatorInitializedCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInAccumulatorInitializedCallback(int32_t index, - int32_t uid); -HAL_Bool HALSIM_GetAnalogInAccumulatorInitialized(int32_t index); -void HALSIM_SetAnalogInAccumulatorInitialized(int32_t index, - HAL_Bool accumulatorInitialized); - -int32_t HALSIM_RegisterAnalogInAccumulatorValueCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInAccumulatorValueCallback(int32_t index, int32_t uid); -int64_t HALSIM_GetAnalogInAccumulatorValue(int32_t index); -void HALSIM_SetAnalogInAccumulatorValue(int32_t index, - int64_t accumulatorValue); - -int32_t HALSIM_RegisterAnalogInAccumulatorCountCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInAccumulatorCountCallback(int32_t index, int32_t uid); -int64_t HALSIM_GetAnalogInAccumulatorCount(int32_t index); -void HALSIM_SetAnalogInAccumulatorCount(int32_t index, - int64_t accumulatorCount); - -int32_t HALSIM_RegisterAnalogInAccumulatorCenterCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInAccumulatorCenterCallback(int32_t index, int32_t uid); -int32_t HALSIM_GetAnalogInAccumulatorCenter(int32_t index); -void HALSIM_SetAnalogInAccumulatorCenter(int32_t index, - int32_t accumulatorCenter); - -int32_t HALSIM_RegisterAnalogInAccumulatorDeadbandCallback( - int32_t index, HAL_NotifyCallback callback, void* param, - HAL_Bool initialNotify); -void HALSIM_CancelAnalogInAccumulatorDeadbandCallback(int32_t index, - int32_t uid); -int32_t HALSIM_GetAnalogInAccumulatorDeadband(int32_t index); -void HALSIM_SetAnalogInAccumulatorDeadband(int32_t index, - int32_t accumulatorDeadband); - void HALSIM_RegisterAnalogInAllCallbacks(int32_t index, HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify); diff --git a/hal/src/main/native/sim/AnalogAccumulator.cpp b/hal/src/main/native/sim/AnalogAccumulator.cpp deleted file mode 100644 index 0f65b13a9c4..00000000000 --- a/hal/src/main/native/sim/AnalogAccumulator.cpp +++ /dev/null @@ -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" diff --git a/hal/src/main/native/sim/AnalogGyro.cpp b/hal/src/main/native/sim/AnalogGyro.cpp deleted file mode 100644 index 3efca200e7b..00000000000 --- a/hal/src/main/native/sim/AnalogGyro.cpp +++ /dev/null @@ -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 - -#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* analogGyroHandles; - -namespace hal::init { -void InitializeAnalogGyro() { - static IndexedHandleResource - 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" diff --git a/hal/src/main/native/sim/AnalogInput.cpp b/hal/src/main/native/sim/AnalogInput.cpp index 4697dc24930..40cbe07306c 100644 --- a/hal/src/main/native/sim/AnalogInput.cpp +++ b/hal/src/main/native/sim/AnalogInput.cpp @@ -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(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) { diff --git a/hal/src/main/native/sim/HAL.cpp b/hal/src/main/native/sim/HAL.cpp index 84ce262ff19..d69422e9375 100644 --- a/hal/src/main/native/sim/HAL.cpp +++ b/hal/src/main/native/sim/HAL.cpp @@ -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(); diff --git a/hal/src/main/native/sim/HALInitializer.h b/hal/src/main/native/sim/HALInitializer.h index ce76bb0ff25..4ccc10e8786 100644 --- a/hal/src/main/native/sim/HALInitializer.h +++ b/hal/src/main/native/sim/HALInitializer.h @@ -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(); diff --git a/hal/src/main/native/sim/Ports.cpp b/hal/src/main/native/sim/Ports.cpp index 9219b04b7f3..271c19e9031 100644 --- a/hal/src/main/native/sim/Ports.cpp +++ b/hal/src/main/native/sim/Ports.cpp @@ -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; } diff --git a/hal/src/main/native/sim/mockdata/AnalogGyroData.cpp b/hal/src/main/native/sim/mockdata/AnalogGyroData.cpp deleted file mode 100644 index bb4e278d7e7..00000000000 --- a/hal/src/main/native/sim/mockdata/AnalogGyroData.cpp +++ /dev/null @@ -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" diff --git a/hal/src/main/native/sim/mockdata/AnalogGyroDataInternal.h b/hal/src/main/native/sim/mockdata/AnalogGyroDataInternal.h deleted file mode 100644 index d88c56de158..00000000000 --- a/hal/src/main/native/sim/mockdata/AnalogGyroDataInternal.h +++ /dev/null @@ -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 angle{0.0}; - SimDataValue rate{0.0}; - SimDataValue initialized{ - false}; - - virtual void ResetData(); -}; -extern AnalogGyroData* SimAnalogGyroData; -} // namespace hal diff --git a/hal/src/main/native/sim/mockdata/AnalogInData.cpp b/hal/src/main/native/sim/mockdata/AnalogInData.cpp index a93cad00a2e..ebe22757c68 100644 --- a/hal/src/main/native/sim/mockdata/AnalogInData.cpp +++ b/hal/src/main/native/sim/mockdata/AnalogInData.cpp @@ -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" diff --git a/hal/src/main/native/sim/mockdata/AnalogInDataInternal.h b/hal/src/main/native/sim/mockdata/AnalogInDataInternal.h index 953c8f82d18..8986d16850f 100644 --- a/hal/src/main/native/sim/mockdata/AnalogInDataInternal.h +++ b/hal/src/main/native/sim/mockdata/AnalogInDataInternal.h @@ -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 initialized{ @@ -26,16 +21,6 @@ class AnalogInData { SimDataValue averageBits{7}; SimDataValue oversampleBits{0}; SimDataValue voltage{0.0}; - SimDataValue - accumulatorInitialized{false}; - SimDataValue accumulatorValue{ - 0}; - SimDataValue accumulatorCount{ - 0}; - SimDataValue - accumulatorCenter{0}; - SimDataValue - accumulatorDeadband{0}; virtual void ResetData(); }; diff --git a/hal/src/main/native/sim/mockdata/Reset.cpp b/hal/src/main/native/sim/mockdata/Reset.cpp index cb43ba3a504..776aeafdf08 100644 --- a/hal/src/main/native/sim/mockdata/Reset.cpp +++ b/hal/src/main/native/sim/mockdata/Reset.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -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); } diff --git a/hal/src/main/native/systemcore/AnalogAccumulator.cpp b/hal/src/main/native/systemcore/AnalogAccumulator.cpp deleted file mode 100644 index 312c6561fc7..00000000000 --- a/hal/src/main/native/systemcore/AnalogAccumulator.cpp +++ /dev/null @@ -1,65 +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 "hal/HAL.h" - -using namespace hal; - -namespace hal::init { -void InitializeAnalogAccumulator() {} -} // namespace hal::init - -extern "C" { - -HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return false; -} - -void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle, - int32_t center, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle, - int32_t deadband, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle, - int64_t* value, int64_t* count, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -} // extern "C" diff --git a/hal/src/main/native/systemcore/AnalogGyro.cpp b/hal/src/main/native/systemcore/AnalogGyro.cpp deleted file mode 100644 index bfcfd42b8bf..00000000000 --- a/hal/src/main/native/systemcore/AnalogGyro.cpp +++ /dev/null @@ -1,92 +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 -#include -#include - -#include - -#include "HALInitializer.h" -#include "HALInternal.h" -#include "hal/AnalogAccumulator.h" -#include "hal/AnalogInput.h" -#include "hal/handles/IndexedHandleResource.h" - -using namespace hal; - -namespace hal::init { -void InitializeAnalogGyro() {} -} // namespace hal::init - -extern "C" { - -HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle analogHandle, - const char* allocationLocation, - int32_t* status) { - hal::init::CheckInit(); - *status = HAL_HANDLE_ERROR; - return HAL_kInvalidHandle; -} - -void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {} - -void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle, - double voltsPerDegreePerSecond, double offset, - int32_t center, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle, - double voltsPerDegreePerSecond, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts, - int32_t* status) { - *status = HAL_HANDLE_ERROR; - return; -} - -double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -int32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status) { - *status = HAL_HANDLE_ERROR; - return 0; -} - -} // extern "C" diff --git a/hal/src/main/native/systemcore/AnalogInput.cpp b/hal/src/main/native/systemcore/AnalogInput.cpp index 24555e4ad2b..4cc8ca0ab97 100644 --- a/hal/src/main/native/systemcore/AnalogInput.cpp +++ b/hal/src/main/native/systemcore/AnalogInput.cpp @@ -13,7 +13,6 @@ #include "HALInternal.h" #include "PortsInternal.h" #include "SmartIo.h" -#include "hal/AnalogAccumulator.h" #include "hal/Errors.h" #include "hal/cpp/fpga_clock.h" #include "hal/handles/HandlesInternal.h" diff --git a/hal/src/main/native/systemcore/DMA.cpp b/hal/src/main/native/systemcore/DMA.cpp index b470ea70b4c..653b40e0217 100644 --- a/hal/src/main/native/systemcore/DMA.cpp +++ b/hal/src/main/native/systemcore/DMA.cpp @@ -13,8 +13,6 @@ #include #include "PortsInternal.h" -#include "hal/AnalogAccumulator.h" -#include "hal/AnalogGyro.h" #include "hal/AnalogInput.h" #include "hal/Errors.h" #include "hal/HALBase.h" diff --git a/hal/src/main/native/systemcore/HAL.cpp b/hal/src/main/native/systemcore/HAL.cpp index e4c9d9b8953..4afdf94d3b9 100644 --- a/hal/src/main/native/systemcore/HAL.cpp +++ b/hal/src/main/native/systemcore/HAL.cpp @@ -50,8 +50,6 @@ void InitializeHAL() { InitializeREVPH(); InitializeAddressableLED(); InitializeAccelerometer(); - InitializeAnalogAccumulator(); - InitializeAnalogGyro(); InitializeAnalogInput(); InitializeAnalogTrigger(); InitializeCAN(); diff --git a/hal/src/main/native/systemcore/HALInitializer.h b/hal/src/main/native/systemcore/HALInitializer.h index 72930340806..848ef0e84a9 100644 --- a/hal/src/main/native/systemcore/HALInitializer.h +++ b/hal/src/main/native/systemcore/HALInitializer.h @@ -20,8 +20,6 @@ extern void InitializeCTREPCM(); extern void InitializeREVPH(); extern void InitializeAccelerometer(); extern void InitializeAddressableLED(); -extern void InitializeAnalogAccumulator(); -extern void InitializeAnalogGyro(); extern void InitializeAnalogInput(); extern void InitializeAnalogInternal(); extern void InitializeAnalogTrigger(); diff --git a/hal/src/main/native/systemcore/Ports.cpp b/hal/src/main/native/systemcore/Ports.cpp index a302709bd8f..670f18fdb16 100644 --- a/hal/src/main/native/systemcore/Ports.cpp +++ b/hal/src/main/native/systemcore/Ports.cpp @@ -13,10 +13,6 @@ void InitializePorts() {} } // namespace hal::init extern "C" { - -int32_t HAL_GetNumAccumulators(void) { - return kNumAccumulators; -} int32_t HAL_GetNumAnalogTriggers(void) { return kNumAnalogTriggers; } diff --git a/hal/src/main/native/systemcore/mockdata/AnalogGyroData.cpp b/hal/src/main/native/systemcore/mockdata/AnalogGyroData.cpp deleted file mode 100644 index b4ff695deaf..00000000000 --- a/hal/src/main/native/systemcore/mockdata/AnalogGyroData.cpp +++ /dev/null @@ -1,23 +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/simulation/AnalogGyroData.h" - -#include "hal/simulation/SimDataValue.h" - -extern "C" { -void HALSIM_ResetAnalogGyroData(int32_t index) {} - -#define DEFINE_CAPI(TYPE, CAPINAME, RETURN) \ - HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, AnalogGyro##CAPINAME, RETURN) - -DEFINE_CAPI(double, Angle, 0) -DEFINE_CAPI(double, Rate, 0) -DEFINE_CAPI(HAL_Bool, Initialized, false) - -void HALSIM_RegisterAnalogGyroAllCallbacks(int32_t index, - HAL_NotifyCallback callback, - void* param, - HAL_Bool initialNotify) {} -} // extern "C" diff --git a/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp b/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp index 30ac79561f2..eaa79c49264 100644 --- a/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp +++ b/hal/src/main/native/systemcore/mockdata/AnalogInData.cpp @@ -20,11 +20,6 @@ DEFINE_CAPI(HAL_Bool, Initialized, false) DEFINE_CAPI(int32_t, AverageBits, 0) DEFINE_CAPI(int32_t, OversampleBits, 0) DEFINE_CAPI(double, Voltage, 0) -DEFINE_CAPI(HAL_Bool, AccumulatorInitialized, false) -DEFINE_CAPI(int64_t, AccumulatorValue, 0) -DEFINE_CAPI(int64_t, AccumulatorCount, 0) -DEFINE_CAPI(int32_t, AccumulatorCenter, 0) -DEFINE_CAPI(int32_t, AccumulatorDeadband, 0) void HALSIM_RegisterAnalogInAllCallbacks(int32_t index, HAL_NotifyCallback callback, diff --git a/simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.cpp b/simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.cpp deleted file mode 100644 index 62c064661b2..00000000000 --- a/simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.cpp +++ /dev/null @@ -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 -#include - -#include -#include -#include -#include -#include - -#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 func) - override; - - private: - // indexed by channel - std::vector> m_models; -}; -} // namespace - -void AnalogGyrosSimModel::Update() { - for (int32_t i = 0, iend = static_cast(m_models.size()); i < iend; - ++i) { - auto& model = m_models[i]; - if (HALSIM_GetAnalogGyroInitialized(i)) { - if (!model) { - model = std::make_unique(i); - } - } else { - model.reset(); - } - } -} - -void AnalogGyrosSimModel::ForEachAnalogGyro( - wpi::function_ref func) { - for (int32_t i = 0, iend = static_cast(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(), [](glass::Model* model) { - glass::DisplayAnalogGyrosDevice( - static_cast(model)); - }); -} diff --git a/simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.h b/simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.h deleted file mode 100644 index 89f91ca7d09..00000000000 --- a/simulation/halsim_gui/src/main/native/cpp/AnalogGyroSimGui.h +++ /dev/null @@ -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 diff --git a/simulation/halsim_gui/src/main/native/cpp/AnalogInputSimGui.cpp b/simulation/halsim_gui/src/main/native/cpp/AnalogInputSimGui.cpp index dfefe5051c4..954d4f240b3 100644 --- a/simulation/halsim_gui/src/main/native/cpp/AnalogInputSimGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/AnalogInputSimGui.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -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); diff --git a/simulation/halsim_gui/src/main/native/cpp/main.cpp b/simulation/halsim_gui/src/main/native/cpp/main.cpp index de844b5c631..2a5f57a9c24 100644 --- a/simulation/halsim_gui/src/main/native/cpp/main.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/main.cpp @@ -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(); diff --git a/simulation/halsim_ws_core/doc/hardware_ws_api.md b/simulation/halsim_ws_core/doc/hardware_ws_api.md index 0197eb71ab0..2fca74a0c17 100644 --- a/simulation/halsim_ws_core/doc/hardware_ws_api.md +++ b/simulation/halsim_ws_core/doc/hardware_ws_api.md @@ -132,11 +132,6 @@ The basic analog input just reads a voltage. An analog input can also be configu | ``"voltage"`` | Float | Input voltage, in volts | -| ``"accum_value"`` | Integer | The accumulated value | -| ``">accum_count"`` | Integer | The number of accumulated values | -| ``"voltage": type: number description: "Input voltage, in volts" - "accum_value": - type: integer - description: "The accumulated value" - ">accum_count": - type: integer - description: "The number of accumulated values" - "(param)->ProcessHalCallback( \ - {{jsonid, static_cast(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, "voltage", double, double); - - m_accumInitCbKey = - REGISTER_AIN_ACCUM(Initialized, "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, "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 diff --git a/simulation/halsim_ws_core/src/main/native/include/WSProvider_Analog.h b/simulation/halsim_ws_core/src/main/native/include/WSProvider_Analog.h index 1b8f0ef3443..a8091c8153c 100644 --- a/simulation/halsim_ws_core/src/main/native/include/WSProvider_Analog.h +++ b/simulation/halsim_ws_core/src/main/native/include/WSProvider_Analog.h @@ -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 diff --git a/wpilibc/src/main/native/cpp/AnalogGyro.cpp b/wpilibc/src/main/native/cpp/AnalogGyro.cpp deleted file mode 100644 index 6362b45b41a..00000000000 --- a/wpilibc/src/main/native/cpp/AnalogGyro.cpp +++ /dev/null @@ -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 -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "frc/AnalogInput.h" -#include "frc/Errors.h" - -using namespace frc; - -AnalogGyro::AnalogGyro(int channel) - : AnalogGyro(std::make_shared(channel)) { - wpi::SendableRegistry::AddChild(this, m_analog.get()); -} - -AnalogGyro::AnalogGyro(AnalogInput* channel) - : AnalogGyro(std::shared_ptr( - channel, wpi::NullDeleter())) {} - -AnalogGyro::AnalogGyro(std::shared_ptr 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(channel), center, offset) { - wpi::SendableRegistry::AddChild(this, m_analog.get()); -} - -AnalogGyro::AnalogGyro(std::shared_ptr 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 AnalogGyro::GetAnalogInput() const { - return m_analog; -} - -void AnalogGyro::InitSendable(wpi::SendableBuilder& builder) { - builder.SetSmartDashboardType("Gyro"); - builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr); -} diff --git a/wpilibc/src/main/native/cpp/AnalogInput.cpp b/wpilibc/src/main/native/cpp/AnalogInput.cpp index 15e28ceeffc..188ddb74994 100644 --- a/wpilibc/src/main/native/cpp/AnalogInput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogInput.cpp @@ -6,7 +6,6 @@ #include -#include #include #include #include @@ -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); diff --git a/wpilibc/src/main/native/cpp/simulation/AnalogGyroSim.cpp b/wpilibc/src/main/native/cpp/simulation/AnalogGyroSim.cpp deleted file mode 100644 index 5e630edf16c..00000000000 --- a/wpilibc/src/main/native/cpp/simulation/AnalogGyroSim.cpp +++ /dev/null @@ -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 - -#include - -#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 AnalogGyroSim::RegisterAngleCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - 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 AnalogGyroSim::RegisterRateCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - 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 AnalogGyroSim::RegisterInitializedCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - 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); -} diff --git a/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp b/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp index aae5c0a6292..bff8cefc23c 100644 --- a/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/AnalogInputSim.cpp @@ -86,95 +86,6 @@ void AnalogInputSim::SetVoltage(double voltage) { HALSIM_SetAnalogInVoltage(m_index, voltage); } -std::unique_ptr -AnalogInputSim::RegisterAccumulatorInitializedCallback(NotifyCallback callback, - bool initialNotify) { - auto store = std::make_unique( - 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 AnalogInputSim::RegisterAccumulatorValueCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - 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 AnalogInputSim::RegisterAccumulatorCountCallback( - NotifyCallback callback, bool initialNotify) { - auto store = std::make_unique( - 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 -AnalogInputSim::RegisterAccumulatorCenterCallback(NotifyCallback callback, - bool initialNotify) { - auto store = std::make_unique( - 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 -AnalogInputSim::RegisterAccumulatorDeadbandCallback(NotifyCallback callback, - bool initialNotify) { - auto store = std::make_unique( - 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); } diff --git a/wpilibc/src/main/native/include/frc/AnalogGyro.h b/wpilibc/src/main/native/include/frc/AnalogGyro.h index a822eea33b8..6a2d259b77a 100644 --- a/wpilibc/src/main/native/include/frc/AnalogGyro.h +++ b/wpilibc/src/main/native/include/frc/AnalogGyro.h @@ -6,7 +6,6 @@ #include -#include #include #include #include @@ -33,19 +32,13 @@ class AnalogInput; class AnalogGyro : public wpi::Sendable, public wpi::SendableHelper { 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 channel); + explicit AnalogGyro(std::shared_ptr 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 channel, int center, double offset); + AnalogGyro(std::shared_ptr 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 GetAnalogInput() const; - - void InitSendable(wpi::SendableBuilder& builder) override; + std::shared_ptr GetAnalogInput() const { return nullptr; } - private: - std::shared_ptr m_analog; - hal::Handle m_gyroHandle; + void InitSendable(wpi::SendableBuilder& builder) override {} }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/AnalogInput.h b/wpilibc/src/main/native/include/frc/AnalogInput.h index 8e46126771b..237f26d6550 100644 --- a/wpilibc/src/main/native/include/frc/AnalogInput.h +++ b/wpilibc/src/main/native/include/frc/AnalogInput.h @@ -31,15 +31,10 @@ class DMASample; class AnalogInput : public wpi::Sendable, public wpi::SendableHelper { 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 m_port; - int64_t m_accumulatorOffset; }; } // namespace frc diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h deleted file mode 100644 index 0210818b628..00000000000 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h +++ /dev/null @@ -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 - -#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 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 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 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 diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h index 05c9898d919..75e8092d95b 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h @@ -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 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 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 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 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 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. */ diff --git a/wpilibc/src/test/native/cpp/simulation/AnalogGyroSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/AnalogGyroSimTest.cpp deleted file mode 100644 index 6352491d36e..00000000000 --- a/wpilibc/src/test/native/cpp/simulation/AnalogGyroSimTest.cpp +++ /dev/null @@ -1,88 +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" // NOLINT(build/include_order) - -#include - -#include -#include - -#include "callback_helpers/TestCallbackHelpers.h" -#include "frc/AnalogGyro.h" -#include "frc/AnalogInput.h" - -namespace frc::sim { - -TEST(AnalogGyroSimTest, InitializeGyro) { - HAL_Initialize(500, 0); - AnalogGyroSim sim{0}; - EXPECT_FALSE(sim.GetInitialized()); - - BooleanCallback initializedCallback; - - auto cb = - sim.RegisterInitializedCallback(initializedCallback.GetCallback(), false); - AnalogGyro gyro(0); - EXPECT_TRUE(sim.GetInitialized()); - EXPECT_TRUE(initializedCallback.WasTriggered()); - EXPECT_TRUE(initializedCallback.GetLastValue()); -} - -TEST(AnalogGyroSimTest, SetAngle) { - HAL_Initialize(500, 0); - - AnalogGyroSim sim{0}; - DoubleCallback callback; - - AnalogInput ai(0); - AnalogGyro gyro(&ai); - auto cb = sim.RegisterAngleCallback(callback.GetCallback(), false); - EXPECT_EQ(0, gyro.GetAngle()); - - constexpr double kTestAngle = 35.04; - sim.SetAngle(kTestAngle); - EXPECT_EQ(kTestAngle, sim.GetAngle()); - EXPECT_EQ(kTestAngle, gyro.GetAngle()); - EXPECT_EQ(-kTestAngle, gyro.GetRotation2d().Degrees().value()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(kTestAngle, callback.GetLastValue()); -} - -TEST(AnalogGyroSimTest, SetRate) { - HAL_Initialize(500, 0); - - AnalogGyroSim sim{0}; - DoubleCallback callback; - - std::shared_ptr ai(new AnalogInput(0)); - AnalogGyro gyro(ai); - auto cb = sim.RegisterRateCallback(callback.GetCallback(), false); - EXPECT_EQ(0, gyro.GetRate()); - - constexpr double kTestRate = -19.1; - sim.SetRate(kTestRate); - EXPECT_EQ(kTestRate, sim.GetRate()); - EXPECT_EQ(kTestRate, gyro.GetRate()); - - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(kTestRate, callback.GetLastValue()); -} - -TEST(AnalogGyroSimTest, Reset) { - HAL_Initialize(500, 0); - - AnalogInput ai{0}; - AnalogGyro gyro(&ai); - AnalogGyroSim sim(gyro); - sim.SetAngle(12.34); - sim.SetRate(43.21); - - sim.ResetData(); - EXPECT_EQ(0, sim.GetAngle()); - EXPECT_EQ(0, sim.GetRate()); - EXPECT_EQ(0, gyro.GetAngle()); - EXPECT_EQ(0, gyro.GetRate()); -} -} // namespace frc::sim diff --git a/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp index 2f963fa34e5..42faf7efe29 100644 --- a/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/AnalogInputSimTest.cpp @@ -92,97 +92,4 @@ TEST(AnalogInputSimTest, SetAverageBits) { EXPECT_EQ(3504, callback.GetLastValue()); } -TEST(AnalogInputSimTest, InitAccumulator) { - HAL_Initialize(500, 0); - AnalogInput input{0}; - AnalogInputSim sim(input); - - BooleanCallback callback; - auto cb = - sim.RegisterAccumulatorInitializedCallback(callback.GetCallback(), false); - - input.InitAccumulator(); - input.ResetAccumulator(); - EXPECT_TRUE(sim.GetAccumulatorInitialized()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_TRUE(callback.GetLastValue()); -} - -TEST(AnalogInputSimTest, InitAccumulatorOnInvalidPort) { - HAL_Initialize(500, 0); - AnalogInput input{5}; - AnalogInputSim sim(input); - - BooleanCallback callback; - auto cb = - sim.RegisterAccumulatorInitializedCallback(callback.GetCallback(), false); - - EXPECT_THROW(input.InitAccumulator(), std::runtime_error); - EXPECT_FALSE(callback.WasTriggered()); -} - -TEST(AnalogInputSimTest, SetAccumulatorValue) { - HAL_Initialize(500, 0); - AnalogInput input{0}; - AnalogInputSim sim(input); - - LongCallback callback; - auto cb = sim.RegisterAccumulatorValueCallback(callback.GetCallback(), false); - - input.InitAccumulator(); - sim.SetAccumulatorValue(3504191229); - EXPECT_EQ(3504191229, sim.GetAccumulatorValue()); - EXPECT_EQ(3504191229, input.GetAccumulatorValue()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(3504191229, callback.GetLastValue()); -} - -TEST(AnalogInputSimTest, SetAccumulatorCount) { - HAL_Initialize(500, 0); - AnalogInput input{0}; - AnalogInputSim sim(input); - - LongCallback callback; - auto cb = sim.RegisterAccumulatorCountCallback(callback.GetCallback(), false); - - input.InitAccumulator(); - sim.SetAccumulatorCount(3504191229); - EXPECT_EQ(3504191229, sim.GetAccumulatorCount()); - EXPECT_EQ(3504191229, input.GetAccumulatorCount()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(3504191229, callback.GetLastValue()); -} - -TEST(AnalogInputSimTest, SetAccumulatorDeadband) { - HAL_Initialize(500, 0); - AnalogInput input{0}; - AnalogInputSim sim(input); - - IntCallback callback; - auto cb = - sim.RegisterAccumulatorDeadbandCallback(callback.GetCallback(), false); - - input.InitAccumulator(); - input.SetAccumulatorDeadband(3504); - EXPECT_EQ(3504, sim.GetAccumulatorDeadband()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(3504, callback.GetLastValue()); -} - -TEST(AnalogInputSimTest, SetAccumulatorCenter) { - HAL_Initialize(500, 0); - AnalogInput input{0}; - AnalogInputSim sim(input); - - IntCallback callback; - auto cb = - sim.RegisterAccumulatorCenterCallback(callback.GetCallback(), false); - - input.InitAccumulator(); - input.SetAccumulatorCenter(3504); - EXPECT_EQ(3504, sim.GetAccumulatorCenter()); - EXPECT_TRUE(callback.WasTriggered()); - EXPECT_EQ(3504, callback.GetLastValue()); -} - } // namespace frc::sim diff --git a/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp b/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp index 4cd61cf62d2..7c850b3017f 100644 --- a/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/SimInitializationTest.cpp @@ -8,7 +8,6 @@ #include #include "frc/simulation/AddressableLEDSim.h" -#include "frc/simulation/AnalogGyroSim.h" #include "frc/simulation/AnalogInputSim.h" #include "frc/simulation/AnalogTriggerSim.h" #include "frc/simulation/BuiltInAccelerometerSim.h" @@ -27,7 +26,6 @@ using namespace frc::sim; TEST(SimInitializationTest, AllInitialize) { HAL_Initialize(500, 0); BuiltInAccelerometerSim biacsim; - AnalogGyroSim agsim{0}; AnalogInputSim aisim{0}; EXPECT_THROW(AnalogTriggerSim::CreateForChannel(0), std::out_of_range); EXPECT_THROW(DigitalPWMSim::CreateForChannel(0), std::out_of_range); diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp index 178267f1a8f..9d7e28102d2 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp @@ -124,7 +124,7 @@ void Drivetrain::SimulationPeriodic() { m_rightEncoderSim.SetDistance( m_drivetrainSimulator.GetRightPosition().value()); m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value()); - m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value()); + // m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value()); } void Drivetrain::Periodic() { diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h index 633571ef173..724a79fb908 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -165,7 +164,6 @@ class Drivetrain { frc::SimpleMotorFeedforward m_feedforward{1_V, 3_V / 1_mps}; // Simulation classes - frc::sim::AnalogGyroSim m_gyroSim{m_gyro}; frc::sim::EncoderSim m_leftEncoderSim{m_leftEncoder}; frc::sim::EncoderSim m_rightEncoderSim{m_rightEncoder}; frc::Field2d m_fieldSim; diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp index 603facaa2f0..38606156ea2 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp @@ -52,7 +52,7 @@ void Drivetrain::SimulationPeriodic() { m_rightEncoderSim.SetDistance( m_drivetrainSimulator.GetRightPosition().value()); m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value()); - m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value()); + // m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value()); } void Drivetrain::Periodic() { diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h index ca82547f7cb..09974806e53 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -100,7 +99,6 @@ class Drivetrain { frc::SimpleMotorFeedforward m_feedforward{1_V, 3_V / 1_mps}; // Simulation classes help us simulate our robot - frc::sim::AnalogGyroSim m_gyroSim{m_gyro}; frc::sim::EncoderSim m_leftEncoderSim{m_leftEncoder}; frc::sim::EncoderSim m_rightEncoderSim{m_rightEncoder}; frc::Field2d m_fieldSim; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java index 29a17bbed0e..1628bf78785 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogGyro.java @@ -6,7 +6,6 @@ import static edu.wpi.first.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.math.geometry.Rotation2d; @@ -24,20 +23,11 @@ *

This class is for gyro sensors that connect to an analog input. */ public class AnalogGyro implements Sendable, AutoCloseable { - private static final double kDefaultVoltsPerDegreePerSecond = 0.007; private AnalogInput m_analog; private boolean m_channelAllocated; - private int m_gyroHandle; - /** Initialize the gyro. Calibration is handled by calibrate(). */ private void initGyro() { - if (m_gyroHandle == 0) { - m_gyroHandle = AnalogGyroJNI.initializeAnalogGyro(m_analog.m_port); - } - - AnalogGyroJNI.setupAnalogGyro(m_gyroHandle); - HAL.report(tResourceType.kResourceType_Gyro, m_analog.getChannel() + 1); SendableRegistry.addLW(this, "AnalogGyro", m_analog.getChannel()); } @@ -50,9 +40,7 @@ private void initGyro() { * are in progress, this is typically done when the robot is first turned on while it's sitting at * rest before the competition starts. */ - public void calibrate() { - AnalogGyroJNI.calibrateAnalogGyro(m_gyroHandle); - } + public void calibrate() {} /** * Return the heading of the robot as a {@link edu.wpi.first.math.geometry.Rotation2d}. @@ -126,15 +114,12 @@ public AnalogGyro(int channel, int center, double offset) { * @param center Preset uncalibrated value to use as the accumulator center value. * @param offset Preset uncalibrated value to use as the gyro offset. */ - @SuppressWarnings("this-escape") + @SuppressWarnings({"this-escape", "PMD.UnusedFormalParameter"}) public AnalogGyro(AnalogInput channel, int center, double offset) { requireNonNullParam(channel, "channel", "AnalogGyro"); m_analog = channel; initGyro(); - AnalogGyroJNI.setAnalogGyroParameters( - m_gyroHandle, kDefaultVoltsPerDegreePerSecond, - offset, center); reset(); } @@ -144,9 +129,7 @@ public AnalogGyro(AnalogInput channel, int center, double offset) { *

Resets the gyro to a heading of zero. This can be used if there is significant drift in the * gyro, and it needs to be recalibrated after it has been running. */ - public void reset() { - AnalogGyroJNI.resetAnalogGyro(m_gyroHandle); - } + public void reset() {} /** Delete (free) the accumulator and the analog components used for the gyro. */ @Override @@ -156,7 +139,6 @@ public void close() { m_analog.close(); } m_analog = null; - AnalogGyroJNI.freeAnalogGyro(m_gyroHandle); } /** @@ -174,11 +156,7 @@ public void close() { * @return the current heading of the robot in degrees. */ public double getAngle() { - if (m_analog == null) { - return 0.0; - } else { - return AnalogGyroJNI.getAnalogGyroAngle(m_gyroHandle); - } + return 0.0; } /** @@ -192,11 +170,7 @@ public double getAngle() { * @return the current rate in degrees per second */ public double getRate() { - if (m_analog == null) { - return 0.0; - } else { - return AnalogGyroJNI.getAnalogGyroRate(m_gyroHandle); - } + return 0.0; } /** @@ -205,7 +179,7 @@ public double getRate() { * @return the current offset value */ public double getOffset() { - return AnalogGyroJNI.getAnalogGyroOffset(m_gyroHandle); + return 0.0; } /** @@ -214,7 +188,7 @@ public double getOffset() { * @return the current center value */ public int getCenter() { - return AnalogGyroJNI.getAnalogGyroCenter(m_gyroHandle); + return 0; } /** @@ -224,9 +198,7 @@ public int getCenter() { * * @param voltsPerDegreePerSecond The sensitivity in Volts/degree/second. */ - public void setSensitivity(double voltsPerDegreePerSecond) { - AnalogGyroJNI.setAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle, voltsPerDegreePerSecond); - } + public void setSensitivity(double voltsPerDegreePerSecond) {} /** * Set the size of the neutral zone. Any voltage from the gyro less than this amount from the @@ -235,9 +207,7 @@ public void setSensitivity(double voltsPerDegreePerSecond) { * * @param volts The size of the deadband in volts */ - public void setDeadband(double volts) { - AnalogGyroJNI.setAnalogGyroDeadband(m_gyroHandle, volts); - } + public void setDeadband(double volts) {} /** * Gets the analog input for the gyro. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java index 3c6458bfad4..e3a786bc951 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java @@ -4,12 +4,10 @@ package edu.wpi.first.wpilibj; -import edu.wpi.first.hal.AccumulatorResult; import edu.wpi.first.hal.AnalogJNI; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; import edu.wpi.first.hal.SimDevice; -import edu.wpi.first.hal.util.AllocationException; import edu.wpi.first.util.sendable.Sendable; import edu.wpi.first.util.sendable.SendableBuilder; import edu.wpi.first.util.sendable.SendableRegistry; @@ -27,11 +25,8 @@ * number of samples to retain the resolution, but get more stable values. */ public class AnalogInput implements Sendable, AutoCloseable { - private static final int kAccumulatorSlot = 1; int m_port; // explicit no modifier, private and package accessible. private int m_channel; - private static final int[] kAccumulatorChannels = {0, 1}; - private long m_accumulatorOffset; /** * Construct an analog channel. @@ -56,7 +51,6 @@ public void close() { AnalogJNI.freeAnalogInputPort(m_port); m_port = 0; m_channel = 0; - m_accumulatorOffset = 0; } /** @@ -181,127 +175,6 @@ public int getOversampleBits() { return AnalogJNI.getAnalogOversampleBits(m_port); } - /** Initialize the accumulator. */ - public void initAccumulator() { - if (!isAccumulatorChannel()) { - throw new AllocationException( - "Accumulators are only available on slot " - + kAccumulatorSlot - + " on channels " - + kAccumulatorChannels[0] - + ", " - + kAccumulatorChannels[1]); - } - m_accumulatorOffset = 0; - AnalogJNI.initAccumulator(m_port); - } - - /** - * Set an initial value for the accumulator. - * - *

This will be added to all values returned to the user. - * - * @param initialValue The value that the accumulator should start from when reset. - */ - public void setAccumulatorInitialValue(long initialValue) { - m_accumulatorOffset = initialValue; - } - - /** Resets the accumulator to the initial value. */ - public void resetAccumulator() { - AnalogJNI.resetAccumulator(m_port); - - // Wait until the next sample, so the next call to getAccumulator*() - // won't have old values. - final double sampleTime = 1.0 / getGlobalSampleRate(); - final double overSamples = 1 << getOversampleBits(); - final double averageSamples = 1 << getAverageBits(); - Timer.delay(sampleTime * overSamples * averageSamples); - } - - /** - * 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 the - * accumulator channel. Because of this, any non-zero oversample bits will affect the size of the - * value for this field. - * - * @param center The accumulator's center value. - */ - public void setAccumulatorCenter(int center) { - AnalogJNI.setAccumulatorCenter(m_port, center); - } - - /** - * Set the accumulator's deadband. - * - * @param deadband The deadband size in ADC codes (12-bit value) - */ - public void setAccumulatorDeadband(int deadband) { - AnalogJNI.setAccumulatorDeadband(m_port, 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(). - */ - public long getAccumulatorValue() { - return AnalogJNI.getAccumulatorValue(m_port) + m_accumulatorOffset; - } - - /** - * 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. - */ - public long getAccumulatorCount() { - return AnalogJNI.getAccumulatorCount(m_port); - } - - /** - * 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 result AccumulatorResult object to store the results in. - */ - public void getAccumulatorOutput(AccumulatorResult result) { - if (result == null) { - throw new IllegalArgumentException("Null parameter `result'"); - } - if (!isAccumulatorChannel()) { - throw new IllegalArgumentException( - "Channel " + m_channel + " is not an accumulator channel."); - } - AnalogJNI.getAccumulatorOutput(m_port, result); - result.value += m_accumulatorOffset; - } - - /** - * Is the channel attached to an accumulator. - * - * @return The analog channel is attached to an accumulator. - */ - public boolean isAccumulatorChannel() { - for (int channel : kAccumulatorChannels) { - if (m_channel == channel) { - return true; - } - } - return false; - } - /** * Set the sample rate per channel. * diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java deleted file mode 100644 index 33712f312f3..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java +++ /dev/null @@ -1,127 +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.simulation; - -import edu.wpi.first.hal.simulation.AnalogGyroDataJNI; -import edu.wpi.first.hal.simulation.NotifyCallback; -import edu.wpi.first.wpilibj.AnalogGyro; - -/** Class to control a simulated analog gyro. */ -public class AnalogGyroSim { - private final int m_index; - - /** - * Constructs from an AnalogGyro object. - * - * @param gyro AnalogGyro to simulate - */ - public AnalogGyroSim(AnalogGyro gyro) { - m_index = gyro.getAnalogInput().getChannel(); - } - - /** - * Constructs from an analog input channel number. - * - * @param channel Channel number - */ - public AnalogGyroSim(int channel) { - m_index = 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerAngleCallback(NotifyCallback callback, boolean initialNotify) { - int uid = AnalogGyroDataJNI.registerAngleCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogGyroDataJNI::cancelAngleCallback); - } - - /** - * Get the current angle of the gyro. - * - * @return the angle measured by the gyro - */ - public double getAngle() { - return AnalogGyroDataJNI.getAngle(m_index); - } - - /** - * Change the angle measured by the gyro. - * - * @param angle the new value - */ - public void setAngle(double angle) { - AnalogGyroDataJNI.setAngle(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerRateCallback(NotifyCallback callback, boolean initialNotify) { - int uid = AnalogGyroDataJNI.registerRateCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogGyroDataJNI::cancelRateCallback); - } - - /** - * Get the rate of angle change on this gyro. - * - * @return the rate - */ - public double getRate() { - return AnalogGyroDataJNI.getRate(m_index); - } - - /** - * Change the rate of the gyro. - * - * @param rate the new rate - */ - public void setRate(double rate) { - AnalogGyroDataJNI.setRate(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { - int uid = AnalogGyroDataJNI.registerInitializedCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogGyroDataJNI::cancelInitializedCallback); - } - - /** - * Check if the gyro is initialized. - * - * @return true if initialized - */ - public boolean getInitialized() { - return AnalogGyroDataJNI.getInitialized(m_index); - } - - /** - * Set whether this gyro is initialized. - * - * @param initialized the new value - */ - public void setInitialized(boolean initialized) { - AnalogGyroDataJNI.setInitialized(m_index, initialized); - } - - /** Reset all simulation data for this object. */ - public void resetData() { - AnalogGyroDataJNI.resetData(m_index); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java index 2f045b75ddf..7c98386df23 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java @@ -151,162 +151,6 @@ public void setVoltage(double voltage) { AnalogInDataJNI.setVoltage(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerAccumulatorInitializedCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = - AnalogInDataJNI.registerAccumulatorInitializedCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAccumulatorInitializedCallback); - } - - /** - * Check if the accumulator has been initialized. - * - * @return true if initialized - */ - public boolean getAccumulatorInitialized() { - return AnalogInDataJNI.getAccumulatorInitialized(m_index); - } - - /** - * Change whether the accumulator has been initialized. - * - * @param accumulatorInitialized the new value - */ - public void setAccumulatorInitialized(boolean accumulatorInitialized) { - AnalogInDataJNI.setAccumulatorInitialized(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerAccumulatorValueCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = AnalogInDataJNI.registerAccumulatorValueCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAccumulatorValueCallback); - } - - /** - * Get the accumulator value. - * - * @return the accumulator value - */ - public long getAccumulatorValue() { - return AnalogInDataJNI.getAccumulatorValue(m_index); - } - - /** - * Change the accumulator value. - * - * @param accumulatorValue the new value - */ - public void setAccumulatorValue(long accumulatorValue) { - AnalogInDataJNI.setAccumulatorValue(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerAccumulatorCountCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = AnalogInDataJNI.registerAccumulatorCountCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAccumulatorCountCallback); - } - - /** - * Get the accumulator count. - * - * @return the accumulator count. - */ - public long getAccumulatorCount() { - return AnalogInDataJNI.getAccumulatorCount(m_index); - } - - /** - * Change the accumulator count. - * - * @param accumulatorCount the new count. - */ - public void setAccumulatorCount(long accumulatorCount) { - AnalogInDataJNI.setAccumulatorCount(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerAccumulatorCenterCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = AnalogInDataJNI.registerAccumulatorCenterCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAccumulatorCenterCallback); - } - - /** - * Get the accumulator center. - * - * @return the accumulator center - */ - public int getAccumulatorCenter() { - return AnalogInDataJNI.getAccumulatorCenter(m_index); - } - - /** - * Change the accumulator center. - * - * @param accumulatorCenter the new center - */ - public void setAccumulatorCenter(int accumulatorCenter) { - AnalogInDataJNI.setAccumulatorCenter(m_index, 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 {@link CallbackStore} object associated with this callback. - */ - public CallbackStore registerAccumulatorDeadbandCallback( - NotifyCallback callback, boolean initialNotify) { - int uid = AnalogInDataJNI.registerAccumulatorDeadbandCallback(m_index, callback, initialNotify); - return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAccumulatorDeadbandCallback); - } - - /** - * Get the accumulator deadband. - * - * @return the accumulator deadband - */ - public int getAccumulatorDeadband() { - return AnalogInDataJNI.getAccumulatorDeadband(m_index); - } - - /** - * Change the accumulator deadband. - * - * @param accumulatorDeadband the new deadband - */ - public void setAccumulatorDeadband(int accumulatorDeadband) { - AnalogInDataJNI.setAccumulatorDeadband(m_index, accumulatorDeadband); - } - /** Reset all simulation data for this object. */ public void resetData() { AnalogInDataJNI.resetData(m_index); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/AnalogGyroTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/AnalogGyroTest.java deleted file mode 100644 index daae493e530..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/AnalogGyroTest.java +++ /dev/null @@ -1,38 +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 static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.simulation.AnalogGyroSim; -import org.junit.jupiter.api.Test; - -class AnalogGyroTest { - @Test - void testInitializeWithAnalogInput() { - HAL.initialize(500, 0); - AnalogGyroSim sim = new AnalogGyroSim(0); - assertFalse(sim.getInitialized()); - - try (AnalogInput ai = new AnalogInput(0); - AnalogGyro gyro = new AnalogGyro(ai, 229, 17.4)) { - assertEquals(ai, gyro.getAnalogInput()); - } - } - - @Test - void testInitializeWithChannel() { - HAL.initialize(500, 0); - AnalogGyroSim sim = new AnalogGyroSim(0); - assertFalse(sim.getInitialized()); - - try (AnalogGyro gyro = new AnalogGyro(1, 191, 35.04)) { - assertNotNull(gyro.getAnalogInput()); - } - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSimTest.java deleted file mode 100644 index 5ce5093bfd7..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSimTest.java +++ /dev/null @@ -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. - -package edu.wpi.first.wpilibj.simulation; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import edu.wpi.first.hal.HAL; -import edu.wpi.first.wpilibj.AnalogGyro; -import edu.wpi.first.wpilibj.AnalogInput; -import edu.wpi.first.wpilibj.simulation.testutils.BooleanCallback; -import edu.wpi.first.wpilibj.simulation.testutils.DoubleCallback; -import org.junit.jupiter.api.Test; - -class AnalogGyroSimTest { - @Test - void testInitialization() { - HAL.initialize(500, 0); - AnalogGyroSim sim = new AnalogGyroSim(0); - assertFalse(sim.getInitialized()); - - BooleanCallback initializedCallback = new BooleanCallback(); - - try (CallbackStore cb = sim.registerInitializedCallback(initializedCallback, false); - AnalogInput ai = new AnalogInput(0); - AnalogGyro gyro = new AnalogGyro(ai)) { - assertTrue(sim.getInitialized()); - assertTrue(initializedCallback.wasTriggered()); - assertTrue(initializedCallback.getSetValue()); - } - } - - @Test - void testSetAngle() { - HAL.initialize(500, 0); - - AnalogGyroSim sim = new AnalogGyroSim(0); - DoubleCallback callback = new DoubleCallback(); - - try (AnalogInput ai = new AnalogInput(0); - AnalogGyro gyro = new AnalogGyro(ai); - CallbackStore cb = sim.registerAngleCallback(callback, false)) { - assertEquals(0, gyro.getAngle()); - - final double TEST_ANGLE = 35.04; - sim.setAngle(TEST_ANGLE); - assertEquals(TEST_ANGLE, sim.getAngle()); - assertEquals(TEST_ANGLE, gyro.getAngle()); - assertEquals(-TEST_ANGLE, gyro.getRotation2d().getDegrees()); - assertTrue(callback.wasTriggered()); - assertEquals(TEST_ANGLE, callback.getSetValue()); - } - } - - @Test - void testSetRate() { - HAL.initialize(500, 0); - - AnalogGyroSim sim = new AnalogGyroSim(0); - DoubleCallback callback = new DoubleCallback(); - - try (AnalogInput ai = new AnalogInput(0); - AnalogGyro gyro = new AnalogGyro(ai); - CallbackStore cb = sim.registerRateCallback(callback, false)) { - assertEquals(0, gyro.getRate()); - - final double TEST_RATE = -19.1; - sim.setRate(TEST_RATE); - assertEquals(TEST_RATE, sim.getRate()); - assertEquals(TEST_RATE, gyro.getRate()); - - assertTrue(callback.wasTriggered()); - assertEquals(TEST_RATE, callback.getSetValue()); - } - } - - @Test - void testReset() { - HAL.initialize(500, 0); - - try (AnalogInput ai = new AnalogInput(0); - AnalogGyro gyro = new AnalogGyro(ai)) { - AnalogGyroSim sim = new AnalogGyroSim(gyro); - sim.setAngle(12.34); - sim.setRate(43.21); - - sim.resetData(); - assertEquals(0, sim.getAngle()); - assertEquals(0, sim.getRate()); - assertEquals(0, gyro.getAngle()); - assertEquals(0, gyro.getRate()); - } - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogInputSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogInputSimTest.java index ada4ebf346c..f87cf827568 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogInputSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/AnalogInputSimTest.java @@ -4,13 +4,10 @@ package edu.wpi.first.wpilibj.simulation; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import edu.wpi.first.hal.HAL; -import edu.wpi.first.hal.util.AllocationException; import edu.wpi.first.wpilibj.AnalogInput; import edu.wpi.first.wpilibj.simulation.testutils.BooleanCallback; import edu.wpi.first.wpilibj.simulation.testutils.DoubleCallback; @@ -64,23 +61,4 @@ void testSetOverSampleBits() { assertEquals(3504, input.getOversampleBits()); } } - - @Test - void tesInitAccumulator() { - HAL.initialize(500, 0); - try (AnalogInput input = new AnalogInput(0)) { - // First initialization works fine - assertDoesNotThrow(input::initAccumulator); - - input.resetAccumulator(); - } - } - - @Test - void tesInitAccumulatorOnInvalidPort() { - HAL.initialize(500, 0); - try (AnalogInput input = new AnalogInput(5)) { - assertThrows(AllocationException.class, input::initAccumulator); - } - } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java index fbf6e90b9c9..e1e0607100f 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/differentialdriveposeestimator/Drivetrain.java @@ -32,7 +32,6 @@ import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; -import edu.wpi.first.wpilibj.simulation.AnalogGyroSim; import edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim; import edu.wpi.first.wpilibj.simulation.EncoderSim; import edu.wpi.first.wpilibj.smartdashboard.Field2d; @@ -91,7 +90,6 @@ public class Drivetrain { private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); // Simulation classes - private final AnalogGyroSim m_gyroSim = new AnalogGyroSim(m_gyro); private final EncoderSim m_leftEncoderSim = new EncoderSim(m_leftEncoder); private final EncoderSim m_rightEncoderSim = new EncoderSim(m_rightEncoder); private final LinearSystem m_drivetrainSystem = @@ -257,7 +255,7 @@ public void simulationPeriodic() { m_leftEncoderSim.setRate(m_drivetrainSimulator.getLeftVelocityMetersPerSecond()); m_rightEncoderSim.setDistance(m_drivetrainSimulator.getRightPositionMeters()); m_rightEncoderSim.setRate(m_drivetrainSimulator.getRightVelocityMetersPerSecond()); - m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); + // m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); } /** This function is called periodically, no matter the mode. */ diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java index d0d1ed4dcdc..5045aac3e64 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java @@ -19,7 +19,6 @@ import edu.wpi.first.wpilibj.Encoder; import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; -import edu.wpi.first.wpilibj.simulation.AnalogGyroSim; import edu.wpi.first.wpilibj.simulation.DifferentialDrivetrainSim; import edu.wpi.first.wpilibj.simulation.EncoderSim; import edu.wpi.first.wpilibj.smartdashboard.Field2d; @@ -59,7 +58,6 @@ public class Drivetrain { private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); // Simulation classes help us simulate our robot - private final AnalogGyroSim m_gyroSim = new AnalogGyroSim(m_gyro); private final EncoderSim m_leftEncoderSim = new EncoderSim(m_leftEncoder); private final EncoderSim m_rightEncoderSim = new EncoderSim(m_rightEncoder); private final Field2d m_fieldSim = new Field2d(); @@ -148,7 +146,7 @@ public void simulationPeriodic() { m_leftEncoderSim.setRate(m_drivetrainSimulator.getLeftVelocityMetersPerSecond()); m_rightEncoderSim.setDistance(m_drivetrainSimulator.getRightPositionMeters()); m_rightEncoderSim.setRate(m_drivetrainSimulator.getRightVelocityMetersPerSecond()); - m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); + // m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); } /** Update odometry - this should be run every robot loop. */