mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11: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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user