[hal, wpilib] Remove analog accumulator and analog gyro (#7697)

The 2 high level classes were temporarily kept to keep the examples compiling. We will remove those when we have the interface into the built in IMU.
This commit is contained in:
Thad House
2025-01-17 12:58:31 -08:00
committed by GitHub
parent 92f0a3c961
commit f80874dd4b
76 changed files with 33 additions and 3886 deletions

View File

@@ -1,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 <wpi/StringExtras.h>
#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); });
}

View File

@@ -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();

View File

@@ -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 <wpi/function_ref.h>
#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<void(AnalogGyroModel& model, int index)> func) = 0;
};
void DisplayAnalogGyroDevice(AnalogGyroModel* model, int index);
void DisplayAnalogGyrosDevice(AnalogGyrosModel* model);
} // namespace glass

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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() {}
}

View File

@@ -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 class AnalogJNI extends JNIWrapper {
*/
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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*

View File

@@ -137,29 +137,6 @@ public class DMAJNISample {
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) {

View File

@@ -10,14 +10,6 @@ package edu.wpi.first.hal;
* @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.
*

View File

@@ -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() {}
}

View File

@@ -44,51 +44,6 @@ public class AnalogInDataJNI extends JNIWrapper {
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. */

View File

@@ -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 <jni.h>
#include <cassert>
#include <wpi/jni_util.h>
#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"

View File

@@ -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

View File

@@ -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<jint>(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<jlong>(value),
static_cast<jlong>(count));
}
jbyteArray SetCANDataObject(JNIEnv* env, jobject canData, int32_t length,
uint64_t timestamp) {
static jmethodID func = env->GetMethodID(canDataCls, "setData", "(IJ)[B");

View File

@@ -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);

View File

@@ -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

View File

@@ -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 <jni.h>
#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"

View File

@@ -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

View File

@@ -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 <stdint.h>
#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
/** @} */

View File

@@ -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 <stdint.h>
#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
/** @} */

View File

@@ -7,8 +7,6 @@
#include <stdint.h>
#include "hal/Accelerometer.h"
#include "hal/AnalogAccumulator.h"
#include "hal/AnalogGyro.h"
#include "hal/AnalogInput.h"
#include "hal/AnalogTrigger.h"
#include "hal/CAN.h"

View File

@@ -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.
*

View File

@@ -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

View File

@@ -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);

View File

@@ -1,109 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "hal/AnalogAccumulator.h"
#include "AnalogInternal.h"
#include "mockdata/AnalogInDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeAnalogAccumulator() {}
} // namespace hal::init
extern "C" {
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
}
for (int32_t i = 0; i < kNumAccumulators; i++) {
if (port->channel == kAccumulatorChannels[i]) {
return true;
}
}
return false;
}
void HAL_InitAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
if (!HAL_IsAccumulatorChannel(analogPortHandle, status)) {
*status = HAL_INVALID_ACCUMULATOR_CHANNEL;
return;
}
SimAnalogInData[port->channel].accumulatorInitialized = true;
}
void HAL_ResetAccumulator(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogInData[port->channel].accumulatorCenter = 0;
SimAnalogInData[port->channel].accumulatorCount = 0;
SimAnalogInData[port->channel].accumulatorValue = 0;
}
void HAL_SetAccumulatorCenter(HAL_AnalogInputHandle analogPortHandle,
int32_t center, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogInData[port->channel].accumulatorCenter = center;
}
void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analogPortHandle,
int32_t deadband, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimAnalogInData[port->channel].accumulatorDeadband = deadband;
}
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return SimAnalogInData[port->channel].accumulatorValue;
}
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
return SimAnalogInData[port->channel].accumulatorCount;
}
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analogPortHandle,
int64_t* value, int64_t* count, int32_t* status) {
auto port = analogInputHandles->Get(analogPortHandle);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
*count = SimAnalogInData[port->channel].accumulatorCount;
*value = SimAnalogInData[port->channel].accumulatorValue;
}
} // extern "C"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,48 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "../PortsInternal.h"
#include "AnalogGyroDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializeAnalogGyroData() {
static AnalogGyroData agd[kNumAccumulators];
::hal::SimAnalogGyroData = agd;
}
} // namespace hal::init
AnalogGyroData* hal::SimAnalogGyroData;
void AnalogGyroData::ResetData() {
angle.Reset(0.0);
rate.Reset(0.0);
initialized.Reset(false);
}
extern "C" {
void HALSIM_ResetAnalogGyroData(int32_t index) {
SimAnalogGyroData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, AnalogGyro##CAPINAME, \
SimAnalogGyroData, LOWERNAME)
DEFINE_CAPI(double, Angle, angle)
DEFINE_CAPI(double, Rate, rate)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
#define REGISTER(NAME) \
SimAnalogGyroData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterAnalogGyroAllCallbacks(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
REGISTER(angle);
REGISTER(rate);
REGISTER(initialized);
}
} // extern "C"

View File

@@ -1,25 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include "hal/simulation/AnalogGyroData.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class AnalogGyroData {
HAL_SIMDATAVALUE_DEFINE_NAME(Angle)
HAL_SIMDATAVALUE_DEFINE_NAME(Rate)
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
public:
SimDataValue<double, HAL_MakeDouble, GetAngleName> angle{0.0};
SimDataValue<double, HAL_MakeDouble, GetRateName> rate{0.0};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
false};
virtual void ResetData();
};
extern AnalogGyroData* SimAnalogGyroData;
} // namespace hal

View File

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

View File

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

View File

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

View File

@@ -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"

View File

@@ -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 <cmath>
#include <string>
#include <thread>
#include <wpi/print.h>
#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"

View File

@@ -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"

View File

@@ -13,8 +13,6 @@
#include <wpi/print.h>
#include "PortsInternal.h"
#include "hal/AnalogAccumulator.h"
#include "hal/AnalogGyro.h"
#include "hal/AnalogInput.h"
#include "hal/Errors.h"
#include "hal/HALBase.h"

View File

@@ -50,8 +50,6 @@ void InitializeHAL() {
InitializeREVPH();
InitializeAddressableLED();
InitializeAccelerometer();
InitializeAnalogAccumulator();
InitializeAnalogGyro();
InitializeAnalogInput();
InitializeAnalogTrigger();
InitializeCAN();

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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"

View File

@@ -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,

View File

@@ -1,97 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "AnalogGyroSimGui.h"
#include <memory>
#include <vector>
#include <glass/hardware/AnalogGyro.h>
#include <glass/other/DeviceTree.h>
#include <hal/Ports.h>
#include <hal/Value.h>
#include <hal/simulation/AnalogGyroData.h>
#include "HALDataSource.h"
#include "HALSimGui.h"
#include "SimDeviceGui.h"
using namespace halsimgui;
namespace {
HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(AnalogGyroAngle, "AGyro Angle");
HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(AnalogGyroRate, "AGyro Rate");
class AnalogGyroSimModel : public glass::AnalogGyroModel {
public:
explicit AnalogGyroSimModel(int32_t index)
: m_index{index}, m_angle{index}, m_rate{index} {}
void Update() override {}
bool Exists() override { return HALSIM_GetAnalogGyroInitialized(m_index); }
glass::DoubleSource* GetAngleData() override { return &m_angle; }
glass::DoubleSource* GetRateData() override { return &m_rate; }
void SetAngle(double val) override {
HALSIM_SetAnalogGyroAngle(m_index, val);
}
void SetRate(double val) override { HALSIM_SetAnalogGyroRate(m_index, val); }
private:
int32_t m_index;
AnalogGyroAngleSource m_angle;
AnalogGyroRateSource m_rate;
};
class AnalogGyrosSimModel : public glass::AnalogGyrosModel {
public:
AnalogGyrosSimModel() : m_models(HAL_GetNumAccumulators()) {}
void Update() override;
bool Exists() override { return true; }
void ForEachAnalogGyro(
wpi::function_ref<void(glass::AnalogGyroModel& model, int index)> func)
override;
private:
// indexed by channel
std::vector<std::unique_ptr<AnalogGyroSimModel>> m_models;
};
} // namespace
void AnalogGyrosSimModel::Update() {
for (int32_t i = 0, iend = static_cast<int32_t>(m_models.size()); i < iend;
++i) {
auto& model = m_models[i];
if (HALSIM_GetAnalogGyroInitialized(i)) {
if (!model) {
model = std::make_unique<AnalogGyroSimModel>(i);
}
} else {
model.reset();
}
}
}
void AnalogGyrosSimModel::ForEachAnalogGyro(
wpi::function_ref<void(glass::AnalogGyroModel& model, int index)> func) {
for (int32_t i = 0, iend = static_cast<int32_t>(m_models.size()); i < iend;
++i) {
if (auto model = m_models[i].get()) {
func(*model, i);
}
}
}
void AnalogGyroSimGui::Initialize() {
SimDeviceGui::GetDeviceTree().Add(
std::make_unique<AnalogGyrosSimModel>(), [](glass::Model* model) {
glass::DisplayAnalogGyrosDevice(
static_cast<AnalogGyrosSimModel*>(model));
});
}

View File

@@ -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

View File

@@ -10,7 +10,6 @@
#include <glass/View.h>
#include <glass/hardware/AnalogInput.h>
#include <hal/Ports.h>
#include <hal/simulation/AnalogGyroData.h>
#include <hal/simulation/AnalogInData.h>
#include <hal/simulation/SimDeviceData.h>
@@ -31,11 +30,6 @@ class AnalogInputSimModel : public glass::AnalogInputModel {
bool Exists() override { return HALSIM_GetAnalogInInitialized(m_index); }
bool IsGyro() const override {
return m_index < HAL_GetNumAccumulators() &&
HALSIM_GetAnalogGyroInitialized(m_index);
}
const char* GetSimDevice() const override {
if (auto simDevice = HALSIM_GetAnalogInSimDevice(m_index)) {
return HALSIM_GetSimDeviceName(simDevice);

View File

@@ -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();

View File

@@ -132,11 +132,6 @@ The basic analog input just reads a voltage. An analog input can also be configu
| ``"<avg_bits"`` | Integer | The number of averaging bits |
| ``"<oversample_bits"`` | Integer | The number of oversampling bits |
| ``">voltage"`` | Float | Input voltage, in volts |
| ``"<accum_init"`` | Boolean | If the accumulator is initialized in the robot program |
| ``">accum_value"`` | Integer | The accumulated value |
| ``">accum_count"`` | Integer | The number of accumulated values |
| ``"<accum_center"`` | Integer | The center value of the accumulator |
| ``"<accum_deadband"`` | Integer | The accumulator's deadband |
#### Analog Output ("AO")

View File

@@ -170,21 +170,6 @@ components:
">voltage":
type: number
description: "Input voltage, in volts"
"<accum_init":
type: boolean
description: "If the accumulator is initialized in the robot program"
">accum_value":
type: integer
description: "The accumulated value"
">accum_count":
type: integer
description: "The number of accumulated values"
"<accum_center":
type: integer
description: "The center value of the accumulator"
"<accum_deadband":
type: integer
description: "The accumulator's deadband"
aoData:
type: object

View File

@@ -16,15 +16,6 @@
}, \
this, true)
#define REGISTER_AIN_ACCUM(halsim, jsonid, ctype, haltype) \
HALSIM_RegisterAnalogInAccumulator##halsim##Callback( \
m_channel, \
[](const char* name, void* param, const struct HAL_Value* value) { \
static_cast<HALSimWSProviderAnalogIn*>(param)->ProcessHalCallback( \
{{jsonid, static_cast<ctype>(value->data.v_##haltype)}}); \
}, \
this, true)
namespace wpilibws {
void HALSimWSProviderAnalogIn::Initialize(WSRegisterFunc webRegisterFunc) {
@@ -42,17 +33,6 @@ void HALSimWSProviderAnalogIn::RegisterCallbacks() {
m_oversampleCbKey =
REGISTER_AIN(OversampleBits, "<oversample_bits", int32_t, int);
m_voltageCbKey = REGISTER_AIN(Voltage, ">voltage", double, double);
m_accumInitCbKey =
REGISTER_AIN_ACCUM(Initialized, "<accum_init", bool, boolean);
m_accumValueCbKey = REGISTER_AIN_ACCUM(Value, ">accum_value", int64_t,
long); // NOLINT(runtime/int)
m_accumCountCbKey = REGISTER_AIN_ACCUM(Count, ">accum_count", int64_t,
long); // NOLINT(runtime/int)
m_accumCenterCbKey =
REGISTER_AIN_ACCUM(Center, "<accum_center", int32_t, int);
m_accumDeadbandCbKey =
REGISTER_AIN_ACCUM(Deadband, "<accum_deadband", int32_t, int);
}
void HALSimWSProviderAnalogIn::CancelCallbacks() {
@@ -65,24 +45,12 @@ void HALSimWSProviderAnalogIn::DoCancelCallbacks() {
HALSIM_CancelAnalogInAverageBitsCallback(m_channel, m_avgbitsCbKey);
HALSIM_CancelAnalogInOversampleBitsCallback(m_channel, m_oversampleCbKey);
HALSIM_CancelAnalogInVoltageCallback(m_channel, m_voltageCbKey);
HALSIM_CancelAnalogInAccumulatorInitializedCallback(m_channel,
m_accumInitCbKey);
HALSIM_CancelAnalogInAccumulatorValueCallback(m_channel, m_accumValueCbKey);
HALSIM_CancelAnalogInAccumulatorCountCallback(m_channel, m_accumCountCbKey);
HALSIM_CancelAnalogInAccumulatorCenterCallback(m_channel, m_accumCenterCbKey);
HALSIM_CancelAnalogInAccumulatorDeadbandCallback(m_channel,
m_accumDeadbandCbKey);
// Reset callback IDs
m_initCbKey = 0;
m_avgbitsCbKey = 0;
m_oversampleCbKey = 0;
m_voltageCbKey = 0;
m_accumInitCbKey = 0;
m_accumValueCbKey = 0;
m_accumCountCbKey = 0;
m_accumCenterCbKey = 0;
m_accumDeadbandCbKey = 0;
}
void HALSimWSProviderAnalogIn::OnNetValueChanged(const wpi::json& json) {
@@ -90,12 +58,6 @@ void HALSimWSProviderAnalogIn::OnNetValueChanged(const wpi::json& json) {
if ((it = json.find(">voltage")) != json.end()) {
HALSIM_SetAnalogInVoltage(m_channel, it.value());
}
if ((it = json.find(">accum_value")) != json.end()) {
HALSIM_SetAnalogInAccumulatorValue(m_channel, it.value());
}
if ((it = json.find(">accum_count")) != json.end()) {
HALSIM_SetAnalogInAccumulatorCount(m_channel, it.value());
}
}
} // namespace wpilibws

View File

@@ -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

View File

@@ -1,143 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/AnalogGyro.h"
#include <climits>
#include <memory>
#include <string>
#include <hal/AnalogGyro.h>
#include <hal/Errors.h>
#include <hal/FRCUsageReporting.h>
#include <wpi/NullDeleter.h>
#include <wpi/StackTrace.h>
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc/AnalogInput.h"
#include "frc/Errors.h"
using namespace frc;
AnalogGyro::AnalogGyro(int channel)
: AnalogGyro(std::make_shared<AnalogInput>(channel)) {
wpi::SendableRegistry::AddChild(this, m_analog.get());
}
AnalogGyro::AnalogGyro(AnalogInput* channel)
: AnalogGyro(std::shared_ptr<AnalogInput>(
channel, wpi::NullDeleter<AnalogInput>())) {}
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel)
: m_analog(channel) {
if (!channel) {
throw FRC_MakeError(err::NullParameter, "channel");
}
InitGyro();
Calibrate();
}
AnalogGyro::AnalogGyro(int channel, int center, double offset)
: AnalogGyro(std::make_shared<AnalogInput>(channel), center, offset) {
wpi::SendableRegistry::AddChild(this, m_analog.get());
}
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
double offset)
: m_analog(channel) {
if (!channel) {
throw FRC_MakeError(err::NullParameter, "channel");
}
InitGyro();
int32_t status = 0;
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
offset, center, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
Reset();
}
double AnalogGyro::GetAngle() const {
int32_t status = 0;
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
return value;
}
double AnalogGyro::GetRate() const {
int32_t status = 0;
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
return value;
}
int AnalogGyro::GetCenter() const {
int32_t status = 0;
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
return value;
}
double AnalogGyro::GetOffset() const {
int32_t status = 0;
double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
return value;
}
void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) {
int32_t status = 0;
HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle,
voltsPerDegreePerSecond, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
}
void AnalogGyro::SetDeadband(double volts) {
int32_t status = 0;
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
}
void AnalogGyro::Reset() {
int32_t status = 0;
HAL_ResetAnalogGyro(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
}
void AnalogGyro::InitGyro() {
if (m_gyroHandle == HAL_kInvalidHandle) {
int32_t status = 0;
std::string stackTrace = wpi::GetStackTrace(1);
m_gyroHandle =
HAL_InitializeAnalogGyro(m_analog->m_port, stackTrace.c_str(), &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
}
int32_t status = 0;
HAL_SetupAnalogGyro(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
HAL_Report(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel() + 1);
wpi::SendableRegistry::AddLW(this, "AnalogGyro", m_analog->GetChannel());
}
void AnalogGyro::Calibrate() {
int32_t status = 0;
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_analog->GetChannel());
}
Rotation2d AnalogGyro::GetRotation2d() const {
return units::degree_t{-GetAngle()};
}
std::shared_ptr<AnalogInput> AnalogGyro::GetAnalogInput() const {
return m_analog;
}
void AnalogGyro::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Gyro");
builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr);
}

View File

@@ -6,7 +6,6 @@
#include <string>
#include <hal/AnalogAccumulator.h>
#include <hal/AnalogInput.h>
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
@@ -111,70 +110,6 @@ int AnalogInput::GetOffset() const {
return offset;
}
bool AnalogInput::IsAccumulatorChannel() const {
int32_t status = 0;
bool isAccum = HAL_IsAccumulatorChannel(m_port, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
return isAccum;
}
void AnalogInput::InitAccumulator() {
m_accumulatorOffset = 0;
int32_t status = 0;
HAL_InitAccumulator(m_port, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
}
void AnalogInput::SetAccumulatorInitialValue(int64_t initialValue) {
m_accumulatorOffset = initialValue;
}
void AnalogInput::ResetAccumulator() {
int32_t status = 0;
HAL_ResetAccumulator(m_port, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
// Wait until the next sample, so the next call to GetAccumulator*()
// won't have old values.
const double sampleTime = 1.0 / GetSampleRate();
const double overSamples = 1 << GetOversampleBits();
const double averageSamples = 1 << GetAverageBits();
Wait(units::second_t{sampleTime * overSamples * averageSamples});
}
void AnalogInput::SetAccumulatorCenter(int center) {
int32_t status = 0;
HAL_SetAccumulatorCenter(m_port, center, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
}
void AnalogInput::SetAccumulatorDeadband(int deadband) {
int32_t status = 0;
HAL_SetAccumulatorDeadband(m_port, deadband, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
}
int64_t AnalogInput::GetAccumulatorValue() const {
int32_t status = 0;
int64_t value = HAL_GetAccumulatorValue(m_port, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
return value + m_accumulatorOffset;
}
int64_t AnalogInput::GetAccumulatorCount() const {
int32_t status = 0;
int64_t count = HAL_GetAccumulatorCount(m_port, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
return count;
}
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
int32_t status = 0;
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
value += m_accumulatorOffset;
}
void AnalogInput::SetSampleRate(double samplesPerSecond) {
int32_t status = 0;
HAL_SetAnalogSampleRate(samplesPerSecond, &status);

View File

@@ -1,75 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/AnalogGyroSim.h"
#include <memory>
#include <hal/simulation/AnalogGyroData.h>
#include "frc/AnalogGyro.h"
#include "frc/AnalogInput.h"
using namespace frc;
using namespace frc::sim;
AnalogGyroSim::AnalogGyroSim(const AnalogGyro& gyro)
: m_index{gyro.GetAnalogInput()->GetChannel()} {}
AnalogGyroSim::AnalogGyroSim(int channel) : m_index{channel} {}
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterAngleCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroAngleCallback);
store->SetUid(HALSIM_RegisterAnalogGyroAngleCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogGyroSim::GetAngle() const {
return HALSIM_GetAnalogGyroAngle(m_index);
}
void AnalogGyroSim::SetAngle(double angle) {
HALSIM_SetAnalogGyroAngle(m_index, angle);
}
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterRateCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroRateCallback);
store->SetUid(HALSIM_RegisterAnalogGyroRateCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double AnalogGyroSim::GetRate() const {
return HALSIM_GetAnalogGyroRate(m_index);
}
void AnalogGyroSim::SetRate(double rate) {
HALSIM_SetAnalogGyroRate(m_index, rate);
}
std::unique_ptr<CallbackStore> AnalogGyroSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogGyroInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogGyroInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogGyroSim::GetInitialized() const {
return HALSIM_GetAnalogGyroInitialized(m_index);
}
void AnalogGyroSim::SetInitialized(bool initialized) {
HALSIM_SetAnalogGyroInitialized(m_index, initialized);
}
void AnalogGyroSim::ResetData() {
HALSIM_ResetAnalogGyroData(m_index);
}

View File

@@ -86,95 +86,6 @@ void AnalogInputSim::SetVoltage(double voltage) {
HALSIM_SetAnalogInVoltage(m_index, voltage);
}
std::unique_ptr<CallbackStore>
AnalogInputSim::RegisterAccumulatorInitializedCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback,
&HALSIM_CancelAnalogInAccumulatorInitializedCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool AnalogInputSim::GetAccumulatorInitialized() const {
return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
}
void AnalogInputSim::SetAccumulatorInitialized(bool accumulatorInitialized) {
HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAccumulatorValueCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int64_t AnalogInputSim::GetAccumulatorValue() const {
return HALSIM_GetAnalogInAccumulatorValue(m_index);
}
void AnalogInputSim::SetAccumulatorValue(int64_t accumulatorValue) {
HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
}
std::unique_ptr<CallbackStore> AnalogInputSim::RegisterAccumulatorCountCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int64_t AnalogInputSim::GetAccumulatorCount() const {
return HALSIM_GetAnalogInAccumulatorCount(m_index);
}
void AnalogInputSim::SetAccumulatorCount(int64_t accumulatorCount) {
HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
}
std::unique_ptr<CallbackStore>
AnalogInputSim::RegisterAccumulatorCenterCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AnalogInputSim::GetAccumulatorCenter() const {
return HALSIM_GetAnalogInAccumulatorCenter(m_index);
}
void AnalogInputSim::SetAccumulatorCenter(int accumulatorCenter) {
HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
}
std::unique_ptr<CallbackStore>
AnalogInputSim::RegisterAccumulatorDeadbandCallback(NotifyCallback callback,
bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
int AnalogInputSim::GetAccumulatorDeadband() const {
return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
}
void AnalogInputSim::SetAccumulatorDeadband(int accumulatorDeadband) {
HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
}
void AnalogInputSim::ResetData() {
HALSIM_ResetAnalogInData(m_index);
}

View File

@@ -6,7 +6,6 @@
#include <memory>
#include <hal/AnalogGyro.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -33,19 +32,13 @@ class AnalogInput;
class AnalogGyro : public wpi::Sendable,
public wpi::SendableHelper<AnalogGyro> {
public:
static constexpr int kOversampleBits = 10;
static constexpr int kAverageBits = 0;
static constexpr double kSamplesPerSecond = 50.0;
static constexpr double kCalibrationSampleTime = 5.0;
static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
/**
* %Gyro constructor using the Analog Input channel number.
*
* @param channel The analog channel the gyro is connected to. Gyros can only
* be used on on-board Analog Inputs 0-1.
*/
explicit AnalogGyro(int channel);
explicit AnalogGyro(int channel) {}
/**
* Gyro constructor with a precreated AnalogInput object.
@@ -59,7 +52,7 @@ class AnalogGyro : public wpi::Sendable,
* @param channel A pointer to the AnalogInput object that the gyro is
* connected to.
*/
explicit AnalogGyro(AnalogInput* channel);
explicit AnalogGyro(AnalogInput* channel) {}
/**
* %Gyro constructor with a precreated AnalogInput object.
@@ -71,7 +64,7 @@ class AnalogGyro : public wpi::Sendable,
* @param channel A pointer to the AnalogInput object that the gyro is
* connected to.
*/
explicit AnalogGyro(std::shared_ptr<AnalogInput> channel);
explicit AnalogGyro(std::shared_ptr<AnalogInput> channel) {}
/**
* %Gyro constructor using the Analog Input channel number with parameters for
@@ -83,7 +76,7 @@ class AnalogGyro : public wpi::Sendable,
* value.
* @param offset Preset uncalibrated value to use as the gyro offset.
*/
AnalogGyro(int channel, int center, double offset);
AnalogGyro(int channel, int center, double offset) {}
/**
* %Gyro constructor with a precreated AnalogInput object and calibrated
@@ -99,7 +92,7 @@ class AnalogGyro : public wpi::Sendable,
* value.
* @param offset Preset uncalibrated value to use as the gyro offset.
*/
AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset) {}
AnalogGyro(AnalogGyro&& rhs) = default;
AnalogGyro& operator=(AnalogGyro&& rhs) = default;
@@ -118,7 +111,7 @@ class AnalogGyro : public wpi::Sendable,
* @return The current heading of the robot in degrees. This heading is based
* on integration of the returned rate from the gyro.
*/
double GetAngle() const;
double GetAngle() const { return 0; }
/**
* Return the rate of rotation of the gyro
@@ -127,7 +120,7 @@ class AnalogGyro : public wpi::Sendable,
*
* @return the current rate in degrees per second
*/
double GetRate() const;
double GetRate() const { return 0; }
/**
* Return the gyro center value. If run after calibration,
@@ -135,7 +128,7 @@ class AnalogGyro : public wpi::Sendable,
*
* @return the current center value
*/
virtual int GetCenter() const;
virtual int GetCenter() const { return 0; }
/**
* Return the gyro offset value. If run after calibration,
@@ -143,7 +136,7 @@ class AnalogGyro : public wpi::Sendable,
*
* @return the current offset value
*/
virtual double GetOffset() const;
virtual double GetOffset() const { return 0; }
/**
* Set the gyro sensitivity.
@@ -154,7 +147,7 @@ class AnalogGyro : public wpi::Sendable,
*
* @param voltsPerDegreePerSecond The sensitivity in Volts/degree/second
*/
void SetSensitivity(double voltsPerDegreePerSecond);
void SetSensitivity(double voltsPerDegreePerSecond) {}
/**
* Set the size of the neutral zone.
@@ -165,7 +158,7 @@ class AnalogGyro : public wpi::Sendable,
*
* @param volts The size of the deadband in volts
*/
void SetDeadband(double volts);
void SetDeadband(double volts) {}
/**
* Reset the gyro.
@@ -174,14 +167,14 @@ class AnalogGyro : public wpi::Sendable,
* significant drift in the gyro and it needs to be recalibrated after it has
* been running.
*/
void Reset();
void Reset() {}
/**
* Initialize the gyro.
*
* Calibration is handled by Calibrate().
*/
void InitGyro();
void InitGyro() {}
/**
* Calibrate the gyro by running for a number of samples and computing the
@@ -193,7 +186,7 @@ class AnalogGyro : public wpi::Sendable,
* robot is first turned on while it's sitting at rest before the competition
* starts.
*/
void Calibrate();
void Calibrate() {}
/**
* Return the heading of the robot as a Rotation2d.
@@ -208,20 +201,16 @@ class AnalogGyro : public wpi::Sendable,
* @return the current heading of the robot as a Rotation2d. This heading is
* based on integration of the returned rate from the gyro.
*/
Rotation2d GetRotation2d() const;
Rotation2d GetRotation2d() const { return {}; }
/**
* Gets the analog input for the gyro.
*
* @return AnalogInput
*/
std::shared_ptr<AnalogInput> GetAnalogInput() const;
std::shared_ptr<AnalogInput> GetAnalogInput() const { return nullptr; }
void InitSendable(wpi::SendableBuilder& builder) override;
private:
std::shared_ptr<AnalogInput> m_analog;
hal::Handle<HAL_GyroHandle, HAL_FreeAnalogGyro> m_gyroHandle;
void InitSendable(wpi::SendableBuilder& builder) override {}
};
} // namespace frc

View File

@@ -31,15 +31,10 @@ class DMASample;
class AnalogInput : public wpi::Sendable,
public wpi::SendableHelper<AnalogInput> {
friend class AnalogTrigger;
friend class AnalogGyro;
friend class DMA;
friend class DMASample;
public:
static constexpr int kAccumulatorModuleNumber = 1;
static constexpr int kAccumulatorNumChannels = 2;
static constexpr int kAccumulatorChannels[kAccumulatorNumChannels] = {0, 1};
/**
* Construct an analog input.
*
@@ -182,81 +177,6 @@ class AnalogInput : public wpi::Sendable,
*/
int GetOffset() const;
/**
* Is the channel attached to an accumulator.
*
* @return The analog input is attached to an accumulator.
*/
bool IsAccumulatorChannel() const;
/**
* Initialize the accumulator.
*/
void InitAccumulator();
/**
* Set an initial value for the accumulator.
*
* This will be added to all values returned to the user.
*
* @param value The value that the accumulator should start from when reset.
*/
void SetAccumulatorInitialValue(int64_t value);
/**
* Resets the accumulator to the initial value.
*/
void ResetAccumulator();
/**
* Set the center value of the accumulator.
*
* The center value is subtracted from each A/D value before it is added to
* the accumulator. This is used for the center value of devices like gyros
* and accelerometers to take the device offset into account when integrating.
*
* This center value is based on the output of the oversampled and averaged
* source from the accumulator channel. Because of this, any non-zero
* oversample bits will affect the size of the value for this field.
*/
void SetAccumulatorCenter(int center);
/**
* Set the accumulator's deadband.
*/
void SetAccumulatorDeadband(int deadband);
/**
* Read the accumulated value.
*
* Read the value that has been accumulating.
* The accumulator is attached after the oversample and average engine.
*
* @return The 64-bit value accumulated since the last Reset().
*/
int64_t GetAccumulatorValue() const;
/**
* Read the number of accumulated values.
*
* Read the count of the accumulated values since the accumulator was last
* Reset().
*
* @return The number of times samples from the channel were accumulated.
*/
int64_t GetAccumulatorCount() const;
/**
* Read the accumulated value and the number of accumulated values atomically.
*
* This function reads the value and count from the FPGA atomically.
* This can be used for averaging.
*
* @param value Reference to the 64-bit accumulated output.
* @param count Reference to the number of accumulation cycles.
*/
void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
/**
* Set the sample rate per channel for all analog channels.
*
@@ -286,7 +206,6 @@ class AnalogInput : public wpi::Sendable,
private:
int m_channel;
hal::Handle<HAL_AnalogInputHandle, HAL_FreeAnalogInputPort> m_port;
int64_t m_accumulatorOffset;
};
} // namespace frc

View File

@@ -1,121 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include "frc/simulation/CallbackStore.h"
namespace frc {
class AnalogGyro;
namespace sim {
/**
* Class to control a simulated analog gyro.
*/
class AnalogGyroSim {
public:
/**
* Constructs from an AnalogGyro object.
*
* @param gyro AnalogGyro to simulate
*/
explicit AnalogGyroSim(const AnalogGyro& gyro);
/**
* Constructs from an analog input channel number.
*
* @param channel Channel number
*/
explicit AnalogGyroSim(int channel);
/**
* Register a callback on the angle.
*
* @param callback the callback that will be called whenever the angle changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterAngleCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the current angle of the gyro.
*
* @return the angle measured by the gyro
*/
double GetAngle() const;
/**
* Change the angle measured by the gyro.
*
* @param angle the new value
*/
void SetAngle(double angle);
/**
* Register a callback on the rate.
*
* @param callback the callback that will be called whenever the rate changes
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterRateCallback(NotifyCallback callback,
bool initialNotify);
/**
* Get the rate of angle change on this gyro.
*
* @return the rate
*/
double GetRate() const;
/**
* Change the rate of the gyro.
*
* @param rate the new rate
*/
void SetRate(double rate);
/**
* Register a callback on whether the gyro is initialized.
*
* @param callback the callback that will be called whenever the gyro is
* initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the gyro is initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Set whether this gyro is initialized.
*
* @param initialized the new value
*/
void SetInitialized(bool initialized);
/**
* Reset all simulation data for this object.
*/
void ResetData();
private:
int m_index;
};
} // namespace sim
} // namespace frc

View File

@@ -137,136 +137,6 @@ class AnalogInputSim {
*/
void SetVoltage(double voltage);
/**
* Register a callback on whether the accumulator is initialized.
*
* @param callback the callback that will be called whenever the accumulator
* is initialized
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
NotifyCallback callback, bool initialNotify);
/**
* Check if the accumulator has been initialized.
*
* @return true if initialized
*/
bool GetAccumulatorInitialized() const;
/**
* Change whether the accumulator has been initialized.
*
* @param accumulatorInitialized the new value
*/
void SetAccumulatorInitialized(bool accumulatorInitialized);
/**
* Register a callback on the accumulator value.
*
* @param callback the callback that will be called whenever the accumulator
* value is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the accumulator value.
*
* @return the accumulator value
*/
int64_t GetAccumulatorValue() const;
/**
* Change the accumulator value.
*
* @param accumulatorValue the new value
*/
void SetAccumulatorValue(int64_t accumulatorValue);
/**
* Register a callback on the accumulator count.
*
* @param callback the callback that will be called whenever the accumulator
* count is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the accumulator count.
*
* @return the accumulator count.
*/
int64_t GetAccumulatorCount() const;
/**
* Change the accumulator count.
*
* @param accumulatorCount the new count.
*/
void SetAccumulatorCount(int64_t accumulatorCount);
/**
* Register a callback on the accumulator center.
*
* @param callback the callback that will be called whenever the accumulator
* center is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the accumulator center.
*
* @return the accumulator center
*/
int GetAccumulatorCenter() const;
/**
* Change the accumulator center.
*
* @param accumulatorCenter the new center
*/
void SetAccumulatorCenter(int accumulatorCenter);
/**
* Register a callback on the accumulator deadband.
*
* @param callback the callback that will be called whenever the accumulator
* deadband is changed
* @param initialNotify if true, the callback will be run on the initial value
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the accumulator deadband.
*
* @return the accumulator deadband
*/
int GetAccumulatorDeadband() const;
/**
* Change the accumulator deadband.
*
* @param accumulatorDeadband the new deadband
*/
void SetAccumulatorDeadband(int accumulatorDeadband);
/**
* Reset all simulation data for this object.
*/

View File

@@ -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 <memory>
#include <gtest/gtest.h>
#include <hal/HAL.h>
#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<AnalogInput> 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

View File

@@ -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

View File

@@ -8,7 +8,6 @@
#include <hal/HAL.h>
#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);

View File

@@ -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() {

View File

@@ -22,7 +22,6 @@
#include <frc/geometry/Transform3d.h>
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/simulation/AnalogGyroSim.h>
#include <frc/simulation/DifferentialDrivetrainSim.h>
#include <frc/simulation/EncoderSim.h>
#include <frc/smartdashboard/Field2d.h>
@@ -165,7 +164,6 @@ class Drivetrain {
frc::SimpleMotorFeedforward<units::meters> 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;

View File

@@ -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() {

View File

@@ -13,7 +13,6 @@
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/kinematics/DifferentialDriveOdometry.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/simulation/AnalogGyroSim.h>
#include <frc/simulation/DifferentialDrivetrainSim.h>
#include <frc/simulation/EncoderSim.h>
#include <frc/smartdashboard/Field2d.h>
@@ -100,7 +99,6 @@ class Drivetrain {
frc::SimpleMotorFeedforward<units::meters> 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;

View File

@@ -6,7 +6,6 @@ package edu.wpi.first.wpilibj;
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 @@ import edu.wpi.first.util.sendable.SendableRegistry;
* <p>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 @@ public class AnalogGyro implements Sendable, AutoCloseable {
* 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 class AnalogGyro implements Sendable, AutoCloseable {
* @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 class AnalogGyro implements Sendable, AutoCloseable {
* <p>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 class AnalogGyro implements Sendable, AutoCloseable {
m_analog.close();
}
m_analog = null;
AnalogGyroJNI.freeAnalogGyro(m_gyroHandle);
}
/**
@@ -174,11 +156,7 @@ public class AnalogGyro implements Sendable, AutoCloseable {
* @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 class AnalogGyro implements Sendable, AutoCloseable {
* @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 class AnalogGyro implements Sendable, AutoCloseable {
* @return the current offset value
*/
public double getOffset() {
return AnalogGyroJNI.getAnalogGyroOffset(m_gyroHandle);
return 0.0;
}
/**
@@ -214,7 +188,7 @@ public class AnalogGyro implements Sendable, AutoCloseable {
* @return the current center value
*/
public int getCenter() {
return AnalogGyroJNI.getAnalogGyroCenter(m_gyroHandle);
return 0;
}
/**
@@ -224,9 +198,7 @@ public class AnalogGyro implements Sendable, AutoCloseable {
*
* @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 class AnalogGyro implements Sendable, AutoCloseable {
*
* @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.

View File

@@ -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 @@ import edu.wpi.first.util.sendable.SendableRegistry;
* 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 class AnalogInput implements Sendable, AutoCloseable {
AnalogJNI.freeAnalogInputPort(m_port);
m_port = 0;
m_channel = 0;
m_accumulatorOffset = 0;
}
/**
@@ -181,127 +175,6 @@ public class AnalogInput implements Sendable, AutoCloseable {
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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*
* <p>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.
*

View File

@@ -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);
}
}

View File

@@ -151,162 +151,6 @@ public class AnalogInputSim {
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);

View File

@@ -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());
}
}
}

View File

@@ -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());
}
}
}

View File

@@ -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 @@ class AnalogInputSimTest {
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);
}
}
}

View File

@@ -32,7 +32,6 @@ import edu.wpi.first.wpilibj.Encoder;
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<N2, N2, N2> m_drivetrainSystem =
@@ -257,7 +255,7 @@ public class Drivetrain {
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. */

View File

@@ -19,7 +19,6 @@ import edu.wpi.first.wpilibj.AnalogGyro;
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 class Drivetrain {
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. */