mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Clean up Java style (#5990)
Also make equivalent changes in C++ where applicable. Co-authored-by: Sriman Achanta <68172138+srimanachanta@users.noreply.github.com>
This commit is contained in:
@@ -108,9 +108,9 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
_32s(10),
|
||||
_64s(11);
|
||||
|
||||
private int value;
|
||||
private final int value;
|
||||
|
||||
private CalibrationTime(int value) {
|
||||
CalibrationTime(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -130,9 +130,9 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
private IMUAxis m_yaw_axis;
|
||||
|
||||
/* Offset data storage */
|
||||
private double m_offset_data_gyro_rate_x[];
|
||||
private double m_offset_data_gyro_rate_y[];
|
||||
private double m_offset_data_gyro_rate_z[];
|
||||
private double[] m_offset_data_gyro_rate_x;
|
||||
private double[] m_offset_data_gyro_rate_y;
|
||||
private double[] m_offset_data_gyro_rate_z;
|
||||
|
||||
/* Instant raw output variables */
|
||||
private double m_gyro_rate_x = 0.0;
|
||||
@@ -199,7 +199,7 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
private SimDouble m_simAccelZ;
|
||||
|
||||
/* CRC-16 Look-Up Table */
|
||||
int adiscrc[] =
|
||||
int[] adiscrc =
|
||||
new int[] {
|
||||
0x0000, 0x17CE, 0x0FDF, 0x1811, 0x1FBE, 0x0870, 0x1061, 0x07AF,
|
||||
0x1F3F, 0x08F1, 0x10E0, 0x072E, 0x0081, 0x174F, 0x0F5E, 0x1890,
|
||||
@@ -358,7 +358,7 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
|
||||
/** */
|
||||
private static int toShort(int... buf) {
|
||||
return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF) << 0));
|
||||
return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@@ -481,7 +481,7 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable {
|
||||
}
|
||||
|
||||
public int configDecRate(int m_decRate) {
|
||||
int writeValue = m_decRate;
|
||||
int writeValue;
|
||||
int readbackValue;
|
||||
if (!switchToStandardSPI()) {
|
||||
DriverStation.reportError("Failed to configure/reconfigure standard SPI.", false);
|
||||
|
||||
@@ -193,9 +193,9 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
_32s(10),
|
||||
_64s(11);
|
||||
|
||||
private int value;
|
||||
private final int value;
|
||||
|
||||
private CalibrationTime(int value) {
|
||||
CalibrationTime(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
* @return
|
||||
*/
|
||||
private static int toShort(int... buf) {
|
||||
return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF) << 0));
|
||||
return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,7 +593,6 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable {
|
||||
if (!switchToAutoSPI()) {
|
||||
DriverStation.reportError("Failed to configure/reconfigure auto SPI.", false);
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -239,6 +239,7 @@ public final class DriverStation {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (axes.m_axes[i] != m_prevAxes.m_axes[i]) {
|
||||
needToLog = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,6 +256,7 @@ public final class DriverStation {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (povs.m_povs[i] != m_prevPOVs.m_povs[i]) {
|
||||
needToLog = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ public class I2C implements AutoCloseable {
|
||||
|
||||
byte[] deviceData = new byte[4];
|
||||
for (int i = 0; i < count; i += 4) {
|
||||
int toRead = count - i < 4 ? count - i : 4;
|
||||
int toRead = Math.min(count - i, 4);
|
||||
// Read the chunk of data. Return false if the sensor does not
|
||||
// respond.
|
||||
dataToSend[0] = (byte) (registerAddress + i);
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class MotorSafety {
|
||||
synchronized (m_listMutex) {
|
||||
m_instanceList.add(this);
|
||||
if (m_safetyThread == null) {
|
||||
m_safetyThread = new Thread(() -> threadMain(), "MotorSafety Thread");
|
||||
m_safetyThread = new Thread(MotorSafety::threadMain, "MotorSafety Thread");
|
||||
m_safetyThread.setDaemon(true);
|
||||
m_safetyThread.start();
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class Notifier implements AutoCloseable {
|
||||
updateAlarm();
|
||||
} else {
|
||||
// Need to update the alarm to cause it to wait again
|
||||
updateAlarm((long) -1);
|
||||
updateAlarm(-1);
|
||||
}
|
||||
} finally {
|
||||
m_processLock.unlock();
|
||||
@@ -134,7 +134,7 @@ public class Notifier implements AutoCloseable {
|
||||
error = cause;
|
||||
}
|
||||
DriverStation.reportError(
|
||||
"Unhandled exception in Notifier thread: " + error.toString(), error.getStackTrace());
|
||||
"Unhandled exception in Notifier thread: " + error, error.getStackTrace());
|
||||
DriverStation.reportError(
|
||||
"The Runnable for this Notifier (or methods called by it) should have handled "
|
||||
+ "the exception above.\n"
|
||||
|
||||
@@ -59,8 +59,7 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
output.write(("currentVersion=" + fwVersion).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
DriverStation.reportError(
|
||||
"Could not write " + fileName + ": " + ex.toString(), ex.getStackTrace());
|
||||
DriverStation.reportError("Could not write " + fileName + ": " + ex, ex.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,14 +114,12 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
|
||||
/** Converts volts to PSI per the REV Analog Pressure Sensor datasheet. */
|
||||
private static double voltsToPsi(double sensorVoltage, double supplyVoltage) {
|
||||
double pressure = 250 * (sensorVoltage / supplyVoltage) - 25;
|
||||
return pressure;
|
||||
return 250 * (sensorVoltage / supplyVoltage) - 25;
|
||||
}
|
||||
|
||||
/** Converts PSI to volts per the REV Analog Pressure Sensor datasheet. */
|
||||
private static double psiToVolts(double pressure, double supplyVoltage) {
|
||||
double voltage = supplyVoltage * (0.004 * pressure + 0.1);
|
||||
return voltage;
|
||||
return supplyVoltage * (0.004 * pressure + 0.1);
|
||||
}
|
||||
|
||||
private final DataStore m_dataStore;
|
||||
|
||||
@@ -6,5 +6,5 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
public enum PneumaticsModuleType {
|
||||
CTREPCM,
|
||||
REVPH;
|
||||
REVPH
|
||||
}
|
||||
|
||||
@@ -101,9 +101,7 @@ public class PowerDistribution implements Sendable, AutoCloseable {
|
||||
* @return The current of the channel in Amperes
|
||||
*/
|
||||
public double getCurrent(int channel) {
|
||||
double current = PowerDistributionJNI.getChannelCurrent(m_handle, channel);
|
||||
|
||||
return current;
|
||||
return PowerDistributionJNI.getChannelCurrent(m_handle, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -321,8 +321,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
robotName = elements[0].getClassName();
|
||||
}
|
||||
DriverStation.reportError(
|
||||
"Unhandled exception instantiating robot " + robotName + " " + throwable.toString(),
|
||||
elements);
|
||||
"Unhandled exception instantiating robot " + robotName + " " + throwable, elements);
|
||||
DriverStation.reportError(
|
||||
"The robot program quit unexpectedly."
|
||||
+ " This is usually due to a code error.\n"
|
||||
@@ -353,8 +352,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
output.write(WPILibVersion.Version.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
DriverStation.reportError(
|
||||
"Could not write FRC_Lib_Version.ini: " + ex.toString(), ex.getStackTrace());
|
||||
DriverStation.reportError("Could not write FRC_Lib_Version.ini: " + ex, ex.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,8 +364,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
if (cause != null) {
|
||||
throwable = cause;
|
||||
}
|
||||
DriverStation.reportError(
|
||||
"Unhandled exception: " + throwable.toString(), throwable.getStackTrace());
|
||||
DriverStation.reportError("Unhandled exception: " + throwable, throwable.getStackTrace());
|
||||
errorOnExit = true;
|
||||
} finally {
|
||||
m_runMutex.lock();
|
||||
|
||||
@@ -33,7 +33,7 @@ public final class RobotController {
|
||||
* @return FPGA Revision number.
|
||||
*/
|
||||
public static long getFPGARevision() {
|
||||
return (long) HALUtil.getFPGARevision();
|
||||
return HALUtil.getFPGARevision();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,12 +59,12 @@ public final class SensorUtil {
|
||||
*/
|
||||
public static void checkDigitalChannel(final int channel) {
|
||||
if (!DIOJNI.checkDIOChannel(channel)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Requested DIO channel is out of range. Minimum: 0, Maximum: ")
|
||||
.append(kDigitalChannels)
|
||||
.append(", Requested: ")
|
||||
.append(channel);
|
||||
throw new IllegalArgumentException(buf.toString());
|
||||
String buf =
|
||||
"Requested DIO channel is out of range. Minimum: 0, Maximum: "
|
||||
+ kDigitalChannels
|
||||
+ ", Requested: "
|
||||
+ channel;
|
||||
throw new IllegalArgumentException(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,12 +76,12 @@ public final class SensorUtil {
|
||||
*/
|
||||
public static void checkRelayChannel(final int channel) {
|
||||
if (!RelayJNI.checkRelayChannel(channel)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Requested relay channel is out of range. Minimum: 0, Maximum: ")
|
||||
.append(kRelayChannels)
|
||||
.append(", Requested: ")
|
||||
.append(channel);
|
||||
throw new IllegalArgumentException(buf.toString());
|
||||
String buf =
|
||||
"Requested relay channel is out of range. Minimum: 0, Maximum: "
|
||||
+ kRelayChannels
|
||||
+ ", Requested: "
|
||||
+ channel;
|
||||
throw new IllegalArgumentException(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +93,12 @@ public final class SensorUtil {
|
||||
*/
|
||||
public static void checkPWMChannel(final int channel) {
|
||||
if (!PWMJNI.checkPWMChannel(channel)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Requested PWM channel is out of range. Minimum: 0, Maximum: ")
|
||||
.append(kPwmChannels)
|
||||
.append(", Requested: ")
|
||||
.append(channel);
|
||||
throw new IllegalArgumentException(buf.toString());
|
||||
String buf =
|
||||
"Requested PWM channel is out of range. Minimum: 0, Maximum: "
|
||||
+ kPwmChannels
|
||||
+ ", Requested: "
|
||||
+ channel;
|
||||
throw new IllegalArgumentException(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,12 +110,12 @@ public final class SensorUtil {
|
||||
*/
|
||||
public static void checkAnalogInputChannel(final int channel) {
|
||||
if (!AnalogJNI.checkAnalogInputChannel(channel)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Requested analog input channel is out of range. Minimum: 0, Maximum: ")
|
||||
.append(kAnalogInputChannels)
|
||||
.append(", Requested: ")
|
||||
.append(channel);
|
||||
throw new IllegalArgumentException(buf.toString());
|
||||
String buf =
|
||||
"Requested analog input channel is out of range. Minimum: 0, Maximum: "
|
||||
+ kAnalogInputChannels
|
||||
+ ", Requested: "
|
||||
+ channel;
|
||||
throw new IllegalArgumentException(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,12 +127,12 @@ public final class SensorUtil {
|
||||
*/
|
||||
public static void checkAnalogOutputChannel(final int channel) {
|
||||
if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("Requested analog output channel is out of range. Minimum: 0, Maximum: ")
|
||||
.append(kAnalogOutputChannels)
|
||||
.append(", Requested: ")
|
||||
.append(channel);
|
||||
throw new IllegalArgumentException(buf.toString());
|
||||
String buf =
|
||||
"Requested analog output channel is out of range. Minimum: 0, Maximum: "
|
||||
+ kAnalogOutputChannels
|
||||
+ ", Requested: "
|
||||
+ channel;
|
||||
throw new IllegalArgumentException(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ public class SerialPort implements AutoCloseable {
|
||||
*/
|
||||
public String readString(int count) {
|
||||
byte[] out = read(count);
|
||||
return new String(out, 0, out.length, StandardCharsets.US_ASCII);
|
||||
return new String(out, StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,9 +75,7 @@ public class Tracer {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
m_lastEpochsPrintTime = now;
|
||||
m_epochs.forEach(
|
||||
(key, value) -> {
|
||||
sb.append(String.format("\t%s: %.6fs\n", key, value / 1.0e6));
|
||||
});
|
||||
(key, value) -> sb.append(String.format("\t%s: %.6fs\n", key, value / 1.0e6)));
|
||||
if (sb.length() > 0) {
|
||||
output.accept(sb.toString());
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
}
|
||||
|
||||
private static void updateAlarm() {
|
||||
if (m_watchdogs.size() == 0) {
|
||||
if (m_watchdogs.isEmpty()) {
|
||||
NotifierJNI.cancelNotifierAlarm(m_notifier);
|
||||
} else {
|
||||
NotifierJNI.updateNotifierAlarm(
|
||||
@@ -233,7 +233,7 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
|
||||
m_queueMutex.lock();
|
||||
try {
|
||||
if (m_watchdogs.size() == 0) {
|
||||
if (m_watchdogs.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class LiveWindow {
|
||||
private static Runnable disabledListener;
|
||||
|
||||
static {
|
||||
SendableRegistry.setLiveWindowBuilderFactory(() -> new SendableBuilderImpl());
|
||||
SendableRegistry.setLiveWindowBuilderFactory(SendableBuilderImpl::new);
|
||||
enabledPub.set(false);
|
||||
}
|
||||
|
||||
@@ -105,10 +105,7 @@ public final class LiveWindow {
|
||||
} else {
|
||||
System.out.println("stopping live window mode.");
|
||||
SendableRegistry.foreachLiveWindow(
|
||||
dataHandle,
|
||||
cbdata -> {
|
||||
((SendableBuilderImpl) cbdata.builder).stopLiveWindowMode();
|
||||
});
|
||||
dataHandle, cbdata -> ((SendableBuilderImpl) cbdata.builder).stopLiveWindowMode());
|
||||
if (disabledListener != null) {
|
||||
disabledListener.run();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ import edu.wpi.first.wpilibj.PWM;
|
||||
* 884 controllers also but if users experience issues such as asymmetric behavior around the
|
||||
* deadband or inability to saturate the controller in either direction, calibration is recommended.
|
||||
* The calibration procedure can be found in the Victor 884 User Manual available from VEX Robotics:
|
||||
* http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf
|
||||
* <a
|
||||
* href="http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf">http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf</a>
|
||||
*
|
||||
* <ul>
|
||||
* <li>2.027ms = full "forward"
|
||||
|
||||
@@ -236,12 +236,9 @@ public class DifferentialDrivetrainSim {
|
||||
* @return the drivetrain's left side current draw, in amps
|
||||
*/
|
||||
public double getLeftCurrentDrawAmps() {
|
||||
var loadIleft =
|
||||
m_motor.getCurrent(
|
||||
getState(State.kLeftVelocity) * m_currentGearing / m_wheelRadiusMeters,
|
||||
m_u.get(0, 0))
|
||||
* Math.signum(m_u.get(0, 0));
|
||||
return loadIleft;
|
||||
return m_motor.getCurrent(
|
||||
getState(State.kLeftVelocity) * m_currentGearing / m_wheelRadiusMeters, m_u.get(0, 0))
|
||||
* Math.signum(m_u.get(0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,13 +247,9 @@ public class DifferentialDrivetrainSim {
|
||||
* @return the drivetrain's right side current draw, in amps
|
||||
*/
|
||||
public double getRightCurrentDrawAmps() {
|
||||
var loadIright =
|
||||
m_motor.getCurrent(
|
||||
getState(State.kRightVelocity) * m_currentGearing / m_wheelRadiusMeters,
|
||||
m_u.get(1, 0))
|
||||
* Math.signum(m_u.get(1, 0));
|
||||
|
||||
return loadIright;
|
||||
return m_motor.getCurrent(
|
||||
getState(State.kRightVelocity) * m_currentGearing / m_wheelRadiusMeters, m_u.get(1, 0))
|
||||
* Math.signum(m_u.get(1, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -135,7 +135,7 @@ public class GenericHIDSim {
|
||||
*/
|
||||
public boolean getOutput(int outputNumber) {
|
||||
long outputs = getOutputs();
|
||||
return (outputs & (1 << (outputNumber - 1))) != 0;
|
||||
return (outputs & (1L << (outputNumber - 1))) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@ import edu.wpi.first.math.geometry.Translation2d;
|
||||
import edu.wpi.first.math.trajectory.Trajectory;
|
||||
import edu.wpi.first.networktables.DoubleArrayEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** Game field object on a Field2d. */
|
||||
@@ -70,9 +71,7 @@ public class FieldObject2d implements AutoCloseable {
|
||||
*/
|
||||
public synchronized void setPoses(List<Pose2d> poses) {
|
||||
m_poses.clear();
|
||||
for (Pose2d pose : poses) {
|
||||
m_poses.add(pose);
|
||||
}
|
||||
m_poses.addAll(poses);
|
||||
updateEntry();
|
||||
}
|
||||
|
||||
@@ -83,9 +82,7 @@ public class FieldObject2d implements AutoCloseable {
|
||||
*/
|
||||
public synchronized void setPoses(Pose2d... poses) {
|
||||
m_poses.clear();
|
||||
for (Pose2d pose : poses) {
|
||||
m_poses.add(pose);
|
||||
}
|
||||
Collections.addAll(m_poses, poses);
|
||||
updateEntry();
|
||||
}
|
||||
|
||||
@@ -109,7 +106,7 @@ public class FieldObject2d implements AutoCloseable {
|
||||
*/
|
||||
public synchronized List<Pose2d> getPoses() {
|
||||
updateFromEntry();
|
||||
return new ArrayList<Pose2d>(m_poses);
|
||||
return new ArrayList<>(m_poses);
|
||||
}
|
||||
|
||||
void updateEntry() {
|
||||
@@ -143,7 +140,7 @@ public class FieldObject2d implements AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
double[] arr = m_entry.get((double[]) null);
|
||||
double[] arr = m_entry.get(null);
|
||||
if (arr != null) {
|
||||
if ((arr.length % 3) != 0) {
|
||||
return;
|
||||
|
||||
@@ -31,9 +31,9 @@ class ListenerExecutor implements Executor {
|
||||
/** Runs all posted tasks. Called periodically from main thread. */
|
||||
public void runListenerTasks() {
|
||||
// Locally copy tasks from internal list; minimizes blocking time
|
||||
Collection<Runnable> tasks = new ArrayList<>();
|
||||
Collection<Runnable> tasks;
|
||||
synchronized (m_lock) {
|
||||
tasks.addAll(m_tasks);
|
||||
tasks = new ArrayList<>(m_tasks);
|
||||
m_tasks.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -144,11 +144,7 @@ class TimedRobotTest {
|
||||
void disabledModeTest() {
|
||||
MockRobot robot = new MockRobot();
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(false);
|
||||
@@ -231,11 +227,7 @@ class TimedRobotTest {
|
||||
void autonomousModeTest() {
|
||||
MockRobot robot = new MockRobot();
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(true);
|
||||
@@ -320,11 +312,7 @@ class TimedRobotTest {
|
||||
void teleopModeTest() {
|
||||
MockRobot robot = new MockRobot();
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(true);
|
||||
@@ -411,11 +399,7 @@ class TimedRobotTest {
|
||||
MockRobot robot = new MockRobot();
|
||||
robot.enableLiveWindowInTest(isLW);
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(true);
|
||||
@@ -531,11 +515,7 @@ class TimedRobotTest {
|
||||
void modeChangeTest() {
|
||||
MockRobot robot = new MockRobot();
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
// Start in disabled
|
||||
@@ -655,17 +635,9 @@ class TimedRobotTest {
|
||||
MockRobot robot = new MockRobot();
|
||||
|
||||
final AtomicInteger callbackCount = new AtomicInteger(0);
|
||||
robot.addPeriodic(
|
||||
() -> {
|
||||
callbackCount.addAndGet(1);
|
||||
},
|
||||
kPeriod / 2.0);
|
||||
robot.addPeriodic(() -> callbackCount.addAndGet(1), kPeriod / 2.0);
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(false);
|
||||
@@ -704,12 +676,7 @@ class TimedRobotTest {
|
||||
MockRobot robot = new MockRobot();
|
||||
|
||||
final AtomicInteger callbackCount = new AtomicInteger(0);
|
||||
robot.addPeriodic(
|
||||
() -> {
|
||||
callbackCount.addAndGet(1);
|
||||
},
|
||||
kPeriod / 2.0,
|
||||
kPeriod / 4.0);
|
||||
robot.addPeriodic(() -> callbackCount.addAndGet(1), kPeriod / 2.0, kPeriod / 4.0);
|
||||
|
||||
// Expirations in this test (ms)
|
||||
//
|
||||
@@ -720,11 +687,7 @@ class TimedRobotTest {
|
||||
// p | 0.75p
|
||||
// 2p | 1.25p
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(false);
|
||||
|
||||
@@ -54,22 +54,10 @@ class TimesliceRobotTest {
|
||||
// | RobotPeriodic() | 0 | 2 |
|
||||
// | Callback 1 | 2 | 0.5 |
|
||||
// | Callback 2 | 2.5 | 1 |
|
||||
robot.schedule(
|
||||
() -> {
|
||||
callbackCount1.addAndGet(1);
|
||||
},
|
||||
0.0005);
|
||||
robot.schedule(
|
||||
() -> {
|
||||
callbackCount2.addAndGet(1);
|
||||
},
|
||||
0.001);
|
||||
robot.schedule(() -> callbackCount1.addAndGet(1), 0.0005);
|
||||
robot.schedule(() -> callbackCount2.addAndGet(1), 0.001);
|
||||
|
||||
Thread robotThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
robot.startCompetition();
|
||||
});
|
||||
Thread robotThread = new Thread(robot::startCompetition);
|
||||
robotThread.start();
|
||||
|
||||
DriverStationSim.setEnabled(false);
|
||||
|
||||
@@ -33,12 +33,7 @@ class WatchdogTest {
|
||||
void enableDisableTest() {
|
||||
final AtomicInteger watchdogCounter = new AtomicInteger(0);
|
||||
|
||||
try (Watchdog watchdog =
|
||||
new Watchdog(
|
||||
0.4,
|
||||
() -> {
|
||||
watchdogCounter.addAndGet(1);
|
||||
})) {
|
||||
try (Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1))) {
|
||||
// Run 1
|
||||
watchdog.enable();
|
||||
SimHooks.stepTiming(0.2);
|
||||
@@ -71,12 +66,7 @@ class WatchdogTest {
|
||||
void resetTest() {
|
||||
final AtomicInteger watchdogCounter = new AtomicInteger(0);
|
||||
|
||||
try (Watchdog watchdog =
|
||||
new Watchdog(
|
||||
0.4,
|
||||
() -> {
|
||||
watchdogCounter.addAndGet(1);
|
||||
})) {
|
||||
try (Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1))) {
|
||||
watchdog.enable();
|
||||
SimHooks.stepTiming(0.2);
|
||||
watchdog.reset();
|
||||
@@ -92,12 +82,7 @@ class WatchdogTest {
|
||||
void setTimeoutTest() {
|
||||
final AtomicInteger watchdogCounter = new AtomicInteger(0);
|
||||
|
||||
try (Watchdog watchdog =
|
||||
new Watchdog(
|
||||
1.0,
|
||||
() -> {
|
||||
watchdogCounter.addAndGet(1);
|
||||
})) {
|
||||
try (Watchdog watchdog = new Watchdog(1.0, () -> watchdogCounter.addAndGet(1))) {
|
||||
watchdog.enable();
|
||||
SimHooks.stepTiming(0.2);
|
||||
watchdog.setTimeout(0.2);
|
||||
@@ -137,12 +122,7 @@ class WatchdogTest {
|
||||
void epochsTest() {
|
||||
final AtomicInteger watchdogCounter = new AtomicInteger(0);
|
||||
|
||||
try (Watchdog watchdog =
|
||||
new Watchdog(
|
||||
0.4,
|
||||
() -> {
|
||||
watchdogCounter.addAndGet(1);
|
||||
})) {
|
||||
try (Watchdog watchdog = new Watchdog(0.4, () -> watchdogCounter.addAndGet(1))) {
|
||||
// Run 1
|
||||
watchdog.enable();
|
||||
watchdog.addEpoch("Epoch 1");
|
||||
@@ -173,18 +153,8 @@ class WatchdogTest {
|
||||
final AtomicInteger watchdogCounter1 = new AtomicInteger(0);
|
||||
final AtomicInteger watchdogCounter2 = new AtomicInteger(0);
|
||||
|
||||
try (Watchdog watchdog1 =
|
||||
new Watchdog(
|
||||
0.2,
|
||||
() -> {
|
||||
watchdogCounter1.addAndGet(1);
|
||||
});
|
||||
Watchdog watchdog2 =
|
||||
new Watchdog(
|
||||
0.6,
|
||||
() -> {
|
||||
watchdogCounter2.addAndGet(1);
|
||||
})) {
|
||||
try (Watchdog watchdog1 = new Watchdog(0.2, () -> watchdogCounter1.addAndGet(1));
|
||||
Watchdog watchdog2 = new Watchdog(0.6, () -> watchdogCounter2.addAndGet(1))) {
|
||||
watchdog2.enable();
|
||||
SimHooks.stepTiming(0.25);
|
||||
assertEquals(0, watchdogCounter1.get(), "Watchdog triggered early");
|
||||
|
||||
@@ -136,7 +136,7 @@ class ShuffleboardInstanceTest {
|
||||
try (StringSubscriber subscriber =
|
||||
m_ntInstance
|
||||
.getStringTopic("/Shuffleboard/.metadata/Selected")
|
||||
.subscribe("", PubSubOption.keepDuplicates(true)); ) {
|
||||
.subscribe("", PubSubOption.keepDuplicates(true))) {
|
||||
listener =
|
||||
m_ntInstance.addListener(
|
||||
subscriber,
|
||||
|
||||
@@ -79,7 +79,7 @@ class AddressableLEDSimTest {
|
||||
BufferCallback callback = new BufferCallback();
|
||||
|
||||
try (AddressableLED led = new AddressableLED(0);
|
||||
CallbackStore cb = sim.registerDataCallback(callback); ) {
|
||||
CallbackStore cb = sim.registerDataCallback(callback)) {
|
||||
assertFalse(sim.getRunning());
|
||||
|
||||
assertEquals(1, sim.getLength()); // Defaults to 1 led
|
||||
|
||||
@@ -63,7 +63,7 @@ class DCMotorSimTest {
|
||||
|
||||
try (var motor = new PWMVictorSPX(0);
|
||||
var encoder = new Encoder(0, 1);
|
||||
var controller = new PIDController(0.04, 0.0, 0.001); ) {
|
||||
var controller = new PIDController(0.04, 0.0, 0.001)) {
|
||||
var encoderSim = new EncoderSim(encoder);
|
||||
encoderSim.resetData();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class DigitalPWMSimTest {
|
||||
BooleanCallback initializeCallback = new BooleanCallback();
|
||||
DoubleCallback dutyCycleCallback = new DoubleCallback();
|
||||
try (CallbackStore initCb = sim.registerInitializedCallback(initializeCallback, false);
|
||||
CallbackStore dutyCycleCb = sim.registerDutyCycleCallback(dutyCycleCallback, false); ) {
|
||||
CallbackStore dutyCycleCb = sim.registerDutyCycleCallback(dutyCycleCallback, false)) {
|
||||
final double kTestDutyCycle = 0.191;
|
||||
output.enablePWM(kTestDutyCycle);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class RelaySimTest {
|
||||
|
||||
try (CallbackStore fwdCb = sim.registerInitializedForwardCallback(forwardCallback, false);
|
||||
CallbackStore revCb = sim.registerInitializedReverseCallback(reverseCallback, false);
|
||||
Relay relay = new Relay(0, Relay.Direction.kForward); ) {
|
||||
Relay relay = new Relay(0, Relay.Direction.kForward)) {
|
||||
assertTrue(sim.getInitializedForward());
|
||||
assertFalse(sim.getInitializedReverse());
|
||||
|
||||
@@ -84,7 +84,7 @@ class RelaySimTest {
|
||||
|
||||
try (CallbackStore fwdCb = sim.registerInitializedForwardCallback(forwardCallback, false);
|
||||
CallbackStore revCb = sim.registerInitializedReverseCallback(reverseCallback, false);
|
||||
Relay relay = new Relay(0, Relay.Direction.kReverse); ) {
|
||||
Relay relay = new Relay(0, Relay.Direction.kReverse)) {
|
||||
assertFalse(sim.getInitializedForward());
|
||||
assertTrue(sim.getInitializedReverse());
|
||||
|
||||
|
||||
@@ -41,18 +41,10 @@ class SimDeviceSimTest {
|
||||
SimDevice dev1 = SimDevice.create("testDC1")) {
|
||||
try (CallbackStore callback1 =
|
||||
SimDeviceSim.registerDeviceCreatedCallback(
|
||||
"testDC",
|
||||
(name, handle) -> {
|
||||
callback1Counter.addAndGet(1);
|
||||
},
|
||||
false);
|
||||
"testDC", (name, handle) -> callback1Counter.addAndGet(1), false);
|
||||
CallbackStore callback2 =
|
||||
SimDeviceSim.registerDeviceCreatedCallback(
|
||||
"testDC",
|
||||
(name, handle) -> {
|
||||
callback2Counter.addAndGet(1);
|
||||
},
|
||||
true)) {
|
||||
"testDC", (name, handle) -> callback2Counter.addAndGet(1), true)) {
|
||||
assertEquals(0, callback1Counter.get(), "Callback 1 called early");
|
||||
assertEquals(
|
||||
1,
|
||||
@@ -82,11 +74,7 @@ class SimDeviceSimTest {
|
||||
SimDevice dev1 = SimDevice.create("testDF1");
|
||||
try (CallbackStore callback =
|
||||
SimDeviceSim.registerDeviceFreedCallback(
|
||||
"testDF",
|
||||
(name, handle) -> {
|
||||
counter.addAndGet(1);
|
||||
},
|
||||
false)) {
|
||||
"testDF", (name, handle) -> counter.addAndGet(1), false)) {
|
||||
assertEquals(0, counter.get(), "Callback called early");
|
||||
dev1.close();
|
||||
assertEquals(1, counter.get(), "Callback called either more than once or not at all");
|
||||
@@ -108,16 +96,10 @@ class SimDeviceSimTest {
|
||||
SimDeviceSim sim = new SimDeviceSim("testVM1");
|
||||
try (CallbackStore callback1 =
|
||||
sim.registerValueCreatedCallback(
|
||||
(name, handle, readonly, value) -> {
|
||||
callback1Counter.addAndGet(1);
|
||||
},
|
||||
false);
|
||||
(name, handle, readonly, value) -> callback1Counter.addAndGet(1), false);
|
||||
CallbackStore callback2 =
|
||||
sim.registerValueCreatedCallback(
|
||||
(name, handle, readonly, value) -> {
|
||||
callback2Counter.addAndGet(1);
|
||||
},
|
||||
true)) {
|
||||
(name, handle, readonly, value) -> callback2Counter.addAndGet(1), true)) {
|
||||
assertEquals(0, callback1Counter.get(), "Callback 1 called early");
|
||||
assertEquals(
|
||||
1,
|
||||
@@ -148,18 +130,10 @@ class SimDeviceSimTest {
|
||||
SimValue simVal = sim.getValue("v1");
|
||||
try (CallbackStore callback1 =
|
||||
sim.registerValueChangedCallback(
|
||||
simVal,
|
||||
(name, handle, readonly, value) -> {
|
||||
callback1Counter.addAndGet(1);
|
||||
},
|
||||
false);
|
||||
simVal, (name, handle, readonly, value) -> callback1Counter.addAndGet(1), false);
|
||||
CallbackStore callback2 =
|
||||
sim.registerValueChangedCallback(
|
||||
simVal,
|
||||
(name, handle, readonly, value) -> {
|
||||
callback2Counter.addAndGet(1);
|
||||
},
|
||||
true)) {
|
||||
simVal, (name, handle, readonly, value) -> callback2Counter.addAndGet(1), true)) {
|
||||
assertEquals(0, callback1Counter.get(), "Callback 1 called early");
|
||||
assertEquals(
|
||||
1,
|
||||
|
||||
@@ -75,7 +75,7 @@ class SendableChooserTest {
|
||||
chooser.addOption(String.valueOf(i), i);
|
||||
}
|
||||
AtomicInteger currentVal = new AtomicInteger();
|
||||
chooser.onChange(val -> currentVal.set(val));
|
||||
chooser.onChange(currentVal::set);
|
||||
|
||||
SmartDashboard.putData("changeListenerChooser", chooser);
|
||||
SmartDashboard.updateValues();
|
||||
|
||||
Reference in New Issue
Block a user