diff --git a/hal/src/main/java/edu/wpi/first/hal/SimDevice.java b/hal/src/main/java/edu/wpi/first/hal/SimDevice.java index 8e45e81032..9bc879f317 100644 --- a/hal/src/main/java/edu/wpi/first/hal/SimDevice.java +++ b/hal/src/main/java/edu/wpi/first/hal/SimDevice.java @@ -4,7 +4,17 @@ package edu.wpi.first.hal; -/** A wrapper around a simulator device handle. */ +/** + * A wrapper around a simulator device handle. + * + *

Teams: if you are using this class, you are likely confusing it for {@link + * edu.wpi.first.wpilibj.simulation.SimDeviceSim}. + * + *

Vendors: This class should be used from inside the device class to define the + * properties/fields of the device. Use {@link #create} to get a SimDevice object, then use {@link + * #createDouble(String, Direction, double)} or similar to define the device's fields. See {@link + * edu.wpi.first.wpilibj.ADXRS450_Gyro} for an example implementation. + */ public class SimDevice implements AutoCloseable { public enum Direction { kInput(SimDeviceJNI.kInput), diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/RoboRioDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/RoboRioDataJNI.java index 90a3813d0c..05b203e31f 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/RoboRioDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/RoboRioDataJNI.java @@ -7,13 +7,17 @@ package edu.wpi.first.hal.simulation; import edu.wpi.first.hal.JNIWrapper; public class RoboRioDataJNI extends JNIWrapper { + @SuppressWarnings("AbbreviationAsWordInName") public static native int registerFPGAButtonCallback( NotifyCallback callback, boolean initialNotify); + @SuppressWarnings("AbbreviationAsWordInName") public static native void cancelFPGAButtonCallback(int uid); + @SuppressWarnings("AbbreviationAsWordInName") public static native boolean getFPGAButton(); + @SuppressWarnings("AbbreviationAsWordInName") public static native void setFPGAButton(boolean fPGAButton); public static native int registerVInVoltageCallback( diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java index d8e88fdadf..03c009f711 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java @@ -29,6 +29,7 @@ public class SimDeviceDataJNI extends JNIWrapper { public static native int getSimValueDeviceHandle(int handle); public static class SimDeviceInfo { + @SuppressWarnings("JavadocMethod") public SimDeviceInfo(String name, int handle) { this.name = name; this.handle = handle; @@ -62,6 +63,7 @@ public class SimDeviceDataJNI extends JNIWrapper { public static native int getSimValueHandle(int device, String name); public static class SimValueInfo { + @SuppressWarnings("JavadocMethod") public SimValueInfo( String name, int handle, int direction, int type, long value1, double value2) { this.name = name; diff --git a/styleguide/suppressions.xml b/styleguide/suppressions.xml index c2b2dfc726..54d4c2bce8 100644 --- a/styleguide/suppressions.xml +++ b/styleguide/suppressions.xml @@ -3,8 +3,6 @@ suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> - diff --git a/wpilibc/src/main/native/cpp/simulation/SimDeviceSim.cpp b/wpilibc/src/main/native/cpp/simulation/SimDeviceSim.cpp index eee7d44e2b..272b4b0fbd 100644 --- a/wpilibc/src/main/native/cpp/simulation/SimDeviceSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/SimDeviceSim.cpp @@ -20,6 +20,14 @@ hal::SimValue SimDeviceSim::GetValue(const char* name) const { return HALSIM_GetSimValueHandle(m_handle, name); } +hal::SimInt SimDeviceSim::GetInt(const char* name) const { + return HALSIM_GetSimValueHandle(m_handle, name); +} + +hal::SimLong SimDeviceSim::GetLong(const char* name) const { + return HALSIM_GetSimValueHandle(m_handle, name); +} + hal::SimDouble SimDeviceSim::GetDouble(const char* name) const { return HALSIM_GetSimValueHandle(m_handle, name); } diff --git a/wpilibc/src/main/native/include/frc/simulation/AddressableLEDSim.h b/wpilibc/src/main/native/include/frc/simulation/AddressableLEDSim.h index 2a5a708852..f6e2488096 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AddressableLEDSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AddressableLEDSim.h @@ -52,39 +52,130 @@ class AddressableLEDSim { */ static AddressableLEDSim CreateForIndex(int index); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback on the Initialized property. + * + * @param callback the callback that will be called whenever the Initialized + * property is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object storing this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Change the Initialized value of the LED strip. + * + * @param initialized the new value + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterOutputPortCallback( + /** + * Register a callback on the output port. + * + * @param callback the callback that will be called whenever the output port + * 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 RegisterOutputPortCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the output port. + * + * @return the output port + */ int GetOutputPort() const; + /** + * Change the output port. + * + * @param outputPort the new output port + */ void SetOutputPort(int outputPort); - std::unique_ptr RegisterLengthCallback(NotifyCallback callback, - bool initialNotify); - - int GetLength() const; - - void SetLength(int length); - - std::unique_ptr RegisterRunningCallback( + /** + * Register a callback on the length. + * + * @param callback the callback that will be called whenever the length 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 RegisterLengthCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the length of the LED strip. + * + * @return the length + */ + int GetLength() const; + + /** + * Change the length of the LED strip. + * + * @param length the new value + */ + void SetLength(int length); + + /** + * Register a callback on whether the LEDs are running. + * + * @param callback the callback that will be called whenever the LED state 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 RegisterRunningCallback( + NotifyCallback callback, bool initialNotify); + + /** + * Check if the LEDs are running. + * + * @return true if they are + */ int GetRunning() const; + /** + * Change whether the LEDs are active. + * + * @param running the new value + */ void SetRunning(bool running); - std::unique_ptr RegisterDataCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback on the LED data. + * + * @param callback the callback that will be called whenever the LED data is + * changed + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterDataCallback( + NotifyCallback callback, bool initialNotify); + /** + * Get the LED data. + * + * @param data output parameter to fill with LED data + * @return the length of the LED data + */ int GetData(struct HAL_AddressableLEDData* data) const; + /** + * Change the LED data. + * + * @param data the new data + * @param length the length of the LED data + */ void SetData(struct HAL_AddressableLEDData* data, int length); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogEncoderSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogEncoderSim.h index b05d4f68f0..6d76326704 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogEncoderSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AnalogEncoderSim.h @@ -28,7 +28,7 @@ class AnalogEncoderSim { explicit AnalogEncoderSim(const AnalogEncoder& encoder); /** - * Set the position using an {@link Rotation2d}. + * Set the position using an Rotation2d. * * @param angle The angle. */ @@ -47,7 +47,7 @@ class AnalogEncoderSim { units::turn_t GetTurns(); /** - * Get the position as a {@link Rotation2d}. + * Get the position as a Rotation2d. */ Rotation2d GetPosition(); diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h index b879971bb4..faa11d712f 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AnalogGyroSim.h @@ -33,27 +33,82 @@ class AnalogGyroSim { */ explicit AnalogGyroSim(int channel); - std::unique_ptr RegisterAngleCallback(NotifyCallback callback, - bool initialNotify); - - double GetAngle() const; - - void SetAngle(double angle); - - std::unique_ptr RegisterRateCallback(NotifyCallback callback, - bool initialNotify); - - double GetRate() const; - - void SetRate(double rate); - - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback on the angle. + * + * @param callback the callback that will be called whenever the angle changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterAngleCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the current angle of the gyro. + * + * @return the angle measured by the gyro + */ + double GetAngle() const; + + /** + * Change the angle measured by the gyro. + * + * @param angle the new value + */ + void SetAngle(double angle); + + /** + * Register a callback on the rate. + * + * @param callback the callback that will be called whenever the rate changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterRateCallback( + NotifyCallback callback, bool initialNotify); + + /** + * Get the rate of angle change on this gyro. + * + * @return the rate + */ + double GetRate() const; + + /** + * Change the rate of the gyro. + * + * @param rate the new rate + */ + void SetRate(double rate); + + /** + * Register a callback on whether the gyro is initialized. + * + * @param callback the callback that will be called whenever the gyro is + * initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( + NotifyCallback callback, bool initialNotify); + + /** + * Check if the gyro is initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Set whether this gyro is initialized. + * + * @param initialized the new value + */ void SetInitialized(bool initialized); + /** + * Reset all simulation data for this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h index b6445e81aa..03d754896a 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AnalogInputSim.h @@ -33,69 +33,237 @@ class AnalogInputSim { */ explicit AnalogInputSim(int channel); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback on whether the analog input is initialized. + * + * @param callback the callback that will be called whenever the analog input + * is initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if this analog input has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Change whether this analog input has been initialized. + * + * @param initialized the new value + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterAverageBitsCallback( + /** + * Register a callback on the number of average bits. + * + * @param callback the callback that will be called whenever the number of + * average bits 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 RegisterAverageBitsCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the number of average bits. + * + * @return the number of average bits + */ int GetAverageBits() const; + /** + * Change the number of average bits. + * + * @param averageBits the new value + */ void SetAverageBits(int averageBits); - std::unique_ptr RegisterOversampleBitsCallback( + /** + * Register a callback on the amount of oversampling bits. + * + * @param callback the callback that will be called whenever the oversampling + * bits are 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 RegisterOversampleBitsCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the amount of oversampling bits. + * + * @return the amount of oversampling bits + */ int GetOversampleBits() const; + /** + * Change the amount of oversampling bits. + * + * @param oversampleBits the new value + */ void SetOversampleBits(int oversampleBits); - std::unique_ptr RegisterVoltageCallback( + /** + * Register a callback on the voltage. + * + * @param callback the callback that will be called whenever the voltage 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 RegisterVoltageCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the voltage. + * + * @return the voltage + */ double GetVoltage() const; + /** + * Change the voltage. + * + * @param voltage the new value + */ void SetVoltage(double voltage); - std::unique_ptr RegisterAccumulatorInitializedCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on whether the accumulator is initialized. + * + * @param callback the callback that will be called whenever the accumulator + * is initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterAccumulatorInitializedCallback(NotifyCallback callback, + bool initialNotify); + /** + * Check if the accumulator has been initialized. + * + * @return true if initialized + */ bool GetAccumulatorInitialized() const; + /** + * Change whether the accumulator has been initialized. + * + * @param accumulatorInitialized the new value + */ void SetAccumulatorInitialized(bool accumulatorInitialized); - std::unique_ptr RegisterAccumulatorValueCallback( + /** + * Register a callback on the accumulator value. + * + * @param callback the callback that will be called whenever the accumulator + * value is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterAccumulatorValueCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the accumulator value. + * + * @return the accumulator value + */ int64_t GetAccumulatorValue() const; + /** + * Change the accumulator value. + * + * @param accumulatorValue the new value + */ void SetAccumulatorValue(int64_t accumulatorValue); - std::unique_ptr RegisterAccumulatorCountCallback( + /** + * Register a callback on the accumulator count. + * + * @param callback the callback that will be called whenever the accumulator + * count is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterAccumulatorCountCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the accumulator count. + * + * @return the accumulator count. + */ int64_t GetAccumulatorCount() const; + /** + * Change the accumulator count. + * + * @param accumulatorCount the new count. + */ void SetAccumulatorCount(int64_t accumulatorCount); - std::unique_ptr RegisterAccumulatorCenterCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on the accumulator center. + * + * @param callback the callback that will be called whenever the accumulator + * center is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterAccumulatorCenterCallback(NotifyCallback callback, + bool initialNotify); + /** + * Get the accumulator center. + * + * @return the accumulator center + */ int GetAccumulatorCenter() const; + /** + * Change the accumulator center. + * + * @param accumulatorCenter the new center + */ void SetAccumulatorCenter(int accumulatorCenter); - std::unique_ptr RegisterAccumulatorDeadbandCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on the accumulator deadband. + * + * @param callback the callback that will be called whenever the accumulator + * deadband is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterAccumulatorDeadbandCallback(NotifyCallback callback, + bool initialNotify); + /** + * Get the accumulator deadband. + * + * @return the accumulator deadband + */ int GetAccumulatorDeadband() const; + /** + * Change the accumulator deadband. + * + * @param accumulatorDeadband the new deadband + */ void SetAccumulatorDeadband(int accumulatorDeadband); + /** + * Reset all simulation data for this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogOutputSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogOutputSim.h index 55c64db553..ffec03a819 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogOutputSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AnalogOutputSim.h @@ -33,20 +33,57 @@ class AnalogOutputSim { */ explicit AnalogOutputSim(int channel); - std::unique_ptr RegisterVoltageCallback( + /** + * Register a callback to be run whenever the voltage changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterVoltageCallback( NotifyCallback callback, bool initialNotify); + /** + * Read the analog output voltage. + * + * @return the voltage on this analog output + */ double GetVoltage() const; + /** + * Set the analog output voltage. + * + * @param voltage the new voltage on this analog output + */ void SetVoltage(double voltage); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback to be run when this analog output is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether this analog output has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Define whether this analog output has been initialized. + * + * @param initialized whether this object is initialized + */ void SetInitialized(bool initialized); + /** + * Reset all simulation data on this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h b/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h index d2184675c9..04e9e9b7d1 100644 --- a/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/AnalogTriggerSim.h @@ -45,27 +45,86 @@ class AnalogTriggerSim { */ static AnalogTriggerSim CreateForIndex(int index); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback on whether the analog trigger is initialized. + * + * @param callback the callback that will be called whenever the analog + * trigger is initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if this analog trigger has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Change whether this analog trigger has been initialized. + * + * @param initialized the new value + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterTriggerLowerBoundCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on the lower bound. + * + * @param callback the callback that will be called whenever the lower bound + * 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 + RegisterTriggerLowerBoundCallback(NotifyCallback callback, + bool initialNotify); + /** + * Get the lower bound. + * + * @return the lower bound + */ double GetTriggerLowerBound() const; + /** + * Change the lower bound. + * + * @param triggerLowerBound the new lower bound + */ void SetTriggerLowerBound(double triggerLowerBound); - std::unique_ptr RegisterTriggerUpperBoundCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on the upper bound. + * + * @param callback the callback that will be called whenever the upper bound + * 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 + RegisterTriggerUpperBoundCallback(NotifyCallback callback, + bool initialNotify); + /** + * Get the upper bound. + * + * @return the upper bound + */ double GetTriggerUpperBound() const; + /** + * Change the upper bound. + * + * @param triggerUpperBound the new upper bound + */ void SetTriggerUpperBound(double triggerUpperBound); + /** + * Reset all simulation data for this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/BuiltInAccelerometerSim.h b/wpilibc/src/main/native/include/frc/simulation/BuiltInAccelerometerSim.h index c596b29bf5..9ffcf5b64d 100644 --- a/wpilibc/src/main/native/include/frc/simulation/BuiltInAccelerometerSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/BuiltInAccelerometerSim.h @@ -33,41 +33,129 @@ class BuiltInAccelerometerSim { */ explicit BuiltInAccelerometerSim(const BuiltInAccelerometer& accel); - std::unique_ptr RegisterActiveCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run when this accelerometer activates. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterActiveCallback( + NotifyCallback callback, bool initialNotify); + /** + * Check whether the accelerometer is active. + * + * @return true if active + */ bool GetActive() const; + /** + * Define whether this accelerometer is active. + * + * @param active the new state + */ void SetActive(bool active); - std::unique_ptr RegisterRangeCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the range changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterRangeCallback( + NotifyCallback callback, bool initialNotify); + /** + * Check the range of this accelerometer. + * + * @return the accelerometer range + */ HAL_AccelerometerRange GetRange() const; + /** + * Change the range of this accelerometer. + * + * @param range the new accelerometer range + */ void SetRange(HAL_AccelerometerRange range); - std::unique_ptr RegisterXCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the X axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterXCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the X axis value. + * + * @return the X axis measurement + */ double GetX() const; + /** + * Change the X axis value of the accelerometer. + * + * @param x the new reading of the X axis + */ void SetX(double x); - std::unique_ptr RegisterYCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the Y axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterYCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the Y axis value. + * + * @return the Y axis measurement + */ double GetY() const; + /** + * Change the Y axis value of the accelerometer. + * + * @param y the new reading of the Y axis + */ void SetY(double y); - std::unique_ptr RegisterZCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the Z axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterZCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the Z axis value. + * + * @return the Z axis measurement + */ double GetZ() const; + /** + * Change the Z axis value of the accelerometer. + * + * @param z the new reading of the Z axis + */ void SetZ(double z); + /** + * Reset all simulation data of this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/CallbackStore.h b/wpilibc/src/main/native/include/frc/simulation/CallbackStore.h index bdc861413e..0a13a4ff10 100644 --- a/wpilibc/src/main/native/include/frc/simulation/CallbackStore.h +++ b/wpilibc/src/main/native/include/frc/simulation/CallbackStore.h @@ -24,6 +24,9 @@ void ConstBufferCallbackStoreThunk(const char* name, void* param, const unsigned char* buffer, unsigned int count); +/** + * Manages simulation callbacks; each object is associated with a callback. + */ class CallbackStore { public: CallbackStore(int32_t i, NotifyCallback cb, CancelCallbackNoIndexFunc ccf); diff --git a/wpilibc/src/main/native/include/frc/simulation/DIOSim.h b/wpilibc/src/main/native/include/frc/simulation/DIOSim.h index fa3bd03f9a..9bbd3fb8e9 100644 --- a/wpilibc/src/main/native/include/frc/simulation/DIOSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/DIOSim.h @@ -41,41 +41,132 @@ class DIOSim { */ explicit DIOSim(int channel); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback to be run when this DIO is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether this DIO has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Define whether this DIO has been initialized. + * + * @param initialized whether this object is initialized + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterValueCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the DIO value changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterValueCallback( + NotifyCallback callback, bool initialNotify); + /** + * Read the value of the DIO port. + * + * @return the DIO value + */ bool GetValue() const; + /** + * Change the DIO value. + * + * @param value the new value + */ void SetValue(bool value); - std::unique_ptr RegisterPulseLengthCallback( + /** + * Register a callback to be run whenever the pulse length changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterPulseLengthCallback( NotifyCallback callback, bool initialNotify); + /** + * Read the pulse length. + * + * @return the pulse length of this DIO port + */ double GetPulseLength() const; + /** + * Change the pulse length of this DIO port. + * + * @param pulseLength the new pulse length + */ void SetPulseLength(double pulseLength); - std::unique_ptr RegisterIsInputCallback( + /** + * Register a callback to be run whenever this DIO changes to be an input. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterIsInputCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether this DIO port is currently an Input. + * + * @return true if Input + */ bool GetIsInput() const; + /** + * Define whether this DIO port is an Input. + * + * @param isInput whether this DIO should be an Input + */ void SetIsInput(bool isInput); - std::unique_ptr RegisterFilterIndexCallback( + /** + * Register a callback to be run whenever the filter index changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterFilterIndexCallback( NotifyCallback callback, bool initialNotify); + /** + * Read the filter index. + * + * @return the filter index of this DIO port + */ int GetFilterIndex() const; + /** + * Change the filter index of this DIO port. + * + * @param filterIndex the new filter index + */ void SetFilterIndex(int filterIndex); + /** + * Reset all simulation data of this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/DigitalPWMSim.h b/wpilibc/src/main/native/include/frc/simulation/DigitalPWMSim.h index 963a73c7f9..53caee7427 100644 --- a/wpilibc/src/main/native/include/frc/simulation/DigitalPWMSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/DigitalPWMSim.h @@ -47,27 +47,81 @@ class DigitalPWMSim { */ static DigitalPWMSim CreateForIndex(int index); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback to be run when this PWM output is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether this PWM output has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Define whether this PWM output has been initialized. + * + * @param initialized whether this object is initialized + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterDutyCycleCallback( + /** + * Register a callback to be run whenever the duty cycle value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterDutyCycleCallback( NotifyCallback callback, bool initialNotify); + /** + * Read the duty cycle value. + * + * @return the duty cycle value of this PWM output + */ double GetDutyCycle() const; + /** + * Set the duty cycle value of this PWM output. + * + * @param dutyCycle the new value + */ void SetDutyCycle(double dutyCycle); - std::unique_ptr RegisterPinCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the pin changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterPinCallback( + NotifyCallback callback, bool initialNotify); + /** + * Check the pin number. + * + * @return the pin number + */ int GetPin() const; + /** + * Change the pin number. + * + * @param pin the new pin number + */ void SetPin(int pin); + /** + * Reset all simulation data. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/DriverStationSim.h b/wpilibc/src/main/native/include/frc/simulation/DriverStationSim.h index 5d21ea3950..3b692de83e 100644 --- a/wpilibc/src/main/native/include/frc/simulation/DriverStationSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/DriverStationSim.h @@ -18,60 +18,205 @@ namespace frc::sim { */ class DriverStationSim { public: - static std::unique_ptr RegisterEnabledCallback( + /** + * Register a callback on whether the DS is enabled. + * + * @param callback the callback that will be called whenever the enabled + * state is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr RegisterEnabledCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if the DS is enabled. + * + * @return true if enabled + */ static bool GetEnabled(); + /** + * Change whether the DS is enabled. + * + * @param enabled the new value + */ static void SetEnabled(bool enabled); - static std::unique_ptr RegisterAutonomousCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on whether the DS is in autonomous mode. + * + * @param callback the callback that will be called on autonomous mode + * entrance/exit + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterAutonomousCallback(NotifyCallback callback, bool initialNotify); + /** + * Check if the DS is in autonomous. + * + * @return true if autonomous + */ static bool GetAutonomous(); + /** + * Change whether the DS is in autonomous. + * + * @param autonomous the new value + */ static void SetAutonomous(bool autonomous); - static std::unique_ptr RegisterTestCallback( + /** + * Register a callback on whether the DS is in test mode. + * + * @param callback the callback that will be called whenever the test mode + * is entered or left + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr RegisterTestCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if the DS is in test. + * + * @return true if test + */ static bool GetTest(); + /** + * Change whether the DS is in test. + * + * @param test the new value + */ static void SetTest(bool test); - static std::unique_ptr RegisterEStopCallback( + /** + * Register a callback on the eStop state. + * + * @param callback the callback that will be called whenever the eStop state + * changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr RegisterEStopCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if eStop has been activated. + * + * @return true if eStopped + */ static bool GetEStop(); + /** + * Set whether eStop is active. + * + * @param eStop true to activate + */ static void SetEStop(bool eStop); - static std::unique_ptr RegisterFmsAttachedCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on whether the FMS is connected. + * + * @param callback the callback that will be called whenever the FMS + * connection changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterFmsAttachedCallback(NotifyCallback callback, bool initialNotify); + /** + * Check if the FMS is connected. + * + * @return true if FMS is connected + */ static bool GetFmsAttached(); + /** + * Change whether the FMS is connected. + * + * @param fmsAttached the new value + */ static void SetFmsAttached(bool fmsAttached); - static std::unique_ptr RegisterDsAttachedCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on whether the DS is connected. + * + * @param callback the callback that will be called whenever the DS + * connection changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterDsAttachedCallback(NotifyCallback callback, bool initialNotify); + /** + * Check if the DS is attached. + * + * @return true if attached + */ static bool GetDsAttached(); + /** + * Change whether the DS is attached. + * + * @param dsAttached the new value + */ static void SetDsAttached(bool dsAttached); - static std::unique_ptr RegisterAllianceStationIdCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback on the alliance station ID. + * + * @param callback the callback that will be called whenever the alliance + * station changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterAllianceStationIdCallback(NotifyCallback callback, + bool initialNotify); + /** + * Get the alliance station ID (color + number). + * + * @return the alliance station color and number + */ static HAL_AllianceStationID GetAllianceStationId(); + /** + * Change the alliance station. + * + * @param allianceStationId the new alliance station + */ static void SetAllianceStationId(HAL_AllianceStationID allianceStationId); - static std::unique_ptr RegisterMatchTimeCallback( + /** + * Register a callback on match time. + * + * @param callback the callback that will be called whenever match time + * changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr RegisterMatchTimeCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the current value of the match timer. + * + * @return the current match time + */ static double GetMatchTime(); + /** + * Sets the match timer. + * + * @param matchTime the new match time + */ static void SetMatchTime(double matchTime); /** @@ -238,6 +383,9 @@ class DriverStationSim { */ static void SetReplayNumber(int replayNumber); + /** + * Reset all simulation data for the Driver Station. + */ static void ResetData(); }; } // namespace frc::sim diff --git a/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h b/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h index 874d4d2337..93fa0a79bf 100644 --- a/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/DutyCycleSim.h @@ -44,27 +44,81 @@ class DutyCycleSim { */ static DutyCycleSim CreateForIndex(int index); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback to be run when this duty cycle input is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether this duty cycle input has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Define whether this duty cycle input has been initialized. + * + * @param initialized whether this object is initialized + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterFrequencyCallback( + /** + * Register a callback to be run whenever the frequency changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterFrequencyCallback( NotifyCallback callback, bool initialNotify); + /** + * Measure the frequency. + * + * @return the duty cycle frequency + */ int GetFrequency() const; + /** + * Change the duty cycle frequency. + * + * @param frequency the new frequency + */ void SetFrequency(int count); - std::unique_ptr RegisterOutputCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the output changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterOutputCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the output from this duty cycle port. + * + * @return the output value + */ double GetOutput() const; + /** + * Change the duty cycle output. + * + * @param output the new output value + */ void SetOutput(double period); + /** + * Reset all simulation data for the duty cycle output. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/EncoderSim.h b/wpilibc/src/main/native/include/frc/simulation/EncoderSim.h index 862e86536b..0d578b4988 100644 --- a/wpilibc/src/main/native/include/frc/simulation/EncoderSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/EncoderSim.h @@ -45,77 +45,261 @@ class EncoderSim { */ static EncoderSim CreateForIndex(int index); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback on the Initialized property of the encoder. + * + * @param callback the callback that will be called whenever the Initialized + * property 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 RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Read the Initialized value of the encoder. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Change the Initialized value of the encoder. + * + * @param initialized the new value + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterCountCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback on the count property of the encoder. + * + * @param callback the callback that will be called whenever the count + * property 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 RegisterCountCallback( + NotifyCallback callback, bool initialNotify); + /** + * Read the count of the encoder. + * + * @return the count + */ int GetCount() const; + /** + * Change the count of the encoder. + * + * @param count the new count + */ void SetCount(int count); - std::unique_ptr RegisterPeriodCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback on the period of the encoder. + * + * @param callback the callback that will be called whenever the period 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 RegisterPeriodCallback( + NotifyCallback callback, bool initialNotify); + /** + * Read the period of the encoder. + * + * @return the encoder period + */ double GetPeriod() const; + /** + * Change the encoder period. + * + * @param period the new period + */ void SetPeriod(double period); - std::unique_ptr RegisterResetCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be called whenever the encoder is reset. + * + * @param callback the callback + * @param initialNotify whether to run the callback on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterResetCallback( + NotifyCallback callback, bool initialNotify); + /** + * Check if the encoder has been reset. + * + * @return true if reset + */ bool GetReset() const; + /** + * Change the reset property of the encoder. + * + * @param reset the new value + */ void SetReset(bool reset); - std::unique_ptr RegisterMaxPeriodCallback( + /** + * Register a callback to be run whenever the max period of the encoder is + * changed. + * + * @param callback the callback + * @param initialNotify whether to run the callback on the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterMaxPeriodCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the max period of the encoder. + * + * @return the max period of the encoder + */ double GetMaxPeriod() const; + /** + * Change the max period of the encoder. + * + * @param maxPeriod the new value + */ void SetMaxPeriod(double maxPeriod); - std::unique_ptr RegisterDirectionCallback( + /** + * Register a callback on the direction of the encoder. + * + * @param callback the callback that will be called whenever the direction + * 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 RegisterDirectionCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the direction of the encoder. + * + * @return the direction of the encoder + */ bool GetDirection() const; + /** + * Set the direction of the encoder. + * + * @param direction the new direction + */ void SetDirection(bool direction); - std::unique_ptr RegisterReverseDirectionCallback( + /** + * Register a callback on the reverse direction. + * + * @param callback the callback that will be called whenever the reverse + * direction 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 RegisterReverseDirectionCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the reverse direction of the encoder. + * + * @return the reverse direction of the encoder + */ bool GetReverseDirection() const; + /** + * Set the reverse direction. + * + * @param reverseDirection the new value + */ void SetReverseDirection(bool reverseDirection); - std::unique_ptr RegisterSamplesToAverageCallback( + /** + * Register a callback on the samples-to-average value of this encoder. + * + * @param callback the callback that will be called whenever the + * samples-to-average 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 RegisterSamplesToAverageCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the samples-to-average value. + * + * @return the samples-to-average value + */ int GetSamplesToAverage() const; + /** + * Set the samples-to-average value. + * + * @param samplesToAverage the new value + */ void SetSamplesToAverage(int samplesToAverage); - std::unique_ptr RegisterDistancePerPulseCallback( + /** + * Register a callback on the distance per pulse value of this encoder. + * + * @param callback the callback that will be called whenever the + * distance per pulse 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 RegisterDistancePerPulseCallback( NotifyCallback callback, bool initialNotify); + /** + * Read the distance per pulse of the encoder. + * + * @return the encoder distance per pulse + */ double GetDistancePerPulse() const; + /** + * Change the encoder distance per pulse. + * + * @param distancePerPulse the new distance per pulse + */ void SetDistancePerPulse(double distancePerPulse); + /** + * Resets all simulation data for this encoder. + */ void ResetData(); + /** + * Change the encoder distance. + * + * @param distance the new distance + */ void SetDistance(double distance); + /** + * Read the distance of the encoder. + * + * @return the encoder distance + */ double GetDistance(); + /** + * Change the rate of the encoder. + * + * @param rate the new rate + */ void SetRate(double rate); + /** + * Get the rate of the encoder. + * + * @return the rate of change + */ double GetRate(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/GenericHIDSim.h b/wpilibc/src/main/native/include/frc/simulation/GenericHIDSim.h index 977a91cfb1..399e0c16d1 100644 --- a/wpilibc/src/main/native/include/frc/simulation/GenericHIDSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/GenericHIDSim.h @@ -38,30 +38,101 @@ class GenericHIDSim { */ void NotifyNewData(); + /** + * Set the value of a given button. + * + * @param button the button to set + * @param value the new value + */ void SetRawButton(int button, bool value); + /** + * Set the value of a given axis. + * + * @param axis the axis to set + * @param value the new value + */ void SetRawAxis(int axis, double value); + /** + * Set the value of a given POV. + * + * @param pov the POV to set + * @param value the new value + */ void SetPOV(int pov, int value); + /** + * Set the value of the default POV (port 0). + * + * @param value the new value + */ void SetPOV(int value); + /** + * Set the axis count of this device. + * + * @param count the new axis count + */ void SetAxisCount(int count); + /** + * Set the POV count of this device. + * + * @param count the new POV count + */ void SetPOVCount(int count); + /** + * Set the button count of this device. + * + * @param count the new button count + */ void SetButtonCount(int count); + /** + * Set the type of this device. + * + * @param type the new device type + */ void SetType(GenericHID::HIDType type); + /** + * Set the name of this device. + * + * @param name the new device name + */ void SetName(const char* name); + /** + * Set the type of an axis. + * + * @param axis the axis + * @param type the type + */ void SetAxisType(int axis, int type); + /** + * Read the output of a button. + * + * @param outputNumber the button number + * @return the value of the button (true = pressed) + */ bool GetOutput(int outputNumber); + /** + * Get the encoded 16-bit integer that passes button values. + * + * @return the button values + */ int64_t GetOutputs(); + /** + * Get the joystick rumble. + * + * @param type the rumble to read + * @return the rumble value + */ double GetRumble(GenericHID::RumbleType type); protected: diff --git a/wpilibc/src/main/native/include/frc/simulation/JoystickSim.h b/wpilibc/src/main/native/include/frc/simulation/JoystickSim.h index 999741062d..db573ad396 100644 --- a/wpilibc/src/main/native/include/frc/simulation/JoystickSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/JoystickSim.h @@ -31,18 +31,53 @@ class JoystickSim : public GenericHIDSim { */ explicit JoystickSim(int port); + /** + * Set the X value of the joystick. + * + * @param value the new X value + */ void SetX(double value); + /** + * Set the Y value of the joystick. + * + * @param value the new Y value + */ void SetY(double value); + /** + * Set the Z value of the joystick. + * + * @param value the new Z value + */ void SetZ(double value); + /** + * Set the twist value of the joystick. + * + * @param value the new twist value + */ void SetTwist(double value); + /** + * Set the throttle value of the joystick. + * + * @param value the new throttle value + */ void SetThrottle(double value); + /** + * Set the trigger value of the joystick. + * + * @param state the new value + */ void SetTrigger(bool state); + /** + * Set the top state of the joystick. + * + * @param state the new state + */ void SetTop(bool state); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/PCMSim.h b/wpilibc/src/main/native/include/frc/simulation/PCMSim.h index cfb8d7b033..b3bf94a09d 100644 --- a/wpilibc/src/main/native/include/frc/simulation/PCMSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/PCMSim.h @@ -38,59 +38,204 @@ class PCMSim { */ explicit PCMSim(const Compressor& compressor); - std::unique_ptr RegisterSolenoidInitializedCallback( - int channel, NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run when a solenoid is initialized on a channel. + * + * @param channel the channel to monitor + * @param callback the callback + * @param initialNotify should the callback be run with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterSolenoidInitializedCallback(int channel, NotifyCallback callback, + bool initialNotify); + /** + * Check if a solenoid has been initialized on a specific channel. + * + * @param channel the channel to check + * @return true if initialized + */ bool GetSolenoidInitialized(int channel) const; + /** + * Define whether a solenoid has been initialized on a specific channel. + * + * @param channel the channel + * @param solenoidInitialized is there a solenoid initialized on that channel + */ void SetSolenoidInitialized(int channel, bool solenoidInitialized); - std::unique_ptr RegisterSolenoidOutputCallback( + /** + * Register a callback to be run when the solenoid output on a channel + * changes. + * + * @param channel the channel to monitor + * @param callback the callback + * @param initialNotify should the callback be run with the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterSolenoidOutputCallback( int channel, NotifyCallback callback, bool initialNotify); + /** + * Check the solenoid output on a specific channel. + * + * @param channel the channel to check + * @return the solenoid output + */ bool GetSolenoidOutput(int channel) const; + /** + * Change the solenoid output on a specific channel. + * + * @param channel the channel to check + * @param solenoidOutput the new solenoid output + */ void SetSolenoidOutput(int channel, bool solenoidOutput); - std::unique_ptr RegisterCompressorInitializedCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run when the compressor is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterCompressorInitializedCallback(NotifyCallback callback, + bool initialNotify); + /** + * Check whether the compressor has been initialized. + * + * @return true if initialized + */ bool GetCompressorInitialized() const; + /** + * Define whether the compressor has been initialized. + * + * @param compressorInitialized whether the compressor is initialized + */ void SetCompressorInitialized(bool compressorInitialized); - std::unique_ptr RegisterCompressorOnCallback( + /** + * Register a callback to be run when the compressor activates. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterCompressorOnCallback( NotifyCallback callback, bool initialNotify); + /** + * Check if the compressor is on. + * + * @return true if the compressor is active + */ bool GetCompressorOn() const; + /** + * Set whether the compressor is active. + * + * @param compressorOn the new value + */ void SetCompressorOn(bool compressorOn); - std::unique_ptr RegisterClosedLoopEnabledCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the closed loop state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterClosedLoopEnabledCallback(NotifyCallback callback, + bool initialNotify); + /** + * Check whether the closed loop compressor control is active. + * + * @return true if active + */ bool GetClosedLoopEnabled() const; + /** + * Turn on/off the closed loop control of the compressor. + * + * @param closedLoopEnabled whether the control loop is active + */ void SetClosedLoopEnabled(bool closedLoopEnabled); - std::unique_ptr RegisterPressureSwitchCallback( + /** + * Register a callback to be run whenever the pressure switch value changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterPressureSwitchCallback( NotifyCallback callback, bool initialNotify); + /** + * Check the value of the pressure switch. + * + * @return the pressure switch value + */ bool GetPressureSwitch() const; + /** + * Set the value of the pressure switch. + * + * @param pressureSwitch the new value + */ void SetPressureSwitch(bool pressureSwitch); - std::unique_ptr RegisterCompressorCurrentCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the compressor current changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterCompressorCurrentCallback(NotifyCallback callback, + bool initialNotify); + /** + * Read the compressor current. + * + * @return the current of the compressor connected to this module + */ double GetCompressorCurrent() const; + /** + * Set the compressor current. + * + * @param compressorCurrent the new compressor current + */ void SetCompressorCurrent(double compressorCurrent); + /** + * Get the current value of all solenoid outputs. + * + * @return the solenoid outputs (1 bit per output) + */ uint8_t GetAllSolenoidOutputs() const; + /** + * Change all of the solenoid outputs. + * + * @param outputs the new solenoid outputs (1 bit per output) + */ void SetAllSolenoidOutputs(uint8_t outputs); + /** + * Reset all simulation data for this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/PDPSim.h b/wpilibc/src/main/native/include/frc/simulation/PDPSim.h index 2b80db4c47..259af5a289 100644 --- a/wpilibc/src/main/native/include/frc/simulation/PDPSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/PDPSim.h @@ -33,38 +33,125 @@ class PDPSim { */ explicit PDPSim(const PowerDistributionPanel& pdp); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback to be run when the PDP is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether the PDP has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Define whether the PDP has been initialized. + * + * @param initialized whether this object is initialized + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterTemperatureCallback( + /** + * Register a callback to be run whenever the PDP temperature changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterTemperatureCallback( NotifyCallback callback, bool initialNotify); + /** + * Check the temperature of the PDP. + * + * @return the PDP temperature + */ double GetTemperature() const; + /** + * Define the PDP temperature. + * + * @param temperature the new PDP temperature + */ void SetTemperature(double temperature); - std::unique_ptr RegisterVoltageCallback( + /** + * Register a callback to be run whenever the PDP voltage changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterVoltageCallback( NotifyCallback callback, bool initialNotify); + /** + * Check the PDP voltage. + * + * @return the PDP voltage. + */ double GetVoltage() const; + /** + * Set the PDP voltage. + * + * @param voltage the new PDP voltage + */ void SetVoltage(double voltage); - std::unique_ptr RegisterCurrentCallback( + /** + * Register a callback to be run whenever the current of a specific channel + * changes. + * + * @param channel the channel + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterCurrentCallback( int channel, NotifyCallback callback, bool initialNotify); + /** + * Read the current in one of the PDP channels. + * + * @param channel the channel to check + * @return the current in the given channel + */ double GetCurrent(int channel) const; + /** + * Change the current in the given channel. + * + * @param channel the channel to edit + * @param current the new current for the channel + */ void SetCurrent(int channel, double current); + /** + * Read the current of all of the PDP channels. + * + * @param currents output array; set to the current in each channel. The + * array must be big enough to hold all the PDP channels + */ void GetAllCurrents(double* currents) const; + /** + * Change the current in all of the PDP channels. + * + * @param currents array containing the current values for each channel. The + * array must be big enough to hold all the PDP channels + */ void SetAllCurrents(const double* currents); + /** + * Reset all PDP simulation data. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/PWMSim.h b/wpilibc/src/main/native/include/frc/simulation/PWMSim.h index e88e66e592..97e9b1f65d 100644 --- a/wpilibc/src/main/native/include/frc/simulation/PWMSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/PWMSim.h @@ -33,48 +33,153 @@ class PWMSim { */ explicit PWMSim(int channel); - std::unique_ptr RegisterInitializedCallback( + /** + * Register a callback to be run when the PWM is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterInitializedCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether the PWM has been initialized. + * + * @return true if initialized + */ bool GetInitialized() const; + /** + * Define whether the PWM has been initialized. + * + * @param initialized whether this object is initialized + */ void SetInitialized(bool initialized); - std::unique_ptr RegisterRawValueCallback( + /** + * Register a callback to be run when the PWM raw value changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterRawValueCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the PWM raw value. + * + * @return the PWM raw value + */ int GetRawValue() const; + /** + * Set the PWM raw value. + * + * @param rawValue the PWM raw value + */ void SetRawValue(int rawValue); - std::unique_ptr RegisterSpeedCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run when the PWM speed changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterSpeedCallback( + NotifyCallback callback, bool initialNotify); + /** + * Get the PWM speed. + * + * @return the PWM speed (-1.0 to 1.0) + */ double GetSpeed() const; + /** + * Set the PWM speed. + * + * @param speed the PWM speed (-1.0 to 1.0) + */ void SetSpeed(double speed); - std::unique_ptr RegisterPositionCallback( + /** + * Register a callback to be run when the PWM position changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterPositionCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the PWM position. + * + * @return the PWM position (0.0 to 1.0) + */ double GetPosition() const; + /** + * Set the PWM position. + * + * @param position the PWM position (0.0 to 1.0) + */ void SetPosition(double position); - std::unique_ptr RegisterPeriodScaleCallback( + /** + * Register a callback to be run when the PWM period scale changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterPeriodScaleCallback( NotifyCallback callback, bool initialNotify); + /** + * Get the PWM period scale. + * + * @return the PWM period scale + */ int GetPeriodScale() const; + /** + * Set the PWM period scale. + * + * @param periodScale the PWM period scale + */ void SetPeriodScale(int periodScale); - std::unique_ptr RegisterZeroLatchCallback( + /** + * Register a callback to be run when the PWM zero latch state changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterZeroLatchCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether the PWM is zero latched. + * + * @return true if zero latched + */ bool GetZeroLatch() const; + /** + * Define whether the PWM has been zero latched. + * + * @param zeroLatch true to indicate zero latched + */ void SetZeroLatch(bool zeroLatch); + /** + * Reset all simulation data. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/RelaySim.h b/wpilibc/src/main/native/include/frc/simulation/RelaySim.h index ff379e8937..5034885868 100644 --- a/wpilibc/src/main/native/include/frc/simulation/RelaySim.h +++ b/wpilibc/src/main/native/include/frc/simulation/RelaySim.h @@ -33,34 +33,107 @@ class RelaySim { */ explicit RelaySim(int channel); - std::unique_ptr RegisterInitializedForwardCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run when the forward direction is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterInitializedForwardCallback(NotifyCallback callback, + bool initialNotify); + /** + * Check whether the forward direction has been initialized. + * + * @return true if initialized + */ bool GetInitializedForward() const; + /** + * Define whether the forward direction has been initialized. + * + * @param initializedForward whether this object is initialized + */ void SetInitializedForward(bool initializedForward); - std::unique_ptr RegisterInitializedReverseCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run when the reverse direction is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr + RegisterInitializedReverseCallback(NotifyCallback callback, + bool initialNotify); + /** + * Check whether the reverse direction has been initialized. + * + * @return true if initialized + */ bool GetInitializedReverse() const; + /** + * Define whether the reverse direction has been initialized. + * + * @param initializedReverse whether this object is initialized + */ void SetInitializedReverse(bool initializedReverse); - std::unique_ptr RegisterForwardCallback( + /** + * Register a callback to be run when the forward direction changes state. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterForwardCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether the forward direction is active. + * + * @return true if active + */ bool GetForward() const; + /** + * Set whether the forward direction is active. + * + * @param forward true to make active + */ void SetForward(bool forward); - std::unique_ptr RegisterReverseCallback( + /** + * Register a callback to be run when the reverse direction changes state. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterReverseCallback( NotifyCallback callback, bool initialNotify); + /** + * Check whether the reverse direction is active. + * + * @return true if active + */ bool GetReverse() const; + /** + * Set whether the reverse direction is active. + * + * @param reverse true to make active + */ void SetReverse(bool reverse); + /** + * Reset all simulation data. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/RoboRioSim.h b/wpilibc/src/main/native/include/frc/simulation/RoboRioSim.h index 3e4da6e07e..162f7f97ef 100644 --- a/wpilibc/src/main/native/include/frc/simulation/RoboRioSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/RoboRioSim.h @@ -18,111 +18,385 @@ namespace frc::sim { */ class RoboRioSim { public: - static std::unique_ptr RegisterFPGAButtonCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run when the FPGA button state changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterFPGAButtonCallback(NotifyCallback callback, bool initialNotify); + /** + * Query the state of the FPGA button. + * + * @return the FPGA button state + */ static bool GetFPGAButton(); + /** + * Define the state of the FPGA button. + * + * @param fpgaButton the new state + */ static void SetFPGAButton(bool fPGAButton); - static std::unique_ptr RegisterVInVoltageCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the Vin voltage changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterVInVoltageCallback(NotifyCallback callback, bool initialNotify); + /** + * Measure the Vin voltage. + * + * @return the Vin voltage + */ static units::volt_t GetVInVoltage(); + /** + * Define the Vin voltage. + * + * @param vInVoltage the new voltage + */ static void SetVInVoltage(units::volt_t vInVoltage); - static std::unique_ptr RegisterVInCurrentCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the Vin current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterVInCurrentCallback(NotifyCallback callback, bool initialNotify); + /** + * Measure the Vin current. + * + * @return the Vin current + */ static units::ampere_t GetVInCurrent(); + /** + * Define the Vin current. + * + * @param vInCurrent the new current + */ static void SetVInCurrent(units::ampere_t vInCurrent); - static std::unique_ptr RegisterUserVoltage6VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 6V rail voltage changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserVoltage6VCallback(NotifyCallback callback, bool initialNotify); + /** + * Measure the 6V rail voltage. + * + * @return the 6V rail voltage + */ static units::volt_t GetUserVoltage6V(); + /** + * Define the 6V rail voltage. + * + * @param userVoltage6V the new voltage + */ static void SetUserVoltage6V(units::volt_t userVoltage6V); - static std::unique_ptr RegisterUserCurrent6VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 6V rail current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserCurrent6VCallback(NotifyCallback callback, bool initialNotify); + /** + * Measure the 6V rail current. + * + * @return the 6V rail current + */ static units::ampere_t GetUserCurrent6V(); + /** + * Define the 6V rail current. + * + * @param userCurrent6V the new current + */ static void SetUserCurrent6V(units::ampere_t userCurrent6V); - static std::unique_ptr RegisterUserActive6VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 6V rail active state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserActive6VCallback(NotifyCallback callback, bool initialNotify); + /** + * Get the 6V rail active state. + * + * @return true if the 6V rail is active + */ static bool GetUserActive6V(); + /** + * Set the 6V rail active state. + * + * @param userActive6V true to make rail active + */ static void SetUserActive6V(bool userActive6V); - static std::unique_ptr RegisterUserVoltage5VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 5V rail voltage changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserVoltage5VCallback(NotifyCallback callback, bool initialNotify); + /** + * Measure the 5V rail voltage. + * + * @return the 5V rail voltage + */ static units::volt_t GetUserVoltage5V(); + /** + * Define the 5V rail voltage. + * + * @param userVoltage5V the new voltage + */ static void SetUserVoltage5V(units::volt_t userVoltage5V); - static std::unique_ptr RegisterUserCurrent5VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 5V rail current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserCurrent5VCallback(NotifyCallback callback, bool initialNotify); + /** + * Measure the 5V rail current. + * + * @return the 5V rail current + */ static units::ampere_t GetUserCurrent5V(); + /** + * Define the 5V rail current. + * + * @param userCurrent5V the new current + */ static void SetUserCurrent5V(units::ampere_t userCurrent5V); - static std::unique_ptr RegisterUserActive5VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 5V rail active state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserActive5VCallback(NotifyCallback callback, bool initialNotify); + /** + * Get the 5V rail active state. + * + * @return true if the 5V rail is active + */ static bool GetUserActive5V(); + /** + * Set the 5V rail active state. + * + * @param userActive5V true to make rail active + */ static void SetUserActive5V(bool userActive5V); - static std::unique_ptr RegisterUserVoltage3V3Callback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 3.3V rail voltage changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserVoltage3V3Callback(NotifyCallback callback, bool initialNotify); + /** + * Measure the 3.3V rail voltage. + * + * @return the 3.3V rail voltage + */ static units::volt_t GetUserVoltage3V3(); + /** + * Define the 3.3V rail voltage. + * + * @param userVoltage3V3 the new voltage + */ static void SetUserVoltage3V3(units::volt_t userVoltage3V3); - static std::unique_ptr RegisterUserCurrent3V3Callback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 3.3V rail current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserCurrent3V3Callback(NotifyCallback callback, bool initialNotify); + /** + * Measure the 3.3V rail current. + * + * @return the 3.3V rail current + */ static units::ampere_t GetUserCurrent3V3(); + /** + * Define the 3.3V rail current. + * + * @param userCurrent3V3 the new current + */ static void SetUserCurrent3V3(units::ampere_t userCurrent3V3); - static std::unique_ptr RegisterUserActive3V3Callback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 3.3V rail active state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserActive3V3Callback(NotifyCallback callback, bool initialNotify); + /** + * Get the 3.3V rail active state. + * + * @return true if the 3.3V rail is active + */ static bool GetUserActive3V3(); + /** + * Set the 3.3V rail active state. + * + * @param userActive3V3 true to make rail active + */ static void SetUserActive3V3(bool userActive3V3); - static std::unique_ptr RegisterUserFaults6VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 6V rail number of faults + * changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserFaults6VCallback(NotifyCallback callback, bool initialNotify); + /** + * Get the 6V rail number of faults. + * + * @return number of faults + */ static int GetUserFaults6V(); + /** + * Set the 6V rail number of faults. + * + * @param userFaults6V number of faults + */ static void SetUserFaults6V(int userFaults6V); - static std::unique_ptr RegisterUserFaults5VCallback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 5V rail number of faults + * changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserFaults5VCallback(NotifyCallback callback, bool initialNotify); + /** + * Get the 5V rail number of faults. + * + * @return number of faults + */ static int GetUserFaults5V(); + /** + * Set the 5V rail number of faults. + * + * @param userFaults5V number of faults + */ static void SetUserFaults5V(int userFaults5V); - static std::unique_ptr RegisterUserFaults3V3Callback( - NotifyCallback callback, bool initialNotify); + /** + * Register a callback to be run whenever the 3.3V rail number of faults + * changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the + * initial value + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] static std::unique_ptr + RegisterUserFaults3V3Callback(NotifyCallback callback, bool initialNotify); + /** + * Get the 3.3V rail number of faults. + * + * @return number of faults + */ static int GetUserFaults3V3(); + /** + * Set the 3.3V rail number of faults. + * + * @param userFaults3V3 number of faults + */ static void SetUserFaults3V3(int userFaults3V3); + /** + * Reset all simulation data. + */ static void ResetData(); }; } // namespace frc::sim diff --git a/wpilibc/src/main/native/include/frc/simulation/SPIAccelerometerSim.h b/wpilibc/src/main/native/include/frc/simulation/SPIAccelerometerSim.h index 4b360a2342..9d31bd0acb 100644 --- a/wpilibc/src/main/native/include/frc/simulation/SPIAccelerometerSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/SPIAccelerometerSim.h @@ -11,43 +11,136 @@ namespace frc::sim { class SPIAccelerometerSim { public: + /** + * Construct a new simulation object. + * + * @param index the HAL index of the accelerometer + */ explicit SPIAccelerometerSim(int index); - std::unique_ptr RegisterActiveCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run when this accelerometer activates. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterActiveCallback( + NotifyCallback callback, bool initialNotify); + /** + * Check whether the accelerometer is active. + * + * @return true if active + */ bool GetActive() const; + /** + * Define whether this accelerometer is active. + * + * @param active the new state + */ void SetActive(bool active); - std::unique_ptr RegisterRangeCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the range changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterRangeCallback( + NotifyCallback callback, bool initialNotify); + /** + * Check the range of this accelerometer. + * + * @return the accelerometer range + */ int GetRange() const; + /** + * Change the range of this accelerometer. + * + * @param range the new accelerometer range + */ void SetRange(int range); - std::unique_ptr RegisterXCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the X axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterXCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the X axis value. + * + * @return the X axis measurement + */ double GetX() const; + /** + * Change the X axis value of the accelerometer. + * + * @param x the new reading of the X axis + */ void SetX(double x); - std::unique_ptr RegisterYCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the Y axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterYCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the Y axis value. + * + * @return the Y axis measurement + */ double GetY() const; + /** + * Change the Y axis value of the accelerometer. + * + * @param y the new reading of the Y axis + */ void SetY(double y); - std::unique_ptr RegisterZCallback(NotifyCallback callback, - bool initialNotify); + /** + * Register a callback to be run whenever the Z axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the CallbackStore object associated with this callback + */ + [[nodiscard]] std::unique_ptr RegisterZCallback( + NotifyCallback callback, bool initialNotify); + /** + * Measure the Z axis value. + * + * @return the Z axis measurement + */ double GetZ() const; + /** + * Change the Z axis value of the accelerometer. + * + * @param z the new reading of the Z axis + */ void SetZ(double z); + /** + * Reset all simulation data of this object. + */ void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/SimDeviceSim.h b/wpilibc/src/main/native/include/frc/simulation/SimDeviceSim.h index 3e5de8b290..142f61dfc3 100644 --- a/wpilibc/src/main/native/include/frc/simulation/SimDeviceSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/SimDeviceSim.h @@ -25,26 +25,84 @@ class SimDeviceSim { */ explicit SimDeviceSim(const char* name); + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ hal::SimValue GetValue(const char* name) const; + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ + hal::SimInt GetInt(const char* name) const; + + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ + hal::SimLong GetLong(const char* name) const; + + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ hal::SimDouble GetDouble(const char* name) const; + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ hal::SimEnum GetEnum(const char* name) const; + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ hal::SimBoolean GetBoolean(const char* name) const; + /** + * Get all options for the given enum. + * + * @param val the enum + * @return names of the different values for that enum + */ static std::vector GetEnumOptions(hal::SimEnum val); + /** + * Get all properties. + * + * @param callback callback called for each property (SimValue). Signature + * of the callback must be const char*, HAL_SimValueHandle, + * int, const HAL_Value* + */ template void EnumerateValues(F callback) const { return HALSIM_EnumerateSimValues( m_handle, &callback, [](const char* name, void* param, HAL_SimValueHandle handle, - HAL_Bool readonly, const struct HAL_Value* value) { - std::invoke(*static_cast(param), name, handle, readonly, value); + int direction, const struct HAL_Value* value) { + std::invoke(*static_cast(param), name, handle, direction, value); }); } + /** + * Get the raw handle of this object. + * + * @return the handle used to refer to this object + */ operator HAL_SimDeviceHandle() const { return m_handle; } // NOLINT template @@ -56,6 +114,9 @@ class SimDeviceSim { }); } + /** + * Reset all SimDevice data. + */ static void ResetData(); private: diff --git a/wpilibc/src/main/native/include/frc/simulation/SimHooks.h b/wpilibc/src/main/native/include/frc/simulation/SimHooks.h index dfde4fcd47..84d274c97c 100644 --- a/wpilibc/src/main/native/include/frc/simulation/SimHooks.h +++ b/wpilibc/src/main/native/include/frc/simulation/SimHooks.h @@ -11,6 +11,11 @@ namespace frc::sim { +/** + * Override the HAL runtime type (simulated/real). + * + * @param type runtime type + */ void SetRuntimeType(HAL_RuntimeType type); void WaitForProgramStart(); @@ -19,16 +24,40 @@ void SetProgramStarted(); bool GetProgramStarted(); +/** + * Restart the simulator time. + */ void RestartTiming(); +/** + * Pause the simulator time. + */ void PauseTiming(); +/** + * Resume the simulator time. + */ void ResumeTiming(); +/** + * Check if the simulator time is paused. + * + * @return true if paused + */ bool IsTimingPaused(); +/** + * Advance the simulator time and wait for all notifiers to run. + * + * @param deltaSeconds the amount to advance (in seconds) + */ void StepTiming(units::second_t delta); +/** + * Advance the simulator time and return immediately. + * + * @param deltaSeconds the amount to advance (in seconds) + */ void StepTimingAsync(units::second_t delta); } // namespace frc::sim diff --git a/wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h b/wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h index 23000d6e87..e75205bff3 100644 --- a/wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/XboxControllerSim.h @@ -31,26 +31,86 @@ class XboxControllerSim : public GenericHIDSim { */ explicit XboxControllerSim(int port); + /** + * Change the X value of the joystick. + * + * @param hand the joystick hand + * @param value the new value + */ void SetX(GenericHID::JoystickHand hand, double value); + /** + * Change the Y value of the joystick. + * + * @param hand the joystick hand + * @param value the new value + */ void SetY(GenericHID::JoystickHand hand, double value); + /** + * Change the value of a trigger axis on the joystick. + * + * @param hand the joystick hand + * @param value the new value + */ void SetTriggerAxis(GenericHID::JoystickHand hand, double value); + /** + * Change the value of a bumper on the joystick. + * + * @param hand the joystick hand + * @param state the new value + */ void SetBumper(GenericHID::JoystickHand hand, bool state); + /** + * Change the value of a button on the joystick. + * + * @param hand the joystick hand + * @param state the new value + */ void SetStickButton(GenericHID::JoystickHand hand, bool state); + /** + * Change the value of the A button. + * + * @param state the new value + */ void SetAButton(bool state); + /** + * Change the value of the B button. + * + * @param state the new value + */ void SetBButton(bool state); + /** + * Change the value of the X button. + * + * @param state the new value + */ void SetXButton(bool state); + /** + * Change the value of the Y button. + * + * @param state the new value + */ void SetYButton(bool state); + /** + * Change the value of the Back button. + * + * @param state the new value + */ void SetBackButton(bool state); + /** + * Change the value of the Start button. + * + * @param state the new value + */ void SetStartButton(bool state); }; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ADXRS450_GyroSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ADXRS450_GyroSim.java index 0743cbde0b..27e06a3cbd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ADXRS450_GyroSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ADXRS450_GyroSim.java @@ -8,7 +8,7 @@ import edu.wpi.first.hal.SimDouble; import edu.wpi.first.wpilibj.ADXRS450_Gyro; /** Class to control a simulated ADXRS450 gyroscope. */ -@SuppressWarnings("TypeName") +@SuppressWarnings({"TypeName", "AbbreviationAsWordInName"}) public class ADXRS450_GyroSim { private final SimDouble m_simAngle; private final SimDouble m_simRate; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AddressableLEDSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AddressableLEDSim.java index 9df269275d..bf543c03b3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AddressableLEDSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AddressableLEDSim.java @@ -60,71 +60,161 @@ public class AddressableLEDSim { return new AddressableLEDSim(index); } + /** + * Register a callback on the Initialized property. + * + * @param callback the callback that will be called whenever the Initialized property is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = AddressableLEDDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelInitializedCallback); } + /** + * Check if initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return AddressableLEDDataJNI.getInitialized(m_index); } + /** + * Change the Initialized value of the LED strip. + * + * @param initialized the new value + */ public void setInitialized(boolean initialized) { AddressableLEDDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback on the output port. + * + * @param callback the callback that will be called whenever the output port is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerOutputPortCallback(NotifyCallback callback, boolean initialNotify) { int uid = AddressableLEDDataJNI.registerOutputPortCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelOutputPortCallback); } + /** + * Get the output port. + * + * @return the output port + */ public int getOutputPort() { return AddressableLEDDataJNI.getOutputPort(m_index); } + /** + * Change the output port. + * + * @param outputPort the new output port + */ public void setOutputPort(int outputPort) { AddressableLEDDataJNI.setOutputPort(m_index, outputPort); } + /** + * Register a callback on the length. + * + * @param callback the callback that will be called whenever the length is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerLengthCallback(NotifyCallback callback, boolean initialNotify) { int uid = AddressableLEDDataJNI.registerLengthCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelLengthCallback); } + /** + * Get the length of the LED strip. + * + * @return the length + */ public int getLength() { return AddressableLEDDataJNI.getLength(m_index); } + /** + * Change the length of the LED strip. + * + * @param length the new value + */ public void setLength(int length) { AddressableLEDDataJNI.setLength(m_index, length); } + /** + * Register a callback on whether the LEDs are running. + * + * @param callback the callback that will be called whenever the LED state is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerRunningCallback(NotifyCallback callback, boolean initialNotify) { int uid = AddressableLEDDataJNI.registerRunningCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelRunningCallback); } + /** + * Check if the LEDs are running. + * + * @return true if they are + */ public boolean getRunning() { return AddressableLEDDataJNI.getRunning(m_index); } + /** + * Change whether the LEDs are active. + * + * @param running the new value + */ public void setRunning(boolean running) { AddressableLEDDataJNI.setRunning(m_index, running); } + /** + * Register a callback on the LED data. + * + * @param callback the callback that will be called whenever the LED data is changed + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerDataCallback(ConstBufferCallback callback) { int uid = AddressableLEDDataJNI.registerDataCallback(m_index, callback); return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelDataCallback); } + /** + * Get the LED data. + * + * @return the LED data + */ public byte[] getData() { return AddressableLEDDataJNI.getData(m_index); } + /** + * Change the LED data. + * + * @param data the new data + */ public void setData(byte[] data) { AddressableLEDDataJNI.setData(m_index, data); } + /** Reset all simulation data for this LED object. */ public void resetData() { AddressableLEDDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java index 7435a37c78..87217aa741 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogGyroSim.java @@ -30,45 +30,100 @@ public class AnalogGyroSim { 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. Save a reference to + * this object so GC doesn't cancel the 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. Save a reference to + * this object so GC doesn't cancel the 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. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogGyroDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogGyroDataJNI::cancelInitializedCallback); } + /** + * Check if the gyro is initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return AnalogGyroDataJNI.getInitialized(m_index); } + /** + * Set whether this gyro is initialized. + * + * @param initialized the new value + */ public void setInitialized(boolean initialized) { AnalogGyroDataJNI.setInitialized(m_index, initialized); } + /** Reset all simulation data for this object. */ public void resetData() { AnalogGyroDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java index 3f0a9b8486..87dce71700 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogInputSim.java @@ -30,59 +30,139 @@ public class AnalogInputSim { m_index = channel; } + /** + * Register a callback on whether the analog input is initialized. + * + * @param callback the callback that will be called whenever the analog input is initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogInDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelInitializedCallback); } + /** + * Check if this analog input has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return AnalogInDataJNI.getInitialized(m_index); } + /** + * Change whether this analog input has been initialized. + * + * @param initialized the new value + */ public void setInitialized(boolean initialized) { AnalogInDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback on the number of average bits. + * + * @param callback the callback that will be called whenever the number of average bits is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerAverageBitsCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogInDataJNI.registerAverageBitsCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAverageBitsCallback); } + /** + * Get the number of average bits. + * + * @return the number of average bits + */ public int getAverageBits() { return AnalogInDataJNI.getAverageBits(m_index); } + /** + * Change the number of average bits. + * + * @param averageBits the new value + */ public void setAverageBits(int averageBits) { AnalogInDataJNI.setAverageBits(m_index, averageBits); } + /** + * Register a callback on the amount of oversampling bits. + * + * @param callback the callback that will be called whenever the oversampling bits are changed. + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerOversampleBitsCallback( NotifyCallback callback, boolean initialNotify) { int uid = AnalogInDataJNI.registerOversampleBitsCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelOversampleBitsCallback); } + /** + * Get the amount of oversampling bits. + * + * @return the amount of oversampling bits + */ public int getOversampleBits() { return AnalogInDataJNI.getOversampleBits(m_index); } + /** + * Change the amount of oversampling bits. + * + * @param oversampleBits the new value + */ public void setOversampleBits(int oversampleBits) { AnalogInDataJNI.setOversampleBits(m_index, oversampleBits); } + /** + * Register a callback on the voltage. + * + * @param callback the callback that will be called whenever the voltage is changed. + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerVoltageCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogInDataJNI.registerVoltageCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelVoltageCallback); } + /** + * Get the voltage. + * + * @return the voltage + */ public double getVoltage() { return AnalogInDataJNI.getVoltage(m_index); } + /** + * Change the voltage. + * + * @param voltage the new value + */ public void setVoltage(double voltage) { AnalogInDataJNI.setVoltage(m_index, voltage); } + /** + * Register a callback on whether the accumulator is initialized. + * + * @param callback the callback that will be called whenever the accumulator is initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerAccumulatorInitializedCallback( NotifyCallback callback, boolean initialNotify) { int uid = @@ -90,70 +170,153 @@ public class AnalogInputSim { 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. Save a reference to + * this object so GC doesn't cancel the 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. Save a reference to + * this object so GC doesn't cancel the 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. Save a reference to + * this object so GC doesn't cancel the 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. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerAccumulatorDeadbandCallback( NotifyCallback callback, boolean initialNotify) { int uid = AnalogInDataJNI.registerAccumulatorDeadbandCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogInDataJNI::cancelAccumulatorDeadbandCallback); } + /** + * Get the accumulator deadband. + * + * @return the accumulator deadband + */ public int getAccumulatorDeadband() { return AnalogInDataJNI.getAccumulatorDeadband(m_index); } + /** + * Change the accumulator deadband. + * + * @param accumulatorDeadband the new deadband + */ public void setAccumulatorDeadband(int accumulatorDeadband) { AnalogInDataJNI.setAccumulatorDeadband(m_index, accumulatorDeadband); } + /** Reset all simulation data for this object. */ public void resetData() { AnalogInDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogOutputSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogOutputSim.java index 819f0d88ae..985fcd9527 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogOutputSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogOutputSim.java @@ -30,32 +30,69 @@ public class AnalogOutputSim { m_index = channel; } + /** + * Register a callback to be run whenever the voltage changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerVoltageCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogOutDataJNI.registerVoltageCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogOutDataJNI::cancelVoltageCallback); } + /** + * Read the analog output voltage. + * + * @return the voltage on this analog output + */ public double getVoltage() { return AnalogOutDataJNI.getVoltage(m_index); } + /** + * Set the analog output voltage. + * + * @param voltage the new voltage on this analog output + */ public void setVoltage(double voltage) { AnalogOutDataJNI.setVoltage(m_index, voltage); } + /** + * Register a callback to be run when this analog output is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogOutDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogOutDataJNI::cancelInitializedCallback); } + /** + * Check whether this analog output has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return AnalogOutDataJNI.getInitialized(m_index); } + /** + * Define whether this analog output has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { AnalogOutDataJNI.setInitialized(m_index, initialized); } + /** Reset all simulation data on this object. */ public void resetData() { AnalogOutDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java index 44efb9d97a..58d51b199f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/AnalogTriggerSim.java @@ -52,19 +52,45 @@ public class AnalogTriggerSim { return new AnalogTriggerSim(index); } + /** + * Register a callback on whether the analog trigger is initialized. + * + * @param callback the callback that will be called whenever the analog trigger is initialized + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = AnalogTriggerDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelInitializedCallback); } + /** + * Check if this analog trigger has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return AnalogTriggerDataJNI.getInitialized(m_index); } + /** + * Change whether this analog trigger has been initialized. + * + * @param initialized the new value + */ public void setInitialized(boolean initialized) { AnalogTriggerDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback on the lower bound. + * + * @param callback the callback that will be called whenever the lower bound is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerTriggerLowerBoundCallback( NotifyCallback callback, boolean initialNotify) { int uid = @@ -72,14 +98,32 @@ public class AnalogTriggerSim { return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelTriggerLowerBoundCallback); } + /** + * Get the lower bound. + * + * @return the lower bound + */ public double getTriggerLowerBound() { return AnalogTriggerDataJNI.getTriggerLowerBound(m_index); } + /** + * Change the lower bound. + * + * @param triggerLowerBound the new lower bound + */ public void setTriggerLowerBound(double triggerLowerBound) { AnalogTriggerDataJNI.setTriggerLowerBound(m_index, triggerLowerBound); } + /** + * Register a callback on the upper bound. + * + * @param callback the callback that will be called whenever the upper bound is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerTriggerUpperBoundCallback( NotifyCallback callback, boolean initialNotify) { int uid = @@ -87,14 +131,25 @@ public class AnalogTriggerSim { return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelTriggerUpperBoundCallback); } + /** + * Get the upper bound. + * + * @return the upper bound + */ public double getTriggerUpperBound() { return AnalogTriggerDataJNI.getTriggerUpperBound(m_index); } + /** + * Change the upper bound. + * + * @param triggerUpperBound the new upper bound + */ public void setTriggerUpperBound(double triggerUpperBound) { AnalogTriggerDataJNI.setTriggerUpperBound(m_index, triggerUpperBound); } + /** Reset all simulation data for this object. */ public void resetData() { AnalogTriggerDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BatterySim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BatterySim.java index 05f71d48e6..78c988848c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BatterySim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BatterySim.java @@ -4,6 +4,7 @@ package edu.wpi.first.wpilibj.simulation; +/** A utility class to simulate the robot battery. */ public final class BatterySim { private BatterySim() { // Utility class diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BuiltInAccelerometerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BuiltInAccelerometerSim.java index 496788f2c8..5714a2d94b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BuiltInAccelerometerSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/BuiltInAccelerometerSim.java @@ -27,71 +27,165 @@ public class BuiltInAccelerometerSim { m_index = 0; } + /** + * Register a callback to be run when this accelerometer activates. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerActiveCallback(NotifyCallback callback, boolean initialNotify) { int uid = AccelerometerDataJNI.registerActiveCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AccelerometerDataJNI::cancelActiveCallback); } + /** + * Check whether the accelerometer is active. + * + * @return true if active + */ public boolean getActive() { return AccelerometerDataJNI.getActive(m_index); } + /** + * Define whether this accelerometer is active. + * + * @param active the new state + */ public void setActive(boolean active) { AccelerometerDataJNI.setActive(m_index, active); } + /** + * Register a callback to be run whenever the range changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerRangeCallback(NotifyCallback callback, boolean initialNotify) { int uid = AccelerometerDataJNI.registerRangeCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AccelerometerDataJNI::cancelRangeCallback); } + /** + * Check the range of this accelerometer. + * + * @return the accelerometer range + */ public int getRange() { return AccelerometerDataJNI.getRange(m_index); } + /** + * Change the range of this accelerometer. + * + * @param range the new accelerometer range + */ public void setRange(int range) { AccelerometerDataJNI.setRange(m_index, range); } + /** + * Register a callback to be run whenever the X axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerXCallback(NotifyCallback callback, boolean initialNotify) { int uid = AccelerometerDataJNI.registerXCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AccelerometerDataJNI::cancelXCallback); } + /** + * Measure the X axis value. + * + * @return the X axis measurement + */ public double getX() { return AccelerometerDataJNI.getX(m_index); } + /** + * Change the X axis value of the accelerometer. + * + * @param x the new reading of the X axis + */ + @SuppressWarnings("ParameterName") public void setX(double x) { AccelerometerDataJNI.setX(m_index, x); } + /** + * Register a callback to be run whenever the Y axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerYCallback(NotifyCallback callback, boolean initialNotify) { int uid = AccelerometerDataJNI.registerYCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AccelerometerDataJNI::cancelYCallback); } + /** + * Measure the Y axis value. + * + * @return the Y axis measurement + */ public double getY() { return AccelerometerDataJNI.getY(m_index); } + /** + * Change the Y axis value of the accelerometer. + * + * @param y the new reading of the Y axis + */ + @SuppressWarnings("ParameterName") public void setY(double y) { AccelerometerDataJNI.setY(m_index, y); } + /** + * Register a callback to be run whenever the Z axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerZCallback(NotifyCallback callback, boolean initialNotify) { int uid = AccelerometerDataJNI.registerZCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, AccelerometerDataJNI::cancelZCallback); } + /** + * Measure the Z axis value. + * + * @return the Z axis measurement + */ public double getZ() { return AccelerometerDataJNI.getZ(m_index); } + /** + * Change the Z axis value of the accelerometer. + * + * @param z the new reading of the Z axis + */ + @SuppressWarnings("ParameterName") public void setZ(double z) { AccelerometerDataJNI.setZ(m_index, z); } + /** Reset all simulation data of this object. */ public void resetData() { AccelerometerDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/CallbackStore.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/CallbackStore.java index 0f0ea7568f..7710af3685 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/CallbackStore.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/CallbackStore.java @@ -4,19 +4,26 @@ package edu.wpi.first.wpilibj.simulation; +/** Manages simulation callbacks; each object is associated with a callback. */ public class CallbackStore implements AutoCloseable { + /** Note: This interface is for simulation classes only. It should not be used by teams! */ interface CancelCallbackFunc { void cancel(int index, int uid); } + /** Note: This interface is for simulation classes only. It should not be used by teams! */ interface CancelCallbackChannelFunc { void cancel(int index, int channel, int uid); } + /** Note: This interface is for simulation classes only. It should not be used by teams! */ interface CancelCallbackNoIndexFunc { void cancel(int uid); } + /** + * Note: This constructor is for simulation classes only. It should not be called by teams! + */ public CallbackStore(int index, int uid, CancelCallbackFunc ccf) { this.m_cancelType = kNormalCancel; this.m_index = index; @@ -24,6 +31,9 @@ public class CallbackStore implements AutoCloseable { this.m_cancelCallback = ccf; } + /** + * Note: This constructor is for simulation classes only. It should not be called by teams! + */ public CallbackStore(int index, int channel, int uid, CancelCallbackChannelFunc ccf) { this.m_cancelType = kChannelCancel; this.m_index = index; @@ -32,6 +42,9 @@ public class CallbackStore implements AutoCloseable { this.m_cancelCallbackChannel = ccf; } + /** + * Note: This constructor is for simulation classes only. It should not be called by teams! + */ public CallbackStore(int uid, CancelCallbackNoIndexFunc ccf) { this.m_cancelType = kNoIndexCancel; this.m_uid = uid; @@ -49,6 +62,7 @@ public class CallbackStore implements AutoCloseable { private static final int kNoIndexCancel = 2; private int m_cancelType; + /** Cancel the callback associated with this object. */ @Override public void close() { switch (m_cancelType) { @@ -68,6 +82,7 @@ public class CallbackStore implements AutoCloseable { m_cancelType = -1; } + @SuppressWarnings("NoFinalizer") @Override protected void finalize() throws Throwable { try { diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DIOSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DIOSim.java index 201b0fd85b..83afb74e8d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DIOSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DIOSim.java @@ -40,71 +40,162 @@ public class DIOSim { m_index = channel; } + /** + * Register a callback to be run when this DIO is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = DIODataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DIODataJNI::cancelInitializedCallback); } + /** + * Check whether this DIO has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return DIODataJNI.getInitialized(m_index); } + /** + * Define whether this DIO has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { DIODataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run whenever the DIO value changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerValueCallback(NotifyCallback callback, boolean initialNotify) { int uid = DIODataJNI.registerValueCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DIODataJNI::cancelValueCallback); } + /** + * Read the value of the DIO port. + * + * @return the DIO value + */ public boolean getValue() { return DIODataJNI.getValue(m_index); } + /** + * Change the DIO value. + * + * @param value the new value + */ public void setValue(boolean value) { DIODataJNI.setValue(m_index, value); } + /** + * Register a callback to be run whenever the pulse length changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerPulseLengthCallback(NotifyCallback callback, boolean initialNotify) { int uid = DIODataJNI.registerPulseLengthCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DIODataJNI::cancelPulseLengthCallback); } + /** + * Read the pulse length. + * + * @return the pulse length of this DIO port + */ public double getPulseLength() { return DIODataJNI.getPulseLength(m_index); } + /** + * Change the pulse length of this DIO port. + * + * @param pulseLength the new pulse length + */ public void setPulseLength(double pulseLength) { DIODataJNI.setPulseLength(m_index, pulseLength); } + /** + * Register a callback to be run whenever this DIO changes to be an input. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerIsInputCallback(NotifyCallback callback, boolean initialNotify) { int uid = DIODataJNI.registerIsInputCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DIODataJNI::cancelIsInputCallback); } + /** + * Check whether this DIO port is currently an Input. + * + * @return true if Input + */ public boolean getIsInput() { return DIODataJNI.getIsInput(m_index); } + /** + * Define whether this DIO port is an Input. + * + * @param isInput whether this DIO should be an Input + */ public void setIsInput(boolean isInput) { DIODataJNI.setIsInput(m_index, isInput); } + /** + * Register a callback to be run whenever the filter index changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerFilterIndexCallback(NotifyCallback callback, boolean initialNotify) { int uid = DIODataJNI.registerFilterIndexCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DIODataJNI::cancelFilterIndexCallback); } + /** + * Read the filter index. + * + * @return the filter index of this DIO port + */ public int getFilterIndex() { return DIODataJNI.getFilterIndex(m_index); } + /** + * Change the filter index of this DIO port. + * + * @param filterIndex the new filter index + */ public void setFilterIndex(int filterIndex) { DIODataJNI.setFilterIndex(m_index, filterIndex); } + /** Reset all simulation data of this object. */ public void resetData() { DIODataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java index 22fb40e7bd..19657f3dcf 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DifferentialDrivetrainSim.java @@ -60,8 +60,8 @@ public class DifferentialDrivetrainSim { * Create a SimDrivetrain. * * @param driveMotor A {@link DCMotor} representing the left side of the drivetrain. - * @param gearing The gearing on the drive between motor and wheel, as output over input. This - * must be the same ratio as the ratio used to identify or create the drivetrainPlant. + * @param gearing The gearing ratio between motor and wheel, as output over input. This must be + * the same ratio as the ratio used to identify or create the drivetrainPlant. * @param jKgMetersSquared The moment of inertia of the drivetrain about its center. * @param massKg The mass of the drivebase. * @param wheelRadiusMeters The radius of the wheels on the drivetrain. @@ -72,6 +72,7 @@ public class DifferentialDrivetrainSim { * m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting * point. */ + @SuppressWarnings("ParameterName") public DifferentialDrivetrainSim( DCMotor driveMotor, double gearing, @@ -147,6 +148,11 @@ public class DifferentialDrivetrainSim { m_u = clampInput(VecBuilder.fill(leftVoltageVolts, rightVoltageVolts)); } + /** + * Update the drivetrain states with the current time difference. + * + * @param dtSeconds the time difference + */ @SuppressWarnings("LocalVariableName") public void update(double dtSeconds) { @@ -163,6 +169,12 @@ public class DifferentialDrivetrainSim { return m_x; } + /** + * Get one of the drivetrain states. + * + * @param state the state to get + * @return the state + */ double getState(State state) { return m_x.get(state.value, 0); } @@ -221,6 +233,11 @@ public class DifferentialDrivetrainSim { return getOutput(State.kLeftVelocity); } + /** + * Get the current draw of the left side of the drivetrain. + * + * @return the drivetrain's left side current draw, in amps + */ public double getLeftCurrentDrawAmps() { var loadIleft = m_motor.getCurrent( @@ -230,6 +247,11 @@ public class DifferentialDrivetrainSim { return loadIleft; } + /** + * Get the current draw of the right side of the drivetrain. + * + * @return the drivetrain's right side current draw, in amps + */ public double getRightCurrentDrawAmps() { var loadIright = m_motor.getCurrent( @@ -240,10 +262,20 @@ public class DifferentialDrivetrainSim { return loadIright; } + /** + * Get the current draw of the drivetrain. + * + * @return the current draw, in amps + */ public double getCurrentDrawAmps() { return getLeftCurrentDrawAmps() + getRightCurrentDrawAmps(); } + /** + * Get the drivetrain gearing. + * + * @return the gearing ration + */ public double getCurrentGearing() { return m_currentGearing; } @@ -279,7 +311,7 @@ public class DifferentialDrivetrainSim { m_x.set(State.kRightPosition.value, 0, 0); } - @SuppressWarnings({"DuplicatedCode", "LocalVariableName"}) + @SuppressWarnings({"DuplicatedCode", "LocalVariableName", "ParameterName"}) protected Matrix getDynamics(Matrix x, Matrix u) { // Because G can be factored out of B, we can divide by the old ratio and multiply @@ -327,6 +359,7 @@ public class DifferentialDrivetrainSim { return StateSpaceUtil.normalizeInputVector(u, RobotController.getBatteryVoltage()); } + /** Represents the different states of the drivetrain. */ enum State { kX(0), kY(1), @@ -339,6 +372,7 @@ public class DifferentialDrivetrainSim { @SuppressWarnings("MemberName") public final int value; + @SuppressWarnings("ParameterName") State(int i) { this.value = i; } @@ -358,11 +392,13 @@ public class DifferentialDrivetrainSim { @SuppressWarnings("MemberName") public final double value; + @SuppressWarnings("ParameterName") KitbotGearing(double i) { this.value = i; } } + /** Represents common motor layouts of the kit drivetrain. */ public enum KitbotMotor { kSingleCIMPerSide(DCMotor.getCIM(1)), kDualCIMPerSide(DCMotor.getCIM(2)), @@ -372,11 +408,13 @@ public class DifferentialDrivetrainSim { @SuppressWarnings("MemberName") public final DCMotor value; + @SuppressWarnings("ParameterName") KitbotMotor(DCMotor i) { this.value = i; } } + /** Represents common wheel sizes of the kit drivetrain. */ public enum KitbotWheelSize { SixInch(Units.inchesToMeters(6)), EightInch(Units.inchesToMeters(8)), @@ -385,6 +423,7 @@ public class DifferentialDrivetrainSim { @SuppressWarnings("MemberName") public final double value; + @SuppressWarnings("ParameterName") KitbotWheelSize(double i) { this.value = i; } @@ -430,6 +469,7 @@ public class DifferentialDrivetrainSim { * m/s, and position measurement standard deviations of 0.005 meters are a reasonable starting * point. */ + @SuppressWarnings("ParameterName") public static DifferentialDrivetrainSim createKitbotSim( KitbotMotor motor, KitbotGearing gearing, diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DigitalPWMSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DigitalPWMSim.java index d7b2bb1792..f18f092b80 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DigitalPWMSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DigitalPWMSim.java @@ -57,45 +57,100 @@ public class DigitalPWMSim { return new DigitalPWMSim(index); } + /** + * Register a callback to be run when this PWM output is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = DigitalPWMDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DigitalPWMDataJNI::cancelInitializedCallback); } + /** + * Check whether this PWM output has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return DigitalPWMDataJNI.getInitialized(m_index); } + /** + * Define whether this PWM output has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { DigitalPWMDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run whenever the duty cycle value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerDutyCycleCallback(NotifyCallback callback, boolean initialNotify) { int uid = DigitalPWMDataJNI.registerDutyCycleCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DigitalPWMDataJNI::cancelDutyCycleCallback); } + /** + * Read the duty cycle value. + * + * @return the duty cycle value of this PWM output + */ public double getDutyCycle() { return DigitalPWMDataJNI.getDutyCycle(m_index); } + /** + * Set the duty cycle value of this PWM output. + * + * @param dutyCycle the new value + */ public void setDutyCycle(double dutyCycle) { DigitalPWMDataJNI.setDutyCycle(m_index, dutyCycle); } + /** + * Register a callback to be run whenever the pin changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerPinCallback(NotifyCallback callback, boolean initialNotify) { int uid = DigitalPWMDataJNI.registerPinCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DigitalPWMDataJNI::cancelPinCallback); } + /** + * Check the pin number. + * + * @return the pin number + */ public int getPin() { return DigitalPWMDataJNI.getPin(m_index); } + /** + * Change the pin number. + * + * @param pin the new pin number + */ public void setPin(int pin) { DigitalPWMDataJNI.setPin(m_index, pin); } + /** Reset all simulation data. */ public void resetData() { DigitalPWMDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DriverStationSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DriverStationSim.java index 7eb947cb1b..fac5dcbf2e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DriverStationSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DriverStationSim.java @@ -12,95 +12,217 @@ import edu.wpi.first.wpilibj.DriverStation; /** Class to control a simulated driver station. */ @SuppressWarnings({"PMD.UseUtilityClass", "PMD.GodClass", "PMD.ExcessivePublicCount"}) public class DriverStationSim { + /** + * Register a callback on whether the DS is enabled. + * + * @param callback the callback that will be called whenever the enabled state is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerEnabledCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerEnabledCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelEnabledCallback); } + /** + * Check if the DS is enabled. + * + * @return true if enabled + */ public static boolean getEnabled() { return DriverStationDataJNI.getEnabled(); } + /** + * Change whether the DS is enabled. + * + * @param enabled the new value + */ public static void setEnabled(boolean enabled) { DriverStationDataJNI.setEnabled(enabled); } + /** + * Register a callback on whether the DS is in autonomous mode. + * + * @param callback the callback that will be called on autonomous mode entrance/exit + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerAutonomousCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerAutonomousCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelAutonomousCallback); } + /** + * Check if the DS is in autonomous. + * + * @return true if autonomous + */ public static boolean getAutonomous() { return DriverStationDataJNI.getAutonomous(); } + /** + * Change whether the DS is in autonomous. + * + * @param autonomous the new value + */ public static void setAutonomous(boolean autonomous) { DriverStationDataJNI.setAutonomous(autonomous); } + /** + * Register a callback on whether the DS is in test mode. + * + * @param callback the callback that will be called whenever the test mode is entered or left + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerTestCallback(NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerTestCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelTestCallback); } + /** + * Check if the DS is in test. + * + * @return true if test + */ public static boolean getTest() { return DriverStationDataJNI.getTest(); } + /** + * Change whether the DS is in test. + * + * @param test the new value + */ public static void setTest(boolean test) { DriverStationDataJNI.setTest(test); } + /** + * Register a callback on the eStop state. + * + * @param callback the callback that will be called whenever the eStop state changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerEStopCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerEStopCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelEStopCallback); } + /** + * Check if eStop has been activated. + * + * @return true if eStopped + */ public static boolean getEStop() { return DriverStationDataJNI.getEStop(); } + /** + * Set whether eStop is active. + * + * @param eStop true to activate + */ + @SuppressWarnings("ParameterName") public static void setEStop(boolean eStop) { DriverStationDataJNI.setEStop(eStop); } + /** + * Register a callback on whether the FMS is connected. + * + * @param callback the callback that will be called whenever the FMS connection changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerFmsAttachedCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerFmsAttachedCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelFmsAttachedCallback); } + /** + * Check if the FMS is connected. + * + * @return true if FMS is connected + */ public static boolean getFmsAttached() { return DriverStationDataJNI.getFmsAttached(); } + /** + * Change whether the FMS is connected. + * + * @param fmsAttached the new value + */ public static void setFmsAttached(boolean fmsAttached) { DriverStationDataJNI.setFmsAttached(fmsAttached); } + /** + * Register a callback on whether the DS is connected. + * + * @param callback the callback that will be called whenever the DS connection changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerDsAttachedCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerDsAttachedCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelDsAttachedCallback); } + /** + * Check if the DS is attached. + * + * @return true if attached + */ public static boolean getDsAttached() { return DriverStationDataJNI.getDsAttached(); } + /** + * Change whether the DS is attached. + * + * @param dsAttached the new value + */ public static void setDsAttached(boolean dsAttached) { DriverStationDataJNI.setDsAttached(dsAttached); } + /** + * Register a callback on the alliance station ID. + * + * @param callback the callback that will be called whenever the alliance station changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerAllianceStationIdCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerAllianceStationIdCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelAllianceStationIdCallback); } + /** + * Get the alliance station ID (color + number). + * + * @return the alliance station color and number + */ public static AllianceStationID getAllianceStationId() { switch (DriverStationDataJNI.getAllianceStationId()) { case 0: @@ -120,6 +242,11 @@ public class DriverStationSim { } } + /** + * Change the alliance station. + * + * @param allianceStationId the new alliance station + */ public static void setAllianceStationId(AllianceStationID allianceStationId) { int allianceStation; switch (allianceStationId) { @@ -147,16 +274,34 @@ public class DriverStationSim { DriverStationDataJNI.setAllianceStationId(allianceStation); } + /** + * Register a callback on match time. + * + * @param callback the callback that will be called whenever match time changes + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerMatchTimeCallback( NotifyCallback callback, boolean initialNotify) { int uid = DriverStationDataJNI.registerMatchTimeCallback(callback, initialNotify); return new CallbackStore(uid, DriverStationDataJNI::cancelMatchTimeCallback); } + /** + * Get the current value of the match timer. + * + * @return the current match time + */ public static double getMatchTime() { return DriverStationDataJNI.getMatchTime(); } + /** + * Sets the match timer. + * + * @param matchTime the new match time + */ public static void setMatchTime(double matchTime) { DriverStationDataJNI.setMatchTime(matchTime); } @@ -382,6 +527,7 @@ public class DriverStationSim { DriverStationDataJNI.setReplayNumber(replayNumber); } + /** Reset all simulation data for the Driver Station. */ public static void resetData() { DriverStationDataJNI.resetData(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java index dde556200a..e8939543bd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/DutyCycleSim.java @@ -52,42 +52,101 @@ public class DutyCycleSim { return new DutyCycleSim(index); } + /** + * Register a callback to be run when this duty cycle input is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = DutyCycleDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelInitializedCallback); } + /** + * Check whether this duty cycle input has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return DutyCycleDataJNI.getInitialized(m_index); } + /** + * Define whether this duty cycle input has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { DutyCycleDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run whenever the frequency changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerFrequencyCallback(NotifyCallback callback, boolean initialNotify) { int uid = DutyCycleDataJNI.registerFrequencyCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelFrequencyCallback); } + /** + * Measure the frequency. + * + * @return the duty cycle frequency + */ public int getFrequency() { return DutyCycleDataJNI.getFrequency(m_index); } + /** + * Change the duty cycle frequency. + * + * @param frequency the new frequency + */ public void setFrequency(int frequency) { DutyCycleDataJNI.setFrequency(m_index, frequency); } + /** + * Register a callback to be run whenever the output changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerOutputCallback(NotifyCallback callback, boolean initialNotify) { int uid = DutyCycleDataJNI.registerOutputCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelOutputCallback); } + /** + * Measure the output from this duty cycle port. + * + * @return the output value + */ public double getOutput() { return DutyCycleDataJNI.getOutput(m_index); } + /** + * Change the duty cycle output. + * + * @param output the new output value + */ public void setOutput(double output) { DutyCycleDataJNI.setOutput(m_index, output); } + + /** Reset all simulation data for the duty cycle output. */ + public void resetData() { + DutyCycleDataJNI.resetData(m_index); + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java index 7262cc8793..12f2506362 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/ElevatorSim.java @@ -133,6 +133,7 @@ public class ElevatorSim extends LinearSystemSim { * @param x The current elevator state. * @return Whether the elevator has hit the lower limit. */ + @SuppressWarnings("ParameterName") public boolean hasHitLowerLimit(Matrix x) { return x.get(0, 0) < this.m_minHeight; } @@ -143,6 +144,7 @@ public class ElevatorSim extends LinearSystemSim { * @param x The current elevator state. * @return Whether the elevator has hit the upper limit. */ + @SuppressWarnings("ParameterName") public boolean hasHitUpperLimit(Matrix x) { return x.get(0, 0) > this.m_maxHeight; } @@ -198,6 +200,7 @@ public class ElevatorSim extends LinearSystemSim { * @param u The system inputs (voltage). * @param dtSeconds The time difference between controller updates. */ + @SuppressWarnings({"ParameterName", "LambdaParameterName"}) @Override protected Matrix updateX(Matrix currentXhat, Matrix u, double dtSeconds) { // Calculate updated x-hat from Runge-Kutta. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/EncoderSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/EncoderSim.java index b466b40569..924ba991e1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/EncoderSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/EncoderSim.java @@ -53,128 +53,293 @@ public class EncoderSim { return new EncoderSim(index); } + /** + * Register a callback on the Initialized property of the encoder. + * + * @param callback the callback that will be called whenever the Initialized property is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelInitializedCallback); } + /** + * Read the Initialized value of the encoder. + * + * @return true if initialized + */ public boolean getInitialized() { return EncoderDataJNI.getInitialized(m_index); } + /** + * Change the Initialized value of the encoder. + * + * @param initialized the new value + */ public void setInitialized(boolean initialized) { EncoderDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback on the count property of the encoder. + * + * @param callback the callback that will be called whenever the count property is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerCountCallback(NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerCountCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelCountCallback); } + /** + * Read the count of the encoder. + * + * @return the count + */ public int getCount() { return EncoderDataJNI.getCount(m_index); } + /** + * Change the count of the encoder. + * + * @param count the new count + */ public void setCount(int count) { EncoderDataJNI.setCount(m_index, count); } + /** + * Register a callback on the period of the encoder. + * + * @param callback the callback that will be called whenever the period is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerPeriodCallback(NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerPeriodCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelPeriodCallback); } + /** + * Read the period of the encoder. + * + * @return the encoder period + */ public double getPeriod() { return EncoderDataJNI.getPeriod(m_index); } + /** + * Change the encoder period. + * + * @param period the new period + */ public void setPeriod(double period) { EncoderDataJNI.setPeriod(m_index, period); } + /** + * Register a callback to be called whenever the encoder is reset. + * + * @param callback the callback + * @param initialNotify whether to run the callback on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerResetCallback(NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerResetCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelResetCallback); } + /** + * Check if the encoder has been reset. + * + * @return true if reset + */ public boolean getReset() { return EncoderDataJNI.getReset(m_index); } + /** + * Change the reset property of the encoder. + * + * @param reset the new value + */ public void setReset(boolean reset) { EncoderDataJNI.setReset(m_index, reset); } + /** + * Register a callback to be run whenever the max period of the encoder is changed. + * + * @param callback the callback + * @param initialNotify whether to run the callback on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerMaxPeriodCallback(NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerMaxPeriodCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelMaxPeriodCallback); } + /** + * Get the max period of the encoder. + * + * @return the max period of the encoder + */ public double getMaxPeriod() { return EncoderDataJNI.getMaxPeriod(m_index); } + /** + * Change the max period of the encoder. + * + * @param maxPeriod the new value + */ public void setMaxPeriod(double maxPeriod) { EncoderDataJNI.setMaxPeriod(m_index, maxPeriod); } + /** + * Register a callback on the direction of the encoder. + * + * @param callback the callback that will be called whenever the direction is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerDirectionCallback(NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerDirectionCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelDirectionCallback); } + /** + * Get the direction of the encoder. + * + * @return the direction of the encoder + */ public boolean getDirection() { return EncoderDataJNI.getDirection(m_index); } + /** + * Set the direction of the encoder. + * + * @param direction the new direction + */ public void setDirection(boolean direction) { EncoderDataJNI.setDirection(m_index, direction); } + /** + * Register a callback on the reverse direction. + * + * @param callback the callback that will be called whenever the reverse direction is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerReverseDirectionCallback( NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerReverseDirectionCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelReverseDirectionCallback); } + /** + * Get the reverse direction of the encoder. + * + * @return the reverse direction of the encoder + */ public boolean getReverseDirection() { return EncoderDataJNI.getReverseDirection(m_index); } + /** + * Set the reverse direction. + * + * @param reverseDirection the new value + */ public void setReverseDirection(boolean reverseDirection) { EncoderDataJNI.setReverseDirection(m_index, reverseDirection); } + /** + * Register a callback on the samples-to-average value of this encoder. + * + * @param callback the callback that will be called whenever the samples-to-average is changed + * @param initialNotify if true, the callback will be run on the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerSamplesToAverageCallback( NotifyCallback callback, boolean initialNotify) { int uid = EncoderDataJNI.registerSamplesToAverageCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, EncoderDataJNI::cancelSamplesToAverageCallback); } + /** + * Get the samples-to-average value. + * + * @return the samples-to-average value + */ public int getSamplesToAverage() { return EncoderDataJNI.getSamplesToAverage(m_index); } + /** + * Set the samples-to-average value. + * + * @param samplesToAverage the new value + */ public void setSamplesToAverage(int samplesToAverage) { EncoderDataJNI.setSamplesToAverage(m_index, samplesToAverage); } + /** + * Change the encoder distance. + * + * @param distance the new distance + */ public void setDistance(double distance) { EncoderDataJNI.setDistance(m_index, distance); } + /** + * Read the distance of the encoder. + * + * @return the encoder distance + */ public double getDistance() { return EncoderDataJNI.getDistance(m_index); } + /** + * Change the rate of the encoder. + * + * @param rate the new rate + */ public void setRate(double rate) { EncoderDataJNI.setRate(m_index, rate); } + /** + * Get the rate of the encoder. + * + * @return the rate of change + */ public double getRate() { return EncoderDataJNI.getRate(m_index); } + /** Resets all simulation data for this encoder. */ public void resetData() { EncoderDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java index 435054dc13..8dd7bc43dd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/FlywheelSim.java @@ -58,6 +58,7 @@ public class FlywheelSim extends LinearSystemSim { * @param jKgMetersSquared The moment of inertia of the flywheel. If this is unknown, use the * {@link #FlywheelSim(LinearSystem, DCMotor, double, Matrix)} constructor. */ + @SuppressWarnings("ParameterName") public FlywheelSim(DCMotor gearbox, double gearing, double jKgMetersSquared) { super(LinearSystemId.createFlywheelSystem(gearbox, jKgMetersSquared, gearing)); m_gearbox = gearbox; @@ -73,6 +74,7 @@ public class FlywheelSim extends LinearSystemSim { * {@link #FlywheelSim(LinearSystem, DCMotor, double, Matrix)} constructor. * @param measurementStdDevs The standard deviations of the measurements. */ + @SuppressWarnings("ParameterName") public FlywheelSim( DCMotor gearbox, double gearing, double jKgMetersSquared, Matrix measurementStdDevs) { super( diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GenericHIDSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GenericHIDSim.java index aadfb37180..c5878ca1e4 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GenericHIDSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GenericHIDSim.java @@ -33,55 +33,126 @@ public class GenericHIDSim { DriverStationSim.notifyNewData(); } + /** + * Set the value of a given button. + * + * @param button the button to set + * @param value the new value + */ public void setRawButton(int button, boolean value) { DriverStationSim.setJoystickButton(m_port, button, value); } + /** + * Set the value of a given axis. + * + * @param axis the axis to set + * @param value the new value + */ public void setRawAxis(int axis, double value) { DriverStationSim.setJoystickAxis(m_port, axis, value); } + /** + * Set the value of a given POV. + * + * @param pov the POV to set + * @param value the new value + */ public void setPOV(int pov, int value) { DriverStationSim.setJoystickPOV(m_port, pov, value); } + /** + * Set the value of the default POV (port 0). + * + * @param value the new value + */ public void setPOV(int value) { setPOV(0, value); } + /** + * Set the axis count of this device. + * + * @param count the new axis count + */ public void setAxisCount(int count) { DriverStationSim.setJoystickAxisCount(m_port, count); } + /** + * Set the POV count of this device. + * + * @param count the new POV count + */ public void setPOVCount(int count) { DriverStationSim.setJoystickPOVCount(m_port, count); } + /** + * Set the button count of this device. + * + * @param count the new button count + */ public void setButtonCount(int count) { DriverStationSim.setJoystickButtonCount(m_port, count); } + /** + * Set the type of this device. + * + * @param type the new device type + */ public void setType(GenericHID.HIDType type) { DriverStationSim.setJoystickType(m_port, type.value); } + /** + * Set the name of this device. + * + * @param name the new device name + */ public void setName(String name) { DriverStationSim.setJoystickName(m_port, name); } + /** + * Set the type of an axis. + * + * @param axis the axis + * @param type the type + */ public void setAxisType(int axis, int type) { DriverStationSim.setJoystickAxisType(m_port, axis, type); } + /** + * Read the output of a button. + * + * @param outputNumber the button number + * @return the value of the button (true = pressed) + */ public boolean getOutput(int outputNumber) { long outputs = getOutputs(); return (outputs & (1 << (outputNumber - 1))) != 0; } + /** + * Get the encoded 16-bit integer that passes button values. + * + * @return the button values + */ public long getOutputs() { return DriverStationSim.getJoystickOutputs(m_port); } + /** + * Get the joystick rumble. + * + * @param type the rumble to read + * @return the rumble value + */ public double getRumble(GenericHID.RumbleType type) { int value = DriverStationSim.getJoystickRumble( diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/I2CSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/I2CSim.java index 19b8e39be9..986e310a8a 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/I2CSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/I2CSim.java @@ -9,36 +9,75 @@ import edu.wpi.first.hal.simulation.ConstBufferCallback; import edu.wpi.first.hal.simulation.I2CDataJNI; import edu.wpi.first.hal.simulation.NotifyCallback; +/** A class to control a simulated I2C device. */ public class I2CSim { private final int m_index; + /** + * Construct a new I2C simulation object. + * + * @param index the HAL index of the I2C object + */ public I2CSim(int index) { m_index = index; } + /** + * Register a callback to be run when this I2C device is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = I2CDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, I2CDataJNI::cancelInitializedCallback); } + /** + * Check whether this I2C device has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return I2CDataJNI.getInitialized(m_index); } + /** + * Define whether this I2C device has been initialized. + * + * @param initialized whether this device is initialized + */ public void setInitialized(boolean initialized) { I2CDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run whenever a `read` operation is done. + * + * @param callback the callback that is run on `read` operations + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerReadCallback(BufferCallback callback) { int uid = I2CDataJNI.registerReadCallback(m_index, callback); return new CallbackStore(m_index, uid, I2CDataJNI::cancelReadCallback); } + /** + * Register a callback to be run whenever a `write` operation is done. + * + * @param callback the callback that is run on `write` operations + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerWriteCallback(ConstBufferCallback callback) { int uid = I2CDataJNI.registerWriteCallback(m_index, callback); return new CallbackStore(m_index, uid, I2CDataJNI::cancelWriteCallback); } + /** Reset all I2C simulation data. */ public void resetData() { I2CDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/JoystickSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/JoystickSim.java index 35126839ff..f55b038499 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/JoystickSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/JoystickSim.java @@ -37,33 +37,68 @@ public class JoystickSim extends GenericHIDSim { setPOVCount(1); } + /** + * Set the X value of the joystick. + * + * @param value the new X value + */ public void setX(double value) { setRawAxis(m_joystick != null ? m_joystick.getXChannel() : Joystick.kDefaultXChannel, value); } + /** + * Set the Y value of the joystick. + * + * @param value the new Y value + */ public void setY(double value) { setRawAxis(m_joystick != null ? m_joystick.getYChannel() : Joystick.kDefaultYChannel, value); } + /** + * Set the Z value of the joystick. + * + * @param value the new Z value + */ public void setZ(double value) { setRawAxis(m_joystick != null ? m_joystick.getZChannel() : Joystick.kDefaultZChannel, value); } + /** + * Set the twist value of the joystick. + * + * @param value the new twist value + */ public void setTwist(double value) { setRawAxis( m_joystick != null ? m_joystick.getTwistChannel() : Joystick.kDefaultTwistChannel, value); } + /** + * Set the throttle value of the joystick. + * + * @param value the new throttle value + */ public void setThrottle(double value) { setRawAxis( m_joystick != null ? m_joystick.getThrottleChannel() : Joystick.kDefaultThrottleChannel, value); } + /** + * Set the trigger value of the joystick. + * + * @param state the new value + */ public void setTrigger(boolean state) { setRawButton(1, state); } + /** + * Set the top state of the joystick. + * + * @param state the new state + */ public void setTop(boolean state) { setRawButton(2, state); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java index 3b2fe15004..aec9ce7273 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java @@ -115,6 +115,7 @@ public class LinearSystemSim u) { this.m_u = clampInput(u); } @@ -135,6 +136,7 @@ public class LinearSystemSim updateX( Matrix currentXhat, Matrix u, double dtSeconds) { return m_plant.calculateX(currentXhat, u, dtSeconds); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PCMSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PCMSim.java index 163f9e1cfd..04e29324b7 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PCMSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PCMSim.java @@ -36,6 +36,15 @@ public class PCMSim { m_index = compressor.getModule(); } + /** + * Register a callback to be run when a solenoid is initialized on a channel. + * + * @param channel the channel to monitor + * @param callback the callback + * @param initialNotify should the callback be run with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerSolenoidInitializedCallback( int channel, NotifyCallback callback, boolean initialNotify) { int uid = @@ -43,98 +52,222 @@ public class PCMSim { return new CallbackStore(m_index, channel, uid, PCMDataJNI::cancelSolenoidInitializedCallback); } + /** + * Check if a solenoid has been initialized on a specific channel. + * + * @param channel the channel to check + * @return true if initialized + */ public boolean getSolenoidInitialized(int channel) { return PCMDataJNI.getSolenoidInitialized(m_index, channel); } + /** + * Define whether a solenoid has been initialized on a specific channel. + * + * @param channel the channel + * @param solenoidInitialized is there a solenoid initialized on that channel + */ public void setSolenoidInitialized(int channel, boolean solenoidInitialized) { PCMDataJNI.setSolenoidInitialized(m_index, channel, solenoidInitialized); } + /** + * Register a callback to be run when the solenoid output on a channel changes. + * + * @param channel the channel to monitor + * @param callback the callback + * @param initialNotify should the callback be run with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerSolenoidOutputCallback( int channel, NotifyCallback callback, boolean initialNotify) { int uid = PCMDataJNI.registerSolenoidOutputCallback(m_index, channel, callback, initialNotify); return new CallbackStore(m_index, channel, uid, PCMDataJNI::cancelSolenoidOutputCallback); } + /** + * Check the solenoid output on a specific channel. + * + * @param channel the channel to check + * @return the solenoid output + */ public boolean getSolenoidOutput(int channel) { return PCMDataJNI.getSolenoidOutput(m_index, channel); } + /** + * Change the solenoid output on a specific channel. + * + * @param channel the channel to check + * @param solenoidOutput the new solenoid output + */ public void setSolenoidOutput(int channel, boolean solenoidOutput) { PCMDataJNI.setSolenoidOutput(m_index, channel, solenoidOutput); } + /** + * Register a callback to be run when the compressor is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerCompressorInitializedCallback( NotifyCallback callback, boolean initialNotify) { int uid = PCMDataJNI.registerCompressorInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PCMDataJNI::cancelCompressorInitializedCallback); } + /** + * Check whether the compressor has been initialized. + * + * @return true if initialized + */ public boolean getCompressorInitialized() { return PCMDataJNI.getCompressorInitialized(m_index); } + /** + * Define whether the compressor has been initialized. + * + * @param compressorInitialized whether the compressor is initialized + */ public void setCompressorInitialized(boolean compressorInitialized) { PCMDataJNI.setCompressorInitialized(m_index, compressorInitialized); } + /** + * Register a callback to be run when the compressor activates. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerCompressorOnCallback( NotifyCallback callback, boolean initialNotify) { int uid = PCMDataJNI.registerCompressorOnCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PCMDataJNI::cancelCompressorOnCallback); } + /** + * Check if the compressor is on. + * + * @return true if the compressor is active + */ public boolean getCompressorOn() { return PCMDataJNI.getCompressorOn(m_index); } + /** + * Set whether the compressor is active. + * + * @param compressorOn the new value + */ public void setCompressorOn(boolean compressorOn) { PCMDataJNI.setCompressorOn(m_index, compressorOn); } + /** + * Register a callback to be run whenever the closed loop state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerClosedLoopEnabledCallback( NotifyCallback callback, boolean initialNotify) { int uid = PCMDataJNI.registerClosedLoopEnabledCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PCMDataJNI::cancelClosedLoopEnabledCallback); } + /** + * Check whether the closed loop compressor control is active. + * + * @return true if active + */ public boolean getClosedLoopEnabled() { return PCMDataJNI.getClosedLoopEnabled(m_index); } + /** + * Turn on/off the closed loop control of the compressor. + * + * @param closedLoopEnabled whether the control loop is active + */ public void setClosedLoopEnabled(boolean closedLoopEnabled) { PCMDataJNI.setClosedLoopEnabled(m_index, closedLoopEnabled); } + /** + * Register a callback to be run whenever the pressure switch value changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerPressureSwitchCallback( NotifyCallback callback, boolean initialNotify) { int uid = PCMDataJNI.registerPressureSwitchCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PCMDataJNI::cancelPressureSwitchCallback); } + /** + * Check the value of the pressure switch. + * + * @return the pressure switch value + */ public boolean getPressureSwitch() { return PCMDataJNI.getPressureSwitch(m_index); } + /** + * Set the value of the pressure switch. + * + * @param pressureSwitch the new value + */ public void setPressureSwitch(boolean pressureSwitch) { PCMDataJNI.setPressureSwitch(m_index, pressureSwitch); } + /** + * Register a callback to be run whenever the compressor current changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerCompressorCurrentCallback( NotifyCallback callback, boolean initialNotify) { int uid = PCMDataJNI.registerCompressorCurrentCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PCMDataJNI::cancelCompressorCurrentCallback); } + /** + * Read the compressor current. + * + * @return the current of the compressor connected to this module + */ public double getCompressorCurrent() { return PCMDataJNI.getCompressorCurrent(m_index); } + /** + * Set the compressor current. + * + * @param compressorCurrent the new compressor current + */ public void setCompressorCurrent(double compressorCurrent) { PCMDataJNI.setCompressorCurrent(m_index, compressorCurrent); } + /** Reset all simulation data for this object. */ public void resetData() { PCMDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PDPSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PDPSim.java index 83a4d73df7..b432b849f5 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PDPSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PDPSim.java @@ -35,59 +35,135 @@ public class PDPSim { m_index = pdp.getModule(); } + /** + * Register a callback to be run when the PDP is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = PDPDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PDPDataJNI::cancelInitializedCallback); } + /** + * Check whether the PDP has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return PDPDataJNI.getInitialized(m_index); } + /** + * Define whether the PDP has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { PDPDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run whenever the PDP temperature changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerTemperatureCallback(NotifyCallback callback, boolean initialNotify) { int uid = PDPDataJNI.registerTemperatureCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PDPDataJNI::cancelTemperatureCallback); } + /** + * Check the temperature of the PDP. + * + * @return the PDP temperature + */ public double getTemperature() { return PDPDataJNI.getTemperature(m_index); } + /** + * Define the PDP temperature. + * + * @param temperature the new PDP temperature + */ public void setTemperature(double temperature) { PDPDataJNI.setTemperature(m_index, temperature); } + /** + * Register a callback to be run whenever the PDP voltage changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerVoltageCallback(NotifyCallback callback, boolean initialNotify) { int uid = PDPDataJNI.registerVoltageCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PDPDataJNI::cancelVoltageCallback); } + /** + * Check the PDP voltage. + * + * @return the PDP voltage. + */ public double getVoltage() { return PDPDataJNI.getVoltage(m_index); } + /** + * Set the PDP voltage. + * + * @param voltage the new PDP voltage + */ public void setVoltage(double voltage) { PDPDataJNI.setVoltage(m_index, voltage); } + /** + * Register a callback to be run whenever the current of a specific channel changes. + * + * @param channel the channel + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerCurrentCallback( int channel, NotifyCallback callback, boolean initialNotify) { int uid = PDPDataJNI.registerCurrentCallback(m_index, channel, callback, initialNotify); return new CallbackStore(m_index, channel, uid, PDPDataJNI::cancelCurrentCallback); } + /** + * Read the current in one of the PDP channels. + * + * @param channel the channel to check + * @return the current in the given channel + */ public double getCurrent(int channel) { return PDPDataJNI.getCurrent(m_index, channel); } + /** + * Change the current in the given channel. + * + * @param channel the channel to edit + * @param current the new current for the channel + */ public void setCurrent(int channel, double current) { PDPDataJNI.setCurrent(m_index, channel, current); } + /** Reset all PDP simulation data. */ public void resetData() { PDPDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PWMSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PWMSim.java index b3e61504e7..8a60e52608 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PWMSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PWMSim.java @@ -30,84 +30,193 @@ public class PWMSim { m_index = channel; } + /** + * Register a callback to be run when the PWM is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = PWMDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PWMDataJNI::cancelInitializedCallback); } + /** + * Check whether the PWM has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return PWMDataJNI.getInitialized(m_index); } + /** + * Define whether the PWM has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { PWMDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run when the PWM raw value changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerRawValueCallback(NotifyCallback callback, boolean initialNotify) { int uid = PWMDataJNI.registerRawValueCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PWMDataJNI::cancelRawValueCallback); } + /** + * Get the PWM raw value. + * + * @return the PWM raw value + */ public int getRawValue() { return PWMDataJNI.getRawValue(m_index); } + /** + * Set the PWM raw value. + * + * @param rawValue the PWM raw value + */ public void setRawValue(int rawValue) { PWMDataJNI.setRawValue(m_index, rawValue); } + /** + * Register a callback to be run when the PWM speed changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerSpeedCallback(NotifyCallback callback, boolean initialNotify) { int uid = PWMDataJNI.registerSpeedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PWMDataJNI::cancelSpeedCallback); } + /** + * Get the PWM speed. + * + * @return the PWM speed (-1.0 to 1.0) + */ public double getSpeed() { return PWMDataJNI.getSpeed(m_index); } + /** + * Set the PWM speed. + * + * @param speed the PWM speed (-1.0 to 1.0) + */ public void setSpeed(double speed) { PWMDataJNI.setSpeed(m_index, speed); } + /** + * Register a callback to be run when the PWM position changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerPositionCallback(NotifyCallback callback, boolean initialNotify) { int uid = PWMDataJNI.registerPositionCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PWMDataJNI::cancelPositionCallback); } + /** + * Get the PWM position. + * + * @return the PWM position (0.0 to 1.0) + */ public double getPosition() { return PWMDataJNI.getPosition(m_index); } + /** + * Set the PWM position. + * + * @param position the PWM position (0.0 to 1.0) + */ public void setPosition(double position) { PWMDataJNI.setPosition(m_index, position); } + /** + * Register a callback to be run when the PWM period scale changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerPeriodScaleCallback(NotifyCallback callback, boolean initialNotify) { int uid = PWMDataJNI.registerPeriodScaleCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PWMDataJNI::cancelPeriodScaleCallback); } + /** + * Get the PWM period scale. + * + * @return the PWM period scale + */ public int getPeriodScale() { return PWMDataJNI.getPeriodScale(m_index); } + /** + * Set the PWM period scale. + * + * @param periodScale the PWM period scale + */ public void setPeriodScale(int periodScale) { PWMDataJNI.setPeriodScale(m_index, periodScale); } + /** + * Register a callback to be run when the PWM zero latch state changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerZeroLatchCallback(NotifyCallback callback, boolean initialNotify) { int uid = PWMDataJNI.registerZeroLatchCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, PWMDataJNI::cancelZeroLatchCallback); } + /** + * Check whether the PWM is zero latched. + * + * @return true if zero latched + */ public boolean getZeroLatch() { return PWMDataJNI.getZeroLatch(m_index); } + /** + * Define whether the PWM has been zero latched. + * + * @param zeroLatch true to indicate zero latched + */ public void setZeroLatch(boolean zeroLatch) { PWMDataJNI.setZeroLatch(m_index, zeroLatch); } + /** Reset all simulation data. */ public void resetData() { PWMDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RelaySim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RelaySim.java index 567043c754..b6f25420f3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RelaySim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RelaySim.java @@ -30,60 +30,133 @@ public class RelaySim { m_index = channel; } + /** + * Register a callback to be run when the forward direction is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedForwardCallback( NotifyCallback callback, boolean initialNotify) { int uid = RelayDataJNI.registerInitializedForwardCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, RelayDataJNI::cancelInitializedForwardCallback); } + /** + * Check whether the forward direction has been initialized. + * + * @return true if initialized + */ public boolean getInitializedForward() { return RelayDataJNI.getInitializedForward(m_index); } + /** + * Define whether the forward direction has been initialized. + * + * @param initializedForward whether this object is initialized + */ public void setInitializedForward(boolean initializedForward) { RelayDataJNI.setInitializedForward(m_index, initializedForward); } + /** + * Register a callback to be run when the reverse direction is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedReverseCallback( NotifyCallback callback, boolean initialNotify) { int uid = RelayDataJNI.registerInitializedReverseCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, RelayDataJNI::cancelInitializedReverseCallback); } + /** + * Check whether the reverse direction has been initialized. + * + * @return true if initialized + */ public boolean getInitializedReverse() { return RelayDataJNI.getInitializedReverse(m_index); } + /** + * Define whether the reverse direction has been initialized. + * + * @param initializedReverse whether this object is initialized + */ public void setInitializedReverse(boolean initializedReverse) { RelayDataJNI.setInitializedReverse(m_index, initializedReverse); } + /** + * Register a callback to be run when the forward direction changes state. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerForwardCallback(NotifyCallback callback, boolean initialNotify) { int uid = RelayDataJNI.registerForwardCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, RelayDataJNI::cancelForwardCallback); } + /** + * Check whether the forward direction is active. + * + * @return true if active + */ public boolean getForward() { return RelayDataJNI.getForward(m_index); } + /** + * Set whether the forward direction is active. + * + * @param forward true to make active + */ public void setForward(boolean forward) { RelayDataJNI.setForward(m_index, forward); } + /** + * Register a callback to be run when the reverse direction changes state. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerReverseCallback(NotifyCallback callback, boolean initialNotify) { int uid = RelayDataJNI.registerReverseCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, RelayDataJNI::cancelReverseCallback); } + /** + * Check whether the reverse direction is active. + * + * @return true if active + */ public boolean getReverse() { return RelayDataJNI.getReverse(m_index); } + /** + * Set whether the reverse direction is active. + * + * @param reverse true to make active + */ public void setReverse(boolean reverse) { RelayDataJNI.setReverse(m_index, reverse); } + /** Reset all simulation data. */ public void resetData() { RelayDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RoboRioSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RoboRioSim.java index e358ddbe04..607ab445b3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RoboRioSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/RoboRioSim.java @@ -10,216 +10,492 @@ import edu.wpi.first.hal.simulation.RoboRioDataJNI; /** Class to control a simulated RoboRIO. */ @SuppressWarnings({"PMD.ExcessivePublicCount", "PMD.UseUtilityClass"}) public class RoboRioSim { + /** + * Register a callback to be run when the FPGA button state changes. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ + @SuppressWarnings("AbbreviationAsWordInName") public static CallbackStore registerFPGAButtonCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerFPGAButtonCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelFPGAButtonCallback); } + /** + * Query the state of the FPGA button. + * + * @return the FPGA button state + */ + @SuppressWarnings("AbbreviationAsWordInName") public static boolean getFPGAButton() { return RoboRioDataJNI.getFPGAButton(); } - public static void setFPGAButton(boolean fPGAButton) { - RoboRioDataJNI.setFPGAButton(fPGAButton); + /** + * Define the state of the FPGA button. + * + * @param fpgaButton the new state + */ + @SuppressWarnings("AbbreviationAsWordInName") + public static void setFPGAButton(boolean fpgaButton) { + RoboRioDataJNI.setFPGAButton(fpgaButton); } + /** + * Register a callback to be run whenever the Vin voltage changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerVInVoltageCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerVInVoltageCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelVInVoltageCallback); } + /** + * Measure the Vin voltage. + * + * @return the Vin voltage + */ public static double getVInVoltage() { return RoboRioDataJNI.getVInVoltage(); } + /** + * Define the Vin voltage. + * + * @param vInVoltage the new voltage + */ + @SuppressWarnings("ParameterName") public static void setVInVoltage(double vInVoltage) { RoboRioDataJNI.setVInVoltage(vInVoltage); } + /** + * Register a callback to be run whenever the Vin current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerVInCurrentCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerVInCurrentCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelVInCurrentCallback); } + /** + * Measure the Vin current. + * + * @return the Vin current + */ public static double getVInCurrent() { return RoboRioDataJNI.getVInCurrent(); } + /** + * Define the Vin current. + * + * @param vInCurrent the new current + */ + @SuppressWarnings("ParameterName") public static void setVInCurrent(double vInCurrent) { RoboRioDataJNI.setVInCurrent(vInCurrent); } + /** + * Register a callback to be run whenever the 6V rail voltage changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserVoltage6VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserVoltage6VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage6VCallback); } + /** + * Measure the 6V rail voltage. + * + * @return the 6V rail voltage + */ public static double getUserVoltage6V() { return RoboRioDataJNI.getUserVoltage6V(); } + /** + * Define the 6V rail voltage. + * + * @param userVoltage6V the new voltage + */ public static void setUserVoltage6V(double userVoltage6V) { RoboRioDataJNI.setUserVoltage6V(userVoltage6V); } + /** + * Register a callback to be run whenever the 6V rail current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserCurrent6VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserCurrent6VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent6VCallback); } + /** + * Measure the 6V rail current. + * + * @return the 6V rail current + */ public static double getUserCurrent6V() { return RoboRioDataJNI.getUserCurrent6V(); } + /** + * Define the 6V rail current. + * + * @param userCurrent6V the new current + */ public static void setUserCurrent6V(double userCurrent6V) { RoboRioDataJNI.setUserCurrent6V(userCurrent6V); } + /** + * Register a callback to be run whenever the 6V rail active state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserActive6VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserActive6VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive6VCallback); } + /** + * Get the 6V rail active state. + * + * @return true if the 6V rail is active + */ public static boolean getUserActive6V() { return RoboRioDataJNI.getUserActive6V(); } + /** + * Set the 6V rail active state. + * + * @param userActive6V true to make rail active + */ public static void setUserActive6V(boolean userActive6V) { RoboRioDataJNI.setUserActive6V(userActive6V); } + /** + * Register a callback to be run whenever the 5V rail voltage changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserVoltage5VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserVoltage5VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage5VCallback); } + /** + * Measure the 5V rail voltage. + * + * @return the 5V rail voltage + */ public static double getUserVoltage5V() { return RoboRioDataJNI.getUserVoltage5V(); } + /** + * Define the 5V rail voltage. + * + * @param userVoltage5V the new voltage + */ public static void setUserVoltage5V(double userVoltage5V) { RoboRioDataJNI.setUserVoltage5V(userVoltage5V); } + /** + * Register a callback to be run whenever the 5V rail current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserCurrent5VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserCurrent5VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent5VCallback); } + /** + * Measure the 5V rail current. + * + * @return the 5V rail current + */ public static double getUserCurrent5V() { return RoboRioDataJNI.getUserCurrent5V(); } + /** + * Define the 5V rail current. + * + * @param userCurrent5V the new current + */ public static void setUserCurrent5V(double userCurrent5V) { RoboRioDataJNI.setUserCurrent5V(userCurrent5V); } + /** + * Register a callback to be run whenever the 5V rail active state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserActive5VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserActive5VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive5VCallback); } + /** + * Get the 5V rail active state. + * + * @return true if the 5V rail is active + */ public static boolean getUserActive5V() { return RoboRioDataJNI.getUserActive5V(); } + /** + * Set the 5V rail active state. + * + * @param userActive5V true to make rail active + */ public static void setUserActive5V(boolean userActive5V) { RoboRioDataJNI.setUserActive5V(userActive5V); } + /** + * Register a callback to be run whenever the 3.3V rail voltage changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserVoltage3V3Callback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserVoltage3V3Callback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage3V3Callback); } + /** + * Measure the 3.3V rail voltage. + * + * @return the 3.3V rail voltage + */ public static double getUserVoltage3V3() { return RoboRioDataJNI.getUserVoltage3V3(); } + /** + * Define the 3.3V rail voltage. + * + * @param userVoltage3V3 the new voltage + */ public static void setUserVoltage3V3(double userVoltage3V3) { RoboRioDataJNI.setUserVoltage3V3(userVoltage3V3); } + /** + * Register a callback to be run whenever the 3.3V rail current changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserCurrent3V3Callback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserCurrent3V3Callback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent3V3Callback); } + /** + * Measure the 3.3V rail current. + * + * @return the 3.3V rail current + */ public static double getUserCurrent3V3() { return RoboRioDataJNI.getUserCurrent3V3(); } + /** + * Define the 3.3V rail current. + * + * @param userCurrent3V3 the new current + */ public static void setUserCurrent3V3(double userCurrent3V3) { RoboRioDataJNI.setUserCurrent3V3(userCurrent3V3); } + /** + * Register a callback to be run whenever the 3.3V rail active state changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserActive3V3Callback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserActive3V3Callback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive3V3Callback); } + /** + * Get the 3.3V rail active state. + * + * @return true if the 3.3V rail is active + */ public static boolean getUserActive3V3() { return RoboRioDataJNI.getUserActive3V3(); } + /** + * Set the 3.3V rail active state. + * + * @param userActive3V3 true to make rail active + */ public static void setUserActive3V3(boolean userActive3V3) { RoboRioDataJNI.setUserActive3V3(userActive3V3); } + /** + * Register a callback to be run whenever the 6V rail number of faults changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserFaults6VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserFaults6VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults6VCallback); } + /** + * Get the 6V rail number of faults. + * + * @return number of faults + */ public static int getUserFaults6V() { return RoboRioDataJNI.getUserFaults6V(); } + /** + * Set the 6V rail number of faults. + * + * @param userFaults6V number of faults + */ public static void setUserFaults6V(int userFaults6V) { RoboRioDataJNI.setUserFaults6V(userFaults6V); } + /** + * Register a callback to be run whenever the 5V rail number of faults changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserFaults5VCallback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserFaults5VCallback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults5VCallback); } + /** + * Get the 5V rail number of faults. + * + * @return number of faults + */ public static int getUserFaults5V() { return RoboRioDataJNI.getUserFaults5V(); } + /** + * Set the 5V rail number of faults. + * + * @param userFaults5V number of faults + */ public static void setUserFaults5V(int userFaults5V) { RoboRioDataJNI.setUserFaults5V(userFaults5V); } + /** + * Register a callback to be run whenever the 3.3V rail number of faults changes. + * + * @param callback the callback + * @param initialNotify whether the callback should be called with the initial value + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerUserFaults3V3Callback( NotifyCallback callback, boolean initialNotify) { int uid = RoboRioDataJNI.registerUserFaults3V3Callback(callback, initialNotify); return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults3V3Callback); } + /** + * Get the 3.3V rail number of faults. + * + * @return number of faults + */ public static int getUserFaults3V3() { return RoboRioDataJNI.getUserFaults3V3(); } + /** + * Set the 3.3V rail number of faults. + * + * @param userFaults3V3 number of faults + */ public static void setUserFaults3V3(int userFaults3V3) { RoboRioDataJNI.setUserFaults3V3(userFaults3V3); } + /** Reset all simulation data. */ public static void resetData() { RoboRioDataJNI.resetData(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPIAccelerometerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPIAccelerometerSim.java index ea70e8fa3c..da1213a3b2 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPIAccelerometerSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPIAccelerometerSim.java @@ -7,78 +7,178 @@ package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.hal.simulation.NotifyCallback; import edu.wpi.first.hal.simulation.SPIAccelerometerDataJNI; +/** A class to control a simulated accelerometer over SPI. */ public class SPIAccelerometerSim { private final int m_index; + /** + * Construct a new simulation object. + * + * @param index the HAL index of the accelerometer + */ public SPIAccelerometerSim(int index) { m_index = index; } + /** + * Register a callback to be run when this accelerometer activates. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerActiveCallback(NotifyCallback callback, boolean initialNotify) { int uid = SPIAccelerometerDataJNI.registerActiveCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, SPIAccelerometerDataJNI::cancelActiveCallback); } + /** + * Check whether the accelerometer is active. + * + * @return true if active + */ public boolean getActive() { return SPIAccelerometerDataJNI.getActive(m_index); } + /** + * Define whether this accelerometer is active. + * + * @param active the new state + */ public void setActive(boolean active) { SPIAccelerometerDataJNI.setActive(m_index, active); } + /** + * Register a callback to be run whenever the range changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerRangeCallback(NotifyCallback callback, boolean initialNotify) { int uid = SPIAccelerometerDataJNI.registerRangeCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, SPIAccelerometerDataJNI::cancelRangeCallback); } + /** + * Check the range of this accelerometer. + * + * @return the accelerometer range + */ public int getRange() { return SPIAccelerometerDataJNI.getRange(m_index); } + /** + * Change the range of this accelerometer. + * + * @param range the new accelerometer range + */ public void setRange(int range) { SPIAccelerometerDataJNI.setRange(m_index, range); } + /** + * Register a callback to be run whenever the X axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerXCallback(NotifyCallback callback, boolean initialNotify) { int uid = SPIAccelerometerDataJNI.registerXCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, SPIAccelerometerDataJNI::cancelXCallback); } + /** + * Measure the X axis value. + * + * @return the X axis measurement + */ public double getX() { return SPIAccelerometerDataJNI.getX(m_index); } + /** + * Change the X axis value of the accelerometer. + * + * @param x the new reading of the X axis + */ + @SuppressWarnings("ParameterName") public void setX(double x) { SPIAccelerometerDataJNI.setX(m_index, x); } + /** + * Register a callback to be run whenever the Y axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerYCallback(NotifyCallback callback, boolean initialNotify) { int uid = SPIAccelerometerDataJNI.registerYCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, SPIAccelerometerDataJNI::cancelYCallback); } + /** + * Measure the Y axis value. + * + * @return the Y axis measurement + */ public double getY() { return SPIAccelerometerDataJNI.getY(m_index); } + /** + * Change the Y axis value of the accelerometer. + * + * @param y the new reading of the Y axis + */ + @SuppressWarnings("ParameterName") public void setY(double y) { SPIAccelerometerDataJNI.setY(m_index, y); } + /** + * Register a callback to be run whenever the Z axis value changes. + * + * @param callback the callback + * @param initialNotify whether to call the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerZCallback(NotifyCallback callback, boolean initialNotify) { int uid = SPIAccelerometerDataJNI.registerZCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, SPIAccelerometerDataJNI::cancelZCallback); } + /** + * Measure the Z axis value. + * + * @return the Z axis measurement + */ public double getZ() { return SPIAccelerometerDataJNI.getZ(m_index); } + /** + * Change the Z axis value of the accelerometer. + * + * @param z the new reading of the Z axis + */ + @SuppressWarnings("ParameterName") public void setZ(double z) { SPIAccelerometerDataJNI.setZ(m_index, z); } + /** Reset all simulation data of this object. */ public void resetData() { SPIAccelerometerDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPISim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPISim.java index 17ebc78b38..6c0b9e99b5 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPISim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SPISim.java @@ -10,31 +10,65 @@ import edu.wpi.first.hal.simulation.NotifyCallback; import edu.wpi.first.hal.simulation.SPIDataJNI; import edu.wpi.first.hal.simulation.SpiReadAutoReceiveBufferCallback; +/** A class for controlling a simulated SPI device. */ public class SPISim { private final int m_index; + /** Create a new simulated SPI device. */ public SPISim() { m_index = 0; } + /** + * Register a callback to be run when this device is initialized. + * + * @param callback the callback + * @param initialNotify whether to run the callback with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) { int uid = SPIDataJNI.registerInitializedCallback(m_index, callback, initialNotify); return new CallbackStore(m_index, uid, SPIDataJNI::cancelInitializedCallback); } + /** + * Check whether this device has been initialized. + * + * @return true if initialized + */ public boolean getInitialized() { return SPIDataJNI.getInitialized(m_index); } + /** + * Define whether this device has been initialized. + * + * @param initialized whether this object is initialized + */ public void setInitialized(boolean initialized) { SPIDataJNI.setInitialized(m_index, initialized); } + /** + * Register a callback to be run whenever a `read` operation is executed. + * + * @param callback the callback + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerReadCallback(BufferCallback callback) { int uid = SPIDataJNI.registerReadCallback(m_index, callback); return new CallbackStore(m_index, uid, SPIDataJNI::cancelReadCallback); } + /** + * Register a callback to be run whenever a `write` operation is executed. + * + * @param callback the callback + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerWriteCallback(ConstBufferCallback callback) { int uid = SPIDataJNI.registerWriteCallback(m_index, callback); return new CallbackStore(m_index, uid, SPIDataJNI::cancelWriteCallback); @@ -46,6 +80,7 @@ public class SPISim { return new CallbackStore(m_index, uid, SPIDataJNI::cancelReadAutoReceiveBufferCallback); } + /** Reset all simulation data. */ public void resetData() { SPIDataJNI.resetData(m_index); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java index 49b3909306..df445eb6fd 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java @@ -7,6 +7,8 @@ package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.hal.SimBoolean; import edu.wpi.first.hal.SimDouble; import edu.wpi.first.hal.SimEnum; +import edu.wpi.first.hal.SimInt; +import edu.wpi.first.hal.SimLong; import edu.wpi.first.hal.SimValue; import edu.wpi.first.hal.simulation.SimDeviceCallback; import edu.wpi.first.hal.simulation.SimDeviceDataJNI; @@ -25,6 +27,12 @@ public class SimDeviceSim { m_handle = SimDeviceDataJNI.getSimDeviceHandle(name); } + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ public SimValue getValue(String name) { int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name); if (handle <= 0) { @@ -33,6 +41,40 @@ public class SimDeviceSim { return new SimValue(handle); } + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ + public SimInt getInt(String name) { + int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name); + if (handle <= 0) { + return null; + } + return new SimInt(handle); + } + + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ + public SimLong getLong(String name) { + int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name); + if (handle <= 0) { + return null; + } + return new SimLong(handle); + } + + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ public SimDouble getDouble(String name) { int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name); if (handle <= 0) { @@ -41,6 +83,12 @@ public class SimDeviceSim { return new SimDouble(handle); } + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ public SimEnum getEnum(String name) { int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name); if (handle <= 0) { @@ -49,6 +97,12 @@ public class SimDeviceSim { return new SimEnum(handle); } + /** + * Get the property object with the given name. + * + * @param name the property name + * @return the property object + */ public SimBoolean getBoolean(String name) { int handle = SimDeviceDataJNI.getSimValueHandle(m_handle, name); if (handle <= 0) { @@ -57,24 +111,56 @@ public class SimDeviceSim { return new SimBoolean(handle); } + /** + * Get all options for the given enum. + * + * @param val the enum + * @return names of the different values for that enum + */ public static String[] getEnumOptions(SimEnum val) { return SimDeviceDataJNI.getSimValueEnumOptions(val.getNativeHandle()); } + /** + * Get all data of this object. + * + * @return all data and fields of this object + */ public SimDeviceDataJNI.SimValueInfo[] enumerateValues() { return SimDeviceDataJNI.enumerateSimValues(m_handle); } + /** + * Get the native handle of this object. + * + * @return the handle used to refer to this object through JNI + */ public int getNativeHandle() { return m_handle; } + /** + * Register a callback to be run every time a new value is added to this device. + * + * @param callback the callback + * @param initialNotify should the callback be run with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerValueCreatedCallback( SimValueCallback callback, boolean initialNotify) { int uid = SimDeviceDataJNI.registerSimValueCreatedCallback(m_handle, callback, initialNotify); return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueCreatedCallback); } + /** + * Register a callback to be run every time a value is changed on this device. + * + * @param callback the callback + * @param initialNotify should the callback be run with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public CallbackStore registerValueChangedCallback( SimValue value, SimValueCallback callback, boolean initialNotify) { int uid = @@ -83,22 +169,45 @@ public class SimDeviceSim { return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueChangedCallback); } + /** + * Get all sim devices with the given prefix. + * + * @param prefix the prefix to filter sim devices + * @return all sim devices + */ public static SimDeviceDataJNI.SimDeviceInfo[] enumerateDevices(String prefix) { return SimDeviceDataJNI.enumerateSimDevices(prefix); } + /** + * Register a callback to be run every time a new {@link edu.wpi.first.hal.SimDevice} is created. + * + * @param callback the callback + * @param initialNotify should the callback be run with the initial state + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerDeviceCreatedCallback( String prefix, SimDeviceCallback callback, boolean initialNotify) { int uid = SimDeviceDataJNI.registerSimDeviceCreatedCallback(prefix, callback, initialNotify); return new CallbackStore(uid, SimDeviceDataJNI::cancelSimDeviceCreatedCallback); } + /** + * Register a callback to be run every time a {@link edu.wpi.first.hal.SimDevice} is + * freed/destroyed. + * + * @param callback the callback + * @return the {@link CallbackStore} object associated with this callback. Save a reference to + * this object so GC doesn't cancel the callback. + */ public static CallbackStore registerDeviceFreedCallback( String prefix, SimDeviceCallback callback, boolean initialNotify) { int uid = SimDeviceDataJNI.registerSimDeviceFreedCallback(prefix, callback, initialNotify); return new CallbackStore(uid, SimDeviceDataJNI::cancelSimDeviceFreedCallback); } + /** Reset all SimDevice data. */ public static void resetData() { SimDeviceDataJNI.resetSimDeviceData(); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimHooks.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimHooks.java index 9441bc6885..1664081de9 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimHooks.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimHooks.java @@ -9,6 +9,11 @@ import edu.wpi.first.hal.simulation.SimulatorJNI; public final class SimHooks { private SimHooks() {} + /** + * Override the HAL runtime type (simulated/real). + * + * @param type runtime type + */ public static void setHALRuntimeType(int type) { SimulatorJNI.setRuntimeType(type); } @@ -25,26 +30,44 @@ public final class SimHooks { return SimulatorJNI.getProgramStarted(); } + /** Restart the simulator time. */ public static void restartTiming() { SimulatorJNI.restartTiming(); } + /** Pause the simulator time. */ public static void pauseTiming() { SimulatorJNI.pauseTiming(); } + /** Resume the simulator time. */ public static void resumeTiming() { SimulatorJNI.resumeTiming(); } + /** + * Check if the simulator time is paused. + * + * @return true if paused + */ public static boolean isTimingPaused() { return SimulatorJNI.isTimingPaused(); } + /** + * Advance the simulator time and wait for all notifiers to run. + * + * @param deltaSeconds the amount to advance (in seconds) + */ public static void stepTiming(double deltaSeconds) { SimulatorJNI.stepTiming((long) (deltaSeconds * 1e6)); } + /** + * Advance the simulator time and return immediately. + * + * @param deltaSeconds the amount to advance (in seconds) + */ public static void stepTimingAsync(double deltaSeconds) { SimulatorJNI.stepTimingAsync((long) (deltaSeconds * 1e6)); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java index b9c5508c48..2a09d7d84f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSim.java @@ -108,14 +108,14 @@ public class SingleJointedArmSim extends LinearSystemSim { * * @param gearbox The type of and number of motors in the arm gearbox. * @param gearing The gearing of the arm (numbers greater than 1 represent reductions). - * @param jKgMetersSquared The moment of inertia of the arm. This can be calculated from CAD - * software. + * @param jKgMetersSquared The moment of inertia of the arm, can be calculated from CAD software. * @param armLengthMeters The length of the arm. * @param minAngleRads The minimum angle that the arm is capable of. * @param maxAngleRads The maximum angle that the arm is capable of. * @param armMassKg The mass of the arm. * @param simulateGravity Whether gravity should be simulated or not. */ + @SuppressWarnings("ParameterName") public SingleJointedArmSim( DCMotor gearbox, double gearing, @@ -142,8 +142,7 @@ public class SingleJointedArmSim extends LinearSystemSim { * * @param gearbox The type of and number of motors in the arm gearbox. * @param gearing The gearing of the arm (numbers greater than 1 represent reductions). - * @param jKgMetersSquared The moment of inertia of the arm. This can be calculated from CAD - * software. + * @param jKgMetersSquared The moment of inertia of the arm; can be calculated from CAD software. * @param armLengthMeters The length of the arm. * @param minAngleRads The minimum angle that the arm is capable of. * @param maxAngleRads The maximum angle that the arm is capable of. @@ -151,6 +150,7 @@ public class SingleJointedArmSim extends LinearSystemSim { * @param simulateGravity Whether gravity should be simulated or not. * @param measurementStdDevs The standard deviations of the measurements. */ + @SuppressWarnings("ParameterName") public SingleJointedArmSim( DCMotor gearbox, double gearing, @@ -179,6 +179,7 @@ public class SingleJointedArmSim extends LinearSystemSim { * @param x The current arm state. * @return Whether the arm has hit the lower limit. */ + @SuppressWarnings("ParameterName") public boolean hasHitLowerLimit(Matrix x) { return x.get(0, 0) < this.m_minAngle; } @@ -189,6 +190,7 @@ public class SingleJointedArmSim extends LinearSystemSim { * @param x The current arm state. * @return Whether the arm has hit the upper limit. */ + @SuppressWarnings("ParameterName") public boolean hasHitUpperLimit(Matrix x) { return x.get(0, 0) > this.m_maxAngle; } @@ -252,6 +254,7 @@ public class SingleJointedArmSim extends LinearSystemSim { * @param dtSeconds The time difference between controller updates. */ @Override + @SuppressWarnings({"ParameterName", "LambdaParameterName"}) protected Matrix updateX(Matrix currentXhat, Matrix u, double dtSeconds) { // Horizontal case: // Torque = F * r = I * alpha diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java index 2bbb2fa6ea..588eb2effe 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java @@ -31,6 +31,12 @@ public class XboxControllerSim extends GenericHIDSim { setButtonCount(10); } + /** + * Change the X value of the joystick. + * + * @param hand the joystick hand + * @param value the new value + */ public void setX(GenericHID.Hand hand, double value) { if (hand.equals(GenericHID.Hand.kLeft)) { setRawAxis(XboxController.Axis.kLeftX.value, value); @@ -39,6 +45,12 @@ public class XboxControllerSim extends GenericHIDSim { } } + /** + * Change the Y value of the joystick. + * + * @param hand the joystick hand + * @param value the new value + */ public void setY(GenericHID.Hand hand, double value) { if (hand.equals(GenericHID.Hand.kLeft)) { setRawAxis(XboxController.Axis.kLeftY.value, value); @@ -47,6 +59,12 @@ public class XboxControllerSim extends GenericHIDSim { } } + /** + * Change the value of a trigger axis on the joystick. + * + * @param hand the joystick hand + * @param value the new value + */ public void setTriggerAxis(GenericHID.Hand hand, double value) { if (hand.equals(GenericHID.Hand.kLeft)) { setRawAxis(XboxController.Axis.kLeftTrigger.value, value); @@ -55,6 +73,12 @@ public class XboxControllerSim extends GenericHIDSim { } } + /** + * Change the value of a bumper on the joystick. + * + * @param hand the joystick hand + * @param state the new value + */ public void setBumper(GenericHID.Hand hand, boolean state) { if (hand.equals(GenericHID.Hand.kLeft)) { setRawButton(XboxController.Button.kBumperLeft.value, state); @@ -63,6 +87,12 @@ public class XboxControllerSim extends GenericHIDSim { } } + /** + * Change the value of a button on the joystick. + * + * @param hand the joystick hand + * @param state the new value + */ public void setStickButton(GenericHID.Hand hand, boolean state) { if (hand.equals(GenericHID.Hand.kLeft)) { setRawButton(XboxController.Button.kStickLeft.value, state); @@ -71,26 +101,56 @@ public class XboxControllerSim extends GenericHIDSim { } } + /** + * Change the value of the A button. + * + * @param state the new value + */ public void setAButton(boolean state) { setRawButton(XboxController.Button.kA.value, state); } + /** + * Change the value of the B button. + * + * @param state the new value + */ public void setBButton(boolean state) { setRawButton(XboxController.Button.kB.value, state); } + /** + * Change the value of the X button. + * + * @param state the new value + */ public void setXButton(boolean state) { setRawButton(XboxController.Button.kX.value, state); } + /** + * Change the value of the Y button. + * + * @param state the new value + */ public void setYButton(boolean state) { setRawButton(XboxController.Button.kY.value, state); } + /** + * Change the value of the Back button. + * + * @param state the new value + */ public void setBackButton(boolean state) { setRawButton(XboxController.Button.kBack.value, state); } + /** + * Change the value of the Start button. + * + * @param state the new value + */ public void setStartButton(boolean state) { setRawButton(XboxController.Button.kStart.value, state); } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java index 55338a02c3..7bb881f726 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/simpledifferentialdrivesimulation/Drivetrain.java @@ -75,6 +75,7 @@ public class Drivetrain { new DifferentialDrivetrainSim( m_drivetrainSystem, DCMotor.getCIM(2), 8, kTrackWidth, kWheelRadius, null); + /** Subsystem constructor. */ public Drivetrain() { // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder @@ -89,6 +90,7 @@ public class Drivetrain { SmartDashboard.putData("Field", m_fieldSim); } + /** Sets speeds to the drivetrain motors. */ public void setSpeeds(DifferentialDriveWheelSpeeds speeds) { var leftFeedforward = m_feedforward.calculate(speeds.leftMetersPerSecond); var rightFeedforward = m_feedforward.calculate(speeds.rightMetersPerSecond); @@ -101,15 +103,24 @@ public class Drivetrain { m_rightGroup.setVoltage(rightOutput + rightFeedforward); } + /** + * Controls the robot using arcade drive. + * + * @param xSpeed the speed for the x axis + * @param rot the rotation + */ + @SuppressWarnings("ParameterName") public void drive(double xSpeed, double rot) { setSpeeds(m_kinematics.toWheelSpeeds(new ChassisSpeeds(xSpeed, 0, rot))); } + /** Update robot odometry. */ public void updateOdometry() { m_odometry.update( m_gyro.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance()); } + /** Resets robot odometry. */ public void resetOdometry(Pose2d pose) { m_leftEncoder.reset(); m_rightEncoder.reset(); @@ -117,10 +128,12 @@ public class Drivetrain { m_odometry.resetPosition(pose, m_gyro.getRotation2d()); } + /** Check the current robot pose. */ public Pose2d getPose() { return m_odometry.getPoseMeters(); } + /** Update our simulation. This should be run every robot loop in simulation. */ public void simulationPeriodic() { // To update our simulation, we set motor voltage inputs, update the // simulation, and write the simulated positions and velocities to our @@ -138,6 +151,7 @@ public class Drivetrain { m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); } + /** Update odometry - this should be run every robot loop. */ public void periodic() { updateOdometry(); m_fieldSim.setRobotPose(m_odometry.getPoseMeters()); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java index 3bcc444e85..4db41a60fc 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/RobotContainer.java @@ -8,6 +8,7 @@ import static edu.wpi.first.wpilibj.XboxController.Button; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.XboxController.Button; import edu.wpi.first.wpilibj.controller.PIDController; import edu.wpi.first.wpilibj.controller.RamseteController; import edu.wpi.first.wpilibj.controller.SimpleMotorFeedforward; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java index e81a320136..506ffe1f4e 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/statespacedifferentialdrivesimulation/subsystems/DriveSubsystem.java @@ -11,7 +11,7 @@ import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.RobotController; import edu.wpi.first.wpilibj.SpeedControllerGroup; import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation.Constants; +import edu.wpi.first.wpilibj.examples.statespacedifferentialdrivesimulation.Constants.DriveConstants; import edu.wpi.first.wpilibj.geometry.Pose2d; import edu.wpi.first.wpilibj.geometry.Rotation2d; import edu.wpi.first.wpilibj.kinematics.DifferentialDriveOdometry; @@ -28,14 +28,14 @@ public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. private final SpeedControllerGroup m_leftMotors = new SpeedControllerGroup( - new PWMVictorSPX(Constants.DriveConstants.kLeftMotor1Port), - new PWMVictorSPX(Constants.DriveConstants.kLeftMotor2Port)); + new PWMVictorSPX(DriveConstants.kLeftMotor1Port), + new PWMVictorSPX(DriveConstants.kLeftMotor2Port)); // The motors on the right side of the drive. private final SpeedControllerGroup m_rightMotors = new SpeedControllerGroup( - new PWMVictorSPX(Constants.DriveConstants.kRightMotor1Port), - new PWMVictorSPX(Constants.DriveConstants.kRightMotor2Port)); + new PWMVictorSPX(DriveConstants.kRightMotor1Port), + new PWMVictorSPX(DriveConstants.kRightMotor2Port)); // The robot's drive private final DifferentialDrive m_drive = new DifferentialDrive(m_leftMotors, m_rightMotors); @@ -43,16 +43,16 @@ public class DriveSubsystem extends SubsystemBase { // The left-side drive encoder private final Encoder m_leftEncoder = new Encoder( - Constants.DriveConstants.kLeftEncoderPorts[0], - Constants.DriveConstants.kLeftEncoderPorts[1], - Constants.DriveConstants.kLeftEncoderReversed); + DriveConstants.kLeftEncoderPorts[0], + DriveConstants.kLeftEncoderPorts[1], + DriveConstants.kLeftEncoderReversed); // The right-side drive encoder private final Encoder m_rightEncoder = new Encoder( - Constants.DriveConstants.kRightEncoderPorts[0], - Constants.DriveConstants.kRightEncoderPorts[1], - Constants.DriveConstants.kRightEncoderReversed); + DriveConstants.kRightEncoderPorts[0], + DriveConstants.kRightEncoderPorts[1], + DriveConstants.kRightEncoderReversed); // The gyro sensor private final ADXRS450_Gyro m_gyro = new ADXRS450_Gyro(); @@ -71,8 +71,8 @@ public class DriveSubsystem extends SubsystemBase { /** Creates a new DriveSubsystem. */ public DriveSubsystem() { // Sets the distance per pulse for the encoders - m_leftEncoder.setDistancePerPulse(Constants.DriveConstants.kEncoderDistancePerPulse); - m_rightEncoder.setDistancePerPulse(Constants.DriveConstants.kEncoderDistancePerPulse); + m_leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); resetEncoders(); m_odometry = new DifferentialDriveOdometry(Rotation2d.fromDegrees(getHeading())); @@ -81,11 +81,11 @@ public class DriveSubsystem extends SubsystemBase { // This class simulates our drivetrain's motion around the field. m_drivetrainSimulator = new DifferentialDrivetrainSim( - Constants.DriveConstants.kDrivetrainPlant, - Constants.DriveConstants.kDriveGearbox, - Constants.DriveConstants.kDriveGearing, - Constants.DriveConstants.kTrackwidthMeters, - Constants.DriveConstants.kWheelDiameterMeters / 2.0, + DriveConstants.kDrivetrainPlant, + DriveConstants.kDriveGearbox, + DriveConstants.kDriveGearing, + DriveConstants.kTrackwidthMeters, + DriveConstants.kWheelDiameterMeters / 2.0, VecBuilder.fill(0, 0, 0.0001, 0.1, 0.1, 0.005, 0.005)); // The encoder and gyro angle sims let us set simulated sensor readings @@ -246,7 +246,6 @@ public class DriveSubsystem extends SubsystemBase { * @return the robot's heading in degrees, from -180 to 180 */ public double getHeading() { - return Math.IEEEremainder(m_gyro.getAngle(), 360) - * (Constants.DriveConstants.kGyroReversed ? -1.0 : 1.0); + return Math.IEEEremainder(m_gyro.getAngle(), 360) * (DriveConstants.kGyroReversed ? -1.0 : 1.0); } }