[wpilib] Document simulation APIs (#3079)

- Remove sim checkstyle suppression
- Add [[nodiscard]] to C++ register callback functions
- Add a couple of missing sim functions

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: Starlight220 <yotamshlomi@gmail.com>
This commit is contained in:
Peter Johnson
2021-01-11 21:55:45 -08:00
committed by GitHub
parent 26584ff145
commit 9c3b51ca0f
64 changed files with 4516 additions and 199 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 {
/** <b>Note: This interface is for simulation classes only. It should not be used by teams!</b> */
interface CancelCallbackFunc {
void cancel(int index, int uid);
}
/** <b>Note: This interface is for simulation classes only. It should not be used by teams!</b> */
interface CancelCallbackChannelFunc {
void cancel(int index, int channel, int uid);
}
/** <b>Note: This interface is for simulation classes only. It should not be used by teams!</b> */
interface CancelCallbackNoIndexFunc {
void cancel(int uid);
}
/**
* <b>Note: This constructor is for simulation classes only. It should not be called by teams!</b>
*/
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;
}
/**
* <b>Note: This constructor is for simulation classes only. It should not be called by teams!</b>
*/
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;
}
/**
* <b>Note: This constructor is for simulation classes only. It should not be called by teams!</b>
*/
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 {

View File

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

View File

@@ -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<N7, N1> getDynamics(Matrix<N7, N1> x, Matrix<N2, N1> 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,

View File

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

View File

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

View File

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

View File

@@ -133,6 +133,7 @@ public class ElevatorSim extends LinearSystemSim<N2, N1, N1> {
* @param x The current elevator state.
* @return Whether the elevator has hit the lower limit.
*/
@SuppressWarnings("ParameterName")
public boolean hasHitLowerLimit(Matrix<N2, N1> x) {
return x.get(0, 0) < this.m_minHeight;
}
@@ -143,6 +144,7 @@ public class ElevatorSim extends LinearSystemSim<N2, N1, N1> {
* @param x The current elevator state.
* @return Whether the elevator has hit the upper limit.
*/
@SuppressWarnings("ParameterName")
public boolean hasHitUpperLimit(Matrix<N2, N1> x) {
return x.get(0, 0) > this.m_maxHeight;
}
@@ -198,6 +200,7 @@ public class ElevatorSim extends LinearSystemSim<N2, N1, N1> {
* @param u The system inputs (voltage).
* @param dtSeconds The time difference between controller updates.
*/
@SuppressWarnings({"ParameterName", "LambdaParameterName"})
@Override
protected Matrix<N2, N1> updateX(Matrix<N2, N1> currentXhat, Matrix<N1, N1> u, double dtSeconds) {
// Calculate updated x-hat from Runge-Kutta.

View File

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

View File

@@ -58,6 +58,7 @@ public class FlywheelSim extends LinearSystemSim<N1, N1, N1> {
* @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<N1, N1, N1> {
* {@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<N1, N1> measurementStdDevs) {
super(

View File

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

View File

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

View File

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

View File

@@ -115,6 +115,7 @@ public class LinearSystemSim<States extends Num, Inputs extends Num, Outputs ext
*
* @param u The system inputs.
*/
@SuppressWarnings("ParameterName")
public void setInput(Matrix<Inputs, N1> u) {
this.m_u = clampInput(u);
}
@@ -135,6 +136,7 @@ public class LinearSystemSim<States extends Num, Inputs extends Num, Outputs ext
*
* @param u An array of doubles that represent the inputs of the system.
*/
@SuppressWarnings("ParameterName")
public void setInput(double... u) {
if (u.length != m_u.getNumRows()) {
throw new MatrixDimensionException(
@@ -170,6 +172,7 @@ public class LinearSystemSim<States extends Num, Inputs extends Num, Outputs ext
* @param dtSeconds The time difference between controller updates.
* @return The new state.
*/
@SuppressWarnings("ParameterName")
protected Matrix<States, N1> updateX(
Matrix<States, N1> currentXhat, Matrix<Inputs, N1> u, double dtSeconds) {
return m_plant.calculateX(currentXhat, u, dtSeconds);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -108,14 +108,14 @@ public class SingleJointedArmSim extends LinearSystemSim<N2, N1, N1> {
*
* @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<N2, N1, N1> {
*
* @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<N2, N1, N1> {
* @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<N2, N1, N1> {
* @param x The current arm state.
* @return Whether the arm has hit the lower limit.
*/
@SuppressWarnings("ParameterName")
public boolean hasHitLowerLimit(Matrix<N2, N1> x) {
return x.get(0, 0) < this.m_minAngle;
}
@@ -189,6 +190,7 @@ public class SingleJointedArmSim extends LinearSystemSim<N2, N1, N1> {
* @param x The current arm state.
* @return Whether the arm has hit the upper limit.
*/
@SuppressWarnings("ParameterName")
public boolean hasHitUpperLimit(Matrix<N2, N1> x) {
return x.get(0, 0) > this.m_maxAngle;
}
@@ -252,6 +254,7 @@ public class SingleJointedArmSim extends LinearSystemSim<N2, N1, N1> {
* @param dtSeconds The time difference between controller updates.
*/
@Override
@SuppressWarnings({"ParameterName", "LambdaParameterName"})
protected Matrix<N2, N1> updateX(Matrix<N2, N1> currentXhat, Matrix<N1, N1> u, double dtSeconds) {
// Horizontal case:
// Torque = F * r = I * alpha

View File

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