mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Update and enable PMD 6.3.0 (#1107)
This commit is contained in:
committed by
Peter Johnson
parent
8eafe7f325
commit
e548a5f705
@@ -75,17 +75,13 @@ ext.addTaskToCopyAllOutputs = { task ->
|
||||
subprojects {
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'checkstyle'
|
||||
|
||||
apply from: "${rootDir}/shared/java/javastyle.gradle"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "8.10"
|
||||
configFile = new File(rootDir, "styleguide/checkstyle.xml")
|
||||
}
|
||||
|
||||
// Disables doclint in java 8.
|
||||
if (JavaVersion.current().isJava8Compatible()) {
|
||||
tasks.withType(Javadoc) {
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
package edu.wpi.first.cameraserver;
|
||||
|
||||
public class DevMain {
|
||||
public final class DevMain {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
private DevMain() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import edu.wpi.cscore.AxisCamera;
|
||||
@@ -34,7 +36,8 @@ import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
* Singleton class for creating and keeping camera servers.
|
||||
* Also publishes camera information to NetworkTables.
|
||||
*/
|
||||
public class CameraServer {
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public final class CameraServer {
|
||||
public static final int kBasePort = 1181;
|
||||
|
||||
@Deprecated
|
||||
@@ -57,11 +60,11 @@ public class CameraServer {
|
||||
return server;
|
||||
}
|
||||
|
||||
private AtomicInteger m_defaultUsbDevice;
|
||||
private final AtomicInteger m_defaultUsbDevice;
|
||||
private String m_primarySourceName;
|
||||
private final Hashtable<String, VideoSource> m_sources;
|
||||
private final Hashtable<String, VideoSink> m_sinks;
|
||||
private final Hashtable<Integer, NetworkTable> m_tables; // indexed by source handle
|
||||
private final Map<String, VideoSource> m_sources;
|
||||
private final Map<String, VideoSink> m_sinks;
|
||||
private final Map<Integer, NetworkTable> m_tables; // indexed by source handle
|
||||
private final NetworkTable m_publishTable;
|
||||
private final VideoListener m_videoListener; //NOPMD
|
||||
private final int m_tableListener; //NOPMD
|
||||
@@ -115,7 +118,7 @@ public class CameraServer {
|
||||
// Otherwise generate for hostname and all interface addresses
|
||||
values.add(makeStreamValue(CameraServerJNI.getHostname() + ".local", port));
|
||||
for (String addr : m_addresses) {
|
||||
if (addr.equals("127.0.0.1")) {
|
||||
if ("127.0.0.1".equals(addr)) {
|
||||
continue; // ignore localhost
|
||||
}
|
||||
values.add(makeStreamValue(addr, port));
|
||||
@@ -146,10 +149,7 @@ public class CameraServer {
|
||||
if (source == sinkSource
|
||||
&& VideoSink.getKindFromInt(CameraServerJNI.getSinkKind(sink)) == VideoSink.Kind.kMjpeg) {
|
||||
// Add USB-only passthrough
|
||||
String[] finalValues = new String[values.length + 1];
|
||||
for (int j = 0; j < values.length; j++) {
|
||||
finalValues[j] = values[j];
|
||||
}
|
||||
String[] finalValues = Arrays.copyOf(values, values.length + 1);
|
||||
int port = CameraServerJNI.getMjpegServerPort(sink);
|
||||
finalValues[values.length] = makeStreamValue("172.22.11.2", port);
|
||||
return finalValues;
|
||||
@@ -238,7 +238,7 @@ public class CameraServer {
|
||||
return modeStrings;
|
||||
}
|
||||
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
@SuppressWarnings({"JavadocMethod", "PMD.CyclomaticComplexity"})
|
||||
private static void putSourcePropertyValue(NetworkTable table, VideoEvent event, boolean isNew) {
|
||||
String name;
|
||||
String infoName;
|
||||
@@ -286,12 +286,13 @@ public class CameraServer {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (VideoException ex) {
|
||||
} catch (VideoException ignored) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"JavadocMethod", "PMD.UnusedLocalVariable"})
|
||||
@SuppressWarnings({"JavadocMethod", "PMD.UnusedLocalVariable", "PMD.ExcessiveMethodLength",
|
||||
"PMD.NPathComplexity"})
|
||||
private CameraServer() {
|
||||
m_defaultUsbDevice = new AtomicInteger();
|
||||
m_sources = new Hashtable<>();
|
||||
@@ -329,7 +330,7 @@ public class CameraServer {
|
||||
VideoMode mode = CameraServerJNI.getSourceVideoMode(event.sourceHandle);
|
||||
table.getEntry("mode").setDefaultString(videoModeToString(mode));
|
||||
table.getEntry("modes").setStringArray(getSourceModeValues(event.sourceHandle));
|
||||
} catch (VideoException ex) {
|
||||
} catch (VideoException ignored) {
|
||||
// Do nothing. Let the other event handlers update this if there is an error.
|
||||
}
|
||||
break;
|
||||
@@ -394,7 +395,7 @@ public class CameraServer {
|
||||
try {
|
||||
String[] choices = CameraServerJNI.getEnumPropertyChoices(event.propertyHandle);
|
||||
table.getEntry("PropertyInfo/" + event.name + "/choices").setStringArray(choices);
|
||||
} catch (VideoException ex) {
|
||||
} catch (VideoException ignored) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@@ -437,7 +438,7 @@ public class CameraServer {
|
||||
|
||||
// handle standard names
|
||||
String propName;
|
||||
if (relativeKey.equals("mode")) {
|
||||
if ("mode".equals(relativeKey)) {
|
||||
// reset to current mode
|
||||
event.getEntry().setString(videoModeToString(source.getVideoMode()));
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
public class CameraServerSharedStore {
|
||||
public final class CameraServerSharedStore {
|
||||
private static CameraServerShared cameraServerShared;
|
||||
|
||||
private CameraServerSharedStore() {
|
||||
|
||||
@@ -9,7 +9,7 @@ package edu.wpi.cscore;
|
||||
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class DevMain {
|
||||
public final class DevMain {
|
||||
/**
|
||||
* Main method.
|
||||
*/
|
||||
@@ -18,4 +18,7 @@ public class DevMain {
|
||||
System.out.println(RuntimeDetector.getPlatformPath());
|
||||
System.out.println(CameraServerJNI.getHostname());
|
||||
}
|
||||
|
||||
private DevMain() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ public class VideoEvent {
|
||||
* @param kind The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 0x0001: return Kind.kSourceCreated;
|
||||
@@ -69,6 +70,7 @@ public class VideoEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.ExcessiveParameterList")
|
||||
VideoEvent(int kind, int source, int sink, String name, int pixelFormat,
|
||||
int width, int height, int fps, int property, int propertyKind,
|
||||
int value, String valueStr) {
|
||||
|
||||
@@ -148,6 +148,7 @@ public class VideoSink implements AutoCloseable {
|
||||
* Enumerate all existing sinks.
|
||||
* @return Vector of sinks.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public static VideoSink[] enumerateSinks() {
|
||||
int[] handles = CameraServerJNI.enumerateSinks();
|
||||
VideoSink[] rv = new VideoSink[handles.length];
|
||||
|
||||
@@ -138,6 +138,7 @@ public class VideoSource implements AutoCloseable {
|
||||
/**
|
||||
* Enumerate all properties of this source.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public VideoProperty[] enumerateProperties() {
|
||||
int[] handles = CameraServerJNI.enumerateSourceProperties(m_handle);
|
||||
VideoProperty[] rv = new VideoProperty[handles.length];
|
||||
@@ -239,6 +240,7 @@ public class VideoSource implements AutoCloseable {
|
||||
* Enumerate all sinks connected to this source.
|
||||
* @return Vector of sinks.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public VideoSink[] enumerateSinks() {
|
||||
int[] handles = CameraServerJNI.enumerateSourceSinks(m_handle);
|
||||
VideoSink[] rv = new VideoSink[handles.length];
|
||||
@@ -252,6 +254,7 @@ public class VideoSource implements AutoCloseable {
|
||||
* Enumerate all existing sources.
|
||||
* @return Vector of sources.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
public static VideoSource[] enumerateSources() {
|
||||
int[] handles = CameraServerJNI.enumerateSources();
|
||||
VideoSource[] rv = new VideoSource[handles.length];
|
||||
|
||||
@@ -140,12 +140,12 @@ public class FRCNetComm extends JNIWrapper {
|
||||
for i in range(1, len(enumCamel)):
|
||||
temp.write(enumCamel[i][0].lower() + \
|
||||
enumCamel[i][1:len(enumCamel[i])] + " ")
|
||||
temp.write("from " + os.path.basename(fileName) + "\n"
|
||||
" */\n"
|
||||
" @SuppressWarnings(\"TypeName\")\n"
|
||||
" public static final class " + enumName +
|
||||
" {\n"
|
||||
" private " + enumName + "() {\n }\n\n")
|
||||
temp.write(
|
||||
"from " + os.path.basename(fileName) + "\n"
|
||||
" */\n"
|
||||
" @SuppressWarnings({\"TypeName\", \"PMD.ConstantsInInterface\"})\n"
|
||||
" public static final class " + enumName + " {\n"
|
||||
" private " + enumName + "() {\n }\n\n")
|
||||
|
||||
# Write enum values
|
||||
count = 0
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
public class DevMain {
|
||||
public final class DevMain {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
private DevMain() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class CANData {
|
||||
/**
|
||||
* API used from JNI to set the data.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public byte[] setData(int length, long timestamp) {
|
||||
this.length = length;
|
||||
this.timestamp = timestamp;
|
||||
|
||||
@@ -10,14 +10,14 @@ package edu.wpi.first.wpilibj.can;
|
||||
import edu.wpi.first.wpilibj.communication.NIRioStatus;
|
||||
import edu.wpi.first.wpilibj.util.UncleanStatusException;
|
||||
|
||||
public class CANExceptionFactory {
|
||||
public final class CANExceptionFactory {
|
||||
// FRC Error codes
|
||||
static final int ERR_CANSessionMux_InvalidBuffer = -44086;
|
||||
static final int ERR_CANSessionMux_MessageNotFound = -44087;
|
||||
static final int ERR_CANSessionMux_NotAllowed = -44088;
|
||||
static final int ERR_CANSessionMux_NotInitialized = -44089;
|
||||
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
@SuppressWarnings({"JavadocMethod", "PMD.CyclomaticComplexity"})
|
||||
public static void checkStatus(int status, int messageID) throws CANInvalidBufferException,
|
||||
CANMessageNotAllowedException, CANNotInitializedException, UncleanStatusException {
|
||||
switch (status) {
|
||||
@@ -41,4 +41,8 @@ public class CANExceptionFactory {
|
||||
status));
|
||||
}
|
||||
}
|
||||
|
||||
private CANExceptionFactory() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class FRCNetComm extends JNIWrapper {
|
||||
/**
|
||||
* Module type from LoadOut.h
|
||||
*/
|
||||
@SuppressWarnings("TypeName")
|
||||
@SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"})
|
||||
public static final class tModuleType {
|
||||
private tModuleType() {
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class FRCNetComm extends JNIWrapper {
|
||||
/**
|
||||
* Target class from LoadOut.h
|
||||
*/
|
||||
@SuppressWarnings("TypeName")
|
||||
@SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"})
|
||||
public static final class tTargetClass {
|
||||
private tTargetClass() {
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class FRCNetComm extends JNIWrapper {
|
||||
/**
|
||||
* Resource type from UsageReporting.h
|
||||
*/
|
||||
@SuppressWarnings("TypeName")
|
||||
@SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"})
|
||||
public static final class tResourceType {
|
||||
private tResourceType() {
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class FRCNetComm extends JNIWrapper {
|
||||
/**
|
||||
* Instances from UsageReporting.h
|
||||
*/
|
||||
@SuppressWarnings("TypeName")
|
||||
@SuppressWarnings({"TypeName", "PMD.ConstantsInInterface"})
|
||||
public static final class tInstances {
|
||||
private tInstances() {
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import java.nio.ByteBuffer;
|
||||
/**
|
||||
* JNI Wrapper for HAL<br>.
|
||||
*/
|
||||
@SuppressWarnings({"AbbreviationAsWordInName", "MethodName"})
|
||||
public class HAL extends JNIWrapper {
|
||||
@SuppressWarnings({"AbbreviationAsWordInName", "MethodName", "PMD.TooManyMethods"})
|
||||
public final class HAL extends JNIWrapper {
|
||||
public static native void waitForDSData();
|
||||
|
||||
public static native boolean initialize(int timeout, int mode);
|
||||
@@ -127,4 +127,8 @@ public class HAL extends JNIWrapper {
|
||||
public static native int getPortWithModule(byte module, byte channel);
|
||||
|
||||
public static native int getPort(byte channel);
|
||||
|
||||
private HAL() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class HALUtil extends JNIWrapper {
|
||||
public final class HALUtil extends JNIWrapper {
|
||||
public static final int NULL_PARAMETER = -1005;
|
||||
public static final int SAMPLE_RATE_TOO_HIGH = 1001;
|
||||
public static final int VOLTAGE_OUT_OF_RANGE = 1002;
|
||||
@@ -37,4 +37,8 @@ public class HALUtil extends JNIWrapper {
|
||||
public static String getHALstrerror() {
|
||||
return getHALstrerror(getHALErrno());
|
||||
}
|
||||
|
||||
private HALUtil() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.AccelerometerDataJNI;
|
||||
|
||||
public class AccelerometerSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public AccelerometerSim() {
|
||||
m_index = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.AnalogGyroDataJNI;
|
||||
|
||||
public class AnalogGyroSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public AnalogGyroSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.AnalogInDataJNI;
|
||||
|
||||
public class AnalogInSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public AnalogInSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.AnalogOutDataJNI;
|
||||
|
||||
public class AnalogOutSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public AnalogOutSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.AnalogTriggerDataJNI;
|
||||
|
||||
public class AnalogTriggerSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public AnalogTriggerSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CallbackStore implements AutoCloseable {
|
||||
|
||||
private int index;
|
||||
private int channel;
|
||||
private int uid;
|
||||
private final int uid;
|
||||
private CancelCallbackFunc cancelCallback;
|
||||
private CancelCallbackChannelFunc cancelCallbackChannel;
|
||||
private CancelCallbackNoIndexFunc cancelCallbackNoIndex;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.DIODataJNI;
|
||||
|
||||
public class DIOSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public DIOSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.DigitalPWMDataJNI;
|
||||
|
||||
public class DigitalPWMSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public DigitalPWMSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.EncoderDataJNI;
|
||||
|
||||
public class EncoderSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public EncoderSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.I2CDataJNI;
|
||||
|
||||
public class I2CSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public I2CSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -14,21 +14,22 @@ public interface NotifyCallback {
|
||||
switch(type) {
|
||||
case 0x01:
|
||||
callback(name, SimValue.makeBoolean(value1 != 0));
|
||||
break;
|
||||
break;
|
||||
case 0x02:
|
||||
callback(name, SimValue.makeDouble(value2));
|
||||
break;
|
||||
break;
|
||||
case 0x16:
|
||||
callback(name, SimValue.makeEnum((int)value1));
|
||||
break;
|
||||
break;
|
||||
case 0x32:
|
||||
callback(name, SimValue.makeInt((int)value1));
|
||||
break;
|
||||
break;
|
||||
case 0x64:
|
||||
callback(name, SimValue.makeLong(value1));
|
||||
break;
|
||||
default:
|
||||
callback(name, SimValue.makeUnassigned());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.PCMDataJNI;
|
||||
|
||||
public class PCMSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public PCMSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.PDPDataJNI;
|
||||
|
||||
public class PDPSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public PDPSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.PWMDataJNI;
|
||||
|
||||
public class PWMSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public PWMSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.RelayDataJNI;
|
||||
|
||||
public class RelaySim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public RelaySim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -9,8 +9,9 @@ package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
import edu.wpi.first.hal.sim.mockdata.RoboRioDataJNI;
|
||||
|
||||
@SuppressWarnings({"PMD.ExcessivePublicCount", "PMD.TooManyMethods"})
|
||||
public class RoboRioSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public RoboRioSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.SPIAccelerometerDataJNI;
|
||||
|
||||
public class SPIAccelerometerSim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public SPIAccelerometerSim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
import edu.wpi.first.hal.sim.mockdata.SPIDataJNI;
|
||||
|
||||
public class SPISim {
|
||||
private int m_index;
|
||||
private final int m_index;
|
||||
|
||||
public SPISim(int index) {
|
||||
m_index = index;
|
||||
|
||||
@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
import edu.wpi.first.hal.sim.mockdata.SimulatorJNI;
|
||||
|
||||
public class SimHooks {
|
||||
public final class SimHooks {
|
||||
private SimHooks() {
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
public class SimValue {
|
||||
public final class SimValue {
|
||||
private boolean v_boolean;
|
||||
private long v_long;
|
||||
private double v_double;
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.ntcore;
|
||||
import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class DevMain {
|
||||
public final class DevMain {
|
||||
/**
|
||||
* Main method.
|
||||
*/
|
||||
@@ -19,4 +19,7 @@ public class DevMain {
|
||||
System.out.println(RuntimeDetector.getPlatformPath());
|
||||
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
|
||||
}
|
||||
|
||||
private DevMain() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ public final class NetworkTable {
|
||||
return m_inst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NetworkTable: " + m_path;
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
this.inst = inst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() { return "NetworkTable: " + path; }
|
||||
|
||||
private final ConcurrentMap<String, NetworkTableEntry> entries = new ConcurrentHashMap<String, NetworkTableEntry>();
|
||||
@@ -331,6 +332,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* @return True if connected, false if not connected.
|
||||
* @deprecated Use {@link NetworkTableInstance#isConnected()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isConnected() {
|
||||
return inst.isConnected();
|
||||
@@ -341,6 +343,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* @return True if operating as a server, false otherwise.
|
||||
* @deprecated Use {@link NetworkTableInstance#getNetworkMode()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isServer() {
|
||||
return (inst.getNetworkMode() & NetworkTableInstance.kNetModeServer) != 0;
|
||||
@@ -369,16 +372,20 @@ public class NetworkTable implements ITable, IRemote {
|
||||
private static final HashMap<IRemoteConnectionListener,ConnectionListenerAdapter> globalConnectionListenerMap = new HashMap<IRemoteConnectionListener,ConnectionListenerAdapter>();
|
||||
|
||||
private static IRemote staticRemote = new IRemote() {
|
||||
@Override
|
||||
public void addConnectionListener(IRemoteConnectionListener listener, boolean immediateNotify) {
|
||||
NetworkTable.addGlobalConnectionListener(listener, immediateNotify);
|
||||
}
|
||||
@Override
|
||||
public void removeConnectionListener(IRemoteConnectionListener listener) {
|
||||
NetworkTable.removeGlobalConnectionListener(listener);
|
||||
}
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
ConnectionInfo[] conns = NetworkTableInstance.getDefault().getConnections();
|
||||
return conns.length > 0;
|
||||
}
|
||||
@Override
|
||||
public boolean isServer() {
|
||||
return (NetworkTableInstance.getDefault().getNetworkMode() & NetworkTableInstance.kNetModeServer) != 0;
|
||||
}
|
||||
@@ -420,6 +427,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* @param immediateNotify call listener immediately for all existing connections
|
||||
* @deprecated Use {@link NetworkTableInstance#addConnectionListener(Consumer, boolean)} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public synchronized void addConnectionListener(IRemoteConnectionListener listener,
|
||||
boolean immediateNotify) {
|
||||
@@ -435,6 +443,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* @param listener connection listener
|
||||
* @deprecated Use {@link NetworkTableInstance#removeConnectionListener(int)} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public synchronized void removeConnectionListener(IRemoteConnectionListener listener) {
|
||||
ConnectionListenerAdapter adapter = connectionListenerMap.get(listener);
|
||||
@@ -657,6 +666,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
return getEntry(key).exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsSubTable(String key) {
|
||||
int[] handles = NetworkTablesJNI.getEntries(inst.getHandle(), pathWithSep + key + PATH_SEPARATOR, 0);
|
||||
return handles.length != 0;
|
||||
@@ -666,6 +676,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* @param types bitmask of types; 0 is treated as a "don't care".
|
||||
* @return keys currently in the table
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getKeys(int types) {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
int prefixLen = path.length() + 1;
|
||||
@@ -718,6 +729,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultNumber(String key, double defaultValue) {
|
||||
return getEntry(key).setDefaultDouble(defaultValue);
|
||||
}
|
||||
@@ -741,6 +753,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultString(String key, String defaultValue) {
|
||||
return getEntry(key).setDefaultString(defaultValue);
|
||||
}
|
||||
@@ -764,6 +777,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultBoolean(String key, boolean defaultValue) {
|
||||
return getEntry(key).setDefaultBoolean(defaultValue);
|
||||
}
|
||||
@@ -795,6 +809,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultBooleanArray(String key, boolean[] defaultValue) {
|
||||
return getEntry(key).setDefaultBooleanArray(defaultValue);
|
||||
}
|
||||
@@ -802,6 +817,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultBooleanArray(String key, Boolean[] defaultValue) {
|
||||
return getEntry(key).setDefaultBooleanArray(defaultValue);
|
||||
}
|
||||
@@ -841,6 +857,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultNumberArray(String key, double[] defaultValue) {
|
||||
return getEntry(key).setDefaultDoubleArray(defaultValue);
|
||||
}
|
||||
@@ -848,6 +865,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultNumberArray(String key, Double[] defaultValue) {
|
||||
return getEntry(key).setDefaultNumberArray(defaultValue);
|
||||
}
|
||||
@@ -879,6 +897,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultStringArray(String key, String[] defaultValue) {
|
||||
return getEntry(key).setDefaultStringArray(defaultValue);
|
||||
}
|
||||
@@ -902,6 +921,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean setDefaultRaw(String key, byte[] defaultValue) {
|
||||
return getEntry(key).setDefaultRaw(defaultValue);
|
||||
}
|
||||
@@ -957,6 +977,7 @@ public class NetworkTable implements ITable, IRemote {
|
||||
* instead, e.g. `NetworkTable.getEntry(key).setValue(NetworkTableEntry.makeBoolean(false));`
|
||||
* or `NetworkTable.getEntry(key).setValue(new Boolean(false));`
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean putValue(String key, Object value) throws IllegalArgumentException {
|
||||
if (value instanceof Boolean)
|
||||
|
||||
@@ -2,7 +2,6 @@ apply plugin: 'maven-publish'
|
||||
apply plugin: 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin'
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'net.ltgt.errorprone'
|
||||
apply plugin: 'pmd'
|
||||
|
||||
if (!hasProperty('releaseType')) {
|
||||
WPILibVersion {
|
||||
@@ -98,14 +97,6 @@ if (project.hasProperty('onlyAthena')) {
|
||||
test.enabled = false
|
||||
}
|
||||
|
||||
pmd {
|
||||
sourceSets = [sourceSets.main]
|
||||
consoleOutput = true
|
||||
reportsDir = file("$project.buildDir/reports/pmd")
|
||||
ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml"))
|
||||
ruleSets = []
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
16
shared/java/javastyle.gradle
Normal file
16
shared/java/javastyle.gradle
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
apply plugin: 'checkstyle'
|
||||
apply plugin: 'pmd'
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "8.10"
|
||||
configFile = new File(rootDir, "styleguide/checkstyle.xml")
|
||||
}
|
||||
|
||||
pmd {
|
||||
toolVersion = '6.3.0'
|
||||
consoleOutput = true
|
||||
reportsDir = file("$project.buildDir/reports/pmd")
|
||||
ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml"))
|
||||
ruleSets = []
|
||||
}
|
||||
@@ -4,6 +4,64 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
|
||||
<description>PMD Ruleset for WPILib</description>
|
||||
|
||||
<exclude-pattern>.*/*JNI.*</exclude-pattern>
|
||||
<exclude-pattern>.*/*Test.*</exclude-pattern>
|
||||
|
||||
<rule ref="category/java/bestpractices.xml">
|
||||
<exclude name="AccessorClassGeneration" />
|
||||
<exclude name="AccessorMethodGeneration" />
|
||||
<exclude name="AvoidPrintStackTrace" />
|
||||
<exclude name="AvoidReassigningParameters" />
|
||||
<exclude name="JUnitAssertionsShouldIncludeMessage" />
|
||||
<exclude name="JUnitTestContainsTooManyAsserts" />
|
||||
<exclude name="JUnit4TestShouldUseTestAnnotation" />
|
||||
<exclude name="ReplaceHashtableWithMap" />
|
||||
<exclude name="ReplaceVectorWithList" />
|
||||
<exclude name="SwitchStmtsShouldHaveDefault" />
|
||||
<exclude name="SystemPrintln" />
|
||||
<exclude name="UseVarargs" />
|
||||
</rule>
|
||||
|
||||
<rule ref="category/java/design.xml">
|
||||
<exclude name="DataClass" />
|
||||
<exclude name="LawOfDemeter" />
|
||||
<exclude name="LoosePackageCoupling" />
|
||||
<exclude name="NcssConstructorCount" />
|
||||
<exclude name="NcssCount" />
|
||||
<exclude name="NcssMethodCount" />
|
||||
</rule>
|
||||
|
||||
<rule ref="category/java/errorprone.xml">
|
||||
<exclude name="AssignmentToNonFinalStatic" />
|
||||
<exclude name="AvoidDuplicateLiterals" />
|
||||
<exclude name="AvoidLiteralsInIfCondition" />
|
||||
<exclude name="BeanMembersShouldSerialize" />
|
||||
<exclude name="ConstructorCallsOverridableMethod" />
|
||||
<exclude name="DataflowAnomalyAnalysis" />
|
||||
<exclude name="DoNotCallSystemExit" />
|
||||
<exclude name="FinalizeDoesNotCallSuperFinalize" />
|
||||
<exclude name="NullAssignment" />
|
||||
</rule>
|
||||
|
||||
<rule ref="category/java/multithreading.xml">
|
||||
<exclude name="AvoidSynchronizedAtMethodLevel" />
|
||||
<exclude name="AvoidUsingVolatile" />
|
||||
<exclude name="DoNotUseThreads" />
|
||||
</rule>
|
||||
|
||||
<rule ref="category/java/performance.xml">
|
||||
<exclude name="AvoidUsingShortType" />
|
||||
</rule>
|
||||
|
||||
<rule name="UnnecessaryCastRule"
|
||||
language="java"
|
||||
message="Avoid unnecessary casts"
|
||||
class="net.sourceforge.pmd.lang.java.rule.migrating.UnnecessaryCastRule"
|
||||
externalInfoUrl="https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/migrating/UnnecessaryCastRule.java" />
|
||||
|
||||
<!--
|
||||
<rule ref="rulesets/java/basic.xml" />
|
||||
<rule ref="rulesets/java/braces.xml" />
|
||||
<rule ref="rulesets/java/empty.xml" />
|
||||
@@ -28,6 +86,8 @@
|
||||
value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Custom Rules -->
|
||||
<rule name="UseRequireNonNull"
|
||||
message="Use Objects.requireNonNull() instead of throwing a NullPointerException yourself."
|
||||
|
||||
@@ -11,7 +11,7 @@ import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class DevMain {
|
||||
public final class DevMain {
|
||||
/**
|
||||
* Main entry point.
|
||||
*/
|
||||
@@ -21,4 +21,7 @@ public class DevMain {
|
||||
System.out.println(NetworkTablesJNI.now());
|
||||
System.out.println(HALUtil.getHALRuntimeType());
|
||||
}
|
||||
|
||||
private DevMain() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class AnalogAccelerometer extends SendableBase implements PIDSource {
|
||||
private AnalogInput m_analogChannel;
|
||||
private double m_voltsPerG = 1.0;
|
||||
private double m_zeroGVoltage = 2.5;
|
||||
private boolean m_allocatedChannel;
|
||||
private final boolean m_allocatedChannel;
|
||||
protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
|
||||
|
||||
/**
|
||||
@@ -42,8 +42,7 @@ public class AnalogAccelerometer extends SendableBase implements PIDSource {
|
||||
* @param channel The channel number for the analog input the accelerometer is connected to
|
||||
*/
|
||||
public AnalogAccelerometer(final int channel) {
|
||||
this(new AnalogInput(channel));
|
||||
m_allocatedChannel = true;
|
||||
this(new AnalogInput(channel), true);
|
||||
addChild(m_analogChannel);
|
||||
}
|
||||
|
||||
@@ -55,10 +54,13 @@ public class AnalogAccelerometer extends SendableBase implements PIDSource {
|
||||
* @param channel The existing AnalogInput object for the analog input the accelerometer is
|
||||
* connected to
|
||||
*/
|
||||
public AnalogAccelerometer(AnalogInput channel) {
|
||||
requireNonNull(channel, "Analog Channel given was null");
|
||||
public AnalogAccelerometer(final AnalogInput channel) {
|
||||
this(channel, false);
|
||||
}
|
||||
|
||||
m_allocatedChannel = false;
|
||||
private AnalogAccelerometer(final AnalogInput channel, final boolean allocatedChannel) {
|
||||
requireNonNull(channel, "Analog Channel given was null");
|
||||
m_allocatedChannel = allocatedChannel;
|
||||
m_analogChannel = channel;
|
||||
initAccelerometer();
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ import static java.util.Objects.requireNonNull;
|
||||
public class AnalogGyro extends GyroBase implements Gyro, PIDSource, Sendable {
|
||||
private static final double kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
protected AnalogInput m_analog;
|
||||
private boolean m_channelAllocated = false;
|
||||
private boolean m_channelAllocated;
|
||||
|
||||
private int m_gyroHandle = 0;
|
||||
private int m_gyroHandle;
|
||||
|
||||
/**
|
||||
* Initialize the gyro. Calibration is handled by calibrate().
|
||||
|
||||
@@ -41,8 +41,8 @@ public class AnalogTrigger extends SendableBase {
|
||||
*/
|
||||
protected int m_port;
|
||||
protected int m_index;
|
||||
protected AnalogInput m_analogInput = null;
|
||||
protected boolean m_ownsAnalog = false;
|
||||
protected AnalogInput m_analogInput;
|
||||
protected boolean m_ownsAnalog;
|
||||
|
||||
/**
|
||||
* Constructor for an analog trigger given a channel number.
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CAN implements Closeable {
|
||||
public static final int kTeamManufacturer = 8;
|
||||
public static final int kTeamDeviceType = 10;
|
||||
|
||||
private int m_handle;
|
||||
private final int m_handle;
|
||||
|
||||
/**
|
||||
* Create a new CAN communication interface with the specific device ID.
|
||||
|
||||
@@ -14,10 +14,10 @@ public class CircularBuffer {
|
||||
private double[] m_data;
|
||||
|
||||
// Index of element at front of buffer
|
||||
private int m_front = 0;
|
||||
private int m_front;
|
||||
|
||||
// Number of elements used in buffer
|
||||
private int m_length = 0;
|
||||
private int m_length;
|
||||
|
||||
/**
|
||||
* Create a CircularBuffer with the provided size.
|
||||
|
||||
@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.hal.PowerJNI;
|
||||
* @deprecated Use RobotController class instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class ControllerPower {
|
||||
public final class ControllerPower {
|
||||
/**
|
||||
* Get the input voltage to the robot controller.
|
||||
*
|
||||
@@ -157,4 +157,7 @@ public class ControllerPower {
|
||||
public static int getFaultCount6V() {
|
||||
return PowerJNI.getUserCurrentFaults6V();
|
||||
}
|
||||
|
||||
private ControllerPower() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
|
||||
requireNonNull(downSource, "Down Source given was null");
|
||||
|
||||
if (encodingType != EncodingType.k1X && encodingType != EncodingType.k2X) {
|
||||
throw new RuntimeException("Counters only support 1X and 2X quadrature decoding!");
|
||||
throw new IllegalArgumentException("Counters only support 1X and 2X quadrature decoding!");
|
||||
}
|
||||
|
||||
setUpSource(upSource);
|
||||
@@ -253,7 +253,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
|
||||
*/
|
||||
public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) {
|
||||
if (m_upSource == null) {
|
||||
throw new RuntimeException("Up Source must be set before setting the edge!");
|
||||
throw new IllegalStateException("Up Source must be set before setting the edge!");
|
||||
}
|
||||
CounterJNI.setCounterUpSourceEdge(m_counter, risingEdge, fallingEdge);
|
||||
}
|
||||
@@ -528,6 +528,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
|
||||
*
|
||||
* @param pidSource An enum to select the parameter.
|
||||
*/
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {
|
||||
requireNonNull(pidSource, "PID Source Parameter given was null");
|
||||
if (pidSource != PIDSourceType.kDisplacement && pidSource != PIDSourceType.kRate) {
|
||||
@@ -537,6 +538,7 @@ public class Counter extends SendableBase implements CounterBase, PIDSource {
|
||||
m_pidSource = pidSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return m_pidSource;
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ public class DigitalGlitchFilter extends SendableBase {
|
||||
/ (long) (SensorUtil.kSystemClockTicksPerMicrosecond / 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter")
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
* for devices like switches etc. that aren't implemented anywhere else.
|
||||
*/
|
||||
public class DigitalInput extends DigitalSource {
|
||||
private int m_channel = 0;
|
||||
private int m_handle = 0;
|
||||
private final int m_channel;
|
||||
private int m_handle;
|
||||
|
||||
/**
|
||||
* Create an instance of a Digital Input class. Creates a digital input given a channel.
|
||||
@@ -43,8 +43,8 @@ public class DigitalInput extends DigitalSource {
|
||||
if (m_interrupt != 0) {
|
||||
cancelInterrupts();
|
||||
}
|
||||
|
||||
DIOJNI.freeDIOPort(m_handle);
|
||||
m_handle = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,8 +20,8 @@ public class DigitalOutput extends SendableBase {
|
||||
private static final int invalidPwmGenerator = 0;
|
||||
private int m_pwmGenerator = invalidPwmGenerator;
|
||||
|
||||
private int m_channel = 0;
|
||||
private int m_handle = 0;
|
||||
private final int m_channel;
|
||||
private int m_handle;
|
||||
|
||||
/**
|
||||
* Create an instance of a digital output. Create an instance of a digital output given a
|
||||
|
||||
@@ -31,8 +31,8 @@ public class DoubleSolenoid extends SolenoidBase {
|
||||
|
||||
private byte m_forwardMask; // The mask for the forward channel.
|
||||
private byte m_reverseMask; // The mask for the reverse channel.
|
||||
private int m_forwardHandle = 0;
|
||||
private int m_reverseHandle = 0;
|
||||
private int m_forwardHandle;
|
||||
private int m_reverseHandle;
|
||||
|
||||
/**
|
||||
* Constructor. Uses the default PCM ID (defaults to 0).
|
||||
|
||||
@@ -25,6 +25,9 @@ import edu.wpi.first.wpilibj.hal.PowerJNI;
|
||||
/**
|
||||
* Provide access to the network communication data to / from the Driver Station.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.ExcessiveClassLength",
|
||||
"PMD.ExcessivePublicCount", "PMD.GodClass", "PMD.TooManyFields",
|
||||
"PMD.TooManyMethods"})
|
||||
public class DriverStation implements RobotState.Interface {
|
||||
/**
|
||||
* Number of Joystick Ports.
|
||||
@@ -66,15 +69,16 @@ public class DriverStation implements RobotState.Interface {
|
||||
}
|
||||
|
||||
private static final double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0;
|
||||
private double m_nextMessageTime = 0.0;
|
||||
private double m_nextMessageTime;
|
||||
|
||||
private static class DriverStationTask implements Runnable {
|
||||
private DriverStation m_ds;
|
||||
private final DriverStation m_ds;
|
||||
|
||||
DriverStationTask(DriverStation ds) {
|
||||
m_ds = ds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
m_ds.run();
|
||||
}
|
||||
@@ -144,12 +148,13 @@ public class DriverStation implements RobotState.Interface {
|
||||
private int[] m_joystickButtonsReleased = new int[kJoystickPorts];
|
||||
|
||||
// preallocated byte buffer for button count
|
||||
private ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
|
||||
private final ByteBuffer m_buttonCountBuffer = ByteBuffer.allocateDirect(1);
|
||||
|
||||
private MatchDataSender m_matchDataSender;
|
||||
private final MatchDataSender m_matchDataSender;
|
||||
|
||||
// Internal Driver Station thread
|
||||
private Thread m_thread;
|
||||
@SuppressWarnings("PMD.SingularField")
|
||||
private final Thread m_thread;
|
||||
private volatile boolean m_threadKeepAlive = true;
|
||||
|
||||
private final ReentrantLock m_cacheDataMutex = new ReentrantLock();
|
||||
@@ -159,14 +164,14 @@ public class DriverStation implements RobotState.Interface {
|
||||
private int m_waitForDataCount;
|
||||
|
||||
// Robot state status variables
|
||||
private boolean m_userInDisabled = false;
|
||||
private boolean m_userInAutonomous = false;
|
||||
private boolean m_userInTeleop = false;
|
||||
private boolean m_userInTest = false;
|
||||
private boolean m_userInDisabled;
|
||||
private boolean m_userInAutonomous;
|
||||
private boolean m_userInTeleop;
|
||||
private boolean m_userInTest;
|
||||
|
||||
// Control word variables
|
||||
private final Object m_controlWordMutex;
|
||||
private ControlWord m_controlWordCache;
|
||||
private final ControlWord m_controlWordCache;
|
||||
private long m_lastControlWordUpdate;
|
||||
|
||||
/**
|
||||
@@ -184,6 +189,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
* <p>The single DriverStation instance is created statically with the instance static member
|
||||
* variable.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
||||
private DriverStation() {
|
||||
HAL.initialize(500, 0);
|
||||
m_waitForDataCount = 0;
|
||||
@@ -277,12 +283,12 @@ public class DriverStation implements RobotState.Interface {
|
||||
} else {
|
||||
locString = "";
|
||||
}
|
||||
String traceString = "";
|
||||
StringBuilder traceString = new StringBuilder("");
|
||||
if (printTrace) {
|
||||
boolean haveLoc = false;
|
||||
for (int i = stackTraceFirst; i < stackTrace.length; i++) {
|
||||
String loc = stackTrace[i].toString();
|
||||
traceString += "\tat " + loc + "\n";
|
||||
traceString.append("\tat ").append(loc).append('\n');
|
||||
// get first user function
|
||||
if (!haveLoc && !loc.startsWith("edu.wpi.first")) {
|
||||
locString = loc;
|
||||
@@ -290,7 +296,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
}
|
||||
}
|
||||
}
|
||||
HAL.sendError(isError, code, false, error, locString, traceString, true);
|
||||
HAL.sendError(isError, code, false, error, locString, traceString.toString(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +308,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public boolean getStickButton(final int stick, final int button) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
if (button <= 0) {
|
||||
reportJoystickUnpluggedError("Button indexes begin at 1 in WPILib for C++ and Java\n");
|
||||
@@ -338,7 +344,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
return false;
|
||||
}
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
boolean error = false;
|
||||
boolean retVal = false;
|
||||
@@ -377,7 +383,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
return false;
|
||||
}
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
boolean error = false;
|
||||
boolean retVal = false;
|
||||
@@ -412,10 +418,10 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public double getStickAxis(int stick, int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
if (axis >= HAL.kMaxJoystickAxes) {
|
||||
throw new RuntimeException("Joystick axis is out of range");
|
||||
throw new IllegalArgumentException("Joystick axis is out of range");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -443,10 +449,10 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getStickPOV(int stick, int pov) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
if (pov >= HAL.kMaxJoystickPOVs) {
|
||||
throw new RuntimeException("Joystick POV is out of range");
|
||||
throw new IllegalArgumentException("Joystick POV is out of range");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -474,7 +480,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getStickButtons(final int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-3");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-3");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -493,7 +499,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getStickAxisCount(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -512,7 +518,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getStickPOVCount(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -531,7 +537,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getStickButtonCount(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -550,7 +556,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public boolean getJoystickIsXbox(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -569,7 +575,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getJoystickType(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -588,7 +594,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public String getJoystickName(int stick) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -608,7 +614,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*/
|
||||
public int getJoystickAxisType(int stick, int axis) {
|
||||
if (stick < 0 || stick >= kJoystickPorts) {
|
||||
throw new RuntimeException("Joystick index is out of range, should be 0-5");
|
||||
throw new IllegalArgumentException("Joystick index is out of range, should be 0-5");
|
||||
}
|
||||
|
||||
m_cacheDataMutex.lock();
|
||||
@@ -624,6 +630,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*
|
||||
* @return True if the robot is enabled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
synchronized (m_controlWordMutex) {
|
||||
updateControlWord(false);
|
||||
@@ -636,6 +643,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*
|
||||
* @return True if the robot should be disabled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
return !isEnabled();
|
||||
}
|
||||
@@ -646,6 +654,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*
|
||||
* @return True if autonomous mode should be enabled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAutonomous() {
|
||||
synchronized (m_controlWordMutex) {
|
||||
updateControlWord(false);
|
||||
@@ -659,6 +668,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*
|
||||
* @return True if operator-controlled mode should be enabled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isOperatorControl() {
|
||||
return !(isAutonomous() || isTest());
|
||||
}
|
||||
@@ -669,6 +679,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
*
|
||||
* @return True if test mode should be enabled, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTest() {
|
||||
synchronized (m_controlWordMutex) {
|
||||
updateControlWord(false);
|
||||
@@ -1139,7 +1150,8 @@ public class DriverStation implements RobotState.Interface {
|
||||
safetyCounter = 0;
|
||||
}
|
||||
|
||||
if (++safetyCounter >= 4) {
|
||||
safetyCounter++;
|
||||
if (safetyCounter >= 4) {
|
||||
MotorSafetyHelper.checkMotors();
|
||||
safetyCounter = 0;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
/**
|
||||
* The index source.
|
||||
*/
|
||||
protected DigitalSource m_indexSource = null; // Index on some encoders
|
||||
protected DigitalSource m_indexSource; // Index on some encoders
|
||||
private boolean m_allocatedA;
|
||||
private boolean m_allocatedB;
|
||||
private boolean m_allocatedI;
|
||||
@@ -329,6 +329,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
*
|
||||
* @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale factor.
|
||||
*/
|
||||
@Override
|
||||
public int get() {
|
||||
return EncoderJNI.getEncoder(m_encoder);
|
||||
}
|
||||
@@ -336,6 +337,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
/**
|
||||
* Reset the Encoder distance to zero. Resets the current count to zero on the encoder.
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
EncoderJNI.resetEncoder(m_encoder);
|
||||
}
|
||||
@@ -350,6 +352,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
* @return Period in seconds of the most recent pulse.
|
||||
* @deprecated Use getRate() in favor of this method.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public double getPeriod() {
|
||||
return EncoderJNI.getEncoderPeriod(m_encoder);
|
||||
@@ -364,6 +367,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
* @param maxPeriod The maximum time between rising and falling edges before the FPGA will report
|
||||
* the device stopped. This is expressed in seconds.
|
||||
*/
|
||||
@Override
|
||||
public void setMaxPeriod(double maxPeriod) {
|
||||
EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod);
|
||||
}
|
||||
@@ -375,6 +379,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
*
|
||||
* @return True if the encoder is considered stopped.
|
||||
*/
|
||||
@Override
|
||||
public boolean getStopped() {
|
||||
return EncoderJNI.getEncoderStopped(m_encoder);
|
||||
}
|
||||
@@ -384,6 +389,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
*
|
||||
* @return The last direction the encoder value changed.
|
||||
*/
|
||||
@Override
|
||||
public boolean getDirection() {
|
||||
return EncoderJNI.getEncoderDirection(m_encoder);
|
||||
}
|
||||
@@ -478,6 +484,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
*
|
||||
* @param pidSource An enum to select the parameter.
|
||||
*/
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {
|
||||
m_pidSource = pidSource;
|
||||
}
|
||||
@@ -492,6 +499,7 @@ public class Encoder extends SendableBase implements CounterBase, PIDSource {
|
||||
*
|
||||
* @return The current value of the selected source parameter.
|
||||
*/
|
||||
@Override
|
||||
public double pidGet() {
|
||||
switch (m_pidSource) {
|
||||
case kDisplacement:
|
||||
|
||||
@@ -18,6 +18,7 @@ public abstract class GamepadBase extends GenericHID {
|
||||
super(port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract double getRawAxis(int axis);
|
||||
|
||||
/**
|
||||
@@ -43,19 +44,27 @@ public abstract class GamepadBase extends GenericHID {
|
||||
return getStickButton(Hand.kRight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean getRawButton(int button);
|
||||
|
||||
@Override
|
||||
public abstract int getPOV(int pov);
|
||||
|
||||
@Override
|
||||
public abstract int getPOVCount();
|
||||
|
||||
@Override
|
||||
public abstract HIDType getType();
|
||||
|
||||
@Override
|
||||
public abstract String getName();
|
||||
|
||||
@Override
|
||||
public abstract void setOutput(int outputNumber, boolean value);
|
||||
|
||||
@Override
|
||||
public abstract void setOutputs(int value);
|
||||
|
||||
@Override
|
||||
public abstract void setRumble(RumbleType type, double value);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public abstract class GenericHID {
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int value;
|
||||
@SuppressWarnings("PMD.UseConcurrentHashMap")
|
||||
private static final Map<Integer, HIDType> map = new HashMap<>();
|
||||
|
||||
HIDType(int value) {
|
||||
@@ -57,7 +58,7 @@ public abstract class GenericHID {
|
||||
}
|
||||
|
||||
public static HIDType of(int value) {
|
||||
return (HIDType) map.get(value);
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
|
||||
* Support for high level usage reporting.
|
||||
*/
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
public class HLUsageReporting {
|
||||
public final class HLUsageReporting {
|
||||
private static Interface impl;
|
||||
|
||||
@SuppressWarnings("MethodName")
|
||||
@@ -54,14 +54,20 @@ public class HLUsageReporting {
|
||||
}
|
||||
|
||||
public static class Null implements Interface {
|
||||
@Override
|
||||
public void reportScheduler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter")
|
||||
public void reportPIDController(int num) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportSmartDashboard() {
|
||||
}
|
||||
}
|
||||
|
||||
private HLUsageReporting() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import static java.util.Objects.requireNonNull;
|
||||
* <p>This class is intended to be used by sensor (and other I2C device) drivers. It probably should
|
||||
* not be used directly.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"})
|
||||
public class I2C implements AutoCloseable {
|
||||
public enum Port {
|
||||
kOnboard(0), kMXP(1);
|
||||
@@ -99,6 +100,7 @@ public class I2C implements AutoCloseable {
|
||||
* @param receiveSize Number of bytes to read from the device.
|
||||
* @return Transfer Aborted... false for success, true for aborted.
|
||||
*/
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
public synchronized boolean transaction(ByteBuffer dataToSend, int sendSize,
|
||||
ByteBuffer dataReceived, int receiveSize) {
|
||||
if (dataToSend.hasArray() && dataReceived.hasArray()) {
|
||||
@@ -231,7 +233,7 @@ public class I2C implements AutoCloseable {
|
||||
return transaction(registerAddressArray, registerAddressArray.length, buffer, count);
|
||||
}
|
||||
|
||||
private ByteBuffer m_readDataToSendBuffer = null;
|
||||
private ByteBuffer m_readDataToSendBuffer;
|
||||
|
||||
/**
|
||||
* Execute a read transaction with the device.
|
||||
@@ -352,12 +354,11 @@ public class I2C implements AutoCloseable {
|
||||
byte[] dataToSend = new byte[1];
|
||||
|
||||
byte[] deviceData = new byte[4];
|
||||
for (int i = 0, curRegisterAddress = registerAddress;
|
||||
i < count; i += 4, curRegisterAddress += 4) {
|
||||
for (int i = 0; i < count; i += 4) {
|
||||
int toRead = count - i < 4 ? count - i : 4;
|
||||
// Read the chunk of data. Return false if the sensor does not
|
||||
// respond.
|
||||
dataToSend[0] = (byte) curRegisterAddress;
|
||||
dataToSend[0] = (byte) (registerAddress + i);
|
||||
if (transaction(dataToSend, 1, deviceData, toRead)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
/**
|
||||
* Base for sensors to be used with interrupts.
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public abstract class InterruptableSensorBase extends SendableBase {
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
public enum WaitResult {
|
||||
@@ -35,7 +36,7 @@ public abstract class InterruptableSensorBase extends SendableBase {
|
||||
/**
|
||||
* Flags if the interrupt being allocated is synchronous.
|
||||
*/
|
||||
protected boolean m_isSynchronousInterrupt = false;
|
||||
protected boolean m_isSynchronousInterrupt;
|
||||
|
||||
/**
|
||||
* Create a new InterrupatableSensorBase.
|
||||
|
||||
@@ -27,6 +27,7 @@ public class IterativeRobot extends IterativeRobotBase {
|
||||
/**
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
@Override
|
||||
public void startCompetition() {
|
||||
robotInit();
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
* - teleopPeriodic()
|
||||
* - testPeriodic()
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public abstract class IterativeRobotBase extends RobotBase {
|
||||
private enum Mode {
|
||||
kNone,
|
||||
@@ -54,6 +55,7 @@ public abstract class IterativeRobotBase extends RobotBase {
|
||||
/**
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
@Override
|
||||
public abstract void startCompetition();
|
||||
|
||||
/* ----------- Overridable initialization code ----------------- */
|
||||
|
||||
@@ -21,6 +21,7 @@ public interface NamedSendable extends Sendable {
|
||||
*
|
||||
* @return the name of the subtable of SmartDashboard that the Sendable object will use.
|
||||
*/
|
||||
@Override
|
||||
String getName();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,11 +16,11 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
*/
|
||||
public class NidecBrushless extends SendableBase implements SpeedController, MotorSafety, Sendable {
|
||||
private final MotorSafetyHelper m_safetyHelper;
|
||||
private boolean m_isInverted = false;
|
||||
private DigitalOutput m_dio;
|
||||
private PWM m_pwm;
|
||||
private volatile double m_speed = 0.0;
|
||||
private volatile boolean m_disabled = false;
|
||||
private boolean m_isInverted;
|
||||
private final DigitalOutput m_dio;
|
||||
private final PWM m_pwm;
|
||||
private volatile double m_speed;
|
||||
private volatile boolean m_disabled;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -22,15 +22,15 @@ public class Notifier implements AutoCloseable {
|
||||
private final AtomicInteger m_notifier = new AtomicInteger();
|
||||
// The time, in microseconds, at which the corresponding handler should be
|
||||
// called. Has the same zero as Utility.getFPGATime().
|
||||
private double m_expirationTime = 0;
|
||||
private double m_expirationTime;
|
||||
// The handler passed in by the user which should be called at the
|
||||
// appropriate interval.
|
||||
private Runnable m_handler;
|
||||
// Whether we are calling the handler just once or periodically.
|
||||
private boolean m_periodic = false;
|
||||
private boolean m_periodic;
|
||||
// If periodic, the period of the calling; if just once, stores how long it
|
||||
// is until we call the handler.
|
||||
private double m_period = 0;
|
||||
private double m_period;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NoFinalizer")
|
||||
|
||||
@@ -25,9 +25,10 @@ import static java.util.Objects.requireNonNull;
|
||||
* and derivative calculations. Therefore, the sample rate affects the controller's behavior for a
|
||||
* given set of PID constants.
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyFields")
|
||||
public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
public static final double kDefaultPeriod = 0.05;
|
||||
private static int instances = 0;
|
||||
private static int instances;
|
||||
|
||||
// Factor for "proportional" control
|
||||
@SuppressWarnings("MemberName")
|
||||
@@ -52,34 +53,34 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
private double m_minimumOutput = -1.0;
|
||||
|
||||
// Maximum input - limit setpoint to this
|
||||
private double m_maximumInput = 0.0;
|
||||
private double m_maximumInput;
|
||||
|
||||
// Minimum input - limit setpoint to this
|
||||
private double m_minimumInput = 0.0;
|
||||
private double m_minimumInput;
|
||||
|
||||
// Input range - difference between maximum and minimum
|
||||
private double m_inputRange = 0.0;
|
||||
private double m_inputRange;
|
||||
|
||||
// Do the endpoints wrap around? (e.g., absolute encoder)
|
||||
private boolean m_continuous = false;
|
||||
private boolean m_continuous;
|
||||
|
||||
// Is the PID controller enabled
|
||||
protected boolean m_enabled = false;
|
||||
protected boolean m_enabled;
|
||||
|
||||
// The prior error (used to compute velocity)
|
||||
private double m_prevError = 0.0;
|
||||
private double m_prevError;
|
||||
|
||||
// The sum of the errors for use in the integral calc
|
||||
private double m_totalError = 0.0;
|
||||
private double m_totalError;
|
||||
|
||||
// The tolerance object used to check if on target
|
||||
private Tolerance m_tolerance;
|
||||
|
||||
private double m_setpoint = 0.0;
|
||||
private double m_prevSetpoint = 0.0;
|
||||
private double m_setpoint;
|
||||
private double m_prevSetpoint;
|
||||
@SuppressWarnings("PMD.UnusedPrivateField")
|
||||
private double m_error = 0.0;
|
||||
private double m_result = 0.0;
|
||||
private double m_error;
|
||||
private double m_result;
|
||||
|
||||
private PIDSource m_origSource;
|
||||
private LinearDigitalFilter m_filter;
|
||||
@@ -110,7 +111,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
public class NullTolerance implements Tolerance {
|
||||
@Override
|
||||
public boolean onTarget() {
|
||||
throw new RuntimeException("No tolerance value set when calling onTarget().");
|
||||
throw new IllegalStateException("No tolerance value set when calling onTarget().");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +199,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
* Read the input, calculate the output accordingly, and write to the output. This should only be
|
||||
* called by the PIDTask and is created during initialization.
|
||||
*/
|
||||
@SuppressWarnings("LocalVariableName")
|
||||
@SuppressWarnings({"LocalVariableName", "PMD.ExcessiveMethodLength", "PMD.NPathComplexity"})
|
||||
protected void calculate() {
|
||||
if (m_origSource == null || m_pidOutput == null) {
|
||||
return;
|
||||
@@ -334,6 +335,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
* @param i Integral coefficient
|
||||
* @param d Differential coefficient
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("ParameterName")
|
||||
public void setPID(double p, double i, double d) {
|
||||
m_thisMutex.lock();
|
||||
@@ -433,6 +435,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*
|
||||
* @return proportional coefficient
|
||||
*/
|
||||
@Override
|
||||
public double getP() {
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
@@ -447,6 +450,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*
|
||||
* @return integral coefficient
|
||||
*/
|
||||
@Override
|
||||
public double getI() {
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
@@ -461,6 +465,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*
|
||||
* @return differential coefficient
|
||||
*/
|
||||
@Override
|
||||
public double getD() {
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
@@ -508,7 +513,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*/
|
||||
public void setContinuous(boolean continuous) {
|
||||
if (continuous && m_inputRange <= 0) {
|
||||
throw new RuntimeException("No input range set when calling setContinuous().");
|
||||
throw new IllegalStateException("No input range set when calling setContinuous().");
|
||||
}
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
@@ -573,6 +578,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*
|
||||
* @param setpoint the desired setpoint
|
||||
*/
|
||||
@Override
|
||||
public void setSetpoint(double setpoint) {
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
@@ -597,6 +603,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*
|
||||
* @return the current setpoint
|
||||
*/
|
||||
@Override
|
||||
public double getSetpoint() {
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
@@ -625,6 +632,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
|
||||
*
|
||||
* @return the current error
|
||||
*/
|
||||
@Override
|
||||
public double getError() {
|
||||
m_thisMutex.lock();
|
||||
try {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PWM extends SendableBase {
|
||||
k4X
|
||||
}
|
||||
|
||||
private int m_channel;
|
||||
private final int m_channel;
|
||||
private int m_handle;
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
* Common base class for all PWM Speed Controllers.
|
||||
*/
|
||||
public abstract class PWMSpeedController extends SafePWM implements SpeedController {
|
||||
private boolean m_isInverted = false;
|
||||
private boolean m_isInverted;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -31,7 +31,7 @@ import static java.util.Objects.requireNonNull;
|
||||
* <p> This will also interact with {@link NetworkTable} by creating a table called "Preferences"
|
||||
* with all the key-value pairs. </p>
|
||||
*/
|
||||
public class Preferences {
|
||||
public final class Preferences {
|
||||
/**
|
||||
* The Preferences table name.
|
||||
*/
|
||||
@@ -75,6 +75,7 @@ public class Preferences {
|
||||
* Gets the vector of keys.
|
||||
* @return a vector of the keys
|
||||
*/
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
public Vector<String> getKeys() {
|
||||
return new Vector<>(m_table.getKeys());
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ public class Relay extends SendableBase implements MotorSafety {
|
||||
|
||||
private final int m_channel;
|
||||
|
||||
private int m_forwardHandle = 0;
|
||||
private int m_reverseHandle = 0;
|
||||
private int m_forwardHandle;
|
||||
private int m_reverseHandle;
|
||||
|
||||
private Direction m_direction;
|
||||
|
||||
@@ -150,12 +150,12 @@ public class Relay extends SendableBase implements MotorSafety {
|
||||
private void freeRelay() {
|
||||
try {
|
||||
RelayJNI.setRelay(m_forwardHandle, false);
|
||||
} catch (UncleanStatusException ex) {
|
||||
} catch (UncleanStatusException ignored) {
|
||||
// do nothing. Ignore
|
||||
}
|
||||
try {
|
||||
RelayJNI.setRelay(m_reverseHandle, false);
|
||||
} catch (UncleanStatusException ex) {
|
||||
} catch (UncleanStatusException ignored) {
|
||||
// do nothing. Ignore
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ public class Relay extends SendableBase implements MotorSafety {
|
||||
*
|
||||
* @param value The state to set the relay.
|
||||
*/
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
public void set(Value value) {
|
||||
switch (value) {
|
||||
case kOff:
|
||||
|
||||
@@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
* unload/reload.
|
||||
*/
|
||||
public final class Resource {
|
||||
private static Resource resourceList = null;
|
||||
private static Resource resourceList;
|
||||
private final boolean[] m_numAllocated;
|
||||
private final int m_size;
|
||||
private final Resource m_nextResource;
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
@@ -188,9 +189,9 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
if (propVal == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (propVal.equalsIgnoreCase("false")) {
|
||||
if ("false".equalsIgnoreCase(propVal)) {
|
||||
return false;
|
||||
} else if (propVal.equalsIgnoreCase("true")) {
|
||||
} else if ("true".equalsIgnoreCase(propVal)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new IllegalStateException(propVal);
|
||||
@@ -218,7 +219,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
/**
|
||||
* Starting point for the applications.
|
||||
*/
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter")
|
||||
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable",
|
||||
"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
|
||||
public static void main(String... args) {
|
||||
if (!HAL.initialize(500, 0)) {
|
||||
throw new IllegalStateException("Failed to initialize. Terminating");
|
||||
@@ -232,7 +234,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
} else {
|
||||
Enumeration<URL> resources = null;
|
||||
try {
|
||||
resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
|
||||
resources = Thread.currentThread()
|
||||
.getContextClassLoader().getResources("META-INF/MANIFEST.MF");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -273,7 +276,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
|
||||
file.createNewFile();
|
||||
|
||||
try (FileOutputStream output = new FileOutputStream(file)) {
|
||||
try (OutputStream output = Files.newOutputStream(file.toPath())) {
|
||||
output.write("Java ".getBytes());
|
||||
output.write(WPILibVersion.Version.getBytes());
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import static java.util.Objects.requireNonNull;
|
||||
* or {@link edu.wpi.first.wpilibj.drive.MecanumDrive} classes instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings({"PMD.GodClass", "PMD.TooManyMethods"})
|
||||
public class RobotDrive implements MotorSafety, AutoCloseable {
|
||||
protected MotorSafetyHelper m_safetyHelper;
|
||||
|
||||
@@ -53,11 +54,11 @@ public class RobotDrive implements MotorSafety, AutoCloseable {
|
||||
protected SpeedController m_rearLeftMotor;
|
||||
protected SpeedController m_rearRightMotor;
|
||||
protected boolean m_allocatedSpeedControllers;
|
||||
protected static boolean kArcadeRatioCurve_Reported = false;
|
||||
protected static boolean kTank_Reported = false;
|
||||
protected static boolean kArcadeStandard_Reported = false;
|
||||
protected static boolean kMecanumCartesian_Reported = false;
|
||||
protected static boolean kMecanumPolar_Reported = false;
|
||||
protected static boolean kArcadeRatioCurve_Reported;
|
||||
protected static boolean kTank_Reported;
|
||||
protected static boolean kArcadeStandard_Reported;
|
||||
protected static boolean kMecanumCartesian_Reported;
|
||||
protected static boolean kMecanumPolar_Reported;
|
||||
|
||||
/**
|
||||
* Constructor for RobotDrive with 2 motors specified with channel numbers. Set up parameters for
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.wpilibj;
|
||||
import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
|
||||
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
public class RobotState {
|
||||
public final class RobotState {
|
||||
private static Interface m_impl;
|
||||
|
||||
@SuppressWarnings("MethodName")
|
||||
@@ -69,4 +69,7 @@ public class RobotState {
|
||||
|
||||
boolean isTest();
|
||||
}
|
||||
|
||||
private RobotState() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import edu.wpi.first.wpilibj.hal.SPIJNI;
|
||||
/**
|
||||
* Represents a SPI bus port.
|
||||
*/
|
||||
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.TooManyMethods"})
|
||||
public class SPI implements AutoCloseable {
|
||||
public enum Port {
|
||||
kOnboardCS0(0), kOnboardCS1(1), kOnboardCS2(2), kOnboardCS3(3), kMXP(4);
|
||||
@@ -28,7 +29,7 @@ public class SPI implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private static int devices = 0;
|
||||
private static int devices;
|
||||
|
||||
private int m_port;
|
||||
private int m_bitOrder;
|
||||
@@ -268,6 +269,7 @@ public class SPI implements AutoCloseable {
|
||||
* @param dataReceived Buffer to receive data from the device.
|
||||
* @param size The length of the transaction, in bytes
|
||||
*/
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
public int transaction(ByteBuffer dataToSend, ByteBuffer dataReceived, int size) {
|
||||
if (dataToSend.hasArray() && dataReceived.hasArray()) {
|
||||
return transaction(dataToSend.array(), dataReceived.array(), size);
|
||||
@@ -420,6 +422,7 @@ public class SPI implements AutoCloseable {
|
||||
|
||||
private static final int kAccumulateDepth = 2048;
|
||||
|
||||
@SuppressWarnings("PMD.TooManyFields")
|
||||
private static class Accumulator implements AutoCloseable {
|
||||
Accumulator(int port, int xferSize, int validMask, int validValue, int dataShift,
|
||||
int dataSize, boolean isSigned, boolean bigEndian) {
|
||||
@@ -462,6 +465,7 @@ public class SPI implements AutoCloseable {
|
||||
final boolean m_bigEndian; // is response big endian?
|
||||
final int m_port;
|
||||
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
void update() {
|
||||
synchronized (m_mutex) {
|
||||
boolean done = false;
|
||||
@@ -527,7 +531,7 @@ public class SPI implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private Accumulator m_accum = null;
|
||||
private Accumulator m_accum;
|
||||
|
||||
/**
|
||||
* Initialize the accumulator.
|
||||
|
||||
@@ -32,6 +32,7 @@ public class SafePWM extends PWM implements MotorSafety {
|
||||
*
|
||||
* @param timeout The timeout (in seconds) for this motor object
|
||||
*/
|
||||
@Override
|
||||
public void setExpiration(double timeout) {
|
||||
m_safetyHelper.setExpiration(timeout);
|
||||
}
|
||||
@@ -41,6 +42,7 @@ public class SafePWM extends PWM implements MotorSafety {
|
||||
*
|
||||
* @return The expiration time value.
|
||||
*/
|
||||
@Override
|
||||
public double getExpiration() {
|
||||
return m_safetyHelper.getExpiration();
|
||||
}
|
||||
@@ -50,6 +52,7 @@ public class SafePWM extends PWM implements MotorSafety {
|
||||
*
|
||||
* @return a bool value that is true if the motor has NOT timed out and should still be running.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
return m_safetyHelper.isAlive();
|
||||
}
|
||||
@@ -58,6 +61,7 @@ public class SafePWM extends PWM implements MotorSafety {
|
||||
* Stop the motor associated with this PWM object. This is called by the MotorSafetyHelper object
|
||||
* when it has a timeout for this PWM and needs to stop it from running.
|
||||
*/
|
||||
@Override
|
||||
public void stopMotor() {
|
||||
disable();
|
||||
}
|
||||
@@ -67,6 +71,7 @@ public class SafePWM extends PWM implements MotorSafety {
|
||||
*
|
||||
* @return True if motor safety is enforced for this object
|
||||
*/
|
||||
@Override
|
||||
public boolean isSafetyEnabled() {
|
||||
return m_safetyHelper.isSafetyEnabled();
|
||||
}
|
||||
@@ -91,10 +96,12 @@ public class SafePWM extends PWM implements MotorSafety {
|
||||
m_safetyHelper.feed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSafetyEnabled(boolean enabled) {
|
||||
m_safetyHelper.setSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "PWM " + getChannel();
|
||||
}
|
||||
|
||||
@@ -114,6 +114,8 @@ public class SampleRobot extends RobotBase {
|
||||
* state to change, either the other mode starts or the robot is disabled. Then go back and wait
|
||||
* for the robot to be enabled again.
|
||||
*/
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
@Override
|
||||
public void startCompetition() {
|
||||
robotInit();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import edu.wpi.first.wpilibj.hal.SerialPortJNI;
|
||||
* .com/pdf/manuals/370423a.pdf and the NI-VISA Programmer's Reference Manual here:
|
||||
* http://www.ni.com/pdf/manuals/370132c.pdf
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public class SerialPort implements AutoCloseable {
|
||||
private byte m_port;
|
||||
|
||||
|
||||
@@ -13,15 +13,16 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
* Allows multiple {@link SpeedController} objects to be linked together.
|
||||
*/
|
||||
public class SpeedControllerGroup extends SendableBase implements SpeedController {
|
||||
private boolean m_isInverted = false;
|
||||
private boolean m_isInverted;
|
||||
private final SpeedController[] m_speedControllers;
|
||||
private static int instances = 0;
|
||||
private static int instances;
|
||||
|
||||
/**
|
||||
* Create a new SpeedControllerGroup with the provided SpeedControllers.
|
||||
*
|
||||
* @param speedControllers The SpeedControllers to add
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidArrayLoops")
|
||||
public SpeedControllerGroup(SpeedController speedController,
|
||||
SpeedController... speedControllers) {
|
||||
m_speedControllers = new SpeedController[speedControllers.length + 1];
|
||||
|
||||
@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.ThreadsJNI;
|
||||
|
||||
public class Threads {
|
||||
public final class Threads {
|
||||
/**
|
||||
* Get the thread priority for the current thread.
|
||||
* @return The current thread priority. Scaled 1-99.
|
||||
@@ -39,4 +39,7 @@ public class Threads {
|
||||
public static boolean setCurrentThreadPriority(boolean realTime, int priority) {
|
||||
return ThreadsJNI.setCurrentThreadPriority(realTime, priority);
|
||||
}
|
||||
|
||||
private Threads() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
public static final double kDefaultPeriod = 0.02;
|
||||
|
||||
// Prevents loop from starting if user calls setPeriod() in robotInit()
|
||||
private boolean m_startLoop = false;
|
||||
private boolean m_startLoop;
|
||||
|
||||
// The C pointer to the notifier object. We don't use it directly, it is
|
||||
// just passed to the JNI bindings.
|
||||
private final int m_notifier = NotifierJNI.initializeNotifier();
|
||||
|
||||
// The absolute expiration time
|
||||
private double m_expirationTime = 0;
|
||||
private double m_expirationTime;
|
||||
|
||||
private double m_period = kDefaultPeriod;
|
||||
|
||||
@@ -49,6 +49,7 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
/**
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
@Override
|
||||
public void startCompetition() {
|
||||
robotInit();
|
||||
|
||||
|
||||
@@ -41,19 +41,19 @@ public class Ultrasonic extends SendableBase implements PIDSource {
|
||||
private static final double kPingTime = 10 * 1e-6;
|
||||
private static final double kSpeedOfSoundInchesPerSec = 1130.0 * 12.0;
|
||||
// head of the ultrasonic sensor list
|
||||
private static Ultrasonic m_firstSensor = null;
|
||||
private static Ultrasonic m_firstSensor;
|
||||
// automatic round robin mode
|
||||
private static boolean m_automaticEnabled = false;
|
||||
private static boolean m_automaticEnabled;
|
||||
private DigitalInput m_echoChannel;
|
||||
private DigitalOutput m_pingChannel = null;
|
||||
private DigitalOutput m_pingChannel;
|
||||
private boolean m_allocatedChannels;
|
||||
private boolean m_enabled = false;
|
||||
private Counter m_counter = null;
|
||||
private Ultrasonic m_nextSensor = null;
|
||||
private boolean m_enabled;
|
||||
private Counter m_counter;
|
||||
private Ultrasonic m_nextSensor;
|
||||
// task doing the round-robin automatic sensing
|
||||
private static Thread m_task = null;
|
||||
private static Thread m_task;
|
||||
private Unit m_units;
|
||||
private static int m_instances = 0;
|
||||
private static int m_instances;
|
||||
protected PIDSourceType m_pidSource = PIDSourceType.kDisplacement;
|
||||
|
||||
/**
|
||||
@@ -190,6 +190,7 @@ public class Ultrasonic extends SendableBase implements PIDSource {
|
||||
* stopped, then started again after this sensor is removed (provided this wasn't the last
|
||||
* sensor).
|
||||
*/
|
||||
@SuppressWarnings("PMD.CyclomaticComplexity")
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
super.close();
|
||||
|
||||
@@ -33,7 +33,7 @@ public class XboxController extends GenericHID {
|
||||
kBack(7),
|
||||
kStart(8);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
@SuppressWarnings({"MemberName", "PMD.SingularField"})
|
||||
private int value;
|
||||
|
||||
Button(int value) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class InternalButton extends Button {
|
||||
m_pressed = pressed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean get() {
|
||||
return m_pressed ^ m_inverted;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class JoystickButton extends Button {
|
||||
*
|
||||
* @return The value of the joystick button
|
||||
*/
|
||||
@Override
|
||||
public boolean get() {
|
||||
return m_joystick.getRawButton(m_buttonNumber);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class NetworkButton extends Button {
|
||||
m_entry = table.getEntry(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean get() {
|
||||
return m_entry.getInstance().isConnected() && m_entry.getBoolean(false);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
* the full functionality of the Trigger class.
|
||||
*/
|
||||
public abstract class Trigger extends SendableBase {
|
||||
private volatile boolean m_sendablePressed = false;
|
||||
private volatile boolean m_sendablePressed;
|
||||
|
||||
/**
|
||||
* Returns whether or not the trigger is active.
|
||||
|
||||
@@ -39,6 +39,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
* @see CommandGroup
|
||||
* @see IllegalUseOfCommandException
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public abstract class Command extends SendableBase {
|
||||
/**
|
||||
* The time since this command was initialized.
|
||||
@@ -53,7 +54,7 @@ public abstract class Command extends SendableBase {
|
||||
/**
|
||||
* Whether or not this command has been initialized.
|
||||
*/
|
||||
private boolean m_initialized = false;
|
||||
private boolean m_initialized;
|
||||
|
||||
/**
|
||||
* The required subsystems.
|
||||
@@ -63,7 +64,7 @@ public abstract class Command extends SendableBase {
|
||||
/**
|
||||
* Whether or not it is running.
|
||||
*/
|
||||
private boolean m_running = false;
|
||||
private boolean m_running;
|
||||
|
||||
/**
|
||||
* Whether or not it is interruptible.
|
||||
@@ -73,22 +74,22 @@ public abstract class Command extends SendableBase {
|
||||
/**
|
||||
* Whether or not it has been canceled.
|
||||
*/
|
||||
private boolean m_canceled = false;
|
||||
private boolean m_canceled;
|
||||
|
||||
/**
|
||||
* Whether or not it has been locked.
|
||||
*/
|
||||
private boolean m_locked = false;
|
||||
private boolean m_locked;
|
||||
|
||||
/**
|
||||
* Whether this command should run when the robot is disabled.
|
||||
*/
|
||||
private boolean m_runWhenDisabled = false;
|
||||
private boolean m_runWhenDisabled;
|
||||
|
||||
/**
|
||||
* Whether or not this command has completed running.
|
||||
*/
|
||||
private boolean m_completed = false;
|
||||
private boolean m_completed;
|
||||
|
||||
/**
|
||||
* The {@link CommandGroup} this is in.
|
||||
|
||||
@@ -31,10 +31,12 @@ import static java.util.Objects.requireNonNull;
|
||||
* @see Subsystem
|
||||
* @see IllegalUseOfCommandException
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public class CommandGroup extends Command {
|
||||
/**
|
||||
* The commands in this group (stored in entries).
|
||||
*/
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
private final Vector<Entry> m_commands = new Vector<>();
|
||||
/*
|
||||
* Intentionally package private
|
||||
@@ -42,6 +44,7 @@ public class CommandGroup extends Command {
|
||||
/**
|
||||
* The active children in this group (stored in entries).
|
||||
*/
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
final Vector<Entry> m_children = new Vector<>();
|
||||
/**
|
||||
* The current command, -1 signifies that none have been run.
|
||||
@@ -206,12 +209,14 @@ public class CommandGroup extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MethodName")
|
||||
void _initialize() {
|
||||
m_currentCommandIndex = -1;
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodName")
|
||||
@Override
|
||||
@SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
|
||||
void _execute() {
|
||||
Entry entry = null;
|
||||
Command cmd = null;
|
||||
@@ -278,6 +283,7 @@ public class CommandGroup extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MethodName")
|
||||
void _end() {
|
||||
// Theoretically, we don't have to check this, but we do if teams override
|
||||
@@ -297,6 +303,7 @@ public class CommandGroup extends Command {
|
||||
m_children.removeAllElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MethodName")
|
||||
void _interrupted() {
|
||||
_end();
|
||||
@@ -311,23 +318,28 @@ public class CommandGroup extends Command {
|
||||
*
|
||||
* @return whether this {@link CommandGroup} is finished
|
||||
*/
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return m_currentCommandIndex >= m_commands.size() && m_children.isEmpty();
|
||||
}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void initialize() {
|
||||
}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void execute() {
|
||||
}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void end() {
|
||||
}
|
||||
|
||||
// Can be overwritten by teams
|
||||
@Override
|
||||
protected void interrupted() {
|
||||
}
|
||||
|
||||
@@ -338,6 +350,7 @@ public class CommandGroup extends Command {
|
||||
*
|
||||
* @return whether or not this {@link CommandGroup} is interruptible.
|
||||
*/
|
||||
@Override
|
||||
public synchronized boolean isInterruptible() {
|
||||
if (!super.isInterruptible()) {
|
||||
return false;
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class ConditionalCommand extends Command {
|
||||
/**
|
||||
* Stores command chosen by condition.
|
||||
*/
|
||||
private Command m_chosenCommand = null;
|
||||
private Command m_chosenCommand;
|
||||
|
||||
private void requireAll() {
|
||||
if (m_onTrue != null) {
|
||||
|
||||
@@ -25,6 +25,7 @@ public class InstantCommand extends Command {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,13 +33,16 @@ public abstract class PIDCommand extends Command {
|
||||
* A source which calls {@link PIDCommand#returnPIDInput()}.
|
||||
*/
|
||||
private final PIDSource m_source = new PIDSource() {
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return PIDSourceType.kDisplacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double pidGet() {
|
||||
return returnPIDInput();
|
||||
}
|
||||
|
||||
@@ -35,13 +35,16 @@ public abstract class PIDSubsystem extends Subsystem {
|
||||
* A source which calls {@link PIDCommand#returnPIDInput()}.
|
||||
*/
|
||||
private final PIDSource m_source = new PIDSource() {
|
||||
@Override
|
||||
public void setPIDSourceType(PIDSourceType pidSource) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PIDSourceType getPIDSourceType() {
|
||||
return PIDSourceType.kDisplacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double pidGet() {
|
||||
return returnPIDInput();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class PrintCommand extends InstantCommand {
|
||||
/**
|
||||
* The message to print out.
|
||||
*/
|
||||
private String m_message;
|
||||
private final String m_message;
|
||||
|
||||
/**
|
||||
* Instantiates a {@link PrintCommand} which will print the given message when it is run.
|
||||
@@ -28,6 +28,7 @@ public class PrintCommand extends InstantCommand {
|
||||
m_message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize() {
|
||||
System.out.println(m_message);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
*
|
||||
* @see Command
|
||||
*/
|
||||
public class Scheduler extends SendableBase {
|
||||
public final class Scheduler extends SendableBase {
|
||||
/**
|
||||
* The Singleton Instance.
|
||||
*/
|
||||
@@ -50,11 +50,12 @@ public class Scheduler extends SendableBase {
|
||||
/**
|
||||
* A hashtable of active {@link Command Commands} to their {@link LinkedListElement}.
|
||||
*/
|
||||
private Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
|
||||
@SuppressWarnings("PMD.LooseCoupling")
|
||||
private final Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
|
||||
/**
|
||||
* The {@link Set} of all {@link Subsystem Subsystems}.
|
||||
*/
|
||||
private Set m_subsystems = new Set();
|
||||
private final Set m_subsystems = new Set();
|
||||
/**
|
||||
* The first {@link Command} in the list.
|
||||
*/
|
||||
@@ -66,15 +67,16 @@ public class Scheduler extends SendableBase {
|
||||
/**
|
||||
* Whether or not we are currently adding a command.
|
||||
*/
|
||||
private boolean m_adding = false;
|
||||
private boolean m_adding;
|
||||
/**
|
||||
* Whether or not we are currently disabled.
|
||||
*/
|
||||
private boolean m_disabled = false;
|
||||
private boolean m_disabled;
|
||||
/**
|
||||
* A list of all {@link Command Commands} which need to be added.
|
||||
*/
|
||||
private Vector<Command> m_additions = new Vector<>();
|
||||
@SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"})
|
||||
private final Vector<Command> m_additions = new Vector<>();
|
||||
private NetworkTableEntry m_namesEntry;
|
||||
private NetworkTableEntry m_idsEntry;
|
||||
private NetworkTableEntry m_cancelEntry;
|
||||
@@ -82,6 +84,7 @@ public class Scheduler extends SendableBase {
|
||||
* A list of all {@link edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler Buttons}. It is
|
||||
* created lazily.
|
||||
*/
|
||||
@SuppressWarnings("PMD.LooseCoupling")
|
||||
private Vector<ButtonScheduler> m_buttons;
|
||||
private boolean m_runningCommandsChanged;
|
||||
|
||||
@@ -115,6 +118,7 @@ public class Scheduler extends SendableBase {
|
||||
*
|
||||
* @param button the button to add
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseArrayListInsteadOfVector")
|
||||
public void addButton(ButtonScheduler button) {
|
||||
if (m_buttons == null) {
|
||||
m_buttons = new Vector<>();
|
||||
@@ -129,7 +133,7 @@ public class Scheduler extends SendableBase {
|
||||
*
|
||||
* @param command the {@link Command} to add
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
@SuppressWarnings({"MethodName", "PMD.CyclomaticComplexity"})
|
||||
private void _add(Command command) {
|
||||
if (command == null) {
|
||||
return;
|
||||
@@ -189,6 +193,7 @@ public class Scheduler extends SendableBase {
|
||||
* <ol> <li>Poll the Buttons</li> <li>Execute/Remove the Commands</li> <li>Send values to
|
||||
* SmartDashboard</li> <li>Add Commands</li> <li>Add Defaults</li> </ol>
|
||||
*/
|
||||
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
|
||||
public void run() {
|
||||
m_runningCommandsChanged = false;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class StartCommand extends InstantCommand {
|
||||
/**
|
||||
* The command to fork.
|
||||
*/
|
||||
private Command m_commandToFork;
|
||||
private final Command m_commandToFork;
|
||||
|
||||
/**
|
||||
* Instantiates a {@link StartCommand} which will start the given command whenever its {@link
|
||||
@@ -28,6 +28,7 @@ public class StartCommand extends InstantCommand {
|
||||
m_commandToFork = commandToStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize() {
|
||||
m_commandToFork.start();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class Subsystem extends SendableBase {
|
||||
/**
|
||||
* Whether or not getDefaultCommand() was called.
|
||||
*/
|
||||
private boolean m_initializedDefaultCommand = false;
|
||||
private boolean m_initializedDefaultCommand;
|
||||
/**
|
||||
* The current command.
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,7 @@ public class TimedCommand extends Command {
|
||||
/**
|
||||
* Ends command when timed out.
|
||||
*/
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return isTimedOut();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package edu.wpi.first.wpilibj.command;
|
||||
* to finish, before continuing in the main {@link CommandGroup} sequence.
|
||||
*/
|
||||
public class WaitForChildren extends Command {
|
||||
@Override
|
||||
protected boolean isFinished() {
|
||||
return getGroup() == null || getGroup().m_children.isEmpty();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import edu.wpi.first.wpilibj.Timer;
|
||||
* some value, then continue to the next command.
|
||||
*/
|
||||
public class WaitUntilCommand extends Command {
|
||||
private double m_time;
|
||||
private final double m_time;
|
||||
|
||||
public WaitUntilCommand(double time) {
|
||||
super("WaitUntil(" + time + ")");
|
||||
@@ -24,6 +24,7 @@ public class WaitUntilCommand extends Command {
|
||||
/**
|
||||
* Check if we've reached the actual finish time.
|
||||
*/
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return Timer.getMatchTime() >= m_time;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user