From 50880b113fc739164eb1f009e6043a254013249c Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:59:18 -0400 Subject: [PATCH 1/4] Don't force public variables to have an m_ prefix --- .../src/main/java/org/wpilib/vision/apriltag/AprilTag.java | 2 +- .../java/org/wpilib/vision/apriltag/AprilTagDetector.java | 2 -- .../java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java | 2 -- .../org/wpilib/vision/apriltag/AprilTagPoseEstimate.java | 1 - .../org/wpilib/vision/apriltag/AprilTagPoseEstimator.java | 1 - .../multiCameraServer/src/main/java/org/wpilib/Main.java | 1 - .../main/java/org/wpilib/vision/camera/UsbCameraInfo.java | 1 - .../src/main/java/org/wpilib/vision/camera/VideoEvent.java | 1 - cscore/src/main/java/org/wpilib/vision/camera/VideoMode.java | 1 - datalog/src/main/java/org/wpilib/datalog/DataLogRecord.java | 2 -- .../main/java/org/wpilib/epilogue/EpilogueConfiguration.java | 1 - hal/src/main/java/org/wpilib/hardware/hal/CANAPITypes.java | 2 -- hal/src/main/java/org/wpilib/hardware/hal/MatchInfoData.java | 1 - .../org/wpilib/hardware/hal/PowerDistributionVersion.java | 1 - hal/src/main/java/org/wpilib/hardware/hal/REVPHVersion.java | 1 - hal/src/main/java/org/wpilib/hardware/hal/can/CANStatus.java | 1 - .../java/org/wpilib/hardware/hal/can/CANStreamMessage.java | 5 ----- .../org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java | 2 -- ntcore/src/generate/main/java/Timestamped.java.jinja | 3 --- .../java/org/wpilib/networktables/TimestampedBoolean.java | 3 --- .../org/wpilib/networktables/TimestampedBooleanArray.java | 3 --- .../java/org/wpilib/networktables/TimestampedDouble.java | 3 --- .../org/wpilib/networktables/TimestampedDoubleArray.java | 3 --- .../main/java/org/wpilib/networktables/TimestampedFloat.java | 3 --- .../java/org/wpilib/networktables/TimestampedFloatArray.java | 3 --- .../java/org/wpilib/networktables/TimestampedInteger.java | 3 --- .../org/wpilib/networktables/TimestampedIntegerArray.java | 3 --- .../main/java/org/wpilib/networktables/TimestampedRaw.java | 3 --- .../java/org/wpilib/networktables/TimestampedString.java | 3 --- .../org/wpilib/networktables/TimestampedStringArray.java | 3 --- .../main/java/org/wpilib/networktables/ConnectionInfo.java | 1 - .../src/main/java/org/wpilib/networktables/LogMessage.java | 1 - .../java/org/wpilib/networktables/NetworkTableEvent.java | 1 - .../main/java/org/wpilib/networktables/PubSubOptions.java | 1 - .../java/org/wpilib/networktables/TimeSyncEventData.java | 1 - .../java/org/wpilib/networktables/TimestampedObject.java | 3 --- ntcore/src/main/java/org/wpilib/networktables/TopicInfo.java | 1 - .../main/java/org/wpilib/networktables/ValueEventData.java | 1 - styleguide/checkstyle.xml | 1 + .../src/main/java/org/wpilib/counter/EdgeConfiguration.java | 1 - .../src/main/java/org/wpilib/drive/DifferentialDrive.java | 1 - wpilibj/src/main/java/org/wpilib/drive/MecanumDrive.java | 1 - .../examples/rapidreactcommandbot/subsystems/Storage.java | 1 - wpiutil/src/main/java/org/wpilib/util/Color.java | 1 - wpiutil/src/main/java/org/wpilib/util/Color8Bit.java | 1 - .../main/java/org/wpilib/util/struct/StructFieldType.java | 4 ---- .../org/wpilib/util/struct/parser/ParsedDeclaration.java | 5 ----- .../java/org/wpilib/util/struct/parser/ParsedSchema.java | 1 - 48 files changed, 2 insertions(+), 89 deletions(-) diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java index b2f36c1d0c0..3e6c0d48779 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java @@ -11,11 +11,11 @@ import org.wpilib.vision.apriltag.jni.AprilTagJNI; /** Represents an AprilTag's metadata. */ -@SuppressWarnings("MemberName") @Json public class AprilTag { /** The tag's ID. */ @Json.Property("ID") + @SuppressWarnings("MemberName") public int ID; /** The tag's pose. */ diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagDetector.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagDetector.java index 6bba9cc671e..22aa4f09b60 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagDetector.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagDetector.java @@ -14,7 +14,6 @@ */ public class AprilTagDetector implements AutoCloseable { /** Detector configuration. */ - @SuppressWarnings("MemberName") public static class Config { /** * How many threads should be used for computation. Default is single-threaded operation (1 @@ -110,7 +109,6 @@ public boolean equals(Object obj) { } /** Quad threshold parameters. */ - @SuppressWarnings("MemberName") public static class QuadThresholdParameters { /** Threshold used to reject quads containing too few pixels. Default is 300 pixels. */ public int minClusterPixels = 300; diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java index 62b878ed9be..6ad63ea8862 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java @@ -264,11 +264,9 @@ public int hashCode() { } static class FieldDimensions { - @SuppressWarnings("MemberName") @Json.Property(value = "length") public final double fieldLength; - @SuppressWarnings("MemberName") @Json.Property(value = "width") public final double fieldWidth; diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimate.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimate.java index 54727e1a4f8..2025e069c8e 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimate.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimate.java @@ -7,7 +7,6 @@ import org.wpilib.math.geometry.Transform3d; /** A pair of AprilTag pose estimates. */ -@SuppressWarnings("MemberName") public class AprilTagPoseEstimate { /** * Constructs a pose estimate. diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimator.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimator.java index 224b78f3ef8..2c9c3f1d31c 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimator.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagPoseEstimator.java @@ -10,7 +10,6 @@ /** Pose estimators for AprilTag tags. */ public class AprilTagPoseEstimator { /** Configuration for the pose estimator. */ - @SuppressWarnings("MemberName") public static class Config { /** * Creates a pose estimator configuration. diff --git a/cameraserver/multiCameraServer/src/main/java/org/wpilib/Main.java b/cameraserver/multiCameraServer/src/main/java/org/wpilib/Main.java index 8da41bb3409..0ab2e7c226c 100644 --- a/cameraserver/multiCameraServer/src/main/java/org/wpilib/Main.java +++ b/cameraserver/multiCameraServer/src/main/java/org/wpilib/Main.java @@ -49,7 +49,6 @@ public final class Main { private static String configFile = "/boot/CameraServerConfig.json"; - @SuppressWarnings("MemberName") public static class CameraConfig { public String name; public String path; diff --git a/cscore/src/main/java/org/wpilib/vision/camera/UsbCameraInfo.java b/cscore/src/main/java/org/wpilib/vision/camera/UsbCameraInfo.java index dc164b4854d..503a27e7520 100644 --- a/cscore/src/main/java/org/wpilib/vision/camera/UsbCameraInfo.java +++ b/cscore/src/main/java/org/wpilib/vision/camera/UsbCameraInfo.java @@ -5,7 +5,6 @@ package org.wpilib.vision.camera; /** USB camera information. */ -@SuppressWarnings("MemberName") public class UsbCameraInfo { /** * Create a new set of UsbCameraInfo. diff --git a/cscore/src/main/java/org/wpilib/vision/camera/VideoEvent.java b/cscore/src/main/java/org/wpilib/vision/camera/VideoEvent.java index 61657eb413f..9977af91fd6 100644 --- a/cscore/src/main/java/org/wpilib/vision/camera/VideoEvent.java +++ b/cscore/src/main/java/org/wpilib/vision/camera/VideoEvent.java @@ -5,7 +5,6 @@ package org.wpilib.vision.camera; /** Video event. */ -@SuppressWarnings("MemberName") public class VideoEvent { /** VideoEvent kind. */ public enum Kind { diff --git a/cscore/src/main/java/org/wpilib/vision/camera/VideoMode.java b/cscore/src/main/java/org/wpilib/vision/camera/VideoMode.java index 24f9e98fe62..34e86503806 100644 --- a/cscore/src/main/java/org/wpilib/vision/camera/VideoMode.java +++ b/cscore/src/main/java/org/wpilib/vision/camera/VideoMode.java @@ -8,7 +8,6 @@ import org.wpilib.util.PixelFormat; /** Video mode. */ -@SuppressWarnings("MemberName") public class VideoMode { /** * Create a new video mode. diff --git a/datalog/src/main/java/org/wpilib/datalog/DataLogRecord.java b/datalog/src/main/java/org/wpilib/datalog/DataLogRecord.java index b2f06388517..c7af37d3410 100644 --- a/datalog/src/main/java/org/wpilib/datalog/DataLogRecord.java +++ b/datalog/src/main/java/org/wpilib/datalog/DataLogRecord.java @@ -124,7 +124,6 @@ public boolean isSetMetadata() { * Data contained in a start control record as created by DataLog.start() when writing the log. * This can be read by calling getStartData(). */ - @SuppressWarnings("MemberName") public static class StartRecordData { StartRecordData(int entry, String name, String type, String metadata) { this.entry = entry; @@ -169,7 +168,6 @@ public StartRecordData getStartData() { * Data contained in a set metadata control record as created by DataLog.setMetadata(). This can * be read by calling getSetMetadataData(). */ - @SuppressWarnings("MemberName") public static class MetadataRecordData { MetadataRecordData(int entry, String metadata) { this.entry = entry; diff --git a/epilogue-runtime/src/main/java/org/wpilib/epilogue/EpilogueConfiguration.java b/epilogue-runtime/src/main/java/org/wpilib/epilogue/EpilogueConfiguration.java index 5e046eb87a8..91d9753bc39 100644 --- a/epilogue-runtime/src/main/java/org/wpilib/epilogue/EpilogueConfiguration.java +++ b/epilogue-runtime/src/main/java/org/wpilib/epilogue/EpilogueConfiguration.java @@ -15,7 +15,6 @@ * A configuration object to be used by the generated {@code Epilogue} class to customize its * behavior. */ -@SuppressWarnings("checkstyle:MemberName") public class EpilogueConfiguration { /** * The backend implementation for Epilogue to use. By default, this will log data directly to diff --git a/hal/src/main/java/org/wpilib/hardware/hal/CANAPITypes.java b/hal/src/main/java/org/wpilib/hardware/hal/CANAPITypes.java index df13e5c67fa..403bc8ce53e 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/CANAPITypes.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/CANAPITypes.java @@ -55,7 +55,6 @@ public enum CANDeviceType { FIRMWARE_UPDATE(31); /** The device type ID. */ - @SuppressWarnings("MemberName") public final int id; CANDeviceType(int id) { @@ -118,7 +117,6 @@ public enum CANManufacturer { BRUSHLAND_LABS(20); /** The manufacturer ID. */ - @SuppressWarnings("MemberName") public final int id; CANManufacturer(int id) { diff --git a/hal/src/main/java/org/wpilib/hardware/hal/MatchInfoData.java b/hal/src/main/java/org/wpilib/hardware/hal/MatchInfoData.java index 3b8eb6aee7d..2c738813766 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/MatchInfoData.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/MatchInfoData.java @@ -5,7 +5,6 @@ package org.wpilib.hardware.hal; /** Structure for holding the match info data request. */ -@SuppressWarnings("MemberName") public class MatchInfoData { /** Stores the event name. */ public String eventName = ""; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionVersion.java b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionVersion.java index 086ed42f780..62f221e4d93 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionVersion.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionVersion.java @@ -5,7 +5,6 @@ package org.wpilib.hardware.hal; /** Power distribution version. */ -@SuppressWarnings("MemberName") public class PowerDistributionVersion { /** Firmware major version number. */ public final int firmwareMajor; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/REVPHVersion.java b/hal/src/main/java/org/wpilib/hardware/hal/REVPHVersion.java index 1dbd075f549..d63860839a0 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/REVPHVersion.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/REVPHVersion.java @@ -5,7 +5,6 @@ package org.wpilib.hardware.hal; /** Version and device data received from a REV PH. */ -@SuppressWarnings("MemberName") public class REVPHVersion { /** The firmware major version. */ public final int firmwareMajor; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/can/CANStatus.java b/hal/src/main/java/org/wpilib/hardware/hal/can/CANStatus.java index e5aeb1e0645..badd06e39f2 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/can/CANStatus.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/can/CANStatus.java @@ -5,7 +5,6 @@ package org.wpilib.hardware.hal.can; /** Structure for holding the result of a CAN Status request. */ -@SuppressWarnings("MemberName") public class CANStatus { /** The utilization of the CAN Bus. */ public double percentBusUtilization; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/can/CANStreamMessage.java b/hal/src/main/java/org/wpilib/hardware/hal/can/CANStreamMessage.java index d268103820f..e7c491ed7a4 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/can/CANStreamMessage.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/can/CANStreamMessage.java @@ -7,23 +7,18 @@ /** Represents a CAN message read from a stream. */ public class CANStreamMessage { /** The message data. */ - @SuppressWarnings("MemberName") public final byte[] data = new byte[64]; /** The length of the data received (0-64 bytes). */ - @SuppressWarnings("MemberName") public int length; /** The flags of the message. */ - @SuppressWarnings("MemberName") public int flags; /** Timestamp message was received, in milliseconds (based off of CLOCK_MONOTONIC). */ - @SuppressWarnings("MemberName") public long timestamp; /** The message ID. */ - @SuppressWarnings("MemberName") public int messageId; /** Default constructor. */ diff --git a/hal/src/main/java/org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java index 89fd771cb93..cd6c343048f 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java @@ -29,7 +29,6 @@ public static native int registerSimDeviceFreedCallback( public static native int getSimValueDeviceHandle(int handle); - @SuppressWarnings("MemberName") public static class SimDeviceInfo { public String name; public int handle; @@ -74,7 +73,6 @@ public static native int registerSimValueResetCallback( public static native int getSimValueHandle(int device, String name); - @SuppressWarnings("MemberName") public static class SimValueInfo { public String name; public int handle; diff --git a/ntcore/src/generate/main/java/Timestamped.java.jinja b/ntcore/src/generate/main/java/Timestamped.java.jinja index 144cc5023da..580037dc220 100644 --- a/ntcore/src/generate/main/java/Timestamped.java.jinja +++ b/ntcore/src/generate/main/java/Timestamped.java.jinja @@ -24,19 +24,16 @@ public final class Timestamped{{ TypeName }} { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final {{ java.ValueType }} value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBoolean.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBoolean.java index aa8590d2135..7104e088807 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBoolean.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBoolean.java @@ -24,18 +24,15 @@ public TimestampedBoolean(long timestamp, long serverTime, boolean value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final boolean value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBooleanArray.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBooleanArray.java index 24218f65355..c027f725b14 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBooleanArray.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedBooleanArray.java @@ -24,18 +24,15 @@ public TimestampedBooleanArray(long timestamp, long serverTime, boolean[] value) /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final boolean[] value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDouble.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDouble.java index 7a5ceaf50e4..7a9e46d67b9 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDouble.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDouble.java @@ -24,18 +24,15 @@ public TimestampedDouble(long timestamp, long serverTime, double value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final double value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDoubleArray.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDoubleArray.java index ff8d3c02061..9da8fdb87fe 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDoubleArray.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedDoubleArray.java @@ -24,18 +24,15 @@ public TimestampedDoubleArray(long timestamp, long serverTime, double[] value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final double[] value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloat.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloat.java index 3ecf2c32d2b..f12f87149bc 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloat.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloat.java @@ -24,18 +24,15 @@ public TimestampedFloat(long timestamp, long serverTime, float value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final float value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloatArray.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloatArray.java index 70dbc9d6a8d..1c9a5f826ba 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloatArray.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedFloatArray.java @@ -24,18 +24,15 @@ public TimestampedFloatArray(long timestamp, long serverTime, float[] value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final float[] value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedInteger.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedInteger.java index 56cee7539bd..2eec4426222 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedInteger.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedInteger.java @@ -24,18 +24,15 @@ public TimestampedInteger(long timestamp, long serverTime, long value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final long value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedIntegerArray.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedIntegerArray.java index 9221386eed0..91f2966f2c8 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedIntegerArray.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedIntegerArray.java @@ -24,18 +24,15 @@ public TimestampedIntegerArray(long timestamp, long serverTime, long[] value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final long[] value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedRaw.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedRaw.java index a54e54b4c16..74984d93244 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedRaw.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedRaw.java @@ -24,18 +24,15 @@ public TimestampedRaw(long timestamp, long serverTime, byte[] value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final byte[] value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedString.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedString.java index 860d3527634..1e275580c33 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedString.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedString.java @@ -24,18 +24,15 @@ public TimestampedString(long timestamp, long serverTime, String value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final String value; } diff --git a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedStringArray.java b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedStringArray.java index 29d094683f6..87fb72c1857 100644 --- a/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedStringArray.java +++ b/ntcore/src/generated/main/java/org/wpilib/networktables/TimestampedStringArray.java @@ -24,18 +24,15 @@ public TimestampedStringArray(long timestamp, long serverTime, String[] value) { /** * Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** * Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** * Value. */ - @SuppressWarnings("MemberName") public final String[] value; } diff --git a/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java b/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java index 33ef2525db5..f0a0746893b 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java +++ b/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java @@ -5,7 +5,6 @@ package org.wpilib.networktables; /** NetworkTables Connection information. */ -@SuppressWarnings("MemberName") public final class ConnectionInfo { /** * The remote identifier (as set on the remote node by {@link diff --git a/ntcore/src/main/java/org/wpilib/networktables/LogMessage.java b/ntcore/src/main/java/org/wpilib/networktables/LogMessage.java index f35599b6990..a7faa20f4cd 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/LogMessage.java +++ b/ntcore/src/main/java/org/wpilib/networktables/LogMessage.java @@ -5,7 +5,6 @@ package org.wpilib.networktables; /** NetworkTables log message. */ -@SuppressWarnings("MemberName") public final class LogMessage { /** Critical logging level. */ public static final int CRITICAL = 50; diff --git a/ntcore/src/main/java/org/wpilib/networktables/NetworkTableEvent.java b/ntcore/src/main/java/org/wpilib/networktables/NetworkTableEvent.java index 401ac50535b..49c1c9a1e36 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/NetworkTableEvent.java +++ b/ntcore/src/main/java/org/wpilib/networktables/NetworkTableEvent.java @@ -10,7 +10,6 @@ *

There are different kinds of events. When creating a listener, a combination of event kinds * can be listened to by building an EnumSet of NetworkTableEvent.Kind. */ -@SuppressWarnings("MemberName") public final class NetworkTableEvent { /** NetworkTable event kind. */ public enum Kind { diff --git a/ntcore/src/main/java/org/wpilib/networktables/PubSubOptions.java b/ntcore/src/main/java/org/wpilib/networktables/PubSubOptions.java index 2bf16c7d757..b50cae5cb8e 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/PubSubOptions.java +++ b/ntcore/src/main/java/org/wpilib/networktables/PubSubOptions.java @@ -5,7 +5,6 @@ package org.wpilib.networktables; /** NetworkTables publish/subscribe options. */ -@SuppressWarnings("MemberName") public class PubSubOptions { /** * Construct from a list of options. diff --git a/ntcore/src/main/java/org/wpilib/networktables/TimeSyncEventData.java b/ntcore/src/main/java/org/wpilib/networktables/TimeSyncEventData.java index bc3d96f8edd..b1dbc2dfdc7 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/TimeSyncEventData.java +++ b/ntcore/src/main/java/org/wpilib/networktables/TimeSyncEventData.java @@ -5,7 +5,6 @@ package org.wpilib.networktables; /** NetworkTables time sync event data. */ -@SuppressWarnings("MemberName") public final class TimeSyncEventData { /** * Offset between local time and server time, in microseconds. Add this value to local time to get diff --git a/ntcore/src/main/java/org/wpilib/networktables/TimestampedObject.java b/ntcore/src/main/java/org/wpilib/networktables/TimestampedObject.java index 7ecc94d09e4..a2726c41526 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/TimestampedObject.java +++ b/ntcore/src/main/java/org/wpilib/networktables/TimestampedObject.java @@ -24,14 +24,11 @@ public TimestampedObject(long timestamp, long serverTime, T value) { } /** Timestamp in local time base. */ - @SuppressWarnings("MemberName") public final long timestamp; /** Timestamp in server time base. May be 0 or 1 for locally set values. */ - @SuppressWarnings("MemberName") public final long serverTime; /** Value. */ - @SuppressWarnings("MemberName") public final T value; } diff --git a/ntcore/src/main/java/org/wpilib/networktables/TopicInfo.java b/ntcore/src/main/java/org/wpilib/networktables/TopicInfo.java index 754ec4d67f7..71eedbb0465 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/TopicInfo.java +++ b/ntcore/src/main/java/org/wpilib/networktables/TopicInfo.java @@ -5,7 +5,6 @@ package org.wpilib.networktables; /** NetworkTables topic information. */ -@SuppressWarnings("MemberName") public final class TopicInfo { /** Topic handle. */ public final int topic; diff --git a/ntcore/src/main/java/org/wpilib/networktables/ValueEventData.java b/ntcore/src/main/java/org/wpilib/networktables/ValueEventData.java index ba381f58e1d..c59f83a0d95 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/ValueEventData.java +++ b/ntcore/src/main/java/org/wpilib/networktables/ValueEventData.java @@ -5,7 +5,6 @@ package org.wpilib.networktables; /** NetworkTables value event data. */ -@SuppressWarnings("MemberName") public final class ValueEventData { /** Topic handle. Topic.getHandle() can be used to map this to the corresponding Topic object. */ public final int topic; diff --git a/styleguide/checkstyle.xml b/styleguide/checkstyle.xml index 9ebe62c3c27..e641c16291e 100644 --- a/styleguide/checkstyle.xml +++ b/styleguide/checkstyle.xml @@ -173,6 +173,7 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" value="^(m_([a-zA-Z]|[a-z][a-zA-Z0-9]+)|value)$" /> + Uses normalized voltage [-1.0..1.0]. */ - @SuppressWarnings("MemberName") public static class WheelVelocities { /** Left wheel velocity. */ public double left; diff --git a/wpilibj/src/main/java/org/wpilib/drive/MecanumDrive.java b/wpilibj/src/main/java/org/wpilib/drive/MecanumDrive.java index 8badcfb6769..05e9469109c 100644 --- a/wpilibj/src/main/java/org/wpilib/drive/MecanumDrive.java +++ b/wpilibj/src/main/java/org/wpilib/drive/MecanumDrive.java @@ -70,7 +70,6 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea * *

Uses normalized voltage [-1.0..1.0]. */ - @SuppressWarnings("MemberName") public static class WheelVelocities { /** Front-left wheel velocity. */ public double frontLeft; diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java index 17e197f28ee..94fec8a24ff 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java @@ -23,7 +23,6 @@ public class Storage extends SubsystemBase { // inter-subsystem communications /** Whether the ball storage is full. */ @Logged(name = "Has Cargo") - @SuppressWarnings("checkstyle:MemberName") public final Trigger hasCargo = new Trigger(m_ballSensor::get); /** Create a new Storage subsystem. */ diff --git a/wpiutil/src/main/java/org/wpilib/util/Color.java b/wpiutil/src/main/java/org/wpilib/util/Color.java index 90a79afb6f5..eb17e25e9b9 100644 --- a/wpiutil/src/main/java/org/wpilib/util/Color.java +++ b/wpiutil/src/main/java/org/wpilib/util/Color.java @@ -11,7 +11,6 @@ * *

Limited to 12 bits of precision. */ -@SuppressWarnings("MemberName") public class Color { /** Red component (0-1). */ public final double red; diff --git a/wpiutil/src/main/java/org/wpilib/util/Color8Bit.java b/wpiutil/src/main/java/org/wpilib/util/Color8Bit.java index d33ca81f34b..8aed51822c7 100644 --- a/wpiutil/src/main/java/org/wpilib/util/Color8Bit.java +++ b/wpiutil/src/main/java/org/wpilib/util/Color8Bit.java @@ -7,7 +7,6 @@ import java.util.Objects; /** Represents colors with 8 bits of precision. */ -@SuppressWarnings("MemberName") public class Color8Bit { /** Red component (0-255). */ public final int red; diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldType.java b/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldType.java index d550dd8dca9..4140055a974 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldType.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldType.java @@ -34,19 +34,15 @@ public enum StructFieldType { STRUCT("struct", false, false, 0); /** The name of the data type. */ - @SuppressWarnings("MemberName") public final String name; /** Indicates if the data type is a signed integer. */ - @SuppressWarnings("MemberName") public final boolean isInt; /** Indicates if the data type is an unsigned integer. */ - @SuppressWarnings("MemberName") public final boolean isUint; /** The size (in bytes) of the data type. */ - @SuppressWarnings("MemberName") public final int size; StructFieldType(String name, boolean isInt, boolean isUint, int size) { diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedDeclaration.java b/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedDeclaration.java index 5b7a5e09bc1..e2aeaccbcbf 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedDeclaration.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedDeclaration.java @@ -9,23 +9,18 @@ /** Raw struct schema declaration. */ public class ParsedDeclaration { /** Type string. */ - @SuppressWarnings("MemberName") public String typeString; /** Name. */ - @SuppressWarnings("MemberName") public String name; /** Enum values. */ - @SuppressWarnings("MemberName") public Map enumValues; /** Array size. */ - @SuppressWarnings("MemberName") public int arraySize = 1; /** Bit width. */ - @SuppressWarnings("MemberName") public int bitWidth; /** Default constructor. */ diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedSchema.java b/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedSchema.java index 767765a88d0..72c816108e8 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedSchema.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/parser/ParsedSchema.java @@ -10,7 +10,6 @@ /** Raw struct schema. */ public class ParsedSchema { /** Declarations. */ - @SuppressWarnings("MemberName") public List declarations = new ArrayList<>(); /** Default constructor. */ From a0c7a70806a1627e141958e28923f06062be39bc Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:29:22 -0400 Subject: [PATCH 2/4] Remove m_ prefix from public variables --- .../vision/apriltag/AprilTagFieldLayout.java | 4 +- .../vision/apriltag/AprilTagFields.java | 4 +- .../wpilib/command2/sysid/SysIdRoutine.java | 68 +++++++++---------- .../java/org/wpilib/fields/FieldConfig.java | 21 +++--- .../main/java/org/wpilib/fields/Fields.java | 1 - .../org/wpilib/hardware/hal/SimDevice.java | 19 +++--- .../DifferentialDriveFeedforward.java | 16 ++--- .../DifferentialDriveFeedforwardProto.java | 8 +-- .../DifferentialDriveFeedforwardStruct.java | 8 +-- .../DifferentialDriveFeedforwardProto.cpp | 8 +-- .../DifferentialDriveFeedforwardStruct.cpp | 8 +-- .../DifferentialDriveFeedforward.hpp | 16 ++--- .../semiwrap/DifferentialDriveFeedforward.yml | 8 +-- ...DifferentialDriveFeedforwardProtoTest.java | 8 +-- ...ifferentialDriveFeedforwardStructTest.java | 8 +-- .../DifferentialDriveFeedforwardProtoTest.cpp | 8 +-- ...DifferentialDriveFeedforwardStructTest.cpp | 8 +-- 17 files changed, 109 insertions(+), 112 deletions(-) diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java index 6ad63ea8862..2c125f36475 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java @@ -218,10 +218,10 @@ public void serialize(Path path) throws IOException { public static AprilTagFieldLayout loadField(AprilTagFields field) { if (field.m_fieldLayout == null) { try { - field.m_fieldLayout = loadFromResource(field.m_resourceFile); + field.m_fieldLayout = loadFromResource(field.resourceFile); } catch (IOException e) { throw new UncheckedIOException( - "Could not load AprilTagFieldLayout from " + field.m_resourceFile, e); + "Could not load AprilTagFieldLayout from " + field.resourceFile, e); } } // Copy layout because the layout's origin is mutable diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java index f0c75bc2b21..d2169d309bc 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java @@ -28,11 +28,11 @@ public enum AprilTagFields { public static final AprilTagFields kDefaultField = k2026RebuiltWelded; /** Resource filename. */ - public final String m_resourceFile; + public final String resourceFile; AprilTagFieldLayout m_fieldLayout; AprilTagFields(String resourceFile) { - m_resourceFile = kBaseResourceDir + resourceFile; + this.resourceFile = kBaseResourceDir + resourceFile; } } diff --git a/commandsv2/src/main/java/org/wpilib/command2/sysid/SysIdRoutine.java b/commandsv2/src/main/java/org/wpilib/command2/sysid/SysIdRoutine.java index 56fdd5c90d5..30d67e0021c 100644 --- a/commandsv2/src/main/java/org/wpilib/command2/sysid/SysIdRoutine.java +++ b/commandsv2/src/main/java/org/wpilib/command2/sysid/SysIdRoutine.java @@ -50,25 +50,25 @@ public class SysIdRoutine extends SysIdRoutineLog { * @param mechanism Hardware interface for the SysId routine. */ public SysIdRoutine(Config config, Mechanism mechanism) { - super(mechanism.m_name); + super(mechanism.name); m_config = config; m_mechanism = mechanism; - m_recordState = config.m_recordState != null ? config.m_recordState : this::recordState; + m_recordState = config.recordState != null ? config.recordState : this::recordState; } /** Hardware-independent configuration for a SysId test routine. */ public static class Config { /** The voltage ramp rate used for quasistatic test routines. */ - public final Velocity m_rampRate; + public final Velocity rampRate; /** The step voltage output used for dynamic test routines. */ - public final Voltage m_stepVoltage; + public final Voltage stepVoltage; /** Safety timeout for the test routine commands. */ - public final Time m_timeout; + public final Time timeout; /** Optional handle for recording test state in a third-party logging solution. */ - public final Consumer m_recordState; + public final Consumer recordState; /** * Create a new configuration for a SysId test routine. @@ -88,10 +88,10 @@ public Config( Voltage stepVoltage, Time timeout, Consumer recordState) { - m_rampRate = rampRate != null ? rampRate : Volts.of(1).per(Second); - m_stepVoltage = stepVoltage != null ? stepVoltage : Volts.of(7); - m_timeout = timeout != null ? timeout : Seconds.of(10); - m_recordState = recordState; + this.rampRate = rampRate != null ? rampRate : Volts.of(1).per(Second); + this.stepVoltage = stepVoltage != null ? stepVoltage : Volts.of(7); + this.timeout = timeout != null ? timeout : Seconds.of(10); + this.recordState = recordState; } /** @@ -128,19 +128,19 @@ public Config() { */ public static class Mechanism { /** Sends the SysId-specified drive signal to the mechanism motors during test routines. */ - public final Consumer m_drive; + public final Consumer drive; /** * Returns measured data (voltages, positions, velocities) of the mechanism motors during test * routines. */ - public final Consumer m_log; + public final Consumer log; /** The subsystem containing the motor(s) that is (or are) being characterized. */ - public final Subsystem m_subsystem; + public final Subsystem subsystem; /** The name of the mechanism being tested. */ - public final String m_name; + public final String name; /** * Create a new mechanism specification for a SysId routine. @@ -160,10 +160,10 @@ public static class Mechanism { */ public Mechanism( Consumer drive, Consumer log, Subsystem subsystem, String name) { - m_drive = drive; - m_log = log != null ? log : l -> {}; - m_subsystem = subsystem; - m_name = name != null ? name : subsystem.getName(); + this.drive = drive; + this.log = log != null ? log : l -> {}; + this.subsystem = subsystem; + this.name = name != null ? name : subsystem.getName(); } /** @@ -217,24 +217,24 @@ public Command quasistatic(Direction direction) { Timer timer = new Timer(); return m_mechanism - .m_subsystem + .subsystem .runOnce(timer::restart) .andThen( - m_mechanism.m_subsystem.run( + m_mechanism.subsystem.run( () -> { - m_mechanism.m_drive.accept( - (Voltage) m_config.m_rampRate.times(Seconds.of(timer.get() * outputSign))); - m_mechanism.m_log.accept(this); + m_mechanism.drive.accept( + (Voltage) m_config.rampRate.times(Seconds.of(timer.get() * outputSign))); + m_mechanism.log.accept(this); m_recordState.accept(state); })) .finallyDo( () -> { - m_mechanism.m_drive.accept(Volts.of(0)); + m_mechanism.drive.accept(Volts.of(0)); m_recordState.accept(State.NONE); timer.stop(); }) - .withName("sysid-" + state.toString() + "-" + m_mechanism.m_name) - .withTimeout(m_config.m_timeout.in(Seconds)); + .withName("sysid-" + state.toString() + "-" + m_mechanism.name) + .withTimeout(m_config.timeout.in(Seconds)); } /** @@ -257,21 +257,21 @@ public Command dynamic(Direction direction) { Voltage[] output = {Volts.zero()}; return m_mechanism - .m_subsystem - .runOnce(() -> output[0] = m_config.m_stepVoltage.times(outputSign)) + .subsystem + .runOnce(() -> output[0] = m_config.stepVoltage.times(outputSign)) .andThen( - m_mechanism.m_subsystem.run( + m_mechanism.subsystem.run( () -> { - m_mechanism.m_drive.accept(output[0]); - m_mechanism.m_log.accept(this); + m_mechanism.drive.accept(output[0]); + m_mechanism.log.accept(this); m_recordState.accept(state); })) .finallyDo( () -> { - m_mechanism.m_drive.accept(Volts.of(0)); + m_mechanism.drive.accept(Volts.of(0)); m_recordState.accept(State.NONE); }) - .withName("sysid-" + state.toString() + "-" + m_mechanism.m_name) - .withTimeout(m_config.m_timeout.in(Seconds)); + .withName("sysid-" + state.toString() + "-" + m_mechanism.name) + .withTimeout(m_config.timeout.in(Seconds)); } } diff --git a/fields/src/main/java/org/wpilib/fields/FieldConfig.java b/fields/src/main/java/org/wpilib/fields/FieldConfig.java index bdbfd6668c6..9891602fac6 100644 --- a/fields/src/main/java/org/wpilib/fields/FieldConfig.java +++ b/fields/src/main/java/org/wpilib/fields/FieldConfig.java @@ -17,39 +17,38 @@ public class FieldConfig { public static class Corners { @Json.Property("top-left") - public double[] m_topLeft; + public double[] topLeft; @Json.Property("bottom-right") - public double[] m_bottomRight; + public double[] bottomRight; } @Json.Property("game") - public String m_game; + public String game; @Json.Property("field-image") - public String m_fieldImage; + public String fieldImage; @Json.Property("field-corners") - public Corners m_fieldCorners; + public Corners fieldCorners; @Json.Property("field-size") - public double[] m_fieldSize; + public double[] fieldSize; @Json.Property("field-unit") - public String m_fieldUnit; + public String fieldUnit; @Json.Property("program") - public String m_program; + public String program; public FieldConfig() {} public URL getImageUrl() { - return getClass().getResource(Fields.BASE_RESOURCE_DIR + m_program + "/" + m_fieldImage); + return getClass().getResource(Fields.BASE_RESOURCE_DIR + program + "/" + fieldImage); } public InputStream getImageAsStream() { - return getClass() - .getResourceAsStream(Fields.BASE_RESOURCE_DIR + m_program + "/" + m_fieldImage); + return getClass().getResourceAsStream(Fields.BASE_RESOURCE_DIR + program + "/" + fieldImage); } /** diff --git a/fields/src/main/java/org/wpilib/fields/Fields.java b/fields/src/main/java/org/wpilib/fields/Fields.java index b0f7c506421..9a469922838 100644 --- a/fields/src/main/java/org/wpilib/fields/Fields.java +++ b/fields/src/main/java/org/wpilib/fields/Fields.java @@ -24,7 +24,6 @@ public enum Fields { public static final String BASE_RESOURCE_DIR = "/org/wpilib/fields/"; - @SuppressWarnings("MemberName") public final String resourceFile; Fields(String resourceFile) { diff --git a/hal/src/main/java/org/wpilib/hardware/hal/SimDevice.java b/hal/src/main/java/org/wpilib/hardware/hal/SimDevice.java index 373613fd318..91a9c49cf78 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/SimDevice.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/SimDevice.java @@ -26,10 +26,10 @@ public enum Direction { BIDIR(SimDeviceJNI.VALUE_BIDIR); /** The native value of this Direction. */ - public final int m_value; + public final int value; Direction(int value) { - m_value = value; + this.value = value; } } @@ -140,7 +140,7 @@ public String getName() { * @return simulated value object */ public SimValue createValue(String name, Direction direction, HALValue initialValue) { - int handle = SimDeviceJNI.createSimValue(m_handle, name, direction.m_value, initialValue); + int handle = SimDeviceJNI.createSimValue(m_handle, name, direction.value, initialValue); if (handle <= 0) { return null; } @@ -158,7 +158,7 @@ public SimValue createValue(String name, Direction direction, HALValue initialVa * @return simulated double value object */ public SimInt createInt(String name, Direction direction, int initialValue) { - int handle = SimDeviceJNI.createSimValueInt(m_handle, name, direction.m_value, initialValue); + int handle = SimDeviceJNI.createSimValueInt(m_handle, name, direction.value, initialValue); if (handle <= 0) { return null; } @@ -176,7 +176,7 @@ public SimInt createInt(String name, Direction direction, int initialValue) { * @return simulated double value object */ public SimLong createLong(String name, Direction direction, long initialValue) { - int handle = SimDeviceJNI.createSimValueLong(m_handle, name, direction.m_value, initialValue); + int handle = SimDeviceJNI.createSimValueLong(m_handle, name, direction.value, initialValue); if (handle <= 0) { return null; } @@ -194,7 +194,7 @@ public SimLong createLong(String name, Direction direction, long initialValue) { * @return simulated double value object */ public SimDouble createDouble(String name, Direction direction, double initialValue) { - int handle = SimDeviceJNI.createSimValueDouble(m_handle, name, direction.m_value, initialValue); + int handle = SimDeviceJNI.createSimValueDouble(m_handle, name, direction.value, initialValue); if (handle <= 0) { return null; } @@ -216,7 +216,7 @@ public SimDouble createDouble(String name, Direction direction, double initialVa */ public SimEnum createEnum(String name, Direction direction, String[] options, int initialValue) { int handle = - SimDeviceJNI.createSimValueEnum(m_handle, name, direction.m_value, options, initialValue); + SimDeviceJNI.createSimValueEnum(m_handle, name, direction.value, options, initialValue); if (handle <= 0) { return null; } @@ -241,7 +241,7 @@ public SimEnum createEnumDouble( String name, Direction direction, String[] options, double[] optionValues, int initialValue) { int handle = SimDeviceJNI.createSimValueEnumDouble( - m_handle, name, direction.m_value, options, optionValues, initialValue); + m_handle, name, direction.value, options, optionValues, initialValue); if (handle <= 0) { return null; } @@ -259,8 +259,7 @@ public SimEnum createEnumDouble( * @return simulated boolean value object */ public SimBoolean createBoolean(String name, Direction direction, boolean initialValue) { - int handle = - SimDeviceJNI.createSimValueBoolean(m_handle, name, direction.m_value, initialValue); + int handle = SimDeviceJNI.createSimValueBoolean(m_handle, name, direction.value, initialValue); if (handle <= 0) { return null; } diff --git a/wpimath/src/main/java/org/wpilib/math/controller/DifferentialDriveFeedforward.java b/wpimath/src/main/java/org/wpilib/math/controller/DifferentialDriveFeedforward.java index d15c54388a0..71273e97cd2 100644 --- a/wpimath/src/main/java/org/wpilib/math/controller/DifferentialDriveFeedforward.java +++ b/wpimath/src/main/java/org/wpilib/math/controller/DifferentialDriveFeedforward.java @@ -18,16 +18,16 @@ public class DifferentialDriveFeedforward implements ProtobufSerializable, Struc private final LinearSystem m_plant; /** The linear velocity gain in volts per (meters per second). */ - public final double m_kVLinear; + public final double kVLinear; /** The linear acceleration gain in volts per (meters per second squared). */ - public final double m_kALinear; + public final double kALinear; /** The angular velocity gain in volts per (radians per second). */ - public final double m_kVAngular; + public final double kVAngular; /** The angular acceleration gain in volts per (radians per second squared). */ - public final double m_kAAngular; + public final double kAAngular; /** * Creates a new DifferentialDriveFeedforward with the specified parameters. @@ -56,10 +56,10 @@ public DifferentialDriveFeedforward( public DifferentialDriveFeedforward( double kVLinear, double kALinear, double kVAngular, double kAAngular) { m_plant = Models.differentialDriveFromSysId(kVLinear, kALinear, kVAngular, kAAngular); - m_kVLinear = kVLinear; - m_kALinear = kALinear; - m_kVAngular = kVAngular; - m_kAAngular = kAAngular; + this.kVLinear = kVLinear; + this.kALinear = kALinear; + this.kVAngular = kVAngular; + this.kAAngular = kAAngular; } /** diff --git a/wpimath/src/main/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProto.java b/wpimath/src/main/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProto.java index f1a2cfa8e09..8cd51ebd6be 100644 --- a/wpimath/src/main/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProto.java +++ b/wpimath/src/main/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProto.java @@ -34,9 +34,9 @@ public DifferentialDriveFeedforward unpack(ProtobufDifferentialDriveFeedforward @Override public void pack(ProtobufDifferentialDriveFeedforward msg, DifferentialDriveFeedforward value) { - msg.setKvLinear(value.m_kVLinear); - msg.setKaLinear(value.m_kALinear); - msg.setKvAngular(value.m_kVAngular); - msg.setKaAngular(value.m_kAAngular); + msg.setKvLinear(value.kVLinear); + msg.setKaLinear(value.kALinear); + msg.setKvAngular(value.kVAngular); + msg.setKaAngular(value.kAAngular); } } diff --git a/wpimath/src/main/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStruct.java b/wpimath/src/main/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStruct.java index 66fc9a5e2a4..48dc9132f4d 100644 --- a/wpimath/src/main/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStruct.java +++ b/wpimath/src/main/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStruct.java @@ -41,9 +41,9 @@ public DifferentialDriveFeedforward unpack(ByteBuffer bb) { @Override public void pack(ByteBuffer bb, DifferentialDriveFeedforward value) { - bb.putDouble(value.m_kVLinear); - bb.putDouble(value.m_kALinear); - bb.putDouble(value.m_kVAngular); - bb.putDouble(value.m_kAAngular); + bb.putDouble(value.kVLinear); + bb.putDouble(value.kALinear); + bb.putDouble(value.kVAngular); + bb.putDouble(value.kAAngular); } } diff --git a/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp b/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp index 742a27d1d17..703a8960a74 100644 --- a/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp +++ b/wpimath/src/main/native/cpp/controller/proto/DifferentialDriveFeedforwardProto.cpp @@ -25,10 +25,10 @@ bool wpi::util::Protobuf::Pack( OutputStream& stream, const wpi::math::DifferentialDriveFeedforward& value) { wpi_proto_ProtobufDifferentialDriveFeedforward msg{ - .kv_linear = value.m_kVLinear.value(), - .ka_linear = value.m_kALinear.value(), - .kv_angular = value.m_kVAngular.value(), - .ka_angular = value.m_kAAngular.value(), + .kv_linear = value.kVLinear.value(), + .ka_linear = value.kALinear.value(), + .kv_angular = value.kVAngular.value(), + .ka_angular = value.kAAngular.value(), }; return stream.Encode(msg); } diff --git a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp index de924ac96ad..3275befefd4 100644 --- a/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp +++ b/wpimath/src/main/native/cpp/controller/struct/DifferentialDriveFeedforwardStruct.cpp @@ -27,8 +27,8 @@ wpi::util::Struct::Unpack( void wpi::util::Struct::Pack( std::span data, const wpi::math::DifferentialDriveFeedforward& value) { - wpi::util::PackStruct(data, value.m_kVLinear.value()); - wpi::util::PackStruct(data, value.m_kALinear.value()); - wpi::util::PackStruct(data, value.m_kVAngular.value()); - wpi::util::PackStruct(data, value.m_kAAngular.value()); + wpi::util::PackStruct(data, value.kVLinear.value()); + wpi::util::PackStruct(data, value.kALinear.value()); + wpi::util::PackStruct(data, value.kVAngular.value()); + wpi::util::PackStruct(data, value.kAAngular.value()); } diff --git a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp index 0b320ad9fcf..90b1bfb4a5f 100644 --- a/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp +++ b/wpimath/src/main/native/include/wpi/math/controller/DifferentialDriveFeedforward.hpp @@ -66,10 +66,10 @@ class WPILIB_DLLEXPORT DifferentialDriveFeedforward { decltype(1_V / 1_mps_sq) kAAngular) : m_plant{wpi::math::Models::DifferentialDriveFromSysId( kVLinear, kALinear, kVAngular, kAAngular)}, - m_kVLinear{kVLinear}, - m_kALinear{kALinear}, - m_kVAngular{kVAngular}, - m_kAAngular{kAAngular} {} + kVLinear{kVLinear}, + kALinear{kALinear}, + kVAngular{kVAngular}, + kAAngular{kAAngular} {} /** * Calculates the differential drive feedforward inputs given velocity @@ -92,10 +92,10 @@ class WPILIB_DLLEXPORT DifferentialDriveFeedforward { wpi::units::meters_per_second_t nextRightVelocity, wpi::units::second_t dt); - decltype(1_V / 1_mps) m_kVLinear; - decltype(1_V / 1_mps_sq) m_kALinear; - decltype(1_V / 1_mps) m_kVAngular; - decltype(1_V / 1_mps_sq) m_kAAngular; + decltype(1_V / 1_mps) kVLinear; + decltype(1_V / 1_mps_sq) kALinear; + decltype(1_V / 1_mps) kVAngular; + decltype(1_V / 1_mps_sq) kAAngular; }; } // namespace wpi::math diff --git a/wpimath/src/main/python/semiwrap/DifferentialDriveFeedforward.yml b/wpimath/src/main/python/semiwrap/DifferentialDriveFeedforward.yml index 6abe7270d80..c4b2169ccd3 100644 --- a/wpimath/src/main/python/semiwrap/DifferentialDriveFeedforward.yml +++ b/wpimath/src/main/python/semiwrap/DifferentialDriveFeedforward.yml @@ -7,10 +7,10 @@ classes: - wpi::units::radians_per_second_squared - wpi::units::compound_unit attributes: - m_kVLinear: - m_kALinear: - m_kVAngular: - m_kAAngular: + kVLinear: + kALinear: + kVAngular: + kAAngular: methods: DifferentialDriveFeedforward: overloads: diff --git a/wpimath/src/test/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProtoTest.java b/wpimath/src/test/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProtoTest.java index a1da6199cb9..982905c5260 100644 --- a/wpimath/src/test/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProtoTest.java +++ b/wpimath/src/test/java/org/wpilib/math/controller/proto/DifferentialDriveFeedforwardProtoTest.java @@ -22,9 +22,9 @@ class DifferentialDriveFeedforwardProtoTest @Override public void checkEquals( DifferentialDriveFeedforward testData, DifferentialDriveFeedforward data) { - assertEquals(testData.m_kVLinear, data.m_kVLinear); - assertEquals(testData.m_kALinear, data.m_kALinear); - assertEquals(testData.m_kVAngular, data.m_kVAngular); - assertEquals(testData.m_kAAngular, data.m_kAAngular); + assertEquals(testData.kVLinear, data.kVLinear); + assertEquals(testData.kALinear, data.kALinear); + assertEquals(testData.kVAngular, data.kVAngular); + assertEquals(testData.kAAngular, data.kAAngular); } } diff --git a/wpimath/src/test/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStructTest.java b/wpimath/src/test/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStructTest.java index 1d95b5405bb..04bc82e19e6 100644 --- a/wpimath/src/test/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStructTest.java +++ b/wpimath/src/test/java/org/wpilib/math/controller/struct/DifferentialDriveFeedforwardStructTest.java @@ -20,9 +20,9 @@ class DifferentialDriveFeedforwardStructTest extends StructTestBase Date: Wed, 4 Jun 2025 08:31:11 -0400 Subject: [PATCH 3/4] Add new rules --- .../org/wpilib/vision/apriltag/AprilTag.java | 2 +- .../vision/apriltag/AprilTagFieldLayout.java | 12 +- .../vision/apriltag/AprilTagFields.java | 2 +- .../vision/apriltag/AprilTagDetectorTest.java | 3 +- .../wpilib/vision/stream/CameraServer.java | 182 +++--- .../org/wpilib/command2/button/Trigger.java | 2 +- .../cpp/frc2/command/sysid/SysIdRoutine.cpp | 32 +- .../wpi/commands2/sysid/SysIdRoutine.hpp | 50 +- .../command2/button/NetworkButtonTest.java | 12 +- .../command2/sysid/SysIdRoutineTest.java | 118 ++-- .../java/org/wpilib/command3/Binding.java | 2 +- .../org/wpilib/command3/CommandState.java | 16 +- .../wpilib/command3/CommandTraceHelper.java | 2 +- .../org/wpilib/command3/Continuation.java | 14 +- .../wpilib/command3/ContinuationScope.java | 8 +- .../org/wpilib/command3/SchedulerTest.java | 2 +- .../org/wpilib/vision/camera/ImageSource.java | 2 +- .../wpilib/vision/camera/VideoProperty.java | 26 +- .../org/wpilib/datalog/DoubleLogEntry.java | 4 +- .../org/wpilib/datalog/FloatLogEntry.java | 4 +- .../org/wpilib/datalog/IntegerLogEntry.java | 4 +- .../java/org/wpilib/datalog/DataLogTest.java | 47 +- .../epilogue/processor/EpilogueGenerator.java | 4 +- .../org/wpilib/hardware/hal/OpModeOption.java | 6 - .../hardware/hal/PowerDistributionFaults.java | 2 +- .../hal/PowerDistributionStickyFaults.java | 2 +- .../org/wpilib/hardware/hal/REVPHFaults.java | 2 +- .../hardware/hal/REVPHStickyFaults.java | 2 +- .../hardware/hal/can/CANReceiveMessage.java | 4 - .../hardware/hal/simulation/AlertDataJNI.java | 5 - .../CoroutineYieldInLoopDetector.java | 44 +- .../wpilib/networktables/ConnectionInfo.java | 20 +- shared/java/javastyle.gradle | 3 + styleguide/checkstyle.xml | 7 - styleguide/pmd-ruleset.xml | 37 +- .../src/test/native/cpp/TimedRobotTest.cpp | 582 +++++++++--------- .../internal/DriverStationBackend.java | 272 ++++---- .../java/org/wpilib/framework/RobotBase.java | 2 +- .../java/org/wpilib/framework/TimedRobot.java | 1 - .../hardware/accelerometer/ADXL345_I2C.java | 1 - .../wpilib/hardware/discrete/AnalogInput.java | 2 +- .../hardware/expansionhub/ExpansionHub.java | 52 +- .../wpilib/hardware/led/AddressableLED.java | 8 +- .../hardware/led/AddressableLEDBuffer.java | 18 +- .../hardware/pneumatic/PneumaticHub.java | 76 +-- .../pneumatic/PneumaticsControlModule.java | 68 +- .../org/wpilib/hardware/range/SharpIR.java | 4 + .../wpilib/hardware/rotation/DutyCycle.java | 3 +- .../org/wpilib/hardware/rotation/Encoder.java | 2 +- .../internal/PeriodicPriorityQueue.java | 50 +- .../java/org/wpilib/simulation/AlertSim.java | 5 - .../simulation/DifferentialDrivetrainSim.java | 2 +- .../org/wpilib/smartdashboard/Field2d.java | 6 +- .../wpilib/smartdashboard/FieldObject2d.java | 20 +- .../smartdashboard/ListenerExecutor.java | 2 +- .../smartdashboard/SendableBuilderImpl.java | 1 + .../main/java/org/wpilib/system/Watchdog.java | 4 +- .../wpilib/event/NetworkBooleanEventTest.java | 12 +- .../org/wpilib/framework/OpModeRobotTest.java | 41 +- .../org/wpilib/framework/TimedRobotTest.java | 582 +++++++++--------- .../wpilib/framework/TimesliceRobotTest.java | 12 +- .../led/AddressableLEDBufferTest.java | 6 +- .../wpilib/hardware/led/LEDPatternTest.java | 52 +- .../wpilib/math/estimator/PoseEstimator.java | 2 +- .../math/estimator/PoseEstimator3d.java | 2 +- .../wpilib/math/geometry/CoordinateAxis.java | 4 +- .../math/geometry/CoordinateSystem.java | 6 +- .../LTVDifferentialDriveControllerTest.java | 10 +- .../math/controller/LinearSystemLoopTest.java | 10 +- .../java/org/wpilib/math/linalg/DARETest.java | 3 +- .../trajectory/ExponentialProfileTest.java | 6 +- .../java/org/wpilib/units/ExampleUnit.java | 2 +- .../util/sendable/SendableRegistry.java | 1 + .../org/wpilib/util/struct/DynamicStruct.java | 88 +-- .../wpilib/util/struct/StructDescriptor.java | 52 +- .../util/struct/StructDescriptorDatabase.java | 12 +- .../util/struct/StructFieldDescriptor.java | 22 +- .../org/wpilib/util/struct/parser/Lexer.java | 26 +- .../org/wpilib/util/struct/parser/Parser.java | 12 +- .../org/wpilib/util/ConstructorMatchTest.java | 6 +- .../wpilib/util/cleanup/CleanupPoolTest.java | 16 +- .../util/cleanup/ReflectionCleanupTest.java | 28 +- .../wpilib/util/struct/DynamicStructTest.java | 5 +- .../util/struct/StructGeneratorTest.java | 18 +- 84 files changed, 1455 insertions(+), 1446 deletions(-) diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java index 3e6c0d48779..394014381b8 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTag.java @@ -15,7 +15,7 @@ public class AprilTag { /** The tag's ID. */ @Json.Property("ID") - @SuppressWarnings("MemberName") + @SuppressWarnings("PMD.PublicFieldNamingConvention") public int ID; /** The tag's pose. */ diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java index 2c125f36475..cc4734674a6 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java @@ -51,6 +51,7 @@ public enum OriginPosition { @Json.Ignore private final Map m_apriltags = new HashMap<>(); @Json.Property("field") + @SuppressWarnings("PMD.PublicFieldNamingConvention") FieldDimensions m_fieldDimensions; @Json.Ignore private Pose3d m_origin; @@ -216,9 +217,9 @@ public void serialize(Path path) throws IOException { * @throws UncheckedIOException If the layout does not exist. */ public static AprilTagFieldLayout loadField(AprilTagFields field) { - if (field.m_fieldLayout == null) { + if (field.fieldLayout == null) { try { - field.m_fieldLayout = loadFromResource(field.resourceFile); + field.fieldLayout = loadFromResource(field.resourceFile); } catch (IOException e) { throw new UncheckedIOException( "Could not load AprilTagFieldLayout from " + field.resourceFile, e); @@ -226,9 +227,9 @@ public static AprilTagFieldLayout loadField(AprilTagFields field) { } // Copy layout because the layout's origin is mutable return new AprilTagFieldLayout( - field.m_fieldLayout.getTags(), - field.m_fieldLayout.getFieldLength(), - field.m_fieldLayout.getFieldWidth()); + field.fieldLayout.getTags(), + field.fieldLayout.getFieldLength(), + field.fieldLayout.getFieldWidth()); } /** @@ -263,6 +264,7 @@ public int hashCode() { return Objects.hash(m_apriltags, m_origin); } + @SuppressWarnings("PMD.PublicMemberInNonPublicType") static class FieldDimensions { @Json.Property(value = "length") public final double fieldLength; diff --git a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java index d2169d309bc..fe3ce21a47f 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java @@ -30,7 +30,7 @@ public enum AprilTagFields { /** Resource filename. */ public final String resourceFile; - AprilTagFieldLayout m_fieldLayout; + AprilTagFieldLayout fieldLayout; AprilTagFields(String resourceFile) { this.resourceFile = kBaseResourceDir + resourceFile; diff --git a/apriltag/src/test/java/org/wpilib/vision/apriltag/AprilTagDetectorTest.java b/apriltag/src/test/java/org/wpilib/vision/apriltag/AprilTagDetectorTest.java index 1678997f1e7..a026edbc01e 100644 --- a/apriltag/src/test/java/org/wpilib/vision/apriltag/AprilTagDetectorTest.java +++ b/apriltag/src/test/java/org/wpilib/vision/apriltag/AprilTagDetectorTest.java @@ -25,7 +25,6 @@ import org.wpilib.util.runtime.RuntimeLoader; class AprilTagDetectorTest { - @SuppressWarnings("MemberName") AprilTagDetector detector; @BeforeAll @@ -110,7 +109,7 @@ void testRemoveFamily() { detector.removeFamily("tag16h5"); } - public Mat loadImage(String resource) throws IOException { + Mat loadImage(String resource) throws IOException { Mat encoded; try (InputStream is = getClass().getResource(resource).openStream()) { try (ByteArrayOutputStream os = new ByteArrayOutputStream(is.available())) { diff --git a/cameraserver/src/main/java/org/wpilib/vision/stream/CameraServer.java b/cameraserver/src/main/java/org/wpilib/vision/stream/CameraServer.java index 73a3dc21012..8a1e93cc855 100644 --- a/cameraserver/src/main/java/org/wpilib/vision/stream/CameraServer.java +++ b/cameraserver/src/main/java/org/wpilib/vision/stream/CameraServer.java @@ -60,28 +60,28 @@ private static final class PropertyPublisher implements AutoCloseable { try { switch (event.propertyKind) { case kBoolean: - m_booleanValueEntry = table.getBooleanTopic(name).getEntry(false); - m_booleanValueEntry.setDefault(event.value != 0); + booleanValueEntry = table.getBooleanTopic(name).getEntry(false); + booleanValueEntry.setDefault(event.value != 0); break; case kEnum: - m_choicesTopic = table.getStringArrayTopic(infoName + "/choices"); + choicesTopic = table.getStringArrayTopic(infoName + "/choices"); // fallthrough case kInteger: - m_integerValueEntry = table.getIntegerTopic(name).getEntry(0); - m_minPublisher = table.getIntegerTopic(infoName + "/min").publish(); - m_maxPublisher = table.getIntegerTopic(infoName + "/max").publish(); - m_stepPublisher = table.getIntegerTopic(infoName + "/step").publish(); - m_defaultPublisher = table.getIntegerTopic(infoName + "/default").publish(); - - m_integerValueEntry.setDefault(event.value); - m_minPublisher.set(CameraServerJNI.getPropertyMin(event.propertyHandle)); - m_maxPublisher.set(CameraServerJNI.getPropertyMax(event.propertyHandle)); - m_stepPublisher.set(CameraServerJNI.getPropertyStep(event.propertyHandle)); - m_defaultPublisher.set(CameraServerJNI.getPropertyDefault(event.propertyHandle)); + integerValueEntry = table.getIntegerTopic(name).getEntry(0); + minPublisher = table.getIntegerTopic(infoName + "/min").publish(); + maxPublisher = table.getIntegerTopic(infoName + "/max").publish(); + stepPublisher = table.getIntegerTopic(infoName + "/step").publish(); + defaultPublisher = table.getIntegerTopic(infoName + "/default").publish(); + + integerValueEntry.setDefault(event.value); + minPublisher.set(CameraServerJNI.getPropertyMin(event.propertyHandle)); + maxPublisher.set(CameraServerJNI.getPropertyMax(event.propertyHandle)); + stepPublisher.set(CameraServerJNI.getPropertyStep(event.propertyHandle)); + defaultPublisher.set(CameraServerJNI.getPropertyDefault(event.propertyHandle)); break; case kString: - m_stringValueEntry = table.getStringTopic(name).getEntry(""); - m_stringValueEntry.setDefault(event.valueStr); + stringValueEntry = table.getStringTopic(name).getEntry(""); + stringValueEntry.setDefault(event.valueStr); break; default: break; @@ -94,18 +94,18 @@ private static final class PropertyPublisher implements AutoCloseable { void update(VideoEvent event) { switch (event.propertyKind) { case kBoolean -> { - if (m_booleanValueEntry != null) { - m_booleanValueEntry.set(event.value != 0); + if (booleanValueEntry != null) { + booleanValueEntry.set(event.value != 0); } } case kInteger, kEnum -> { - if (m_integerValueEntry != null) { - m_integerValueEntry.set(event.value); + if (integerValueEntry != null) { + integerValueEntry.set(event.value); } } case kString -> { - if (m_stringValueEntry != null) { - m_stringValueEntry.set(event.valueStr); + if (stringValueEntry != null) { + stringValueEntry.set(event.valueStr); } } default -> { @@ -117,65 +117,65 @@ void update(VideoEvent event) { @Override public void close() { try { - if (m_booleanValueEntry != null) { - m_booleanValueEntry.close(); + if (booleanValueEntry != null) { + booleanValueEntry.close(); } - if (m_integerValueEntry != null) { - m_integerValueEntry.close(); + if (integerValueEntry != null) { + integerValueEntry.close(); } - if (m_stringValueEntry != null) { - m_stringValueEntry.close(); + if (stringValueEntry != null) { + stringValueEntry.close(); } - if (m_minPublisher != null) { - m_minPublisher.close(); + if (minPublisher != null) { + minPublisher.close(); } - if (m_maxPublisher != null) { - m_maxPublisher.close(); + if (maxPublisher != null) { + maxPublisher.close(); } - if (m_stepPublisher != null) { - m_stepPublisher.close(); + if (stepPublisher != null) { + stepPublisher.close(); } - if (m_defaultPublisher != null) { - m_defaultPublisher.close(); + if (defaultPublisher != null) { + defaultPublisher.close(); } - if (m_choicesPublisher != null) { - m_choicesPublisher.close(); + if (choicesPublisher != null) { + choicesPublisher.close(); } } finally { Reference.reachabilityFence(m_videoListener); } } - BooleanEntry m_booleanValueEntry; - IntegerEntry m_integerValueEntry; - StringEntry m_stringValueEntry; - IntegerPublisher m_minPublisher; - IntegerPublisher m_maxPublisher; - IntegerPublisher m_stepPublisher; - IntegerPublisher m_defaultPublisher; - StringArrayTopic m_choicesTopic; - StringArrayPublisher m_choicesPublisher; + BooleanEntry booleanValueEntry; + IntegerEntry integerValueEntry; + StringEntry stringValueEntry; + IntegerPublisher minPublisher; + IntegerPublisher maxPublisher; + IntegerPublisher stepPublisher; + IntegerPublisher defaultPublisher; + StringArrayTopic choicesTopic; + StringArrayPublisher choicesPublisher; } private static final class SourcePublisher implements AutoCloseable { SourcePublisher(NetworkTable table, int sourceHandle) { - this.m_table = table; - m_sourcePublisher = table.getStringTopic("source").publish(); - m_descriptionPublisher = table.getStringTopic("description").publish(); - m_connectedPublisher = table.getBooleanTopic("connected").publish(); - m_streamsPublisher = table.getStringArrayTopic("streams").publish(); - m_modeEntry = table.getStringTopic("mode").getEntry(""); - m_modesPublisher = table.getStringArrayTopic("modes").publish(); - - m_sourcePublisher.set(makeSourceValue(sourceHandle)); - m_descriptionPublisher.set(CameraServerJNI.getSourceDescription(sourceHandle)); - m_connectedPublisher.set(CameraServerJNI.isSourceConnected(sourceHandle)); - m_streamsPublisher.set(getSourceStreamValues(sourceHandle)); + this.table = table; + sourceUriPublisher = table.getStringTopic("source").publish(); + descriptionPublisher = table.getStringTopic("description").publish(); + connectedPublisher = table.getBooleanTopic("connected").publish(); + streamsPublisher = table.getStringArrayTopic("streams").publish(); + modeEntry = table.getStringTopic("mode").getEntry(""); + modesPublisher = table.getStringArrayTopic("modes").publish(); + + sourceUriPublisher.set(makeSourceValue(sourceHandle)); + descriptionPublisher.set(CameraServerJNI.getSourceDescription(sourceHandle)); + connectedPublisher.set(CameraServerJNI.isSourceConnected(sourceHandle)); + streamsPublisher.set(getSourceStreamValues(sourceHandle)); try { VideoMode mode = CameraServerJNI.getSourceVideoMode(sourceHandle); - m_modeEntry.setDefault(videoModeToString(mode)); - m_modesPublisher.set(getSourceModeValues(sourceHandle)); + modeEntry.setDefault(videoModeToString(mode)); + modesPublisher.set(getSourceModeValues(sourceHandle)); } catch (VideoException ignored) { // Do nothing. Let the other event handlers update this if there is an error. } @@ -183,25 +183,25 @@ private static final class SourcePublisher implements AutoCloseable { @Override public void close() throws Exception { - m_sourcePublisher.close(); - m_descriptionPublisher.close(); - m_connectedPublisher.close(); - m_streamsPublisher.close(); - m_modeEntry.close(); - m_modesPublisher.close(); - for (PropertyPublisher pp : m_properties.values()) { + sourceUriPublisher.close(); + descriptionPublisher.close(); + connectedPublisher.close(); + streamsPublisher.close(); + modeEntry.close(); + modesPublisher.close(); + for (PropertyPublisher pp : properties.values()) { pp.close(); } } - final NetworkTable m_table; - final StringPublisher m_sourcePublisher; - final StringPublisher m_descriptionPublisher; - final BooleanPublisher m_connectedPublisher; - final StringArrayPublisher m_streamsPublisher; - final StringEntry m_modeEntry; - final StringArrayPublisher m_modesPublisher; - final Map m_properties = new HashMap<>(); + final NetworkTable table; + final StringPublisher sourceUriPublisher; + final StringPublisher descriptionPublisher; + final BooleanPublisher connectedPublisher; + final StringArrayPublisher streamsPublisher; + final StringEntry modeEntry; + final StringArrayPublisher modesPublisher; + final Map properties = new HashMap<>(); } private static final AtomicInteger m_defaultUsbDevice = new AtomicInteger(); @@ -253,40 +253,40 @@ public void close() throws Exception { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { // update the description too (as it may have changed) - publisher.m_descriptionPublisher.set( + publisher.descriptionPublisher.set( CameraServerJNI.getSourceDescription(event.sourceHandle)); - publisher.m_connectedPublisher.set(true); + publisher.connectedPublisher.set(true); } } case kSourceDisconnected -> { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { - publisher.m_connectedPublisher.set(false); + publisher.connectedPublisher.set(false); } } case kSourceVideoModesUpdated -> { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { - publisher.m_modesPublisher.set(getSourceModeValues(event.sourceHandle)); + publisher.modesPublisher.set(getSourceModeValues(event.sourceHandle)); } } case kSourceVideoModeChanged -> { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { - publisher.m_modeEntry.set(videoModeToString(event.mode)); + publisher.modeEntry.set(videoModeToString(event.mode)); } } case kSourcePropertyCreated -> { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { - publisher.m_properties.put( - event.propertyHandle, new PropertyPublisher(publisher.m_table, event)); + publisher.properties.put( + event.propertyHandle, new PropertyPublisher(publisher.table, event)); } } case kSourcePropertyValueUpdated -> { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { - PropertyPublisher pp = publisher.m_properties.get(event.propertyHandle); + PropertyPublisher pp = publisher.properties.get(event.propertyHandle); if (pp != null) { pp.update(event); } @@ -295,15 +295,15 @@ public void close() throws Exception { case kSourcePropertyChoicesUpdated -> { SourcePublisher publisher = m_publishers.get(event.sourceHandle); if (publisher != null) { - PropertyPublisher pp = publisher.m_properties.get(event.propertyHandle); - if (pp != null && pp.m_choicesTopic != null) { + PropertyPublisher pp = publisher.properties.get(event.propertyHandle); + if (pp != null && pp.choicesTopic != null) { try { String[] choices = CameraServerJNI.getEnumPropertyChoices(event.propertyHandle); - if (pp.m_choicesPublisher == null) { - pp.m_choicesPublisher = pp.m_choicesTopic.publish(); + if (pp.choicesPublisher == null) { + pp.choicesPublisher = pp.choicesTopic.publish(); } - pp.m_choicesPublisher.set(choices); + pp.choicesPublisher.set(choices); } catch (VideoException ignored) { // ignore (just don't publish choices if we can't get them) } @@ -459,7 +459,7 @@ private static synchronized void updateStreamValues() { // Set table value String[] values = getSinkStreamValues(sink); if (values.length > 0) { - publisher.m_streamsPublisher.set(values); + publisher.streamsPublisher.set(values); } } } @@ -474,7 +474,7 @@ private static synchronized void updateStreamValues() { // Set table value String[] values = getSourceStreamValues(source); if (values.length > 0) { - publisher.m_streamsPublisher.set(values); + publisher.streamsPublisher.set(values); } } } diff --git a/commandsv2/src/main/java/org/wpilib/command2/button/Trigger.java b/commandsv2/src/main/java/org/wpilib/command2/button/Trigger.java index cf0980b8b05..0e5ccd1d885 100644 --- a/commandsv2/src/main/java/org/wpilib/command2/button/Trigger.java +++ b/commandsv2/src/main/java/org/wpilib/command2/button/Trigger.java @@ -280,7 +280,7 @@ public Trigger debounce(double seconds, Debouncer.DebounceType type) { return new Trigger( m_loop, new BooleanSupplier() { - final Debouncer m_debouncer = new Debouncer(seconds, type); + private final Debouncer m_debouncer = new Debouncer(seconds, type); @Override public boolean getAsBoolean() { diff --git a/commandsv2/src/main/native/cpp/frc2/command/sysid/SysIdRoutine.cpp b/commandsv2/src/main/native/cpp/frc2/command/sysid/SysIdRoutine.cpp index 089fdb8c929..07ae68f2dc7 100644 --- a/commandsv2/src/main/native/cpp/frc2/command/sysid/SysIdRoutine.cpp +++ b/commandsv2/src/main/native/cpp/frc2/command/sysid/SysIdRoutine.cpp @@ -18,24 +18,24 @@ wpi::cmd::CommandPtr SysIdRoutine::Quasistatic(Direction direction) { double outputSign = direction == Direction::kForward ? 1.0 : -1.0; - return m_mechanism.m_subsystem->RunOnce([this] { timer.Restart(); }) + return m_mechanism.subsystem->RunOnce([this] { timer.Restart(); }) .AndThen( - m_mechanism.m_subsystem + m_mechanism.subsystem ->Run([this, state, outputSign] { - m_outputVolts = outputSign * timer.Get() * m_config.m_rampRate; - m_mechanism.m_drive(m_outputVolts); - m_mechanism.m_log(this); + m_outputVolts = outputSign * timer.Get() * m_config.rampRate; + m_mechanism.drive(m_outputVolts); + m_mechanism.log(this); m_recordState(state); }) .FinallyDo([this] { - m_mechanism.m_drive(0_V); + m_mechanism.drive(0_V); m_recordState(wpi::sysid::State::NONE); timer.Stop(); }) .WithName("sysid-" + wpi::sysid::SysIdRoutineLog::StateEnumToString(state) + - "-" + m_mechanism.m_name) - .WithTimeout(m_config.m_timeout)); + "-" + m_mechanism.name) + .WithTimeout(m_config.timeout)); } wpi::cmd::CommandPtr SysIdRoutine::Dynamic(Direction direction) { @@ -48,19 +48,19 @@ wpi::cmd::CommandPtr SysIdRoutine::Dynamic(Direction direction) { double outputSign = direction == Direction::kForward ? 1.0 : -1.0; - return m_mechanism.m_subsystem - ->RunOnce([this] { m_outputVolts = m_config.m_stepVoltage; }) - .AndThen(m_mechanism.m_subsystem->Run([this, state, outputSign] { - m_mechanism.m_drive(m_outputVolts * outputSign); - m_mechanism.m_log(this); + return m_mechanism.subsystem + ->RunOnce([this] { m_outputVolts = m_config.stepVoltage; }) + .AndThen(m_mechanism.subsystem->Run([this, state, outputSign] { + m_mechanism.drive(m_outputVolts * outputSign); + m_mechanism.log(this); m_recordState(state); })) .FinallyDo([this] { - m_mechanism.m_drive(0_V); + m_mechanism.drive(0_V); m_recordState(wpi::sysid::State::NONE); }) .WithName("sysid-" + wpi::sysid::SysIdRoutineLog::StateEnumToString(state) + "-" + - m_mechanism.m_name) - .WithTimeout(m_config.m_timeout); + m_mechanism.name) + .WithTimeout(m_config.timeout); } diff --git a/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp b/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp index 9b78ee611f3..bcfff9a3d52 100644 --- a/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp +++ b/commandsv2/src/main/native/include/wpi/commands2/sysid/SysIdRoutine.hpp @@ -23,17 +23,17 @@ using ramp_rate_t = wpi::units::unit_t m_recordState; + std::function recordState; /** * Create a new configuration for a SysId test routine. @@ -52,15 +52,15 @@ class Config { std::optional stepVoltage, std::optional timeout, std::function recordState) - : m_recordState{std::move(recordState)} { + : recordState{std::move(recordState)} { if (rampRate) { - m_rampRate = rampRate.value(); + this->rampRate = rampRate.value(); } if (stepVoltage) { - m_stepVoltage = stepVoltage.value(); + this->stepVoltage = stepVoltage.value(); } if (timeout) { - m_timeout = timeout.value(); + this->timeout = timeout.value(); } } }; @@ -69,19 +69,19 @@ class Mechanism { public: /// Sends the SysId-specified drive signal to the mechanism motors during test /// routines. - std::function m_drive; + std::function drive; /// Returns measured data (voltages, positions, velocities) of the mechanism /// motors during test routines. - std::function m_log; + std::function log; /// The subsystem containing the motor(s) that is (or are) being /// characterized. - wpi::cmd::Subsystem* m_subsystem; + wpi::cmd::Subsystem* subsystem; /// The name of the mechanism being tested. Will be appended to the log entry /// title for the routine's test state, e.g. "sysid-test-state-mechanism". - std::string m_name; + std::string name; /** * Create a new mechanism specification for a SysId routine. @@ -105,10 +105,10 @@ class Mechanism { Mechanism(std::function drive, std::function log, wpi::cmd::Subsystem* subsystem, std::string_view name) - : m_drive{std::move(drive)}, - m_log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}}, - m_subsystem{subsystem}, - m_name{name} {} + : drive{std::move(drive)}, + log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}}, + subsystem{subsystem}, + name{name} {} /** * Create a new mechanism specification for a SysId routine. Defaults the @@ -130,10 +130,10 @@ class Mechanism { Mechanism(std::function drive, std::function log, wpi::cmd::Subsystem* subsystem) - : m_drive{std::move(drive)}, - m_log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}}, - m_subsystem{subsystem}, - m_name{m_subsystem->GetName()} {} + : drive{std::move(drive)}, + log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}}, + subsystem{subsystem}, + name{subsystem->GetName()} {} }; /** @@ -176,13 +176,13 @@ class SysIdRoutine : public wpi::sysid::SysIdRoutineLog { * @param mechanism Hardware interface for the SysId routine. */ SysIdRoutine(Config config, Mechanism mechanism) - : SysIdRoutineLog(mechanism.m_name), + : SysIdRoutineLog(mechanism.name), m_config(config), m_mechanism(mechanism), - m_recordState(config.m_recordState ? config.m_recordState - : [this](wpi::sysid::State state) { - this->RecordState(state); - }) {} + m_recordState(config.recordState ? config.recordState + : [this](wpi::sysid::State state) { + this->RecordState(state); + }) {} wpi::cmd::CommandPtr Quasistatic(Direction direction); wpi::cmd::CommandPtr Dynamic(Direction direction); diff --git a/commandsv2/src/test/java/org/wpilib/command2/button/NetworkButtonTest.java b/commandsv2/src/test/java/org/wpilib/command2/button/NetworkButtonTest.java index 94ef8a96947..0ad3492f34f 100644 --- a/commandsv2/src/test/java/org/wpilib/command2/button/NetworkButtonTest.java +++ b/commandsv2/src/test/java/org/wpilib/command2/button/NetworkButtonTest.java @@ -15,17 +15,17 @@ import org.wpilib.networktables.NetworkTableInstance; class NetworkButtonTest extends CommandTestBase { - NetworkTableInstance m_inst; + NetworkTableInstance inst; @BeforeEach void setup() { - m_inst = NetworkTableInstance.create(); - m_inst.startLocal(); + inst = NetworkTableInstance.create(); + inst.startLocal(); } @AfterEach void teardown() { - m_inst.close(); + inst.close(); } @Test @@ -33,9 +33,9 @@ void setNetworkButtonTest() { var scheduler = CommandScheduler.getInstance(); var commandHolder = new MockCommandHolder(true); var command = commandHolder.getMock(); - var pub = m_inst.getTable("TestTable").getBooleanTopic("Test").publish(); + var pub = inst.getTable("TestTable").getBooleanTopic("Test").publish(); - var button = new NetworkButton(m_inst, "TestTable", "Test"); + var button = new NetworkButton(inst, "TestTable", "Test"); pub.set(false); button.onTrue(command); scheduler.run(); diff --git a/commandsv2/src/test/java/org/wpilib/command2/sysid/SysIdRoutineTest.java b/commandsv2/src/test/java/org/wpilib/command2/sysid/SysIdRoutineTest.java index f201147f99f..f7e7bc48369 100644 --- a/commandsv2/src/test/java/org/wpilib/command2/sysid/SysIdRoutineTest.java +++ b/commandsv2/src/test/java/org/wpilib/command2/sysid/SysIdRoutineTest.java @@ -32,12 +32,12 @@ interface Mechanism extends Subsystem { void log(SysIdRoutineLog log); } - Mechanism m_mechanism; - SysIdRoutine m_sysidRoutine; - Command m_quasistaticForward; - Command m_quasistaticReverse; - Command m_dynamicForward; - Command m_dynamicReverse; + Mechanism mechanism; + SysIdRoutine sysidRoutine; + Command quasistaticForward; + Command quasistaticReverse; + Command dynamicForward; + Command dynamicReverse; void runCommand(Command command) { command.initialize(); @@ -52,15 +52,15 @@ void runCommand(Command command) { void setup() { HAL.initialize(500, 0); SimHooks.pauseTiming(); - m_mechanism = mock(Mechanism.class); - m_sysidRoutine = + mechanism = mock(Mechanism.class); + sysidRoutine = new SysIdRoutine( - new SysIdRoutine.Config(null, null, null, m_mechanism::recordState), - new SysIdRoutine.Mechanism(m_mechanism::drive, m_mechanism::log, new Subsystem() {})); - m_quasistaticForward = m_sysidRoutine.quasistatic(SysIdRoutine.Direction.kForward); - m_quasistaticReverse = m_sysidRoutine.quasistatic(SysIdRoutine.Direction.kReverse); - m_dynamicForward = m_sysidRoutine.dynamic(SysIdRoutine.Direction.kForward); - m_dynamicReverse = m_sysidRoutine.dynamic(SysIdRoutine.Direction.kReverse); + new SysIdRoutine.Config(null, null, null, mechanism::recordState), + new SysIdRoutine.Mechanism(mechanism::drive, mechanism::log, new Subsystem() {})); + quasistaticForward = sysidRoutine.quasistatic(SysIdRoutine.Direction.kForward); + quasistaticReverse = sysidRoutine.quasistatic(SysIdRoutine.Direction.kReverse); + dynamicForward = sysidRoutine.dynamic(SysIdRoutine.Direction.kForward); + dynamicReverse = sysidRoutine.dynamic(SysIdRoutine.Direction.kReverse); } @AfterEach @@ -70,74 +70,74 @@ void cleanupAll() { @Test void recordStateBookendsMotorLogging() { - runCommand(m_quasistaticForward); + runCommand(quasistaticForward); - var orderCheck = inOrder(m_mechanism); + var orderCheck = inOrder(mechanism); - orderCheck.verify(m_mechanism).recordState(SysIdRoutineLog.State.QUASISTATIC_FORWARD); - orderCheck.verify(m_mechanism).drive(any()); - orderCheck.verify(m_mechanism).log(any()); - orderCheck.verify(m_mechanism).recordState(SysIdRoutineLog.State.NONE); + orderCheck.verify(mechanism).recordState(SysIdRoutineLog.State.QUASISTATIC_FORWARD); + orderCheck.verify(mechanism).drive(any()); + orderCheck.verify(mechanism).log(any()); + orderCheck.verify(mechanism).recordState(SysIdRoutineLog.State.NONE); orderCheck.verifyNoMoreInteractions(); - clearInvocations(m_mechanism); - orderCheck = inOrder(m_mechanism); - runCommand(m_dynamicForward); + clearInvocations(mechanism); + orderCheck = inOrder(mechanism); + runCommand(dynamicForward); - orderCheck.verify(m_mechanism).recordState(SysIdRoutineLog.State.DYNAMIC_FORWARD); - orderCheck.verify(m_mechanism).drive(any()); - orderCheck.verify(m_mechanism).log(any()); - orderCheck.verify(m_mechanism).recordState(SysIdRoutineLog.State.NONE); + orderCheck.verify(mechanism).recordState(SysIdRoutineLog.State.DYNAMIC_FORWARD); + orderCheck.verify(mechanism).drive(any()); + orderCheck.verify(mechanism).log(any()); + orderCheck.verify(mechanism).recordState(SysIdRoutineLog.State.NONE); orderCheck.verifyNoMoreInteractions(); } @Test void testsDeclareCorrectState() { - runCommand(m_quasistaticForward); - verify(m_mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.QUASISTATIC_FORWARD); + runCommand(quasistaticForward); + verify(mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.QUASISTATIC_FORWARD); - runCommand(m_quasistaticReverse); - verify(m_mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.QUASISTATIC_REVERSE); + runCommand(quasistaticReverse); + verify(mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.QUASISTATIC_REVERSE); - runCommand(m_dynamicForward); - verify(m_mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.DYNAMIC_FORWARD); + runCommand(dynamicForward); + verify(mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.DYNAMIC_FORWARD); - runCommand(m_dynamicReverse); - verify(m_mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.DYNAMIC_REVERSE); + runCommand(dynamicReverse); + verify(mechanism, atLeastOnce()).recordState(SysIdRoutineLog.State.DYNAMIC_REVERSE); } @Test void testsOutputCorrectVoltage() { - runCommand(m_quasistaticForward); - var orderCheck = inOrder(m_mechanism); + runCommand(quasistaticForward); + var orderCheck = inOrder(mechanism); - orderCheck.verify(m_mechanism, atLeastOnce()).drive(Volts.of(1)); - orderCheck.verify(m_mechanism).drive(Volts.of(0)); - orderCheck.verify(m_mechanism, never()).drive(any()); + orderCheck.verify(mechanism, atLeastOnce()).drive(Volts.of(1)); + orderCheck.verify(mechanism).drive(Volts.of(0)); + orderCheck.verify(mechanism, never()).drive(any()); - clearInvocations(m_mechanism); - runCommand(m_quasistaticReverse); - orderCheck = inOrder(m_mechanism); + clearInvocations(mechanism); + runCommand(quasistaticReverse); + orderCheck = inOrder(mechanism); - orderCheck.verify(m_mechanism, atLeastOnce()).drive(Volts.of(-1)); - orderCheck.verify(m_mechanism).drive(Volts.of(0)); - orderCheck.verify(m_mechanism, never()).drive(any()); + orderCheck.verify(mechanism, atLeastOnce()).drive(Volts.of(-1)); + orderCheck.verify(mechanism).drive(Volts.of(0)); + orderCheck.verify(mechanism, never()).drive(any()); - clearInvocations(m_mechanism); - runCommand(m_dynamicForward); - orderCheck = inOrder(m_mechanism); + clearInvocations(mechanism); + runCommand(dynamicForward); + orderCheck = inOrder(mechanism); - orderCheck.verify(m_mechanism, atLeastOnce()).drive(Volts.of(7)); - orderCheck.verify(m_mechanism).drive(Volts.of(0)); - orderCheck.verify(m_mechanism, never()).drive(any()); + orderCheck.verify(mechanism, atLeastOnce()).drive(Volts.of(7)); + orderCheck.verify(mechanism).drive(Volts.of(0)); + orderCheck.verify(mechanism, never()).drive(any()); - clearInvocations(m_mechanism); - runCommand(m_dynamicForward); - orderCheck = inOrder(m_mechanism); + clearInvocations(mechanism); + runCommand(dynamicForward); + orderCheck = inOrder(mechanism); - runCommand(m_dynamicReverse); - orderCheck.verify(m_mechanism, atLeastOnce()).drive(Volts.of(-7)); - orderCheck.verify(m_mechanism).drive(Volts.of(0)); - orderCheck.verify(m_mechanism, never()).drive(any()); + runCommand(dynamicReverse); + orderCheck.verify(mechanism, atLeastOnce()).drive(Volts.of(-7)); + orderCheck.verify(mechanism).drive(Volts.of(0)); + orderCheck.verify(mechanism, never()).drive(any()); } } diff --git a/commandsv3/src/main/java/org/wpilib/command3/Binding.java b/commandsv3/src/main/java/org/wpilib/command3/Binding.java index 4d79496612e..e138c63dfc1 100644 --- a/commandsv3/src/main/java/org/wpilib/command3/Binding.java +++ b/commandsv3/src/main/java/org/wpilib/command3/Binding.java @@ -17,7 +17,7 @@ * instead of giving a fairly useless backtrace of the command framework. */ record Binding(BindingScope scope, BindingType type, Command command, StackTraceElement[] frames) { - public Binding { + Binding { ErrorMessages.requireNonNullParam(scope, "scope", "Binding"); ErrorMessages.requireNonNullParam(type, "type", "Binding"); ErrorMessages.requireNonNullParam(command, "command", "Binding"); diff --git a/commandsv3/src/main/java/org/wpilib/command3/CommandState.java b/commandsv3/src/main/java/org/wpilib/command3/CommandState.java index 56f1aacb588..351de366210 100644 --- a/commandsv3/src/main/java/org/wpilib/command3/CommandState.java +++ b/commandsv3/src/main/java/org/wpilib/command3/CommandState.java @@ -43,19 +43,19 @@ final class CommandState { m_id = ++s_lastId; } - public Command command() { + Command command() { return m_command; } - public Command parent() { + Command parent() { return m_parent; } - public Coroutine coroutine() { + Coroutine coroutine() { return m_coroutine; } - public Binding binding() { + Binding binding() { return m_binding; } @@ -65,20 +65,20 @@ public Binding binding() { * * @return The runtime, in milliseconds. */ - public double lastRuntimeMs() { + double lastRuntimeMs() { return m_lastRuntimeMs; } - public void setLastRuntimeMs(double lastRuntimeMs) { + void setLastRuntimeMs(double lastRuntimeMs) { m_lastRuntimeMs = lastRuntimeMs; m_totalRuntimeMs += lastRuntimeMs; } - public double totalRuntimeMs() { + double totalRuntimeMs() { return m_totalRuntimeMs; } - public int id() { + int id() { return m_id; } diff --git a/commandsv3/src/main/java/org/wpilib/command3/CommandTraceHelper.java b/commandsv3/src/main/java/org/wpilib/command3/CommandTraceHelper.java index ff8d5c9c55f..66bc1c08ca8 100644 --- a/commandsv3/src/main/java/org/wpilib/command3/CommandTraceHelper.java +++ b/commandsv3/src/main/java/org/wpilib/command3/CommandTraceHelper.java @@ -21,7 +21,7 @@ private CommandTraceHelper() { * @param commandScheduleTrace The trace of when the command was scheduled. * @return A new array of stack trace elements. */ - public static StackTraceElement[] modifyTrace( + static StackTraceElement[] modifyTrace( StackTraceElement[] commandExceptionTrace, StackTraceElement[] commandScheduleTrace) { List frames = new ArrayList<>(); diff --git a/commandsv3/src/main/java/org/wpilib/command3/Continuation.java b/commandsv3/src/main/java/org/wpilib/command3/Continuation.java index 82fbb979bdc..ea028da8e3a 100644 --- a/commandsv3/src/main/java/org/wpilib/command3/Continuation.java +++ b/commandsv3/src/main/java/org/wpilib/command3/Continuation.java @@ -118,7 +118,7 @@ static final class InternalContinuationError extends Error { @SuppressWarnings("PMD.AvoidCatchingGenericException") Continuation(ContinuationScope scope, Runnable target) { try { - m_continuation = CONSTRUCTOR.invoke(scope.m_continuationScope, target); + m_continuation = CONSTRUCTOR.invoke(scope.continuationScope, target); m_scope = scope; } catch (RuntimeException | Error e) { throw e; @@ -134,9 +134,9 @@ static final class InternalContinuationError extends Error { * @throws IllegalStateException if not currently in this continuation's scope */ @SuppressWarnings("PMD.AvoidCatchingGenericException") - public boolean yield() { + boolean yield() { try { - return (boolean) YIELD.invoke(m_scope.m_continuationScope); + return (boolean) YIELD.invoke(m_scope.continuationScope); } catch (RuntimeException | Error e) { throw e; } catch (Throwable t) { @@ -150,7 +150,7 @@ public boolean yield() { * continuation is suspended, it will continue from the most recent yield point. */ @SuppressWarnings("PMD.AvoidCatchingGenericException") - public void run() { + void run() { try { RUN.invoke(m_continuation); } catch (WrongMethodTypeException | ClassCastException e) { @@ -169,7 +169,7 @@ public void run() { * @return whether this continuation is completed */ @SuppressWarnings("PMD.AvoidCatchingGenericException") - public boolean isDone() { + boolean isDone() { try { return (boolean) IS_DONE.invoke(m_continuation); } catch (RuntimeException | Error e) { @@ -187,7 +187,7 @@ public boolean isDone() { * @param continuation the continuation to mount */ @SuppressWarnings("PMD.AvoidCatchingGenericException") - public static void mountContinuation(Continuation continuation) { + static void mountContinuation(Continuation continuation) { try { if (continuation == null) { java_lang_thread_setContinuation.invoke(Thread.currentThread(), null); @@ -215,7 +215,7 @@ public static void mountContinuation(Continuation continuation) { * * @return The continuation mounted on the current thread. */ - public static Continuation getMountedContinuation() { + static Continuation getMountedContinuation() { return mountedContinuation.get(); } diff --git a/commandsv3/src/main/java/org/wpilib/command3/ContinuationScope.java b/commandsv3/src/main/java/org/wpilib/command3/ContinuationScope.java index 2e4c9bcd832..7cd303605b1 100644 --- a/commandsv3/src/main/java/org/wpilib/command3/ContinuationScope.java +++ b/commandsv3/src/main/java/org/wpilib/command3/ContinuationScope.java @@ -10,11 +10,11 @@ import java.util.Objects; /** A continuation scope. */ -@SuppressWarnings("PMD.AvoidCatchingGenericException") +@SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.AvoidFieldNameMatchingTypeName"}) final class ContinuationScope { // The underlying jdk.internal.vm.ContinuationScope object // https://github.com/openjdk/jdk/blob/jdk-21%2B35/src/java.base/share/classes/jdk/internal/vm/ContinuationScope.java - final Object m_continuationScope; + final Object continuationScope; static final Class jdk_internal_vm_ContinuationScope; private static final MethodHandle CONSTRUCTOR; @@ -42,7 +42,7 @@ final class ContinuationScope { ContinuationScope(String name) { Objects.requireNonNull(name); try { - m_continuationScope = CONSTRUCTOR.invoke(name); + continuationScope = CONSTRUCTOR.invoke(name); } catch (Throwable e) { throw new RuntimeException(e); } @@ -50,6 +50,6 @@ final class ContinuationScope { @Override public String toString() { - return m_continuationScope.toString(); + return continuationScope.toString(); } } diff --git a/commandsv3/src/test/java/org/wpilib/command3/SchedulerTest.java b/commandsv3/src/test/java/org/wpilib/command3/SchedulerTest.java index 5e222073a8e..7c0da90e690 100644 --- a/commandsv3/src/test/java/org/wpilib/command3/SchedulerTest.java +++ b/commandsv3/src/test/java/org/wpilib/command3/SchedulerTest.java @@ -132,7 +132,7 @@ void nestedMechanisms() { private final Mechanism m_elevator = new Mechanism("Elevator", m_scheduler); private final Mechanism m_arm = new Mechanism("Arm", m_scheduler); - public Command superCommand() { + Command superCommand() { return run(co -> { co.await(m_elevator.run(Coroutine::park).named("Elevator Subcommand")); co.await(m_arm.run(Coroutine::park).named("Arm Subcommand")); diff --git a/cscore/src/main/java/org/wpilib/vision/camera/ImageSource.java b/cscore/src/main/java/org/wpilib/vision/camera/ImageSource.java index 4b470a61730..688103625ba 100644 --- a/cscore/src/main/java/org/wpilib/vision/camera/ImageSource.java +++ b/cscore/src/main/java/org/wpilib/vision/camera/ImageSource.java @@ -137,6 +137,6 @@ public VideoProperty createStringProperty(String name, String value) { * @param choices Choices */ public void setEnumPropertyChoices(VideoProperty property, String[] choices) { - CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.m_handle, choices); + CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.handle, choices); } } diff --git a/cscore/src/main/java/org/wpilib/vision/camera/VideoProperty.java b/cscore/src/main/java/org/wpilib/vision/camera/VideoProperty.java index 788867640b0..93125b83eb7 100644 --- a/cscore/src/main/java/org/wpilib/vision/camera/VideoProperty.java +++ b/cscore/src/main/java/org/wpilib/vision/camera/VideoProperty.java @@ -57,7 +57,7 @@ public static Kind getKindFromInt(int kind) { * @return Property name. */ public String getName() { - return CameraServerJNI.getPropertyName(m_handle); + return CameraServerJNI.getPropertyName(handle); } /** @@ -120,7 +120,7 @@ public boolean isEnum() { * @return Property value. */ public int get() { - return CameraServerJNI.getProperty(m_handle); + return CameraServerJNI.getProperty(handle); } /** @@ -129,7 +129,7 @@ public int get() { * @param value Property value. */ public void set(int value) { - CameraServerJNI.setProperty(m_handle, value); + CameraServerJNI.setProperty(handle, value); } /** @@ -138,7 +138,7 @@ public void set(int value) { * @return Property minimum value. */ public int getMin() { - return CameraServerJNI.getPropertyMin(m_handle); + return CameraServerJNI.getPropertyMin(handle); } /** @@ -147,7 +147,7 @@ public int getMin() { * @return Property maximum value. */ public int getMax() { - return CameraServerJNI.getPropertyMax(m_handle); + return CameraServerJNI.getPropertyMax(handle); } /** @@ -156,7 +156,7 @@ public int getMax() { * @return Property step size. */ public int getStep() { - return CameraServerJNI.getPropertyStep(m_handle); + return CameraServerJNI.getPropertyStep(handle); } /** @@ -165,7 +165,7 @@ public int getStep() { * @return Property default value. */ public int getDefault() { - return CameraServerJNI.getPropertyDefault(m_handle); + return CameraServerJNI.getPropertyDefault(handle); } /** @@ -176,7 +176,7 @@ public int getDefault() { * @return The string property value. */ public String getString() { - return CameraServerJNI.getStringProperty(m_handle); + return CameraServerJNI.getStringProperty(handle); } /** @@ -187,7 +187,7 @@ public String getString() { * @param value String property value. */ public void setString(String value) { - CameraServerJNI.setStringProperty(m_handle, value); + CameraServerJNI.setStringProperty(handle, value); } /** @@ -198,19 +198,19 @@ public void setString(String value) { * @return The possible values for the enum property value. */ public String[] getChoices() { - return CameraServerJNI.getEnumPropertyChoices(m_handle); + return CameraServerJNI.getEnumPropertyChoices(handle); } VideoProperty(int handle) { - m_handle = handle; + this.handle = handle; m_kind = getKindFromInt(CameraServerJNI.getPropertyKind(handle)); } VideoProperty(int handle, Kind kind) { - m_handle = handle; + this.handle = handle; m_kind = kind; } - int m_handle; + int handle; private final Kind m_kind; } diff --git a/datalog/src/main/java/org/wpilib/datalog/DoubleLogEntry.java b/datalog/src/main/java/org/wpilib/datalog/DoubleLogEntry.java index 98e988f06a2..eab1afe44d6 100644 --- a/datalog/src/main/java/org/wpilib/datalog/DoubleLogEntry.java +++ b/datalog/src/main/java/org/wpilib/datalog/DoubleLogEntry.java @@ -125,6 +125,6 @@ public synchronized double getLastValue() { return m_lastValue; } - boolean m_hasLastValue; - double m_lastValue; + private boolean m_hasLastValue; + private double m_lastValue; } diff --git a/datalog/src/main/java/org/wpilib/datalog/FloatLogEntry.java b/datalog/src/main/java/org/wpilib/datalog/FloatLogEntry.java index cdb51d313de..a0728e7286a 100644 --- a/datalog/src/main/java/org/wpilib/datalog/FloatLogEntry.java +++ b/datalog/src/main/java/org/wpilib/datalog/FloatLogEntry.java @@ -125,6 +125,6 @@ public synchronized float getLastValue() { return m_lastValue; } - boolean m_hasLastValue; - float m_lastValue; + private boolean m_hasLastValue; + private float m_lastValue; } diff --git a/datalog/src/main/java/org/wpilib/datalog/IntegerLogEntry.java b/datalog/src/main/java/org/wpilib/datalog/IntegerLogEntry.java index 6fd5548599c..065c77427a5 100644 --- a/datalog/src/main/java/org/wpilib/datalog/IntegerLogEntry.java +++ b/datalog/src/main/java/org/wpilib/datalog/IntegerLogEntry.java @@ -125,6 +125,6 @@ public synchronized long getLastValue() { return m_lastValue; } - boolean m_hasLastValue; - long m_lastValue; + private boolean m_hasLastValue; + private long m_lastValue; } diff --git a/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java b/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java index 1e0f33acfe7..b5dbdba059f 100644 --- a/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java +++ b/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java @@ -48,7 +48,7 @@ public ImmutableThing unpack(ByteBuffer bb) { @Override public void pack(ByteBuffer bb, ImmutableThing value) { - bb.put(value.m_x); + bb.put(value.x); } @Override @@ -58,23 +58,23 @@ public boolean isImmutable() { } static class ImmutableThing implements StructSerializable { - byte m_x; + byte x; ImmutableThing(int x) { - m_x = (byte) x; + this.x = (byte) x; } @Override public boolean equals(Object obj) { - return obj instanceof ImmutableThing other && other.m_x == m_x; + return obj instanceof ImmutableThing other && other.x == x; } @Override public int hashCode() { - return Objects.hash(m_x); + return Objects.hash(x); } - public static final ImmutableThingStruct struct = new ImmutableThingStruct(); + static final ImmutableThingStruct struct = new ImmutableThingStruct(); } static class CloneableThingStruct implements Struct { @@ -105,7 +105,7 @@ public CloneableThing unpack(ByteBuffer bb) { @Override public void pack(ByteBuffer bb, CloneableThing value) { - bb.put(value.m_x); + bb.put(value.x); } @Override @@ -119,24 +119,23 @@ public CloneableThing clone(CloneableThing obj) throws CloneNotSupportedExceptio } } - @SuppressWarnings("MemberName") private static int cloneCalls; static class CloneableThing implements StructSerializable, Cloneable { - byte m_x; + byte x; CloneableThing(int x) { - m_x = (byte) x; + this.x = (byte) x; } @Override public boolean equals(Object obj) { - return obj instanceof CloneableThing other && other.m_x == m_x; + return obj instanceof CloneableThing other && other.x == x; } @Override public int hashCode() { - return Objects.hash(m_x); + return Objects.hash(x); } @Override @@ -146,7 +145,7 @@ public CloneableThing clone() throws CloneNotSupportedException { return thing; } - public static final CloneableThingStruct struct = new CloneableThingStruct(); + static final CloneableThingStruct struct = new CloneableThingStruct(); } static class ThingStruct implements Struct { @@ -177,45 +176,43 @@ public Thing unpack(ByteBuffer bb) { @Override public void pack(ByteBuffer bb, Thing value) { - bb.put(value.m_x); + bb.put(value.x); } } static class Thing implements StructSerializable { - byte m_x; + byte x; Thing(int x) { - m_x = (byte) x; + this.x = (byte) x; } @Override public boolean equals(Object obj) { - return obj instanceof Thing other && other.m_x == m_x; + return obj instanceof Thing other && other.x == x; } @Override public int hashCode() { - return Objects.hash(m_x); + return Objects.hash(x); } - public static final ThingStruct struct = new ThingStruct(); + static final ThingStruct struct = new ThingStruct(); } - @SuppressWarnings("MemberName") - private ByteArrayOutputStream data; + ByteArrayOutputStream data; - @SuppressWarnings("MemberName") - private DataLog log; + DataLog log; @BeforeEach - public void init() { + void init() { data = new ByteArrayOutputStream(); log = new DataLogWriter(data); cloneCalls = 0; } @AfterEach - public void shutdown() { + void shutdown() { log.close(); } diff --git a/epilogue-processor/src/main/java/org/wpilib/epilogue/processor/EpilogueGenerator.java b/epilogue-processor/src/main/java/org/wpilib/epilogue/processor/EpilogueGenerator.java index ed437431bd6..e136a0ce90c 100644 --- a/epilogue-processor/src/main/java/org/wpilib/epilogue/processor/EpilogueGenerator.java +++ b/epilogue-processor/src/main/java/org/wpilib/epilogue/processor/EpilogueGenerator.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; import java.util.Map; @@ -48,7 +49,8 @@ public void writeEpilogueFile( var centralStore = m_processingEnv.getFiler().createSourceFile("org.wpilib.epilogue.Epilogue"); - try (var out = new PrintWriter(centralStore.openOutputStream())) { + try (var out = + new PrintWriter(centralStore.openOutputStream(), false, StandardCharsets.UTF_8)) { out.println("package org.wpilib.epilogue;"); out.println(); diff --git a/hal/src/main/java/org/wpilib/hardware/hal/OpModeOption.java b/hal/src/main/java/org/wpilib/hardware/hal/OpModeOption.java index 0e471823d88..c003cc1a7bd 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/OpModeOption.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/OpModeOption.java @@ -7,22 +7,16 @@ /** An individual opmode option. */ public class OpModeOption { /** Unique id. Encodes robot mode in bits 57-56, LSB 56 bits is hash of name. */ - @SuppressWarnings("MemberName") public final long id; - @SuppressWarnings("MemberName") public final String name; - @SuppressWarnings("MemberName") public final String group; - @SuppressWarnings("MemberName") public final String description; - @SuppressWarnings("MemberName") public final int textColor; - @SuppressWarnings("MemberName") public final int backgroundColor; /** diff --git a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionFaults.java b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionFaults.java index 2a796f06823..a44ffae2a04 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionFaults.java @@ -8,7 +8,7 @@ * Faults for a PowerDistribution device. These faults are only active while the condition is * active. */ -@SuppressWarnings("MemberName") +@SuppressWarnings("PMD.PublicFieldNamingConvention") public class PowerDistributionFaults { /** Breaker fault on channel 0. */ public final boolean Channel0BreakerFault; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionStickyFaults.java b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionStickyFaults.java index 32eca38281e..37f7727f664 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionStickyFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionStickyFaults.java @@ -8,7 +8,7 @@ * Sticky faults for a PowerDistribution device. These faults will remain active until they are * reset by the user. */ -@SuppressWarnings("MemberName") +@SuppressWarnings("PMD.PublicFieldNamingConvention") public class PowerDistributionStickyFaults { /** Breaker fault on channel 0. */ public final boolean Channel0BreakerFault; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java b/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java index d61da9c5127..306db2871bf 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java @@ -5,7 +5,7 @@ package org.wpilib.hardware.hal; /** Faults for a REV PH. These faults are only active while the condition is active. */ -@SuppressWarnings("MemberName") +@SuppressWarnings("PMD.PublicFieldNamingConvention") public class REVPHFaults { /** Fault on channel 0. */ public final boolean Channel0Fault; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/REVPHStickyFaults.java b/hal/src/main/java/org/wpilib/hardware/hal/REVPHStickyFaults.java index 945d88e5d40..77fd58eef0f 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/REVPHStickyFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/REVPHStickyFaults.java @@ -5,7 +5,7 @@ package org.wpilib.hardware.hal; /** Sticky faults for a REV PH. These faults will remain active until they are reset by the user. */ -@SuppressWarnings("MemberName") +@SuppressWarnings("PMD.PublicFieldNamingConvention") public class REVPHStickyFaults { /** An overcurrent event occurred on the compressor output. */ public final boolean CompressorOverCurrent; diff --git a/hal/src/main/java/org/wpilib/hardware/hal/can/CANReceiveMessage.java b/hal/src/main/java/org/wpilib/hardware/hal/can/CANReceiveMessage.java index 1be388b017f..d17a80f1dd4 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/can/CANReceiveMessage.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/can/CANReceiveMessage.java @@ -7,19 +7,15 @@ /** Represents a CAN message read from a stream. */ public class CANReceiveMessage { /** The message data. */ - @SuppressWarnings("MemberName") public final byte[] data = new byte[64]; /** The length of the data received (0-8 bytes). */ - @SuppressWarnings("MemberName") public int length; /** The flags of the message. */ - @SuppressWarnings("MemberName") public int flags; /** Timestamp message was received, in microseconds (wpi time). */ - @SuppressWarnings("MemberName") public long timestamp; /** Default constructor. */ diff --git a/hal/src/main/java/org/wpilib/hardware/hal/simulation/AlertDataJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/simulation/AlertDataJNI.java index 9d65a3898b2..f25055dc7c7 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/simulation/AlertDataJNI.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/simulation/AlertDataJNI.java @@ -18,19 +18,14 @@ public AlertInfo(int handle, String group, String text, long activeStartTime, in this.level = level; } - @SuppressWarnings("MemberName") public final int handle; - @SuppressWarnings("MemberName") public final String group; - @SuppressWarnings("MemberName") public final String text; - @SuppressWarnings("MemberName") public final long activeStartTime; // 0 if not active - @SuppressWarnings("MemberName") public final int level; // ALERT_LEVEL_HIGH, ALERT_LEVEL_MEDIUM, ALERT_LEVEL_LOW } diff --git a/javacPlugin/src/main/java/org/wpilib/javacplugin/CoroutineYieldInLoopDetector.java b/javacPlugin/src/main/java/org/wpilib/javacplugin/CoroutineYieldInLoopDetector.java index e510a8f4db0..cb383560f91 100644 --- a/javacPlugin/src/main/java/org/wpilib/javacplugin/CoroutineYieldInLoopDetector.java +++ b/javacPlugin/src/main/java/org/wpilib/javacplugin/CoroutineYieldInLoopDetector.java @@ -68,27 +68,27 @@ public CoroutineYieldInLoopDetector(JavacTask task) { */ private static final class LoopState { /** The loop element being tracked. */ - WhileLoopTree m_loop; + WhileLoopTree loop; /** * All discovered calls to Coroutine.yield(). Only applies to calls to coroutines in - * m_availableCoroutines. + * `availableCoroutines`. */ - final List m_yieldCalls = new ArrayList<>(); + final List yieldCalls = new ArrayList<>(); /** * The set of the most local coroutine arguments. eg for nested lambdas, the coroutine arguments * to the innermost lambda will be present, but none of the coroutine arguments from any of the * enclosing lambdas. */ - final List m_availableCoroutines = new ArrayList<>(); + final List availableCoroutines = new ArrayList<>(); /** - * All `while` loops nested inside m_loop. Only applies to direct children; loops in + * All `while` loops nested inside `loop`. Only applies to direct children; loops in * conditionals, switch blocks, and the like will be present, but not loops in other nested * loops, nor loops declared inside a lambda inside a loop. */ - final List m_children = new ArrayList<>(); + final List children = new ArrayList<>(); } private final class Scanner extends TreeScanner { @@ -126,9 +126,9 @@ public LoopState visitMethod(MethodTree node, LoopState loopState) { // Therefore, we do not copy the available coroutines from the parent state to the new // child state. var localState = new LoopState(); - localState.m_availableCoroutines.addAll(coroutineParameters); + localState.availableCoroutines.addAll(coroutineParameters); if (loopState != null) { - loopState.m_children.add(localState); + loopState.children.add(localState); } return super.visitMethod(node, localState); @@ -163,9 +163,9 @@ public LoopState visitLambdaExpression(LambdaExpressionTree node, LoopState loop // Therefore, we do not copy the available coroutines from the parent state to the new // child state. var localState = new LoopState(); - localState.m_availableCoroutines.addAll(coroutineParameters); + localState.availableCoroutines.addAll(coroutineParameters); if (loopState != null) { - loopState.m_children.add(localState); + loopState.children.add(localState); } return super.visitLambdaExpression(node, localState); @@ -184,17 +184,17 @@ public LoopState visitWhileLoop(WhileLoopTree node, LoopState loopState) { return super.visitWhileLoop(node, loopState); } - if (loopState.m_loop == null) { - loopState.m_loop = node; + if (loopState.loop == null) { + loopState.loop = node; var result = super.visitWhileLoop(node, loopState); printErrors(loopState); return result; } else { // Nested loop; split off a new child with the same available coroutines var localState = new LoopState(); - localState.m_loop = node; - localState.m_availableCoroutines.addAll(loopState.m_availableCoroutines); - loopState.m_children.add(localState); + localState.loop = node; + localState.availableCoroutines.addAll(loopState.availableCoroutines); + loopState.children.add(localState); // Don't print errors now - we'll handle that when we finish the parent loop // Otherwise, errors would be printed by the innermost loops first and appear out of order, @@ -207,20 +207,20 @@ private void printErrors(LoopState state) { if (state == null) { return; } - if (state.m_availableCoroutines.isEmpty() || state.m_loop == null) { + if (state.availableCoroutines.isEmpty() || state.loop == null) { // Technically, this state should never be reachable. // But to prevent errors in the compiler plugin from preventing user code from building, // we silently ignore this bad state. return; } - if (state.m_yieldCalls.isEmpty()) { + if (state.yieldCalls.isEmpty()) { m_trees.printMessage( - Diagnostic.Kind.ERROR, buildErrorMessageForLoop(state), state.m_loop, m_root); + Diagnostic.Kind.ERROR, buildErrorMessageForLoop(state), state.loop, m_root); } // Recurse over children - for (var childLoop : state.m_children) { + for (var childLoop : state.children) { printErrors(childLoop); } } @@ -228,7 +228,7 @@ private void printErrors(LoopState state) { private CharSequence buildErrorMessageForLoop(LoopState state) { StringBuilder messageBuilder = new StringBuilder(64).append("Missing call to "); var suggestedFunctionCalls = - state.m_availableCoroutines.stream() + state.availableCoroutines.stream() .map(e -> "`" + e.getSimpleName().toString() + ".yield()`") .toList(); @@ -277,9 +277,9 @@ public LoopState visitMethodInvocation(MethodInvocationTree node, LoopState loop if (recv instanceof IdentifierTree id) { var idPath = m_trees.getPath(m_root, id); var el = m_trees.getElement(idPath); - if (el instanceof VariableElement ve && loopState.m_availableCoroutines.contains(ve)) { + if (el instanceof VariableElement ve && loopState.availableCoroutines.contains(ve)) { // definitely calling yield on a local (method or lambda argument) coroutine object - loopState.m_yieldCalls.add(el); + loopState.yieldCalls.add(el); } } } diff --git a/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java b/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java index f0a0746893b..aeedd02e1b3 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java +++ b/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java @@ -10,25 +10,25 @@ public final class ConnectionInfo { * The remote identifier (as set on the remote node by {@link * NetworkTableInstance#startClient(String)}). */ - public final String remote_id; + public final String remoteId; /** The IP address of the remote node. */ - public final String remote_ip; + public final String remoteIp; /** The port number of the remote node. */ - public final int remote_port; + public final int remotePort; /** * The last time any update was received from the remote node (same scale as returned by {@link * NetworkTablesJNI#now()}). */ - public final long last_update; + public final long lastUpdate; /** * The protocol version being used for this connection. This is in protocol layer format, so * 0x0200 = 2.0, 0x0300 = 3.0). */ - public final int protocol_version; + public final int protocolVersion; /** * Constructor. This should generally only be used internally to NetworkTables. @@ -41,10 +41,10 @@ public final class ConnectionInfo { */ public ConnectionInfo( String remoteId, String remoteIp, int remotePort, long lastUpdate, int protocolVersion) { - remote_id = remoteId; - remote_ip = remoteIp; - remote_port = remotePort; - last_update = lastUpdate; - protocol_version = protocolVersion; + this.remoteId = remoteId; + this.remoteIp = remoteIp; + this.remotePort = remotePort; + this.lastUpdate = lastUpdate; + this.protocolVersion = protocolVersion; } } diff --git a/shared/java/javastyle.gradle b/shared/java/javastyle.gradle index b8771616c30..fc4cc47f8c3 100644 --- a/shared/java/javastyle.gradle +++ b/shared/java/javastyle.gradle @@ -87,3 +87,6 @@ task javaFormat { dependsOn(tasks.withType(Pmd)) } javaFormat.dependsOn 'spotlessApply' +tasks.withType(Checkstyle) { + it.mustRunAfter 'spotlessApply' +} \ No newline at end of file diff --git a/styleguide/checkstyle.xml b/styleguide/checkstyle.xml index e641c16291e..2ca946b2946 100644 --- a/styleguide/checkstyle.xml +++ b/styleguide/checkstyle.xml @@ -168,13 +168,6 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" - - - - - diff --git a/styleguide/pmd-ruleset.xml b/styleguide/pmd-ruleset.xml index 9bbebd1effa..9ed6eb82ae8 100644 --- a/styleguide/pmd-ruleset.xml +++ b/styleguide/pmd-ruleset.xml @@ -70,7 +70,6 @@ - @@ -143,4 +142,40 @@ ]]> + + + + + 3 + + + + + + + + + + + + + 3 + + + + + + + + diff --git a/wpilibc/src/test/native/cpp/TimedRobotTest.cpp b/wpilibc/src/test/native/cpp/TimedRobotTest.cpp index fb372dc6602..f68fc4f4dbb 100644 --- a/wpilibc/src/test/native/cpp/TimedRobotTest.cpp +++ b/wpilibc/src/test/native/cpp/TimedRobotTest.cpp @@ -32,55 +32,55 @@ class TimedRobotTest : public ::testing::Test { class MockRobot : public TimedRobot { public: - std::atomic m_simulationInitCount{0}; - std::atomic m_disabledInitCount{0}; - std::atomic m_autonomousInitCount{0}; - std::atomic m_teleopInitCount{0}; - std::atomic m_testInitCount{0}; - - std::atomic m_disabledExitCount{0}; - std::atomic m_autonomousExitCount{0}; - std::atomic m_teleopExitCount{0}; - std::atomic m_testExitCount{0}; - - std::atomic m_robotPeriodicCount{0}; - std::atomic m_simulationPeriodicCount{0}; - std::atomic m_disabledPeriodicCount{0}; - std::atomic m_autonomousPeriodicCount{0}; - std::atomic m_teleopPeriodicCount{0}; - std::atomic m_testPeriodicCount{0}; + std::atomic simulationInitCount{0}; + std::atomic disabledInitCount{0}; + std::atomic autonomousInitCount{0}; + std::atomic teleopInitCount{0}; + std::atomic testInitCount{0}; + + std::atomic disabledExitCount{0}; + std::atomic autonomousExitCount{0}; + std::atomic teleopExitCount{0}; + std::atomic testExitCount{0}; + + std::atomic robotPeriodicCount{0}; + std::atomic simulationPeriodicCount{0}; + std::atomic disabledPeriodicCount{0}; + std::atomic autonomousPeriodicCount{0}; + std::atomic teleopPeriodicCount{0}; + std::atomic testPeriodicCount{0}; MockRobot() : TimedRobot{kPeriod} {} - void SimulationInit() override { m_simulationInitCount++; } + void SimulationInit() override { simulationInitCount++; } - void DisabledInit() override { m_disabledInitCount++; } + void DisabledInit() override { disabledInitCount++; } - void AutonomousInit() override { m_autonomousInitCount++; } + void AutonomousInit() override { autonomousInitCount++; } - void TeleopInit() override { m_teleopInitCount++; } + void TeleopInit() override { teleopInitCount++; } - void UtilityInit() override { m_testInitCount++; } + void UtilityInit() override { testInitCount++; } - void RobotPeriodic() override { m_robotPeriodicCount++; } + void RobotPeriodic() override { robotPeriodicCount++; } - void SimulationPeriodic() override { m_simulationPeriodicCount++; } + void SimulationPeriodic() override { simulationPeriodicCount++; } - void DisabledPeriodic() override { m_disabledPeriodicCount++; } + void DisabledPeriodic() override { disabledPeriodicCount++; } - void AutonomousPeriodic() override { m_autonomousPeriodicCount++; } + void AutonomousPeriodic() override { autonomousPeriodicCount++; } - void TeleopPeriodic() override { m_teleopPeriodicCount++; } + void TeleopPeriodic() override { teleopPeriodicCount++; } - void UtilityPeriodic() override { m_testPeriodicCount++; } + void UtilityPeriodic() override { testPeriodicCount++; } - void DisabledExit() override { m_disabledExitCount++; } + void DisabledExit() override { disabledExitCount++; } - void AutonomousExit() override { m_autonomousExitCount++; } + void AutonomousExit() override { autonomousExitCount++; } - void TeleopExit() override { m_teleopExitCount++; } + void TeleopExit() override { teleopExitCount++; } - void UtilityExit() override { m_testExitCount++; } + void UtilityExit() override { testExitCount++; } }; } // namespace @@ -93,63 +93,63 @@ TEST_F(TimedRobotTest, DisabledMode) { wpi::sim::DriverStationSim::SetEnabled(false); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(0u, robot.m_robotPeriodicCount); - EXPECT_EQ(0u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(0u, robot.robotPeriodicCount); + EXPECT_EQ(0u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_robotPeriodicCount); - EXPECT_EQ(1u, robot.m_simulationPeriodicCount); - EXPECT_EQ(1u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(1u, robot.robotPeriodicCount); + EXPECT_EQ(1u, robot.simulationPeriodicCount); + EXPECT_EQ(1u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(2u, robot.m_robotPeriodicCount); - EXPECT_EQ(2u, robot.m_simulationPeriodicCount); - EXPECT_EQ(2u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(2u, robot.robotPeriodicCount); + EXPECT_EQ(2u, robot.simulationPeriodicCount); + EXPECT_EQ(2u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); robot.EndCompetition(); robotThread.join(); @@ -165,63 +165,63 @@ TEST_F(TimedRobotTest, AutonomousMode) { wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_AUTONOMOUS); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(0u, robot.m_robotPeriodicCount); - EXPECT_EQ(0u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(0u, robot.robotPeriodicCount); + EXPECT_EQ(0u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_robotPeriodicCount); - EXPECT_EQ(1u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(1u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(1u, robot.robotPeriodicCount); + EXPECT_EQ(1u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(1u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(2u, robot.m_robotPeriodicCount); - EXPECT_EQ(2u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(2u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(2u, robot.robotPeriodicCount); + EXPECT_EQ(2u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(2u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); robot.EndCompetition(); robotThread.join(); @@ -237,63 +237,63 @@ TEST_F(TimedRobotTest, TeleopMode) { wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_TELEOPERATED); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(0u, robot.m_robotPeriodicCount); - EXPECT_EQ(0u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(0u, robot.robotPeriodicCount); + EXPECT_EQ(0u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(1u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(1u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_robotPeriodicCount); - EXPECT_EQ(1u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(1u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(1u, robot.robotPeriodicCount); + EXPECT_EQ(1u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(1u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(1u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(1u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(2u, robot.m_robotPeriodicCount); - EXPECT_EQ(2u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(2u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(2u, robot.robotPeriodicCount); + EXPECT_EQ(2u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(2u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); robot.EndCompetition(); robotThread.join(); @@ -308,85 +308,85 @@ TEST_F(TimedRobotTest, TestMode) { wpi::sim::DriverStationSim::SetRobotMode(HAL_ROBOT_MODE_UTILITY); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(0u, robot.m_robotPeriodicCount); - EXPECT_EQ(0u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(0u, robot.m_testPeriodicCount); + EXPECT_EQ(0u, robot.robotPeriodicCount); + EXPECT_EQ(0u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(0u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(1u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(1u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_robotPeriodicCount); - EXPECT_EQ(1u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(1u, robot.m_testPeriodicCount); + EXPECT_EQ(1u, robot.robotPeriodicCount); + EXPECT_EQ(1u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(1u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(1u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(1u, robot.testInitCount); - EXPECT_EQ(2u, robot.m_robotPeriodicCount); - EXPECT_EQ(2u, robot.m_simulationPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(2u, robot.m_testPeriodicCount); + EXPECT_EQ(2u, robot.robotPeriodicCount); + EXPECT_EQ(2u, robot.simulationPeriodicCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(2u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::DriverStationSim::SetEnabled(false); wpi::sim::DriverStationSim::NotifyNewData(); wpi::sim::StepTiming(20_ms); // Wait for Notifiers - EXPECT_EQ(1u, robot.m_simulationInitCount); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(1u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.simulationInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(1u, robot.testInitCount); - EXPECT_EQ(3u, robot.m_robotPeriodicCount); - EXPECT_EQ(3u, robot.m_simulationPeriodicCount); - EXPECT_EQ(1u, robot.m_disabledPeriodicCount); - EXPECT_EQ(0u, robot.m_autonomousPeriodicCount); - EXPECT_EQ(0u, robot.m_teleopPeriodicCount); - EXPECT_EQ(2u, robot.m_testPeriodicCount); + EXPECT_EQ(3u, robot.robotPeriodicCount); + EXPECT_EQ(3u, robot.simulationPeriodicCount); + EXPECT_EQ(1u, robot.disabledPeriodicCount); + EXPECT_EQ(0u, robot.autonomousPeriodicCount); + EXPECT_EQ(0u, robot.teleopPeriodicCount); + EXPECT_EQ(2u, robot.testPeriodicCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(1u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(1u, robot.testExitCount); robot.EndCompetition(); robotThread.join(); @@ -402,27 +402,27 @@ TEST_F(TimedRobotTest, ModeChange) { wpi::sim::DriverStationSim::SetEnabled(false); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(0u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(0u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); // Transition to autonomous wpi::sim::DriverStationSim::SetEnabled(true); @@ -431,15 +431,15 @@ TEST_F(TimedRobotTest, ModeChange) { wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_autonomousInitCount); - EXPECT_EQ(0u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.autonomousInitCount); + EXPECT_EQ(0u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_disabledExitCount); - EXPECT_EQ(0u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(1u, robot.disabledExitCount); + EXPECT_EQ(0u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); // Transition to teleop wpi::sim::DriverStationSim::SetEnabled(true); @@ -448,15 +448,15 @@ TEST_F(TimedRobotTest, ModeChange) { wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_autonomousInitCount); - EXPECT_EQ(1u, robot.m_teleopInitCount); - EXPECT_EQ(0u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.autonomousInitCount); + EXPECT_EQ(1u, robot.teleopInitCount); + EXPECT_EQ(0u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_disabledExitCount); - EXPECT_EQ(1u, robot.m_autonomousExitCount); - EXPECT_EQ(0u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(1u, robot.disabledExitCount); + EXPECT_EQ(1u, robot.autonomousExitCount); + EXPECT_EQ(0u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); // Transition to test wpi::sim::DriverStationSim::SetEnabled(true); @@ -465,15 +465,15 @@ TEST_F(TimedRobotTest, ModeChange) { wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_autonomousInitCount); - EXPECT_EQ(1u, robot.m_teleopInitCount); - EXPECT_EQ(1u, robot.m_testInitCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.autonomousInitCount); + EXPECT_EQ(1u, robot.teleopInitCount); + EXPECT_EQ(1u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_disabledExitCount); - EXPECT_EQ(1u, robot.m_autonomousExitCount); - EXPECT_EQ(1u, robot.m_teleopExitCount); - EXPECT_EQ(0u, robot.m_testExitCount); + EXPECT_EQ(1u, robot.disabledExitCount); + EXPECT_EQ(1u, robot.autonomousExitCount); + EXPECT_EQ(1u, robot.teleopExitCount); + EXPECT_EQ(0u, robot.testExitCount); // Transition to disabled wpi::sim::DriverStationSim::SetEnabled(false); @@ -481,15 +481,15 @@ TEST_F(TimedRobotTest, ModeChange) { wpi::sim::StepTiming(kPeriod); - EXPECT_EQ(2u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_autonomousInitCount); - EXPECT_EQ(1u, robot.m_teleopInitCount); - EXPECT_EQ(1u, robot.m_testInitCount); + EXPECT_EQ(2u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.autonomousInitCount); + EXPECT_EQ(1u, robot.teleopInitCount); + EXPECT_EQ(1u, robot.testInitCount); - EXPECT_EQ(1u, robot.m_disabledExitCount); - EXPECT_EQ(1u, robot.m_autonomousExitCount); - EXPECT_EQ(1u, robot.m_teleopExitCount); - EXPECT_EQ(1u, robot.m_testExitCount); + EXPECT_EQ(1u, robot.disabledExitCount); + EXPECT_EQ(1u, robot.autonomousExitCount); + EXPECT_EQ(1u, robot.teleopExitCount); + EXPECT_EQ(1u, robot.testExitCount); robot.EndCompetition(); robotThread.join(); @@ -507,20 +507,20 @@ TEST_F(TimedRobotTest, AddPeriodic) { wpi::sim::DriverStationSim::SetEnabled(false); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); EXPECT_EQ(0u, callbackCount); wpi::sim::StepTiming(kPeriod / 2.0); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); EXPECT_EQ(1u, callbackCount); wpi::sim::StepTiming(kPeriod / 2.0); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_disabledPeriodicCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.disabledPeriodicCount); EXPECT_EQ(2u, callbackCount); robot.EndCompetition(); @@ -546,32 +546,32 @@ TEST_F(TimedRobotTest, AddPeriodicWithOffset) { wpi::sim::DriverStationSim::SetEnabled(false); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); EXPECT_EQ(0u, callbackCount); wpi::sim::StepTiming(kPeriod * 3.0 / 8.0); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); EXPECT_EQ(0u, callbackCount); wpi::sim::StepTiming(kPeriod * 3.0 / 8.0); - EXPECT_EQ(0u, robot.m_disabledInitCount); - EXPECT_EQ(0u, robot.m_disabledPeriodicCount); + EXPECT_EQ(0u, robot.disabledInitCount); + EXPECT_EQ(0u, robot.disabledPeriodicCount); EXPECT_EQ(1u, callbackCount); wpi::sim::StepTiming(kPeriod / 4.0); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_disabledPeriodicCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.disabledPeriodicCount); EXPECT_EQ(1u, callbackCount); wpi::sim::StepTiming(kPeriod / 4.0); - EXPECT_EQ(1u, robot.m_disabledInitCount); - EXPECT_EQ(1u, robot.m_disabledPeriodicCount); + EXPECT_EQ(1u, robot.disabledInitCount); + EXPECT_EQ(1u, robot.disabledPeriodicCount); EXPECT_EQ(2u, callbackCount); robot.EndCompetition(); diff --git a/wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java b/wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java index cd74c2c555d..42286583aca 100644 --- a/wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java +++ b/wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java @@ -65,68 +65,68 @@ private static int availableToCount(long available) { } private static final class HALJoystickTouchpadFinger { - public float m_x; - public float m_y; - public boolean m_down; + float x; + float y; + boolean down; } private static class HALJoystickTouchpad { - public final HALJoystickTouchpadFinger[] m_fingers = + final HALJoystickTouchpadFinger[] fingers = new HALJoystickTouchpadFinger[DriverStationJNI.MAX_JOYSTICK_TOUCHPAD_FINGERS]; - public int m_count; + int count; HALJoystickTouchpad() { - for (int i = 0; i < m_fingers.length; i++) { - m_fingers[i] = new HALJoystickTouchpadFinger(); + for (int i = 0; i < fingers.length; i++) { + fingers[i] = new HALJoystickTouchpadFinger(); } } } private static class HALJoystickTouchpads { - public final HALJoystickTouchpad[] m_touchpads = + final HALJoystickTouchpad[] touchpads = new HALJoystickTouchpad[DriverStationJNI.MAX_JOYSTICK_TOUCHPADS]; - public int m_count; + int count; HALJoystickTouchpads() { - for (int i = 0; i < m_touchpads.length; i++) { - m_touchpads[i] = new HALJoystickTouchpad(); + for (int i = 0; i < touchpads.length; i++) { + touchpads[i] = new HALJoystickTouchpad(); } } } private static final class HALJoystickButtons { - public long m_buttons; - public long m_available; + long buttons; + long available; } private static class HALJoystickAxes { - public final float[] m_axes; - public int m_available; + final float[] axes; + int available; HALJoystickAxes(int count) { - m_axes = new float[count]; + axes = new float[count]; } } private static class HALJoystickAxesRaw { - public final short[] m_axes; + final short[] axes; @SuppressWarnings("unused") - public int m_available; + int available; HALJoystickAxesRaw(int count) { - m_axes = new short[count]; + axes = new short[count]; } } private static class HALJoystickPOVs { - public final byte[] m_povs; - public int m_available; + final byte[] povs; + int available; HALJoystickPOVs(int count) { - m_povs = new byte[count]; + povs = new byte[count]; for (int i = 0; i < count; i++) { - m_povs[i] = 0; + povs[i] = 0; } } } @@ -273,32 +273,31 @@ private void sendMatchData() { private static class JoystickLogSender { JoystickLogSender(DataLog log, int stick, long timestamp) { - m_stick = stick; + this.stick = stick; - m_logButtons = new BooleanArrayLogEntry(log, "DS:joystick" + stick + "/buttons", timestamp); - m_logAxes = new FloatArrayLogEntry(log, "DS:joystick" + stick + "/axes", timestamp); - m_logPOVs = new IntegerArrayLogEntry(log, "DS:joystick" + stick + "/povs", timestamp); + logButtons = new BooleanArrayLogEntry(log, "DS:joystick" + stick + "/buttons", timestamp); + logAxes = new FloatArrayLogEntry(log, "DS:joystick" + stick + "/axes", timestamp); + logPOVs = new IntegerArrayLogEntry(log, "DS:joystick" + stick + "/povs", timestamp); - appendButtons(m_joystickButtons[m_stick], timestamp); - appendAxes(m_joystickAxes[m_stick], timestamp); - appendPOVs(m_joystickPOVs[m_stick], timestamp); + appendButtons(m_joystickButtons[stick], timestamp); + appendAxes(m_joystickAxes[stick], timestamp); + appendPOVs(m_joystickPOVs[stick], timestamp); } - public void send(long timestamp) { - HALJoystickButtons buttons = m_joystickButtons[m_stick]; - if (buttons.m_available != m_prevButtons.m_available - || buttons.m_buttons != m_prevButtons.m_buttons) { + void send(long timestamp) { + HALJoystickButtons buttons = m_joystickButtons[stick]; + if (buttons.available != prevButtons.available || buttons.buttons != prevButtons.buttons) { appendButtons(buttons, timestamp); } - HALJoystickAxes axes = m_joystickAxes[m_stick]; - int available = axes.m_available; + HALJoystickAxes axes = m_joystickAxes[stick]; + int available = axes.available; boolean needToLog = false; - if (available != m_prevAxes.m_available) { + if (available != prevAxes.available) { needToLog = true; } else { - for (int i = 0; i < m_prevAxes.m_axes.length; i++) { - if (axes.m_axes[i] != m_prevAxes.m_axes[i]) { + for (int i = 0; i < prevAxes.axes.length; i++) { + if (axes.axes[i] != prevAxes.axes[i]) { needToLog = true; break; } @@ -308,14 +307,14 @@ public void send(long timestamp) { appendAxes(axes, timestamp); } - HALJoystickPOVs povs = m_joystickPOVs[m_stick]; - available = m_joystickPOVs[m_stick].m_available; + HALJoystickPOVs povs = m_joystickPOVs[stick]; + available = m_joystickPOVs[stick].available; needToLog = false; - if (available != m_prevPOVs.m_available) { + if (available != prevPOVs.available) { needToLog = true; } else { - for (int i = 0; i < m_prevPOVs.m_povs.length; i++) { - if (povs.m_povs[i] != m_prevPOVs.m_povs[i]) { + for (int i = 0; i < prevPOVs.povs.length; i++) { + if (povs.povs[i] != prevPOVs.povs[i]) { needToLog = true; break; } @@ -327,102 +326,101 @@ public void send(long timestamp) { } void appendButtons(HALJoystickButtons buttons, long timestamp) { - int count = availableToCount(buttons.m_available); - if (m_sizedButtons == null || m_sizedButtons.length != count) { - m_sizedButtons = new boolean[count]; + int count = availableToCount(buttons.available); + if (sizedButtons == null || sizedButtons.length != count) { + sizedButtons = new boolean[count]; } - long buttonsValue = buttons.m_buttons; + long buttonsValue = buttons.buttons; for (int i = 0; i < count; i++) { - m_sizedButtons[i] = (buttonsValue & (1L << i)) != 0; + sizedButtons[i] = (buttonsValue & (1L << i)) != 0; } - m_logButtons.append(m_sizedButtons, timestamp); - m_prevButtons.m_available = buttons.m_available; - m_prevButtons.m_buttons = buttons.m_buttons; + logButtons.append(sizedButtons, timestamp); + prevButtons.available = buttons.available; + prevButtons.buttons = buttons.buttons; } void appendAxes(HALJoystickAxes axes, long timestamp) { - int count = availableToCount(axes.m_available); - if (m_sizedAxes == null || m_sizedAxes.length != count) { - m_sizedAxes = new float[count]; + int count = availableToCount(axes.available); + if (sizedAxes == null || sizedAxes.length != count) { + sizedAxes = new float[count]; } - System.arraycopy(axes.m_axes, 0, m_sizedAxes, 0, count); - m_logAxes.append(m_sizedAxes, timestamp); - m_prevAxes.m_available = axes.m_available; - System.arraycopy(axes.m_axes, 0, m_prevAxes.m_axes, 0, count); + System.arraycopy(axes.axes, 0, sizedAxes, 0, count); + logAxes.append(sizedAxes, timestamp); + prevAxes.available = axes.available; + System.arraycopy(axes.axes, 0, prevAxes.axes, 0, count); } void appendPOVs(HALJoystickPOVs povs, long timestamp) { - int count = availableToCount(povs.m_available); - if (m_sizedPOVs == null || m_sizedPOVs.length != count) { - m_sizedPOVs = new long[count]; + int count = availableToCount(povs.available); + if (sizedPOVs == null || sizedPOVs.length != count) { + sizedPOVs = new long[count]; } for (int i = 0; i < count; i++) { - m_sizedPOVs[i] = povs.m_povs[i]; + sizedPOVs[i] = povs.povs[i]; } - m_logPOVs.append(m_sizedPOVs, timestamp); - m_prevPOVs.m_available = povs.m_available; - System.arraycopy(povs.m_povs, 0, m_prevPOVs.m_povs, 0, count); + logPOVs.append(sizedPOVs, timestamp); + prevPOVs.available = povs.available; + System.arraycopy(povs.povs, 0, prevPOVs.povs, 0, count); } - final int m_stick; - boolean[] m_sizedButtons; - float[] m_sizedAxes; - long[] m_sizedPOVs; - final HALJoystickButtons m_prevButtons = new HALJoystickButtons(); - final HALJoystickAxes m_prevAxes = new HALJoystickAxes(DriverStationJNI.MAX_JOYSTICK_AXES); - final HALJoystickPOVs m_prevPOVs = new HALJoystickPOVs(DriverStationJNI.MAX_JOYSTICK_POVS); - final BooleanArrayLogEntry m_logButtons; - final FloatArrayLogEntry m_logAxes; - final IntegerArrayLogEntry m_logPOVs; + final int stick; + boolean[] sizedButtons; + float[] sizedAxes; + long[] sizedPOVs; + final HALJoystickButtons prevButtons = new HALJoystickButtons(); + final HALJoystickAxes prevAxes = new HALJoystickAxes(DriverStationJNI.MAX_JOYSTICK_AXES); + final HALJoystickPOVs prevPOVs = new HALJoystickPOVs(DriverStationJNI.MAX_JOYSTICK_POVS); + final BooleanArrayLogEntry logButtons; + final FloatArrayLogEntry logAxes; + final IntegerArrayLogEntry logPOVs; } private static class DataLogSender { DataLogSender(DataLog log, boolean logJoysticks, long timestamp) { - m_logControlWord = - StructLogEntry.create(log, "DS:controlWord", ControlWord.struct, timestamp); + logControlWord = StructLogEntry.create(log, "DS:controlWord", ControlWord.struct, timestamp); // append initial control word value - m_logControlWord.append(m_controlWordCache, timestamp); - m_oldControlWord.update(m_controlWordCache); + logControlWord.append(m_controlWordCache, timestamp); + oldControlWord.update(m_controlWordCache); // append initial opmode value - m_logOpMode = new StringLogEntry(log, "DS:opMode", timestamp); - m_logOpMode.append(m_opModeCache, timestamp); + logOpMode = new StringLogEntry(log, "DS:opMode", timestamp); + logOpMode.append(m_opModeCache, timestamp); if (logJoysticks) { - m_joysticks = new JoystickLogSender[JOYSTICK_PORTS]; + joysticks = new JoystickLogSender[JOYSTICK_PORTS]; for (int i = 0; i < JOYSTICK_PORTS; i++) { - m_joysticks[i] = new JoystickLogSender(log, i, timestamp); + joysticks[i] = new JoystickLogSender(log, i, timestamp); } } else { - m_joysticks = new JoystickLogSender[0]; + joysticks = new JoystickLogSender[0]; } } - public void send(long timestamp) { + void send(long timestamp) { // append control word value changes - if (!m_controlWordCache.equals(m_oldControlWord)) { + if (!m_controlWordCache.equals(oldControlWord)) { // append opmode value changes long opModeId = m_controlWordCache.getOpModeId(); - if (opModeId != m_oldControlWord.getOpModeId()) { - m_logOpMode.append(m_opModeCache, timestamp); + if (opModeId != oldControlWord.getOpModeId()) { + logOpMode.append(m_opModeCache, timestamp); } - m_logControlWord.append(m_controlWordCache, timestamp); - m_oldControlWord.update(m_controlWordCache); + logControlWord.append(m_controlWordCache, timestamp); + oldControlWord.update(m_controlWordCache); } // append joystick value changes - for (JoystickLogSender joystick : m_joysticks) { + for (JoystickLogSender joystick : joysticks) { joystick.send(timestamp); } } - final ControlWord m_oldControlWord = new ControlWord(); - final StructLogEntry m_logControlWord; - final StringLogEntry m_logOpMode; + final ControlWord oldControlWord = new ControlWord(); + final StructLogEntry logControlWord; + final StringLogEntry logOpMode; - final JoystickLogSender[] m_joysticks; + final JoystickLogSender[] joysticks; } // Joystick User Data @@ -594,8 +592,8 @@ public static boolean getStickButton(final int stick, final int button) { m_cacheDataMutex.lock(); try { - if ((m_joystickButtons[stick].m_available & mask) != 0) { - return (m_joystickButtons[stick].m_buttons & mask) != 0; + if ((m_joystickButtons[stick].available & mask) != 0) { + return (m_joystickButtons[stick].buttons & mask) != 0; } } finally { m_cacheDataMutex.unlock(); @@ -625,8 +623,8 @@ public static Optional getStickButtonIfAvailable(final int stick, final m_cacheDataMutex.lock(); try { - if ((m_joystickButtons[stick].m_available & mask) != 0) { - return Optional.of((m_joystickButtons[stick].m_buttons & mask) != 0); + if ((m_joystickButtons[stick].available & mask) != 0) { + return Optional.of((m_joystickButtons[stick].buttons & mask) != 0); } } finally { m_cacheDataMutex.unlock(); @@ -653,7 +651,7 @@ public static boolean getStickButtonPressed(final int stick, final int button) { m_cacheDataMutex.lock(); try { - if ((m_joystickButtons[stick].m_available & mask) != 0) { + if ((m_joystickButtons[stick].available & mask) != 0) { // If button was pressed, clear flag and return true if ((m_joystickButtonsPressed[stick] & mask) != 0) { m_joystickButtonsPressed[stick] &= ~mask; @@ -690,7 +688,7 @@ public static boolean getStickButtonReleased(final int stick, final int button) m_cacheDataMutex.lock(); try { - if ((m_joystickButtons[stick].m_available & mask) != 0) { + if ((m_joystickButtons[stick].available & mask) != 0) { // If button was released, clear flag and return true if ((m_joystickButtonsReleased[stick] & mask) != 0) { m_joystickButtonsReleased[stick] &= ~mask; @@ -728,8 +726,8 @@ public static double getStickAxis(int stick, int axis) { m_cacheDataMutex.lock(); try { - if ((m_joystickAxes[stick].m_available & mask) != 0) { - return m_joystickAxes[stick].m_axes[axis]; + if ((m_joystickAxes[stick].available & mask) != 0) { + return m_joystickAxes[stick].axes[axis]; } } finally { m_cacheDataMutex.unlock(); @@ -761,12 +759,12 @@ public static TouchpadFinger getStickTouchpadFinger(int stick, int touchpad, int int touchpadCount; m_cacheDataMutex.lock(); try { - touchpadCount = m_joystickTouchpads[stick].m_count; + touchpadCount = m_joystickTouchpads[stick].count; if (touchpad < touchpadCount) { - HALJoystickTouchpad tp = m_joystickTouchpads[stick].m_touchpads[touchpad]; - if (finger < tp.m_count) { + HALJoystickTouchpad tp = m_joystickTouchpads[stick].touchpads[touchpad]; + if (finger < tp.count) { return new TouchpadFinger( - tp.m_fingers[finger].m_down, tp.m_fingers[finger].m_x, tp.m_fingers[finger].m_y); + tp.fingers[finger].down, tp.fingers[finger].x, tp.fingers[finger].y); } } } finally { @@ -807,10 +805,10 @@ public static boolean getStickTouchpadFingerAvailable(int stick, int touchpad, i int touchpadCount; m_cacheDataMutex.lock(); try { - touchpadCount = m_joystickTouchpads[stick].m_count; + touchpadCount = m_joystickTouchpads[stick].count; if (touchpad < touchpadCount) { - HALJoystickTouchpad tp = m_joystickTouchpads[stick].m_touchpads[touchpad]; - if (finger < tp.m_count) { + HALJoystickTouchpad tp = m_joystickTouchpads[stick].touchpads[touchpad]; + if (finger < tp.count) { return true; } } @@ -841,8 +839,8 @@ public static OptionalDouble getStickAxisIfAvailable(int stick, int axis) { m_cacheDataMutex.lock(); try { - if ((m_joystickAxes[stick].m_available & mask) != 0) { - return OptionalDouble.of(m_joystickAxes[stick].m_axes[axis]); + if ((m_joystickAxes[stick].available & mask) != 0) { + return OptionalDouble.of(m_joystickAxes[stick].axes[axis]); } } finally { m_cacheDataMutex.unlock(); @@ -870,8 +868,8 @@ public static POVDirection getStickPOV(int stick, int pov) { m_cacheDataMutex.lock(); try { - if ((m_joystickPOVs[stick].m_available & mask) != 0) { - return POVDirection.of(m_joystickPOVs[stick].m_povs[pov]); + if ((m_joystickPOVs[stick].available & mask) != 0) { + return POVDirection.of(m_joystickPOVs[stick].povs[pov]); } } finally { m_cacheDataMutex.unlock(); @@ -894,7 +892,7 @@ public static long getStickButtons(final int stick) { m_cacheDataMutex.lock(); try { - return m_joystickButtons[stick].m_buttons; + return m_joystickButtons[stick].buttons; } finally { m_cacheDataMutex.unlock(); } @@ -923,7 +921,7 @@ public static int getStickAxesAvailable(int stick) { m_cacheDataMutex.lock(); try { - return m_joystickAxes[stick].m_available; + return m_joystickAxes[stick].available; } finally { m_cacheDataMutex.unlock(); } @@ -952,7 +950,7 @@ public static int getStickPOVsAvailable(int stick) { m_cacheDataMutex.lock(); try { - return m_joystickPOVs[stick].m_available; + return m_joystickPOVs[stick].available; } finally { m_cacheDataMutex.unlock(); } @@ -981,7 +979,7 @@ public static long getStickButtonsAvailable(int stick) { m_cacheDataMutex.lock(); try { - return m_joystickButtons[stick].m_available; + return m_joystickButtons[stick].available; } finally { m_cacheDataMutex.unlock(); } @@ -1695,26 +1693,26 @@ public static void refreshData() { for (byte stick = 0; stick < JOYSTICK_PORTS; stick++) { DriverStationJNI.getAllJoystickData( stick, - m_joystickAxesCache[stick].m_axes, - m_joystickAxesRawCache[stick].m_axes, - m_joystickPOVsCache[stick].m_povs, + m_joystickAxesCache[stick].axes, + m_joystickAxesRawCache[stick].axes, + m_joystickPOVsCache[stick].povs, m_touchpadFingersCache, m_metadataCache); - m_joystickAxesCache[stick].m_available = (int) m_metadataCache[0]; - m_joystickAxesRawCache[stick].m_available = (int) m_metadataCache[0]; - m_joystickPOVsCache[stick].m_available = (int) m_metadataCache[1]; - m_joystickButtonsCache[stick].m_available = m_metadataCache[2]; - m_joystickButtonsCache[stick].m_buttons = m_metadataCache[3]; - m_joystickTouchpadsCache[stick].m_count = (int) m_metadataCache[4]; - for (int i = 0; i < m_joystickTouchpadsCache[stick].m_count; i++) { + m_joystickAxesCache[stick].available = (int) m_metadataCache[0]; + m_joystickAxesRawCache[stick].available = (int) m_metadataCache[0]; + m_joystickPOVsCache[stick].available = (int) m_metadataCache[1]; + m_joystickButtonsCache[stick].available = m_metadataCache[2]; + m_joystickButtonsCache[stick].buttons = m_metadataCache[3]; + m_joystickTouchpadsCache[stick].count = (int) m_metadataCache[4]; + for (int i = 0; i < m_joystickTouchpadsCache[stick].count; i++) { long metadata = m_metadataCache[5 + i]; - m_joystickTouchpadsCache[stick].m_touchpads[i].m_fingers[0].m_down = (metadata & 0x1) != 0; - m_joystickTouchpadsCache[stick].m_touchpads[i].m_fingers[1].m_down = (metadata & 0x2) != 0; - m_joystickTouchpadsCache[stick].m_touchpads[i].m_count = (int) (metadata >> 2 & 0x3); - for (int j = 0; j < m_joystickTouchpadsCache[stick].m_touchpads[i].m_count; j++) { - m_joystickTouchpadsCache[stick].m_touchpads[i].m_fingers[j].m_x = + m_joystickTouchpadsCache[stick].touchpads[i].fingers[0].down = (metadata & 0x1) != 0; + m_joystickTouchpadsCache[stick].touchpads[i].fingers[1].down = (metadata & 0x2) != 0; + m_joystickTouchpadsCache[stick].touchpads[i].count = (int) (metadata >> 2 & 0x3); + for (int j = 0; j < m_joystickTouchpadsCache[stick].touchpads[i].count; j++) { + m_joystickTouchpadsCache[stick].touchpads[i].fingers[j].x = m_touchpadFingersCache[i * 4 + j * 2 + 0]; - m_joystickTouchpadsCache[stick].m_touchpads[i].m_fingers[j].m_y = + m_joystickTouchpadsCache[stick].touchpads[i].fingers[j].y = m_touchpadFingersCache[i * 4 + j * 2 + 1]; } } @@ -1737,11 +1735,11 @@ public static void refreshData() { for (int i = 0; i < JOYSTICK_PORTS; i++) { // If buttons weren't pressed and are now, set flags in m_buttonsPressed m_joystickButtonsPressed[i] |= - ~m_joystickButtons[i].m_buttons & m_joystickButtonsCache[i].m_buttons; + ~m_joystickButtons[i].buttons & m_joystickButtonsCache[i].buttons; // If buttons were pressed and aren't now, set flags in m_buttonsReleased m_joystickButtonsReleased[i] |= - m_joystickButtons[i].m_buttons & ~m_joystickButtonsCache[i].m_buttons; + m_joystickButtons[i].buttons & ~m_joystickButtonsCache[i].buttons; } // move cache to actual data diff --git a/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java b/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java index 16aef6abe9d..a73a6aa67a6 100644 --- a/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java +++ b/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java @@ -131,7 +131,7 @@ protected RobotBase() { false, event -> { if (event.is(NetworkTableEvent.Kind.CONNECTED)) { - HAL.reportUsage("NT/" + event.connInfo.remote_id, ""); + HAL.reportUsage("NT/" + event.connInfo.remoteId, ""); } }); } diff --git a/wpilibj/src/main/java/org/wpilib/framework/TimedRobot.java b/wpilibj/src/main/java/org/wpilib/framework/TimedRobot.java index 446ee60fd40..abd58246d25 100644 --- a/wpilibj/src/main/java/org/wpilib/framework/TimedRobot.java +++ b/wpilibj/src/main/java/org/wpilib/framework/TimedRobot.java @@ -23,7 +23,6 @@ */ public class TimedRobot extends IterativeRobotBase { /** Default loop period. */ - @SuppressWarnings("MemberName") public static final double DEFAULT_PERIOD = 0.02; // The C pointer to the notifier object. We don't use it directly, it is diff --git a/wpilibj/src/main/java/org/wpilib/hardware/accelerometer/ADXL345_I2C.java b/wpilibj/src/main/java/org/wpilib/hardware/accelerometer/ADXL345_I2C.java index 8473e5c4a27..dc9c69375df 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/accelerometer/ADXL345_I2C.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/accelerometer/ADXL345_I2C.java @@ -57,7 +57,6 @@ public enum Axis { } /** Container type for accelerations from all axes. */ - @SuppressWarnings("MemberName") public static class AllAxes { /** Acceleration along the X axis in g-forces. */ public double x; diff --git a/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java b/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java index 3a4b05df891..aa487962eda 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/discrete/AnalogInput.java @@ -17,7 +17,7 @@ *

Each analog channel is read from hardware as a 12-bit number representing 0V to 3.3V. */ public class AnalogInput implements Sendable, AutoCloseable { - int m_port; // explicit no modifier, private and package accessible. + private int m_port; private int m_channel; /** diff --git a/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java b/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java index 61605096c35..be1115ad48b 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java @@ -13,16 +13,16 @@ /** This class controls a REV ExpansionHub plugged in over USB to Systemcore. */ public class ExpansionHub implements AutoCloseable { private static class DataStore implements AutoCloseable { - public final int m_usbId; - private int m_refCount; - private int m_reservedMotorMask; - private int m_reservedServoMask; - private final Object m_reserveLock = new Object(); + final int usbId; + int refCount; + int reservedMotorMask; + int reservedServoMask; + final Object reserveLock = new Object(); private final BooleanSubscriber m_hubConnectedSubscriber; DataStore(int usbId) { - m_usbId = usbId; + this.usbId = usbId; m_storeMap[usbId] = this; NetworkTableInstance systemServer = SystemServer.getSystemServer(); @@ -43,16 +43,16 @@ private static class DataStore implements AutoCloseable { @Override public void close() { - m_storeMap[m_usbId] = null; + m_storeMap[usbId] = null; } - public void addRef() { - m_refCount++; + void addRef() { + refCount++; } - public void removeRef() { - m_refCount--; - if (m_refCount == 0) { + void removeRef() { + refCount--; + if (refCount == 0) { this.close(); } } @@ -113,19 +113,19 @@ boolean checkServoChannel(int channel) { boolean checkAndReserveServo(int channel) { int mask = 1 << channel; - synchronized (m_dataStore.m_reserveLock) { - if ((m_dataStore.m_reservedServoMask & mask) != 0) { + synchronized (m_dataStore.reserveLock) { + if ((m_dataStore.reservedServoMask & mask) != 0) { return false; } - m_dataStore.m_reservedServoMask |= mask; + m_dataStore.reservedServoMask |= mask; return true; } } void unreserveServo(int channel) { int mask = 1 << channel; - synchronized (m_dataStore.m_reserveLock) { - m_dataStore.m_reservedServoMask &= ~mask; + synchronized (m_dataStore.reserveLock) { + m_dataStore.reservedServoMask &= ~mask; } } @@ -135,24 +135,24 @@ boolean checkMotorChannel(int channel) { boolean checkAndReserveMotor(int channel) { int mask = 1 << channel; - synchronized (m_dataStore.m_reserveLock) { - if ((m_dataStore.m_reservedMotorMask & mask) != 0) { + synchronized (m_dataStore.reserveLock) { + if ((m_dataStore.reservedMotorMask & mask) != 0) { return false; } - m_dataStore.m_reservedMotorMask |= mask; + m_dataStore.reservedMotorMask |= mask; return true; } } void unreserveMotor(int channel) { int mask = 1 << channel; - synchronized (m_dataStore.m_reserveLock) { - m_dataStore.m_reservedMotorMask &= ~mask; + synchronized (m_dataStore.reserveLock) { + m_dataStore.reservedMotorMask &= ~mask; } } void reportUsage(String device, String data) { - HAL.reportUsage("ExpansionHub[" + m_dataStore.m_usbId + "]/" + device, data); + HAL.reportUsage("ExpansionHub[" + m_dataStore.usbId + "]/" + device, data); } /** @@ -164,7 +164,7 @@ void reportUsage(String device, String data) { * @return Servo object */ public ExpansionHubServo makeServo(int channel) { - return new ExpansionHubServo(m_dataStore.m_usbId, channel); + return new ExpansionHubServo(m_dataStore.usbId, channel); } /** @@ -176,7 +176,7 @@ public ExpansionHubServo makeServo(int channel) { * @return Motor object */ public ExpansionHubMotor makeMotor(int channel) { - return new ExpansionHubMotor(m_dataStore.m_usbId, channel); + return new ExpansionHubMotor(m_dataStore.usbId, channel); } /** @@ -194,6 +194,6 @@ public boolean isHubConnected() { * @return The USB ID */ public int getUsbId() { - return m_dataStore.m_usbId; + return m_dataStore.usbId; } } diff --git a/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLED.java b/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLED.java index 3d9d89acf5d..381ceec3399 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLED.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLED.java @@ -144,11 +144,7 @@ public void setLength(int length) { */ public void setData(AddressableLEDBuffer buffer) { AddressableLEDJNI.setData( - m_start, - m_colorOrder.value, - buffer.m_buffer, - 0, - 3 * Math.min(m_length, buffer.getLength())); + m_start, m_colorOrder.value, buffer.buffer, 0, 3 * Math.min(m_length, buffer.getLength())); } /** @@ -159,6 +155,6 @@ public void setData(AddressableLEDBuffer buffer) { * @param buffer the buffer to write */ public static void setGlobalData(int start, ColorOrder colorOrder, AddressableLEDBuffer buffer) { - AddressableLEDJNI.setData(start, colorOrder.value, buffer.m_buffer); + AddressableLEDJNI.setData(start, colorOrder.value, buffer.buffer); } } diff --git a/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLEDBuffer.java b/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLEDBuffer.java index 641e10b7cce..dfd1c9c6048 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLEDBuffer.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/led/AddressableLEDBuffer.java @@ -6,7 +6,7 @@ /** Buffer storage for Addressable LEDs. */ public class AddressableLEDBuffer implements LEDReader, LEDWriter { - byte[] m_buffer; + byte[] buffer; /** * Constructs a new LED buffer with the specified length. @@ -14,7 +14,7 @@ public class AddressableLEDBuffer implements LEDReader, LEDWriter { * @param length The length of the buffer in pixels */ public AddressableLEDBuffer(int length) { - m_buffer = new byte[length * 3]; + buffer = new byte[length * 3]; } /** @@ -27,9 +27,9 @@ public AddressableLEDBuffer(int length) { */ @Override public void setRGB(int index, int r, int g, int b) { - m_buffer[index * 3] = (byte) r; - m_buffer[(index * 3) + 1] = (byte) g; - m_buffer[(index * 3) + 2] = (byte) b; + buffer[index * 3] = (byte) r; + buffer[(index * 3) + 1] = (byte) g; + buffer[(index * 3) + 2] = (byte) b; } /** @@ -39,7 +39,7 @@ public void setRGB(int index, int r, int g, int b) { */ @Override public int getLength() { - return m_buffer.length / 3; + return buffer.length / 3; } /** @@ -50,7 +50,7 @@ public int getLength() { */ @Override public int getRed(int index) { - return m_buffer[index * 3] & 0xFF; + return buffer[index * 3] & 0xFF; } /** @@ -61,7 +61,7 @@ public int getRed(int index) { */ @Override public int getGreen(int index) { - return m_buffer[index * 3 + 1] & 0xFF; + return buffer[index * 3 + 1] & 0xFF; } /** @@ -72,7 +72,7 @@ public int getGreen(int index) { */ @Override public int getBlue(int index) { - return m_buffer[index * 3 + 2] & 0xFF; + return buffer[index * 3 + 2] & 0xFF; } /** diff --git a/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticHub.java b/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticHub.java index 35e5e4a12b2..3224d95771e 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticHub.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticHub.java @@ -17,22 +17,22 @@ /** Module class for controlling a REV Robotics Pneumatic Hub. */ public class PneumaticHub implements PneumaticsBase { private static class DataStore implements AutoCloseable { - public final int m_module; - public final int m_handle; - private final int m_busId; - private int m_refCount; - private int m_reservedMask; - private boolean m_compressorReserved; - public final int[] m_oneShotDurMs = new int[PortsJNI.getNumREVPHChannels()]; - private final Object m_reserveLock = new Object(); + final int module; + final int handle; + final int busId; + int refCount; + int reservedMask; + boolean compressorReserved; + final int[] oneShotDurMs = new int[PortsJNI.getNumREVPHChannels()]; + final Object reserveLock = new Object(); DataStore(int busId, int module) { - m_handle = REVPHJNI.initialize(busId, module); - m_module = module; - m_busId = busId; + handle = REVPHJNI.initialize(busId, module); + this.module = module; + this.busId = busId; m_handleMaps[busId].put(module, this); - final REVPHVersion version = REVPHJNI.getVersion(m_handle); + final REVPHVersion version = REVPHJNI.getVersion(handle); final String fwVersion = version.firmwareMajor + "." + version.firmwareMinor + "." + version.firmwareFix; @@ -48,17 +48,17 @@ private static class DataStore implements AutoCloseable { @Override public void close() { - REVPHJNI.free(m_handle); - m_handleMaps[m_busId].remove(m_module); + REVPHJNI.free(handle); + m_handleMaps[busId].remove(module); } - public void addRef() { - m_refCount++; + void addRef() { + refCount++; } - public void removeRef() { - m_refCount--; - if (m_refCount == 0) { + void removeRef() { + refCount--; + if (refCount == 0) { this.close(); } } @@ -123,7 +123,7 @@ public PneumaticHub(int busId) { */ public PneumaticHub(int busId, int module) { m_dataStore = getForModule(busId, module); - m_handle = m_dataStore.m_handle; + m_handle = m_dataStore.handle; } @Override @@ -163,17 +163,17 @@ public int getSolenoids() { @Override public int getModuleNumber() { - return m_dataStore.m_module; + return m_dataStore.module; } @Override public void fireOneShot(int index) { - REVPHJNI.fireOneShot(m_handle, index, m_dataStore.m_oneShotDurMs[index]); + REVPHJNI.fireOneShot(m_handle, index, m_dataStore.oneShotDurMs[index]); } @Override public void setOneShotDuration(int index, int durMs) { - m_dataStore.m_oneShotDurMs[index] = durMs; + m_dataStore.oneShotDurMs[index] = durMs; } @Override @@ -183,53 +183,53 @@ public boolean checkSolenoidChannel(int channel) { @Override public int checkAndReserveSolenoids(int mask) { - synchronized (m_dataStore.m_reserveLock) { - if ((m_dataStore.m_reservedMask & mask) != 0) { - return m_dataStore.m_reservedMask & mask; + synchronized (m_dataStore.reserveLock) { + if ((m_dataStore.reservedMask & mask) != 0) { + return m_dataStore.reservedMask & mask; } - m_dataStore.m_reservedMask |= mask; + m_dataStore.reservedMask |= mask; return 0; } } @Override public void unreserveSolenoids(int mask) { - synchronized (m_dataStore.m_reserveLock) { - m_dataStore.m_reservedMask &= ~mask; + synchronized (m_dataStore.reserveLock) { + m_dataStore.reservedMask &= ~mask; } } @Override public Solenoid makeSolenoid(int channel) { - return new Solenoid(m_dataStore.m_module, PneumaticsModuleType.REV_PH, channel); + return new Solenoid(m_dataStore.module, PneumaticsModuleType.REV_PH, channel); } @Override public DoubleSolenoid makeDoubleSolenoid(int forwardChannel, int reverseChannel) { return new DoubleSolenoid( - m_dataStore.m_module, PneumaticsModuleType.REV_PH, forwardChannel, reverseChannel); + m_dataStore.module, PneumaticsModuleType.REV_PH, forwardChannel, reverseChannel); } @Override public Compressor makeCompressor() { - return new Compressor(m_dataStore.m_module, PneumaticsModuleType.REV_PH); + return new Compressor(m_dataStore.module, PneumaticsModuleType.REV_PH); } @Override public boolean reserveCompressor() { - synchronized (m_dataStore.m_reserveLock) { - if (m_dataStore.m_compressorReserved) { + synchronized (m_dataStore.reserveLock) { + if (m_dataStore.compressorReserved) { return false; } - m_dataStore.m_compressorReserved = true; + m_dataStore.compressorReserved = true; return true; } } @Override public void unreserveCompressor() { - synchronized (m_dataStore.m_reserveLock) { - m_dataStore.m_compressorReserved = false; + synchronized (m_dataStore.reserveLock) { + m_dataStore.compressorReserved = false; } } @@ -428,6 +428,6 @@ public double getSolenoidsVoltage() { @Override public void reportUsage(String device, String data) { - HAL.reportUsage("PH[" + m_dataStore.m_module + "]/" + device, data); + HAL.reportUsage("PH[" + m_dataStore.module + "]/" + device, data); } } diff --git a/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticsControlModule.java b/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticsControlModule.java index da16079f776..a31f7199b53 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticsControlModule.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticsControlModule.java @@ -14,34 +14,34 @@ /** Module class for controlling a Cross The Road Electronics Pneumatics Control Module. */ public class PneumaticsControlModule implements PneumaticsBase { private static class DataStore implements AutoCloseable { - public final int m_module; - public final int m_handle; - private final int m_busId; - private int m_refCount; - private int m_reservedMask; - private boolean m_compressorReserved; - private final Object m_reserveLock = new Object(); + final int module; + final int handle; + final int busId; + int refCount; + int reservedMask; + boolean compressorReserved; + final Object reserveLock = new Object(); DataStore(int busId, int module) { - m_handle = CTREPCMJNI.initialize(busId, module); - m_module = module; - m_busId = busId; + handle = CTREPCMJNI.initialize(busId, module); + this.module = module; + this.busId = busId; m_handleMaps[busId].put(module, this); } @Override public void close() { - CTREPCMJNI.free(m_handle); - m_handleMaps[m_busId].remove(m_module); + CTREPCMJNI.free(handle); + m_handleMaps[busId].remove(module); } - public void addRef() { - m_refCount++; + void addRef() { + refCount++; } - public void removeRef() { - m_refCount--; - if (m_refCount == 0) { + void removeRef() { + refCount--; + if (refCount == 0) { this.close(); } } @@ -96,7 +96,7 @@ public PneumaticsControlModule(int busId) { */ public PneumaticsControlModule(int busId, int module) { m_dataStore = getForModule(busId, module); - m_handle = m_dataStore.m_handle; + m_handle = m_dataStore.handle; } @Override @@ -196,7 +196,7 @@ public int getSolenoids() { @Override public int getModuleNumber() { - return m_dataStore.m_module; + return m_dataStore.module; } @Override @@ -247,53 +247,53 @@ public boolean checkSolenoidChannel(int channel) { @Override public int checkAndReserveSolenoids(int mask) { - synchronized (m_dataStore.m_reserveLock) { - if ((m_dataStore.m_reservedMask & mask) != 0) { - return m_dataStore.m_reservedMask & mask; + synchronized (m_dataStore.reserveLock) { + if ((m_dataStore.reservedMask & mask) != 0) { + return m_dataStore.reservedMask & mask; } - m_dataStore.m_reservedMask |= mask; + m_dataStore.reservedMask |= mask; return 0; } } @Override public void unreserveSolenoids(int mask) { - synchronized (m_dataStore.m_reserveLock) { - m_dataStore.m_reservedMask &= ~mask; + synchronized (m_dataStore.reserveLock) { + m_dataStore.reservedMask &= ~mask; } } @Override public Solenoid makeSolenoid(int channel) { - return new Solenoid(m_dataStore.m_module, PneumaticsModuleType.CTRE_PCM, channel); + return new Solenoid(m_dataStore.module, PneumaticsModuleType.CTRE_PCM, channel); } @Override public DoubleSolenoid makeDoubleSolenoid(int forwardChannel, int reverseChannel) { return new DoubleSolenoid( - m_dataStore.m_module, PneumaticsModuleType.CTRE_PCM, forwardChannel, reverseChannel); + m_dataStore.module, PneumaticsModuleType.CTRE_PCM, forwardChannel, reverseChannel); } @Override public Compressor makeCompressor() { - return new Compressor(m_dataStore.m_module, PneumaticsModuleType.CTRE_PCM); + return new Compressor(m_dataStore.module, PneumaticsModuleType.CTRE_PCM); } @Override public boolean reserveCompressor() { - synchronized (m_dataStore.m_reserveLock) { - if (m_dataStore.m_compressorReserved) { + synchronized (m_dataStore.reserveLock) { + if (m_dataStore.compressorReserved) { return false; } - m_dataStore.m_compressorReserved = true; + m_dataStore.compressorReserved = true; return true; } } @Override public void unreserveCompressor() { - synchronized (m_dataStore.m_reserveLock) { - m_dataStore.m_compressorReserved = false; + synchronized (m_dataStore.reserveLock) { + m_dataStore.compressorReserved = false; } } @@ -366,6 +366,6 @@ public double getPressure(int channel) { @Override public void reportUsage(String device, String data) { - HAL.reportUsage("PCM[" + m_dataStore.m_module + "]/" + device, data); + HAL.reportUsage("PCM[" + m_dataStore.module + "]/" + device, data); } } diff --git a/wpilibj/src/main/java/org/wpilib/hardware/range/SharpIR.java b/wpilibj/src/main/java/org/wpilib/hardware/range/SharpIR.java index 261446caaa8..1f5b0c4efb2 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/range/SharpIR.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/range/SharpIR.java @@ -27,8 +27,12 @@ public class SharpIR implements Sendable, AutoCloseable { private SimDevice m_simDevice; private SimDouble m_simRange; + @SuppressWarnings("PMD.InternalFieldNamingConvention") private final double m_A; + + @SuppressWarnings("PMD.InternalFieldNamingConvention") private final double m_B; + private final double m_min; // m private final double m_max; // m diff --git a/wpilibj/src/main/java/org/wpilib/hardware/rotation/DutyCycle.java b/wpilibj/src/main/java/org/wpilib/hardware/rotation/DutyCycle.java index 69815d09a71..80422a941d1 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/rotation/DutyCycle.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/rotation/DutyCycle.java @@ -17,8 +17,7 @@ * These can be attached to any SmartIO. */ public class DutyCycle implements Sendable, AutoCloseable { - // Explicitly package private - final int m_handle; + private final int m_handle; private final int m_channel; /** diff --git a/wpilibj/src/main/java/org/wpilib/hardware/rotation/Encoder.java b/wpilibj/src/main/java/org/wpilib/hardware/rotation/Encoder.java index 1d9da0f531c..2a23e5448fa 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/rotation/Encoder.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/rotation/Encoder.java @@ -30,7 +30,7 @@ public class Encoder implements CounterBase, Sendable, AutoCloseable { private final EncodingType m_encodingType; - int m_encoder; // the HAL encoder object + private int m_encoder; // the HAL encoder object /** * Common initialization code for Encoders. This code allocates resources for Encoders and is diff --git a/wpilibj/src/main/java/org/wpilib/internal/PeriodicPriorityQueue.java b/wpilibj/src/main/java/org/wpilib/internal/PeriodicPriorityQueue.java index 2d4eeca958b..389117d3e9e 100644 --- a/wpilibj/src/main/java/org/wpilib/internal/PeriodicPriorityQueue.java +++ b/wpilibj/src/main/java/org/wpilib/internal/PeriodicPriorityQueue.java @@ -109,7 +109,7 @@ public void addAll(Collection callbacks) { * @param func The function whose callbacks should be removed. */ public void remove(Runnable func) { - m_queue.removeIf(callback -> callback.m_func.equals(func)); + m_queue.removeIf(callback -> callback.func.equals(func)); } /** @@ -163,7 +163,7 @@ public boolean runCallbacks(int notifier) { "No callbacks to run! Did you make sure to call add() first?"); } - NotifierJNI.setNotifierAlarm(notifier, callback.m_expirationTime, 0, true, true); + NotifierJNI.setNotifierAlarm(notifier, callback.expirationTime, 0, true, true); try { WPIUtilJNI.waitForObject(notifier); @@ -173,30 +173,28 @@ public boolean runCallbacks(int notifier) { m_loopStartTimeMicros = RobotController.getMonotonicTime(); - callback.m_func.run(); + callback.func.run(); // Increment the expiration time by the number of full periods it's behind // plus one to avoid rapid repeat fires from a large loop overrun. We // assume m_loopStartTime ≥ expirationTime rather than checking for it since // the callback wouldn't be running otherwise. - callback.m_expirationTime += - callback.m_period - + (m_loopStartTimeMicros - callback.m_expirationTime) - / callback.m_period - * callback.m_period; + callback.expirationTime += + callback.period + + (m_loopStartTimeMicros - callback.expirationTime) / callback.period * callback.period; m_queue.add(callback); // Process all other callbacks that are ready to run - while (m_queue.peek().m_expirationTime <= m_loopStartTimeMicros) { + while (m_queue.peek().expirationTime <= m_loopStartTimeMicros) { callback = m_queue.poll(); - callback.m_func.run(); + callback.func.run(); - callback.m_expirationTime += - callback.m_period - + (m_loopStartTimeMicros - callback.m_expirationTime) - / callback.m_period - * callback.m_period; + callback.expirationTime += + callback.period + + (m_loopStartTimeMicros - callback.expirationTime) + / callback.period + * callback.period; m_queue.add(callback); } @@ -223,13 +221,13 @@ public long getLoopStartTime() { */ public static class Callback implements Comparable { /** The function to execute when the callback fires. */ - public final Runnable m_func; + public final Runnable func; /** The period at which to run the callback in microseconds. */ - public final long m_period; + public final long period; /** The next scheduled execution time in monotonic timestamp microseconds. */ - public long m_expirationTime; + public long expirationTime; /** * Construct a callback container. @@ -240,13 +238,13 @@ public static class Callback implements Comparable { * @param offset The offset from the common starting time in microseconds. */ public Callback(Runnable func, long startTime, long period, long offset) { - this.m_func = func; - this.m_period = period; - this.m_expirationTime = + this.func = func; + this.period = period; + this.expirationTime = startTime + offset - + (1 + (RobotController.getMonotonicTime() - startTime - offset) / this.m_period) - * this.m_period; + + (1 + (RobotController.getMonotonicTime() - startTime - offset) / this.period) + * this.period; } /** @@ -280,7 +278,7 @@ public Callback(Runnable func, long timestamp, double periodSeconds) { */ @Override public boolean equals(Object rhs) { - return rhs instanceof Callback callback && m_expirationTime == callback.m_expirationTime; + return rhs instanceof Callback callback && expirationTime == callback.expirationTime; } /** @@ -290,7 +288,7 @@ public boolean equals(Object rhs) { */ @Override public int hashCode() { - return Long.hashCode(m_expirationTime); + return Long.hashCode(expirationTime); } /** @@ -306,7 +304,7 @@ public int hashCode() { public int compareTo(Callback rhs) { // Elements with sooner expiration times are sorted as lesser. The head of // Java's PriorityQueue is the least element. - return Long.compare(m_expirationTime, rhs.m_expirationTime); + return Long.compare(expirationTime, rhs.expirationTime); } } } diff --git a/wpilibj/src/main/java/org/wpilib/simulation/AlertSim.java b/wpilibj/src/main/java/org/wpilib/simulation/AlertSim.java index b3eee54011a..f31ce4ed1cf 100644 --- a/wpilibj/src/main/java/org/wpilib/simulation/AlertSim.java +++ b/wpilibj/src/main/java/org/wpilib/simulation/AlertSim.java @@ -31,23 +31,18 @@ public static class AlertInfo { } /** The handle of the alert. */ - @SuppressWarnings("MemberName") public final int handle; /** The group of the alert. */ - @SuppressWarnings("MemberName") public final String group; /** The text of the alert. */ - @SuppressWarnings("MemberName") public final String text; /** The time the alert became active. 0 if not active. */ - @SuppressWarnings("MemberName") public final long activeStartTime; /** The level of the alert (HIGH, MEDIUM, or LOW). */ - @SuppressWarnings("MemberName") public final Level level; /** diff --git a/wpilibj/src/main/java/org/wpilib/simulation/DifferentialDrivetrainSim.java b/wpilibj/src/main/java/org/wpilib/simulation/DifferentialDrivetrainSim.java index a3d3354f3ab..c046928ec9d 100644 --- a/wpilibj/src/main/java/org/wpilib/simulation/DifferentialDrivetrainSim.java +++ b/wpilibj/src/main/java/org/wpilib/simulation/DifferentialDrivetrainSim.java @@ -359,7 +359,7 @@ enum State { LEFT_POSITION(5), RIGHT_POSITION(6); - public final int value; + final int value; State(int i) { this.value = i; diff --git a/wpilibj/src/main/java/org/wpilib/smartdashboard/Field2d.java b/wpilibj/src/main/java/org/wpilib/smartdashboard/Field2d.java index 8d0dd609400..3344023a865 100644 --- a/wpilibj/src/main/java/org/wpilib/smartdashboard/Field2d.java +++ b/wpilibj/src/main/java/org/wpilib/smartdashboard/Field2d.java @@ -97,7 +97,7 @@ public synchronized Pose2d getRobotPose() { */ public synchronized FieldObject2d getObject(String name) { for (FieldObject2d obj : m_objects) { - if (obj.m_name.equals(name)) { + if (obj.name.equals(name)) { return obj; } } @@ -105,7 +105,7 @@ public synchronized FieldObject2d getObject(String name) { m_objects.add(obj); if (m_table != null) { synchronized (obj) { - obj.m_entry = m_table.getDoubleArrayTopic(name).getEntry(new double[] {}); + obj.entry = m_table.getDoubleArrayTopic(name).getEntry(new double[] {}); } } return obj; @@ -128,7 +128,7 @@ public void initSendable(NTSendableBuilder builder) { m_table = builder.getTable(); for (FieldObject2d obj : m_objects) { synchronized (obj) { - obj.m_entry = m_table.getDoubleArrayTopic(obj.m_name).getEntry(new double[] {}); + obj.entry = m_table.getDoubleArrayTopic(obj.name).getEntry(new double[] {}); obj.updateEntry(true); } } diff --git a/wpilibj/src/main/java/org/wpilib/smartdashboard/FieldObject2d.java b/wpilibj/src/main/java/org/wpilib/smartdashboard/FieldObject2d.java index bc0882565ba..10d6aba2271 100644 --- a/wpilibj/src/main/java/org/wpilib/smartdashboard/FieldObject2d.java +++ b/wpilibj/src/main/java/org/wpilib/smartdashboard/FieldObject2d.java @@ -24,13 +24,13 @@ public class FieldObject2d implements AutoCloseable { * @param name name */ FieldObject2d(String name) { - m_name = name; + this.name = name; } @Override public void close() { - if (m_entry != null) { - m_entry.close(); + if (entry != null) { + entry.close(); } } @@ -128,7 +128,7 @@ void updateEntry() { } synchronized void updateEntry(boolean setDefault) { - if (m_entry == null) { + if (entry == null) { return; } @@ -143,18 +143,18 @@ synchronized void updateEntry(boolean setDefault) { } if (setDefault) { - m_entry.setDefault(arr); + entry.setDefault(arr); } else { - m_entry.set(arr); + entry.set(arr); } } private synchronized void updateFromEntry() { - if (m_entry == null) { + if (entry == null) { return; } - double[] arr = m_entry.get(null); + double[] arr = entry.get(null); if (arr != null) { if ((arr.length % 3) != 0) { return; @@ -167,7 +167,7 @@ private synchronized void updateFromEntry() { } } - String m_name; - DoubleArrayEntry m_entry; + String name; + DoubleArrayEntry entry; private final List m_poses = new ArrayList<>(); } diff --git a/wpilibj/src/main/java/org/wpilib/smartdashboard/ListenerExecutor.java b/wpilibj/src/main/java/org/wpilib/smartdashboard/ListenerExecutor.java index 2d07029549d..b30ce8e387f 100644 --- a/wpilibj/src/main/java/org/wpilib/smartdashboard/ListenerExecutor.java +++ b/wpilibj/src/main/java/org/wpilib/smartdashboard/ListenerExecutor.java @@ -29,7 +29,7 @@ public void execute(Runnable task) { } /** Runs all posted tasks. Called periodically from main thread. */ - public void runListenerTasks() { + void runListenerTasks() { // Locally copy tasks from internal list; minimizes blocking time Collection tasks; synchronized (m_lock) { diff --git a/wpilibj/src/main/java/org/wpilib/smartdashboard/SendableBuilderImpl.java b/wpilibj/src/main/java/org/wpilib/smartdashboard/SendableBuilderImpl.java index 5080e9b7204..87a52e31cec 100644 --- a/wpilibj/src/main/java/org/wpilib/smartdashboard/SendableBuilderImpl.java +++ b/wpilibj/src/main/java/org/wpilib/smartdashboard/SendableBuilderImpl.java @@ -64,6 +64,7 @@ private interface TimedConsumer { void accept(T value, long time); } + @SuppressWarnings("PMD.PublicFieldNamingConvention") private static final class Property

implements AutoCloseable { @Override diff --git a/wpilibj/src/main/java/org/wpilib/system/Watchdog.java b/wpilibj/src/main/java/org/wpilib/system/Watchdog.java index 7aa3f88d3b2..a012bb543a8 100644 --- a/wpilibj/src/main/java/org/wpilib/system/Watchdog.java +++ b/wpilibj/src/main/java/org/wpilib/system/Watchdog.java @@ -33,9 +33,9 @@ public class Watchdog implements Closeable, Comparable { private final Runnable m_callback; private double m_lastTimeoutPrint; // s - boolean m_isExpired; + private boolean m_isExpired; - boolean m_suppressTimeoutMessage; + private boolean m_suppressTimeoutMessage; private final Tracer m_tracer; diff --git a/wpilibj/src/test/java/org/wpilib/event/NetworkBooleanEventTest.java b/wpilibj/src/test/java/org/wpilib/event/NetworkBooleanEventTest.java index 5ab08a52600..95ff3c470f4 100644 --- a/wpilibj/src/test/java/org/wpilib/event/NetworkBooleanEventTest.java +++ b/wpilibj/src/test/java/org/wpilib/event/NetworkBooleanEventTest.java @@ -13,17 +13,17 @@ import org.wpilib.networktables.NetworkTableInstance; class NetworkBooleanEventTest { - NetworkTableInstance m_inst; + NetworkTableInstance inst; @BeforeEach void setup() { - m_inst = NetworkTableInstance.create(); - m_inst.startLocal(); + inst = NetworkTableInstance.create(); + inst.startLocal(); } @AfterEach void teardown() { - m_inst.close(); + inst.close(); } @Test @@ -31,9 +31,9 @@ void testNetworkBooleanEvent() { var loop = new EventLoop(); var counter = new AtomicInteger(0); - var pub = m_inst.getTable("TestTable").getBooleanTopic("Test").publish(); + var pub = inst.getTable("TestTable").getBooleanTopic("Test").publish(); - new NetworkBooleanEvent(loop, m_inst, "TestTable", "Test").ifHigh(counter::incrementAndGet); + new NetworkBooleanEvent(loop, inst, "TestTable", "Test").ifHigh(counter::incrementAndGet); pub.set(false); loop.poll(); assertEquals(0, counter.get()); diff --git a/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java b/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java index 74c4c5fcf0a..d73afc6da8e 100644 --- a/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java +++ b/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java @@ -22,41 +22,42 @@ import org.wpilib.util.Color; @ResourceLock("timing") +@SuppressWarnings("PMD.PublicMemberInNonPublicType") class OpModeRobotTest { static final double kPeriod = 0.02; public static class MockOpMode implements OpMode { - public final AtomicInteger m_disabledPeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_startCount = new AtomicInteger(0); - public final AtomicInteger m_periodicCount = new AtomicInteger(0); - public final AtomicInteger m_endCount = new AtomicInteger(0); - public final AtomicInteger m_closeCount = new AtomicInteger(0); + public final AtomicInteger disabledPeriodicCount = new AtomicInteger(0); + public final AtomicInteger startCount = new AtomicInteger(0); + public final AtomicInteger periodicCount = new AtomicInteger(0); + public final AtomicInteger endCount = new AtomicInteger(0); + public final AtomicInteger closeCount = new AtomicInteger(0); MockOpMode() {} @Override public void close() { - m_closeCount.incrementAndGet(); + closeCount.incrementAndGet(); } @Override public void disabledPeriodic() { - m_disabledPeriodicCount.incrementAndGet(); + disabledPeriodicCount.incrementAndGet(); } @Override public void start() { - m_startCount.incrementAndGet(); + startCount.incrementAndGet(); } @Override public void periodic() { - m_periodicCount.incrementAndGet(); + periodicCount.incrementAndGet(); } @Override public void end() { - m_endCount.incrementAndGet(); + endCount.incrementAndGet(); } } @@ -66,9 +67,9 @@ public static class OneArgOpMode implements OpMode { } static class MockRobot extends OpModeRobot { - public final AtomicInteger m_driverStationConnectedCount = new AtomicInteger(0); - public final AtomicInteger m_nonePeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_robotPeriodicCount = new AtomicInteger(0); + public final AtomicInteger driverStationConnectedCount = new AtomicInteger(0); + public final AtomicInteger nonePeriodicCount = new AtomicInteger(0); + public final AtomicInteger robotPeriodicCount = new AtomicInteger(0); MockRobot() { super(); @@ -76,17 +77,17 @@ static class MockRobot extends OpModeRobot { @Override public void driverStationConnected() { - m_driverStationConnectedCount.incrementAndGet(); + driverStationConnectedCount.incrementAndGet(); } @Override public void nonePeriodic() { - m_nonePeriodicCount.incrementAndGet(); + nonePeriodicCount.incrementAndGet(); } @Override public void robotPeriodic() { - m_robotPeriodicCount.incrementAndGet(); + robotPeriodicCount.incrementAndGet(); } } @@ -243,7 +244,7 @@ class MyMockRobot extends MockRobot { // Time step to get periodic calls on 20 ms robot loop SimHooks.stepTiming(0.11); // 110ms - assertEquals(5, robot.m_nonePeriodicCount.get()); + assertEquals(5, robot.nonePeriodicCount.get()); robot.endCompetition(); robotThread.join(); @@ -266,15 +267,15 @@ class MyMockRobot extends MockRobot { SimHooks.waitForProgramStart(); // RobotPeriodic should be called regardless of state - assertEquals(0, robot.m_robotPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); // Step timing to allow callbacks to execute SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_robotPeriodicCount.get()); + assertEquals(1, robot.robotPeriodicCount.get()); // Additional time steps should continue calling robotPeriodic SimHooks.stepTiming(kPeriod); - assertEquals(2, robot.m_robotPeriodicCount.get()); + assertEquals(2, robot.robotPeriodicCount.get()); robot.endCompetition(); robotThread.join(); diff --git a/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java b/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java index c90e0a83b97..0035f14c49e 100644 --- a/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java +++ b/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java @@ -19,23 +19,23 @@ class TimedRobotTest { static final double kPeriod = 0.02; static class MockRobot extends TimedRobot { - public final AtomicInteger m_simulationInitCount = new AtomicInteger(0); - public final AtomicInteger m_disabledInitCount = new AtomicInteger(0); - public final AtomicInteger m_autonomousInitCount = new AtomicInteger(0); - public final AtomicInteger m_teleopInitCount = new AtomicInteger(0); - public final AtomicInteger m_utilityInitCount = new AtomicInteger(0); - - public final AtomicInteger m_robotPeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_simulationPeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_disabledPeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_autonomousPeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_teleopPeriodicCount = new AtomicInteger(0); - public final AtomicInteger m_utilityPeriodicCount = new AtomicInteger(0); - - public final AtomicInteger m_disabledExitCount = new AtomicInteger(0); - public final AtomicInteger m_autonomousExitCount = new AtomicInteger(0); - public final AtomicInteger m_teleopExitCount = new AtomicInteger(0); - public final AtomicInteger m_utilityExitCount = new AtomicInteger(0); + final AtomicInteger simulationInitCount = new AtomicInteger(0); + final AtomicInteger disabledInitCount = new AtomicInteger(0); + final AtomicInteger autonomousInitCount = new AtomicInteger(0); + final AtomicInteger teleopInitCount = new AtomicInteger(0); + final AtomicInteger utilityInitCount = new AtomicInteger(0); + + final AtomicInteger robotPeriodicCount = new AtomicInteger(0); + final AtomicInteger simulationPeriodicCount = new AtomicInteger(0); + final AtomicInteger disabledPeriodicCount = new AtomicInteger(0); + final AtomicInteger autonomousPeriodicCount = new AtomicInteger(0); + final AtomicInteger teleopPeriodicCount = new AtomicInteger(0); + final AtomicInteger utilityPeriodicCount = new AtomicInteger(0); + + final AtomicInteger disabledExitCount = new AtomicInteger(0); + final AtomicInteger autonomousExitCount = new AtomicInteger(0); + final AtomicInteger teleopExitCount = new AtomicInteger(0); + final AtomicInteger utilityExitCount = new AtomicInteger(0); MockRobot() { super(kPeriod); @@ -43,77 +43,77 @@ static class MockRobot extends TimedRobot { @Override public void simulationInit() { - m_simulationInitCount.addAndGet(1); + simulationInitCount.addAndGet(1); } @Override public void disabledInit() { - m_disabledInitCount.addAndGet(1); + disabledInitCount.addAndGet(1); } @Override public void autonomousInit() { - m_autonomousInitCount.addAndGet(1); + autonomousInitCount.addAndGet(1); } @Override public void teleopInit() { - m_teleopInitCount.addAndGet(1); + teleopInitCount.addAndGet(1); } @Override public void utilityInit() { - m_utilityInitCount.addAndGet(1); + utilityInitCount.addAndGet(1); } @Override public void robotPeriodic() { - m_robotPeriodicCount.addAndGet(1); + robotPeriodicCount.addAndGet(1); } @Override public void simulationPeriodic() { - m_simulationPeriodicCount.addAndGet(1); + simulationPeriodicCount.addAndGet(1); } @Override public void disabledPeriodic() { - m_disabledPeriodicCount.addAndGet(1); + disabledPeriodicCount.addAndGet(1); } @Override public void autonomousPeriodic() { - m_autonomousPeriodicCount.addAndGet(1); + autonomousPeriodicCount.addAndGet(1); } @Override public void teleopPeriodic() { - m_teleopPeriodicCount.addAndGet(1); + teleopPeriodicCount.addAndGet(1); } @Override public void utilityPeriodic() { - m_utilityPeriodicCount.addAndGet(1); + utilityPeriodicCount.addAndGet(1); } @Override public void disabledExit() { - m_disabledExitCount.addAndGet(1); + disabledExitCount.addAndGet(1); } @Override public void autonomousExit() { - m_autonomousExitCount.addAndGet(1); + autonomousExitCount.addAndGet(1); } @Override public void teleopExit() { - m_teleopExitCount.addAndGet(1); + teleopExitCount.addAndGet(1); } @Override public void utilityExit() { - m_utilityExitCount.addAndGet(1); + utilityExitCount.addAndGet(1); } } @@ -141,63 +141,63 @@ void disabledModeTest() { DriverStationSim.setEnabled(false); DriverStationSim.notifyNewData(); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(0, robot.m_robotPeriodicCount.get()); - assertEquals(0, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); + assertEquals(0, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(1, robot.m_robotPeriodicCount.get()); - assertEquals(1, robot.m_simulationPeriodicCount.get()); - assertEquals(1, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(1, robot.robotPeriodicCount.get()); + assertEquals(1, robot.simulationPeriodicCount.get()); + assertEquals(1, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(2, robot.m_robotPeriodicCount.get()); - assertEquals(2, robot.m_simulationPeriodicCount.get()); - assertEquals(2, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(2, robot.robotPeriodicCount.get()); + assertEquals(2, robot.simulationPeriodicCount.get()); + assertEquals(2, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); robot.endCompetition(); try { @@ -222,63 +222,63 @@ void autonomousModeTest() { DriverStationSim.setRobotMode(RobotMode.AUTONOMOUS); DriverStationSim.notifyNewData(); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(0, robot.m_robotPeriodicCount.get()); - assertEquals(0, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); + assertEquals(0, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(1, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(1, robot.m_robotPeriodicCount.get()); - assertEquals(1, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(1, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(1, robot.robotPeriodicCount.get()); + assertEquals(1, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(1, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(1, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(2, robot.m_robotPeriodicCount.get()); - assertEquals(2, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(2, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(2, robot.robotPeriodicCount.get()); + assertEquals(2, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(2, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); robot.endCompetition(); try { @@ -303,63 +303,63 @@ void teleopModeTest() { DriverStationSim.setRobotMode(RobotMode.TELEOPERATED); DriverStationSim.notifyNewData(); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(0, robot.m_robotPeriodicCount.get()); - assertEquals(0, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); + assertEquals(0, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(1, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(1, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(1, robot.m_robotPeriodicCount.get()); - assertEquals(1, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(1, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(1, robot.robotPeriodicCount.get()); + assertEquals(1, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(1, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(1, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(1, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(2, robot.m_robotPeriodicCount.get()); - assertEquals(2, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(2, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(2, robot.robotPeriodicCount.get()); + assertEquals(2, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(2, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); robot.endCompetition(); try { @@ -384,86 +384,86 @@ void utilityModeTest() { DriverStationSim.setRobotMode(RobotMode.UTILITY); DriverStationSim.notifyNewData(); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(0, robot.m_robotPeriodicCount.get()); - assertEquals(0, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(0, robot.m_utilityPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); + assertEquals(0, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(0, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(1, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(1, robot.utilityInitCount.get()); - assertEquals(1, robot.m_robotPeriodicCount.get()); - assertEquals(1, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(1, robot.m_utilityPeriodicCount.get()); + assertEquals(1, robot.robotPeriodicCount.get()); + assertEquals(1, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(1, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(1, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(1, robot.utilityInitCount.get()); - assertEquals(2, robot.m_robotPeriodicCount.get()); - assertEquals(2, robot.m_simulationPeriodicCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(2, robot.m_utilityPeriodicCount.get()); + assertEquals(2, robot.robotPeriodicCount.get()); + assertEquals(2, robot.simulationPeriodicCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(2, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); DriverStationSim.setEnabled(false); DriverStationSim.notifyNewData(); SimHooks.stepTiming(0.02); - assertEquals(1, robot.m_simulationInitCount.get()); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(1, robot.m_utilityInitCount.get()); + assertEquals(1, robot.simulationInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(1, robot.utilityInitCount.get()); - assertEquals(3, robot.m_robotPeriodicCount.get()); - assertEquals(3, robot.m_simulationPeriodicCount.get()); - assertEquals(1, robot.m_disabledPeriodicCount.get()); - assertEquals(0, robot.m_autonomousPeriodicCount.get()); - assertEquals(0, robot.m_teleopPeriodicCount.get()); - assertEquals(2, robot.m_utilityPeriodicCount.get()); + assertEquals(3, robot.robotPeriodicCount.get()); + assertEquals(3, robot.simulationPeriodicCount.get()); + assertEquals(1, robot.disabledPeriodicCount.get()); + assertEquals(0, robot.autonomousPeriodicCount.get()); + assertEquals(0, robot.teleopPeriodicCount.get()); + assertEquals(2, robot.utilityPeriodicCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(1, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(1, robot.utilityExitCount.get()); robot.endCompetition(); try { @@ -488,27 +488,27 @@ void modeChangeTest() { DriverStationSim.setEnabled(false); DriverStationSim.notifyNewData(); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(0, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(0, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(0, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); // Transition to autonomous DriverStationSim.setEnabled(true); @@ -517,15 +517,15 @@ void modeChangeTest() { SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_autonomousInitCount.get()); - assertEquals(0, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(1, robot.autonomousInitCount.get()); + assertEquals(0, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(1, robot.m_disabledExitCount.get()); - assertEquals(0, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(1, robot.disabledExitCount.get()); + assertEquals(0, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); // Transition to teleop DriverStationSim.setEnabled(true); @@ -534,15 +534,15 @@ void modeChangeTest() { SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_autonomousInitCount.get()); - assertEquals(1, robot.m_teleopInitCount.get()); - assertEquals(0, robot.m_utilityInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(1, robot.autonomousInitCount.get()); + assertEquals(1, robot.teleopInitCount.get()); + assertEquals(0, robot.utilityInitCount.get()); - assertEquals(1, robot.m_disabledExitCount.get()); - assertEquals(1, robot.m_autonomousExitCount.get()); - assertEquals(0, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(1, robot.disabledExitCount.get()); + assertEquals(1, robot.autonomousExitCount.get()); + assertEquals(0, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); // Transition to utility DriverStationSim.setEnabled(true); @@ -551,15 +551,15 @@ void modeChangeTest() { SimHooks.stepTiming(kPeriod); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_autonomousInitCount.get()); - assertEquals(1, robot.m_teleopInitCount.get()); - assertEquals(1, robot.m_utilityInitCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(1, robot.autonomousInitCount.get()); + assertEquals(1, robot.teleopInitCount.get()); + assertEquals(1, robot.utilityInitCount.get()); - assertEquals(1, robot.m_disabledExitCount.get()); - assertEquals(1, robot.m_autonomousExitCount.get()); - assertEquals(1, robot.m_teleopExitCount.get()); - assertEquals(0, robot.m_utilityExitCount.get()); + assertEquals(1, robot.disabledExitCount.get()); + assertEquals(1, robot.autonomousExitCount.get()); + assertEquals(1, robot.teleopExitCount.get()); + assertEquals(0, robot.utilityExitCount.get()); // Transition to disabled DriverStationSim.setEnabled(false); @@ -567,15 +567,15 @@ void modeChangeTest() { SimHooks.stepTiming(kPeriod); - assertEquals(2, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_autonomousInitCount.get()); - assertEquals(1, robot.m_teleopInitCount.get()); - assertEquals(1, robot.m_utilityInitCount.get()); + assertEquals(2, robot.disabledInitCount.get()); + assertEquals(1, robot.autonomousInitCount.get()); + assertEquals(1, robot.teleopInitCount.get()); + assertEquals(1, robot.utilityInitCount.get()); - assertEquals(1, robot.m_disabledExitCount.get()); - assertEquals(1, robot.m_autonomousExitCount.get()); - assertEquals(1, robot.m_teleopExitCount.get()); - assertEquals(1, robot.m_utilityExitCount.get()); + assertEquals(1, robot.disabledExitCount.get()); + assertEquals(1, robot.autonomousExitCount.get()); + assertEquals(1, robot.teleopExitCount.get()); + assertEquals(1, robot.utilityExitCount.get()); robot.endCompetition(); try { @@ -602,20 +602,20 @@ void addPeriodicTest() { DriverStationSim.setEnabled(false); DriverStationSim.notifyNewData(); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); assertEquals(0, callbackCount.get()); SimHooks.stepTiming(kPeriod / 2.0); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); assertEquals(1, callbackCount.get()); SimHooks.stepTiming(kPeriod / 2.0); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_disabledPeriodicCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(1, robot.disabledPeriodicCount.get()); assertEquals(2, callbackCount.get()); robot.endCompetition(); @@ -652,32 +652,32 @@ void addPeriodicWithOffsetTest() { DriverStationSim.setEnabled(false); DriverStationSim.notifyNewData(); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); assertEquals(0, callbackCount.get()); SimHooks.stepTiming(kPeriod * 3.0 / 8.0); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); assertEquals(0, callbackCount.get()); SimHooks.stepTiming(kPeriod * 3.0 / 8.0); - assertEquals(0, robot.m_disabledInitCount.get()); - assertEquals(0, robot.m_disabledPeriodicCount.get()); + assertEquals(0, robot.disabledInitCount.get()); + assertEquals(0, robot.disabledPeriodicCount.get()); assertEquals(1, callbackCount.get()); SimHooks.stepTiming(kPeriod / 4.0); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_disabledPeriodicCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(1, robot.disabledPeriodicCount.get()); assertEquals(1, callbackCount.get()); SimHooks.stepTiming(kPeriod / 4.0); - assertEquals(1, robot.m_disabledInitCount.get()); - assertEquals(1, robot.m_disabledPeriodicCount.get()); + assertEquals(1, robot.disabledInitCount.get()); + assertEquals(1, robot.disabledPeriodicCount.get()); assertEquals(2, callbackCount.get()); robot.endCompetition(); diff --git a/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java b/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java index 17fcdbafde3..20ac0f4c4a4 100644 --- a/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java +++ b/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java @@ -17,7 +17,7 @@ class TimesliceRobotTest { static class MockRobot extends TimesliceRobot { - public final AtomicInteger m_robotPeriodicCount = new AtomicInteger(0); + final AtomicInteger robotPeriodicCount = new AtomicInteger(0); MockRobot() { super(0.002, 0.005); @@ -25,7 +25,7 @@ static class MockRobot extends TimesliceRobot { @Override public void robotPeriodic() { - m_robotPeriodicCount.addAndGet(1); + robotPeriodicCount.addAndGet(1); } } @@ -70,25 +70,25 @@ void scheduleTest() { // robotPeriodic()). SimHooks.stepTiming(0.005); - assertEquals(0, robot.m_robotPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); assertEquals(0, callbackCount1.get()); assertEquals(0, callbackCount2.get()); // Step to 1.5 ms SimHooks.stepTiming(0.0015); - assertEquals(0, robot.m_robotPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); assertEquals(0, callbackCount1.get()); assertEquals(0, callbackCount2.get()); // Step to 2.25 ms SimHooks.stepTiming(0.00075); - assertEquals(0, robot.m_robotPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); assertEquals(1, callbackCount1.get()); assertEquals(0, callbackCount2.get()); // Step to 2.75 ms SimHooks.stepTiming(0.0005); - assertEquals(0, robot.m_robotPeriodicCount.get()); + assertEquals(0, robot.robotPeriodicCount.get()); assertEquals(1, callbackCount1.get()); assertEquals(1, callbackCount2.get()); diff --git a/wpilibj/src/test/java/org/wpilib/hardware/led/AddressableLEDBufferTest.java b/wpilibj/src/test/java/org/wpilib/hardware/led/AddressableLEDBufferTest.java index 101b261db34..cacf90b06f3 100644 --- a/wpilibj/src/test/java/org/wpilib/hardware/led/AddressableLEDBufferTest.java +++ b/wpilibj/src/test/java/org/wpilib/hardware/led/AddressableLEDBufferTest.java @@ -24,9 +24,9 @@ void hsvConvertTest(int h, int s, int v, int r, int g, int b) { var buffer = new AddressableLEDBuffer(1); buffer.setHSV(0, h, s, v); assertAll( - () -> assertEquals((byte) r, buffer.m_buffer[0], "R value didn't match"), - () -> assertEquals((byte) g, buffer.m_buffer[1], "G value didn't match"), - () -> assertEquals((byte) b, buffer.m_buffer[2], "B value didn't match")); + () -> assertEquals((byte) r, buffer.buffer[0], "R value didn't match"), + () -> assertEquals((byte) g, buffer.buffer[1], "G value didn't match"), + () -> assertEquals((byte) b, buffer.buffer[2], "B value didn't match")); } static Stream hsvToRgbProvider() { diff --git a/wpilibj/src/test/java/org/wpilib/hardware/led/LEDPatternTest.java b/wpilibj/src/test/java/org/wpilib/hardware/led/LEDPatternTest.java index b78efe99c59..26cc7591f73 100644 --- a/wpilibj/src/test/java/org/wpilib/hardware/led/LEDPatternTest.java +++ b/wpilibj/src/test/java/org/wpilib/hardware/led/LEDPatternTest.java @@ -39,10 +39,10 @@ import org.wpilib.util.Color8Bit; class LEDPatternTest { - long m_mockTime; + long mockTime; // Applies a pattern of White, Yellow, Purple to LED triplets - LEDPattern m_whiteYellowPurple = + LEDPattern whiteYellowPurple = (reader, writer) -> { for (int led = 0; led < reader.getLength(); led++) { switch (led % 3) { @@ -64,8 +64,8 @@ class LEDPatternTest { @BeforeEach void setUp() { - m_mockTime = 0; - RobotController.setTimeSource(() -> m_mockTime); + mockTime = 0; + RobotController.setTimeSource(() -> mockTime); } @AfterEach @@ -224,7 +224,7 @@ void scrollForward() { var scroll = base.scrollAtRelativeVelocity(Value.per(Microsecond).of(1 / 256.0)); for (int time = 0; time < 500; time++) { - m_mockTime = time; + mockTime = time; scroll.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -258,7 +258,7 @@ void scrollBackward() { var scroll = base.scrollAtRelativeVelocity(Value.per(Microsecond).of(-1 / 256.0)); for (int time = 0; time < 500; time++) { - m_mockTime = time; + mockTime = time; scroll.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -294,7 +294,7 @@ void scrollAbsoluteVelocityForward() { var scroll = base.scrollAtAbsoluteVelocity(MetersPerSecond.of(16), Centimeters.of(2)); for (int time = 0; time < 500; time++) { - m_mockTime = time * 1_250; // 1.25ms per LED + mockTime = time * 1_250; // 1.25ms per LED scroll.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -330,7 +330,7 @@ void scrollAbsoluteVelocityBackward() { var scroll = base.scrollAtAbsoluteVelocity(MetersPerSecond.of(-16), Centimeters.of(2)); for (int time = 0; time < 500; time++) { - m_mockTime = time * 1_250; // 1.25ms per LED + mockTime = time * 1_250; // 1.25ms per LED scroll.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -459,7 +459,7 @@ void offsetPositive() { var buffer = new AddressableLEDBuffer(21); // offset repeats PWY - var offset = m_whiteYellowPurple.offsetBy(1); + var offset = whiteYellowPurple.offsetBy(1); offset.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -486,7 +486,7 @@ void offsetNegative() { var buffer = new AddressableLEDBuffer(21); // offset repeats YPW - var offset = m_whiteYellowPurple.offsetBy(-1); + var offset = whiteYellowPurple.offsetBy(-1); offset.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -513,7 +513,7 @@ void offsetZero() { var buffer = new AddressableLEDBuffer(21); // offset copies the base pattern, WYP - var offset = m_whiteYellowPurple.offsetBy(0); + var offset = whiteYellowPurple.offsetBy(0); offset.applyTo(buffer); for (int led = 0; led < buffer.getLength(); led++) { @@ -543,7 +543,7 @@ void blinkSymmetric() { var buffer = new AddressableLEDBuffer(1); for (int t = 0; t < 8; t++) { - m_mockTime = t * 1_000_000L; // time travel 1 second + mockTime = t * 1_000_000L; // time travel 1 second pattern.applyTo(buffer); Color color = buffer.getLED(0); @@ -575,7 +575,7 @@ void blinkAsymmetric() { var buffer = new AddressableLEDBuffer(1); for (int t = 0; t < 8; t++) { - m_mockTime = t * 1_000_000L; // time travel 1 second + mockTime = t * 1_000_000L; // time travel 1 second pattern.applyTo(buffer); Color color = buffer.getLED(0); @@ -627,31 +627,31 @@ void breathe() { var buffer = new AddressableLEDBuffer(1); { - m_mockTime = 0; // start + mockTime = 0; // start pattern.applyTo(buffer); assertColorEquals(WHITE, buffer.getLED(0)); } { - m_mockTime = 1; // midway (down) + mockTime = 1; // midway (down) pattern.applyTo(buffer); assertColorEquals(midGray, buffer.getLED(0)); } { - m_mockTime = 2; // bottom + mockTime = 2; // bottom pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); } { - m_mockTime = 3; // midway (up) + mockTime = 3; // midway (up) pattern.applyTo(buffer); assertColorEquals(midGray, buffer.getLED(0)); } { - m_mockTime = 4; // back to start + mockTime = 4; // back to start pattern.applyTo(buffer); assertColorEquals(WHITE, buffer.getLED(0)); } @@ -871,7 +871,7 @@ void relativeScrollingMask() { var buffer = new AddressableLEDBuffer(8); { - m_mockTime = 0; // start + mockTime = 0; // start pattern.applyTo(buffer); assertColorEquals(RED, buffer.getLED(0)); assertColorEquals(RED, buffer.getLED(1)); @@ -884,7 +884,7 @@ void relativeScrollingMask() { } { - m_mockTime = 1; + mockTime = 1; pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); assertColorEquals(RED, buffer.getLED(1)); @@ -897,7 +897,7 @@ void relativeScrollingMask() { } { - m_mockTime = 2; + mockTime = 2; pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); assertColorEquals(BLACK, buffer.getLED(1)); @@ -910,7 +910,7 @@ void relativeScrollingMask() { } { - m_mockTime = 3; + mockTime = 3; pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); assertColorEquals(BLACK, buffer.getLED(1)); @@ -936,7 +936,7 @@ void absoluteScrollingMask() { var buffer = new AddressableLEDBuffer(8); { - m_mockTime = 0; // start + mockTime = 0; // start pattern.applyTo(buffer); assertColorEquals(RED, buffer.getLED(0)); assertColorEquals(RED, buffer.getLED(1)); @@ -949,7 +949,7 @@ void absoluteScrollingMask() { } { - m_mockTime = 1; + mockTime = 1; pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); assertColorEquals(RED, buffer.getLED(1)); @@ -962,7 +962,7 @@ void absoluteScrollingMask() { } { - m_mockTime = 2; + mockTime = 2; pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); assertColorEquals(BLACK, buffer.getLED(1)); @@ -975,7 +975,7 @@ void absoluteScrollingMask() { } { - m_mockTime = 3; + mockTime = 3; pattern.applyTo(buffer); assertColorEquals(BLACK, buffer.getLED(0)); assertColorEquals(BLACK, buffer.getLED(1)); diff --git a/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator.java b/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator.java index 9e7d659feb4..38be8da77e9 100644 --- a/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator.java +++ b/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator.java @@ -421,7 +421,7 @@ private VisionUpdate(Pose2d visionPose, Pose2d odometryPose) { * @param pose The pose to compensate. * @return The compensated pose. */ - public Pose2d compensate(Pose2d pose) { + Pose2d compensate(Pose2d pose) { var delta = pose.minus(this.odometryPose); return this.visionPose.plus(delta); } diff --git a/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator3d.java b/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator3d.java index b6482fbb19d..536466640cc 100644 --- a/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator3d.java +++ b/wpimath/src/main/java/org/wpilib/math/estimator/PoseEstimator3d.java @@ -436,7 +436,7 @@ private VisionUpdate(Pose3d visionPose, Pose3d odometryPose) { * @param pose The pose to compensate. * @return The compensated pose. */ - public Pose3d compensate(Pose3d pose) { + Pose3d compensate(Pose3d pose) { var delta = pose.minus(this.odometryPose); return this.visionPose.plus(delta); } diff --git a/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateAxis.java b/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateAxis.java index 7bddc949e8b..14862933c1f 100644 --- a/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateAxis.java +++ b/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateAxis.java @@ -17,7 +17,7 @@ public class CoordinateAxis { private static final CoordinateAxis m_u = new CoordinateAxis(0.0, 0.0, 1.0); private static final CoordinateAxis m_d = new CoordinateAxis(0.0, 0.0, -1.0); - final Vector m_axis; + final Vector axis; /** * Constructs a coordinate system axis within the NWU coordinate system and normalizes it. @@ -28,7 +28,7 @@ public class CoordinateAxis { */ public CoordinateAxis(double x, double y, double z) { double norm = Math.sqrt(x * x + y * y + z * z); - m_axis = VecBuilder.fill(x / norm, y / norm, z / norm); + axis = VecBuilder.fill(x / norm, y / norm, z / norm); } /** diff --git a/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateSystem.java b/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateSystem.java index b5198fe0b50..4e478d2d725 100644 --- a/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateSystem.java +++ b/wpimath/src/main/java/org/wpilib/math/geometry/CoordinateSystem.java @@ -34,9 +34,9 @@ public CoordinateSystem( // NWU coordinate system. Each column vector in the change of basis matrix is // one of the old basis vectors mapped to its representation in the new basis. var R = new Matrix<>(Nat.N3(), Nat.N3()); - R.assignBlock(0, 0, positiveX.m_axis); - R.assignBlock(0, 1, positiveY.m_axis); - R.assignBlock(0, 2, positiveZ.m_axis); + R.assignBlock(0, 0, positiveX.axis); + R.assignBlock(0, 1, positiveY.axis); + R.assignBlock(0, 2, positiveZ.axis); // If determinant is -1, coordinate system is left-handed if (Math.abs(R.det() + 1.0) < 1e-9) { diff --git a/wpimath/src/test/java/org/wpilib/math/controller/LTVDifferentialDriveControllerTest.java b/wpimath/src/test/java/org/wpilib/math/controller/LTVDifferentialDriveControllerTest.java index 1282b0db59e..906df67041b 100644 --- a/wpimath/src/test/java/org/wpilib/math/controller/LTVDifferentialDriveControllerTest.java +++ b/wpimath/src/test/java/org/wpilib/math/controller/LTVDifferentialDriveControllerTest.java @@ -32,19 +32,19 @@ class LTVDifferentialDriveControllerTest { /** States of the drivetrain system. */ static class State { /// X position in global coordinate frame. - public static final int kX = 0; + static final int kX = 0; /// Y position in global coordinate frame. - public static final int kY = 1; + static final int kY = 1; /// Heading in global coordinate frame. - public static final int kHeading = 2; + static final int kHeading = 2; /// Left encoder velocity. - public static final int kLeftVelocity = 3; + static final int kLeftVelocity = 3; /// Right encoder velocity. - public static final int kRightVelocity = 4; + static final int kRightVelocity = 4; } private static final double kLinearV = 3.02; // V/(m/s) diff --git a/wpimath/src/test/java/org/wpilib/math/controller/LinearSystemLoopTest.java b/wpimath/src/test/java/org/wpilib/math/controller/LinearSystemLoopTest.java index f9ab499cb47..90c16534267 100644 --- a/wpimath/src/test/java/org/wpilib/math/controller/LinearSystemLoopTest.java +++ b/wpimath/src/test/java/org/wpilib/math/controller/LinearSystemLoopTest.java @@ -26,7 +26,7 @@ class LinearSystemLoopTest { private static final double kPositionStddev = 0.0001; private static final Random random = new Random(); - LinearSystem m_plant = + LinearSystem plant = Models.elevatorFromPhysicalConstants(DCMotor.getVex775Pro(2), 5, 0.0181864, 1.0); @SuppressWarnings("unchecked") @@ -34,7 +34,7 @@ class LinearSystemLoopTest { new KalmanFilter<>( Nat.N2(), Nat.N1(), - (LinearSystem) m_plant.slice(0), + (LinearSystem) plant.slice(0), VecBuilder.fill(0.05, 1.0), VecBuilder.fill(0.0001), kDt); @@ -42,7 +42,7 @@ class LinearSystemLoopTest { @SuppressWarnings("unchecked") LinearQuadraticRegulator m_controller = new LinearQuadraticRegulator<>( - (LinearSystem) m_plant.slice(0), + (LinearSystem) plant.slice(0), VecBuilder.fill(0.02, 0.4), VecBuilder.fill(12.0), 0.005); @@ -50,7 +50,7 @@ class LinearSystemLoopTest { @SuppressWarnings("unchecked") private final LinearSystemLoop m_loop = new LinearSystemLoop<>( - (LinearSystem) m_plant.slice(0), m_controller, m_observer, 12, 0.005); + (LinearSystem) plant.slice(0), m_controller, m_observer, 12, 0.005); private static void updateTwoState( LinearSystem plant, LinearSystemLoop loop, double noise) { @@ -80,7 +80,7 @@ void testStateSpaceEnabled() { m_loop.setNextR(VecBuilder.fill(state.position, state.velocity)); updateTwoState( - (LinearSystem) m_plant.slice(0), + (LinearSystem) plant.slice(0), m_loop, (random.nextGaussian()) * kPositionStddev); var u = m_loop.getU(0); diff --git a/wpimath/src/test/java/org/wpilib/math/linalg/DARETest.java b/wpimath/src/test/java/org/wpilib/math/linalg/DARETest.java index f29b7d4eef6..88bee0c4474 100644 --- a/wpimath/src/test/java/org/wpilib/math/linalg/DARETest.java +++ b/wpimath/src/test/java/org/wpilib/math/linalg/DARETest.java @@ -19,8 +19,7 @@ class DARETest extends UtilityClassTest { super(DARE.class); } - public static void assertMatrixEqual( - Matrix A, Matrix B) { + static void assertMatrixEqual(Matrix A, Matrix B) { for (int i = 0; i < A.getNumRows(); i++) { for (int j = 0; j < A.getNumCols(); j++) { assertEquals(A.get(i, j), B.get(i, j), 1e-4); diff --git a/wpimath/src/test/java/org/wpilib/math/trajectory/ExponentialProfileTest.java b/wpimath/src/test/java/org/wpilib/math/trajectory/ExponentialProfileTest.java index 2cf6e3ccc5e..cf44104c564 100644 --- a/wpimath/src/test/java/org/wpilib/math/trajectory/ExponentialProfileTest.java +++ b/wpimath/src/test/java/org/wpilib/math/trajectory/ExponentialProfileTest.java @@ -198,9 +198,9 @@ void largeNegativeInitialVelocity() { @SuppressWarnings("PMD.TestClassWithoutTestCases") static class TestCase { - public final ExponentialProfile.State initial; - public final ExponentialProfile.State goal; - public final ExponentialProfile.State inflectionPoint; + final ExponentialProfile.State initial; + final ExponentialProfile.State goal; + final ExponentialProfile.State inflectionPoint; TestCase( ExponentialProfile.State initial, diff --git a/wpiunits/src/test/java/org/wpilib/units/ExampleUnit.java b/wpiunits/src/test/java/org/wpilib/units/ExampleUnit.java index 9c940f6f72d..e4311178130 100644 --- a/wpiunits/src/test/java/org/wpilib/units/ExampleUnit.java +++ b/wpiunits/src/test/java/org/wpilib/units/ExampleUnit.java @@ -22,7 +22,7 @@ class ExampleUnit extends Unit { super(null, baseUnitEquivalent, name, symbol); } - public double convertFrom(double magnitude, ExampleUnit otherUnit) { + double convertFrom(double magnitude, ExampleUnit otherUnit) { return fromBaseUnits(otherUnit.toBaseUnits(magnitude)); } diff --git a/wpiutil/src/main/java/org/wpilib/util/sendable/SendableRegistry.java b/wpiutil/src/main/java/org/wpilib/util/sendable/SendableRegistry.java index 9af0a187871..41b9640793e 100644 --- a/wpiutil/src/main/java/org/wpilib/util/sendable/SendableRegistry.java +++ b/wpiutil/src/main/java/org/wpilib/util/sendable/SendableRegistry.java @@ -15,6 +15,7 @@ */ @SuppressWarnings("PMD.AvoidCatchingGenericException") public final class SendableRegistry { + @SuppressWarnings("PMD.PublicFieldNamingConvention") private static class Component implements AutoCloseable { Component() {} diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/DynamicStruct.java b/wpiutil/src/main/java/org/wpilib/util/struct/DynamicStruct.java index c37031b640a..b6c0698644d 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/DynamicStruct.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/DynamicStruct.java @@ -389,8 +389,8 @@ public String getStringField(StructFieldDescriptor field) { if (!m_desc.isValid()) { throw new IllegalStateException("struct descriptor is not valid"); } - byte[] bytes = new byte[field.m_arraySize]; - m_data.position(field.m_offset).get(bytes, 0, field.m_arraySize); + byte[] bytes = new byte[field.getArraySize()]; + m_data.position(field.offset).get(bytes, 0, field.getArraySize()); // Find last non zero character int stringLength = bytes.length; for (; stringLength > 0; stringLength--) { @@ -464,10 +464,10 @@ public boolean setStringField(StructFieldDescriptor field, String value) { throw new IllegalStateException("struct descriptor is not valid"); } ByteBuffer bb = StandardCharsets.UTF_8.encode(value); - int len = Math.min(bb.remaining(), field.m_arraySize); + int len = Math.min(bb.remaining(), field.getArraySize()); boolean copiedFull = len == bb.remaining(); - m_data.position(field.m_offset).put(bb.limit(len)); - for (int i = len; i < field.m_arraySize; i++) { + m_data.position(field.offset).put(bb.limit(len)); + for (int i = len; i < field.getArraySize(); i++) { m_data.put((byte) 0); } return copiedFull; @@ -494,12 +494,12 @@ public DynamicStruct getStructField(StructFieldDescriptor field, int arrIndex) { if (!m_desc.isValid()) { throw new IllegalStateException("struct descriptor is not valid"); } - if (arrIndex < 0 || arrIndex >= field.m_arraySize) { + if (arrIndex < 0 || arrIndex >= field.getArraySize()) { throw new ArrayIndexOutOfBoundsException( - "arrIndex (" + arrIndex + ") is larger than array size (" + field.m_arraySize + ")"); + "arrIndex (" + arrIndex + ") is larger than array size (" + field.getArraySize() + ")"); } StructDescriptor struct = field.getStruct(); - return wrap(struct, m_data.position(field.m_offset + arrIndex * struct.m_size)); + return wrap(struct, m_data.position(field.offset + arrIndex * struct.size)); } /** @@ -544,12 +544,12 @@ public void setStructField(StructFieldDescriptor field, DynamicStruct value, int if (!value.getDescriptor().isValid()) { throw new IllegalStateException("value's struct descriptor is not valid"); } - if (arrIndex < 0 || arrIndex >= field.m_arraySize) { + if (arrIndex < 0 || arrIndex >= field.getArraySize()) { throw new ArrayIndexOutOfBoundsException( - "arrIndex (" + arrIndex + ") is larger than array size (" + field.m_arraySize + ")"); + "arrIndex (" + arrIndex + ") is larger than array size (" + field.getArraySize() + ")"); } m_data - .position(field.m_offset + arrIndex * struct.m_size) + .position(field.offset + arrIndex * struct.size) .put(value.m_data.position(0).limit(value.getDescriptor().getSize())); } @@ -574,28 +574,28 @@ private long getFieldImpl(StructFieldDescriptor field, int arrIndex) { if (!m_desc.isValid()) { throw new IllegalStateException("struct descriptor is not valid"); } - if (arrIndex < 0 || arrIndex >= field.m_arraySize) { + if (arrIndex < 0 || arrIndex >= field.getArraySize()) { throw new ArrayIndexOutOfBoundsException( - "arrIndex (" + arrIndex + ") is larger than array size (" + field.m_arraySize + ")"); + "arrIndex (" + arrIndex + ") is larger than array size (" + field.getArraySize() + ")"); } long val = - switch (field.m_size) { - case 1 -> m_data.get(field.m_offset + arrIndex); - case 2 -> m_data.getShort(field.m_offset + arrIndex * 2); - case 4 -> m_data.getInt(field.m_offset + arrIndex * 4); - case 8 -> m_data.getLong(field.m_offset + arrIndex * 8); + switch (field.size) { + case 1 -> m_data.get(field.offset + arrIndex); + case 2 -> m_data.getShort(field.offset + arrIndex * 2); + case 4 -> m_data.getInt(field.offset + arrIndex * 4); + case 8 -> m_data.getLong(field.offset + arrIndex * 8); default -> throw new IllegalStateException("invalid field size"); }; if (field.isUint() || field.getType() == StructFieldType.BOOL) { // for unsigned fields, we can simply logical shift and mask - return (val >>> field.m_bitShift) & field.getBitMask(); + return (val >>> field.bitShift) & field.getBitMask(); } else { // to get sign extension, shift so the sign bit within the bitfield goes to the long's sign // bit (also clearing all higher bits), then shift back down (also clearing all lower bits); // since upper and lower bits are cleared with the shifts, the bitmask is unnecessary - return (val << (64 - field.m_bitShift - field.getBitWidth())) >> (64 - field.getBitWidth()); + return (val << (64 - field.bitShift - field.getBitWidth())) >> (64 - field.getBitWidth()); } } @@ -606,48 +606,48 @@ private void setFieldImpl(StructFieldDescriptor field, long value, int arrIndex) if (!m_desc.isValid()) { throw new IllegalStateException("struct descriptor is not valid"); } - if (arrIndex < 0 || arrIndex >= field.m_arraySize) { + if (arrIndex < 0 || arrIndex >= field.getArraySize()) { throw new ArrayIndexOutOfBoundsException( - "arrIndex (" + arrIndex + ") is larger than array size (" + field.m_arraySize + ")"); + "arrIndex (" + arrIndex + ") is larger than array size (" + field.getArraySize() + ")"); } // common case is no bit shift and no masking if (!field.isBitField()) { - switch (field.m_size) { - case 1 -> m_data.put(field.m_offset + arrIndex, (byte) value); - case 2 -> m_data.putShort(field.m_offset + arrIndex * 2, (short) value); - case 4 -> m_data.putInt(field.m_offset + arrIndex * 4, (int) value); - case 8 -> m_data.putLong(field.m_offset + arrIndex * 8, value); + switch (field.size) { + case 1 -> m_data.put(field.offset + arrIndex, (byte) value); + case 2 -> m_data.putShort(field.offset + arrIndex * 2, (short) value); + case 4 -> m_data.putInt(field.offset + arrIndex * 4, (int) value); + case 8 -> m_data.putLong(field.offset + arrIndex * 8, value); default -> throw new IllegalStateException("invalid field size"); } return; } // handle bit shifting and masking into current value - switch (field.m_size) { + switch (field.size) { case 1 -> { - byte val = m_data.get(field.m_offset + arrIndex); - val &= (byte) ~(field.getBitMask() << field.m_bitShift); - val |= (byte) ((value & field.getBitMask()) << field.m_bitShift); - m_data.put(field.m_offset + arrIndex, val); + byte val = m_data.get(field.offset + arrIndex); + val &= (byte) ~(field.getBitMask() << field.bitShift); + val |= (byte) ((value & field.getBitMask()) << field.bitShift); + m_data.put(field.offset + arrIndex, val); } case 2 -> { - short val = m_data.getShort(field.m_offset + arrIndex * 2); - val &= (short) ~(field.getBitMask() << field.m_bitShift); - val |= (short) ((value & field.getBitMask()) << field.m_bitShift); - m_data.putShort(field.m_offset + arrIndex * 2, val); + short val = m_data.getShort(field.offset + arrIndex * 2); + val &= (short) ~(field.getBitMask() << field.bitShift); + val |= (short) ((value & field.getBitMask()) << field.bitShift); + m_data.putShort(field.offset + arrIndex * 2, val); } case 4 -> { - int val = m_data.getInt(field.m_offset + arrIndex * 4); - val &= (int) ~(field.getBitMask() << field.m_bitShift); - val |= (int) ((value & field.getBitMask()) << field.m_bitShift); - m_data.putInt(field.m_offset + arrIndex * 4, val); + int val = m_data.getInt(field.offset + arrIndex * 4); + val &= (int) ~(field.getBitMask() << field.bitShift); + val |= (int) ((value & field.getBitMask()) << field.bitShift); + m_data.putInt(field.offset + arrIndex * 4, val); } case 8 -> { - long val = m_data.getLong(field.m_offset + arrIndex * 8); - val &= ~(field.getBitMask() << field.m_bitShift); - val |= (value & field.getBitMask()) << field.m_bitShift; - m_data.putLong(field.m_offset + arrIndex * 8, val); + long val = m_data.getLong(field.offset + arrIndex * 8); + val &= ~(field.getBitMask() << field.bitShift); + val |= (value & field.getBitMask()) << field.bitShift; + m_data.putLong(field.offset + arrIndex * 8, val); } default -> throw new IllegalStateException("invalid field size"); } diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptor.java b/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptor.java index f493d0224a5..8745c38d15b 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptor.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptor.java @@ -33,7 +33,7 @@ public String getName() { * @return schema */ public String getSchema() { - return m_schema; + return schema; } /** @@ -43,7 +43,7 @@ public String getSchema() { * @return true if valid */ public boolean isValid() { - return m_valid; + return valid; } /** @@ -53,10 +53,10 @@ public boolean isValid() { * @throws IllegalStateException if descriptor is invalid */ public int getSize() { - if (!m_valid) { + if (!valid) { throw new IllegalStateException("descriptor is invalid"); } - return m_size; + return size; } /** @@ -66,7 +66,7 @@ public int getSize() { * @return field descriptor, or nullptr if not found */ public StructFieldDescriptor findFieldByName(String name) { - return m_fieldsByName.get(name); + return fieldsByName.get(name); } /** @@ -75,12 +75,12 @@ public StructFieldDescriptor findFieldByName(String name) { * @return field descriptors */ public List getFields() { - return m_fields; + return fields; } boolean checkCircular(Stack stack) { stack.push(this); - for (StructDescriptor ref : m_references) { + for (StructDescriptor ref : references) { if (stack.contains(ref)) { return false; } @@ -96,46 +96,46 @@ void calculateOffsets(Stack stack) { int offset = 0; int shift = 0; int prevBitfieldSize = 0; - for (StructFieldDescriptor field : m_fields) { + for (StructFieldDescriptor field : fields) { if (!field.isBitField()) { shift = 0; // reset shift on non-bitfield element offset += prevBitfieldSize; // finish bitfield if active prevBitfieldSize = 0; // previous is now not bitfield - field.m_offset = offset; + field.offset = offset; StructDescriptor struct = field.getStruct(); if (struct != null) { if (!struct.isValid()) { - m_valid = false; + valid = false; return; } - field.m_size = struct.m_size; + field.size = struct.size; } - offset += field.m_size * field.m_arraySize; + offset += field.size * field.getArraySize(); } else { int bitWidth = field.getBitWidth(); if (field.getType() == StructFieldType.BOOL && prevBitfieldSize != 0 && (shift + 1) <= (prevBitfieldSize * 8)) { // bool takes on size of preceding bitfield type (if it fits) - field.m_size = prevBitfieldSize; - } else if (field.m_size != prevBitfieldSize || (shift + bitWidth) > (field.m_size * 8)) { + field.size = prevBitfieldSize; + } else if (field.size != prevBitfieldSize || (shift + bitWidth) > (field.size * 8)) { shift = 0; offset += prevBitfieldSize; } - prevBitfieldSize = field.m_size; - field.m_offset = offset; - field.m_bitShift = shift; + prevBitfieldSize = field.size; + field.offset = offset; + field.bitShift = shift; shift += bitWidth; } } // update struct size - m_size = offset + prevBitfieldSize; - m_valid = true; + size = offset + prevBitfieldSize; + valid = true; // now that we're valid, referring types may be too stack.push(this); - for (StructDescriptor ref : m_references) { + for (StructDescriptor ref : references) { if (stack.contains(ref)) { throw new IllegalStateException( "internal error (inconsistent data): circular struct reference between " @@ -149,10 +149,10 @@ void calculateOffsets(Stack stack) { } private final String m_name; - String m_schema; - final Set m_references = new HashSet<>(); - final List m_fields = new ArrayList<>(); - final Map m_fieldsByName = new HashMap<>(); - int m_size; - boolean m_valid; + String schema; + final Set references = new HashSet<>(); + final List fields = new ArrayList<>(); + final Map fieldsByName = new HashMap<>(); + int size; + boolean valid; } diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptorDatabase.java b/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptorDatabase.java index ee89de38a9b..9060f140b35 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptorDatabase.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/StructDescriptorDatabase.java @@ -37,8 +37,8 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio // turn parsed schema into descriptors StructDescriptor theStruct = m_structs.computeIfAbsent(name, StructDescriptor::new); - theStruct.m_schema = schema; - theStruct.m_fields.clear(); + theStruct.schema = schema; + theStruct.fields.clear(); boolean isValid = true; for (ParsedDeclaration decl : parsed.declarations) { StructFieldType type = StructFieldType.fromString(decl.typeString); @@ -89,7 +89,7 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio } // add to cross-references for when the struct does become valid - aStruct.m_references.add(theStruct); + aStruct.references.add(theStruct); structDesc = aStruct; } @@ -104,14 +104,14 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio decl.bitWidth, decl.enumValues, structDesc); - if (theStruct.m_fieldsByName.put(decl.name, fieldDesc) != null) { + if (theStruct.fieldsByName.put(decl.name, fieldDesc) != null) { throw new BadSchemaException(decl.name, "duplicate field name"); } - theStruct.m_fields.add(fieldDesc); + theStruct.fields.add(fieldDesc); } - theStruct.m_valid = isValid; + theStruct.valid = isValid; Stack stack = new Stack<>(); if (isValid) { // we have all the info needed, so calculate field offset & shift diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldDescriptor.java b/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldDescriptor.java index d624b7d4b77..f1b0fe57c1d 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldDescriptor.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/StructFieldDescriptor.java @@ -36,8 +36,8 @@ private static long toBitMask(int size, int bitWidth) { StructDescriptor structDesc) { m_parent = parent; m_name = name; - m_size = size; - m_arraySize = arraySize; + this.size = size; + this.m_arraySize = arraySize; m_enum = enumValues; m_struct = structDesc; m_bitMask = toBitMask(size, bitWidth); @@ -96,7 +96,7 @@ public boolean isUint() { * @return number of bytes */ public int getSize() { - return m_size; + return size; } /** @@ -105,7 +105,7 @@ public int getSize() { * @return number of bytes from the start of the struct */ public int getOffset() { - return m_offset; + return offset; } /** @@ -114,7 +114,7 @@ public int getOffset() { * @return number of bits */ public int getBitWidth() { - return m_bitWidth == 0 ? m_size * 8 : m_bitWidth; + return m_bitWidth == 0 ? size * 8 : m_bitWidth; } /** @@ -133,7 +133,7 @@ public long getBitMask() { * @return number of bits */ public int getBitShift() { - return m_bitShift; + return bitShift; } /** @@ -224,18 +224,18 @@ public long getIntMax() { * @return true if bitfield */ public boolean isBitField() { - return (m_bitShift != 0 || m_bitWidth != (m_size * 8)) && m_struct == null; + return (bitShift != 0 || m_bitWidth != (size * 8)) && m_struct == null; } private final StructDescriptor m_parent; private final String m_name; - int m_size; - int m_offset; - final int m_arraySize; // 1 for non-arrays + int size; + int offset; + private final int m_arraySize; // 1 for non-arrays private final Map m_enum; private final StructDescriptor m_struct; // null for non-structs private final long m_bitMask; private final StructFieldType m_type; private final int m_bitWidth; - int m_bitShift; + int bitShift; } diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/parser/Lexer.java b/wpiutil/src/main/java/org/wpilib/util/struct/parser/Lexer.java index a1757de6df3..11b8ba37985 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/parser/Lexer.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/parser/Lexer.java @@ -25,7 +25,7 @@ public TokenKind scan() { do { get(); } while (m_current == ' ' || m_current == '\t' || m_current == '\n' || m_current == '\r'); - m_tokenStart = m_pos - 1; + m_tokenStart = pos - 1; return switch (m_current) { case '[' -> TokenKind.LEFT_BRACKET; @@ -56,7 +56,7 @@ public String getTokenText() { if (m_tokenStart >= m_in.length()) { return ""; } - return m_in.substring(m_tokenStart, m_pos); + return m_in.substring(m_tokenStart, pos); } /** @@ -85,19 +85,19 @@ private TokenKind scanIdentifier() { } private void get() { - if (m_pos < m_in.length()) { - m_current = m_in.charAt(m_pos); + if (pos < m_in.length()) { + m_current = m_in.charAt(pos); } else { m_current = '\0'; } - ++m_pos; + ++pos; } private void unget() { - if (m_pos > 0) { - m_pos--; - if (m_pos < m_in.length()) { - m_current = m_in.charAt(m_pos); + if (pos > 0) { + pos--; + if (pos < m_in.length()) { + m_current = m_in.charAt(pos); } else { m_current = '\0'; } @@ -106,8 +106,8 @@ private void unget() { } } - final String m_in; - char m_current; - int m_tokenStart; - int m_pos; + private final String m_in; + private char m_current; + private int m_tokenStart; + int pos; } diff --git a/wpiutil/src/main/java/org/wpilib/util/struct/parser/Parser.java b/wpiutil/src/main/java/org/wpilib/util/struct/parser/Parser.java index 807806b996b..62cc68144d8 100644 --- a/wpiutil/src/main/java/org/wpilib/util/struct/parser/Parser.java +++ b/wpiutil/src/main/java/org/wpilib/util/struct/parser/Parser.java @@ -78,7 +78,7 @@ private ParsedDeclaration parseDeclaration() throws ParseException { decl.arraySize = value; } else { throw new ParseException( - m_lexer.m_pos, "array size '" + valueStr + "' is not a positive integer"); + m_lexer.pos, "array size '" + valueStr + "' is not a positive integer"); } getNextToken(); expect(TokenKind.RIGHT_BRACKET); @@ -97,7 +97,7 @@ private ParsedDeclaration parseDeclaration() throws ParseException { decl.bitWidth = value; } else { throw new ParseException( - m_lexer.m_pos, "bitfield width '" + valueStr + "' is not a positive integer"); + m_lexer.pos, "bitfield width '" + valueStr + "' is not a positive integer"); } getNextToken(); } @@ -127,7 +127,7 @@ private Map parseEnum() throws ParseException { try { value = Long.parseLong(valueStr); } catch (NumberFormatException e) { - throw new ParseException(m_lexer.m_pos, "could not parse enum value '" + valueStr + "'"); + throw new ParseException(m_lexer.pos, "could not parse enum value '" + valueStr + "'"); } map.put(name, value); getNextToken(); @@ -148,10 +148,10 @@ private TokenKind getNextToken() { private void expect(TokenKind kind) throws ParseException { if (m_token != kind) { throw new ParseException( - m_lexer.m_pos, "expected " + kind + ", got '" + m_lexer.getTokenText() + "'"); + m_lexer.pos, "expected " + kind + ", got '" + m_lexer.getTokenText() + "'"); } } - final Lexer m_lexer; - TokenKind m_token; + private final Lexer m_lexer; + private TokenKind m_token; } diff --git a/wpiutil/src/test/java/org/wpilib/util/ConstructorMatchTest.java b/wpiutil/src/test/java/org/wpilib/util/ConstructorMatchTest.java index 389f7951589..b9c3aeaa620 100644 --- a/wpiutil/src/test/java/org/wpilib/util/ConstructorMatchTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/ConstructorMatchTest.java @@ -11,7 +11,11 @@ import java.util.Optional; import org.junit.jupiter.api.Test; -@SuppressWarnings({"PMD.TestClassWithoutTestCases", "RedundantModifier"}) +@SuppressWarnings({ + "PMD.TestClassWithoutTestCases", + "RedundantModifier", + "PMD.PublicMemberInNonPublicType" +}) class ConstructorMatchTest { public static class TestClass { public TestClass() {} diff --git a/wpiutil/src/test/java/org/wpilib/util/cleanup/CleanupPoolTest.java b/wpiutil/src/test/java/org/wpilib/util/cleanup/CleanupPoolTest.java index 688fe803fe3..960f8cb52d4 100644 --- a/wpiutil/src/test/java/org/wpilib/util/cleanup/CleanupPoolTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/cleanup/CleanupPoolTest.java @@ -14,11 +14,11 @@ class CleanupPoolTest { static class AutoCloseableObject implements AutoCloseable { - public boolean m_closed; + boolean closed; @Override public void close() { - m_closed = true; + closed = true; } } @@ -36,7 +36,7 @@ public void close() { } static class FailingAutoCloseableObject implements AutoCloseable { - public static final String message = "This is an expected failure"; + static final String message = "This is an expected failure"; @Override public void close() { @@ -58,7 +58,7 @@ void cleanupStackWorks() { } for (AutoCloseableObject autoCloseableObject : objects) { - assertTrue(autoCloseableObject.m_closed); + assertTrue(autoCloseableObject.closed); } } @@ -82,7 +82,7 @@ void cleanupStackWithExceptionNotInCloseWorks() { } for (AutoCloseableObject autoCloseableObject : objects) { - assertTrue(autoCloseableObject.m_closed); + assertTrue(autoCloseableObject.closed); } } @@ -101,7 +101,7 @@ void cleanupStackWithExceptionInCloseWorks() { } for (AutoCloseableObject autoCloseableObject : objects) { - assertTrue(autoCloseableObject.m_closed); + assertTrue(autoCloseableObject.closed); } } @@ -123,9 +123,9 @@ void cleanupStackRemovalWorks() { int idx = 0; for (AutoCloseableObject autoCloseableObject : objects) { if (idx == 0) { - assertFalse(autoCloseableObject.m_closed); + assertFalse(autoCloseableObject.closed); } else { - assertTrue(autoCloseableObject.m_closed); + assertTrue(autoCloseableObject.closed); } idx++; } diff --git a/wpiutil/src/test/java/org/wpilib/util/cleanup/ReflectionCleanupTest.java b/wpiutil/src/test/java/org/wpilib/util/cleanup/ReflectionCleanupTest.java index 786e8e5c9c6..0faace0e3f4 100644 --- a/wpiutil/src/test/java/org/wpilib/util/cleanup/ReflectionCleanupTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/cleanup/ReflectionCleanupTest.java @@ -11,20 +11,20 @@ class ReflectionCleanupTest { static class CleanupClass implements AutoCloseable { - public boolean m_closed; + boolean closed; @Override public void close() { - m_closed = true; + closed = true; } } @SuppressWarnings("PMD.TestClassWithoutTestCases") static class CleanupTest implements ReflectionCleanup { - public CleanupClass m_class1 = new CleanupClass(); - public CleanupClass m_class2 = new CleanupClass(); - public Object m_nonCleanupObject = new Object(); - public Object m_nullCleanupObject; + CleanupClass class1 = new CleanupClass(); + CleanupClass class2 = new CleanupClass(); + Object nonCleanupObject = new Object(); + Object nullCleanupObject; @Override public void close() { @@ -33,8 +33,8 @@ public void close() { } static class CleanupTest2 extends CleanupTest { - @SkipCleanup public CleanupClass m_class3 = new CleanupClass(); - public CleanupClass m_class4 = new CleanupClass(); + @SkipCleanup CleanupClass class3 = new CleanupClass(); + CleanupClass class4 = new CleanupClass(); @Override public void close() { @@ -46,17 +46,17 @@ public void close() { void cleanupClosesAllFields() { CleanupTest test = new CleanupTest(); test.close(); - assertTrue(test.m_class1.m_closed); - assertTrue(test.m_class2.m_closed); + assertTrue(test.class1.closed); + assertTrue(test.class2.closed); } @Test void cleanupOnlyClosesExplicitClassAndSkipWorks() { CleanupTest2 test = new CleanupTest2(); test.close(); - assertFalse(test.m_class1.m_closed); - assertFalse(test.m_class2.m_closed); - assertFalse(test.m_class3.m_closed); - assertTrue(test.m_class4.m_closed); + assertFalse(test.class1.closed); + assertFalse(test.class2.closed); + assertFalse(test.class3.closed); + assertTrue(test.class4.closed); } } diff --git a/wpiutil/src/test/java/org/wpilib/util/struct/DynamicStructTest.java b/wpiutil/src/test/java/org/wpilib/util/struct/DynamicStructTest.java index b0c2fdb0197..b46cc308beb 100644 --- a/wpiutil/src/test/java/org/wpilib/util/struct/DynamicStructTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/struct/DynamicStructTest.java @@ -20,11 +20,10 @@ @SuppressWarnings("AvoidEscapedUnicodeCharacters") class DynamicStructTest { - @SuppressWarnings("MemberName") - private StructDescriptorDatabase db; + StructDescriptorDatabase db; @BeforeEach - public void init() { + void init() { db = new StructDescriptorDatabase(); } diff --git a/wpiutil/src/test/java/org/wpilib/util/struct/StructGeneratorTest.java b/wpiutil/src/test/java/org/wpilib/util/struct/StructGeneratorTest.java index 86f2324d2ea..12698736803 100644 --- a/wpiutil/src/test/java/org/wpilib/util/struct/StructGeneratorTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/struct/StructGeneratorTest.java @@ -15,11 +15,11 @@ class StructGeneratorTest { public record CustomRecord(int int32, boolean bool, double float64, char character, short int16) implements StructSerializable { - public static CustomRecord create() { + static CustomRecord create() { return new CustomRecord(42, true, Math.PI, 'a', (short) 16); } - public static final Struct struct = genRecord(CustomRecord.class); + static final Struct struct = genRecord(CustomRecord.class); @Override public final boolean equals(Object arg) { @@ -42,37 +42,37 @@ public final int hashCode() { } } - public enum CustomEnum implements StructSerializable { + enum CustomEnum implements StructSerializable { A(8), B(16), C(32), D(64); - public final int value; + final int value; CustomEnum(int value) { this.value = value; } - public static final Struct struct = genEnum(CustomEnum.class); + static final Struct struct = genEnum(CustomEnum.class); } - public enum AnimalEnum implements StructSerializable { + enum AnimalEnum implements StructSerializable { Dog, Cat; - public static final Struct struct = genEnum(AnimalEnum.class); + static final Struct struct = genEnum(AnimalEnum.class); } public record HigherOrderRecord( CustomRecord procRecord, CustomEnum procEnum, AnimalEnum animal, long i64, byte uint8) implements StructSerializable { - public static HigherOrderRecord create() { + static HigherOrderRecord create() { return new HigherOrderRecord( CustomRecord.create(), CustomEnum.A, AnimalEnum.Dog, 1234567890123456789L, (byte) 100); } - public static final Struct struct = genRecord(HigherOrderRecord.class); + static final Struct struct = genRecord(HigherOrderRecord.class); @Override public final boolean equals(Object arg) { From 557de6ca96b921cc9867c82d7288f4e73e01577b Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 20 Mar 2026 21:52:21 -0400 Subject: [PATCH 4/4] Remove m_ from all examples --- .../DifferentialDrivePoseEstimator/robot.py | 2 +- .../SwerveDrivePoseEstimator/swervemodule.py | 16 +-- shared/java/javastyle.gradle | 2 +- styleguide/pmd-ruleset.xml | 2 +- .../examples/ArcadeDriveGamepad/cpp/Robot.cpp | 22 +-- .../cpp/examples/ArmSimulation/cpp/Robot.cpp | 12 +- .../ArmSimulation/cpp/subsystems/Arm.cpp | 38 +++--- .../examples/ArmSimulation/include/Robot.hpp | 4 +- .../ArmSimulation/include/subsystems/Arm.hpp | 30 ++-- .../DifferentialDriveBot/cpp/Drivetrain.cpp | 24 ++-- .../DifferentialDriveBot/cpp/Robot.cpp | 19 ++- .../include/Drivetrain.hpp | 48 +++---- .../cpp/Drivetrain.cpp | 86 ++++++------ .../cpp/Robot.cpp | 23 ++-- .../include/Drivetrain.hpp | 65 +++++---- .../DriveDistanceOffboard/cpp/Robot.cpp | 12 +- .../cpp/RobotContainer.cpp | 22 +-- .../cpp/subsystems/DriveSubsystem.cpp | 94 ++++++------- .../include/ExampleSmartMotorController.hpp | 6 +- .../DriveDistanceOffboard/include/Robot.hpp | 4 +- .../include/RobotContainer.hpp | 13 +- .../include/subsystems/DriveSubsystem.hpp | 23 ++-- .../examples/DutyCycleEncoder/cpp/Robot.cpp | 10 +- .../ElevatorExponentialProfile/cpp/Robot.cpp | 34 ++--- .../cpp/Robot.cpp | 14 +- .../cpp/subsystems/Elevator.cpp | 32 ++--- .../include/Robot.hpp | 4 +- .../include/subsystems/Elevator.hpp | 54 ++++---- .../ElevatorProfiledPID/cpp/Robot.cpp | 31 ++--- .../examples/ElevatorSimulation/cpp/Robot.cpp | 12 +- .../cpp/subsystems/Elevator.cpp | 28 ++-- .../ElevatorSimulation/include/Robot.hpp | 4 +- .../include/subsystems/Elevator.hpp | 49 ++++--- .../ElevatorTrapezoidProfile/cpp/Robot.cpp | 30 ++-- .../main/cpp/examples/Encoder/cpp/Robot.cpp | 12 +- .../cpp/examples/GettingStarted/cpp/Robot.cpp | 35 +++-- .../src/main/cpp/examples/Gyro/cpp/Robot.cpp | 24 ++-- .../examples/HatchbotInlined/cpp/Robot.cpp | 12 +- .../HatchbotInlined/cpp/RobotContainer.cpp | 30 ++-- .../cpp/subsystems/DriveSubsystem.cpp | 43 +++--- .../cpp/subsystems/HatchSubsystem.cpp | 10 +- .../HatchbotInlined/include/Robot.hpp | 4 +- .../include/RobotContainer.hpp | 13 +- .../include/subsystems/DriveSubsystem.hpp | 18 +-- .../include/subsystems/HatchSubsystem.hpp | 2 +- .../HatchbotTraditional/cpp/Robot.cpp | 12 +- .../cpp/RobotContainer.cpp | 31 ++--- .../cpp/commands/DefaultDrive.cpp | 8 +- .../cpp/commands/DriveDistance.cpp | 12 +- .../cpp/commands/GrabHatch.cpp | 4 +- .../cpp/commands/HalveDriveVelocity.cpp | 6 +- .../cpp/commands/ReleaseHatch.cpp | 4 +- .../cpp/subsystems/DriveSubsystem.cpp | 43 +++--- .../cpp/subsystems/HatchSubsystem.cpp | 10 +- .../HatchbotTraditional/include/Robot.hpp | 4 +- .../include/RobotContainer.hpp | 14 +- .../include/commands/DefaultDrive.hpp | 6 +- .../include/commands/DriveDistance.hpp | 6 +- .../include/commands/GrabHatch.hpp | 2 +- .../include/commands/HalveDriveVelocity.hpp | 2 +- .../include/commands/ReleaseHatch.hpp | 2 +- .../include/subsystems/DriveSubsystem.hpp | 18 +-- .../include/subsystems/HatchSubsystem.hpp | 2 +- .../examples/MecanumBot/cpp/Drivetrain.cpp | 63 +++++---- .../cpp/examples/MecanumBot/cpp/Robot.cpp | 26 ++-- .../MecanumBot/include/Drivetrain.hpp | 52 +++---- .../cpp/examples/MecanumDrive/cpp/Robot.cpp | 38 +++--- .../cpp/Drivetrain.cpp | 62 ++++----- .../MecanumDrivePoseEstimator/cpp/Robot.cpp | 26 ++-- .../include/Drivetrain.hpp | 54 ++++---- .../cpp/examples/Mechanism2d/cpp/Robot.cpp | 37 +++-- .../cpp/RapidReactCommandBot.cpp | 26 ++-- .../RapidReactCommandBot/cpp/Robot.cpp | 12 +- .../cpp/subsystems/Drive.cpp | 62 ++++----- .../cpp/subsystems/Intake.cpp | 8 +- .../cpp/subsystems/Pneumatics.cpp | 6 +- .../cpp/subsystems/Shooter.cpp | 20 +-- .../cpp/subsystems/Storage.cpp | 4 +- .../include/RapidReactCommandBot.hpp | 13 +- .../RapidReactCommandBot/include/Robot.hpp | 4 +- .../include/subsystems/Drive.hpp | 32 ++--- .../include/subsystems/Intake.hpp | 8 +- .../include/subsystems/Pneumatics.hpp | 6 +- .../include/subsystems/Shooter.hpp | 14 +- .../include/subsystems/Storage.hpp | 6 +- .../cpp/examples/RomiReference/cpp/Robot.cpp | 12 +- .../RomiReference/cpp/RobotContainer.cpp | 16 +-- .../cpp/commands/DriveDistance.cpp | 10 +- .../RomiReference/cpp/commands/DriveTime.cpp | 14 +- .../cpp/commands/TeleopArcadeDrive.cpp | 8 +- .../cpp/commands/TurnDegrees.cpp | 14 +- .../RomiReference/cpp/commands/TurnTime.cpp | 14 +- .../cpp/subsystems/Drivetrain.cpp | 36 ++--- .../examples/RomiReference/include/Robot.hpp | 4 +- .../RomiReference/include/RobotContainer.hpp | 18 +-- .../include/commands/DriveDistance.hpp | 10 +- .../include/commands/DriveTime.hpp | 12 +- .../include/commands/TeleopArcadeDrive.hpp | 6 +- .../include/commands/TurnDegrees.hpp | 10 +- .../include/commands/TurnTime.hpp | 12 +- .../include/subsystems/Drivetrain.hpp | 16 +-- .../cpp/Drivetrain.cpp | 60 ++++---- .../cpp/Robot.cpp | 41 +++--- .../include/Drivetrain.hpp | 66 ++++----- .../cpp/examples/StateSpaceArm/cpp/Robot.cpp | 54 ++++---- .../examples/StateSpaceElevator/cpp/Robot.cpp | 56 ++++---- .../examples/StateSpaceFlywheel/cpp/Robot.cpp | 36 ++--- .../StateSpaceFlywheelSysId/cpp/Robot.cpp | 36 ++--- .../cpp/examples/SwerveBot/cpp/Drivetrain.cpp | 21 ++- .../main/cpp/examples/SwerveBot/cpp/Robot.cpp | 32 ++--- .../examples/SwerveBot/cpp/SwerveModule.cpp | 55 ++++---- .../examples/SwerveBot/include/Drivetrain.hpp | 44 +++--- .../SwerveBot/include/SwerveModule.hpp | 16 +-- .../cpp/Drivetrain.cpp | 24 ++-- .../SwerveDrivePoseEstimator/cpp/Robot.cpp | 26 ++-- .../cpp/SwerveModule.cpp | 55 ++++---- .../include/Drivetrain.hpp | 34 ++--- .../include/SwerveModule.hpp | 16 +-- .../cpp/examples/SysIdRoutine/cpp/Robot.cpp | 10 +- .../SysIdRoutine/cpp/SysIdRoutineBot.cpp | 50 ++++--- .../SysIdRoutine/cpp/subsystems/Drive.cpp | 19 ++- .../SysIdRoutine/cpp/subsystems/Shooter.cpp | 16 +-- .../examples/SysIdRoutine/include/Robot.hpp | 4 +- .../SysIdRoutine/include/SysIdRoutineBot.hpp | 6 +- .../SysIdRoutine/include/subsystems/Drive.hpp | 40 +++--- .../include/subsystems/Shooter.hpp | 24 ++-- .../examples/TankDriveGamepad/cpp/Robot.cpp | 22 +-- .../main/cpp/examples/UnitTest/cpp/Robot.cpp | 14 +- .../UnitTest/cpp/subsystems/Intake.cpp | 12 +- .../cpp/examples/UnitTest/include/Robot.hpp | 4 +- .../UnitTest/include/subsystems/Intake.hpp | 8 +- .../cpp/examples/XRPReference/cpp/Robot.cpp | 12 +- .../XRPReference/cpp/RobotContainer.cpp | 28 ++-- .../cpp/commands/DriveDistance.cpp | 10 +- .../XRPReference/cpp/commands/DriveTime.cpp | 14 +- .../cpp/commands/TeleopArcadeDrive.cpp | 8 +- .../XRPReference/cpp/commands/TurnDegrees.cpp | 14 +- .../XRPReference/cpp/commands/TurnTime.cpp | 14 +- .../XRPReference/cpp/subsystems/Arm.cpp | 2 +- .../cpp/subsystems/Drivetrain.cpp | 36 ++--- .../examples/XRPReference/include/Robot.hpp | 4 +- .../XRPReference/include/RobotContainer.hpp | 18 +-- .../include/commands/DriveDistance.hpp | 10 +- .../include/commands/DriveTime.hpp | 12 +- .../include/commands/TeleopArcadeDrive.hpp | 6 +- .../include/commands/TurnDegrees.hpp | 10 +- .../include/commands/TurnTime.hpp | 12 +- .../XRPReference/include/subsystems/Arm.hpp | 2 +- .../include/subsystems/Drivetrain.hpp | 16 +-- .../main/cpp/examples/Xrptimed/cpp/Robot.cpp | 16 +-- .../cpp/examples/Xrptimed/include/Robot.hpp | 14 +- .../snippets/ADXLAccelerometers/cpp/Robot.cpp | 8 +- .../AccelerometerCollision/cpp/Robot.cpp | 18 +-- .../AccelerometerFilter/cpp/Robot.cpp | 9 +- .../cpp/snippets/AddressableLED/cpp/Robot.cpp | 8 +- .../snippets/AddressableLED/include/Robot.hpp | 10 +- .../AnalogAccelerometer/cpp/Robot.cpp | 8 +- .../cpp/snippets/AnalogEncoder/cpp/Robot.cpp | 6 +- .../cpp/snippets/AnalogInput/cpp/Robot.cpp | 6 +- .../AnalogPotentiometer/cpp/Robot.cpp | 8 +- .../main/cpp/snippets/CANPDP/cpp/Robot.cpp | 16 +-- .../DigitalCommunication/cpp/Robot.cpp | 8 +- .../DigitalCommunication/include/Robot.hpp | 8 +- .../cpp/snippets/DigitalInput/cpp/Robot.cpp | 4 +- .../snippets/DutyCycleEncoder/cpp/Robot.cpp | 8 +- .../cpp/snippets/DutyCycleInput/cpp/Robot.cpp | 6 +- .../main/cpp/snippets/Encoder/cpp/Robot.cpp | 26 ++-- .../cpp/snippets/EncoderDrive/cpp/Robot.cpp | 6 +- .../cpp/snippets/EncoderHoming/cpp/Robot.cpp | 14 +- .../main/cpp/snippets/EventLoop/cpp/Robot.cpp | 48 ++++--- .../FlywheelBangBangController/cpp/Robot.cpp | 38 +++--- .../cpp/snippets/LimitSwitch/cpp/Robot.cpp | 22 +-- .../cpp/snippets/MotorControl/cpp/Robot.cpp | 12 +- .../cpp/snippets/OnboardIMU/cpp/Robot.cpp | 16 +-- .../ProfiledPIDFeedforward/cpp/Robot.cpp | 23 ++-- .../cpp/snippets/SelectCommand/cpp/Robot.cpp | 12 +- .../SelectCommand/cpp/RobotContainer.cpp | 10 +- .../snippets/SelectCommand/include/Robot.hpp | 4 +- .../SelectCommand/include/RobotContainer.hpp | 15 +- .../main/cpp/snippets/Solenoid/cpp/Robot.cpp | 37 +++-- .../cpp/snippets/Solenoid/include/Robot.hpp | 10 +- .../cpp/templates/commandv2/cpp/Robot.cpp | 10 +- .../commandv2/cpp/RobotContainer.cpp | 8 +- .../commandv2/cpp/commands/ExampleCommand.cpp | 4 +- .../cpp/templates/commandv2/include/Robot.hpp | 4 +- .../commandv2/include/RobotContainer.hpp | 4 +- .../include/commands/ExampleCommand.hpp | 2 +- .../templates/commandv2skeleton/cpp/Robot.cpp | 10 +- .../commandv2skeleton/include/Robot.hpp | 4 +- .../templates/opmode/cpp/opmode/MyAuto.cpp | 2 +- .../templates/opmode/cpp/opmode/MyTeleop.cpp | 2 +- .../opmode/include/opmode/MyAuto.hpp | 2 +- .../opmode/include/opmode/MyTeleop.hpp | 2 +- .../templates/robotbaseskeleton/cpp/Robot.cpp | 4 +- .../robotbaseskeleton/include/Robot.hpp | 2 +- .../main/cpp/templates/timed/cpp/Robot.cpp | 16 +-- .../cpp/templates/timed/include/Robot.hpp | 4 +- .../cpp/templates/timeslice/cpp/Robot.cpp | 16 +-- .../cpp/templates/timeslice/include/Robot.hpp | 4 +- .../ArmSimulation/cpp/ArmSimulationTest.cpp | 48 +++---- .../cpp/ElevatorSimulationTest.cpp | 48 +++---- .../cpp/DigitalCommunicationTest.cpp | 50 +++---- .../cpp/I2CCommunicationTest.cpp | 30 ++-- .../examples/arcadedrivegamepad/Robot.java | 18 +-- .../wpilib/examples/armsimulation/Robot.java | 18 +-- .../armsimulation/subsystems/Arm.java | 79 ++++++----- .../differentialdrivebot/Drivetrain.java | 63 ++++----- .../examples/differentialdrivebot/Robot.java | 17 ++- .../Drivetrain.java | 129 +++++++++--------- .../differentialdriveposeestimator/Robot.java | 26 ++-- .../ExampleSmartMotorController.java | 6 +- .../examples/drivedistanceoffboard/Robot.java | 16 +-- .../drivedistanceoffboard/RobotContainer.java | 24 ++-- .../subsystems/DriveSubsystem.java | 100 +++++++------- .../examples/dutycycleencoder/Robot.java | 20 +-- .../elevatorexponentialprofile/Robot.java | 32 ++--- .../elevatorexponentialsimulation/Robot.java | 20 +-- .../subsystems/Elevator.java | 66 ++++----- .../examples/elevatorprofiledpid/Robot.java | 30 ++-- .../examples/elevatorsimulation/Robot.java | 18 +-- .../subsystems/Elevator.java | 58 ++++---- .../elevatortrapezoidprofile/Robot.java | 30 ++-- .../org/wpilib/examples/encoder/Robot.java | 12 +- .../wpilib/examples/gettingstarted/Robot.java | 28 ++-- .../java/org/wpilib/examples/gyro/Robot.java | 22 +-- .../examples/hatchbotinlined/Robot.java | 16 +-- .../hatchbotinlined/RobotContainer.java | 41 +++--- .../subsystems/DriveSubsystem.java | 44 +++--- .../subsystems/HatchSubsystem.java | 8 +- .../examples/hatchbottraditional/Robot.java | 16 +-- .../hatchbottraditional/RobotContainer.java | 42 +++--- .../commands/DefaultDrive.java | 16 +-- .../commands/DriveDistance.java | 24 ++-- .../commands/GrabHatch.java | 8 +- .../commands/HalveDriveVelocity.java | 8 +- .../subsystems/DriveSubsystem.java | 44 +++--- .../subsystems/HatchSubsystem.java | 8 +- .../examples/mecanumbot/Drivetrain.java | 96 ++++++------- .../org/wpilib/examples/mecanumbot/Robot.java | 21 ++- .../wpilib/examples/mecanumdrive/Robot.java | 20 +-- .../mecanumdriveposeestimator/Drivetrain.java | 103 +++++++------- .../mecanumdriveposeestimator/Robot.java | 21 ++- .../wpilib/examples/mechanism2d/Robot.java | 31 ++--- .../RapidReactCommandBot.java | 36 +++-- .../examples/rapidreactcommandbot/Robot.java | 16 +-- .../subsystems/Drive.java | 65 +++++---- .../subsystems/Intake.java | 12 +- .../subsystems/Pneumatics.java | 10 +- .../subsystems/Shooter.java | 28 ++-- .../subsystems/Storage.java | 10 +- .../wpilib/examples/romireference/Robot.java | 16 +-- .../romireference/RobotContainer.java | 22 +-- .../romireference/commands/ArcadeDrive.java | 14 +- .../romireference/commands/DriveDistance.java | 22 +-- .../romireference/commands/DriveTime.java | 24 ++-- .../romireference/commands/TurnDegrees.java | 26 ++-- .../romireference/commands/TurnTime.java | 24 ++-- .../romireference/subsystems/Drivetrain.java | 46 +++---- .../Drivetrain.java | 103 +++++++------- .../Robot.java | 39 +++--- .../wpilib/examples/statespacearm/Robot.java | 45 +++--- .../examples/statespaceelevator/Robot.java | 49 +++---- .../examples/statespaceflywheel/Robot.java | 40 +++--- .../statespaceflywheelsysid/Robot.java | 40 +++--- .../wpilib/examples/swervebot/Drivetrain.java | 62 ++++----- .../org/wpilib/examples/swervebot/Robot.java | 20 +-- .../examples/swervebot/SwerveModule.java | 56 ++++---- .../swervedriveposeestimator/Drivetrain.java | 67 +++++---- .../swervedriveposeestimator/Robot.java | 21 ++- .../SwerveModule.java | 56 ++++---- .../wpilib/examples/sysidroutine/Robot.java | 16 +-- .../sysidroutine/SysIdRoutineBot.java | 64 ++++----- .../sysidroutine/subsystems/Drive.java | 46 +++---- .../sysidroutine/subsystems/Shooter.java | 39 +++--- .../examples/tankdrivegamepad/Robot.java | 18 +-- .../org/wpilib/examples/unittest/Robot.java | 18 +-- .../examples/unittest/subsystems/Intake.java | 24 ++-- .../wpilib/examples/xrpreference/Robot.java | 16 +-- .../examples/xrpreference/RobotContainer.java | 36 ++--- .../xrpreference/commands/ArcadeDrive.java | 14 +- .../xrpreference/commands/DriveDistance.java | 22 +-- .../xrpreference/commands/DriveTime.java | 24 ++-- .../xrpreference/commands/TurnDegrees.java | 26 ++-- .../xrpreference/commands/TurnTime.java | 24 ++-- .../examples/xrpreference/subsystems/Arm.java | 6 +- .../xrpreference/subsystems/Drivetrain.java | 46 +++---- .../org/wpilib/examples/xrptimed/Robot.java | 28 ++-- .../accelerometercollision/Robot.java | 18 +-- .../snippets/accelerometerfilter/Robot.java | 8 +- .../wpilib/snippets/addressableled/Robot.java | 22 +-- .../snippets/adxlaccelerometers/Robot.java | 8 +- .../snippets/analogaccelerometer/Robot.java | 8 +- .../wpilib/snippets/analogencoder/Robot.java | 8 +- .../wpilib/snippets/analoginput/Robot.java | 6 +- .../snippets/analogpotentiometer/Robot.java | 10 +- .../org/wpilib/snippets/canpdp/Robot.java | 16 +-- .../snippets/digitalcommunication/Robot.java | 24 ++-- .../wpilib/snippets/digitalinput/Robot.java | 4 +- .../snippets/dutycycleencoder/Robot.java | 10 +- .../wpilib/snippets/dutycycleinput/Robot.java | 8 +- .../org/wpilib/snippets/encoder/Robot.java | 28 ++-- .../wpilib/snippets/encoderdrive/Robot.java | 28 ++-- .../wpilib/snippets/encoderhoming/Robot.java | 14 +- .../org/wpilib/snippets/eventloop/Robot.java | 44 +++--- .../flywheelbangbangcontroller/Robot.java | 36 +++-- .../org/wpilib/snippets/httpcamera/Robot.java | 8 +- .../snippets/i2ccommunication/Robot.java | 6 +- .../snippets/intermediatevision/Robot.java | 8 +- .../wpilib/snippets/limitswitch/Robot.java | 22 +-- .../wpilib/snippets/motorcontrol/Robot.java | 18 +-- .../org/wpilib/snippets/onboardimu/Robot.java | 16 +-- .../profiledpidfeedforward/Robot.java | 20 +-- .../wpilib/snippets/selectcommand/Robot.java | 16 +-- .../selectcommand/RobotContainer.java | 4 +- .../org/wpilib/snippets/solenoid/Robot.java | 44 +++--- .../org/wpilib/templates/commandv2/Robot.java | 16 +-- .../templates/commandv2/RobotContainer.java | 11 +- .../commandv2/commands/ExampleCommand.java | 4 +- .../templates/commandv2skeleton/Robot.java | 16 +-- .../educational/EducationalRobot.java | 6 +- .../templates/opmode/opmode/MyAuto.java | 4 +- .../templates/opmode/opmode/MyTeleop.java | 4 +- .../templates/robotbaseskeleton/Robot.java | 6 +- .../wpilib/templates/romicommandv2/Robot.java | 16 +-- .../romicommandv2/RobotContainer.java | 6 +- .../commands/ExampleCommand.java | 4 +- .../subsystems/RomiDrivetrain.java | 28 ++-- .../romieducational/EducationalRobot.java | 6 +- .../romieducational/RomiDrivetrain.java | 30 ++-- .../org/wpilib/templates/romitimed/Robot.java | 22 +-- .../templates/romitimed/RomiDrivetrain.java | 28 ++-- .../org/wpilib/templates/timed/Robot.java | 18 +-- .../org/wpilib/templates/timeslice/Robot.java | 18 +-- .../wpilib/templates/xrpcommandv2/Robot.java | 16 +-- .../xrpcommandv2/RobotContainer.java | 6 +- .../xrpcommandv2/commands/ExampleCommand.java | 4 +- .../subsystems/XRPDrivetrain.java | 28 ++-- .../xrpeducational/EducationalRobot.java | 6 +- .../xrpeducational/XRPDrivetrain.java | 28 ++-- .../org/wpilib/templates/xrptimed/Robot.java | 22 +-- .../templates/xrptimed/XRPDrivetrain.java | 28 ++-- .../armsimulation/ArmSimulationTest.java | 62 ++++----- .../ElevatorSimulationTest.java | 62 ++++----- .../unittest/subsystems/IntakeTest.java | 34 ++--- .../DigitalCommunicationTest.java | 58 ++++---- .../I2CCommunicationTest.java | 52 +++---- 346 files changed, 3876 insertions(+), 3978 deletions(-) diff --git a/robotpyExamples/DifferentialDrivePoseEstimator/robot.py b/robotpyExamples/DifferentialDrivePoseEstimator/robot.py index 5cde89e2b18..301aef0a803 100644 --- a/robotpyExamples/DifferentialDrivePoseEstimator/robot.py +++ b/robotpyExamples/DifferentialDrivePoseEstimator/robot.py @@ -17,7 +17,7 @@ def __init__(self) -> None: super().__init__() self.inst = ntcore.NetworkTableInstance.getDefault() - self.doubleArrayTopic = self.inst.getDoubleArrayTopic("m_doubleArrayTopic") + self.doubleArrayTopic = self.inst.getDoubleArrayTopic("doubleArrayTopic") self.controller = wpilib.NiDsXboxController(0) self.drive = Drivetrain(self.doubleArrayTopic) diff --git a/robotpyExamples/SwerveDrivePoseEstimator/swervemodule.py b/robotpyExamples/SwerveDrivePoseEstimator/swervemodule.py index 5f0aa9e2109..2d74f282bb2 100644 --- a/robotpyExamples/SwerveDrivePoseEstimator/swervemodule.py +++ b/robotpyExamples/SwerveDrivePoseEstimator/swervemodule.py @@ -112,21 +112,17 @@ def setDesiredVelocity(self, desiredVelocity: wpimath.SwerveModuleVelocity) -> N encoderRotation ) - # Calculate the drive output from the drive PID controller. + # Calculate the drive output from the drive PID controller and feedforward. driveOutput = self.drivePIDController.calculate( self.driveEncoder.getRate(), velocity.velocity - ) - - driveFeedforward = self.driveFeedforward.calculate(velocity.velocity) + ) + self.driveFeedforward.calculate(velocity.velocity) - # Calculate the turning motor output from the turning PID controller. + # Calculate the turning motor output from the turning PID controller and feedforward. turnOutput = self.turningPIDController.calculate( self.turningEncoder.getDistance(), velocity.angle.radians() - ) - - turnFeedforward = self.turnFeedforward.calculate( + ) + self.turnFeedforward.calculate( self.turningPIDController.getSetpoint().velocity ) - self.driveMotor.setVoltage(driveOutput + driveFeedforward) - self.turningMotor.setVoltage(turnOutput + turnFeedforward) + self.driveMotor.setVoltage(driveOutput) + self.turningMotor.setVoltage(turnOutput) diff --git a/shared/java/javastyle.gradle b/shared/java/javastyle.gradle index fc4cc47f8c3..cd3d1fc1973 100644 --- a/shared/java/javastyle.gradle +++ b/shared/java/javastyle.gradle @@ -89,4 +89,4 @@ task javaFormat { javaFormat.dependsOn 'spotlessApply' tasks.withType(Checkstyle) { it.mustRunAfter 'spotlessApply' -} \ No newline at end of file +} diff --git a/styleguide/pmd-ruleset.xml b/styleguide/pmd-ruleset.xml index 9ed6eb82ae8..217dd85b400 100644 --- a/styleguide/pmd-ruleset.xml +++ b/styleguide/pmd-ruleset.xml @@ -12,7 +12,7 @@ .*/Timestamped.*\.java .*/units/measure/.*\.java - .*/*IntegrationTests.* + .*/*Examples.* .*/*JNI.* .*/math/proto.* .*/command3/proto.* diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveGamepad/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveGamepad/cpp/Robot.cpp index d0cd3b477e2..2737143403a 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveGamepad/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveGamepad/cpp/Robot.cpp @@ -12,30 +12,30 @@ * Runs the motors with split arcade steering and a Gamepad. */ class Robot : public wpi::TimedRobot { - wpi::PWMSparkMax m_leftMotor{0}; - wpi::PWMSparkMax m_rightMotor{1}; - wpi::DifferentialDrive m_robotDrive{ - [&](double output) { m_leftMotor.SetThrottle(output); }, - [&](double output) { m_rightMotor.SetThrottle(output); }}; - wpi::Gamepad m_driverController{0}; + wpi::PWMSparkMax leftMotor{0}; + wpi::PWMSparkMax rightMotor{1}; + wpi::DifferentialDrive robotDrive{ + [&](double output) { leftMotor.SetThrottle(output); }, + [&](double output) { rightMotor.SetThrottle(output); }}; + wpi::Gamepad driverController{0}; public: Robot() { - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor); - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor); + wpi::util::SendableRegistry::AddChild(&robotDrive, &leftMotor); + wpi::util::SendableRegistry::AddChild(&robotDrive, &rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.SetInverted(true); + rightMotor.SetInverted(true); } void TeleopPeriodic() override { // Drive with split arcade style // That means that the Y axis of the left stick moves forward // and backward, and the X of the right stick turns left and right. - m_robotDrive.ArcadeDrive(-m_driverController.GetLeftY(), - -m_driverController.GetRightX()); + robotDrive.ArcadeDrive(-driverController.GetLeftY(), + -driverController.GetRightX()); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp index ef04ceb39e1..612235f61f0 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/Robot.cpp @@ -5,26 +5,26 @@ #include "Robot.hpp" void Robot::SimulationPeriodic() { - m_arm.SimulationPeriodic(); + arm.SimulationPeriodic(); } void Robot::TeleopInit() { - m_arm.LoadPreferences(); + arm.LoadPreferences(); } void Robot::TeleopPeriodic() { - if (m_joystick.GetTrigger()) { + if (joystick.GetTrigger()) { // Here, we run PID control like normal. - m_arm.ReachSetpoint(); + arm.ReachSetpoint(); } else { // Otherwise, we disable the motor. - m_arm.Stop(); + arm.Stop(); } } void Robot::DisabledInit() { // This just makes sure that our simulation code knows that the motor's off. - m_arm.Stop(); + arm.Stop(); } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp index 0d2e4f98008..73b639b2da0 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/cpp/subsystems/Arm.cpp @@ -9,55 +9,55 @@ #include "wpi/util/Preferences.hpp" Arm::Arm() { - m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse); + encoder.SetDistancePerPulse(kArmEncoderDistPerPulse); // Put Mechanism 2d to SmartDashboard - wpi::SmartDashboard::PutData("Arm Sim", &m_mech2d); + wpi::SmartDashboard::PutData("Arm Sim", &mech2d); // Set the Arm position setpoint and P constant to Preferences if the keys // don't already exist - wpi::Preferences::InitDouble(kArmPositionKey, m_armSetpoint.value()); - wpi::Preferences::InitDouble(kArmPKey, m_armKp); + wpi::Preferences::InitDouble(kArmPositionKey, armSetpoint.value()); + wpi::Preferences::InitDouble(kArmPKey, armKp); } void Arm::SimulationPeriodic() { // In this method, we update our simulation of what our arm is doing // First, we set our "inputs" (voltages) - m_armSim.SetInput(wpi::math::Vectord<1>{ - m_motor.GetThrottle() * wpi::RobotController::GetInputVoltage()}); + armSim.SetInput(wpi::math::Vectord<1>{ + motor.GetThrottle() * wpi::RobotController::GetInputVoltage()}); // Next, we update it. The standard loop time is 20ms. - m_armSim.Update(20_ms); + armSim.Update(20_ms); // Finally, we set our simulated encoder's readings and simulated battery // voltage - m_encoderSim.SetDistance(m_armSim.GetAngle().value()); + encoderSim.SetDistance(armSim.GetAngle().value()); // SimBattery estimates loaded battery voltages wpi::sim::RoboRioSim::SetVInVoltage( - wpi::sim::BatterySim::Calculate({m_armSim.GetCurrentDraw()})); + wpi::sim::BatterySim::Calculate({armSim.GetCurrentDraw()})); // Update the Mechanism Arm angle based on the simulated arm angle - m_arm->SetAngle(m_armSim.GetAngle()); + arm->SetAngle(armSim.GetAngle()); } void Arm::LoadPreferences() { // Read Preferences for Arm setpoint and kP on entering Teleop - m_armSetpoint = wpi::units::degree_t{ - wpi::Preferences::GetDouble(kArmPositionKey, m_armSetpoint.value())}; - if (m_armKp != wpi::Preferences::GetDouble(kArmPKey, m_armKp)) { - m_armKp = wpi::Preferences::GetDouble(kArmPKey, m_armKp); - m_controller.SetP(m_armKp); + armSetpoint = wpi::units::degree_t{ + wpi::Preferences::GetDouble(kArmPositionKey, armSetpoint.value())}; + if (armKp != wpi::Preferences::GetDouble(kArmPKey, armKp)) { + armKp = wpi::Preferences::GetDouble(kArmPKey, armKp); + controller.SetP(armKp); } } void Arm::ReachSetpoint() { // Here, we run PID control like normal, with a setpoint read from // preferences in degrees. - double pidOutput = m_controller.Calculate( - m_encoder.GetDistance(), (wpi::units::radian_t{m_armSetpoint}.value())); - m_motor.SetVoltage(wpi::units::volt_t{pidOutput}); + double pidOutput = controller.Calculate( + encoder.GetDistance(), (wpi::units::radian_t{armSetpoint}.value())); + motor.SetVoltage(wpi::units::volt_t{pidOutput}); } void Arm::Stop() { - m_motor.SetThrottle(0.0); + motor.SetThrottle(0.0); } diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Robot.hpp index 3db15311468..0165bdaa073 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/Robot.hpp @@ -20,6 +20,6 @@ class Robot : public wpi::TimedRobot { void DisabledInit() override; private: - wpi::Joystick m_joystick{kJoystickPort}; - Arm m_arm; + wpi::Joystick joystick{kJoystickPort}; + Arm arm; }; diff --git a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp index 3abba312fc6..49160fac4fe 100644 --- a/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ArmSimulation/include/subsystems/Arm.hpp @@ -29,23 +29,23 @@ class Arm { private: // The P gain for the PID controller that drives this arm. - double m_armKp = kDefaultArmKp; - wpi::units::degree_t m_armSetpoint = kDefaultArmSetpoint; + double armKp = kDefaultArmKp; + wpi::units::degree_t armSetpoint = kDefaultArmSetpoint; // The arm gearbox represents a gearbox containing two Vex 775pro motors. - wpi::math::DCMotor m_armGearbox = wpi::math::DCMotor::Vex775Pro(2); + wpi::math::DCMotor armGearbox = wpi::math::DCMotor::Vex775Pro(2); // Standard classes for controlling our arm - wpi::math::PIDController m_controller{m_armKp, 0, 0}; - wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; - wpi::PWMSparkMax m_motor{kMotorPort}; + wpi::math::PIDController controller{armKp, 0, 0}; + wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel}; + wpi::PWMSparkMax motor{kMotorPort}; // Simulation classes help us simulate what's going on, including gravity. // This sim represents an arm with 2 775s, a 600:1 reduction, a mass of 5kg, // 30in overall arm length, range of motion in [-75, 255] degrees, and noise // with a standard deviation of 1 encoder tick. - wpi::sim::SingleJointedArmSim m_armSim{ - m_armGearbox, + wpi::sim::SingleJointedArmSim armSim{ + armGearbox, kArmReduction, wpi::sim::SingleJointedArmSim::EstimateMOI(kArmLength, kArmMass), kArmLength, @@ -54,16 +54,16 @@ class Arm { true, 0_deg, {kArmEncoderDistPerPulse}}; - wpi::sim::EncoderSim m_encoderSim{m_encoder}; + wpi::sim::EncoderSim encoderSim{encoder}; // Create a Mechanism2d display of an Arm - wpi::Mechanism2d m_mech2d{60, 60}; - wpi::MechanismRoot2d* m_armBase = m_mech2d.GetRoot("ArmBase", 30, 30); - wpi::MechanismLigament2d* m_armTower = - m_armBase->Append( + wpi::Mechanism2d mech2d{60, 60}; + wpi::MechanismRoot2d* armBase = mech2d.GetRoot("ArmBase", 30, 30); + wpi::MechanismLigament2d* armTower = + armBase->Append( "Arm Tower", 30, -90_deg, 6, wpi::util::Color8Bit{wpi::util::Color::BLUE}); - wpi::MechanismLigament2d* m_arm = m_armBase->Append( - "Arm", 30, m_armSim.GetAngle(), 6, + wpi::MechanismLigament2d* arm = armBase->Append( + "Arm", 30, armSim.GetAngle(), 6, wpi::util::Color8Bit{wpi::util::Color::YELLOW}); }; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp index 1e8d8033b3b..130e3913f9b 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Drivetrain.cpp @@ -6,24 +6,24 @@ void Drivetrain::SetVelocities( const wpi::math::DifferentialDriveWheelVelocities& velocities) { - const auto leftFeedforward = m_feedforward.Calculate(velocities.left); - const auto rightFeedforward = m_feedforward.Calculate(velocities.right); - const double leftOutput = m_leftPIDController.Calculate( - m_leftEncoder.GetRate(), velocities.left.value()); - const double rightOutput = m_rightPIDController.Calculate( - m_rightEncoder.GetRate(), velocities.right.value()); + const auto leftFeedforward = feedforward.Calculate(velocities.left); + const auto rightFeedforward = feedforward.Calculate(velocities.right); + const double leftOutput = leftPIDController.Calculate( + leftEncoder.GetRate(), velocities.left.value()); + const double rightOutput = rightPIDController.Calculate( + rightEncoder.GetRate(), velocities.right.value()); - m_leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); - m_rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); + leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); + rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); } void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::radians_per_second_t rot) { - SetVelocities(m_kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); + SetVelocities(kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); } void Drivetrain::UpdateOdometry() { - m_odometry.Update(m_imu.GetRotation2d(), - wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}); + odometry.Update(imu.GetRotation2d(), + wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}); } diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp index 07240594927..c90cf424b27 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/cpp/Robot.cpp @@ -11,35 +11,34 @@ class Robot : public wpi::TimedRobot { public: void AutonomousPeriodic() override { TeleopPeriodic(); - m_drive.UpdateOdometry(); + drive.UpdateOdometry(); } void TeleopPeriodic() override { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - const auto xVelocity = - -m_velocityLimiter.Calculate(m_controller.GetLeftY()) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -velocityLimiter.Calculate(controller.GetLeftY()) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * + const auto rot = -rotLimiter.Calculate(controller.GetRightX()) * Drivetrain::kMaxAngularVelocity; - m_drive.Drive(xVelocity, rot); + drive.Drive(xVelocity, rot); } private: - wpi::Gamepad m_controller{0}; + wpi::Gamepad controller{0}; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_velocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter velocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; - Drivetrain m_drive; + Drivetrain drive; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp index 66865080b6a..238d1d2dd80 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDriveBot/include/Drivetrain.hpp @@ -24,25 +24,25 @@ class Drivetrain { public: Drivetrain() { - m_leftLeader.AddFollower(m_leftFollower); - m_rightLeader.AddFollower(m_rightFollower); + leftLeader.AddFollower(leftFollower); + rightLeader.AddFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.SetInverted(true); + rightLeader.SetInverted(true); - m_imu.ResetYaw(); + imu.ResetYaw(); // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / - kEncoderResolution); - m_rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / - kEncoderResolution); + leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / + kEncoderResolution); + rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / + kEncoderResolution); - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); } static constexpr wpi::units::meters_per_second_t kMaxVelocity = @@ -61,26 +61,26 @@ class Drivetrain { static constexpr double kWheelRadius = 0.0508; // meters static constexpr int kEncoderResolution = 4096; - wpi::PWMSparkMax m_leftLeader{1}; - wpi::PWMSparkMax m_leftFollower{2}; - wpi::PWMSparkMax m_rightLeader{3}; - wpi::PWMSparkMax m_rightFollower{4}; + wpi::PWMSparkMax leftLeader{1}; + wpi::PWMSparkMax leftFollower{2}; + wpi::PWMSparkMax rightLeader{3}; + wpi::PWMSparkMax rightFollower{4}; - wpi::Encoder m_leftEncoder{0, 1}; - wpi::Encoder m_rightEncoder{2, 3}; + wpi::Encoder leftEncoder{0, 1}; + wpi::Encoder rightEncoder{2, 3}; - wpi::math::PIDController m_leftPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_rightPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController leftPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController rightPIDController{1.0, 0.0, 0.0}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::DifferentialDriveKinematics m_kinematics{kTrackwidth}; - wpi::math::DifferentialDriveOdometry m_odometry{ - m_imu.GetRotation2d(), wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}}; + wpi::math::DifferentialDriveKinematics kinematics{kTrackwidth}; + wpi::math::DifferentialDriveOdometry odometry{ + imu.GetRotation2d(), wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp index ddf698a202b..8a48593c8f1 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Drivetrain.cpp @@ -12,47 +12,47 @@ #include "wpi/system/RobotController.hpp" Drivetrain::Drivetrain() { - m_leftLeader.AddFollower(m_leftFollower); - m_rightLeader.AddFollower(m_rightFollower); + leftLeader.AddFollower(leftFollower); + rightLeader.AddFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.SetInverted(true); + rightLeader.SetInverted(true); - m_imu.ResetYaw(); + imu.ResetYaw(); // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_leftEncoder.SetDistancePerPulse( + leftEncoder.SetDistancePerPulse( (2 * std::numbers::pi * kWheelRadius / kEncoderResolution).value()); - m_rightEncoder.SetDistancePerPulse( + rightEncoder.SetDistancePerPulse( (2 * std::numbers::pi * kWheelRadius / kEncoderResolution).value()); - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); - wpi::SmartDashboard::PutData("FieldSim", &m_fieldSim); - wpi::SmartDashboard::PutData("Approximation", &m_fieldApproximation); + wpi::SmartDashboard::PutData("FieldSim", &fieldSim); + wpi::SmartDashboard::PutData("Approximation", &fieldApproximation); } void Drivetrain::SetVelocities( const wpi::math::DifferentialDriveWheelVelocities& velocities) { - const auto leftFeedforward = m_feedforward.Calculate(velocities.left); - const auto rightFeedforward = m_feedforward.Calculate(velocities.right); - const double leftOutput = m_leftPIDController.Calculate( - m_leftEncoder.GetRate(), velocities.left.value()); - const double rightOutput = m_rightPIDController.Calculate( - m_rightEncoder.GetRate(), velocities.right.value()); - - m_leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); - m_rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); + const auto leftFeedforward = feedforward.Calculate(velocities.left); + const auto rightFeedforward = feedforward.Calculate(velocities.right); + const double leftOutput = leftPIDController.Calculate( + leftEncoder.GetRate(), velocities.left.value()); + const double rightOutput = rightPIDController.Calculate( + rightEncoder.GetRate(), velocities.right.value()); + + leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); + rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); } void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::radians_per_second_t rot) { - SetVelocities(m_kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); + SetVelocities(kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); } void Drivetrain::PublishCameraToObject( @@ -93,19 +93,19 @@ wpi::math::Pose3d Drivetrain::ObjectToRobotPose( } void Drivetrain::UpdateOdometry() { - m_poseEstimator.Update(m_imu.GetRotation2d(), - wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}); + poseEstimator.Update(imu.GetRotation2d(), + wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}); // Publish cameraToObject transformation to networktables --this would // normally be handled by the computer vision solution. - PublishCameraToObject(m_objectInField, m_robotToCamera, - m_cameraToObjectEntryRef, m_drivetrainSimulator); + PublishCameraToObject(objectInField, robotToCamera, cameraToObjectEntryRef, + drivetrainSimulator); // Compute the robot's field-relative position exclusively from vision // measurements. - wpi::math::Pose3d visionMeasurement3d = ObjectToRobotPose( - m_objectInField, m_robotToCamera, m_cameraToObjectEntryRef); + wpi::math::Pose3d visionMeasurement3d = + ObjectToRobotPose(objectInField, robotToCamera, cameraToObjectEntryRef); // Convert robot's pose from wpi::math::Pose3d to wpi::math::Pose2d needed to // apply vision measurements. @@ -114,32 +114,30 @@ void Drivetrain::UpdateOdometry() { // Apply vision measurements. For simulation purposes only, we don't input a // latency delay -- on a real robot, this must be calculated based either on // known latency or timestamps. - m_poseEstimator.AddVisionMeasurement(visionMeasurement2d, - wpi::Timer::GetTimestamp()); + poseEstimator.AddVisionMeasurement(visionMeasurement2d, + wpi::Timer::GetTimestamp()); } void Drivetrain::SimulationPeriodic() { // To update our simulation, we set motor voltage inputs, update the // simulation, and write the simulated positions and velocities to our // simulated encoder and gyro. - m_drivetrainSimulator.SetInputs( - wpi::units::volt_t{m_leftLeader.GetThrottle()} * - wpi::RobotController::GetInputVoltage(), - wpi::units::volt_t{m_rightLeader.GetThrottle()} * - wpi::RobotController::GetInputVoltage()); - m_drivetrainSimulator.Update(20_ms); - - m_leftEncoderSim.SetDistance(m_drivetrainSimulator.GetLeftPosition().value()); - m_leftEncoderSim.SetRate(m_drivetrainSimulator.GetLeftVelocity().value()); - m_rightEncoderSim.SetDistance( - m_drivetrainSimulator.GetRightPosition().value()); - m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value()); - // m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value()); + drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage(), + wpi::units::volt_t{rightLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage()); + drivetrainSimulator.Update(20_ms); + + leftEncoderSim.SetDistance(drivetrainSimulator.GetLeftPosition().value()); + leftEncoderSim.SetRate(drivetrainSimulator.GetLeftVelocity().value()); + rightEncoderSim.SetDistance(drivetrainSimulator.GetRightPosition().value()); + rightEncoderSim.SetRate(drivetrainSimulator.GetRightVelocity().value()); + // gyroSim.SetAngle(-drivetrainSimulator.GetHeading().Degrees().value()); // // TODO(Ryan): fixup when sim implemented } void Drivetrain::Periodic() { UpdateOdometry(); - m_fieldSim.SetRobotPose(m_drivetrainSimulator.GetPose()); - m_fieldApproximation.SetRobotPose(m_poseEstimator.GetEstimatedPosition()); + fieldSim.SetRobotPose(drivetrainSimulator.GetPose()); + fieldApproximation.SetRobotPose(poseEstimator.GetEstimatedPosition()); } diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp index 2a71a00e0f9..df3626f038f 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/cpp/Robot.cpp @@ -11,39 +11,38 @@ class Robot : public wpi::TimedRobot { public: void AutonomousPeriodic() override { TeleopPeriodic(); - m_drive.UpdateOdometry(); + drive.UpdateOdometry(); } - void RobotPeriodic() override { m_drive.Periodic(); } + void RobotPeriodic() override { drive.Periodic(); } void TeleopPeriodic() override { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - const auto xVelocity = - -m_velocityLimiter.Calculate(m_controller.GetLeftY()) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -velocityLimiter.Calculate(controller.GetLeftY()) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * + const auto rot = -rotLimiter.Calculate(controller.GetRightX()) * Drivetrain::kMaxAngularVelocity; - m_drive.Drive(xVelocity, rot); + drive.Drive(xVelocity, rot); } - void SimulationPeriodic() override { m_drive.SimulationPeriodic(); } + void SimulationPeriodic() override { drive.SimulationPeriodic(); } private: - wpi::Gamepad m_controller{0}; + wpi::Gamepad controller{0}; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_velocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter velocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; - Drivetrain m_drive; + Drivetrain drive; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp index e047396a596..694415b61f1 100644 --- a/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DifferentialDrivePoseEstimator/include/Drivetrain.hpp @@ -114,64 +114,63 @@ class Drivetrain { static constexpr std::array kDefaultVal{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - wpi::math::Transform3d m_robotToCamera{ + wpi::math::Transform3d robotToCamera{ wpi::math::Translation3d{1_m, 1_m, 1_m}, wpi::math::Rotation3d{0_rad, 0_rad, wpi::units::radian_t{std::numbers::pi / 2}}}; - wpi::nt::NetworkTableInstance m_inst{ + wpi::nt::NetworkTableInstance inst{ wpi::nt::NetworkTableInstance::GetDefault()}; - wpi::nt::DoubleArrayTopic m_cameraToObjectTopic{ - m_inst.GetDoubleArrayTopic("m_cameraToObjectTopic")}; - wpi::nt::DoubleArrayEntry m_cameraToObjectEntry = - m_cameraToObjectTopic.GetEntry(kDefaultVal); - wpi::nt::DoubleArrayEntry& m_cameraToObjectEntryRef = m_cameraToObjectEntry; + wpi::nt::DoubleArrayTopic cameraToObjectTopic{ + inst.GetDoubleArrayTopic("cameraToObjectTopic")}; + wpi::nt::DoubleArrayEntry cameraToObjectEntry = + cameraToObjectTopic.GetEntry(kDefaultVal); + wpi::nt::DoubleArrayEntry& cameraToObjectEntryRef = cameraToObjectEntry; - wpi::apriltag::AprilTagFieldLayout m_aprilTagFieldLayout{ + wpi::apriltag::AprilTagFieldLayout aprilTagFieldLayout{ wpi::apriltag::AprilTagFieldLayout::LoadField( wpi::apriltag::AprilTagField::k2024Crescendo)}; - wpi::math::Pose3d m_objectInField{ - m_aprilTagFieldLayout.GetTagPose(0).value()}; + wpi::math::Pose3d objectInField{aprilTagFieldLayout.GetTagPose(0).value()}; - wpi::PWMSparkMax m_leftLeader{1}; - wpi::PWMSparkMax m_leftFollower{2}; - wpi::PWMSparkMax m_rightLeader{3}; - wpi::PWMSparkMax m_rightFollower{4}; + wpi::PWMSparkMax leftLeader{1}; + wpi::PWMSparkMax leftFollower{2}; + wpi::PWMSparkMax rightLeader{3}; + wpi::PWMSparkMax rightFollower{4}; - wpi::Encoder m_leftEncoder{0, 1}; - wpi::Encoder m_rightEncoder{2, 3}; + wpi::Encoder leftEncoder{0, 1}; + wpi::Encoder rightEncoder{2, 3}; - wpi::math::PIDController m_leftPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_rightPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController leftPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController rightPIDController{1.0, 0.0, 0.0}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::DifferentialDriveKinematics m_kinematics{kTrackwidth}; + wpi::math::DifferentialDriveKinematics kinematics{kTrackwidth}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::DifferentialDrivePoseEstimator m_poseEstimator{ - m_kinematics, - m_imu.GetRotation2d(), - wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}, + wpi::math::DifferentialDrivePoseEstimator poseEstimator{ + kinematics, + imu.GetRotation2d(), + wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}, wpi::math::Pose2d{}, {0.01, 0.01, 0.01}, {0.1, 0.1, 0.1}}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; // Simulation classes - wpi::sim::EncoderSim m_leftEncoderSim{m_leftEncoder}; - wpi::sim::EncoderSim m_rightEncoderSim{m_rightEncoder}; - wpi::Field2d m_fieldSim; - wpi::Field2d m_fieldApproximation; - wpi::math::LinearSystem<2, 2, 2> m_drivetrainSystem = + wpi::sim::EncoderSim leftEncoderSim{leftEncoder}; + wpi::sim::EncoderSim rightEncoderSim{rightEncoder}; + wpi::Field2d fieldSim; + wpi::Field2d fieldApproximation; + wpi::math::LinearSystem<2, 2, 2> drivetrainSystem = wpi::math::Models::DifferentialDriveFromSysId( 1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_mps, 0.3_V / 1_mps_sq); - wpi::sim::DifferentialDrivetrainSim m_drivetrainSimulator{ - m_drivetrainSystem, kTrackwidth, wpi::math::DCMotor::CIM(2), 8, 2_in}; + wpi::sim::DifferentialDrivetrainSim drivetrainSimulator{ + drivetrainSystem, kTrackwidth, wpi::math::DCMotor::CIM(2), 8, 2_in}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp index 0dc98a27e52..ee3bc8fd01c 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/Robot.cpp @@ -35,11 +35,11 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand) { + if (autonomousCommand) { wpi::cmd::CommandScheduler::GetInstance().Schedule( - m_autonomousCommand.value()); + autonomousCommand.value()); } } @@ -50,9 +50,9 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand) { - m_autonomousCommand->Cancel(); - m_autonomousCommand.reset(); + if (autonomousCommand) { + autonomousCommand->Cancel(); + autonomousCommand.reset(); } } diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp index 6d39814f000..0cbc94bc430 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/RobotContainer.cpp @@ -13,31 +13,31 @@ RobotContainer::RobotContainer() { ConfigureButtonBindings(); // Set up default drive command - m_drive.SetDefaultCommand(wpi::cmd::Run( + drive.SetDefaultCommand(wpi::cmd::Run( [this] { - m_drive.ArcadeDrive(-m_driverController.GetLeftY(), - -m_driverController.GetRightX()); + drive.ArcadeDrive(-driverController.GetLeftY(), + -driverController.GetRightX()); }, - {&m_drive})); + {&drive})); } void RobotContainer::ConfigureButtonBindings() { // Configure your button bindings here // While holding the bumper button, drive at half velocity - m_driverController.RightBumper() - .OnTrue(m_driveHalfVelocity.get()) - .OnFalse(m_driveFullVelocity.get()); + driverController.RightBumper() + .OnTrue(driveHalfVelocity.get()) + .OnFalse(driveFullVelocity.get()); // Drive forward by 3 meters when the 'South Face' button is pressed, with a // timeout of 10 seconds - m_driverController.SouthFace().OnTrue( - m_drive.ProfiledDriveDistance(3_m).WithTimeout(10_s)); + driverController.SouthFace().OnTrue( + drive.ProfiledDriveDistance(3_m).WithTimeout(10_s)); // Do the same thing as above when the 'East Face' button is pressed, but // without resetting the encoders - m_driverController.EastFace().OnTrue( - m_drive.DynamicProfiledDriveDistance(3_m).WithTimeout(10_s)); + driverController.EastFace().OnTrue( + drive.DynamicProfiledDriveDistance(3_m).WithTimeout(10_s)); } wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() { diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp index 6dc25fce99c..07c6ad73ced 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/cpp/subsystems/DriveSubsystem.cpp @@ -9,24 +9,24 @@ using namespace DriveConstants; DriveSubsystem::DriveSubsystem() - : m_leftLeader{kLeftMotor1Port}, - m_leftFollower{kLeftMotor2Port}, - m_rightLeader{kRightMotor1Port}, - m_rightFollower{kRightMotor2Port}, - m_feedforward{ks, kv, ka} { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_leftLeader); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_rightLeader); + : leftLeader{kLeftMotor1Port}, + leftFollower{kLeftMotor2Port}, + rightLeader{kRightMotor1Port}, + rightFollower{kRightMotor2Port}, + feedforward{ks, kv, ka} { + wpi::util::SendableRegistry::AddChild(&drive, &leftLeader); + wpi::util::SendableRegistry::AddChild(&drive, &rightLeader); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.SetInverted(true); + rightLeader.SetInverted(true); - m_leftFollower.Follow(m_leftLeader); - m_rightFollower.Follow(m_rightLeader); + leftFollower.Follow(leftLeader); + rightFollower.Follow(rightLeader); - m_leftLeader.SetPID(kp, 0, 0); - m_rightLeader.SetPID(kp, 0, 0); + leftLeader.SetPID(kp, 0, 0); + rightLeader.SetPID(kp, 0, 0); } void DriveSubsystem::Periodic() { @@ -39,37 +39,37 @@ void DriveSubsystem::SetDriveStates( wpi::math::TrapezoidProfile::State nextLeft, wpi::math::TrapezoidProfile::State nextRight) { // Feedforward is divided by battery voltage to normalize it to [-1, 1] - m_leftLeader.SetSetpoint( + leftLeader.SetSetpoint( ExampleSmartMotorController::PIDMode::kPosition, currentLeft.position.value(), - m_feedforward.Calculate(currentLeft.velocity, nextLeft.velocity) / + feedforward.Calculate(currentLeft.velocity, nextLeft.velocity) / wpi::RobotController::GetBatteryVoltage()); - m_rightLeader.SetSetpoint( + rightLeader.SetSetpoint( ExampleSmartMotorController::PIDMode::kPosition, currentRight.position.value(), - m_feedforward.Calculate(currentRight.velocity, nextRight.velocity) / + feedforward.Calculate(currentRight.velocity, nextRight.velocity) / wpi::RobotController::GetBatteryVoltage()); } void DriveSubsystem::ArcadeDrive(double fwd, double rot) { - m_drive.ArcadeDrive(fwd, rot); + drive.ArcadeDrive(fwd, rot); } void DriveSubsystem::ResetEncoders() { - m_leftLeader.ResetEncoder(); - m_rightLeader.ResetEncoder(); + leftLeader.ResetEncoder(); + rightLeader.ResetEncoder(); } wpi::units::meter_t DriveSubsystem::GetLeftEncoderDistance() { - return wpi::units::meter_t{m_leftLeader.GetEncoderDistance()}; + return wpi::units::meter_t{leftLeader.GetEncoderDistance()}; } wpi::units::meter_t DriveSubsystem::GetRightEncoderDistance() { - return wpi::units::meter_t{m_rightLeader.GetEncoderDistance()}; + return wpi::units::meter_t{rightLeader.GetEncoderDistance()}; } void DriveSubsystem::SetMaxOutput(double maxOutput) { - m_drive.SetMaxOutput(maxOutput); + drive.SetMaxOutput(maxOutput); } wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance( @@ -77,21 +77,21 @@ wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance( return StartRun( [&] { // Restart timer so profile setpoints start at the beginning - m_timer.Restart(); + timer.Restart(); ResetEncoders(); }, [&] { // Current state never changes, so we need to use a timer to get // the setpoints we need to be at - auto currentTime = m_timer.Get(); + auto currentTime = timer.Get(); auto currentSetpoint = - m_profile.Calculate(currentTime, {}, {distance, 0_mps}); - auto nextSetpoint = m_profile.Calculate(currentTime + kDt, {}, - {distance, 0_mps}); + profile.Calculate(currentTime, {}, {distance, 0_mps}); + auto nextSetpoint = + profile.Calculate(currentTime + kDt, {}, {distance, 0_mps}); SetDriveStates(currentSetpoint, currentSetpoint, nextSetpoint, nextSetpoint); }) - .Until([&] { return m_profile.IsFinished(0_s); }); + .Until([&] { return profile.IsFinished(0_s); }); } wpi::cmd::CommandPtr DriveSubsystem::DynamicProfiledDriveDistance( @@ -99,32 +99,32 @@ wpi::cmd::CommandPtr DriveSubsystem::DynamicProfiledDriveDistance( return StartRun( [&] { // Restart timer so profile setpoints start at the beginning - m_timer.Restart(); + timer.Restart(); // Store distance so we know the target distance for each encoder - m_initialLeftDistance = GetLeftEncoderDistance(); - m_initialRightDistance = GetRightEncoderDistance(); + initialLeftDistance = GetLeftEncoderDistance(); + initialRightDistance = GetRightEncoderDistance(); }, [&] { // Current state never changes for the duration of the command, // so we need to use a timer to get the setpoints we need to be // at - auto currentTime = m_timer.Get(); - - auto currentLeftSetpoint = m_profile.Calculate( - currentTime, {m_initialLeftDistance, 0_mps}, - {m_initialLeftDistance + distance, 0_mps}); - auto currentRightSetpoint = m_profile.Calculate( - currentTime, {m_initialRightDistance, 0_mps}, - {m_initialRightDistance + distance, 0_mps}); - - auto nextLeftSetpoint = m_profile.Calculate( - currentTime + kDt, {m_initialLeftDistance, 0_mps}, - {m_initialLeftDistance + distance, 0_mps}); - auto nextRightSetpoint = m_profile.Calculate( - currentTime + kDt, {m_initialRightDistance, 0_mps}, - {m_initialRightDistance + distance, 0_mps}); + auto currentTime = timer.Get(); + + auto currentLeftSetpoint = + profile.Calculate(currentTime, {initialLeftDistance, 0_mps}, + {initialLeftDistance + distance, 0_mps}); + auto currentRightSetpoint = + profile.Calculate(currentTime, {initialRightDistance, 0_mps}, + {initialRightDistance + distance, 0_mps}); + + auto nextLeftSetpoint = profile.Calculate( + currentTime + kDt, {initialLeftDistance, 0_mps}, + {initialLeftDistance + distance, 0_mps}); + auto nextRightSetpoint = profile.Calculate( + currentTime + kDt, {initialRightDistance, 0_mps}, + {initialRightDistance + distance, 0_mps}); SetDriveStates(currentLeftSetpoint, currentRightSetpoint, nextLeftSetpoint, nextRightSetpoint); }) - .Until([&] { return m_profile.IsFinished(0_s); }); + .Until([&] { return profile.IsFinished(0_s); }); } diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.hpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.hpp index ffbc6670877..aafa85b6c09 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/ExampleSmartMotorController.hpp @@ -66,9 +66,9 @@ class ExampleSmartMotorController { */ void ResetEncoder() {} - void Set(double velocity) { m_value = velocity; } + void Set(double velocity) { value = velocity; } - double Get() const { return m_value; } + double Get() const { return value; } void SetInverted(bool isInverted) {} @@ -79,5 +79,5 @@ class ExampleSmartMotorController { void StopMotor() {} private: - double m_value = 0.0; + double value = 0.0; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.hpp index 0e9c4263059..48afbcff88f 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/Robot.hpp @@ -25,7 +25,7 @@ class Robot : public wpi::TimedRobot { private: // Have it null by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - std::optional m_autonomousCommand; + std::optional autonomousCommand; - RobotContainer m_container; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.hpp index 98daed3f92b..8b388c870ea 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/RobotContainer.hpp @@ -26,19 +26,18 @@ class RobotContainer { private: // The driver's controller - wpi::cmd::CommandGamepad m_driverController{ - OIConstants::kDriverControllerPort}; + wpi::cmd::CommandGamepad driverController{OIConstants::kDriverControllerPort}; // The robot's subsystems and commands are defined here... // The robot's subsystems - DriveSubsystem m_drive; + DriveSubsystem drive; // RobotContainer-owned commands - wpi::cmd::CommandPtr m_driveHalfVelocity = - wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}); - wpi::cmd::CommandPtr m_driveFullVelocity = - wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {}); + wpi::cmd::CommandPtr driveHalfVelocity = + wpi::cmd::RunOnce([this] { drive.SetMaxOutput(0.5); }, {}); + wpi::cmd::CommandPtr driveFullVelocity = + wpi::cmd::RunOnce([this] { drive.SetMaxOutput(1); }, {}); void ConfigureButtonBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp index d03185828c1..d291b1f5774 100644 --- a/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp +++ b/wpilibcExamples/src/main/cpp/examples/DriveDistanceOffboard/include/subsystems/DriveSubsystem.hpp @@ -95,25 +95,24 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { wpi::units::meter_t distance); private: - wpi::math::TrapezoidProfile m_profile{ + wpi::math::TrapezoidProfile profile{ {DriveConstants::kMaxVelocity, DriveConstants::kMaxAcceleration}}; - wpi::Timer m_timer; - wpi::units::meter_t m_initialLeftDistance; - wpi::units::meter_t m_initialRightDistance; + wpi::Timer timer; + wpi::units::meter_t initialLeftDistance; + wpi::units::meter_t initialRightDistance; // Components (e.g. motor controllers and sensors) should generally be // declared private and exposed only through public methods. // The motor controllers - ExampleSmartMotorController m_leftLeader; - ExampleSmartMotorController m_leftFollower; - ExampleSmartMotorController m_rightLeader; - ExampleSmartMotorController m_rightFollower; + ExampleSmartMotorController leftLeader; + ExampleSmartMotorController leftFollower; + ExampleSmartMotorController rightLeader; + ExampleSmartMotorController rightFollower; // A feedforward component for the drive - wpi::math::SimpleMotorFeedforward m_feedforward; + wpi::math::SimpleMotorFeedforward feedforward; // The robot's drive - wpi::DifferentialDrive m_drive{ - [&](double output) { m_leftLeader.Set(output); }, - [&](double output) { m_rightLeader.Set(output); }}; + wpi::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); }, + [&](double output) { rightLeader.Set(output); }}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp index d8c58f2ab0a..4af02f14b71 100644 --- a/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/DutyCycleEncoder/cpp/Robot.cpp @@ -17,7 +17,7 @@ class Robot : public wpi::TimedRobot { // to measure this is fairly easy. Set the value to 0, place the mechanism // where you want "0" to be, and observe the value on the dashboard, That // is the value to enter for the 3rd parameter. - wpi::DutyCycleEncoder m_dutyCycleEncoder{0, fullRange, expectedZero}; + wpi::DutyCycleEncoder dutyCycleEncoder{0, fullRange, expectedZero}; public: Robot() { @@ -32,18 +32,18 @@ class Robot : public wpi::TimedRobot { // those values. This number doesn't have to be perfect, // just having a fairly close value will make the output readings // much more stable. - m_dutyCycleEncoder.SetAssumedFrequency(967.8_Hz); + dutyCycleEncoder.SetAssumedFrequency(967.8_Hz); } void RobotPeriodic() override { // Connected can be checked, and uses the frequency of the encoder - auto connected = m_dutyCycleEncoder.IsConnected(); + auto connected = dutyCycleEncoder.IsConnected(); // Duty Cycle Frequency in Hz - auto frequency = m_dutyCycleEncoder.GetFrequency(); + auto frequency = dutyCycleEncoder.GetFrequency(); // Output of encoder - auto output = m_dutyCycleEncoder.Get(); + auto output = dutyCycleEncoder.Get(); // By default, the output will wrap around to the full range value // when the sensor goes below 0. However, for moving mechanisms this diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp index 41e0502a1be..8dc89f92161 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialProfile/cpp/Robot.cpp @@ -19,44 +19,44 @@ class Robot : public wpi::TimedRobot { Robot() { // Note: These gains are fake, and will have to be tuned for your robot. - m_motor.SetPID(1.3, 0.0, 0.7); + motor.SetPID(1.3, 0.0, 0.7); } void TeleopPeriodic() override { - if (m_joystick.GetRawButtonPressed(2)) { - m_goal = {5_m, 0_mps}; - } else if (m_joystick.GetRawButtonPressed(3)) { - m_goal = {0_m, 0_mps}; + if (joystick.GetRawButtonPressed(2)) { + goal = {5_m, 0_mps}; + } else if (joystick.GetRawButtonPressed(3)) { + goal = {0_m, 0_mps}; } // Retrieve the profiled setpoint for the next timestep. This setpoint moves // toward the goal while obeying the constraints. - auto next = m_profile.Calculate(kDt, m_goal, m_setpoint); + auto next = profile.Calculate(kDt, goal, setpoint); // Send setpoint to offboard controller PID - m_motor.SetSetpoint( + motor.SetSetpoint( ExampleSmartMotorController::PIDMode::kPosition, - m_setpoint.position.value(), - m_feedforward.Calculate(m_setpoint.velocity, next.velocity) / 12_V); + setpoint.position.value(), + feedforward.Calculate(setpoint.velocity, next.velocity) / 12_V); - m_setpoint = next; + setpoint = next; } private: - wpi::Joystick m_joystick{1}; - ExampleSmartMotorController m_motor{1}; - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::Joystick joystick{1}; + ExampleSmartMotorController motor{1}; + wpi::math::SimpleMotorFeedforward feedforward{ // Note: These gains are fake, and will have to be tuned for your robot. 1_V, 1_V / 1_mps, 1_V / 1_mps_sq}; // Create a motion profile with the given maximum velocity and maximum // acceleration constraints for the next setpoint. - wpi::math::ExponentialProfile - m_profile{{10_V, 1_V / 1_mps, 1_V / 1_mps_sq}}; + wpi::math::ExponentialProfile profile{ + {10_V, 1_V / 1_mps, 1_V / 1_mps_sq}}; wpi::math::ExponentialProfile::State - m_goal; + goal; wpi::math::ExponentialProfile::State - m_setpoint; + setpoint; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/Robot.cpp index 30ac839b982..1f406d59062 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/Robot.cpp @@ -9,32 +9,32 @@ void Robot::RobotPeriodic() { // Update the telemetry, including mechanism visualization, regardless of // mode. - m_elevator.UpdateTelemetry(); + elevator.UpdateTelemetry(); } void Robot::SimulationPeriodic() { // Update the simulation model. - m_elevator.SimulationPeriodic(); + elevator.SimulationPeriodic(); } void Robot::TeleopInit() { // This just makes sure that our simulation code knows that the motor's off. - m_elevator.Reset(); + elevator.Reset(); } void Robot::TeleopPeriodic() { - if (m_joystick.GetTrigger()) { + if (joystick.GetTrigger()) { // Here, we set the constant setpoint of 0.75 meters. - m_elevator.ReachGoal(Constants::kSetpoint); + elevator.ReachGoal(Constants::kSetpoint); } else { // Otherwise, we update the setpoint to 0. - m_elevator.ReachGoal(Constants::kLowerSetpoint); + elevator.ReachGoal(Constants::kLowerSetpoint); } } void Robot::DisabledInit() { // This just makes sure that our simulation code knows that the motor's off. - m_elevator.Stop(); + elevator.Stop(); } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp index 82e249ce3c1..71a60e64d70 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/cpp/subsystems/Elevator.cpp @@ -8,56 +8,56 @@ #include "wpi/system/RobotController.hpp" Elevator::Elevator() { - m_encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse); + encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse); // Put Mechanism 2d to SmartDashboard // To view the Elevator visualization, select Network Tables -> SmartDashboard // -> Elevator Sim - wpi::SmartDashboard::PutData("Elevator Sim", &m_mech2d); + wpi::SmartDashboard::PutData("Elevator Sim", &mech2d); } void Elevator::SimulationPeriodic() { // In this method, we update our simulation of what our elevator is doing // First, we set our "inputs" (voltages) - m_elevatorSim.SetInput(wpi::math::Vectord<1>{ - m_motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()}); + elevatorSim.SetInput(wpi::math::Vectord<1>{ + motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()}); // Next, we update it. The standard loop time is 20ms. - m_elevatorSim.Update(20_ms); + elevatorSim.Update(20_ms); // Finally, we set our simulated encoder's readings and simulated battery // voltage - m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value()); + encoderSim.SetDistance(elevatorSim.GetPosition().value()); // SimBattery estimates loaded battery voltages wpi::sim::RoboRioSim::SetVInVoltage( - wpi::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()})); + wpi::sim::BatterySim::Calculate({elevatorSim.GetCurrentDraw()})); } void Elevator::UpdateTelemetry() { // Update the Elevator length based on the simulated elevator height - m_elevatorMech2d->SetLength(m_encoder.GetDistance()); + elevatorMech2d->SetLength(encoder.GetDistance()); } void Elevator::ReachGoal(wpi::units::meter_t goal) { wpi::math::ExponentialProfile::State goalState{goal, 0_mps}; - auto next = m_profile.Calculate(20_ms, m_setpoint, goalState); + auto next = profile.Calculate(20_ms, setpoint, goalState); - auto pidOutput = m_controller.Calculate(m_encoder.GetDistance(), - m_setpoint.position / 1_m); + auto pidOutput = + controller.Calculate(encoder.GetDistance(), setpoint.position / 1_m); auto feedforwardOutput = - m_feedforward.Calculate(m_setpoint.velocity, next.velocity); + feedforward.Calculate(setpoint.velocity, next.velocity); - m_motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); + motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); - m_setpoint = next; + setpoint = next; } void Elevator::Reset() { - m_setpoint = {m_encoder.GetDistance() * 1_m, 0_mps}; + setpoint = {encoder.GetDistance() * 1_m, 0_mps}; } void Elevator::Stop() { - m_motor.SetThrottle(0.0); + motor.SetThrottle(0.0); } diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Robot.hpp index 6a1add72889..4f4ee9cb916 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/Robot.hpp @@ -21,6 +21,6 @@ class Robot : public wpi::TimedRobot { void DisabledInit() override; private: - wpi::Joystick m_joystick{Constants::kJoystickPort}; - Elevator m_elevator; + wpi::Joystick joystick{Constants::kJoystickPort}; + Elevator elevator; }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp index 07828f57dd7..4d7a0c880b9 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorExponentialSimulation/include/subsystems/Elevator.hpp @@ -31,45 +31,45 @@ class Elevator { private: // This gearbox represents a gearbox containing 4 Vex 775pro motors. - wpi::math::DCMotor m_elevatorGearbox = wpi::math::DCMotor::NEO(2); + wpi::math::DCMotor elevatorGearbox = wpi::math::DCMotor::NEO(2); // Standard classes for controlling our elevator wpi::math::ExponentialProfile::Constraints m_constraints{ + wpi::units::volts>::Constraints constraints{ Constants::kElevatorMaxV, Constants::kElevatorkV, Constants::kElevatorkA}; - wpi::math::ExponentialProfile - m_profile{m_constraints}; + wpi::math::ExponentialProfile profile{ + constraints}; wpi::math::ExponentialProfile::State - m_setpoint; + setpoint; - wpi::math::PIDController m_controller{ + wpi::math::PIDController controller{ Constants::kElevatorKp, Constants::kElevatorKi, Constants::kElevatorKd}; - wpi::math::ElevatorFeedforward m_feedforward{ + wpi::math::ElevatorFeedforward feedforward{ Constants::kElevatorkS, Constants::kElevatorkG, Constants::kElevatorkV, Constants::kElevatorkA}; - wpi::Encoder m_encoder{Constants::kEncoderAChannel, - Constants::kEncoderBChannel}; - wpi::PWMSparkMax m_motor{Constants::kMotorPort}; - wpi::sim::PWMMotorControllerSim m_motorSim{m_motor}; + wpi::Encoder encoder{Constants::kEncoderAChannel, + Constants::kEncoderBChannel}; + wpi::PWMSparkMax motor{Constants::kMotorPort}; + wpi::sim::PWMMotorControllerSim motorSim{motor}; // Simulation classes help us simulate what's going on, including gravity. - wpi::sim::ElevatorSim m_elevatorSim{m_elevatorGearbox, - Constants::kElevatorGearing, - Constants::kCarriageMass, - Constants::kElevatorDrumRadius, - Constants::kMinElevatorHeight, - Constants::kMaxElevatorHeight, - true, - 0_m, - {0.005}}; - wpi::sim::EncoderSim m_encoderSim{m_encoder}; + wpi::sim::ElevatorSim elevatorSim{elevatorGearbox, + Constants::kElevatorGearing, + Constants::kCarriageMass, + Constants::kElevatorDrumRadius, + Constants::kMinElevatorHeight, + Constants::kMaxElevatorHeight, + true, + 0_m, + {0.005}}; + wpi::sim::EncoderSim encoderSim{encoder}; // Create a Mechanism2d display of an elevator - wpi::Mechanism2d m_mech2d{10_in / 1_m, 51_in / 1_m}; - wpi::MechanismRoot2d* m_elevatorRoot = - m_mech2d.GetRoot("Elevator Root", 5_in / 1_m, 0.5_in / 1_m); - wpi::MechanismLigament2d* m_elevatorMech2d = - m_elevatorRoot->Append( - "Elevator", m_elevatorSim.GetPosition().value(), 90_deg); + wpi::Mechanism2d mech2d{10_in / 1_m, 51_in / 1_m}; + wpi::MechanismRoot2d* elevatorRoot = + mech2d.GetRoot("Elevator Root", 5_in / 1_m, 0.5_in / 1_m); + wpi::MechanismLigament2d* elevatorMech2d = + elevatorRoot->Append( + "Elevator", elevatorSim.GetPosition().value(), 90_deg); }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp index c605aca2264..af72778efb9 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorProfiledPID/cpp/Robot.cpp @@ -22,21 +22,20 @@ class Robot : public wpi::TimedRobot { static constexpr wpi::units::second_t kDt = 20_ms; Robot() { - m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5); + encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5); } void TeleopPeriodic() override { - if (m_joystick.GetRawButtonPressed(2)) { - m_controller.SetGoal(5_m); - } else if (m_joystick.GetRawButtonPressed(3)) { - m_controller.SetGoal(0_m); + if (joystick.GetRawButtonPressed(2)) { + controller.SetGoal(5_m); + } else if (joystick.GetRawButtonPressed(3)) { + controller.SetGoal(0_m); } // Run controller and update motor output - m_motor.SetVoltage( - wpi::units::volt_t{m_controller.Calculate( - wpi::units::meter_t{m_encoder.GetDistance()})} + - m_feedforward.Calculate(m_controller.GetSetpoint().velocity)); + motor.SetVoltage(wpi::units::volt_t{controller.Calculate( + wpi::units::meter_t{encoder.GetDistance()})} + + feedforward.Calculate(controller.GetSetpoint().velocity)); } private: @@ -50,17 +49,17 @@ class Robot : public wpi::TimedRobot { static constexpr wpi::units::volt_t kG = 1.2_V; static constexpr auto kV = 1.3_V / 1_mps; - wpi::Joystick m_joystick{1}; - wpi::Encoder m_encoder{1, 2}; - wpi::PWMSparkMax m_motor{1}; + wpi::Joystick joystick{1}; + wpi::Encoder encoder{1, 2}; + wpi::PWMSparkMax motor{1}; // Create a PID controller whose setpoint's change is subject to maximum // velocity and acceleration constraints. - wpi::math::TrapezoidProfile::Constraints m_constraints{ + wpi::math::TrapezoidProfile::Constraints constraints{ kMaxVelocity, kMaxAcceleration}; - wpi::math::ProfiledPIDController m_controller{ - kP, kI, kD, m_constraints, kDt}; - wpi::math::ElevatorFeedforward m_feedforward{kS, kG, kV}; + wpi::math::ProfiledPIDController controller{ + kP, kI, kD, constraints, kDt}; + wpi::math::ElevatorFeedforward feedforward{kS, kG, kV}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp index d71256a8cee..58fdedde09a 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/Robot.cpp @@ -9,27 +9,27 @@ void Robot::RobotPeriodic() { // Update the telemetry, including mechanism visualization, regardless of // mode. - m_elevator.UpdateTelemetry(); + elevator.UpdateTelemetry(); } void Robot::SimulationPeriodic() { // Update the simulation model. - m_elevator.SimulationPeriodic(); + elevator.SimulationPeriodic(); } void Robot::TeleopPeriodic() { - if (m_joystick.GetTrigger()) { + if (joystick.GetTrigger()) { // Here, we set the constant setpoint of 0.75 meters. - m_elevator.ReachGoal(Constants::kSetpoint); + elevator.ReachGoal(Constants::kSetpoint); } else { // Otherwise, we update the setpoint to 0. - m_elevator.ReachGoal(0.0_m); + elevator.ReachGoal(0.0_m); } } void Robot::DisabledInit() { // This just makes sure that our simulation code knows that the motor's off. - m_elevator.Stop(); + elevator.Stop(); } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp index 2f9f595e660..0ea914fe3b6 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/cpp/subsystems/Elevator.cpp @@ -8,47 +8,47 @@ #include "wpi/system/RobotController.hpp" Elevator::Elevator() { - m_encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse); + encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse); // Put Mechanism 2d to SmartDashboard // To view the Elevator visualization, select Network Tables -> SmartDashboard // -> Elevator Sim - wpi::SmartDashboard::PutData("Elevator Sim", &m_mech2d); + wpi::SmartDashboard::PutData("Elevator Sim", &mech2d); } void Elevator::SimulationPeriodic() { // In this method, we update our simulation of what our elevator is doing // First, we set our "inputs" (voltages) - m_elevatorSim.SetInput(wpi::math::Vectord<1>{ - m_motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()}); + elevatorSim.SetInput(wpi::math::Vectord<1>{ + motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()}); // Next, we update it. The standard loop time is 20ms. - m_elevatorSim.Update(20_ms); + elevatorSim.Update(20_ms); // Finally, we set our simulated encoder's readings and simulated battery // voltage - m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value()); + encoderSim.SetDistance(elevatorSim.GetPosition().value()); // SimBattery estimates loaded battery voltages wpi::sim::RoboRioSim::SetVInVoltage( - wpi::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()})); + wpi::sim::BatterySim::Calculate({elevatorSim.GetCurrentDraw()})); } void Elevator::UpdateTelemetry() { // Update the Elevator length based on the simulated elevator height - m_elevatorMech2d->SetLength(m_encoder.GetDistance()); + elevatorMech2d->SetLength(encoder.GetDistance()); } void Elevator::ReachGoal(wpi::units::meter_t goal) { - m_controller.SetGoal(goal); + controller.SetGoal(goal); // With the setpoint value we run PID control like normal double pidOutput = - m_controller.Calculate(wpi::units::meter_t{m_encoder.GetDistance()}); + controller.Calculate(wpi::units::meter_t{encoder.GetDistance()}); wpi::units::volt_t feedforwardOutput = - m_feedforward.Calculate(m_controller.GetSetpoint().velocity); - m_motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); + feedforward.Calculate(controller.GetSetpoint().velocity); + motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); } void Elevator::Stop() { - m_controller.SetGoal(0.0_m); - m_motor.SetThrottle(0.0); + controller.SetGoal(0.0_m); + motor.SetThrottle(0.0); } diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Robot.hpp index 4dfa94cb274..dd47cf34f49 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/Robot.hpp @@ -20,6 +20,6 @@ class Robot : public wpi::TimedRobot { void DisabledInit() override; private: - wpi::Joystick m_joystick{Constants::kJoystickPort}; - Elevator m_elevator; + wpi::Joystick joystick{Constants::kJoystickPort}; + Elevator elevator; }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp index 3fdf7269cd5..925eddef4c6 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorSimulation/include/subsystems/Elevator.hpp @@ -30,40 +30,39 @@ class Elevator { private: // This gearbox represents a gearbox containing 4 Vex 775pro motors. - wpi::math::DCMotor m_elevatorGearbox = wpi::math::DCMotor::Vex775Pro(4); + wpi::math::DCMotor elevatorGearbox = wpi::math::DCMotor::Vex775Pro(4); // Standard classes for controlling our elevator - wpi::math::TrapezoidProfile::Constraints m_constraints{ + wpi::math::TrapezoidProfile::Constraints constraints{ 2.45_mps, 2.45_mps_sq}; - wpi::math::ProfiledPIDController m_controller{ + wpi::math::ProfiledPIDController controller{ Constants::kElevatorKp, Constants::kElevatorKi, Constants::kElevatorKd, - m_constraints}; + constraints}; - wpi::math::ElevatorFeedforward m_feedforward{ + wpi::math::ElevatorFeedforward feedforward{ Constants::kElevatorkS, Constants::kElevatorkG, Constants::kElevatorkV, Constants::kElevatorkA}; - wpi::Encoder m_encoder{Constants::kEncoderAChannel, - Constants::kEncoderBChannel}; - wpi::PWMSparkMax m_motor{Constants::kMotorPort}; - wpi::sim::PWMMotorControllerSim m_motorSim{m_motor}; + wpi::Encoder encoder{Constants::kEncoderAChannel, + Constants::kEncoderBChannel}; + wpi::PWMSparkMax motor{Constants::kMotorPort}; + wpi::sim::PWMMotorControllerSim motorSim{motor}; // Simulation classes help us simulate what's going on, including gravity. - wpi::sim::ElevatorSim m_elevatorSim{m_elevatorGearbox, - Constants::kElevatorGearing, - Constants::kCarriageMass, - Constants::kElevatorDrumRadius, - Constants::kMinElevatorHeight, - Constants::kMaxElevatorHeight, - true, - 0_m, - {0.01}}; - wpi::sim::EncoderSim m_encoderSim{m_encoder}; + wpi::sim::ElevatorSim elevatorSim{elevatorGearbox, + Constants::kElevatorGearing, + Constants::kCarriageMass, + Constants::kElevatorDrumRadius, + Constants::kMinElevatorHeight, + Constants::kMaxElevatorHeight, + true, + 0_m, + {0.01}}; + wpi::sim::EncoderSim encoderSim{encoder}; // Create a Mechanism2d display of an elevator - wpi::Mechanism2d m_mech2d{20, 50}; - wpi::MechanismRoot2d* m_elevatorRoot = - m_mech2d.GetRoot("Elevator Root", 10, 0); - wpi::MechanismLigament2d* m_elevatorMech2d = - m_elevatorRoot->Append( - "Elevator", m_elevatorSim.GetPosition().value(), 90_deg); + wpi::Mechanism2d mech2d{20, 50}; + wpi::MechanismRoot2d* elevatorRoot = mech2d.GetRoot("Elevator Root", 10, 0); + wpi::MechanismLigament2d* elevatorMech2d = + elevatorRoot->Append( + "Elevator", elevatorSim.GetPosition().value(), 90_deg); }; diff --git a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp index 4903f487558..d7ed37c4a92 100644 --- a/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/ElevatorTrapezoidProfile/cpp/Robot.cpp @@ -19,39 +19,39 @@ class Robot : public wpi::TimedRobot { Robot() { // Note: These gains are fake, and will have to be tuned for your robot. - m_motor.SetPID(1.3, 0.0, 0.7); + motor.SetPID(1.3, 0.0, 0.7); } void TeleopPeriodic() override { - if (m_joystick.GetRawButtonPressed(2)) { - m_goal = {5_m, 0_mps}; - } else if (m_joystick.GetRawButtonPressed(3)) { - m_goal = {0_m, 0_mps}; + if (joystick.GetRawButtonPressed(2)) { + goal = {5_m, 0_mps}; + } else if (joystick.GetRawButtonPressed(3)) { + goal = {0_m, 0_mps}; } // Retrieve the profiled setpoint for the next timestep. This setpoint moves // toward the goal while obeying the constraints. - m_setpoint = m_profile.Calculate(kDt, m_setpoint, m_goal); + setpoint = profile.Calculate(kDt, setpoint, goal); // Send setpoint to offboard controller PID - m_motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition, - m_setpoint.position.value(), - m_feedforward.Calculate(m_setpoint.velocity) / 12_V); + motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition, + setpoint.position.value(), + feedforward.Calculate(setpoint.velocity) / 12_V); } private: - wpi::Joystick m_joystick{1}; - ExampleSmartMotorController m_motor{1}; - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::Joystick joystick{1}; + ExampleSmartMotorController motor{1}; + wpi::math::SimpleMotorFeedforward feedforward{ // Note: These gains are fake, and will have to be tuned for your robot. 1_V, 1.5_V * 1_s / 1_m}; // Create a motion profile with the given maximum velocity and maximum // acceleration constraints for the next setpoint. - wpi::math::TrapezoidProfile m_profile{ + wpi::math::TrapezoidProfile profile{ {1.75_mps, 0.75_mps_sq}}; - wpi::math::TrapezoidProfile::State m_goal; - wpi::math::TrapezoidProfile::State m_setpoint; + wpi::math::TrapezoidProfile::State goal; + wpi::math::TrapezoidProfile::State setpoint; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp index 60d5d313114..245a6c9e4b7 100644 --- a/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Encoder/cpp/Robot.cpp @@ -34,29 +34,29 @@ class Robot : public wpi::TimedRobot { * On a quadrature encoder, values range from 1-255; larger values result in * smoother but potentially less accurate rates than lower values. */ - m_encoder.SetSamplesToAverage(5); + encoder.SetSamplesToAverage(5); /* Defines how far the mechanism attached to the encoder moves per pulse. In * this case, we assume that a 360 count encoder is directly attached to a 3 * inch diameter (1.5inch radius) wheel, and that we want to measure * distance in inches. */ - m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5); + encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * std::numbers::pi * 1.5); /* Defines the lowest rate at which the encoder will not be considered * stopped, for the purposes of the GetStopped() method. Units are in * distance / second, where distance refers to the units of distance that * you are using, in this case inches. */ - m_encoder.SetMinRate(1.0); + encoder.SetMinRate(1.0); } void TeleopPeriodic() override { // Retrieve the net displacement of the Encoder since the last Reset. - wpi::SmartDashboard::PutNumber("Encoder Distance", m_encoder.GetDistance()); + wpi::SmartDashboard::PutNumber("Encoder Distance", encoder.GetDistance()); // Retrieve the current rate of the encoder. - wpi::SmartDashboard::PutNumber("Encoder Rate", m_encoder.GetRate()); + wpi::SmartDashboard::PutNumber("Encoder Rate", encoder.GetRate()); } private: @@ -76,7 +76,7 @@ class Robot : public wpi::TimedRobot { * and defaults to X4. Faster (X4) encoding gives greater positional * precision but more noise in the rate. */ - wpi::Encoder m_encoder{1, 2, false, wpi::Encoder::EncodingType::X4}; + wpi::Encoder encoder{1, 2, false, wpi::Encoder::EncodingType::X4}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp index 71ad9ec71ee..1ccd9ccb7f8 100644 --- a/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GettingStarted/cpp/Robot.cpp @@ -11,27 +11,27 @@ class Robot : public wpi::TimedRobot { public: Robot() { - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_left); - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_right); + wpi::util::SendableRegistry::AddChild(&robotDrive, &left); + wpi::util::SendableRegistry::AddChild(&robotDrive, &right); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_right.SetInverted(true); - m_robotDrive.SetExpiration(100_ms); - m_timer.Start(); + right.SetInverted(true); + robotDrive.SetExpiration(100_ms); + timer.Start(); } - void AutonomousInit() override { m_timer.Restart(); } + void AutonomousInit() override { timer.Restart(); } void AutonomousPeriodic() override { // Drive for 2 seconds - if (m_timer.Get() < 2_s) { + if (timer.Get() < 2_s) { // Drive forwards half velocity, make sure to turn input squaring off - m_robotDrive.ArcadeDrive(0.5, 0.0, false); + robotDrive.ArcadeDrive(0.5, 0.0, false); } else { // Stop robot - m_robotDrive.ArcadeDrive(0.0, 0.0, false); + robotDrive.ArcadeDrive(0.0, 0.0, false); } } @@ -39,8 +39,7 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Drive with arcade style (use right stick to steer) - m_robotDrive.ArcadeDrive(-m_controller.GetLeftY(), - m_controller.GetRightX()); + robotDrive.ArcadeDrive(-controller.GetLeftY(), controller.GetRightX()); } void UtilityInit() override {} @@ -49,14 +48,14 @@ class Robot : public wpi::TimedRobot { private: // Robot drive system - wpi::PWMSparkMax m_left{0}; - wpi::PWMSparkMax m_right{1}; - wpi::DifferentialDrive m_robotDrive{ - [&](double output) { m_left.SetThrottle(output); }, - [&](double output) { m_right.SetThrottle(output); }}; + wpi::PWMSparkMax left{0}; + wpi::PWMSparkMax right{1}; + wpi::DifferentialDrive robotDrive{ + [&](double output) { left.SetThrottle(output); }, + [&](double output) { right.SetThrottle(output); }}; - wpi::Gamepad m_controller{0}; - wpi::Timer m_timer; + wpi::Gamepad controller{0}; + wpi::Timer timer; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp index 75cfbc66122..23631e2207b 100644 --- a/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Gyro/cpp/Robot.cpp @@ -21,10 +21,10 @@ class Robot : public wpi::TimedRobot { // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_right.SetInverted(true); + right.SetInverted(true); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_left); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_right); + wpi::util::SendableRegistry::AddChild(&drive, &left); + wpi::util::SendableRegistry::AddChild(&drive, &right); } /** @@ -34,8 +34,8 @@ class Robot : public wpi::TimedRobot { */ void TeleopPeriodic() override { double turningValue = - (kAngleSetpoint - m_imu.GetRotation2d().Degrees().value()) * kP; - m_drive.ArcadeDrive(-m_joystick.GetY(), -turningValue); + (kAngleSetpoint - imu.GetRotation2d().Degrees().value()) * kP; + drive.ArcadeDrive(-joystick.GetY(), -turningValue); } private: @@ -48,14 +48,14 @@ class Robot : public wpi::TimedRobot { wpi::OnboardIMU::FLAT; static constexpr int kJoystickPort = 0; - wpi::PWMSparkMax m_left{kLeftMotorPort}; - wpi::PWMSparkMax m_right{kRightMotorPort}; - wpi::DifferentialDrive m_drive{ - [&](double output) { m_left.SetThrottle(output); }, - [&](double output) { m_right.SetThrottle(output); }}; + wpi::PWMSparkMax left{kLeftMotorPort}; + wpi::PWMSparkMax right{kRightMotorPort}; + wpi::DifferentialDrive drive{ + [&](double output) { left.SetThrottle(output); }, + [&](double output) { right.SetThrottle(output); }}; - wpi::OnboardIMU m_imu{kIMUMountOrientation}; - wpi::Joystick m_joystick{kJoystickPort}; + wpi::OnboardIMU imu{kIMUMountOrientation}; + wpi::Joystick joystick{kJoystickPort}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp index 9fc2a216c40..f39fcb031e4 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/Robot.cpp @@ -44,10 +44,10 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand != nullptr) { - wpi::cmd::CommandScheduler::GetInstance().Schedule(m_autonomousCommand); + if (autonomousCommand != nullptr) { + wpi::cmd::CommandScheduler::GetInstance().Schedule(autonomousCommand); } } @@ -58,9 +58,9 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != nullptr) { - m_autonomousCommand->Cancel(); - m_autonomousCommand = nullptr; + if (autonomousCommand != nullptr) { + autonomousCommand->Cancel(); + autonomousCommand = nullptr; } } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp index 052f1a5cc54..b79c16cecc5 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp @@ -11,41 +11,41 @@ RobotContainer::RobotContainer() { // Add commands to the autonomous command chooser // Note that we do *not* move ownership into the chooser - m_chooser.SetDefaultOption("Simple Auto", m_simpleAuto.get()); - m_chooser.AddOption("Complex Auto", m_complexAuto.get()); + chooser.SetDefaultOption("Simple Auto", simpleAuto.get()); + chooser.AddOption("Complex Auto", complexAuto.get()); // Put the chooser on the dashboard - wpi::SmartDashboard::PutData("Autonomous", &m_chooser); + wpi::SmartDashboard::PutData("Autonomous", &chooser); // Put subsystems to dashboard. - wpi::SmartDashboard::PutData("Drivetrain", &m_drive); - wpi::SmartDashboard::PutData("HatchSubsystem", &m_hatch); + wpi::SmartDashboard::PutData("Drivetrain", &drive); + wpi::SmartDashboard::PutData("HatchSubsystem", &hatch); // Configure the button bindings ConfigureButtonBindings(); // Set up default drive command - m_drive.SetDefaultCommand(wpi::cmd::Run( + drive.SetDefaultCommand(wpi::cmd::Run( [this] { - m_drive.ArcadeDrive(-m_driverController.GetLeftY(), - -m_driverController.GetRightX()); + drive.ArcadeDrive(-driverController.GetLeftY(), + -driverController.GetRightX()); }, - {&m_drive})); + {&drive})); } void RobotContainer::ConfigureButtonBindings() { // Configure your button bindings here // Grab the hatch when the 'East Face' button is pressed. - m_driverController.EastFace().OnTrue(m_hatch.GrabHatchCommand()); + driverController.EastFace().OnTrue(hatch.GrabHatchCommand()); // Release the hatch when the 'West Face' button is pressed. - m_driverController.WestFace().OnTrue(m_hatch.ReleaseHatchCommand()); + driverController.WestFace().OnTrue(hatch.ReleaseHatchCommand()); // While holding Right Bumper, drive at half velocity - m_driverController.RightBumper() - .OnTrue(wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {})) - .OnFalse(wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1.0); }, {})); + driverController.RightBumper() + .OnTrue(wpi::cmd::RunOnce([this] { drive.SetMaxOutput(0.5); }, {})) + .OnFalse(wpi::cmd::RunOnce([this] { drive.SetMaxOutput(1.0); }, {})); } wpi::cmd::Command* RobotContainer::GetAutonomousCommand() { // Runs the chosen command in autonomous - return m_chooser.GetSelected(); + return chooser.GetSelected(); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp index 8bae9bdad2a..feaa942b87e 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/DriveSubsystem.cpp @@ -9,26 +9,26 @@ using namespace DriveConstants; DriveSubsystem::DriveSubsystem() - : m_left1{kLeftMotor1Port}, - m_left2{kLeftMotor2Port}, - m_right1{kRightMotor1Port}, - m_right2{kRightMotor2Port}, - m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]}, - m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_left1); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_right1); - - m_left1.AddFollower(m_left2); - m_right1.AddFollower(m_right2); + : left1{kLeftMotor1Port}, + left2{kLeftMotor2Port}, + right1{kRightMotor1Port}, + right2{kRightMotor2Port}, + leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]}, + rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} { + wpi::util::SendableRegistry::AddChild(&drive, &left1); + wpi::util::SendableRegistry::AddChild(&drive, &right1); + + left1.AddFollower(left2); + right1.AddFollower(right2); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_right1.SetInverted(true); + right1.SetInverted(true); // Set the distance per pulse for the encoders - m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); - m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); + leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); + rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); } void DriveSubsystem::Periodic() { @@ -36,20 +36,20 @@ void DriveSubsystem::Periodic() { } void DriveSubsystem::ArcadeDrive(double fwd, double rot) { - m_drive.ArcadeDrive(fwd, rot); + drive.ArcadeDrive(fwd, rot); } void DriveSubsystem::ResetEncoders() { - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); } double DriveSubsystem::GetAverageEncoderDistance() { - return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0; + return (leftEncoder.GetDistance() + rightEncoder.GetDistance()) / 2.0; } void DriveSubsystem::SetMaxOutput(double maxOutput) { - m_drive.SetMaxOutput(maxOutput); + drive.SetMaxOutput(maxOutput); } void DriveSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { @@ -57,8 +57,7 @@ void DriveSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { // Publish encoder distances to telemetry. builder.AddDoubleProperty( - "leftDistance", [this] { return m_leftEncoder.GetDistance(); }, nullptr); + "leftDistance", [this] { return leftEncoder.GetDistance(); }, nullptr); builder.AddDoubleProperty( - "rightDistance", [this] { return m_rightEncoder.GetDistance(); }, - nullptr); + "rightDistance", [this] { return rightEncoder.GetDistance(); }, nullptr); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp index be653352f4d..445959ecd81 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/subsystems/HatchSubsystem.cpp @@ -9,19 +9,19 @@ using namespace HatchConstants; HatchSubsystem::HatchSubsystem() - : m_hatchSolenoid{0, wpi::PneumaticsModuleType::CTRE_PCM, - kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {} + : hatchSolenoid{0, wpi::PneumaticsModuleType::CTRE_PCM, + kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {} wpi::cmd::CommandPtr HatchSubsystem::GrabHatchCommand() { // implicitly require `this` return this->RunOnce( - [this] { m_hatchSolenoid.Set(wpi::DoubleSolenoid::FORWARD); }); + [this] { hatchSolenoid.Set(wpi::DoubleSolenoid::FORWARD); }); } wpi::cmd::CommandPtr HatchSubsystem::ReleaseHatchCommand() { // implicitly require `this` return this->RunOnce( - [this] { m_hatchSolenoid.Set(wpi::DoubleSolenoid::REVERSE); }); + [this] { hatchSolenoid.Set(wpi::DoubleSolenoid::REVERSE); }); } void HatchSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { @@ -30,6 +30,6 @@ void HatchSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { // Publish the solenoid state to telemetry. builder.AddBooleanProperty( "extended", - [this] { return m_hatchSolenoid.Get() == wpi::DoubleSolenoid::FORWARD; }, + [this] { return hatchSolenoid.Get() == wpi::DoubleSolenoid::FORWARD; }, nullptr); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.hpp index 377ae1bfc2f..c59dc48dc32 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/Robot.hpp @@ -23,7 +23,7 @@ class Robot : public wpi::TimedRobot { private: // Have it null by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - wpi::cmd::Command* m_autonomousCommand = nullptr; + wpi::cmd::Command* autonomousCommand = nullptr; - RobotContainer m_container; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.hpp index 27b5326b3e7..d614f2b2f42 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/RobotContainer.hpp @@ -30,23 +30,22 @@ class RobotContainer { private: // The driver's controller - wpi::cmd::CommandGamepad m_driverController{ - OIConstants::kDriverControllerPort}; + wpi::cmd::CommandGamepad driverController{OIConstants::kDriverControllerPort}; // The robot's subsystems and commands are defined here... // The robot's subsystems - DriveSubsystem m_drive; - HatchSubsystem m_hatch; + DriveSubsystem drive; + HatchSubsystem hatch; // Commands owned by RobotContainer // The autonomous routines - wpi::cmd::CommandPtr m_simpleAuto = autos::SimpleAuto(&m_drive); - wpi::cmd::CommandPtr m_complexAuto = autos::ComplexAuto(&m_drive, &m_hatch); + wpi::cmd::CommandPtr simpleAuto = autos::SimpleAuto(&drive); + wpi::cmd::CommandPtr complexAuto = autos::ComplexAuto(&drive, &hatch); // The chooser for the autonomous routines - wpi::SendableChooser m_chooser; + wpi::SendableChooser chooser; void ConfigureButtonBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.hpp index 0367dd24090..f3c23f6ac38 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/DriveSubsystem.hpp @@ -56,19 +56,19 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { // declared private and exposed only through public methods. // The motor controllers - wpi::PWMSparkMax m_left1; - wpi::PWMSparkMax m_left2; - wpi::PWMSparkMax m_right1; - wpi::PWMSparkMax m_right2; + wpi::PWMSparkMax left1; + wpi::PWMSparkMax left2; + wpi::PWMSparkMax right1; + wpi::PWMSparkMax right2; // The robot's drive - wpi::DifferentialDrive m_drive{ - [&](double output) { m_left1.SetThrottle(output); }, - [&](double output) { m_right1.SetThrottle(output); }}; + wpi::DifferentialDrive drive{ + [&](double output) { left1.SetThrottle(output); }, + [&](double output) { right1.SetThrottle(output); }}; // The left-side drive encoder - wpi::Encoder m_leftEncoder; + wpi::Encoder leftEncoder; // The right-side drive encoder - wpi::Encoder m_rightEncoder; + wpi::Encoder rightEncoder; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.hpp index d1fd94643cc..0be87fc9076 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/include/subsystems/HatchSubsystem.hpp @@ -31,5 +31,5 @@ class HatchSubsystem : public wpi::cmd::SubsystemBase { private: // Components (e.g. motor controllers and sensors) should generally be // declared private and exposed only through public methods. - wpi::DoubleSolenoid m_hatchSolenoid; + wpi::DoubleSolenoid hatchSolenoid; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp index 9fc2a216c40..f39fcb031e4 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/Robot.cpp @@ -44,10 +44,10 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand != nullptr) { - wpi::cmd::CommandScheduler::GetInstance().Schedule(m_autonomousCommand); + if (autonomousCommand != nullptr) { + wpi::cmd::CommandScheduler::GetInstance().Schedule(autonomousCommand); } } @@ -58,9 +58,9 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != nullptr) { - m_autonomousCommand->Cancel(); - m_autonomousCommand = nullptr; + if (autonomousCommand != nullptr) { + autonomousCommand->Cancel(); + autonomousCommand = nullptr; } } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp index b984ddf91b1..4014810c721 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp @@ -15,22 +15,22 @@ RobotContainer::RobotContainer() { // Initialize all of your commands and subsystems here // Add commands to the autonomous command chooser - m_chooser.SetDefaultOption("Simple Auto", &m_simpleAuto); - m_chooser.AddOption("Complex Auto", &m_complexAuto); + chooser.SetDefaultOption("Simple Auto", &simpleAuto); + chooser.AddOption("Complex Auto", &complexAuto); // Put the chooser on the dashboard - wpi::SmartDashboard::PutData("Autonomous", &m_chooser); + wpi::SmartDashboard::PutData("Autonomous", &chooser); // Put subsystems to dashboard. - wpi::SmartDashboard::PutData("Drivetrain", &m_drive); - wpi::SmartDashboard::PutData("HatchSubsystem", &m_hatch); + wpi::SmartDashboard::PutData("Drivetrain", &drive); + wpi::SmartDashboard::PutData("HatchSubsystem", &hatch); // Configure the button bindings ConfigureButtonBindings(); // Set up default drive command - m_drive.SetDefaultCommand(DefaultDrive( - &m_drive, [this] { return -m_driverController.GetLeftY(); }, - [this] { return -m_driverController.GetRightX(); })); + drive.SetDefaultCommand(DefaultDrive( + &drive, [this] { return -driverController.GetLeftY(); }, + [this] { return -driverController.GetRightX(); })); } void RobotContainer::ConfigureButtonBindings() { @@ -40,18 +40,17 @@ void RobotContainer::ConfigureButtonBindings() { // the scheduler thus, no memory leaks! // Grab the hatch when the 'South Face' button is pressed. - wpi::cmd::GamepadButton(&m_driverController, wpi::Gamepad::Button::SOUTH_FACE) - .OnTrue(GrabHatch(&m_hatch).ToPtr()); + wpi::cmd::GamepadButton(&driverController, wpi::Gamepad::Button::SOUTH_FACE) + .OnTrue(GrabHatch(&hatch).ToPtr()); // Release the hatch when the 'East Face' button is pressed. - wpi::cmd::GamepadButton(&m_driverController, wpi::Gamepad::Button::EAST_FACE) - .OnTrue(ReleaseHatch(&m_hatch).ToPtr()); + wpi::cmd::GamepadButton(&driverController, wpi::Gamepad::Button::EAST_FACE) + .OnTrue(ReleaseHatch(&hatch).ToPtr()); // While holding the bumper button, drive at half velocity - wpi::cmd::GamepadButton(&m_driverController, - wpi::Gamepad::Button::RIGHT_BUMPER) - .WhileTrue(HalveDriveVelocity(&m_drive).ToPtr()); + wpi::cmd::GamepadButton(&driverController, wpi::Gamepad::Button::RIGHT_BUMPER) + .WhileTrue(HalveDriveVelocity(&drive).ToPtr()); } wpi::cmd::Command* RobotContainer::GetAutonomousCommand() { // Runs the chosen command in autonomous - return m_chooser.GetSelected(); + return chooser.GetSelected(); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp index fce831d9c37..13ebd9d7867 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DefaultDrive.cpp @@ -9,12 +9,12 @@ DefaultDrive::DefaultDrive(DriveSubsystem* subsystem, std::function forward, std::function rotation) - : m_drive{subsystem}, - m_forward{std::move(forward)}, - m_rotation{std::move(rotation)} { + : drive{subsystem}, + forward{std::move(forward)}, + rotation{std::move(rotation)} { AddRequirements(subsystem); } void DefaultDrive::Execute() { - m_drive->ArcadeDrive(m_forward(), m_rotation()); + drive->ArcadeDrive(forward(), rotation()); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp index d86e797bf83..9b32feb8845 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/DriveDistance.cpp @@ -8,23 +8,23 @@ DriveDistance::DriveDistance(double inches, double velocity, DriveSubsystem* subsystem) - : m_drive(subsystem), m_distance(inches), m_velocity(velocity) { + : drive(subsystem), distance(inches), velocity(velocity) { AddRequirements(subsystem); } void DriveDistance::Initialize() { - m_drive->ResetEncoders(); - m_drive->ArcadeDrive(m_velocity, 0); + drive->ResetEncoders(); + drive->ArcadeDrive(velocity, 0); } void DriveDistance::Execute() { - m_drive->ArcadeDrive(m_velocity, 0); + drive->ArcadeDrive(velocity, 0); } void DriveDistance::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); + drive->ArcadeDrive(0, 0); } bool DriveDistance::IsFinished() { - return std::abs(m_drive->GetAverageEncoderDistance()) >= m_distance; + return std::abs(drive->GetAverageEncoderDistance()) >= distance; } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp index 001229cc953..e6ebe5b3dd3 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/GrabHatch.cpp @@ -4,12 +4,12 @@ #include "commands/GrabHatch.hpp" -GrabHatch::GrabHatch(HatchSubsystem* subsystem) : m_hatch(subsystem) { +GrabHatch::GrabHatch(HatchSubsystem* subsystem) : hatch(subsystem) { AddRequirements(subsystem); } void GrabHatch::Initialize() { - m_hatch->GrabHatch(); + hatch->GrabHatch(); } bool GrabHatch::IsFinished() { diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveVelocity.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveVelocity.cpp index 4278ad5c9f6..6df4ff982c0 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveVelocity.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/HalveDriveVelocity.cpp @@ -5,12 +5,12 @@ #include "commands/HalveDriveVelocity.hpp" HalveDriveVelocity::HalveDriveVelocity(DriveSubsystem* subsystem) - : m_drive(subsystem) {} + : drive(subsystem) {} void HalveDriveVelocity::Initialize() { - m_drive->SetMaxOutput(0.5); + drive->SetMaxOutput(0.5); } void HalveDriveVelocity::End(bool interrupted) { - m_drive->SetMaxOutput(1); + drive->SetMaxOutput(1); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp index 4dbca0e7efd..c05ecf04ec1 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/commands/ReleaseHatch.cpp @@ -4,12 +4,12 @@ #include "commands/ReleaseHatch.hpp" -ReleaseHatch::ReleaseHatch(HatchSubsystem* subsystem) : m_hatch(subsystem) { +ReleaseHatch::ReleaseHatch(HatchSubsystem* subsystem) : hatch(subsystem) { AddRequirements(subsystem); } void ReleaseHatch::Initialize() { - m_hatch->ReleaseHatch(); + hatch->ReleaseHatch(); } bool ReleaseHatch::IsFinished() { diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp index 8bae9bdad2a..feaa942b87e 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/DriveSubsystem.cpp @@ -9,26 +9,26 @@ using namespace DriveConstants; DriveSubsystem::DriveSubsystem() - : m_left1{kLeftMotor1Port}, - m_left2{kLeftMotor2Port}, - m_right1{kRightMotor1Port}, - m_right2{kRightMotor2Port}, - m_leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]}, - m_rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_left1); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_right1); - - m_left1.AddFollower(m_left2); - m_right1.AddFollower(m_right2); + : left1{kLeftMotor1Port}, + left2{kLeftMotor2Port}, + right1{kRightMotor1Port}, + right2{kRightMotor2Port}, + leftEncoder{kLeftEncoderPorts[0], kLeftEncoderPorts[1]}, + rightEncoder{kRightEncoderPorts[0], kRightEncoderPorts[1]} { + wpi::util::SendableRegistry::AddChild(&drive, &left1); + wpi::util::SendableRegistry::AddChild(&drive, &right1); + + left1.AddFollower(left2); + right1.AddFollower(right2); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_right1.SetInverted(true); + right1.SetInverted(true); // Set the distance per pulse for the encoders - m_leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); - m_rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); + leftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); + rightEncoder.SetDistancePerPulse(kEncoderDistancePerPulse); } void DriveSubsystem::Periodic() { @@ -36,20 +36,20 @@ void DriveSubsystem::Periodic() { } void DriveSubsystem::ArcadeDrive(double fwd, double rot) { - m_drive.ArcadeDrive(fwd, rot); + drive.ArcadeDrive(fwd, rot); } void DriveSubsystem::ResetEncoders() { - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); } double DriveSubsystem::GetAverageEncoderDistance() { - return (m_leftEncoder.GetDistance() + m_rightEncoder.GetDistance()) / 2.0; + return (leftEncoder.GetDistance() + rightEncoder.GetDistance()) / 2.0; } void DriveSubsystem::SetMaxOutput(double maxOutput) { - m_drive.SetMaxOutput(maxOutput); + drive.SetMaxOutput(maxOutput); } void DriveSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { @@ -57,8 +57,7 @@ void DriveSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { // Publish encoder distances to telemetry. builder.AddDoubleProperty( - "leftDistance", [this] { return m_leftEncoder.GetDistance(); }, nullptr); + "leftDistance", [this] { return leftEncoder.GetDistance(); }, nullptr); builder.AddDoubleProperty( - "rightDistance", [this] { return m_rightEncoder.GetDistance(); }, - nullptr); + "rightDistance", [this] { return rightEncoder.GetDistance(); }, nullptr); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp index 1a3e6bc9863..3a4c02fc01a 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/subsystems/HatchSubsystem.cpp @@ -9,15 +9,15 @@ using namespace HatchConstants; HatchSubsystem::HatchSubsystem() - : m_hatchSolenoid{0, wpi::PneumaticsModuleType::CTRE_PCM, - kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {} + : hatchSolenoid{0, wpi::PneumaticsModuleType::CTRE_PCM, + kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {} void HatchSubsystem::GrabHatch() { - m_hatchSolenoid.Set(wpi::DoubleSolenoid::FORWARD); + hatchSolenoid.Set(wpi::DoubleSolenoid::FORWARD); } void HatchSubsystem::ReleaseHatch() { - m_hatchSolenoid.Set(wpi::DoubleSolenoid::REVERSE); + hatchSolenoid.Set(wpi::DoubleSolenoid::REVERSE); } void HatchSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { @@ -26,6 +26,6 @@ void HatchSubsystem::InitSendable(wpi::util::SendableBuilder& builder) { // Publish the solenoid state to telemetry. builder.AddBooleanProperty( "extended", - [this] { return m_hatchSolenoid.Get() == wpi::DoubleSolenoid::FORWARD; }, + [this] { return hatchSolenoid.Get() == wpi::DoubleSolenoid::FORWARD; }, nullptr); } diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.hpp index 377ae1bfc2f..c59dc48dc32 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/Robot.hpp @@ -23,7 +23,7 @@ class Robot : public wpi::TimedRobot { private: // Have it null by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - wpi::cmd::Command* m_autonomousCommand = nullptr; + wpi::cmd::Command* autonomousCommand = nullptr; - RobotContainer m_container; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.hpp index ff38bc36b9b..4a82e45432d 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/RobotContainer.hpp @@ -31,19 +31,19 @@ class RobotContainer { // The robot's subsystems and commands are defined here... // The robot's subsystems - DriveSubsystem m_drive; - HatchSubsystem m_hatch; + DriveSubsystem drive; + HatchSubsystem hatch; // The autonomous routines - DriveDistance m_simpleAuto{AutoConstants::kAutoDriveDistanceInches, - AutoConstants::kAutoDriveVelocity, &m_drive}; - ComplexAuto m_complexAuto{&m_drive, &m_hatch}; + DriveDistance simpleAuto{AutoConstants::kAutoDriveDistanceInches, + AutoConstants::kAutoDriveVelocity, &drive}; + ComplexAuto complexAuto{&drive, &hatch}; // The chooser for the autonomous routines - wpi::SendableChooser m_chooser; + wpi::SendableChooser chooser; // The driver's controller - wpi::Gamepad m_driverController{OIConstants::kDriverControllerPort}; + wpi::Gamepad driverController{OIConstants::kDriverControllerPort}; void ConfigureButtonBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.hpp index a45a1b2ce32..3c7ed8a9a0c 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DefaultDrive.hpp @@ -33,7 +33,7 @@ class DefaultDrive void Execute() override; private: - DriveSubsystem* m_drive; - std::function m_forward; - std::function m_rotation; + DriveSubsystem* drive; + std::function forward; + std::function rotation; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.hpp index 756f127138e..72138d7d837 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/DriveDistance.hpp @@ -29,7 +29,7 @@ class DriveDistance bool IsFinished() override; private: - DriveSubsystem* m_drive; - double m_distance; - double m_velocity; + DriveSubsystem* drive; + double distance; + double velocity; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.hpp index d01746d4989..87ba12ab0d2 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/GrabHatch.hpp @@ -24,5 +24,5 @@ class GrabHatch : public wpi::cmd::CommandHelper { bool IsFinished() override; private: - HatchSubsystem* m_hatch; + HatchSubsystem* hatch; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveVelocity.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveVelocity.hpp index 7440ba265d4..ab23156729c 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveVelocity.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/HalveDriveVelocity.hpp @@ -18,5 +18,5 @@ class HalveDriveVelocity void End(bool interrupted) override; private: - DriveSubsystem* m_drive; + DriveSubsystem* drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.hpp index f6e14c70e66..d5b4730bf37 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/commands/ReleaseHatch.hpp @@ -25,5 +25,5 @@ class ReleaseHatch bool IsFinished() override; private: - HatchSubsystem* m_hatch; + HatchSubsystem* hatch; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.hpp index 0367dd24090..f3c23f6ac38 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/DriveSubsystem.hpp @@ -56,19 +56,19 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase { // declared private and exposed only through public methods. // The motor controllers - wpi::PWMSparkMax m_left1; - wpi::PWMSparkMax m_left2; - wpi::PWMSparkMax m_right1; - wpi::PWMSparkMax m_right2; + wpi::PWMSparkMax left1; + wpi::PWMSparkMax left2; + wpi::PWMSparkMax right1; + wpi::PWMSparkMax right2; // The robot's drive - wpi::DifferentialDrive m_drive{ - [&](double output) { m_left1.SetThrottle(output); }, - [&](double output) { m_right1.SetThrottle(output); }}; + wpi::DifferentialDrive drive{ + [&](double output) { left1.SetThrottle(output); }, + [&](double output) { right1.SetThrottle(output); }}; // The left-side drive encoder - wpi::Encoder m_leftEncoder; + wpi::Encoder leftEncoder; // The right-side drive encoder - wpi::Encoder m_rightEncoder; + wpi::Encoder rightEncoder; }; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.hpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.hpp index 7560a28c81a..0908b1162f4 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.hpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/include/subsystems/HatchSubsystem.hpp @@ -30,5 +30,5 @@ class HatchSubsystem : public wpi::cmd::SubsystemBase { private: // Components (e.g. motor controllers and sensors) should generally be // declared private and exposed only through public methods. - wpi::DoubleSolenoid m_hatchSolenoid; + wpi::DoubleSolenoid hatchSolenoid; }; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp index 76d35011da6..2d7b6daaf11 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Drivetrain.cpp @@ -8,48 +8,48 @@ wpi::math::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const { - return {wpi::units::meter_t{m_frontLeftEncoder.GetDistance()}, - wpi::units::meter_t{m_frontRightEncoder.GetDistance()}, - wpi::units::meter_t{m_backLeftEncoder.GetDistance()}, - wpi::units::meter_t{m_backRightEncoder.GetDistance()}}; + return {wpi::units::meter_t{frontLeftEncoder.GetDistance()}, + wpi::units::meter_t{frontRightEncoder.GetDistance()}, + wpi::units::meter_t{backLeftEncoder.GetDistance()}, + wpi::units::meter_t{backRightEncoder.GetDistance()}}; } wpi::math::MecanumDriveWheelVelocities Drivetrain::GetCurrentWheelVelocities() const { - return {wpi::units::meters_per_second_t{m_frontLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{m_frontRightEncoder.GetRate()}, - wpi::units::meters_per_second_t{m_backLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{m_backRightEncoder.GetRate()}}; + return {wpi::units::meters_per_second_t{frontLeftEncoder.GetRate()}, + wpi::units::meters_per_second_t{frontRightEncoder.GetRate()}, + wpi::units::meters_per_second_t{backLeftEncoder.GetRate()}, + wpi::units::meters_per_second_t{backRightEncoder.GetRate()}}; } void Drivetrain::SetVelocities( const wpi::math::MecanumDriveWheelVelocities& wheelVelocities) { const auto frontLeftFeedforward = - m_feedforward.Calculate(wheelVelocities.frontLeft); + feedforward.Calculate(wheelVelocities.frontLeft); const auto frontRightFeedforward = - m_feedforward.Calculate(wheelVelocities.frontRight); + feedforward.Calculate(wheelVelocities.frontRight); const auto backLeftFeedforward = - m_feedforward.Calculate(wheelVelocities.rearLeft); + feedforward.Calculate(wheelVelocities.rearLeft); const auto backRightFeedforward = - m_feedforward.Calculate(wheelVelocities.rearRight); + feedforward.Calculate(wheelVelocities.rearRight); - const double frontLeftOutput = m_frontLeftPIDController.Calculate( - m_frontLeftEncoder.GetRate(), wheelVelocities.frontLeft.value()); - const double frontRightOutput = m_frontRightPIDController.Calculate( - m_frontRightEncoder.GetRate(), wheelVelocities.frontRight.value()); - const double backLeftOutput = m_backLeftPIDController.Calculate( - m_backLeftEncoder.GetRate(), wheelVelocities.rearLeft.value()); - const double backRightOutput = m_backRightPIDController.Calculate( - m_backRightEncoder.GetRate(), wheelVelocities.rearRight.value()); + const double frontLeftOutput = frontLeftPIDController.Calculate( + frontLeftEncoder.GetRate(), wheelVelocities.frontLeft.value()); + const double frontRightOutput = frontRightPIDController.Calculate( + frontRightEncoder.GetRate(), wheelVelocities.frontRight.value()); + const double backLeftOutput = backLeftPIDController.Calculate( + backLeftEncoder.GetRate(), wheelVelocities.rearLeft.value()); + const double backRightOutput = backRightPIDController.Calculate( + backRightEncoder.GetRate(), wheelVelocities.rearRight.value()); - m_frontLeftMotor.SetVoltage(wpi::units::volt_t{frontLeftOutput} + - frontLeftFeedforward); - m_frontRightMotor.SetVoltage(wpi::units::volt_t{frontRightOutput} + - frontRightFeedforward); - m_backLeftMotor.SetVoltage(wpi::units::volt_t{backLeftOutput} + - backLeftFeedforward); - m_backRightMotor.SetVoltage(wpi::units::volt_t{backRightOutput} + - backRightFeedforward); + frontLeftMotor.SetVoltage(wpi::units::volt_t{frontLeftOutput} + + frontLeftFeedforward); + frontRightMotor.SetVoltage(wpi::units::volt_t{frontRightOutput} + + frontRightFeedforward); + backLeftMotor.SetVoltage(wpi::units::volt_t{backLeftOutput} + + backLeftFeedforward); + backRightMotor.SetVoltage(wpi::units::volt_t{backRightOutput} + + backRightFeedforward); } void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, @@ -58,14 +58,13 @@ void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::second_t period) { wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { - chassisVelocities = - chassisVelocities.ToRobotRelative(m_imu.GetRotation2d()); + chassisVelocities = chassisVelocities.ToRobotRelative(imu.GetRotation2d()); } SetVelocities( - m_kinematics.ToWheelVelocities(chassisVelocities.Discretize(period)) + kinematics.ToWheelVelocities(chassisVelocities.Discretize(period)) .Desaturate(kMaxVelocity)); } void Drivetrain::UpdateOdometry() { - m_odometry.Update(m_imu.GetRotation2d(), GetCurrentWheelDistances()); + odometry.Update(imu.GetRotation2d(), GetCurrentWheelDistances()); } diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp index 34bde68ea8d..fd0d5cf8ed1 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/cpp/Robot.cpp @@ -11,43 +11,41 @@ class Robot : public wpi::TimedRobot { public: void AutonomousPeriodic() override { DriveWithJoystick(false); - m_mecanum.UpdateOdometry(); + mecanum.UpdateOdometry(); } void TeleopPeriodic() override { DriveWithJoystick(true); } private: - wpi::Gamepad m_controller{0}; - Drivetrain m_mecanum; + wpi::Gamepad controller{0}; + Drivetrain mecanum; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - const auto xVelocity = - -m_xVelocityLimiter.Calculate(m_controller.GetLeftY()) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -xVelocityLimiter.Calculate(controller.GetLeftY()) * + Drivetrain::kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this // because we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. - const auto yVelocity = - -m_yVelocityLimiter.Calculate(m_controller.GetLeftX()) * - Drivetrain::kMaxVelocity; + const auto yVelocity = -yVelocityLimiter.Calculate(controller.GetLeftX()) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * + const auto rot = -rotLimiter.Calculate(controller.GetRightX()) * Drivetrain::kMaxAngularVelocity; - m_mecanum.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); + mecanum.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp index dc18c7e4e48..601e6213d7a 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumBot/include/Drivetrain.hpp @@ -22,12 +22,12 @@ class Drivetrain { public: Drivetrain() { - m_imu.ResetYaw(); + imu.ResetYaw(); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_frontRightMotor.SetInverted(true); - m_backRightMotor.SetInverted(true); + frontRightMotor.SetInverted(true); + backRightMotor.SetInverted(true); } wpi::math::MecanumDriveWheelPositions GetCurrentWheelDistances() const; @@ -46,37 +46,37 @@ class Drivetrain { std::numbers::pi}; // 1/2 rotation per second private: - wpi::PWMSparkMax m_frontLeftMotor{1}; - wpi::PWMSparkMax m_frontRightMotor{2}; - wpi::PWMSparkMax m_backLeftMotor{3}; - wpi::PWMSparkMax m_backRightMotor{4}; + wpi::PWMSparkMax frontLeftMotor{1}; + wpi::PWMSparkMax frontRightMotor{2}; + wpi::PWMSparkMax backLeftMotor{3}; + wpi::PWMSparkMax backRightMotor{4}; - wpi::Encoder m_frontLeftEncoder{0, 1}; - wpi::Encoder m_frontRightEncoder{2, 3}; - wpi::Encoder m_backLeftEncoder{4, 5}; - wpi::Encoder m_backRightEncoder{6, 7}; + wpi::Encoder frontLeftEncoder{0, 1}; + wpi::Encoder frontRightEncoder{2, 3}; + wpi::Encoder backLeftEncoder{4, 5}; + wpi::Encoder backRightEncoder{6, 7}; - wpi::math::Translation2d m_frontLeftLocation{0.381_m, 0.381_m}; - wpi::math::Translation2d m_frontRightLocation{0.381_m, -0.381_m}; - wpi::math::Translation2d m_backLeftLocation{-0.381_m, 0.381_m}; - wpi::math::Translation2d m_backRightLocation{-0.381_m, -0.381_m}; + wpi::math::Translation2d frontLeftLocation{0.381_m, 0.381_m}; + wpi::math::Translation2d frontRightLocation{0.381_m, -0.381_m}; + wpi::math::Translation2d backLeftLocation{-0.381_m, 0.381_m}; + wpi::math::Translation2d backRightLocation{-0.381_m, -0.381_m}; - wpi::math::PIDController m_frontLeftPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_frontRightPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_backLeftPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_backRightPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController frontLeftPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController frontRightPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController backLeftPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController backRightPIDController{1.0, 0.0, 0.0}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::MecanumDriveKinematics m_kinematics{ - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, - m_backRightLocation}; + wpi::math::MecanumDriveKinematics kinematics{ + frontLeftLocation, frontRightLocation, backLeftLocation, + backRightLocation}; - wpi::math::MecanumDriveOdometry m_odometry{ - m_kinematics, m_imu.GetRotation2d(), GetCurrentWheelDistances()}; + wpi::math::MecanumDriveOdometry odometry{kinematics, imu.GetRotation2d(), + GetCurrentWheelDistances()}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp index 5bc01edabf9..8b52aba0751 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrive/cpp/Robot.cpp @@ -16,15 +16,15 @@ class Robot : public wpi::TimedRobot { public: Robot() { - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_frontLeft); - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_rearLeft); - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_frontRight); - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_rearRight); + wpi::util::SendableRegistry::AddChild(&robotDrive, &frontLeft); + wpi::util::SendableRegistry::AddChild(&robotDrive, &rearLeft); + wpi::util::SendableRegistry::AddChild(&robotDrive, &frontRight); + wpi::util::SendableRegistry::AddChild(&robotDrive, &rearRight); // Invert the right side motors. You may need to change or remove this to // match your robot. - m_frontRight.SetInverted(true); - m_rearRight.SetInverted(true); + frontRight.SetInverted(true); + rearRight.SetInverted(true); } /** @@ -34,8 +34,8 @@ class Robot : public wpi::TimedRobot { /* Use the joystick Y axis for forward movement, X axis for lateral * movement, and Z axis for rotation. */ - m_robotDrive.DriveCartesian(-m_joystick.GetY(), -m_joystick.GetX(), - -m_joystick.GetZ(), m_imu.GetRotation2d()); + robotDrive.DriveCartesian(-joystick.GetY(), -joystick.GetX(), + -joystick.GetZ(), imu.GetRotation2d()); } private: @@ -47,18 +47,18 @@ class Robot : public wpi::TimedRobot { wpi::OnboardIMU::FLAT; static constexpr int kJoystickPort = 0; - wpi::PWMSparkMax m_frontLeft{kFrontLeftMotorPort}; - wpi::PWMSparkMax m_rearLeft{kRearLeftMotorPort}; - wpi::PWMSparkMax m_frontRight{kFrontRightMotorPort}; - wpi::PWMSparkMax m_rearRight{kRearRightMotorPort}; - wpi::MecanumDrive m_robotDrive{ - [&](double output) { m_frontLeft.SetThrottle(output); }, - [&](double output) { m_rearLeft.SetThrottle(output); }, - [&](double output) { m_frontRight.SetThrottle(output); }, - [&](double output) { m_rearRight.SetThrottle(output); }}; + wpi::PWMSparkMax frontLeft{kFrontLeftMotorPort}; + wpi::PWMSparkMax rearLeft{kRearLeftMotorPort}; + wpi::PWMSparkMax frontRight{kFrontRightMotorPort}; + wpi::PWMSparkMax rearRight{kRearRightMotorPort}; + wpi::MecanumDrive robotDrive{ + [&](double output) { frontLeft.SetThrottle(output); }, + [&](double output) { rearLeft.SetThrottle(output); }, + [&](double output) { frontRight.SetThrottle(output); }, + [&](double output) { rearRight.SetThrottle(output); }}; - wpi::OnboardIMU m_imu{kIMUMountOrientation}; - wpi::Joystick m_joystick{kJoystickPort}; + wpi::OnboardIMU imu{kIMUMountOrientation}; + wpi::Joystick joystick{kJoystickPort}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp index 70019bc7940..86f8ce08e4d 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Drivetrain.cpp @@ -9,42 +9,42 @@ wpi::math::MecanumDriveWheelPositions Drivetrain::GetCurrentWheelDistances() const { - return {wpi::units::meter_t{m_frontLeftEncoder.GetDistance()}, - wpi::units::meter_t{m_frontRightEncoder.GetDistance()}, - wpi::units::meter_t{m_backLeftEncoder.GetDistance()}, - wpi::units::meter_t{m_backRightEncoder.GetDistance()}}; + return {wpi::units::meter_t{frontLeftEncoder.GetDistance()}, + wpi::units::meter_t{frontRightEncoder.GetDistance()}, + wpi::units::meter_t{backLeftEncoder.GetDistance()}, + wpi::units::meter_t{backRightEncoder.GetDistance()}}; } wpi::math::MecanumDriveWheelVelocities Drivetrain::GetCurrentWheelVelocities() const { - return {wpi::units::meters_per_second_t{m_frontLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{m_frontRightEncoder.GetRate()}, - wpi::units::meters_per_second_t{m_backLeftEncoder.GetRate()}, - wpi::units::meters_per_second_t{m_backRightEncoder.GetRate()}}; + return {wpi::units::meters_per_second_t{frontLeftEncoder.GetRate()}, + wpi::units::meters_per_second_t{frontRightEncoder.GetRate()}, + wpi::units::meters_per_second_t{backLeftEncoder.GetRate()}, + wpi::units::meters_per_second_t{backRightEncoder.GetRate()}}; } void Drivetrain::SetVelocities( const wpi::math::MecanumDriveWheelVelocities& wheelVelocities) { std::function - calcAndSetVelocities = [&m_feedforward = m_feedforward]( - wpi::units::meters_per_second_t velocity, - const auto& encoder, auto& controller, - auto& motor) { - auto feedforward = m_feedforward.Calculate(velocity); - double output = - controller.Calculate(encoder.GetRate(), velocity.value()); - motor.SetVoltage(wpi::units::volt_t{output} + feedforward); - }; + calcAndSetVelocities = + [&feedforward = feedforward](wpi::units::meters_per_second_t velocity, + const auto& encoder, auto& controller, + auto& motor) { + auto ff = feedforward.Calculate(velocity); + double output = + controller.Calculate(encoder.GetRate(), velocity.value()); + motor.SetVoltage(wpi::units::volt_t{output} + ff); + }; - calcAndSetVelocities(wheelVelocities.frontLeft, m_frontLeftEncoder, - m_frontLeftPIDController, m_frontLeftMotor); - calcAndSetVelocities(wheelVelocities.frontRight, m_frontRightEncoder, - m_frontRightPIDController, m_frontRightMotor); - calcAndSetVelocities(wheelVelocities.rearLeft, m_backLeftEncoder, - m_backLeftPIDController, m_backLeftMotor); - calcAndSetVelocities(wheelVelocities.rearRight, m_backRightEncoder, - m_backRightPIDController, m_backRightMotor); + calcAndSetVelocities(wheelVelocities.frontLeft, frontLeftEncoder, + frontLeftPIDController, frontLeftMotor); + calcAndSetVelocities(wheelVelocities.frontRight, frontRightEncoder, + frontRightPIDController, frontRightMotor); + calcAndSetVelocities(wheelVelocities.rearLeft, backLeftEncoder, + backLeftPIDController, backLeftMotor); + calcAndSetVelocities(wheelVelocities.rearRight, backRightEncoder, + backRightPIDController, backRightMotor); } void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, @@ -54,23 +54,23 @@ void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { chassisVelocities = chassisVelocities.ToRobotRelative( - m_poseEstimator.GetEstimatedPosition().Rotation()); + poseEstimator.GetEstimatedPosition().Rotation()); } SetVelocities( - m_kinematics.ToWheelVelocities(chassisVelocities.Discretize(period)) + kinematics.ToWheelVelocities(chassisVelocities.Discretize(period)) .Desaturate(kMaxVelocity)); } void Drivetrain::UpdateOdometry() { - m_poseEstimator.Update( - m_imu.GetRotation2d(), + poseEstimator.Update( + imu.GetRotation2d(), GetCurrentWheelDistances()); // TODO(Ryan): fixup when sim implemented // Also apply vision measurements. We use 0.3 seconds in the past as an // example -- on a real robot, this must be calculated based either on latency // or timestamps. - m_poseEstimator.AddVisionMeasurement( + poseEstimator.AddVisionMeasurement( ExampleGlobalMeasurementSensor::GetEstimatedGlobalPose( - m_poseEstimator.GetEstimatedPosition()), + poseEstimator.GetEstimatedPosition()), wpi::Timer::GetTimestamp() - 0.3_s); } diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp index 34bde68ea8d..fd0d5cf8ed1 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/cpp/Robot.cpp @@ -11,43 +11,41 @@ class Robot : public wpi::TimedRobot { public: void AutonomousPeriodic() override { DriveWithJoystick(false); - m_mecanum.UpdateOdometry(); + mecanum.UpdateOdometry(); } void TeleopPeriodic() override { DriveWithJoystick(true); } private: - wpi::Gamepad m_controller{0}; - Drivetrain m_mecanum; + wpi::Gamepad controller{0}; + Drivetrain mecanum; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - const auto xVelocity = - -m_xVelocityLimiter.Calculate(m_controller.GetLeftY()) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -xVelocityLimiter.Calculate(controller.GetLeftY()) * + Drivetrain::kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this // because we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. - const auto yVelocity = - -m_yVelocityLimiter.Calculate(m_controller.GetLeftX()) * - Drivetrain::kMaxVelocity; + const auto yVelocity = -yVelocityLimiter.Calculate(controller.GetLeftX()) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * + const auto rot = -rotLimiter.Calculate(controller.GetRightX()) * Drivetrain::kMaxAngularVelocity; - m_mecanum.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); + mecanum.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp index 8715083f16f..dee0009cd5b 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumDrivePoseEstimator/include/Drivetrain.hpp @@ -22,12 +22,12 @@ class Drivetrain { public: Drivetrain() { - m_imu.ResetYaw(); + imu.ResetYaw(); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_frontRightMotor.SetInverted(true); - m_backRightMotor.SetInverted(true); + frontRightMotor.SetInverted(true); + backRightMotor.SetInverted(true); } wpi::math::MecanumDriveWheelPositions GetCurrentWheelDistances() const; @@ -45,40 +45,40 @@ class Drivetrain { std::numbers::pi}; // 1/2 rotation per second private: - wpi::PWMSparkMax m_frontLeftMotor{1}; - wpi::PWMSparkMax m_frontRightMotor{2}; - wpi::PWMSparkMax m_backLeftMotor{3}; - wpi::PWMSparkMax m_backRightMotor{4}; + wpi::PWMSparkMax frontLeftMotor{1}; + wpi::PWMSparkMax frontRightMotor{2}; + wpi::PWMSparkMax backLeftMotor{3}; + wpi::PWMSparkMax backRightMotor{4}; - wpi::Encoder m_frontLeftEncoder{0, 1}; - wpi::Encoder m_frontRightEncoder{2, 3}; - wpi::Encoder m_backLeftEncoder{4, 5}; - wpi::Encoder m_backRightEncoder{6, 7}; + wpi::Encoder frontLeftEncoder{0, 1}; + wpi::Encoder frontRightEncoder{2, 3}; + wpi::Encoder backLeftEncoder{4, 5}; + wpi::Encoder backRightEncoder{6, 7}; - wpi::math::Translation2d m_frontLeftLocation{0.381_m, 0.381_m}; - wpi::math::Translation2d m_frontRightLocation{0.381_m, -0.381_m}; - wpi::math::Translation2d m_backLeftLocation{-0.381_m, 0.381_m}; - wpi::math::Translation2d m_backRightLocation{-0.381_m, -0.381_m}; + wpi::math::Translation2d frontLeftLocation{0.381_m, 0.381_m}; + wpi::math::Translation2d frontRightLocation{0.381_m, -0.381_m}; + wpi::math::Translation2d backLeftLocation{-0.381_m, 0.381_m}; + wpi::math::Translation2d backRightLocation{-0.381_m, -0.381_m}; - wpi::math::PIDController m_frontLeftPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_frontRightPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_backLeftPIDController{1.0, 0.0, 0.0}; - wpi::math::PIDController m_backRightPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController frontLeftPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController frontRightPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController backLeftPIDController{1.0, 0.0, 0.0}; + wpi::math::PIDController backRightPIDController{1.0, 0.0, 0.0}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::MecanumDriveKinematics m_kinematics{ - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, - m_backRightLocation}; + wpi::math::MecanumDriveKinematics kinematics{ + frontLeftLocation, frontRightLocation, backLeftLocation, + backRightLocation}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::MecanumDrivePoseEstimator m_poseEstimator{ - m_kinematics, m_imu.GetRotation2d(), GetCurrentWheelDistances(), - wpi::math::Pose2d{}, {0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}}; + wpi::math::MecanumDrivePoseEstimator poseEstimator{ + kinematics, imu.GetRotation2d(), GetCurrentWheelDistances(), + wpi::math::Pose2d{}, {0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp index 2d965a1dd58..39fc5715a23 100644 --- a/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Mechanism2d/cpp/Robot.cpp @@ -30,43 +30,40 @@ class Robot : public wpi::TimedRobot { public: Robot() { - m_elevatorEncoder.SetDistancePerPulse(kMetersPerPulse); + elevatorEncoder.SetDistancePerPulse(kMetersPerPulse); // publish to dashboard - wpi::SmartDashboard::PutData("Mech2d", &m_mech); + wpi::SmartDashboard::PutData("Mech2d", &mech); } void RobotPeriodic() override { // update the dashboard mechanism's state - m_elevator->SetLength(kElevatorMinimumLength + - m_elevatorEncoder.GetDistance()); - m_wrist->SetAngle(wpi::units::degree_t{m_wristPotentiometer.Get()}); + elevator->SetLength(kElevatorMinimumLength + elevatorEncoder.GetDistance()); + wrist->SetAngle(wpi::units::degree_t{wristPotentiometer.Get()}); } void TeleopPeriodic() override { - m_elevatorMotor.SetThrottle(m_joystick.GetRawAxis(0)); - m_wristMotor.SetThrottle(m_joystick.GetRawAxis(1)); + elevatorMotor.SetThrottle(joystick.GetRawAxis(0)); + wristMotor.SetThrottle(joystick.GetRawAxis(1)); } private: - wpi::PWMSparkMax m_elevatorMotor{0}; - wpi::PWMSparkMax m_wristMotor{1}; - wpi::Encoder m_elevatorEncoder{0, 1}; - wpi::AnalogPotentiometer m_wristPotentiometer{1, 90}; - wpi::Joystick m_joystick{0}; + wpi::PWMSparkMax elevatorMotor{0}; + wpi::PWMSparkMax wristMotor{1}; + wpi::Encoder elevatorEncoder{0, 1}; + wpi::AnalogPotentiometer wristPotentiometer{1, 90}; + wpi::Joystick joystick{0}; // the main mechanism object - wpi::Mechanism2d m_mech{3, 3}; + wpi::Mechanism2d mech{3, 3}; // the mechanism root node - wpi::MechanismRoot2d* m_root = m_mech.GetRoot("climber", 2, 0); + wpi::MechanismRoot2d* root = mech.GetRoot("climber", 2, 0); // MechanismLigament2d objects represent each "section"/"stage" of the // mechanism, and are based off the root node or another ligament object - wpi::MechanismLigament2d* m_elevator = - m_root->Append("elevator", 1, 90_deg); - wpi::MechanismLigament2d* m_wrist = - m_elevator->Append( - "wrist", 0.5, 90_deg, 6, - wpi::util::Color8Bit{wpi::util::Color::PURPLE}); + wpi::MechanismLigament2d* elevator = + root->Append("elevator", 1, 90_deg); + wpi::MechanismLigament2d* wrist = elevator->Append( + "wrist", 0.5, 90_deg, 6, wpi::util::Color8Bit{wpi::util::Color::PURPLE}); }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp index 371179f7fd2..e3272a9e1e8 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/RapidReactCommandBot.cpp @@ -13,37 +13,35 @@ void RapidReactCommandBot::ConfigureBindings() { // Automatically run the storage motor whenever the ball storage is not full, // and turn it off whenever it fills. Uses subsystem-hosted trigger to // improve readability and make inter-subsystem communication easier. - m_storage.HasCargo.WhileFalse(m_storage.RunCommand()); + storage.HasCargo.WhileFalse(storage.RunCommand()); // Automatically disable and retract the intake whenever the ball storage is // full. - m_storage.HasCargo.OnTrue(m_intake.RetractCommand()); + storage.HasCargo.OnTrue(intake.RetractCommand()); // Control the drive with split-stick arcade controls - m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand( - [this] { return -m_driverController.GetLeftY(); }, - [this] { return -m_driverController.GetRightX(); })); + drive.SetDefaultCommand(drive.ArcadeDriveCommand( + [this] { return -driverController.GetLeftY(); }, + [this] { return -driverController.GetRightX(); })); // Deploy the intake with the West Face button - m_driverController.WestFace().OnTrue(m_intake.IntakeCommand()); + driverController.WestFace().OnTrue(intake.IntakeCommand()); // Retract the intake with the North Face button - m_driverController.NorthFace().OnTrue(m_intake.RetractCommand()); + driverController.NorthFace().OnTrue(intake.RetractCommand()); // Fire the shooter with the South Face button - m_driverController.SouthFace().OnTrue( - wpi::cmd::Parallel( - m_shooter.ShootCommand(ShooterConstants::kShooterTarget), - m_storage.RunCommand()) + driverController.SouthFace().OnTrue( + wpi::cmd::Parallel(shooter.ShootCommand(ShooterConstants::kShooterTarget), + storage.RunCommand()) // Since we composed this inline we should give it a name .WithName("Shoot")); // Toggle compressor with the Start button - m_driverController.Start().ToggleOnTrue( - m_pneumatics.DisableCompressorCommand()); + driverController.Start().ToggleOnTrue(pneumatics.DisableCompressorCommand()); } wpi::cmd::CommandPtr RapidReactCommandBot::GetAutonomousCommand() { - return m_drive + return drive .DriveDistanceCommand(AutoConstants::kDriveDistance, AutoConstants::kDriveVelocity) .WithTimeout(AutoConstants::kTimeout); diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp index ef39cfe6dd7..c86a0f0cb21 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp @@ -6,7 +6,7 @@ Robot::Robot() { // Configure default commands and condition bindings on robot startup - m_robot.ConfigureBindings(); + robot.ConfigureBindings(); } void Robot::RobotPeriodic() { @@ -23,11 +23,11 @@ void Robot::DisabledInit() {} void Robot::DisabledPeriodic() {} void Robot::AutonomousInit() { - m_autonomousCommand = m_robot.GetAutonomousCommand(); + autonomousCommand = robot.GetAutonomousCommand(); - if (m_autonomousCommand) { + if (autonomousCommand) { wpi::cmd::CommandScheduler::GetInstance().Schedule( - m_autonomousCommand.value()); + autonomousCommand.value()); } } @@ -38,8 +38,8 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand) { - m_autonomousCommand->Cancel(); + if (autonomousCommand) { + autonomousCommand->Cancel(); } } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp index c5104a5ce33..ebc86448453 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Drive.cpp @@ -10,34 +10,34 @@ #include "wpi/system/RobotController.hpp" Drive::Drive() { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_leftLeader); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_rightLeader); + wpi::util::SendableRegistry::AddChild(&drive, &leftLeader); + wpi::util::SendableRegistry::AddChild(&drive, &rightLeader); - m_leftLeader.AddFollower(m_leftFollower); - m_rightLeader.AddFollower(m_rightFollower); + leftLeader.AddFollower(leftFollower); + rightLeader.AddFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.SetInverted(true); + rightLeader.SetInverted(true); // Sets the distance per pulse for the encoders - m_leftEncoder.SetDistancePerPulse(DriveConstants::kEncoderDistancePerPulse); - m_rightEncoder.SetDistancePerPulse(DriveConstants::kEncoderDistancePerPulse); + leftEncoder.SetDistancePerPulse(DriveConstants::kEncoderDistancePerPulse); + rightEncoder.SetDistancePerPulse(DriveConstants::kEncoderDistancePerPulse); // Set the controller to be continuous (because it is an angle controller) - m_controller.EnableContinuousInput(-180_deg, 180_deg); + controller.EnableContinuousInput(-180_deg, 180_deg); // Set the controller tolerance - the delta tolerance ensures the robot is // stationary at the setpoint before it is considered as having reached the // reference - m_controller.SetTolerance(DriveConstants::kTurnTolerance, - DriveConstants::kTurnRateTolerance); + controller.SetTolerance(DriveConstants::kTurnTolerance, + DriveConstants::kTurnRateTolerance); } wpi::cmd::CommandPtr Drive::ArcadeDriveCommand(std::function fwd, std::function rot) { return Run([this, fwd = std::move(fwd), rot = std::move(rot)] { - m_drive.ArcadeDrive(fwd(), rot()); + drive.ArcadeDrive(fwd(), rot()); }) .WithName("ArcadeDrive"); } @@ -46,34 +46,32 @@ wpi::cmd::CommandPtr Drive::DriveDistanceCommand(wpi::units::meter_t distance, double velocity) { return RunOnce([this] { // Reset encoders at the start of the command - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); }) // Drive forward at specified velocity - .AndThen(Run([this, velocity] { m_drive.ArcadeDrive(velocity, 0.0); })) + .AndThen(Run([this, velocity] { drive.ArcadeDrive(velocity, 0.0); })) .Until([this, distance] { return wpi::units::math::max( - wpi::units::meter_t(m_leftEncoder.GetDistance()), - wpi::units::meter_t(m_rightEncoder.GetDistance())) >= - distance; + wpi::units::meter_t(leftEncoder.GetDistance()), + wpi::units::meter_t(rightEncoder.GetDistance())) >= distance; }) // Stop the drive when the command ends - .FinallyDo([this](bool interrupted) { m_drive.StopMotor(); }); + .FinallyDo([this](bool interrupted) { drive.StopMotor(); }); } wpi::cmd::CommandPtr Drive::TurnToAngleCommand(wpi::units::degree_t angle) { - return StartRun( - [this] { m_controller.Reset(m_imu.GetRotation2d().Degrees()); }, - [this, angle] { - m_drive.ArcadeDrive( - 0, m_controller.Calculate(m_imu.GetRotation2d().Degrees(), - angle) + - // Divide feedforward voltage by battery voltage to - // normalize it to [-1, 1] - m_feedforward.Calculate( - m_controller.GetSetpoint().velocity) / - wpi::RobotController::GetBatteryVoltage()); - }) - .Until([this] { return m_controller.AtGoal(); }) - .FinallyDo([this] { m_drive.ArcadeDrive(0, 0); }); + return StartRun([this] { controller.Reset(imu.GetRotation2d().Degrees()); }, + [this, angle] { + drive.ArcadeDrive( + 0, controller.Calculate(imu.GetRotation2d().Degrees(), + angle) + + // Divide feedforward voltage by battery voltage + // to normalize it to [-1, 1] + feedforward.Calculate( + controller.GetSetpoint().velocity) / + wpi::RobotController::GetBatteryVoltage()); + }) + .Until([this] { return controller.AtGoal(); }) + .FinallyDo([this] { drive.ArcadeDrive(0, 0); }); } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp index bf6e51f9044..1246a1883c3 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Intake.cpp @@ -5,15 +5,15 @@ #include "subsystems/Intake.hpp" wpi::cmd::CommandPtr Intake::IntakeCommand() { - return RunOnce([this] { m_piston.Set(wpi::DoubleSolenoid::FORWARD); }) - .AndThen(Run([this] { m_motor.SetThrottle(1.0); })) + return RunOnce([this] { piston.Set(wpi::DoubleSolenoid::FORWARD); }) + .AndThen(Run([this] { motor.SetThrottle(1.0); })) .WithName("Intake"); } wpi::cmd::CommandPtr Intake::RetractCommand() { return RunOnce([this] { - m_motor.Disable(); - m_piston.Set(wpi::DoubleSolenoid::REVERSE); + motor.Disable(); + piston.Set(wpi::DoubleSolenoid::REVERSE); }) .WithName("Retract"); } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp index ddd3ac76bee..a9bd132f0e6 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Pneumatics.cpp @@ -10,18 +10,18 @@ wpi::cmd::CommandPtr Pneumatics::DisableCompressorCommand() { return StartEnd( [&] { // Disable closed-loop mode on the compressor. - m_compressor.Disable(); + compressor.Disable(); }, [&] { // Enable closed-loop mode based on the digital pressure switch // connected to the PCM/PH. The switch is open when the pressure is over // ~120 PSI. - m_compressor.EnableDigital(); + compressor.EnableDigital(); }); } wpi::units::pounds_per_square_inch_t Pneumatics::GetPressure() { // Get the pressure (in PSI) from an analog pressure sensor connected to // the RIO. - return wpi::units::pounds_per_square_inch_t{m_pressureTransducer.Get()}; + return wpi::units::pounds_per_square_inch_t{pressureTransducer.Get()}; } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp index 0373c6b59da..3f011971fdb 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Shooter.cpp @@ -7,13 +7,13 @@ #include "wpi/commands2/Commands.hpp" Shooter::Shooter() { - m_shooterFeedback.SetTolerance(ShooterConstants::kShooterTolerance.value()); - m_shooterEncoder.SetDistancePerPulse( + shooterFeedback.SetTolerance(ShooterConstants::kShooterTolerance.value()); + shooterEncoder.SetDistancePerPulse( ShooterConstants::kEncoderDistancePerPulse); SetDefaultCommand(RunOnce([this] { - m_shooterMotor.Disable(); - m_feederMotor.Disable(); + shooterMotor.Disable(); + feederMotor.Disable(); }) .AndThen(Run([] {})) .WithName("Idle")); @@ -25,15 +25,15 @@ wpi::cmd::CommandPtr Shooter::ShootCommand( // Run the shooter flywheel at the desired setpoint using // feedforward and feedback Run([this, setpoint] { - m_shooterMotor.SetVoltage( - m_shooterFeedforward.Calculate(setpoint) + - wpi::units::volt_t(m_shooterFeedback.Calculate( - m_shooterEncoder.GetRate(), setpoint.value()))); + shooterMotor.SetVoltage( + shooterFeedforward.Calculate(setpoint) + + wpi::units::volt_t(shooterFeedback.Calculate( + shooterEncoder.GetRate(), setpoint.value()))); }), // Wait until the shooter has reached the setpoint, and then // run the feeder wpi::cmd::WaitUntil([this] { - return m_shooterFeedback.AtSetpoint(); - }).AndThen([this] { m_feederMotor.SetThrottle(1.0); })) + return shooterFeedback.AtSetpoint(); + }).AndThen([this] { feederMotor.SetThrottle(1.0); })) .WithName("Shoot"); } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp index 6ff8553290a..eb56bcf51d6 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/subsystems/Storage.cpp @@ -6,9 +6,9 @@ Storage::Storage() { SetDefaultCommand( - RunOnce([this] { m_motor.Disable(); }).AndThen([] {}).WithName("Idle")); + RunOnce([this] { motor.Disable(); }).AndThen([] {}).WithName("Idle")); } wpi::cmd::CommandPtr Storage::RunCommand() { - return Run([this] { m_motor.SetThrottle(1.0); }).WithName("Run"); + return Run([this] { motor.SetThrottle(1.0); }).WithName("Run"); } diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.hpp index c8aa9ad9ff3..e60b4413ac8 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/RapidReactCommandBot.hpp @@ -41,13 +41,12 @@ class RapidReactCommandBot { private: // The robot's subsystems - Drive m_drive; - Intake m_intake; - Shooter m_shooter; - Storage m_storage; - Pneumatics m_pneumatics; + Drive drive; + Intake intake; + Shooter shooter; + Storage storage; + Pneumatics pneumatics; // The driver's controller - wpi::cmd::CommandGamepad m_driverController{ - OIConstants::kDriverControllerPort}; + wpi::cmd::CommandGamepad driverController{OIConstants::kDriverControllerPort}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.hpp index 151282ce6fd..5ca3e746943 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/Robot.hpp @@ -24,6 +24,6 @@ class Robot : public wpi::TimedRobot { void UtilityPeriodic() override; private: - RapidReactCommandBot m_robot; - std::optional m_autonomousCommand; + RapidReactCommandBot robot; + std::optional autonomousCommand; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp index 8ac5b46f1b6..d0ee5d0a377 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Drive.hpp @@ -49,29 +49,29 @@ class Drive : public wpi::cmd::SubsystemBase { wpi::cmd::CommandPtr TurnToAngleCommand(wpi::units::degree_t angle); private: - wpi::PWMSparkMax m_leftLeader{DriveConstants::kLeftMotor1Port}; - wpi::PWMSparkMax m_leftFollower{DriveConstants::kLeftMotor2Port}; - wpi::PWMSparkMax m_rightLeader{DriveConstants::kRightMotor1Port}; - wpi::PWMSparkMax m_rightFollower{DriveConstants::kRightMotor2Port}; + wpi::PWMSparkMax leftLeader{DriveConstants::kLeftMotor1Port}; + wpi::PWMSparkMax leftFollower{DriveConstants::kLeftMotor2Port}; + wpi::PWMSparkMax rightLeader{DriveConstants::kRightMotor1Port}; + wpi::PWMSparkMax rightFollower{DriveConstants::kRightMotor2Port}; - wpi::DifferentialDrive m_drive{ - [&](double output) { m_leftLeader.SetThrottle(output); }, - [&](double output) { m_rightLeader.SetThrottle(output); }}; + wpi::DifferentialDrive drive{ + [&](double output) { leftLeader.SetThrottle(output); }, + [&](double output) { rightLeader.SetThrottle(output); }}; - wpi::Encoder m_leftEncoder{DriveConstants::kLeftEncoderPorts[0], - DriveConstants::kLeftEncoderPorts[1], - DriveConstants::kLeftEncoderReversed}; - wpi::Encoder m_rightEncoder{DriveConstants::kRightEncoderPorts[0], - DriveConstants::kRightEncoderPorts[1], - DriveConstants::kRightEncoderReversed}; + wpi::Encoder leftEncoder{DriveConstants::kLeftEncoderPorts[0], + DriveConstants::kLeftEncoderPorts[1], + DriveConstants::kLeftEncoderReversed}; + wpi::Encoder rightEncoder{DriveConstants::kRightEncoderPorts[0], + DriveConstants::kRightEncoderPorts[1], + DriveConstants::kRightEncoderReversed}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::ProfiledPIDController m_controller{ + wpi::math::ProfiledPIDController controller{ DriveConstants::kTurnP, DriveConstants::kTurnI, DriveConstants::kTurnD, {DriveConstants::kMaxTurnRate, DriveConstants::kMaxTurnAcceleration}}; - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ DriveConstants::ks, DriveConstants::kv, DriveConstants::ka}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.hpp index d8b393dc10f..7c5f182d854 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Intake.hpp @@ -24,10 +24,10 @@ class Intake : public wpi::cmd::SubsystemBase { wpi::cmd::CommandPtr RetractCommand(); private: - wpi::PWMSparkMax m_motor{IntakeConstants::kMotorPort}; + wpi::PWMSparkMax motor{IntakeConstants::kMotorPort}; // Double solenoid connected to two channels of a PCM with the default CAN ID - wpi::DoubleSolenoid m_piston{0, wpi::PneumaticsModuleType::CTRE_PCM, - IntakeConstants::kSolenoidPorts[0], - IntakeConstants::kSolenoidPorts[1]}; + wpi::DoubleSolenoid piston{0, wpi::PneumaticsModuleType::CTRE_PCM, + IntakeConstants::kSolenoidPorts[0], + IntakeConstants::kSolenoidPorts[1]}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp index 6f6763f5a49..c42e61b5547 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Pneumatics.hpp @@ -34,9 +34,9 @@ class Pneumatics : wpi::cmd::SubsystemBase { // pressure is 250r-25 static constexpr double kScale = 250; static constexpr double kOffset = -25; - wpi::AnalogPotentiometer m_pressureTransducer{/* the AnalogIn port*/ 2, - kScale, kOffset}; + wpi::AnalogPotentiometer pressureTransducer{/* the AnalogIn port*/ 2, kScale, + kOffset}; // Compressor connected to a PH with a default CAN ID - wpi::Compressor m_compressor{0, wpi::PneumaticsModuleType::CTRE_PCM}; + wpi::Compressor compressor{0, wpi::PneumaticsModuleType::CTRE_PCM}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp index df6496d2541..9bb4d30e427 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Shooter.hpp @@ -30,13 +30,13 @@ class Shooter : public wpi::cmd::SubsystemBase { wpi::cmd::CommandPtr ShootCommand(wpi::units::turns_per_second_t setpoint); private: - wpi::PWMSparkMax m_shooterMotor{ShooterConstants::kShooterMotorPort}; - wpi::PWMSparkMax m_feederMotor{ShooterConstants::kFeederMotorPort}; + wpi::PWMSparkMax shooterMotor{ShooterConstants::kShooterMotorPort}; + wpi::PWMSparkMax feederMotor{ShooterConstants::kFeederMotorPort}; - wpi::Encoder m_shooterEncoder{ShooterConstants::kEncoderPorts[0], - ShooterConstants::kEncoderPorts[1], - ShooterConstants::kEncoderReversed}; - wpi::math::SimpleMotorFeedforward m_shooterFeedforward{ + wpi::Encoder shooterEncoder{ShooterConstants::kEncoderPorts[0], + ShooterConstants::kEncoderPorts[1], + ShooterConstants::kEncoderReversed}; + wpi::math::SimpleMotorFeedforward shooterFeedforward{ ShooterConstants::kS, ShooterConstants::kV}; - wpi::math::PIDController m_shooterFeedback{ShooterConstants::kP, 0.0, 0.0}; + wpi::math::PIDController shooterFeedback{ShooterConstants::kP, 0.0, 0.0}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.hpp b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.hpp index 40227711da8..52facc1f429 100644 --- a/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/include/subsystems/Storage.hpp @@ -18,9 +18,9 @@ class Storage : wpi::cmd::SubsystemBase { wpi::cmd::CommandPtr RunCommand(); /** Whether the ball storage is full. */ - wpi::cmd::Trigger HasCargo{[this] { return m_ballSensor.Get(); }}; + wpi::cmd::Trigger HasCargo{[this] { return ballSensor.Get(); }}; private: - wpi::PWMSparkMax m_motor{StorageConstants::kMotorPort}; - wpi::DigitalInput m_ballSensor{StorageConstants::kBallSensorPort}; + wpi::PWMSparkMax motor{StorageConstants::kMotorPort}; + wpi::DigitalInput ballSensor{StorageConstants::kBallSensorPort}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp index 2ec33e67708..dd9c9161d43 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/Robot.cpp @@ -34,10 +34,10 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand != nullptr) { - wpi::cmd::CommandScheduler::GetInstance().Schedule(m_autonomousCommand); + if (autonomousCommand != nullptr) { + wpi::cmd::CommandScheduler::GetInstance().Schedule(autonomousCommand); } } @@ -48,9 +48,9 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != nullptr) { - m_autonomousCommand->Cancel(); - m_autonomousCommand = nullptr; + if (autonomousCommand != nullptr) { + autonomousCommand->Cancel(); + autonomousCommand = nullptr; } } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp index 793af12753b..88a44eb0af8 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/RobotContainer.cpp @@ -15,20 +15,20 @@ RobotContainer::RobotContainer() { void RobotContainer::ConfigureButtonBindings() { // Also set default commands here - m_drive.SetDefaultCommand(TeleopArcadeDrive( - &m_drive, [this] { return -m_controller.GetRawAxis(1); }, - [this] { return -m_controller.GetRawAxis(2); })); + drive.SetDefaultCommand(TeleopArcadeDrive( + &drive, [this] { return -controller.GetRawAxis(1); }, + [this] { return -controller.GetRawAxis(2); })); // Example of how to use the onboard IO - m_onboardButtonA.OnTrue(wpi::cmd::Print("Button A Pressed")) + onboardButtonA.OnTrue(wpi::cmd::Print("Button A Pressed")) .OnFalse(wpi::cmd::Print("Button A Released")); // Setup SmartDashboard options. - m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance); - m_chooser.AddOption("Auto Routine Time", &m_autoTime); - wpi::SmartDashboard::PutData("Auto Selector", &m_chooser); + chooser.SetDefaultOption("Auto Routine Distance", &autoDistance); + chooser.AddOption("Auto Routine Time", &autoTime); + wpi::SmartDashboard::PutData("Auto Selector", &chooser); } wpi::cmd::Command* RobotContainer::GetAutonomousCommand() { - return m_chooser.GetSelected(); + return chooser.GetSelected(); } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp index a34b01b1afe..d3d186cff2d 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveDistance.cpp @@ -7,18 +7,18 @@ #include "wpi/units/math.hpp" void DriveDistance::Initialize() { - m_drive->ArcadeDrive(0, 0); - m_drive->ResetEncoders(); + drive->ArcadeDrive(0, 0); + drive->ResetEncoders(); } void DriveDistance::Execute() { - m_drive->ArcadeDrive(m_velocity, 0); + drive->ArcadeDrive(velocity, 0); } void DriveDistance::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); + drive->ArcadeDrive(0, 0); } bool DriveDistance::IsFinished() { - return wpi::units::math::abs(m_drive->GetAverageDistance()) >= m_distance; + return wpi::units::math::abs(drive->GetAverageDistance()) >= distance; } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp index f1be542fdd1..68adcd297b0 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/DriveTime.cpp @@ -5,20 +5,20 @@ #include "commands/DriveTime.hpp" void DriveTime::Initialize() { - m_timer.Start(); - m_drive->ArcadeDrive(0, 0); + timer.Start(); + drive->ArcadeDrive(0, 0); } void DriveTime::Execute() { - m_drive->ArcadeDrive(m_velocity, 0); + drive->ArcadeDrive(velocity, 0); } void DriveTime::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); - m_timer.Stop(); - m_timer.Reset(); + drive->ArcadeDrive(0, 0); + timer.Stop(); + timer.Reset(); } bool DriveTime::IsFinished() { - return m_timer.HasElapsed(m_duration); + return timer.HasElapsed(duration); } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp index 5a9f0bdd243..3df5d9d85e0 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TeleopArcadeDrive.cpp @@ -11,12 +11,12 @@ TeleopArcadeDrive::TeleopArcadeDrive( Drivetrain* subsystem, std::function xaxisVelocitySupplier, std::function zaxisRotateSuppplier) - : m_drive{subsystem}, - m_xaxisVelocitySupplier{std::move(xaxisVelocitySupplier)}, - m_zaxisRotateSupplier{std::move(zaxisRotateSuppplier)} { + : drive{subsystem}, + xaxisVelocitySupplier{std::move(xaxisVelocitySupplier)}, + zaxisRotateSupplier{std::move(zaxisRotateSuppplier)} { AddRequirements(subsystem); } void TeleopArcadeDrive::Execute() { - m_drive->ArcadeDrive(m_xaxisVelocitySupplier(), m_zaxisRotateSupplier()); + drive->ArcadeDrive(xaxisVelocitySupplier(), zaxisRotateSupplier()); } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp index bb19d62fa72..27a25e1591b 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnDegrees.cpp @@ -10,16 +10,16 @@ void TurnDegrees::Initialize() { // Set motors to stop, read encoder values for starting point - m_drive->ArcadeDrive(0, 0); - m_drive->ResetEncoders(); + drive->ArcadeDrive(0, 0); + drive->ResetEncoders(); } void TurnDegrees::Execute() { - m_drive->ArcadeDrive(0, m_velocity); + drive->ArcadeDrive(0, velocity); } void TurnDegrees::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); + drive->ArcadeDrive(0, 0); } bool TurnDegrees::IsFinished() { @@ -30,11 +30,11 @@ bool TurnDegrees::IsFinished() { static auto inchPerDegree = (5.551_in * std::numbers::pi) / 360_deg; // Compare distance traveled from start to distance based on degree turn. - return GetAverageTurningDistance() >= inchPerDegree * m_angle; + return GetAverageTurningDistance() >= inchPerDegree * angle; } wpi::units::meter_t TurnDegrees::GetAverageTurningDistance() { - auto l = wpi::units::math::abs(m_drive->GetLeftDistance()); - auto r = wpi::units::math::abs(m_drive->GetRightDistance()); + auto l = wpi::units::math::abs(drive->GetLeftDistance()); + auto r = wpi::units::math::abs(drive->GetRightDistance()); return (l + r) / 2; } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp index fb040614755..88e8f63bf7f 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/commands/TurnTime.cpp @@ -5,20 +5,20 @@ #include "commands/TurnTime.hpp" void TurnTime::Initialize() { - m_timer.Start(); - m_drive->ArcadeDrive(0, 0); + timer.Start(); + drive->ArcadeDrive(0, 0); } void TurnTime::Execute() { - m_drive->ArcadeDrive(0, m_velocity); + drive->ArcadeDrive(0, velocity); } void TurnTime::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); - m_timer.Stop(); - m_timer.Reset(); + drive->ArcadeDrive(0, 0); + timer.Stop(); + timer.Reset(); } bool TurnTime::IsFinished() { - return m_timer.HasElapsed(m_duration); + return timer.HasElapsed(duration); } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp index 91369791c17..e447cbf3793 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/cpp/subsystems/Drivetrain.cpp @@ -15,18 +15,18 @@ using namespace DriveConstants; // The Romi has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right Drivetrain::Drivetrain() { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_leftMotor); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_rightMotor); + wpi::util::SendableRegistry::AddChild(&drive, &leftMotor); + wpi::util::SendableRegistry::AddChild(&drive, &rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.SetInverted(true); + rightMotor.SetInverted(true); - m_leftEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / - kCountsPerRevolution); - m_rightEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / - kCountsPerRevolution); + leftEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / + kCountsPerRevolution); + rightEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / + kCountsPerRevolution); ResetEncoders(); } @@ -35,28 +35,28 @@ void Drivetrain::Periodic() { } void Drivetrain::ArcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_drive.ArcadeDrive(xaxisVelocity, zaxisRotate); + drive.ArcadeDrive(xaxisVelocity, zaxisRotate); } void Drivetrain::ResetEncoders() { - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); } int Drivetrain::GetLeftEncoderCount() { - return m_leftEncoder.Get(); + return leftEncoder.Get(); } int Drivetrain::GetRightEncoderCount() { - return m_rightEncoder.Get(); + return rightEncoder.Get(); } wpi::units::meter_t Drivetrain::GetLeftDistance() { - return wpi::units::meter_t{m_leftEncoder.GetDistance()}; + return wpi::units::meter_t{leftEncoder.GetDistance()}; } wpi::units::meter_t Drivetrain::GetRightDistance() { - return wpi::units::meter_t{m_rightEncoder.GetDistance()}; + return wpi::units::meter_t{rightEncoder.GetDistance()}; } wpi::units::meter_t Drivetrain::GetAverageDistance() { @@ -64,17 +64,17 @@ wpi::units::meter_t Drivetrain::GetAverageDistance() { } wpi::units::radian_t Drivetrain::GetGyroAngleX() { - return m_gyro.GetAngleX(); + return gyro.GetAngleX(); } wpi::units::radian_t Drivetrain::GetGyroAngleY() { - return m_gyro.GetAngleY(); + return gyro.GetAngleY(); } wpi::units::radian_t Drivetrain::GetGyroAngleZ() { - return m_gyro.GetAngleZ(); + return gyro.GetAngleZ(); } void Drivetrain::ResetGyro() { - m_gyro.Reset(); + gyro.Reset(); } diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.hpp index 2d2e802c163..afb6d52b149 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/Robot.hpp @@ -23,6 +23,6 @@ class Robot : public wpi::TimedRobot { private: // Have it null by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - wpi::cmd::Command* m_autonomousCommand = nullptr; - RobotContainer m_container; + wpi::cmd::Command* autonomousCommand = nullptr; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.hpp index cd97b5fa508..b9a410b3384 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/RobotContainer.hpp @@ -41,21 +41,21 @@ class RobotContainer { private: // Assumes a gamepad plugged into channel 0 - wpi::Joystick m_controller{0}; - wpi::SendableChooser m_chooser; + wpi::Joystick controller{0}; + wpi::SendableChooser chooser; // The robot's subsystems - Drivetrain m_drive; - wpi::romi::OnBoardIO m_onboardIO{wpi::romi::OnBoardIO::ChannelMode::INPUT, - wpi::romi::OnBoardIO::ChannelMode::INPUT}; + Drivetrain drive; + wpi::romi::OnBoardIO onboardIO{wpi::romi::OnBoardIO::ChannelMode::INPUT, + wpi::romi::OnBoardIO::ChannelMode::INPUT}; // Example button - wpi::cmd::Trigger m_onboardButtonA{ - [this] { return m_onboardIO.GetButtonAPressed(); }}; + wpi::cmd::Trigger onboardButtonA{ + [this] { return onboardIO.GetButtonAPressed(); }}; // Autonomous commands. - AutonomousDistance m_autoDistance{&m_drive}; - AutonomousTime m_autoTime{&m_drive}; + AutonomousDistance autoDistance{&drive}; + AutonomousTime autoTime{&drive}; void ConfigureButtonBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp index e5ea1cc2c91..9b2a3f33790 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveDistance.hpp @@ -22,8 +22,8 @@ class DriveDistance */ DriveDistance(double velocity, wpi::units::meter_t distance, Drivetrain* drive) - : m_velocity(velocity), m_distance(distance), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), distance(distance), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -32,7 +32,7 @@ class DriveDistance bool IsFinished() override; private: - double m_velocity; - wpi::units::meter_t m_distance; - Drivetrain* m_drive; + double velocity; + wpi::units::meter_t distance; + Drivetrain* drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp index f0b05af0d48..fc3a458268d 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/DriveTime.hpp @@ -22,8 +22,8 @@ class DriveTime : public wpi::cmd::CommandHelper { * @param drive The drivetrain subsystem on which this command will run */ DriveTime(double velocity, wpi::units::second_t time, Drivetrain* drive) - : m_velocity(velocity), m_duration(time), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), duration(time), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -32,8 +32,8 @@ class DriveTime : public wpi::cmd::CommandHelper { bool IsFinished() override; private: - double m_velocity; - wpi::units::second_t m_duration; - Drivetrain* m_drive; - wpi::Timer m_timer; + double velocity; + wpi::units::second_t duration; + Drivetrain* drive; + wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.hpp index b5ab55d0a00..b46029f595a 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TeleopArcadeDrive.hpp @@ -27,7 +27,7 @@ class TeleopArcadeDrive void Execute() override; private: - Drivetrain* m_drive; - std::function m_xaxisVelocitySupplier; - std::function m_zaxisRotateSupplier; + Drivetrain* drive; + std::function xaxisVelocitySupplier; + std::function zaxisRotateSupplier; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp index c1fbbe72a3b..2b049ae67a0 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnDegrees.hpp @@ -23,8 +23,8 @@ class TurnDegrees * @param drive The drive subsystem on which this command will run */ TurnDegrees(double velocity, wpi::units::degree_t angle, Drivetrain* drive) - : m_velocity(velocity), m_angle(angle), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), angle(angle), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -33,9 +33,9 @@ class TurnDegrees bool IsFinished() override; private: - double m_velocity; - wpi::units::degree_t m_angle; - Drivetrain* m_drive; + double velocity; + wpi::units::degree_t angle; + Drivetrain* drive; wpi::units::meter_t GetAverageTurningDistance(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp index c7fe21f761b..24e179c8c66 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/commands/TurnTime.hpp @@ -21,8 +21,8 @@ class TurnTime : public wpi::cmd::CommandHelper { * @param drive The drive subsystem on which this command will run */ TurnTime(double velocity, wpi::units::second_t time, Drivetrain* drive) - : m_velocity(velocity), m_duration(time), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), duration(time), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -31,8 +31,8 @@ class TurnTime : public wpi::cmd::CommandHelper { bool IsFinished() override; private: - double m_velocity; - wpi::units::second_t m_duration; - Drivetrain* m_drive; - wpi::Timer m_timer; + double velocity; + wpi::units::second_t duration; + Drivetrain* drive; + wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp index 104584f57f3..d4716e7a439 100644 --- a/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/RomiReference/include/subsystems/Drivetrain.hpp @@ -99,15 +99,15 @@ class Drivetrain : public wpi::cmd::SubsystemBase { void ResetGyro(); private: - wpi::Spark m_leftMotor{0}; - wpi::Spark m_rightMotor{1}; + wpi::Spark leftMotor{0}; + wpi::Spark rightMotor{1}; - wpi::Encoder m_leftEncoder{4, 5}; - wpi::Encoder m_rightEncoder{6, 7}; + wpi::Encoder leftEncoder{4, 5}; + wpi::Encoder rightEncoder{6, 7}; - wpi::DifferentialDrive m_drive{ - [&](double output) { m_leftMotor.SetThrottle(output); }, - [&](double output) { m_rightMotor.SetThrottle(output); }}; + wpi::DifferentialDrive drive{ + [&](double output) { leftMotor.SetThrottle(output); }, + [&](double output) { rightMotor.SetThrottle(output); }}; - wpi::romi::RomiGyro m_gyro; + wpi::romi::RomiGyro gyro; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp index e32dcf358fe..501edea82c0 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Drivetrain.cpp @@ -8,33 +8,33 @@ void Drivetrain::SetVelocities( const wpi::math::DifferentialDriveWheelVelocities& velocities) { - auto leftFeedforward = m_feedforward.Calculate(velocities.left); - auto rightFeedforward = m_feedforward.Calculate(velocities.right); - double leftOutput = m_leftPIDController.Calculate(m_leftEncoder.GetRate(), - velocities.left.value()); - double rightOutput = m_rightPIDController.Calculate(m_rightEncoder.GetRate(), - velocities.right.value()); - - m_leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); - m_rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); + auto leftFeedforward = feedforward.Calculate(velocities.left); + auto rightFeedforward = feedforward.Calculate(velocities.right); + double leftOutput = leftPIDController.Calculate(leftEncoder.GetRate(), + velocities.left.value()); + double rightOutput = rightPIDController.Calculate(rightEncoder.GetRate(), + velocities.right.value()); + + leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); + rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); } void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::radians_per_second_t rot) { - SetVelocities(m_kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); + SetVelocities(kinematics.ToWheelVelocities({xVelocity, 0_mps, rot})); } void Drivetrain::UpdateOdometry() { - m_odometry.Update(m_imu.GetRotation2d(), - wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}); + odometry.Update(imu.GetRotation2d(), + wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}); } void Drivetrain::ResetOdometry(const wpi::math::Pose2d& pose) { - m_drivetrainSimulator.SetPose(pose); - m_odometry.ResetPosition( - m_imu.GetRotation2d(), wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}, pose); + drivetrainSimulator.SetPose(pose); + odometry.ResetPosition(imu.GetRotation2d(), + wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}, pose); } void Drivetrain::SimulationPeriodic() { @@ -42,22 +42,20 @@ void Drivetrain::SimulationPeriodic() { // simulation, and write the simulated positions and velocities to our // simulated encoder and gyro. We negate the right side so that positive // voltages make the right side move forward. - m_drivetrainSimulator.SetInputs( - wpi::units::volt_t{m_leftLeader.GetThrottle()} * - wpi::RobotController::GetInputVoltage(), - wpi::units::volt_t{m_rightLeader.GetThrottle()} * - wpi::RobotController::GetInputVoltage()); - m_drivetrainSimulator.Update(20_ms); - - m_leftEncoderSim.SetDistance(m_drivetrainSimulator.GetLeftPosition().value()); - m_leftEncoderSim.SetRate(m_drivetrainSimulator.GetLeftVelocity().value()); - m_rightEncoderSim.SetDistance( - m_drivetrainSimulator.GetRightPosition().value()); - m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value()); - // m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value()); + drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage(), + wpi::units::volt_t{rightLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage()); + drivetrainSimulator.Update(20_ms); + + leftEncoderSim.SetDistance(drivetrainSimulator.GetLeftPosition().value()); + leftEncoderSim.SetRate(drivetrainSimulator.GetLeftVelocity().value()); + rightEncoderSim.SetDistance(drivetrainSimulator.GetRightPosition().value()); + rightEncoderSim.SetRate(drivetrainSimulator.GetRightVelocity().value()); + // gyroSim.SetAngle(-drivetrainSimulator.GetHeading().Degrees().value()); } void Drivetrain::Periodic() { UpdateOdometry(); - m_fieldSim.SetRobotPose(m_odometry.GetPose()); + fieldSim.SetRobotPose(odometry.GetPose()); } diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp index 410d539cb1c..77670bbb565 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/cpp/Robot.cpp @@ -13,57 +13,56 @@ class Robot : public wpi::TimedRobot { public: Robot() { - m_trajectory = wpi::math::TrajectoryGenerator::GenerateTrajectory( + trajectory = wpi::math::TrajectoryGenerator::GenerateTrajectory( wpi::math::Pose2d{2_m, 2_m, 0_rad}, {}, wpi::math::Pose2d{6_m, 4_m, 0_rad}, wpi::math::TrajectoryConfig(2_mps, 2_mps_sq)); } - void RobotPeriodic() override { m_drive.Periodic(); } + void RobotPeriodic() override { drive.Periodic(); } void AutonomousInit() override { - m_timer.Restart(); - m_drive.ResetOdometry(m_trajectory.InitialPose()); + timer.Restart(); + drive.ResetOdometry(trajectory.InitialPose()); } void AutonomousPeriodic() override { - auto elapsed = m_timer.Get(); - auto reference = m_trajectory.Sample(elapsed); - auto velocities = m_feedback.Calculate(m_drive.GetPose(), reference); - m_drive.Drive(velocities.vx, velocities.omega); + auto elapsed = timer.Get(); + auto reference = trajectory.Sample(elapsed); + auto velocities = feedback.Calculate(drive.GetPose(), reference); + drive.Drive(velocities.vx, velocities.omega); } void TeleopPeriodic() override { // Get the x velocity. We are inverting this because Xbox controllers return // negative values when we push forward. - const auto xVelocity = - -m_velocityLimiter.Calculate(m_controller.GetLeftY()) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -velocityLimiter.Calculate(controller.GetLeftY()) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Xbox controllers return positive values when you pull to // the right by default. - auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * + auto rot = -rotLimiter.Calculate(controller.GetRightX()) * Drivetrain::kMaxAngularVelocity; - m_drive.Drive(xVelocity, rot); + drive.Drive(xVelocity, rot); } - void SimulationPeriodic() override { m_drive.SimulationPeriodic(); } + void SimulationPeriodic() override { drive.SimulationPeriodic(); } private: - wpi::Gamepad m_controller{0}; + wpi::Gamepad controller{0}; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_velocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter velocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; - Drivetrain m_drive; - wpi::math::Trajectory m_trajectory; - wpi::math::LTVUnicycleController m_feedback{20_ms}; - wpi::Timer m_timer; + Drivetrain drive; + wpi::math::Trajectory trajectory; + wpi::math::LTVUnicycleController feedback{20_ms}; + wpi::Timer timer; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp index 3445331cb93..65ec0340b15 100644 --- a/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SimpleDifferentialDriveSimulation/include/Drivetrain.hpp @@ -28,30 +28,30 @@ class Drivetrain { public: Drivetrain() { - m_imu.ResetYaw(); + imu.ResetYaw(); - m_leftLeader.AddFollower(m_leftFollower); - m_rightLeader.AddFollower(m_rightFollower); + leftLeader.AddFollower(leftFollower); + rightLeader.AddFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.SetInverted(true); + rightLeader.SetInverted(true); // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / - kEncoderResolution); - m_rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / - kEncoderResolution); + leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / + kEncoderResolution); + rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / + kEncoderResolution); - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); - m_rightLeader.SetInverted(true); + rightLeader.SetInverted(true); - wpi::SmartDashboard::PutData("Field", &m_fieldSim); + wpi::SmartDashboard::PutData("Field", &fieldSim); } static constexpr wpi::units::meters_per_second_t kMaxVelocity = @@ -66,7 +66,7 @@ class Drivetrain { void UpdateOdometry(); void ResetOdometry(const wpi::math::Pose2d& pose); - wpi::math::Pose2d GetPose() const { return m_odometry.GetPose(); } + wpi::math::Pose2d GetPose() const { return odometry.GetPose(); } void SimulationPeriodic(); void Periodic(); @@ -76,36 +76,36 @@ class Drivetrain { static constexpr double kWheelRadius = 0.0508; // meters static constexpr int kEncoderResolution = 4096; - wpi::PWMSparkMax m_leftLeader{1}; - wpi::PWMSparkMax m_leftFollower{2}; - wpi::PWMSparkMax m_rightLeader{3}; - wpi::PWMSparkMax m_rightFollower{4}; + wpi::PWMSparkMax leftLeader{1}; + wpi::PWMSparkMax leftFollower{2}; + wpi::PWMSparkMax rightLeader{3}; + wpi::PWMSparkMax rightFollower{4}; - wpi::Encoder m_leftEncoder{0, 1}; - wpi::Encoder m_rightEncoder{2, 3}; + wpi::Encoder leftEncoder{0, 1}; + wpi::Encoder rightEncoder{2, 3}; - wpi::math::PIDController m_leftPIDController{8.5, 0.0, 0.0}; - wpi::math::PIDController m_rightPIDController{8.5, 0.0, 0.0}; + wpi::math::PIDController leftPIDController{8.5, 0.0, 0.0}; + wpi::math::PIDController rightPIDController{8.5, 0.0, 0.0}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::DifferentialDriveKinematics m_kinematics{kTrackwidth}; - wpi::math::DifferentialDriveOdometry m_odometry{ - m_imu.GetRotation2d(), wpi::units::meter_t{m_leftEncoder.GetDistance()}, - wpi::units::meter_t{m_rightEncoder.GetDistance()}}; + wpi::math::DifferentialDriveKinematics kinematics{kTrackwidth}; + wpi::math::DifferentialDriveOdometry odometry{ + imu.GetRotation2d(), wpi::units::meter_t{leftEncoder.GetDistance()}, + wpi::units::meter_t{rightEncoder.GetDistance()}}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 1_V, 3_V / 1_mps}; // Simulation classes help us simulate our robot - wpi::sim::EncoderSim m_leftEncoderSim{m_leftEncoder}; - wpi::sim::EncoderSim m_rightEncoderSim{m_rightEncoder}; - wpi::Field2d m_fieldSim; - wpi::math::LinearSystem<2, 2, 2> m_drivetrainSystem = + wpi::sim::EncoderSim leftEncoderSim{leftEncoder}; + wpi::sim::EncoderSim rightEncoderSim{rightEncoder}; + wpi::Field2d fieldSim; + wpi::math::LinearSystem<2, 2, 2> drivetrainSystem = wpi::math::Models::DifferentialDriveFromSysId( 1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_mps, 0.3_V / 1_mps_sq); - wpi::sim::DifferentialDrivetrainSim m_drivetrainSimulator{ - m_drivetrainSystem, kTrackwidth, wpi::math::DCMotor::CIM(2), 8, 2_in}; + wpi::sim::DifferentialDrivetrainSim drivetrainSimulator{ + drivetrainSystem, kTrackwidth, wpi::math::DCMotor::CIM(2), 8, 2_in}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp index 0fd1d0d8058..3188ed7d882 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceArm/cpp/Robot.cpp @@ -45,14 +45,14 @@ class Robot : public wpi::TimedRobot { // States: [position, velocity], in radians and radians per second. // Inputs (what we can "put in"): [voltage], in volts. // Outputs (what we can measure): [position], in radians. - wpi::math::LinearSystem<2, 1, 1> m_armPlant = + wpi::math::LinearSystem<2, 1, 1> armPlant = wpi::math::Models::SingleJointedArmFromPhysicalConstants( wpi::math::DCMotor::NEO(2), kArmMOI, kArmGearing) .Slice(0); // The observer fuses our encoder data and voltage inputs to reject noise. - wpi::math::KalmanFilter<2, 1, 1> m_observer{ - m_armPlant, + wpi::math::KalmanFilter<2, 1, 1> observer{ + armPlant, {0.015, 0.17}, // How accurate we think our model is {0.01}, // How accurate we think our encoder position // data is. In this case we very highly trust our encoder position @@ -60,8 +60,8 @@ class Robot : public wpi::TimedRobot { 20_ms}; // A LQR uses feedback to create voltage commands. - wpi::math::LinearQuadraticRegulator<2, 1> m_controller{ - m_armPlant, + wpi::math::LinearQuadraticRegulator<2, 1> controller{ + armPlant, // qelms. Velocity error tolerance, in radians and radians per second. // Decrease this to more heavily penalize state excursion, or make the // controller behave more aggressively. @@ -78,65 +78,63 @@ class Robot : public wpi::TimedRobot { // The state-space loop combines a controller, observer, feedforward and plant // for easy control. - wpi::math::LinearSystemLoop<2, 1, 1> m_loop{m_armPlant, m_controller, - m_observer, 12_V, 20_ms}; + wpi::math::LinearSystemLoop<2, 1, 1> loop{armPlant, controller, observer, + 12_V, 20_ms}; // An encoder set up to measure arm position in radians per second. - wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; + wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel}; - wpi::PWMSparkMax m_motor{kMotorPort}; - wpi::Gamepad m_joystick{kJoystickPort}; + wpi::PWMSparkMax motor{kMotorPort}; + wpi::Gamepad joystick{kJoystickPort}; - wpi::math::TrapezoidProfile m_profile{ + wpi::math::TrapezoidProfile profile{ {45_deg_per_s, 90_deg_per_s / 1_s}}; - wpi::math::TrapezoidProfile::State - m_lastProfiledReference; + wpi::math::TrapezoidProfile::State lastProfiledReference; public: Robot() { // We go 2 pi radians per 4096 clicks. - m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0); + encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0); } void TeleopInit() override { - m_loop.Reset( - wpi::math::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()}); + loop.Reset(wpi::math::Vectord<2>{encoder.GetDistance(), encoder.GetRate()}); - m_lastProfiledReference = { - wpi::units::radian_t{m_encoder.GetDistance()}, - wpi::units::radians_per_second_t{m_encoder.GetRate()}}; + lastProfiledReference = { + wpi::units::radian_t{encoder.GetDistance()}, + wpi::units::radians_per_second_t{encoder.GetRate()}}; } void TeleopPeriodic() override { // Sets the target position of our arm. This is similar to setting the // setpoint of a PID controller. wpi::math::TrapezoidProfile::State goal; - if (m_joystick.GetRightBumperButton()) { + if (joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference goal = {kRaisedPosition, 0_rad_per_s}; } else { // We released the bumper, so let's spin down goal = {kLoweredPosition, 0_rad_per_s}; } - m_lastProfiledReference = - m_profile.Calculate(20_ms, m_lastProfiledReference, goal); + lastProfiledReference = + profile.Calculate(20_ms, lastProfiledReference, goal); - m_loop.SetNextR( - wpi::math::Vectord<2>{m_lastProfiledReference.position.value(), - m_lastProfiledReference.velocity.value()}); + loop.SetNextR( + wpi::math::Vectord<2>{lastProfiledReference.position.value(), + lastProfiledReference.velocity.value()}); // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.Correct(wpi::math::Vectord<1>{m_encoder.GetDistance()}); + loop.Correct(wpi::math::Vectord<1>{encoder.GetDistance()}); // Update our LQR to generate new voltage commands and use the voltages to // predict the next state with out Kalman filter. - m_loop.Predict(20_ms); + loop.Predict(20_ms); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(wpi::units::volt_t{m_loop.U(0)}); + motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp index 080cb6cb5b7..4660be5297f 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceElevator/cpp/Robot.cpp @@ -42,14 +42,14 @@ class Robot : public wpi::TimedRobot { // States: [position, velocity], in meters and meters per second. // Inputs (what we can "put in"): [voltage], in volts. // Outputs (what we can measure): [position], in meters. - wpi::math::LinearSystem<2, 1, 1> m_elevatorPlant = + wpi::math::LinearSystem<2, 1, 1> elevatorPlant = wpi::math::Models::ElevatorFromPhysicalConstants( wpi::math::DCMotor::NEO(2), kCarriageMass, kDrumRadius, kGearRatio) .Slice(0); // The observer fuses our encoder data and voltage inputs to reject noise. - wpi::math::KalmanFilter<2, 1, 1> m_observer{ - m_elevatorPlant, + wpi::math::KalmanFilter<2, 1, 1> observer{ + elevatorPlant, {wpi::units::meter_t{2_in}.value(), wpi::units::meters_per_second_t{40_in / 1_s} .value()}, // How accurate we think our model is @@ -59,8 +59,8 @@ class Robot : public wpi::TimedRobot { 20_ms}; // A LQR uses feedback to create voltage commands. - wpi::math::LinearQuadraticRegulator<2, 1> m_controller{ - m_elevatorPlant, + wpi::math::LinearQuadraticRegulator<2, 1> controller{ + elevatorPlant, // qelms. State error tolerance, in meters and meters per second. // Decrease this to more heavily penalize state excursion, or make the // controller behave more aggressively. @@ -77,66 +77,64 @@ class Robot : public wpi::TimedRobot { // The state-space loop combines a controller, observer, feedforward and plant // for easy control. - wpi::math::LinearSystemLoop<2, 1, 1> m_loop{m_elevatorPlant, m_controller, - m_observer, 12_V, 20_ms}; + wpi::math::LinearSystemLoop<2, 1, 1> loop{elevatorPlant, controller, observer, + 12_V, 20_ms}; // An encoder set up to measure elevator height in meters. - wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; + wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel}; - wpi::PWMSparkMax m_motor{kMotorPort}; - wpi::Gamepad m_joystick{kJoystickPort}; + wpi::PWMSparkMax motor{kMotorPort}; + wpi::Gamepad joystick{kJoystickPort}; - wpi::math::TrapezoidProfile m_profile{{3_fps, 6_fps_sq}}; + wpi::math::TrapezoidProfile profile{{3_fps, 6_fps_sq}}; - wpi::math::TrapezoidProfile::State - m_lastProfiledReference; + wpi::math::TrapezoidProfile::State lastProfiledReference; public: Robot() { // Circumference = pi * d, so distance per click = pi * d / counts - m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi * kDrumRadius.value() / - 4096.0); + encoder.SetDistancePerPulse(2.0 * std::numbers::pi * kDrumRadius.value() / + 4096.0); } void TeleopInit() override { // Reset our loop to make sure it's in a known state. - m_loop.Reset( - wpi::math::Vectord<2>{m_encoder.GetDistance(), m_encoder.GetRate()}); + loop.Reset(wpi::math::Vectord<2>{encoder.GetDistance(), encoder.GetRate()}); - m_lastProfiledReference = { - wpi::units::meter_t{m_encoder.GetDistance()}, - wpi::units::meters_per_second_t{m_encoder.GetRate()}}; + lastProfiledReference = { + wpi::units::meter_t{encoder.GetDistance()}, + wpi::units::meters_per_second_t{encoder.GetRate()}}; } void TeleopPeriodic() override { // Sets the target height of our elevator. This is similar to setting the // setpoint of a PID controller. wpi::math::TrapezoidProfile::State goal; - if (m_joystick.GetRightBumperButton()) { + if (joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference goal = {kRaisedPosition, 0_fps}; } else { // We released the bumper, so let's spin down goal = {kLoweredPosition, 0_fps}; } - m_lastProfiledReference = - m_profile.Calculate(20_ms, m_lastProfiledReference, goal); + lastProfiledReference = + profile.Calculate(20_ms, lastProfiledReference, goal); - m_loop.SetNextR( - wpi::math::Vectord<2>{m_lastProfiledReference.position.value(), - m_lastProfiledReference.velocity.value()}); + loop.SetNextR( + wpi::math::Vectord<2>{lastProfiledReference.position.value(), + lastProfiledReference.velocity.value()}); // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.Correct(wpi::math::Vectord<1>{m_encoder.GetDistance()}); + loop.Correct(wpi::math::Vectord<1>{encoder.GetDistance()}); // Update our LQR to generate new voltage commands and use the voltages to // predict the next state with out Kalman filter. - m_loop.Predict(20_ms); + loop.Predict(20_ms); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(wpi::units::volt_t{m_loop.U(0)}); + motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp index 06d07b99bd3..8a5bc8c6cf5 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheel/cpp/Robot.cpp @@ -39,21 +39,21 @@ class Robot : public wpi::TimedRobot { // States: [velocity], in radians per second. // Inputs (what we can "put in"): [voltage], in volts. // Outputs (what we can measure): [velocity], in radians per second. - wpi::math::LinearSystem<1, 1, 1> m_flywheelPlant = + wpi::math::LinearSystem<1, 1, 1> flywheelPlant = wpi::math::Models::FlywheelFromPhysicalConstants( wpi::math::DCMotor::NEO(2), kFlywheelMomentOfInertia, kFlywheelGearing); // The observer fuses our encoder data and voltage inputs to reject noise. - wpi::math::KalmanFilter<1, 1, 1> m_observer{ - m_flywheelPlant, + wpi::math::KalmanFilter<1, 1, 1> observer{ + flywheelPlant, {3.0}, // How accurate we think our model is {0.01}, // How accurate we think our encoder data is 20_ms}; // A LQR uses feedback to create voltage commands. - wpi::math::LinearQuadraticRegulator<1, 1> m_controller{ - m_flywheelPlant, + wpi::math::LinearQuadraticRegulator<1, 1> controller{ + flywheelPlant, // qelms. Velocity error tolerance, in radians per second. Decrease this // to more heavily penalize state excursion, or make the controller behave // more aggressively. @@ -69,47 +69,47 @@ class Robot : public wpi::TimedRobot { // The state-space loop combines a controller, observer, feedforward and plant // for easy control. - wpi::math::LinearSystemLoop<1, 1, 1> m_loop{m_flywheelPlant, m_controller, - m_observer, 12_V, 20_ms}; + wpi::math::LinearSystemLoop<1, 1, 1> loop{flywheelPlant, controller, observer, + 12_V, 20_ms}; // An encoder set up to measure flywheel velocity in radians per second. - wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; + wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel}; - wpi::PWMSparkMax m_motor{kMotorPort}; - wpi::Gamepad m_joystick{kJoystickPort}; + wpi::PWMSparkMax motor{kMotorPort}; + wpi::Gamepad joystick{kJoystickPort}; public: Robot() { // We go 2 pi radians per 4096 clicks. - m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0); + encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0); } void TeleopInit() override { - m_loop.Reset(wpi::math::Vectord<1>{m_encoder.GetRate()}); + loop.Reset(wpi::math::Vectord<1>{encoder.GetRate()}); } void TeleopPeriodic() override { // Sets the target velocity of our flywheel. This is similar to setting the // setpoint of a PID controller. - if (m_joystick.GetRightBumperButton()) { + if (joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference - m_loop.SetNextR(wpi::math::Vectord<1>{kSpinup.value()}); + loop.SetNextR(wpi::math::Vectord<1>{kSpinup.value()}); } else { // We released the bumper, so let's spin down - m_loop.SetNextR(wpi::math::Vectord<1>{0.0}); + loop.SetNextR(wpi::math::Vectord<1>{0.0}); } // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.Correct(wpi::math::Vectord<1>{m_encoder.GetRate()}); + loop.Correct(wpi::math::Vectord<1>{encoder.GetRate()}); // Update our LQR to generate new voltage commands and use the voltages to // predict the next state with out Kalman filter. - m_loop.Predict(20_ms); + loop.Predict(20_ms); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(wpi::units::volt_t{m_loop.U(0)}); + motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp index 712dfe4ca80..7668ed89872 100644 --- a/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/StateSpaceFlywheelSysId/cpp/Robot.cpp @@ -38,19 +38,19 @@ class Robot : public wpi::TimedRobot { // Outputs (what we can measure): [velocity], in radians per second. // // The Kv and Ka constants are found using the FRC Characterization toolsuite. - wpi::math::LinearSystem<1, 1, 1> m_flywheelPlant = + wpi::math::LinearSystem<1, 1, 1> flywheelPlant = wpi::math::Models::FlywheelFromSysId(kFlywheelKv, kFlywheelKa); // The observer fuses our encoder data and voltage inputs to reject noise. - wpi::math::KalmanFilter<1, 1, 1> m_observer{ - m_flywheelPlant, + wpi::math::KalmanFilter<1, 1, 1> observer{ + flywheelPlant, {3.0}, // How accurate we think our model is {0.01}, // How accurate we think our encoder data is 20_ms}; // A LQR uses feedback to create voltage commands. - wpi::math::LinearQuadraticRegulator<1, 1> m_controller{ - m_flywheelPlant, + wpi::math::LinearQuadraticRegulator<1, 1> controller{ + flywheelPlant, // qelms. Velocity error tolerance, in radians per second. Decrease this // to more heavily penalize state excursion, or make the controller behave // more aggressively. @@ -66,47 +66,47 @@ class Robot : public wpi::TimedRobot { // The state-space loop combines a controller, observer, feedforward and plant // for easy control. - wpi::math::LinearSystemLoop<1, 1, 1> m_loop{m_flywheelPlant, m_controller, - m_observer, 12_V, 20_ms}; + wpi::math::LinearSystemLoop<1, 1, 1> loop{flywheelPlant, controller, observer, + 12_V, 20_ms}; // An encoder set up to measure flywheel velocity in radians per second. - wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; + wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel}; - wpi::PWMSparkMax m_motor{kMotorPort}; - wpi::Gamepad m_joystick{kJoystickPort}; + wpi::PWMSparkMax motor{kMotorPort}; + wpi::Gamepad joystick{kJoystickPort}; public: Robot() { // We go 2 pi radians per 4096 clicks. - m_encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0); + encoder.SetDistancePerPulse(2.0 * std::numbers::pi / 4096.0); } void TeleopInit() override { - m_loop.Reset(wpi::math::Vectord<1>{m_encoder.GetRate()}); + loop.Reset(wpi::math::Vectord<1>{encoder.GetRate()}); } void TeleopPeriodic() override { // Sets the target velocity of our flywheel. This is similar to setting the // setpoint of a PID controller. - if (m_joystick.GetRightBumperButton()) { + if (joystick.GetRightBumperButton()) { // We pressed the bumper, so let's set our next reference - m_loop.SetNextR(wpi::math::Vectord<1>{kSpinup.value()}); + loop.SetNextR(wpi::math::Vectord<1>{kSpinup.value()}); } else { // We released the bumper, so let's spin down - m_loop.SetNextR(wpi::math::Vectord<1>{0.0}); + loop.SetNextR(wpi::math::Vectord<1>{0.0}); } // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.Correct(wpi::math::Vectord<1>{m_encoder.GetRate()}); + loop.Correct(wpi::math::Vectord<1>{encoder.GetRate()}); // Update our LQR to generate new voltage commands and use the voltages to // predict the next state with out Kalman filter. - m_loop.Predict(20_ms); + loop.Predict(20_ms); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - m_motor.SetVoltage(wpi::units::volt_t{m_loop.U(0)}); + motor.SetVoltage(wpi::units::volt_t{loop.U(0)}); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp index 150c4e86e5a..2934ee3753c 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Drivetrain.cpp @@ -10,21 +10,20 @@ void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::second_t period) { wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { - chassisVelocities = - chassisVelocities.ToRobotRelative(m_imu.GetRotation2d()); + chassisVelocities = chassisVelocities.ToRobotRelative(imu.GetRotation2d()); } chassisVelocities = chassisVelocities.Discretize(period); - auto [fl, fr, bl, br] = m_kinematics.DesaturateWheelVelocities( - m_kinematics.ToSwerveModuleVelocities(chassisVelocities), kMaxVelocity); - m_frontLeft.SetDesiredVelocity(fl); - m_frontRight.SetDesiredVelocity(fr); - m_backLeft.SetDesiredVelocity(bl); - m_backRight.SetDesiredVelocity(br); + auto [fl, fr, bl, br] = kinematics.DesaturateWheelVelocities( + kinematics.ToSwerveModuleVelocities(chassisVelocities), kMaxVelocity); + frontLeft.SetDesiredVelocity(fl); + frontRight.SetDesiredVelocity(fr); + backLeft.SetDesiredVelocity(bl); + backRight.SetDesiredVelocity(br); } void Drivetrain::UpdateOdometry() { - m_odometry.Update(m_imu.GetRotation2d(), - {m_frontLeft.GetPosition(), m_frontRight.GetPosition(), - m_backLeft.GetPosition(), m_backRight.GetPosition()}); + odometry.Update(imu.GetRotation2d(), + {frontLeft.GetPosition(), frontRight.GetPosition(), + backLeft.GetPosition(), backRight.GetPosition()}); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp index 77e53826371..1bf4630c815 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/Robot.cpp @@ -12,46 +12,44 @@ class Robot : public wpi::TimedRobot { public: void AutonomousPeriodic() override { DriveWithJoystick(false); - m_swerve.UpdateOdometry(); + swerve.UpdateOdometry(); } void TeleopPeriodic() override { DriveWithJoystick(true); } private: - wpi::Gamepad m_controller{0}; - Drivetrain m_swerve; + wpi::Gamepad controller{0}; + Drivetrain swerve; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - const auto xVelocity = - -m_xVelocityLimiter.Calculate( - wpi::math::ApplyDeadband(m_controller.GetLeftY(), 0.02)) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -xVelocityLimiter.Calculate(wpi::math::ApplyDeadband( + controller.GetLeftY(), 0.02)) * + Drivetrain::kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this // because we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. - const auto yVelocity = - -m_yVelocityLimiter.Calculate( - wpi::math::ApplyDeadband(m_controller.GetLeftX(), 0.02)) * - Drivetrain::kMaxVelocity; + const auto yVelocity = -yVelocityLimiter.Calculate(wpi::math::ApplyDeadband( + controller.GetLeftX(), 0.02)) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - const auto rot = -m_rotLimiter.Calculate(wpi::math::ApplyDeadband( - m_controller.GetRightX(), 0.02)) * + const auto rot = -rotLimiter.Calculate(wpi::math::ApplyDeadband( + controller.GetRightX(), 0.02)) * Drivetrain::kMaxAngularVelocity; - m_swerve.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); + swerve.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp index 319b407096f..076b9724993 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/cpp/SwerveModule.cpp @@ -14,43 +14,42 @@ SwerveModule::SwerveModule(const int driveMotorChannel, const int driveEncoderChannelB, const int turningEncoderChannelA, const int turningEncoderChannelB) - : m_driveMotor(driveMotorChannel), - m_turningMotor(turningMotorChannel), - m_driveEncoder(driveEncoderChannelA, driveEncoderChannelB), - m_turningEncoder(turningEncoderChannelA, turningEncoderChannelB) { + : driveMotor(driveMotorChannel), + turningMotor(turningMotorChannel), + driveEncoder(driveEncoderChannelA, driveEncoderChannelB), + turningEncoder(turningEncoderChannelA, turningEncoderChannelB) { // Set the distance per pulse for the drive encoder. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_driveEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / - kEncoderResolution); + driveEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / + kEncoderResolution); // Set the distance (in this case, angle) per pulse for the turning encoder. // This is the the angle through an entire rotation (2 * std::numbers::pi) // divided by the encoder resolution. - m_turningEncoder.SetDistancePerPulse(2 * std::numbers::pi / - kEncoderResolution); + turningEncoder.SetDistancePerPulse(2 * std::numbers::pi / kEncoderResolution); // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. - m_turningPIDController.EnableContinuousInput( + turningPIDController.EnableContinuousInput( -wpi::units::radian_t{std::numbers::pi}, wpi::units::radian_t{std::numbers::pi}); } wpi::math::SwerveModulePosition SwerveModule::GetPosition() const { - return {wpi::units::meter_t{m_driveEncoder.GetDistance()}, - wpi::units::radian_t{m_turningEncoder.GetDistance()}}; + return {wpi::units::meter_t{driveEncoder.GetDistance()}, + wpi::units::radian_t{turningEncoder.GetDistance()}}; } wpi::math::SwerveModuleVelocity SwerveModule::GetVelocity() const { - return {wpi::units::meters_per_second_t{m_driveEncoder.GetRate()}, - wpi::units::radian_t{m_turningEncoder.GetDistance()}}; + return {wpi::units::meters_per_second_t{driveEncoder.GetRate()}, + wpi::units::radian_t{turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredVelocity( wpi::math::SwerveModuleVelocity& desiredVelocity) { wpi::math::Rotation2d encoderRotation{ - wpi::units::radian_t{m_turningEncoder.GetDistance()}}; + wpi::units::radian_t{turningEncoder.GetDistance()}}; // Optimize the desired velocity to avoid spinning further than 90 degrees, // then scale velocity by cosine of angle error. This scales down movement @@ -59,21 +58,21 @@ void SwerveModule::SetDesiredVelocity( auto velocity = desiredVelocity.Optimize(encoderRotation).CosineScale(encoderRotation); - // Calculate the drive output from the drive PID controller. - const auto driveOutput = m_drivePIDController.Calculate( - m_driveEncoder.GetRate(), velocity.velocity.value()); + // Calculate the drive output from the drive PID controller and feedforward. + const auto driveOutput = + wpi::units::volt_t{drivePIDController.Calculate( + driveEncoder.GetRate(), velocity.velocity.value())} + + driveFeedforward.Calculate(velocity.velocity); - const auto driveFeedforward = m_driveFeedforward.Calculate(velocity.velocity); - - // Calculate the turning motor output from the turning PID controller. - const auto turnOutput = m_turningPIDController.Calculate( - wpi::units::radian_t{m_turningEncoder.GetDistance()}, - velocity.angle.Radians()); - - const auto turnFeedforward = m_turnFeedforward.Calculate( - m_turningPIDController.GetSetpoint().velocity); + // Calculate the turning motor output from the turning PID controller and + // feedforward. + const auto turnOutput = + wpi::units::volt_t{turningPIDController.Calculate( + wpi::units::radian_t{turningEncoder.GetDistance()}, + velocity.angle.Radians())} + + turnFeedforward.Calculate(turningPIDController.GetSetpoint().velocity); // Set the motor outputs. - m_driveMotor.SetVoltage(wpi::units::volt_t{driveOutput} + driveFeedforward); - m_turningMotor.SetVoltage(wpi::units::volt_t{turnOutput} + turnFeedforward); + driveMotor.SetVoltage(driveOutput); + turningMotor.SetVoltage(turnOutput); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp index 261bbaf7056..b6c59696b14 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/Drivetrain.hpp @@ -17,7 +17,7 @@ */ class Drivetrain { public: - Drivetrain() { m_imu.ResetYaw(); } + Drivetrain() { imu.ResetYaw(); } void Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::meters_per_second_t yVelocity, @@ -31,25 +31,25 @@ class Drivetrain { std::numbers::pi}; // 1/2 rotation per second private: - wpi::math::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m}; - wpi::math::Translation2d m_frontRightLocation{+0.381_m, -0.381_m}; - wpi::math::Translation2d m_backLeftLocation{-0.381_m, +0.381_m}; - wpi::math::Translation2d m_backRightLocation{-0.381_m, -0.381_m}; - - SwerveModule m_frontLeft{1, 2, 0, 1, 2, 3}; - SwerveModule m_frontRight{3, 4, 4, 5, 6, 7}; - SwerveModule m_backLeft{5, 6, 8, 9, 10, 11}; - SwerveModule m_backRight{7, 8, 12, 13, 14, 15}; - - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; - - wpi::math::SwerveDriveKinematics<4> m_kinematics{ - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, - m_backRightLocation}; - - wpi::math::SwerveDriveOdometry<4> m_odometry{ - m_kinematics, - m_imu.GetRotation2d(), - {m_frontLeft.GetPosition(), m_frontRight.GetPosition(), - m_backLeft.GetPosition(), m_backRight.GetPosition()}}; + wpi::math::Translation2d frontLeftLocation{+0.381_m, +0.381_m}; + wpi::math::Translation2d frontRightLocation{+0.381_m, -0.381_m}; + wpi::math::Translation2d backLeftLocation{-0.381_m, +0.381_m}; + wpi::math::Translation2d backRightLocation{-0.381_m, -0.381_m}; + + SwerveModule frontLeft{1, 2, 0, 1, 2, 3}; + SwerveModule frontRight{3, 4, 4, 5, 6, 7}; + SwerveModule backLeft{5, 6, 8, 9, 10, 11}; + SwerveModule backRight{7, 8, 12, 13, 14, 15}; + + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; + + wpi::math::SwerveDriveKinematics<4> kinematics{ + frontLeftLocation, frontRightLocation, backLeftLocation, + backRightLocation}; + + wpi::math::SwerveDriveOdometry<4> odometry{ + kinematics, + imu.GetRotation2d(), + {frontLeft.GetPosition(), frontRight.GetPosition(), + backLeft.GetPosition(), backRight.GetPosition()}}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp index 27b3d7c6775..78d68e57243 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveBot/include/SwerveModule.hpp @@ -36,21 +36,21 @@ class SwerveModule { static constexpr auto kModuleMaxAngularAcceleration = std::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2 - wpi::PWMSparkMax m_driveMotor; - wpi::PWMSparkMax m_turningMotor; + wpi::PWMSparkMax driveMotor; + wpi::PWMSparkMax turningMotor; - wpi::Encoder m_driveEncoder; - wpi::Encoder m_turningEncoder; + wpi::Encoder driveEncoder; + wpi::Encoder turningEncoder; - wpi::math::PIDController m_drivePIDController{1.0, 0, 0}; - wpi::math::ProfiledPIDController m_turningPIDController{ + wpi::math::PIDController drivePIDController{1.0, 0, 0}; + wpi::math::ProfiledPIDController turningPIDController{ 1.0, 0.0, 0.0, {kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration}}; - wpi::math::SimpleMotorFeedforward m_driveFeedforward{ + wpi::math::SimpleMotorFeedforward driveFeedforward{ 1_V, 3_V / 1_mps}; - wpi::math::SimpleMotorFeedforward m_turnFeedforward{ + wpi::math::SimpleMotorFeedforward turnFeedforward{ 1_V, 0.5_V / 1_rad_per_s}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp index b29e4567941..ce5561c93d6 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Drivetrain.cpp @@ -14,28 +14,28 @@ void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, wpi::math::ChassisVelocities chassisVelocities{xVelocity, yVelocity, rot}; if (fieldRelative) { chassisVelocities = chassisVelocities.ToRobotRelative( - m_poseEstimator.GetEstimatedPosition().Rotation()); + poseEstimator.GetEstimatedPosition().Rotation()); } chassisVelocities = chassisVelocities.Discretize(period); - auto [fl, fr, bl, br] = m_kinematics.DesaturateWheelVelocities( - m_kinematics.ToSwerveModuleVelocities(chassisVelocities), kMaxVelocity); - m_frontLeft.SetDesiredVelocity(fl); - m_frontRight.SetDesiredVelocity(fr); - m_backLeft.SetDesiredVelocity(bl); - m_backRight.SetDesiredVelocity(br); + auto [fl, fr, bl, br] = kinematics.DesaturateWheelVelocities( + kinematics.ToSwerveModuleVelocities(chassisVelocities), kMaxVelocity); + frontLeft.SetDesiredVelocity(fl); + frontRight.SetDesiredVelocity(fr); + backLeft.SetDesiredVelocity(bl); + backRight.SetDesiredVelocity(br); } void Drivetrain::UpdateOdometry() { - m_poseEstimator.Update(m_imu.GetRotation2d(), - {m_frontLeft.GetPosition(), m_frontRight.GetPosition(), - m_backLeft.GetPosition(), m_backRight.GetPosition()}); + poseEstimator.Update(imu.GetRotation2d(), + {frontLeft.GetPosition(), frontRight.GetPosition(), + backLeft.GetPosition(), backRight.GetPosition()}); // Also apply vision measurements. We use 0.3 seconds in the past as an // example -- on a real robot, this must be calculated based either on latency // or timestamps. - m_poseEstimator.AddVisionMeasurement( + poseEstimator.AddVisionMeasurement( ExampleGlobalMeasurementSensor::GetEstimatedGlobalPose( - m_poseEstimator.GetEstimatedPosition()), + poseEstimator.GetEstimatedPosition()), wpi::Timer::GetTimestamp() - 0.3_s); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp index 602cb5a2d6a..c28f4d28078 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/Robot.cpp @@ -11,43 +11,41 @@ class Robot : public wpi::TimedRobot { public: void AutonomousPeriodic() override { DriveWithJoystick(false); - m_swerve.UpdateOdometry(); + swerve.UpdateOdometry(); } void TeleopPeriodic() override { DriveWithJoystick(true); } private: - wpi::Gamepad m_controller{0}; - Drivetrain m_swerve; + wpi::Gamepad controller{0}; + Drivetrain swerve; // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - wpi::math::SlewRateLimiter m_xVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_yVelocityLimiter{3 / 1_s}; - wpi::math::SlewRateLimiter m_rotLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter xVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter yVelocityLimiter{3 / 1_s}; + wpi::math::SlewRateLimiter rotLimiter{3 / 1_s}; void DriveWithJoystick(bool fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - const auto xVelocity = - -m_xVelocityLimiter.Calculate(m_controller.GetLeftY()) * - Drivetrain::kMaxVelocity; + const auto xVelocity = -xVelocityLimiter.Calculate(controller.GetLeftY()) * + Drivetrain::kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this // because we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. - const auto yVelocity = - -m_yVelocityLimiter.Calculate(m_controller.GetLeftX()) * - Drivetrain::kMaxVelocity; + const auto yVelocity = -yVelocityLimiter.Calculate(controller.GetLeftX()) * + Drivetrain::kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * + const auto rot = -rotLimiter.Calculate(controller.GetRightX()) * Drivetrain::kMaxAngularVelocity; - m_swerve.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); + swerve.Drive(xVelocity, yVelocity, rot, fieldRelative, GetPeriod()); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp index c6c025958ba..06a3db83381 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/cpp/SwerveModule.cpp @@ -14,43 +14,42 @@ SwerveModule::SwerveModule(const int driveMotorChannel, const int driveEncoderChannelB, const int turningEncoderChannelA, const int turningEncoderChannelB) - : m_driveMotor(driveMotorChannel), - m_turningMotor(turningMotorChannel), - m_driveEncoder(driveEncoderChannelA, driveEncoderChannelB), - m_turningEncoder(turningEncoderChannelA, turningEncoderChannelB) { + : driveMotor(driveMotorChannel), + turningMotor(turningMotorChannel), + driveEncoder(driveEncoderChannelA, driveEncoderChannelB), + turningEncoder(turningEncoderChannelA, turningEncoderChannelB) { // Set the distance per pulse for the drive encoder. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_driveEncoder.SetDistancePerPulse(2 * std::numbers::pi * - kWheelRadius.value() / kEncoderResolution); + driveEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius.value() / + kEncoderResolution); // Set the distance (in this case, angle) per pulse for the turning encoder. // This is the the angle through an entire rotation (2 * std::numbers::pi) // divided by the encoder resolution. - m_turningEncoder.SetDistancePerPulse(2 * std::numbers::pi / - kEncoderResolution); + turningEncoder.SetDistancePerPulse(2 * std::numbers::pi / kEncoderResolution); // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. - m_turningPIDController.EnableContinuousInput( + turningPIDController.EnableContinuousInput( -wpi::units::radian_t{std::numbers::pi}, wpi::units::radian_t{std::numbers::pi}); } wpi::math::SwerveModulePosition SwerveModule::GetPosition() const { - return {wpi::units::meter_t{m_driveEncoder.GetDistance()}, - wpi::units::radian_t{m_turningEncoder.GetDistance()}}; + return {wpi::units::meter_t{driveEncoder.GetDistance()}, + wpi::units::radian_t{turningEncoder.GetDistance()}}; } wpi::math::SwerveModuleVelocity SwerveModule::GetVelocity() const { - return {wpi::units::meters_per_second_t{m_driveEncoder.GetRate()}, - wpi::units::radian_t{m_turningEncoder.GetDistance()}}; + return {wpi::units::meters_per_second_t{driveEncoder.GetRate()}, + wpi::units::radian_t{turningEncoder.GetDistance()}}; } void SwerveModule::SetDesiredVelocity( wpi::math::SwerveModuleVelocity& desiredVelocity) { wpi::math::Rotation2d encoderRotation{ - wpi::units::radian_t{m_turningEncoder.GetDistance()}}; + wpi::units::radian_t{turningEncoder.GetDistance()}}; // Optimize the desired velocity to avoid spinning further than 90 degrees, // then scale velocity by cosine of angle error. This scales down movement @@ -59,21 +58,21 @@ void SwerveModule::SetDesiredVelocity( auto velocity = desiredVelocity.Optimize(encoderRotation).CosineScale(encoderRotation); - // Calculate the drive output from the drive PID controller. - const auto driveOutput = m_drivePIDController.Calculate( - m_driveEncoder.GetRate(), velocity.velocity.value()); + // Calculate the drive output from the drive PID controller and feedforward. + const auto driveOutput = + wpi::units::volt_t{drivePIDController.Calculate( + driveEncoder.GetRate(), velocity.velocity.value())} + + driveFeedforward.Calculate(velocity.velocity); - const auto driveFeedforward = m_driveFeedforward.Calculate(velocity.velocity); - - // Calculate the turning motor output from the turning PID controller. - const auto turnOutput = m_turningPIDController.Calculate( - wpi::units::radian_t{m_turningEncoder.GetDistance()}, - velocity.angle.Radians()); - - const auto turnFeedforward = m_turnFeedforward.Calculate( - m_turningPIDController.GetSetpoint().velocity); + // Calculate the turning motor output from the turning PID controller and + // feedforward. + const auto turnOutput = + wpi::units::volt_t{turningPIDController.Calculate( + wpi::units::radian_t{turningEncoder.GetDistance()}, + velocity.angle.Radians())} + + turnFeedforward.Calculate(turningPIDController.GetSetpoint().velocity); // Set the motor outputs. - m_driveMotor.SetVoltage(wpi::units::volt_t{driveOutput} + driveFeedforward); - m_turningMotor.SetVoltage(wpi::units::volt_t{turnOutput} + turnFeedforward); + driveMotor.SetVoltage(driveOutput); + turningMotor.SetVoltage(turnOutput); } diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp index 211b5698213..f2b50e5521d 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/Drivetrain.hpp @@ -17,7 +17,7 @@ */ class Drivetrain { public: - Drivetrain() { m_imu.ResetYaw(); } + Drivetrain() { imu.ResetYaw(); } void Drive(wpi::units::meters_per_second_t xVelocity, wpi::units::meters_per_second_t yVelocity, @@ -30,29 +30,29 @@ class Drivetrain { std::numbers::pi}; // 1/2 rotation per second private: - wpi::math::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m}; - wpi::math::Translation2d m_frontRightLocation{+0.381_m, -0.381_m}; - wpi::math::Translation2d m_backLeftLocation{-0.381_m, +0.381_m}; - wpi::math::Translation2d m_backRightLocation{-0.381_m, -0.381_m}; + wpi::math::Translation2d frontLeftLocation{+0.381_m, +0.381_m}; + wpi::math::Translation2d frontRightLocation{+0.381_m, -0.381_m}; + wpi::math::Translation2d backLeftLocation{-0.381_m, +0.381_m}; + wpi::math::Translation2d backRightLocation{-0.381_m, -0.381_m}; - SwerveModule m_frontLeft{1, 2, 0, 1, 2, 3}; - SwerveModule m_frontRight{3, 4, 4, 5, 6, 7}; - SwerveModule m_backLeft{5, 6, 8, 9, 10, 11}; - SwerveModule m_backRight{7, 8, 12, 13, 14, 15}; + SwerveModule frontLeft{1, 2, 0, 1, 2, 3}; + SwerveModule frontRight{3, 4, 4, 5, 6, 7}; + SwerveModule backLeft{5, 6, 8, 9, 10, 11}; + SwerveModule backRight{7, 8, 12, 13, 14, 15}; - wpi::OnboardIMU m_imu{wpi::OnboardIMU::FLAT}; + wpi::OnboardIMU imu{wpi::OnboardIMU::FLAT}; - wpi::math::SwerveDriveKinematics<4> m_kinematics{ - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, - m_backRightLocation}; + wpi::math::SwerveDriveKinematics<4> kinematics{ + frontLeftLocation, frontRightLocation, backLeftLocation, + backRightLocation}; // Gains are for example purposes only - must be determined for your own // robot! - wpi::math::SwerveDrivePoseEstimator<4> m_poseEstimator{ - m_kinematics, + wpi::math::SwerveDrivePoseEstimator<4> poseEstimator{ + kinematics, wpi::math::Rotation2d{}, - {m_frontLeft.GetPosition(), m_frontRight.GetPosition(), - m_backLeft.GetPosition(), m_backRight.GetPosition()}, + {frontLeft.GetPosition(), frontRight.GetPosition(), + backLeft.GetPosition(), backRight.GetPosition()}, wpi::math::Pose2d{}, {0.1, 0.1, 0.1}, {0.1, 0.1, 0.1}}; diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp index d57b7099722..08787fb9f0d 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveDrivePoseEstimator/include/SwerveModule.hpp @@ -36,21 +36,21 @@ class SwerveModule { static constexpr auto kModuleMaxAngularAcceleration = std::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2 - wpi::PWMSparkMax m_driveMotor; - wpi::PWMSparkMax m_turningMotor; + wpi::PWMSparkMax driveMotor; + wpi::PWMSparkMax turningMotor; - wpi::Encoder m_driveEncoder; - wpi::Encoder m_turningEncoder; + wpi::Encoder driveEncoder; + wpi::Encoder turningEncoder; - wpi::math::PIDController m_drivePIDController{1.0, 0, 0}; - wpi::math::ProfiledPIDController m_turningPIDController{ + wpi::math::PIDController drivePIDController{1.0, 0, 0}; + wpi::math::ProfiledPIDController turningPIDController{ 1.0, 0.0, 0.0, {kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration}}; - wpi::math::SimpleMotorFeedforward m_driveFeedforward{ + wpi::math::SimpleMotorFeedforward driveFeedforward{ 1_V, 3_V / 1_mps}; - wpi::math::SimpleMotorFeedforward m_turnFeedforward{ + wpi::math::SimpleMotorFeedforward turnFeedforward{ 1_V, 0.5_V / 1_rad_per_s}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/Robot.cpp index 3dd2cac83b8..132624950e1 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/Robot.cpp @@ -19,11 +19,11 @@ void Robot::DisabledPeriodic() {} void Robot::DisabledExit() {} void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand) { + if (autonomousCommand) { wpi::cmd::CommandScheduler::GetInstance().Schedule( - m_autonomousCommand.value()); + autonomousCommand.value()); } } @@ -32,8 +32,8 @@ void Robot::AutonomousPeriodic() {} void Robot::AutonomousExit() {} void Robot::TeleopInit() { - if (m_autonomousCommand) { - m_autonomousCommand->Cancel(); + if (autonomousCommand) { + autonomousCommand->Cancel(); } } diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/SysIdRoutineBot.cpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/SysIdRoutineBot.cpp index c9f1e144943..a99edb6e530 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/SysIdRoutineBot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/SysIdRoutineBot.cpp @@ -11,38 +11,36 @@ SysIdRoutineBot::SysIdRoutineBot() { } void SysIdRoutineBot::ConfigureBindings() { - m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand( - [this] { return -m_driverController.GetLeftY(); }, - [this] { return -m_driverController.GetRightX(); })); + drive.SetDefaultCommand(drive.ArcadeDriveCommand( + [this] { return -driverController.GetLeftY(); }, + [this] { return -driverController.GetRightX(); })); // Using bumpers as a modifier and combining it with the buttons so that we // can have both sets of bindings at once - (m_driverController.SouthFace() && m_driverController.RightBumper()) + (driverController.SouthFace() && driverController.RightBumper()) + .WhileTrue(drive.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); + (driverController.EastFace() && driverController.RightBumper()) + .WhileTrue(drive.SysIdQuasistatic(wpi::cmd::sysid::Direction::kReverse)); + (driverController.WestFace() && driverController.RightBumper()) + .WhileTrue(drive.SysIdDynamic(wpi::cmd::sysid::Direction::kForward)); + (driverController.NorthFace() && driverController.RightBumper()) + .WhileTrue(drive.SysIdDynamic(wpi::cmd::sysid::Direction::kReverse)); + + shooter.SetDefaultCommand(shooter.RunShooterCommand( + [this] { return driverController.GetLeftTriggerAxis(); })); + + (driverController.SouthFace() && driverController.LeftBumper()) .WhileTrue( - m_drive.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); - (m_driverController.EastFace() && m_driverController.RightBumper()) + shooter.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); + (driverController.EastFace() && driverController.LeftBumper()) .WhileTrue( - m_drive.SysIdQuasistatic(wpi::cmd::sysid::Direction::kReverse)); - (m_driverController.WestFace() && m_driverController.RightBumper()) - .WhileTrue(m_drive.SysIdDynamic(wpi::cmd::sysid::Direction::kForward)); - (m_driverController.NorthFace() && m_driverController.RightBumper()) - .WhileTrue(m_drive.SysIdDynamic(wpi::cmd::sysid::Direction::kReverse)); - - m_shooter.SetDefaultCommand(m_shooter.RunShooterCommand( - [this] { return m_driverController.GetLeftTriggerAxis(); })); - - (m_driverController.SouthFace() && m_driverController.LeftBumper()) - .WhileTrue( - m_shooter.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); - (m_driverController.EastFace() && m_driverController.LeftBumper()) - .WhileTrue( - m_shooter.SysIdQuasistatic(wpi::cmd::sysid::Direction::kReverse)); - (m_driverController.WestFace() && m_driverController.LeftBumper()) - .WhileTrue(m_shooter.SysIdDynamic(wpi::cmd::sysid::Direction::kForward)); - (m_driverController.NorthFace() && m_driverController.LeftBumper()) - .WhileTrue(m_shooter.SysIdDynamic(wpi::cmd::sysid::Direction::kReverse)); + shooter.SysIdQuasistatic(wpi::cmd::sysid::Direction::kReverse)); + (driverController.WestFace() && driverController.LeftBumper()) + .WhileTrue(shooter.SysIdDynamic(wpi::cmd::sysid::Direction::kForward)); + (driverController.NorthFace() && driverController.LeftBumper()) + .WhileTrue(shooter.SysIdDynamic(wpi::cmd::sysid::Direction::kReverse)); } wpi::cmd::CommandPtr SysIdRoutineBot::GetAutonomousCommand() { - return m_drive.Run([] {}); + return drive.Run([] {}); } diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Drive.cpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Drive.cpp index 5c1d2c34e4a..30c0f21365c 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Drive.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Drive.cpp @@ -7,32 +7,31 @@ #include "wpi/commands2/Commands.hpp" Drive::Drive() { - m_leftMotor.AddFollower(wpi::PWMSparkMax{constants::drive::kLeftMotor2Port}); - m_rightMotor.AddFollower( - wpi::PWMSparkMax{constants::drive::kRightMotor2Port}); + leftMotor.AddFollower(wpi::PWMSparkMax{constants::drive::kLeftMotor2Port}); + rightMotor.AddFollower(wpi::PWMSparkMax{constants::drive::kRightMotor2Port}); - m_rightMotor.SetInverted(true); + rightMotor.SetInverted(true); - m_leftEncoder.SetDistancePerPulse( + leftEncoder.SetDistancePerPulse( constants::drive::kEncoderDistancePerPulse.value()); - m_rightEncoder.SetDistancePerPulse( + rightEncoder.SetDistancePerPulse( constants::drive::kEncoderDistancePerPulse.value()); - m_drive.SetSafetyEnabled(false); + drive.SetSafetyEnabled(false); } wpi::cmd::CommandPtr Drive::ArcadeDriveCommand(std::function fwd, std::function rot) { - return wpi::cmd::Run([this, fwd, rot] { m_drive.ArcadeDrive(fwd(), rot()); }, + return wpi::cmd::Run([this, fwd, rot] { drive.ArcadeDrive(fwd(), rot()); }, {this}) .WithName("Arcade Drive"); } wpi::cmd::CommandPtr Drive::SysIdQuasistatic( wpi::cmd::sysid::Direction direction) { - return m_sysIdRoutine.Quasistatic(direction); + return sysIdRoutine.Quasistatic(direction); } wpi::cmd::CommandPtr Drive::SysIdDynamic(wpi::cmd::sysid::Direction direction) { - return m_sysIdRoutine.Dynamic(direction); + return sysIdRoutine.Dynamic(direction); } diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp index 06548fe3d84..d21f1a6c644 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/cpp/subsystems/Shooter.cpp @@ -9,7 +9,7 @@ #include "wpi/units/voltage.hpp" Shooter::Shooter() { - m_shooterEncoder.SetDistancePerPulse( + shooterEncoder.SetDistancePerPulse( constants::shooter::kEncoderDistancePerPulse.value()); } @@ -17,12 +17,12 @@ wpi::cmd::CommandPtr Shooter::RunShooterCommand( std::function shooterVelocity) { return wpi::cmd::Run( [this, shooterVelocity] { - m_shooterMotor.SetVoltage( - wpi::units::volt_t{m_shooterFeedback.Calculate( - m_shooterEncoder.GetRate(), shooterVelocity())} + - m_shooterFeedforward.Calculate( + shooterMotor.SetVoltage( + wpi::units::volt_t{shooterFeedback.Calculate( + shooterEncoder.GetRate(), shooterVelocity())} + + shooterFeedforward.Calculate( wpi::units::turns_per_second_t{shooterVelocity()})); - m_feederMotor.SetThrottle(constants::shooter::kFeederVelocity); + feederMotor.SetThrottle(constants::shooter::kFeederVelocity); }, {this}) .WithName("Set Shooter Velocity"); @@ -30,10 +30,10 @@ wpi::cmd::CommandPtr Shooter::RunShooterCommand( wpi::cmd::CommandPtr Shooter::SysIdQuasistatic( wpi::cmd::sysid::Direction direction) { - return m_sysIdRoutine.Quasistatic(direction); + return sysIdRoutine.Quasistatic(direction); } wpi::cmd::CommandPtr Shooter::SysIdDynamic( wpi::cmd::sysid::Direction direction) { - return m_sysIdRoutine.Dynamic(direction); + return sysIdRoutine.Dynamic(direction); } diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Robot.hpp index 0eb843e390b..0998e52c1c0 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/Robot.hpp @@ -28,7 +28,7 @@ class Robot : public wpi::TimedRobot { void UtilityExit() override; private: - std::optional m_autonomousCommand; + std::optional autonomousCommand; - SysIdRoutineBot m_container; + SysIdRoutineBot container; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/SysIdRoutineBot.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/SysIdRoutineBot.hpp index dd5d208fb04..f86b8b6c342 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/SysIdRoutineBot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/SysIdRoutineBot.hpp @@ -18,8 +18,8 @@ class SysIdRoutineBot { private: void ConfigureBindings(); - wpi::cmd::CommandGamepad m_driverController{ + wpi::cmd::CommandGamepad driverController{ constants::oi::kDriverControllerPort}; - Drive m_drive; - Shooter m_shooter; + Drive drive; + Shooter shooter; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp index bf47d517681..ca36bffe884 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Drive.hpp @@ -24,41 +24,41 @@ class Drive : public wpi::cmd::SubsystemBase { wpi::cmd::CommandPtr SysIdDynamic(wpi::cmd::sysid::Direction direction); private: - wpi::PWMSparkMax m_leftMotor{constants::drive::kLeftMotor1Port}; - wpi::PWMSparkMax m_rightMotor{constants::drive::kRightMotor1Port}; - wpi::DifferentialDrive m_drive{ - [this](auto val) { m_leftMotor.SetThrottle(val); }, - [this](auto val) { m_rightMotor.SetThrottle(val); }}; + wpi::PWMSparkMax leftMotor{constants::drive::kLeftMotor1Port}; + wpi::PWMSparkMax rightMotor{constants::drive::kRightMotor1Port}; + wpi::DifferentialDrive drive{ + [this](auto val) { leftMotor.SetThrottle(val); }, + [this](auto val) { rightMotor.SetThrottle(val); }}; - wpi::Encoder m_leftEncoder{constants::drive::kLeftEncoderPorts[0], - constants::drive::kLeftEncoderPorts[1], - constants::drive::kLeftEncoderReversed}; + wpi::Encoder leftEncoder{constants::drive::kLeftEncoderPorts[0], + constants::drive::kLeftEncoderPorts[1], + constants::drive::kLeftEncoderReversed}; - wpi::Encoder m_rightEncoder{constants::drive::kRightEncoderPorts[0], - constants::drive::kRightEncoderPorts[1], - constants::drive::kRightEncoderReversed}; + wpi::Encoder rightEncoder{constants::drive::kRightEncoderPorts[0], + constants::drive::kRightEncoderPorts[1], + constants::drive::kRightEncoderReversed}; - wpi::cmd::sysid::SysIdRoutine m_sysIdRoutine{ + wpi::cmd::sysid::SysIdRoutine sysIdRoutine{ wpi::cmd::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr}, wpi::cmd::sysid::Mechanism{ [this](wpi::units::volt_t driveVoltage) { - m_leftMotor.SetVoltage(driveVoltage); - m_rightMotor.SetVoltage(driveVoltage); + leftMotor.SetVoltage(driveVoltage); + rightMotor.SetVoltage(driveVoltage); }, [this](wpi::sysid::SysIdRoutineLog* log) { log->Motor("drive-left") - .voltage(m_leftMotor.GetThrottle() * + .voltage(leftMotor.GetThrottle() * wpi::RobotController::GetBatteryVoltage()) - .position(wpi::units::meter_t{m_leftEncoder.GetDistance()}) + .position(wpi::units::meter_t{leftEncoder.GetDistance()}) .velocity( - wpi::units::meters_per_second_t{m_leftEncoder.GetRate()}); + wpi::units::meters_per_second_t{leftEncoder.GetRate()}); log->Motor("drive-right") - .voltage(m_rightMotor.GetThrottle() * + .voltage(rightMotor.GetThrottle() * wpi::RobotController::GetBatteryVoltage()) - .position(wpi::units::meter_t{m_rightEncoder.GetDistance()}) + .position(wpi::units::meter_t{rightEncoder.GetDistance()}) .velocity( - wpi::units::meters_per_second_t{m_rightEncoder.GetRate()}); + wpi::units::meters_per_second_t{rightEncoder.GetRate()}); }, this}}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp index ce9c3933472..a78950f87cf 100644 --- a/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp +++ b/wpilibcExamples/src/main/cpp/examples/SysIdRoutine/include/subsystems/Shooter.hpp @@ -25,30 +25,30 @@ class Shooter : public wpi::cmd::SubsystemBase { wpi::cmd::CommandPtr SysIdDynamic(wpi::cmd::sysid::Direction direction); private: - wpi::PWMSparkMax m_shooterMotor{constants::shooter::kShooterMotorPort}; - wpi::PWMSparkMax m_feederMotor{constants::shooter::kFeederMotorPort}; + wpi::PWMSparkMax shooterMotor{constants::shooter::kShooterMotorPort}; + wpi::PWMSparkMax feederMotor{constants::shooter::kFeederMotorPort}; - wpi::Encoder m_shooterEncoder{constants::shooter::kEncoderPorts[0], - constants::shooter::kEncoderPorts[1], - constants::shooter::kEncoderReversed}; + wpi::Encoder shooterEncoder{constants::shooter::kEncoderPorts[0], + constants::shooter::kEncoderPorts[1], + constants::shooter::kEncoderReversed}; - wpi::cmd::sysid::SysIdRoutine m_sysIdRoutine{ + wpi::cmd::sysid::SysIdRoutine sysIdRoutine{ wpi::cmd::sysid::Config{std::nullopt, std::nullopt, std::nullopt, nullptr}, wpi::cmd::sysid::Mechanism{ [this](wpi::units::volt_t driveVoltage) { - m_shooterMotor.SetVoltage(driveVoltage); + shooterMotor.SetVoltage(driveVoltage); }, [this](wpi::sysid::SysIdRoutineLog* log) { log->Motor("shooter-wheel") - .voltage(m_shooterMotor.GetThrottle() * + .voltage(shooterMotor.GetThrottle() * wpi::RobotController::GetBatteryVoltage()) - .position(wpi::units::turn_t{m_shooterEncoder.GetDistance()}) + .position(wpi::units::turn_t{shooterEncoder.GetDistance()}) .velocity( - wpi::units::turns_per_second_t{m_shooterEncoder.GetRate()}); + wpi::units::turns_per_second_t{shooterEncoder.GetRate()}); }, this}}; - wpi::math::PIDController m_shooterFeedback{constants::shooter::kP, 0, 0}; - wpi::math::SimpleMotorFeedforward m_shooterFeedforward{ + wpi::math::PIDController shooterFeedback{constants::shooter::kP, 0, 0}; + wpi::math::SimpleMotorFeedforward shooterFeedforward{ constants::shooter::kS, constants::shooter::kV, constants::shooter::kA}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/TankDriveGamepad/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/TankDriveGamepad/cpp/Robot.cpp index a4a8e57d89e..ad87de56f40 100644 --- a/wpilibcExamples/src/main/cpp/examples/TankDriveGamepad/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/TankDriveGamepad/cpp/Robot.cpp @@ -12,28 +12,28 @@ * Runs the motors with tank steering and a gamepad. */ class Robot : public wpi::TimedRobot { - wpi::PWMSparkMax m_leftMotor{0}; - wpi::PWMSparkMax m_rightMotor{1}; - wpi::DifferentialDrive m_robotDrive{ - [&](double output) { m_leftMotor.SetThrottle(output); }, - [&](double output) { m_rightMotor.SetThrottle(output); }}; - wpi::Gamepad m_driverController{0}; + wpi::PWMSparkMax leftMotor{0}; + wpi::PWMSparkMax rightMotor{1}; + wpi::DifferentialDrive robotDrive{ + [&](double output) { leftMotor.SetThrottle(output); }, + [&](double output) { rightMotor.SetThrottle(output); }}; + wpi::Gamepad driverController{0}; public: Robot() { - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor); - wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor); + wpi::util::SendableRegistry::AddChild(&robotDrive, &leftMotor); + wpi::util::SendableRegistry::AddChild(&robotDrive, &rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.SetInverted(true); + rightMotor.SetInverted(true); } void TeleopPeriodic() override { // Drive with tank style - m_robotDrive.TankDrive(-m_driverController.GetLeftY(), - -m_driverController.GetRightY()); + robotDrive.TankDrive(-driverController.GetLeftY(), + -driverController.GetRightY()); } }; diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp index 3eec6fb6d2f..fe1c7e1466a 100644 --- a/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/Robot.cpp @@ -9,18 +9,18 @@ */ void Robot::TeleopPeriodic() { // Activate the intake while the trigger is held - if (m_joystick.GetTrigger()) { - m_intake.Activate(IntakeConstants::kIntakeVelocity); + if (joystick.GetTrigger()) { + intake.Activate(IntakeConstants::kIntakeVelocity); } else { - m_intake.Activate(0); + intake.Activate(0); } // Toggle deploying the intake when the top button is pressed - if (m_joystick.GetTop()) { - if (m_intake.IsDeployed()) { - m_intake.Retract(); + if (joystick.GetTop()) { + if (intake.IsDeployed()) { + intake.Retract(); } else { - m_intake.Deploy(); + intake.Deploy(); } } } diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp index 4b929ee93c3..28629e3b57b 100644 --- a/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp +++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/cpp/subsystems/Intake.cpp @@ -5,22 +5,22 @@ #include "subsystems/Intake.hpp" void Intake::Deploy() { - m_piston.Set(wpi::DoubleSolenoid::Value::FORWARD); + piston.Set(wpi::DoubleSolenoid::Value::FORWARD); } void Intake::Retract() { - m_piston.Set(wpi::DoubleSolenoid::Value::REVERSE); - m_motor.SetThrottle(0); // turn off the motor + piston.Set(wpi::DoubleSolenoid::Value::REVERSE); + motor.SetThrottle(0); // turn off the motor } void Intake::Activate(double velocity) { if (IsDeployed()) { - m_motor.SetThrottle(velocity); + motor.SetThrottle(velocity); } else { // if piston isn't open, do nothing - m_motor.SetThrottle(0); + motor.SetThrottle(0); } } bool Intake::IsDeployed() const { - return m_piston.Get() == wpi::DoubleSolenoid::Value::FORWARD; + return piston.Get() == wpi::DoubleSolenoid::Value::FORWARD; } diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.hpp index 00091b1deba..8faad9e842c 100644 --- a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/Robot.hpp @@ -14,6 +14,6 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override; private: - Intake m_intake; - wpi::Joystick m_joystick{OperatorConstants::kJoystickIndex}; + Intake intake; + wpi::Joystick joystick{OperatorConstants::kJoystickIndex}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.hpp b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.hpp index 3d0c33b5f1d..00730443f24 100644 --- a/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.hpp +++ b/wpilibcExamples/src/main/cpp/examples/UnitTest/include/subsystems/Intake.hpp @@ -16,8 +16,8 @@ class Intake { bool IsDeployed() const; private: - wpi::PWMSparkMax m_motor{IntakeConstants::kMotorPort}; - wpi::DoubleSolenoid m_piston{0, wpi::PneumaticsModuleType::CTRE_PCM, - IntakeConstants::kPistonFwdChannel, - IntakeConstants::kPistonRevChannel}; + wpi::PWMSparkMax motor{IntakeConstants::kMotorPort}; + wpi::DoubleSolenoid piston{0, wpi::PneumaticsModuleType::CTRE_PCM, + IntakeConstants::kPistonFwdChannel, + IntakeConstants::kPistonRevChannel}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/Robot.cpp index 2ec33e67708..dd9c9161d43 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/Robot.cpp @@ -34,10 +34,10 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand != nullptr) { - wpi::cmd::CommandScheduler::GetInstance().Schedule(m_autonomousCommand); + if (autonomousCommand != nullptr) { + wpi::cmd::CommandScheduler::GetInstance().Schedule(autonomousCommand); } } @@ -48,9 +48,9 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != nullptr) { - m_autonomousCommand->Cancel(); - m_autonomousCommand = nullptr; + if (autonomousCommand != nullptr) { + autonomousCommand->Cancel(); + autonomousCommand = nullptr; } } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/RobotContainer.cpp index bc68d859674..f7516fe8680 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/RobotContainer.cpp @@ -16,28 +16,28 @@ RobotContainer::RobotContainer() { void RobotContainer::ConfigureButtonBindings() { // Also set default commands here - m_drive.SetDefaultCommand(TeleopArcadeDrive( - &m_drive, [this] { return -m_controller.GetRawAxis(1); }, - [this] { return -m_controller.GetRawAxis(2); })); + drive.SetDefaultCommand(TeleopArcadeDrive( + &drive, [this] { return -controller.GetRawAxis(1); }, + [this] { return -controller.GetRawAxis(2); })); // Example of how to use the onboard IO - m_userButton.OnTrue(wpi::cmd::Print("USER Button Pressed")) + userButton.OnTrue(wpi::cmd::Print("USER Button Pressed")) .OnFalse(wpi::cmd::Print("USER Button Released")); - wpi::cmd::JoystickButton(&m_controller, 1) - .OnTrue(wpi::cmd::RunOnce([this] { m_arm.SetAngle(45_deg); }, {})) - .OnFalse(wpi::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {})); + wpi::cmd::JoystickButton(&controller, 1) + .OnTrue(wpi::cmd::RunOnce([this] { arm.SetAngle(45_deg); }, {})) + .OnFalse(wpi::cmd::RunOnce([this] { arm.SetAngle(0_deg); }, {})); - wpi::cmd::JoystickButton(&m_controller, 2) - .OnTrue(wpi::cmd::RunOnce([this] { m_arm.SetAngle(90_deg); }, {})) - .OnFalse(wpi::cmd::RunOnce([this] { m_arm.SetAngle(0_deg); }, {})); + wpi::cmd::JoystickButton(&controller, 2) + .OnTrue(wpi::cmd::RunOnce([this] { arm.SetAngle(90_deg); }, {})) + .OnFalse(wpi::cmd::RunOnce([this] { arm.SetAngle(0_deg); }, {})); // Setup SmartDashboard options. - m_chooser.SetDefaultOption("Auto Routine Distance", &m_autoDistance); - m_chooser.AddOption("Auto Routine Time", &m_autoTime); - wpi::SmartDashboard::PutData("Auto Selector", &m_chooser); + chooser.SetDefaultOption("Auto Routine Distance", &autoDistance); + chooser.AddOption("Auto Routine Time", &autoTime); + wpi::SmartDashboard::PutData("Auto Selector", &chooser); } wpi::cmd::Command* RobotContainer::GetAutonomousCommand() { - return m_chooser.GetSelected(); + return chooser.GetSelected(); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp index a34b01b1afe..d3d186cff2d 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveDistance.cpp @@ -7,18 +7,18 @@ #include "wpi/units/math.hpp" void DriveDistance::Initialize() { - m_drive->ArcadeDrive(0, 0); - m_drive->ResetEncoders(); + drive->ArcadeDrive(0, 0); + drive->ResetEncoders(); } void DriveDistance::Execute() { - m_drive->ArcadeDrive(m_velocity, 0); + drive->ArcadeDrive(velocity, 0); } void DriveDistance::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); + drive->ArcadeDrive(0, 0); } bool DriveDistance::IsFinished() { - return wpi::units::math::abs(m_drive->GetAverageDistance()) >= m_distance; + return wpi::units::math::abs(drive->GetAverageDistance()) >= distance; } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveTime.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveTime.cpp index f1be542fdd1..68adcd297b0 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveTime.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/DriveTime.cpp @@ -5,20 +5,20 @@ #include "commands/DriveTime.hpp" void DriveTime::Initialize() { - m_timer.Start(); - m_drive->ArcadeDrive(0, 0); + timer.Start(); + drive->ArcadeDrive(0, 0); } void DriveTime::Execute() { - m_drive->ArcadeDrive(m_velocity, 0); + drive->ArcadeDrive(velocity, 0); } void DriveTime::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); - m_timer.Stop(); - m_timer.Reset(); + drive->ArcadeDrive(0, 0); + timer.Stop(); + timer.Reset(); } bool DriveTime::IsFinished() { - return m_timer.HasElapsed(m_duration); + return timer.HasElapsed(duration); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TeleopArcadeDrive.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TeleopArcadeDrive.cpp index 76d0d8bd4f0..f8006fd8f4c 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TeleopArcadeDrive.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TeleopArcadeDrive.cpp @@ -9,12 +9,12 @@ TeleopArcadeDrive::TeleopArcadeDrive( Drivetrain* subsystem, std::function xaxisVelocitySupplier, std::function zaxisRotateSuppplier) - : m_drive{subsystem}, - m_xaxisVelocitySupplier{xaxisVelocitySupplier}, - m_zaxisRotateSupplier{zaxisRotateSuppplier} { + : drive{subsystem}, + xaxisVelocitySupplier{xaxisVelocitySupplier}, + zaxisRotateSupplier{zaxisRotateSuppplier} { AddRequirements(subsystem); } void TeleopArcadeDrive::Execute() { - m_drive->ArcadeDrive(m_xaxisVelocitySupplier(), m_zaxisRotateSupplier()); + drive->ArcadeDrive(xaxisVelocitySupplier(), zaxisRotateSupplier()); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp index 93ebe880d33..b2e09655f5a 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnDegrees.cpp @@ -10,16 +10,16 @@ void TurnDegrees::Initialize() { // Set motors to stop, read encoder values for starting point - m_drive->ArcadeDrive(0, 0); - m_drive->ResetEncoders(); + drive->ArcadeDrive(0, 0); + drive->ResetEncoders(); } void TurnDegrees::Execute() { - m_drive->ArcadeDrive(0, m_velocity); + drive->ArcadeDrive(0, velocity); } void TurnDegrees::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); + drive->ArcadeDrive(0, 0); } bool TurnDegrees::IsFinished() { @@ -30,11 +30,11 @@ bool TurnDegrees::IsFinished() { static auto inchPerDegree = (6.102_in * std::numbers::pi) / 360_deg; // Compare distance traveled from start to distance based on degree turn. - return GetAverageTurningDistance() >= inchPerDegree * m_angle; + return GetAverageTurningDistance() >= inchPerDegree * angle; } wpi::units::meter_t TurnDegrees::GetAverageTurningDistance() { - auto l = wpi::units::math::abs(m_drive->GetLeftDistance()); - auto r = wpi::units::math::abs(m_drive->GetRightDistance()); + auto l = wpi::units::math::abs(drive->GetLeftDistance()); + auto r = wpi::units::math::abs(drive->GetRightDistance()); return (l + r) / 2; } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnTime.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnTime.cpp index fb040614755..88e8f63bf7f 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnTime.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/commands/TurnTime.cpp @@ -5,20 +5,20 @@ #include "commands/TurnTime.hpp" void TurnTime::Initialize() { - m_timer.Start(); - m_drive->ArcadeDrive(0, 0); + timer.Start(); + drive->ArcadeDrive(0, 0); } void TurnTime::Execute() { - m_drive->ArcadeDrive(0, m_velocity); + drive->ArcadeDrive(0, velocity); } void TurnTime::End(bool interrupted) { - m_drive->ArcadeDrive(0, 0); - m_timer.Stop(); - m_timer.Reset(); + drive->ArcadeDrive(0, 0); + timer.Stop(); + timer.Reset(); } bool TurnTime::IsFinished() { - return m_timer.HasElapsed(m_duration); + return timer.HasElapsed(duration); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp index ad3c122a7e7..4dcd1d5d37b 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Arm.cpp @@ -9,5 +9,5 @@ void Arm::Periodic() { } void Arm::SetAngle(wpi::units::radian_t angle) { - m_armServo.SetAngle(angle); + armServo.SetAngle(angle); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp index 8904985febb..f57d0b02af8 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/cpp/subsystems/Drivetrain.cpp @@ -15,18 +15,18 @@ using namespace DriveConstants; // The XRP has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right Drivetrain::Drivetrain() { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_leftMotor); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_rightMotor); + wpi::util::SendableRegistry::AddChild(&drive, &leftMotor); + wpi::util::SendableRegistry::AddChild(&drive, &rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.SetInverted(true); + rightMotor.SetInverted(true); - m_leftEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / - kCountsPerRevolution); - m_rightEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / - kCountsPerRevolution); + leftEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / + kCountsPerRevolution); + rightEncoder.SetDistancePerPulse(std::numbers::pi * kWheelDiameter.value() / + kCountsPerRevolution); ResetEncoders(); } @@ -35,28 +35,28 @@ void Drivetrain::Periodic() { } void Drivetrain::ArcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_drive.ArcadeDrive(xaxisVelocity, zaxisRotate); + drive.ArcadeDrive(xaxisVelocity, zaxisRotate); } void Drivetrain::ResetEncoders() { - m_leftEncoder.Reset(); - m_rightEncoder.Reset(); + leftEncoder.Reset(); + rightEncoder.Reset(); } int Drivetrain::GetLeftEncoderCount() { - return m_leftEncoder.Get(); + return leftEncoder.Get(); } int Drivetrain::GetRightEncoderCount() { - return m_rightEncoder.Get(); + return rightEncoder.Get(); } wpi::units::meter_t Drivetrain::GetLeftDistance() { - return wpi::units::meter_t{m_leftEncoder.GetDistance()}; + return wpi::units::meter_t{leftEncoder.GetDistance()}; } wpi::units::meter_t Drivetrain::GetRightDistance() { - return wpi::units::meter_t{m_rightEncoder.GetDistance()}; + return wpi::units::meter_t{rightEncoder.GetDistance()}; } wpi::units::meter_t Drivetrain::GetAverageDistance() { @@ -64,17 +64,17 @@ wpi::units::meter_t Drivetrain::GetAverageDistance() { } wpi::units::radian_t Drivetrain::GetGyroAngleX() { - return m_gyro.GetAngleX(); + return gyro.GetAngleX(); } wpi::units::radian_t Drivetrain::GetGyroAngleY() { - return m_gyro.GetAngleY(); + return gyro.GetAngleY(); } wpi::units::radian_t Drivetrain::GetGyroAngleZ() { - return m_gyro.GetAngleZ(); + return gyro.GetAngleZ(); } void Drivetrain::ResetGyro() { - m_gyro.Reset(); + gyro.Reset(); } diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/Robot.hpp index 2d2e802c163..afb6d52b149 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/Robot.hpp @@ -23,6 +23,6 @@ class Robot : public wpi::TimedRobot { private: // Have it null by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - wpi::cmd::Command* m_autonomousCommand = nullptr; - RobotContainer m_container; + wpi::cmd::Command* autonomousCommand = nullptr; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/RobotContainer.hpp index a82f8a5d9e1..be8a94a5af5 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/RobotContainer.hpp @@ -42,21 +42,21 @@ class RobotContainer { private: // Assumes a gamepad plugged into channel 0 - wpi::Joystick m_controller{0}; - wpi::SendableChooser m_chooser; + wpi::Joystick controller{0}; + wpi::SendableChooser chooser; // The robot's subsystems - Drivetrain m_drive; - Arm m_arm; - wpi::xrp::XRPOnBoardIO m_onboardIO; + Drivetrain drive; + Arm arm; + wpi::xrp::XRPOnBoardIO onboardIO; // Example button - wpi::cmd::Trigger m_userButton{ - [this] { return m_onboardIO.GetUserButtonPressed(); }}; + wpi::cmd::Trigger userButton{ + [this] { return onboardIO.GetUserButtonPressed(); }}; // Autonomous commands. - AutonomousDistance m_autoDistance{&m_drive}; - AutonomousTime m_autoTime{&m_drive}; + AutonomousDistance autoDistance{&drive}; + AutonomousTime autoTime{&drive}; void ConfigureButtonBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp index e5ea1cc2c91..9b2a3f33790 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveDistance.hpp @@ -22,8 +22,8 @@ class DriveDistance */ DriveDistance(double velocity, wpi::units::meter_t distance, Drivetrain* drive) - : m_velocity(velocity), m_distance(distance), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), distance(distance), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -32,7 +32,7 @@ class DriveDistance bool IsFinished() override; private: - double m_velocity; - wpi::units::meter_t m_distance; - Drivetrain* m_drive; + double velocity; + wpi::units::meter_t distance; + Drivetrain* drive; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp index f0b05af0d48..fc3a458268d 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/DriveTime.hpp @@ -22,8 +22,8 @@ class DriveTime : public wpi::cmd::CommandHelper { * @param drive The drivetrain subsystem on which this command will run */ DriveTime(double velocity, wpi::units::second_t time, Drivetrain* drive) - : m_velocity(velocity), m_duration(time), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), duration(time), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -32,8 +32,8 @@ class DriveTime : public wpi::cmd::CommandHelper { bool IsFinished() override; private: - double m_velocity; - wpi::units::second_t m_duration; - Drivetrain* m_drive; - wpi::Timer m_timer; + double velocity; + wpi::units::second_t duration; + Drivetrain* drive; + wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TeleopArcadeDrive.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TeleopArcadeDrive.hpp index b5ab55d0a00..b46029f595a 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TeleopArcadeDrive.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TeleopArcadeDrive.hpp @@ -27,7 +27,7 @@ class TeleopArcadeDrive void Execute() override; private: - Drivetrain* m_drive; - std::function m_xaxisVelocitySupplier; - std::function m_zaxisRotateSupplier; + Drivetrain* drive; + std::function xaxisVelocitySupplier; + std::function zaxisRotateSupplier; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp index 770781b4e9d..42d1add8e43 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnDegrees.hpp @@ -23,8 +23,8 @@ class TurnDegrees * @param drive The drive subsystem on which this command will run */ TurnDegrees(double velocity, wpi::units::degree_t angle, Drivetrain* drive) - : m_velocity(velocity), m_angle(angle), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), angle(angle), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -33,9 +33,9 @@ class TurnDegrees bool IsFinished() override; private: - double m_velocity; - wpi::units::degree_t m_angle; - Drivetrain* m_drive; + double velocity; + wpi::units::degree_t angle; + Drivetrain* drive; wpi::units::meter_t GetAverageTurningDistance(); }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp index c7fe21f761b..24e179c8c66 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/commands/TurnTime.hpp @@ -21,8 +21,8 @@ class TurnTime : public wpi::cmd::CommandHelper { * @param drive The drive subsystem on which this command will run */ TurnTime(double velocity, wpi::units::second_t time, Drivetrain* drive) - : m_velocity(velocity), m_duration(time), m_drive(drive) { - AddRequirements(m_drive); + : velocity(velocity), duration(time), drive(drive) { + AddRequirements(drive); } void Initialize() override; @@ -31,8 +31,8 @@ class TurnTime : public wpi::cmd::CommandHelper { bool IsFinished() override; private: - double m_velocity; - wpi::units::second_t m_duration; - Drivetrain* m_drive; - wpi::Timer m_timer; + double velocity; + wpi::units::second_t duration; + Drivetrain* drive; + wpi::Timer timer; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp index ea337114403..d7b11493fa8 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Arm.hpp @@ -23,5 +23,5 @@ class Arm : public wpi::cmd::SubsystemBase { void SetAngle(wpi::units::radian_t angle); private: - wpi::xrp::XRPServo m_armServo{4}; + wpi::xrp::XRPServo armServo{4}; }; diff --git a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp index 9481144319e..421d583d972 100644 --- a/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp +++ b/wpilibcExamples/src/main/cpp/examples/XRPReference/include/subsystems/Drivetrain.hpp @@ -104,15 +104,15 @@ class Drivetrain : public wpi::cmd::SubsystemBase { void ResetGyro(); private: - wpi::xrp::XRPMotor m_leftMotor{0}; - wpi::xrp::XRPMotor m_rightMotor{1}; + wpi::xrp::XRPMotor leftMotor{0}; + wpi::xrp::XRPMotor rightMotor{1}; - wpi::Encoder m_leftEncoder{4, 5}; - wpi::Encoder m_rightEncoder{6, 7}; + wpi::Encoder leftEncoder{4, 5}; + wpi::Encoder rightEncoder{6, 7}; - wpi::DifferentialDrive m_drive{ - [&](double output) { m_leftMotor.SetThrottle(output); }, - [&](double output) { m_rightMotor.SetThrottle(output); }}; + wpi::DifferentialDrive drive{ + [&](double output) { leftMotor.SetThrottle(output); }, + [&](double output) { rightMotor.SetThrottle(output); }}; - wpi::xrp::XRPGyro m_gyro; + wpi::xrp::XRPGyro gyro; }; diff --git a/wpilibcExamples/src/main/cpp/examples/Xrptimed/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Xrptimed/cpp/Robot.cpp index 5254620c9c8..8bc48fc2765 100644 --- a/wpilibcExamples/src/main/cpp/examples/Xrptimed/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Xrptimed/cpp/Robot.cpp @@ -5,13 +5,13 @@ #include "Robot.hpp" Robot::Robot() { - wpi::util::SendableRegistry::AddChild(&m_drive, &m_leftMotor); - wpi::util::SendableRegistry::AddChild(&m_drive, &m_rightMotor); + wpi::util::SendableRegistry::AddChild(&drive, &leftMotor); + wpi::util::SendableRegistry::AddChild(&drive, &rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.SetInverted(true); + rightMotor.SetInverted(true); } /** @@ -26,18 +26,18 @@ void Robot::RobotPeriodic() {} // This function is only once each time Autonomous is enabled void Robot::AutonomousInit() { - m_timer.Restart(); + timer.Restart(); } // This function is called periodically during autonomous mode void Robot::AutonomousPeriodic() { // Drive for 2 seconds - if (m_timer.Get() < 2_s) { + if (timer.Get() < 2_s) { // Drive forwards half speed, make sure to turn input squaring off - m_drive.ArcadeDrive(0.5, 0.0, false); + drive.ArcadeDrive(0.5, 0.0, false); } else { // Stop robot - m_drive.ArcadeDrive(0.0, 0.0, false); + drive.ArcadeDrive(0.0, 0.0, false); } } @@ -46,7 +46,7 @@ void Robot::TeleopInit() {} // This function is called periodically during teleop mode void Robot::TeleopPeriodic() { - m_drive.ArcadeDrive(-m_controller.GetRawAxis(2), -m_controller.GetRawAxis(1)); + drive.ArcadeDrive(-controller.GetRawAxis(2), -controller.GetRawAxis(1)); } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/examples/Xrptimed/include/Robot.hpp b/wpilibcExamples/src/main/cpp/examples/Xrptimed/include/Robot.hpp index 9c536e4ff9a..5b1f7522d05 100644 --- a/wpilibcExamples/src/main/cpp/examples/Xrptimed/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/examples/Xrptimed/include/Robot.hpp @@ -20,13 +20,13 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override; private: - wpi::xrp::XRPMotor m_leftMotor{0}; - wpi::xrp::XRPMotor m_rightMotor{1}; + wpi::xrp::XRPMotor leftMotor{0}; + wpi::xrp::XRPMotor rightMotor{1}; // Assumes a gamepad plugged into channel 0 - wpi::Joystick m_controller{0}; - wpi::Timer m_timer; + wpi::Joystick controller{0}; + wpi::Timer timer; - wpi::DifferentialDrive m_drive{ - [&](double output) { m_leftMotor.SetThrottle(output); }, - [&](double output) { m_rightMotor.SetThrottle(output); }}; + wpi::DifferentialDrive drive{ + [&](double output) { leftMotor.SetThrottle(output); }, + [&](double output) { rightMotor.SetThrottle(output); }}; }; diff --git a/wpilibcExamples/src/main/cpp/snippets/ADXLAccelerometers/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/ADXLAccelerometers/cpp/Robot.cpp index fc808d93b7c..e69f0ec3dbc 100644 --- a/wpilibcExamples/src/main/cpp/snippets/ADXLAccelerometers/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/ADXLAccelerometers/cpp/Robot.cpp @@ -16,17 +16,17 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Gets the current acceleration in the X axis - m_accelerometer.GetX(); + accelerometer.GetX(); // Gets the current acceleration in the Y axis - m_accelerometer.GetY(); + accelerometer.GetY(); // Gets the current acceleration in the Z axis - m_accelerometer.GetZ(); + accelerometer.GetZ(); } private: // Creates an ADXL345 accelerometer object with a measurement range from -8 to // 8 G's - wpi::ADXL345_I2C m_accelerometer{wpi::I2C::Port::PORT_0, 8}; + wpi::ADXL345_I2C accelerometer{wpi::I2C::Port::PORT_0, 8}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp index ab1f7278b31..3c32c93eb08 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AccelerometerCollision/cpp/Robot.cpp @@ -15,22 +15,22 @@ class Robot : public wpi::TimedRobot { public: void RobotPeriodic() override { // Gets the current accelerations in the X and Y directions - auto xAccel = m_accelerometer.GetAccelX(); - auto yAccel = m_accelerometer.GetAccelY(); + auto xAccel = accelerometer.GetAccelX(); + auto yAccel = accelerometer.GetAccelY(); // Calculates the jerk in the X and Y directions - auto xJerk = (xAccel - m_prevXAccel) / GetPeriod(); - auto yJerk = (yAccel - m_prevYAccel) / GetPeriod(); - m_prevXAccel = xAccel; - m_prevYAccel = yAccel; + auto xJerk = (xAccel - prevXAccel) / GetPeriod(); + auto yJerk = (yAccel - prevYAccel) / GetPeriod(); + prevXAccel = xAccel; + prevYAccel = yAccel; wpi::SmartDashboard::PutNumber("X Jerk", xJerk.value()); wpi::SmartDashboard::PutNumber("Y Jerk", yJerk.value()); } private: - wpi::units::meters_per_second_squared_t m_prevXAccel = 0.0_mps_sq; - wpi::units::meters_per_second_squared_t m_prevYAccel = 0.0_mps_sq; - wpi::OnboardIMU m_accelerometer{wpi::OnboardIMU::MountOrientation::FLAT}; + wpi::units::meters_per_second_squared_t prevXAccel = 0.0_mps_sq; + wpi::units::meters_per_second_squared_t prevYAccel = 0.0_mps_sq; + wpi::OnboardIMU accelerometer{wpi::OnboardIMU::MountOrientation::FLAT}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp index ac6ebaf457e..112adf57802 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AccelerometerFilter/cpp/Robot.cpp @@ -15,11 +15,10 @@ class Robot : public wpi::TimedRobot { public: void RobotPeriodic() override { - wpi::units::meters_per_second_squared_t XAccel = - m_accelerometer.GetAccelX(); + wpi::units::meters_per_second_squared_t XAccel = accelerometer.GetAccelX(); // Get the filtered X acceleration wpi::units::meters_per_second_squared_t filteredXAccel = - m_xAccelFilter.Calculate(XAccel); + xAccelFilter.Calculate(XAccel); wpi::SmartDashboard::PutNumber("X Acceleration", XAccel.value()); wpi::SmartDashboard::PutNumber("Filtered X Acceleration", @@ -27,9 +26,9 @@ class Robot : public wpi::TimedRobot { } private: - wpi::OnboardIMU m_accelerometer{wpi::OnboardIMU::MountOrientation::FLAT}; + wpi::OnboardIMU accelerometer{wpi::OnboardIMU::MountOrientation::FLAT}; wpi::math::LinearFilter - m_xAccelFilter = wpi::math::LinearFilter< + xAccelFilter = wpi::math::LinearFilter< wpi::units::meters_per_second_squared_t>::MovingAverage(10); }; diff --git a/wpilibcExamples/src/main/cpp/snippets/AddressableLED/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AddressableLED/cpp/Robot.cpp index 69349427c51..cbdd1e7f1dd 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AddressableLED/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AddressableLED/cpp/Robot.cpp @@ -6,15 +6,15 @@ Robot::Robot() { // Default to a length of 60, start empty output - m_led.SetLength(kLength); - m_led.SetData(m_ledBuffer); + led.SetLength(kLength); + led.SetData(ledBuffer); } void Robot::RobotPeriodic() { // Run the rainbow pattern and apply it to the buffer - m_scrollingRainbow.ApplyTo(m_ledBuffer); + scrollingRainbow.ApplyTo(ledBuffer); // Set the LEDs - m_led.SetData(m_ledBuffer); + led.SetData(ledBuffer); } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp b/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp index c5e7422a7a6..33c3966516e 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/snippets/AddressableLED/include/Robot.hpp @@ -19,19 +19,19 @@ class Robot : public wpi::TimedRobot { static constexpr int kLength = 60; // SmartIO port 1 - wpi::AddressableLED m_led{1}; + wpi::AddressableLED led{1}; std::array - m_ledBuffer; // Reuse the buffer + ledBuffer; // Reuse the buffer // Our LED strip has a density of 120 LEDs per meter wpi::units::meter_t kLedSpacing{1 / 120.0}; // Create an LED pattern that will display a rainbow across // all hues at maximum saturation and half brightness - wpi::LEDPattern m_rainbow = wpi::LEDPattern::Rainbow(255, 128); + wpi::LEDPattern rainbow = wpi::LEDPattern::Rainbow(255, 128); // Create a new pattern that scrolls the rainbow pattern across the LED // strip, moving at a velocity of 1 meter per second. - wpi::LEDPattern m_scrollingRainbow = - m_rainbow.ScrollAtAbsoluteVelocity(1_mps, kLedSpacing); + wpi::LEDPattern scrollingRainbow = + rainbow.ScrollAtAbsoluteVelocity(1_mps, kLedSpacing); }; diff --git a/wpilibcExamples/src/main/cpp/snippets/AnalogAccelerometer/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AnalogAccelerometer/cpp/Robot.cpp index d3874dbd480..67e0876a757 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AnalogAccelerometer/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AnalogAccelerometer/cpp/Robot.cpp @@ -14,19 +14,19 @@ class Robot : public wpi::TimedRobot { public: Robot() { // Sets the sensitivity of the accelerometer to 1 volt per G - m_accelerometer.SetSensitivity(1); + accelerometer.SetSensitivity(1); // Sets the zero voltage of the accelerometer to 3 volts - m_accelerometer.SetZero(3); + accelerometer.SetZero(3); } void TeleopPeriodic() override { // Gets the current acceleration - m_accelerometer.GetAcceleration(); + accelerometer.GetAcceleration(); } private: // Creates an analog accelerometer on analog input 0 - wpi::AnalogAccelerometer m_accelerometer{0}; + wpi::AnalogAccelerometer accelerometer{0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AnalogEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AnalogEncoder/cpp/Robot.cpp index 2bf4dd9efbc..a3f03f4d546 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AnalogEncoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AnalogEncoder/cpp/Robot.cpp @@ -15,17 +15,17 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Gets the rotation - m_encoder.Get(); + encoder.Get(); } private: // Initializes an analog encoder on Analog Input pin 0 - wpi::AnalogEncoder m_encoder{0}; + wpi::AnalogEncoder encoder{0}; // Initializes an analog encoder on DIO pins 0 to return a value of 4 for // a full rotation, with the encoder reporting 0 half way through rotation (2 // out of 4) - wpi::AnalogEncoder m_encoderFR{0, 4.0, 2.0}; + wpi::AnalogEncoder encoderFR{0, 4.0, 2.0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp index 79a8e254882..47edf6fda38 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AnalogInput/cpp/Robot.cpp @@ -15,18 +15,18 @@ class Robot : public wpi::TimedRobot { // Gets the raw instantaneous measured value from the analog input, without // applying any calibration and ignoring oversampling and averaging // settings. - m_analog.GetValue(); + analog.GetValue(); // Gets the instantaneous measured voltage from the analog input. // Oversampling and averaging settings are ignored - m_analog.GetVoltage(); + analog.GetVoltage(); } void TeleopPeriodic() override {} private: // Initializes an AnalogInput on port 0 - wpi::AnalogInput m_analog{0}; + wpi::AnalogInput analog{0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp index f4b4e87b375..26c727b4990 100644 --- a/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/AnalogPotentiometer/cpp/Robot.cpp @@ -16,7 +16,7 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Get the value of the potentiometer - m_pot.Get(); + pot.Get(); } private: @@ -24,15 +24,15 @@ class Robot : public wpi::TimedRobot { // The full range of motion (in meaningful external units) is 0-180 (this // could be degrees, for instance) The "starting point" of the motion, i.e. // where the mechanism is located when the potentiometer reads 0v, is 30. - wpi::AnalogPotentiometer m_pot{0, 180, 30}; + wpi::AnalogPotentiometer pot{0, 180, 30}; // Initializes an AnalogInput on port 1 - wpi::AnalogInput m_input{1}; + wpi::AnalogInput input{1}; // Initializes an AnalogPotentiometer with the given AnalogInput // The full range of motion (in meaningful external units) is 0-180 (this // could be degrees, for instance) The "starting point" of the motion, i.e. // where the mechanism is located when the potentiometer reads 0v, is 30. - wpi::AnalogPotentiometer m_pot1{&m_input, 180, 30}; + wpi::AnalogPotentiometer pot1{&input, 180, 30}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/CANPDP/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/CANPDP/cpp/Robot.cpp index b12634b8f3d..e1e490bc923 100644 --- a/wpilibcExamples/src/main/cpp/snippets/CANPDP/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/CANPDP/cpp/Robot.cpp @@ -15,43 +15,43 @@ class Robot : public wpi::TimedRobot { public: Robot() { // Put the PDP itself to the dashboard - wpi::SmartDashboard::PutData("PDP", &m_pdp); + wpi::SmartDashboard::PutData("PDP", &pdp); } void RobotPeriodic() override { // Get the current going through channel 7, in Amperes. // The PDP returns the current in increments of 0.125A. // At low currents the current readings tend to be less accurate. - double current7 = m_pdp.GetCurrent(7); + double current7 = pdp.GetCurrent(7); wpi::SmartDashboard::PutNumber("Current Channel 7", current7); // Get the voltage going into the PDP, in Volts. // The PDP returns the voltage in increments of 0.05 Volts. - double voltage = m_pdp.GetVoltage(); + double voltage = pdp.GetVoltage(); wpi::SmartDashboard::PutNumber("Voltage", voltage); // Retrieves the temperature of the PDP, in degrees Celsius. - double temperatureCelsius = m_pdp.GetTemperature(); + double temperatureCelsius = pdp.GetTemperature(); wpi::SmartDashboard::PutNumber("Temperature", temperatureCelsius); // Get the total current of all channels. - double totalCurrent = m_pdp.GetTotalCurrent(); + double totalCurrent = pdp.GetTotalCurrent(); wpi::SmartDashboard::PutNumber("Total Current", totalCurrent); // Get the total power of all channels. // Power is the bus voltage multiplied by the current with the units Watts. - double totalPower = m_pdp.GetTotalPower(); + double totalPower = pdp.GetTotalPower(); wpi::SmartDashboard::PutNumber("Total Power", totalPower); // Get the total energy of all channels. // Energy is the power summed over time with units Joules. - double totalEnergy = m_pdp.GetTotalEnergy(); + double totalEnergy = pdp.GetTotalEnergy(); wpi::SmartDashboard::PutNumber("Total Energy", totalEnergy); } private: // Object for dealing with the Power Distribution Panel (PDP). - wpi::PowerDistribution m_pdp{0}; + wpi::PowerDistribution pdp{0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/cpp/Robot.cpp index 0e78d207d98..bdb04f0094e 100644 --- a/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/cpp/Robot.cpp @@ -9,17 +9,17 @@ void Robot::RobotPeriodic() { // pull alliance port high if on red alliance, pull low if on blue alliance - m_allianceOutput.Set(wpi::MatchState::GetAlliance() == wpi::Alliance::RED); + allianceOutput.Set(wpi::MatchState::GetAlliance() == wpi::Alliance::RED); // pull enabled port high if enabled, low if disabled - m_enabledOutput.Set(wpi::RobotState::IsEnabled()); + enabledOutput.Set(wpi::RobotState::IsEnabled()); // pull auto port high if in autonomous, low if in teleop (or disabled) - m_autonomousOutput.Set(wpi::RobotState::IsAutonomous()); + autonomousOutput.Set(wpi::RobotState::IsAutonomous()); // pull alert port high if match time remaining is between 30 and 25 seconds auto matchTime = wpi::MatchState::GetMatchTime(); - m_alertOutput.Set(matchTime <= 30_s && matchTime >= 25_s); + alertOutput.Set(matchTime <= 30_s && matchTime >= 25_s); } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/include/Robot.hpp b/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/include/Robot.hpp index a19dda2f9eb..f813219812c 100644 --- a/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/snippets/DigitalCommunication/include/Robot.hpp @@ -24,8 +24,8 @@ class Robot : public wpi::TimedRobot { void RobotPeriodic() override; private: - wpi::DigitalOutput m_allianceOutput{kAlliancePort}; - wpi::DigitalOutput m_enabledOutput{kEnabledPort}; - wpi::DigitalOutput m_autonomousOutput{kAutonomousPort}; - wpi::DigitalOutput m_alertOutput{kAlertPort}; + wpi::DigitalOutput allianceOutput{kAlliancePort}; + wpi::DigitalOutput enabledOutput{kEnabledPort}; + wpi::DigitalOutput autonomousOutput{kAutonomousPort}; + wpi::DigitalOutput alertOutput{kAlertPort}; }; diff --git a/wpilibcExamples/src/main/cpp/snippets/DigitalInput/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/DigitalInput/cpp/Robot.cpp index 249528a61bf..5a4194c4b17 100644 --- a/wpilibcExamples/src/main/cpp/snippets/DigitalInput/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/DigitalInput/cpp/Robot.cpp @@ -14,12 +14,12 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Gets the value of the digital input. Returns true if the circuit is // open. - m_input.Get(); + input.Get(); } private: // Initializes a DigitalInput on DIO 0 - wpi::DigitalInput m_input{0}; + wpi::DigitalInput input{0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp index a702798ab37..f69ae88facc 100644 --- a/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/DutyCycleEncoder/cpp/Robot.cpp @@ -15,20 +15,20 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Gets the rotation - m_encoder.Get(); + encoder.Get(); // Gets if the encoder is connected - m_encoder.IsConnected(); + encoder.IsConnected(); } private: // Initializes a duty cycle encoder on DIO pins 0 - wpi::DutyCycleEncoder m_encoder{0}; + wpi::DutyCycleEncoder encoder{0}; // Initializes a duty cycle encoder on DIO pins 0 to return a value of 4 for // a full rotation, with the encoder reporting 0 half way through rotation (2 // out of 4) - wpi::DutyCycleEncoder m_encoderFR{0, 4.0, 2.0}; + wpi::DutyCycleEncoder encoderFR{0, 4.0, 2.0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/DutyCycleInput/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/DutyCycleInput/cpp/Robot.cpp index 41819c92fa7..6506e0162cd 100644 --- a/wpilibcExamples/src/main/cpp/snippets/DutyCycleInput/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/DutyCycleInput/cpp/Robot.cpp @@ -8,18 +8,18 @@ #include "wpi/smartdashboard/SmartDashboard.hpp" class Robot : public wpi::TimedRobot { - wpi::DutyCycle m_dutyCycle{0}; // Duty cycle input + wpi::DutyCycle dutyCycle{0}; // Duty cycle input public: Robot() {} void RobotPeriodic() override { // Duty Cycle Frequency in Hz - auto frequency = m_dutyCycle.GetFrequency(); + auto frequency = dutyCycle.GetFrequency(); // Output of duty cycle, ranging from 0 to 1 // 1 is fully on, 0 is fully off - auto output = m_dutyCycle.GetOutput(); + auto output = dutyCycle.GetOutput(); wpi::SmartDashboard::PutNumber("Frequency", frequency.value()); wpi::SmartDashboard::PutNumber("Duty Cycle", output); diff --git a/wpilibcExamples/src/main/cpp/snippets/Encoder/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/Encoder/cpp/Robot.cpp index f9e03228562..a445b26df3e 100644 --- a/wpilibcExamples/src/main/cpp/snippets/Encoder/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/Encoder/cpp/Robot.cpp @@ -16,47 +16,47 @@ class Robot : public wpi::TimedRobot { Robot() { // Configures the encoder to return a distance of 4 for every 256 pulses // Also changes the units of getRate - m_encoder.SetDistancePerPulse(4.0 / 256.0); + encoder.SetDistancePerPulse(4.0 / 256.0); // Configures the encoder to consider itself stopped after .1 seconds - m_encoder.SetMaxPeriod(0.1_s); + encoder.SetMaxPeriod(0.1_s); // Configures the encoder to consider itself stopped when its rate is below // 10 - m_encoder.SetMinRate(10); + encoder.SetMinRate(10); // Reverses the direction of the encoder - m_encoder.SetReverseDirection(true); + encoder.SetReverseDirection(true); // Configures an encoder to average its period measurement over 5 samples // Can be between 1 and 127 samples - m_encoder.SetSamplesToAverage(5); + encoder.SetSamplesToAverage(5); } void TeleopPeriodic() override { // Gets the distance traveled - m_encoder.GetDistance(); + encoder.GetDistance(); // Gets the current rate of the encoder - m_encoder.GetRate(); + encoder.GetRate(); // Gets whether the encoder is stopped - m_encoder.GetStopped(); + encoder.GetStopped(); // Gets the last direction in which the encoder moved - m_encoder.GetDirection(); + encoder.GetDirection(); // Gets the current period of the encoder - m_encoder.GetPeriod(); + encoder.GetPeriod(); // Resets the encoder to read a distance of zero - m_encoder.Reset(); + encoder.Reset(); } private: // Initializes an encoder on DIO pins 0 and 1 // Defaults to 4X decoding and non-inverted - wpi::Encoder m_encoder{0, 1}; + wpi::Encoder encoder{0, 1}; // Initializes an encoder on DIO pins 0 and 1 // 2X encoding and non-inverted - wpi::Encoder m_encoder2x{0, 1, false, wpi::Encoder::EncodingType::X2}; + wpi::Encoder encoder2x{0, 1, false, wpi::Encoder::EncodingType::X2}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/EncoderDrive/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/EncoderDrive/cpp/Robot.cpp index 8fae0701079..e13e2885afe 100644 --- a/wpilibcExamples/src/main/cpp/snippets/EncoderDrive/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/EncoderDrive/cpp/Robot.cpp @@ -17,7 +17,7 @@ class Robot : public wpi::TimedRobot { // Configures the encoder's distance-per-pulse // The robot moves forward 1 foot per encoder rotation // There are 256 pulses per encoder rotation - m_encoder.SetDistancePerPulse(1.0 / 256.0); + encoder.SetDistancePerPulse(1.0 / 256.0); // Invert the right side of the drivetrain. You might have to invert the // other side rightLeader.SetInverted(true); @@ -28,7 +28,7 @@ class Robot : public wpi::TimedRobot { void AutonomousPeriodic() override { // Drives forward at half velocity until the robot has moved 5 feet, then // stops: - if (m_encoder.GetDistance() < 5) { + if (encoder.GetDistance() < 5) { drive.TankDrive(0.5, 0.5); } else { drive.TankDrive(0, 0); @@ -37,7 +37,7 @@ class Robot : public wpi::TimedRobot { private: // Creates an encoder on DIO ports 0 and 1. - wpi::Encoder m_encoder{0, 1}; + wpi::Encoder encoder{0, 1}; // Initialize motor controllers and drive wpi::Spark leftLeader{0}; wpi::Spark leftFollower{1}; diff --git a/wpilibcExamples/src/main/cpp/snippets/EncoderHoming/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/EncoderHoming/cpp/Robot.cpp index 8525d7da903..1f01c5addd2 100644 --- a/wpilibcExamples/src/main/cpp/snippets/EncoderHoming/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/EncoderHoming/cpp/Robot.cpp @@ -16,19 +16,19 @@ class Robot : public wpi::TimedRobot { void AutonomousPeriodic() override { // Runs the motor backwards at half velocity until the limit switch is // pressed then turn off the motor and reset the encoder - if (!m_limit.Get()) { - m_spark.SetThrottle(-0.5); + if (!limit.Get()) { + spark.SetThrottle(-0.5); } else { - m_spark.SetThrottle(0); - m_encoder.Reset(); + spark.SetThrottle(0); + encoder.Reset(); } } private: - wpi::Encoder m_encoder{0, 1}; - wpi::Spark m_spark{0}; + wpi::Encoder encoder{0, 1}; + wpi::Spark spark{0}; // Limit switch on DIO 2 - wpi::DigitalInput m_limit{2}; + wpi::DigitalInput limit{2}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp index 667eb737e38..3f7007ace26 100644 --- a/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/EventLoop/cpp/Robot.cpp @@ -21,80 +21,78 @@ static const auto TOLERANCE = 8_rpm; class Robot : public wpi::TimedRobot { public: Robot() { - m_controller.SetTolerance(TOLERANCE.value()); + controller.SetTolerance(TOLERANCE.value()); - wpi::BooleanEvent isBallAtKicker{&m_loop, [] { + wpi::BooleanEvent isBallAtKicker{&loop, [] { return false; // return kickerSensor.GetRange() < // KICKER_THRESHOLD; }}; wpi::BooleanEvent intakeButton{ - &m_loop, [&joystick = m_joystick] { return joystick.GetRawButton(2); }}; + &loop, [&joystick = joystick] { return joystick.GetRawButton(2); }}; // if the thumb button is held (intakeButton // and there is not a ball at the kicker && !isBallAtKicker) // activate the intake - .IfHigh([&intake = m_intake] { intake.SetThrottle(0.5); }); + .IfHigh([&intake = intake] { intake.SetThrottle(0.5); }); // if the thumb button is not held (!intakeButton // or there is a ball in the kicker || isBallAtKicker) // stop the intake - .IfHigh([&intake = m_intake] { intake.SetThrottle(0.0); }); + .IfHigh([&intake = intake] { intake.SetThrottle(0.0); }); wpi::BooleanEvent shootTrigger{ - &m_loop, [&joystick = m_joystick] { return joystick.GetTrigger(); }}; + &loop, [&joystick = joystick] { return joystick.GetTrigger(); }}; // if the trigger is held shootTrigger // accelerate the shooter wheel - .IfHigh([&shooter = m_shooter, &controller = m_controller, &ff = m_ff, - &encoder = m_shooterEncoder] { + .IfHigh([&shooter = shooter, &controller = controller, &ff = ff, + &encoder = shooterEncoder] { shooter.SetVoltage( wpi::units::volt_t{controller.Calculate(encoder.GetRate(), SHOT_VELOCITY.value())} + ff.Calculate(wpi::units::radians_per_second_t{SHOT_VELOCITY})); }); // if not, stop - (!shootTrigger).IfHigh([&shooter = m_shooter] { - shooter.SetThrottle(0.0); - }); + (!shootTrigger).IfHigh([&shooter = shooter] { shooter.SetThrottle(0.0); }); wpi::BooleanEvent atTargetVelocity = wpi::BooleanEvent( - &m_loop, - [&controller = m_controller] { return controller.AtSetpoint(); }) + &loop, + [&controller = controller] { return controller.AtSetpoint(); }) // debounce for more stability .Debounce(0.2_s); // if we're at the target velocity, kick the ball into the shooter wheel - atTargetVelocity.IfHigh([&kicker = m_kicker] { kicker.SetThrottle(0.7); }); + atTargetVelocity.IfHigh([&kicker = kicker] { kicker.SetThrottle(0.7); }); // when we stop being at the target velocity, it means the ball was shot atTargetVelocity .Falling() // so stop the kicker - .IfHigh([&kicker = m_kicker] { kicker.SetThrottle(0.0); }); + .IfHigh([&kicker = kicker] { kicker.SetThrottle(0.0); }); } - void RobotPeriodic() override { m_loop.Poll(); } + void RobotPeriodic() override { loop.Poll(); } private: - wpi::PWMSparkMax m_shooter{0}; - wpi::Encoder m_shooterEncoder{0, 1}; - wpi::math::PIDController m_controller{0.3, 0, 0}; - wpi::math::SimpleMotorFeedforward m_ff{0.1_V, - 0.065_V / 1_rpm}; + wpi::PWMSparkMax shooter{0}; + wpi::Encoder shooterEncoder{0, 1}; + wpi::math::PIDController controller{0.3, 0, 0}; + wpi::math::SimpleMotorFeedforward ff{0.1_V, + 0.065_V / 1_rpm}; - wpi::PWMSparkMax m_kicker{1}; + wpi::PWMSparkMax kicker{1}; - wpi::PWMSparkMax m_intake{3}; + wpi::PWMSparkMax intake{3}; - wpi::EventLoop m_loop{}; - wpi::Joystick m_joystick{0}; + wpi::EventLoop loop{}; + wpi::Joystick joystick{0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp index d3fb7ca084f..41870068fb8 100644 --- a/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/FlywheelBangBangController/cpp/Robot.cpp @@ -27,23 +27,23 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override { // Scale setpoint value between 0 and maxSetpointValue wpi::units::radians_per_second_t setpoint = wpi::units::math::max( - 0_rpm, m_joystick.GetRawAxis(0) * kMaxSetpointValue); + 0_rpm, joystick.GetRawAxis(0) * kMaxSetpointValue); // Set setpoint and measurement of the bang-bang controller wpi::units::volt_t bangOutput = - m_bangBangController.Calculate(m_encoder.GetRate(), setpoint.value()) * + bangBangController.Calculate(encoder.GetRate(), setpoint.value()) * 12_V; // Controls a motor with the output of the BangBang controller and a // feedforward. The feedforward is reduced slightly to avoid overspeeding // the shooter. - m_flywheelMotor.SetVoltage(bangOutput + - 0.9 * m_feedforward.Calculate(setpoint)); + flywheelMotor.SetVoltage(bangOutput + + 0.9 * feedforward.Calculate(setpoint)); } Robot() { // Add bang-bang controller to SmartDashboard and networktables. - wpi::SmartDashboard::PutData("BangBangController", &m_bangBangController); + wpi::SmartDashboard::PutData("BangBangController", &bangBangController); } /** @@ -52,11 +52,11 @@ class Robot : public wpi::TimedRobot { void SimulationPeriodic() override { // To update our simulation, we set motor voltage inputs, update the // simulation, and write the simulated velocities to our simulated encoder - m_flywheelSim.SetInputVoltage( - m_flywheelMotor.GetThrottle() * + flywheelSim.SetInputVoltage( + flywheelMotor.GetThrottle() * wpi::units::volt_t{wpi::RobotController::GetInputVoltage()}); - m_flywheelSim.Update(20_ms); - m_encoderSim.SetRate(m_flywheelSim.GetAngularVelocity().value()); + flywheelSim.Update(20_ms); + encoderSim.SetRate(flywheelSim.GetAngularVelocity().value()); } private: @@ -69,12 +69,12 @@ class Robot : public wpi::TimedRobot { 6000_rpm; // Joystick to control setpoint - wpi::Joystick m_joystick{0}; + wpi::Joystick joystick{0}; - wpi::PWMSparkMax m_flywheelMotor{kMotorPort}; - wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; + wpi::PWMSparkMax flywheelMotor{kMotorPort}; + wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel}; - wpi::math::BangBangController m_bangBangController; + wpi::math::BangBangController bangBangController; // Gains are for example purposes only - must be determined for your own // robot! @@ -82,7 +82,7 @@ class Robot : public wpi::TimedRobot { static constexpr decltype(1_V / 1_rad_per_s) kFlywheelKv = 0.000195_V / 1_rpm; static constexpr decltype(1_V / 1_rad_per_s_sq) kFlywheelKa = 0.0003_V / 1_rev_per_m_per_s; - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ kFlywheelKs, kFlywheelKv, kFlywheelKa}; // Simulation classes help us simulate our robot @@ -95,13 +95,13 @@ class Robot : public wpi::TimedRobot { static constexpr wpi::units::kilogram_square_meter_t kFlywheelMomentOfInertia = 0.5 * 1.5_lb * 4_in * 4_in; - wpi::math::DCMotor m_gearbox = wpi::math::DCMotor::NEO(1); - wpi::math::LinearSystem<1, 1, 1> m_plant{ + wpi::math::DCMotor gearbox = wpi::math::DCMotor::NEO(1); + wpi::math::LinearSystem<1, 1, 1> plant{ wpi::math::Models::FlywheelFromPhysicalConstants( - m_gearbox, kFlywheelMomentOfInertia, kFlywheelGearing)}; + gearbox, kFlywheelMomentOfInertia, kFlywheelGearing)}; - wpi::sim::FlywheelSim m_flywheelSim{m_plant, m_gearbox}; - wpi::sim::EncoderSim m_encoderSim{m_encoder}; + wpi::sim::FlywheelSim flywheelSim{plant, gearbox}; + wpi::sim::EncoderSim encoderSim{encoder}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/LimitSwitch/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/LimitSwitch/cpp/Robot.cpp index 33259d0bbab..7f5468c12c8 100644 --- a/wpilibcExamples/src/main/cpp/snippets/LimitSwitch/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/LimitSwitch/cpp/Robot.cpp @@ -13,34 +13,34 @@ */ class Robot : public wpi::TimedRobot { public: - void TeleopPeriodic() override { SetMotorVelocity(m_joystick.GetRawAxis(2)); } + void TeleopPeriodic() override { SetMotorVelocity(joystick.GetRawAxis(2)); } void SetMotorVelocity(double velocity) { if (velocity > 0) { - if (m_toplimitSwitch.Get()) { + if (toplimitSwitch.Get()) { // We are going up and top limit is tripped so stop - m_motor.SetThrottle(0); + motor.SetThrottle(0); } else { // We are going up but top limit is not tripped so go at commanded // velocity - m_motor.SetThrottle(velocity); + motor.SetThrottle(velocity); } } else { - if (m_bottomlimitSwitch.Get()) { + if (bottomlimitSwitch.Get()) { // We are going down and bottom limit is tripped so stop - m_motor.SetThrottle(0); + motor.SetThrottle(0); } else { // We are going down but bottom limit is not tripped so go at commanded // velocity - m_motor.SetThrottle(velocity); + motor.SetThrottle(velocity); } } } private: - wpi::DigitalInput m_toplimitSwitch{0}; - wpi::DigitalInput m_bottomlimitSwitch{1}; - wpi::PWMVictorSPX m_motor{0}; - wpi::Joystick m_joystick{0}; + wpi::DigitalInput toplimitSwitch{0}; + wpi::DigitalInput bottomlimitSwitch{1}; + wpi::PWMVictorSPX motor{0}; + wpi::Joystick joystick{0}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/MotorControl/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/MotorControl/cpp/Robot.cpp index f63e8bdc437..960150779ef 100644 --- a/wpilibcExamples/src/main/cpp/snippets/MotorControl/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/MotorControl/cpp/Robot.cpp @@ -23,26 +23,26 @@ */ class Robot : public wpi::TimedRobot { public: - void TeleopPeriodic() override { m_motor.SetThrottle(m_stick.GetY()); } + void TeleopPeriodic() override { motor.SetThrottle(stick.GetY()); } /* * The RobotPeriodic function is called every control packet no matter the * robot mode. */ void RobotPeriodic() override { - wpi::SmartDashboard::PutNumber("Encoder", m_encoder.GetDistance()); + wpi::SmartDashboard::PutNumber("Encoder", encoder.GetDistance()); } Robot() { // Use SetDistancePerPulse to set the multiplier for GetDistance // This is set up assuming a 6 inch wheel with a 360 CPR encoder. - m_encoder.SetDistancePerPulse((std::numbers::pi * 6) / 360.0); + encoder.SetDistancePerPulse((std::numbers::pi * 6) / 360.0); } private: - wpi::Joystick m_stick{0}; - wpi::PWMSparkMax m_motor{0}; - wpi::Encoder m_encoder{0, 1}; + wpi::Joystick stick{0}; + wpi::PWMSparkMax motor{0}; + wpi::Encoder encoder{0, 1}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/OnboardIMU/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/OnboardIMU/cpp/Robot.cpp index 6e4563aa3a4..3b9359c85b7 100644 --- a/wpilibcExamples/src/main/cpp/snippets/OnboardIMU/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/OnboardIMU/cpp/Robot.cpp @@ -16,26 +16,26 @@ class Robot : public wpi::TimedRobot { public: void TeleopPeriodic() override { // Gets the current acceleration in the X axis - m_IMU.GetAccelX(); + IMU.GetAccelX(); // Gets the current acceleration in the Y axis - m_IMU.GetAccelY(); + IMU.GetAccelY(); // Gets the current acceleration in the Z axis - m_IMU.GetAccelZ(); + IMU.GetAccelZ(); // Gets the current angle in the X axis - m_IMU.GetAngleX(); + IMU.GetAngleX(); // Gets the current angle in the Y axis - m_IMU.GetAngleY(); + IMU.GetAngleY(); // Gets the current angle in the Z axis - m_IMU.GetAngleZ(); + IMU.GetAngleZ(); // Gets the current angle as a Rotation2D - m_IMU.GetRotation2d(); + IMU.GetRotation2d(); } private: // Creates an object for the Systemcore IMU - wpi::OnboardIMU m_IMU{wpi::OnboardIMU::MountOrientation::FLAT}; + wpi::OnboardIMU IMU{wpi::OnboardIMU::MountOrientation::FLAT}; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp index 864408b1e56..4cb1eb4763d 100644 --- a/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/ProfiledPIDFeedforward/cpp/Robot.cpp @@ -18,18 +18,17 @@ */ class Robot : public wpi::TimedRobot { public: - Robot() { m_encoder.SetDistancePerPulse(1.0 / 256.0); } + Robot() { encoder.SetDistancePerPulse(1.0 / 256.0); } // Controls a simple motor's position using a // wpi::math::SimpleMotorFeedforward and a wpi::math::ProfiledPIDController void GoToPosition(wpi::units::meter_t goalPosition) { - auto pidVal = m_controller.Calculate( - wpi::units::meter_t{m_encoder.GetDistance()}, goalPosition); - m_motor.SetVoltage( + auto pidVal = controller.Calculate( + wpi::units::meter_t{encoder.GetDistance()}, goalPosition); + motor.SetVoltage( wpi::units::volt_t{pidVal} + - m_feedforward.Calculate(m_lastVelocity, - m_controller.GetSetpoint().velocity)); - m_lastVelocity = m_controller.GetSetpoint().velocity; + feedforward.Calculate(lastVelocity, controller.GetSetpoint().velocity)); + lastVelocity = controller.GetSetpoint().velocity; } void TeleopPeriodic() override { @@ -38,14 +37,14 @@ class Robot : public wpi::TimedRobot { } private: - wpi::math::ProfiledPIDController m_controller{ + wpi::math::ProfiledPIDController controller{ 1.0, 0.0, 0.0, {5_mps, 10_mps_sq}}; - wpi::math::SimpleMotorFeedforward m_feedforward{ + wpi::math::SimpleMotorFeedforward feedforward{ 0.5_V, 1.5_V / 1_mps, 0.3_V / 1_mps_sq}; - wpi::Encoder m_encoder{0, 1}; - wpi::PWMSparkMax m_motor{0}; + wpi::Encoder encoder{0, 1}; + wpi::PWMSparkMax motor{0}; - wpi::units::meters_per_second_t m_lastVelocity = 0_mps; + wpi::units::meters_per_second_t lastVelocity = 0_mps; }; #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/Robot.cpp index 98d76a72281..c6aff44dd32 100644 --- a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/Robot.cpp @@ -35,10 +35,10 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand != nullptr) { - wpi::cmd::CommandScheduler::GetInstance().Schedule(m_autonomousCommand); + if (autonomousCommand != nullptr) { + wpi::cmd::CommandScheduler::GetInstance().Schedule(autonomousCommand); } } @@ -49,9 +49,9 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != nullptr) { - m_autonomousCommand->Cancel(); - m_autonomousCommand = nullptr; + if (autonomousCommand != nullptr) { + autonomousCommand->Cancel(); + autonomousCommand = nullptr; } } diff --git a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/RobotContainer.cpp index 9bb102d21cf..42434a06bd7 100644 --- a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/cpp/RobotContainer.cpp @@ -9,11 +9,11 @@ RobotContainer::RobotContainer() { // Initialize all of your commands and subsystems here - m_chooser.SetDefaultOption("ONE", CommandSelector::ONE); - m_chooser.AddOption("TWO", CommandSelector::TWO); - m_chooser.AddOption("THREE", CommandSelector::THREE); + chooser.SetDefaultOption("ONE", CommandSelector::ONE); + chooser.AddOption("TWO", CommandSelector::TWO); + chooser.AddOption("THREE", CommandSelector::THREE); - wpi::SmartDashboard::PutData("Auto Chooser", &m_chooser); + wpi::SmartDashboard::PutData("Auto Chooser", &chooser); // Configure the button bindings ConfigureButtonBindings(); @@ -25,5 +25,5 @@ void RobotContainer::ConfigureButtonBindings() { wpi::cmd::Command* RobotContainer::GetAutonomousCommand() { // Run the select command in autonomous - return m_exampleSelectCommand.get(); + return exampleSelectCommand.get(); } diff --git a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/Robot.hpp b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/Robot.hpp index 377ae1bfc2f..c59dc48dc32 100644 --- a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/Robot.hpp @@ -23,7 +23,7 @@ class Robot : public wpi::TimedRobot { private: // Have it null by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - wpi::cmd::Command* m_autonomousCommand = nullptr; + wpi::cmd::Command* autonomousCommand = nullptr; - RobotContainer m_container; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/RobotContainer.hpp index 417f164989f..6ae318c25bc 100644 --- a/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/snippets/SelectCommand/include/RobotContainer.hpp @@ -27,7 +27,7 @@ class RobotContainer { enum CommandSelector { ONE, TWO, THREE }; // An example of how command selector may be used with SendableChooser - wpi::SendableChooser m_chooser; + wpi::SendableChooser chooser; // The robot's subsystems and commands are defined here... @@ -35,13 +35,12 @@ class RobotContainer { // value returned by the selector method at runtime. Note that selectcommand // takes a generic type, so the selector does not have to be an enum; it could // be any desired type (string, integer, boolean, double...) - wpi::cmd::CommandPtr m_exampleSelectCommand = - wpi::cmd::Select( - [this] { return m_chooser.GetSelected(); }, - // Maps selector values to commands - std::pair{ONE, wpi::cmd::Print("Command one was selected!")}, - std::pair{TWO, wpi::cmd::Print("Command two was selected!")}, - std::pair{THREE, wpi::cmd::Print("Command three was selected!")}); + wpi::cmd::CommandPtr exampleSelectCommand = wpi::cmd::Select( + [this] { return chooser.GetSelected(); }, + // Maps selector values to commands + std::pair{ONE, wpi::cmd::Print("Command one was selected!")}, + std::pair{TWO, wpi::cmd::Print("Command two was selected!")}, + std::pair{THREE, wpi::cmd::Print("Command three was selected!")}); void ConfigureButtonBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/snippets/Solenoid/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/snippets/Solenoid/cpp/Robot.cpp index 3c2c1e2d93b..f56e7ad2cd4 100644 --- a/wpilibcExamples/src/main/cpp/snippets/Solenoid/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/snippets/Solenoid/cpp/Robot.cpp @@ -9,9 +9,9 @@ Robot::Robot() { // Publish elements to shuffleboard. - wpi::SmartDashboard::PutData("Single Solenoid", &m_solenoid); - wpi::SmartDashboard::PutData("Double Solenoid", &m_doubleSolenoid); - wpi::SmartDashboard::PutData("Compressor", &m_compressor); + wpi::SmartDashboard::PutData("Single Solenoid", &solenoid); + wpi::SmartDashboard::PutData("Double Solenoid", &doubleSolenoid); + wpi::SmartDashboard::PutData("Compressor", &compressor); } void Robot::TeleopPeriodic() { @@ -21,50 +21,49 @@ void Robot::TeleopPeriodic() { // This function is supported only on the PH! // On a PCM, this function will return 0. wpi::SmartDashboard::PutNumber("PH Pressure [PSI]", - m_compressor.GetPressure().value()); + compressor.GetPressure().value()); // Get compressor current draw. wpi::SmartDashboard::PutNumber("Compressor Current", - m_compressor.GetCurrent().value()); + compressor.GetCurrent().value()); // Get whether the compressor is active. - wpi::SmartDashboard::PutBoolean("Compressor Active", - m_compressor.IsEnabled()); + wpi::SmartDashboard::PutBoolean("Compressor Active", compressor.IsEnabled()); // Get the digital pressure switch connected to the PCM/PH. // The switch is open when the pressure is over ~120 PSI. wpi::SmartDashboard::PutBoolean("Pressure Switch", - m_compressor.GetPressureSwitchValue()); + compressor.GetPressureSwitchValue()); /* * The output of GetRawButton is true/false depending on whether * the button is pressed; Set takes a boolean for whether * to retract the solenoid (false) or extend it (true). */ - m_solenoid.Set(m_stick.GetRawButton(kSolenoidButton)); + solenoid.Set(stick.GetRawButton(kSolenoidButton)); /* * GetRawButtonPressed will only return true once per press. * If a button is pressed, set the solenoid to the respective channel. */ - if (m_stick.GetRawButtonPressed(kDoubleSolenoidForward)) { - m_doubleSolenoid.Set(wpi::DoubleSolenoid::FORWARD); - } else if (m_stick.GetRawButtonPressed(kDoubleSolenoidReverse)) { - m_doubleSolenoid.Set(wpi::DoubleSolenoid::REVERSE); + if (stick.GetRawButtonPressed(kDoubleSolenoidForward)) { + doubleSolenoid.Set(wpi::DoubleSolenoid::FORWARD); + } else if (stick.GetRawButtonPressed(kDoubleSolenoidReverse)) { + doubleSolenoid.Set(wpi::DoubleSolenoid::REVERSE); } // On button press, toggle the compressor with the mode selected from the // dashboard. - if (m_stick.GetRawButtonPressed(kCompressorButton)) { + if (stick.GetRawButtonPressed(kCompressorButton)) { // Check whether the compressor is currently enabled. - bool isCompressorEnabled = m_compressor.IsEnabled(); + bool isCompressorEnabled = compressor.IsEnabled(); if (isCompressorEnabled) { // Disable closed-loop mode on the compressor. - m_compressor.Disable(); + compressor.Disable(); } else { // Change the if directives to select the closed-loop mode you want to // use: #if 0 // Enable closed-loop mode based on the digital pressure switch // connected to the PCM/PH. - m_compressor.EnableDigital(); + compressor.EnableDigital(); #endif #if 1 // Enable closed-loop mode based on the analog pressure sensor connected @@ -72,7 +71,7 @@ void Robot::TeleopPeriodic() { // sensor is in the specified range ([70 PSI, 120 PSI] in this example). // Analog mode exists only on the PH! On the PCM, this enables digital // control. - m_compressor.EnableAnalog(70_psi, 120_psi); + compressor.EnableAnalog(70_psi, 120_psi); #endif #if 0 // Enable closed-loop mode based on both the digital pressure switch AND the analog @@ -81,7 +80,7 @@ void Robot::TeleopPeriodic() { // specified range ([70 PSI, 120 PSI] in this example) AND the digital switch reports // that the system is not full. // Hybrid mode exists only on the PH! On the PCM, this enables digital control. - m_compressor.EnableHybrid(70_psi, 120_psi); + compressor.EnableHybrid(70_psi, 120_psi); #endif } } diff --git a/wpilibcExamples/src/main/cpp/snippets/Solenoid/include/Robot.hpp b/wpilibcExamples/src/main/cpp/snippets/Solenoid/include/Robot.hpp index 7cc42500cd6..ced4cbb5258 100644 --- a/wpilibcExamples/src/main/cpp/snippets/Solenoid/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/snippets/Solenoid/include/Robot.hpp @@ -39,21 +39,21 @@ class Robot : public wpi::TimedRobot { void TeleopPeriodic() override; private: - wpi::Joystick m_stick{0}; + wpi::Joystick stick{0}; // Solenoid corresponds to a single solenoid. // In this case, it's connected to channel 0 of a PH with the default CAN // ID. - wpi::Solenoid m_solenoid{0, wpi::PneumaticsModuleType::REV_PH, 0}; + wpi::Solenoid solenoid{0, wpi::PneumaticsModuleType::REV_PH, 0}; // DoubleSolenoid corresponds to a double solenoid. // In this case, it's connected to channels 1 and 2 of a PH with the default // CAN ID. - wpi::DoubleSolenoid m_doubleSolenoid{0, wpi::PneumaticsModuleType::REV_PH, 1, - 2}; + wpi::DoubleSolenoid doubleSolenoid{0, wpi::PneumaticsModuleType::REV_PH, 1, + 2}; // Compressor connected to a PH with a default CAN ID - wpi::Compressor m_compressor{0, wpi::PneumaticsModuleType::REV_PH}; + wpi::Compressor compressor{0, wpi::PneumaticsModuleType::REV_PH}; static constexpr int kSolenoidButton = 1; static constexpr int kDoubleSolenoidForward = 2; diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/Robot.cpp index 9af2838a50d..2610b1366ae 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/Robot.cpp @@ -34,11 +34,11 @@ void Robot::DisabledPeriodic() {} * RobotContainer} class. */ void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand) { + if (autonomousCommand) { wpi::cmd::CommandScheduler::GetInstance().Schedule( - m_autonomousCommand.value()); + autonomousCommand.value()); } } @@ -49,8 +49,8 @@ void Robot::TeleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand) { - m_autonomousCommand->Cancel(); + if (autonomousCommand) { + autonomousCommand->Cancel(); } } diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/RobotContainer.cpp index e8720c0149a..81bee18aea3 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/RobotContainer.cpp @@ -20,15 +20,15 @@ void RobotContainer::ConfigureBindings() { // Schedule `ExampleCommand` when `exampleCondition` changes to `true` wpi::cmd::Trigger([this] { - return m_subsystem.ExampleCondition(); - }).OnTrue(ExampleCommand(&m_subsystem).ToPtr()); + return subsystem.ExampleCondition(); + }).OnTrue(ExampleCommand(&subsystem).ToPtr()); // Schedule `ExampleMethodCommand` when the Gamepad's East Face button is // pressed, cancelling on release. - m_driverController.EastFace().WhileTrue(m_subsystem.ExampleMethodCommand()); + driverController.EastFace().WhileTrue(subsystem.ExampleMethodCommand()); } wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() { // An example command will be run in autonomous - return autos::ExampleAuto(&m_subsystem); + return autos::ExampleAuto(&subsystem); } diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/commands/ExampleCommand.cpp b/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/commands/ExampleCommand.cpp index 212ed41ac6e..745221cada8 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/commands/ExampleCommand.cpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2/cpp/commands/ExampleCommand.cpp @@ -5,7 +5,7 @@ #include "commands/ExampleCommand.hpp" ExampleCommand::ExampleCommand(ExampleSubsystem* subsystem) - : m_subsystem{subsystem} { + : subsystem{subsystem} { // Register that this command requires the subsystem. - AddRequirements(m_subsystem); + AddRequirements(this->subsystem); } diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2/include/Robot.hpp b/wpilibcExamples/src/main/cpp/templates/commandv2/include/Robot.hpp index 9c2241d1e14..a91570d7c26 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2/include/Robot.hpp @@ -27,7 +27,7 @@ class Robot : public wpi::TimedRobot { private: // Have it empty by default so that if testing teleop it // doesn't have undefined behavior and potentially crash. - std::optional m_autonomousCommand; + std::optional autonomousCommand; - RobotContainer m_container; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2/include/RobotContainer.hpp b/wpilibcExamples/src/main/cpp/templates/commandv2/include/RobotContainer.hpp index e9c311e8673..62c6daa3f26 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2/include/RobotContainer.hpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2/include/RobotContainer.hpp @@ -24,11 +24,11 @@ class RobotContainer { private: // Replace with CommandPS4Controller or CommandJoystick if needed - wpi::cmd::CommandGamepad m_driverController{ + wpi::cmd::CommandGamepad driverController{ OperatorConstants::kDriverControllerPort}; // The robot's subsystems are defined here... - ExampleSubsystem m_subsystem; + ExampleSubsystem subsystem; void ConfigureBindings(); }; diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2/include/commands/ExampleCommand.hpp b/wpilibcExamples/src/main/cpp/templates/commandv2/include/commands/ExampleCommand.hpp index 049e7591dc4..b24518e17bb 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2/include/commands/ExampleCommand.hpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2/include/commands/ExampleCommand.hpp @@ -26,5 +26,5 @@ class ExampleCommand explicit ExampleCommand(ExampleSubsystem* subsystem); private: - ExampleSubsystem* m_subsystem; + ExampleSubsystem* subsystem; }; diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/cpp/Robot.cpp index 3dd2cac83b8..132624950e1 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/cpp/Robot.cpp @@ -19,11 +19,11 @@ void Robot::DisabledPeriodic() {} void Robot::DisabledExit() {} void Robot::AutonomousInit() { - m_autonomousCommand = m_container.GetAutonomousCommand(); + autonomousCommand = container.GetAutonomousCommand(); - if (m_autonomousCommand) { + if (autonomousCommand) { wpi::cmd::CommandScheduler::GetInstance().Schedule( - m_autonomousCommand.value()); + autonomousCommand.value()); } } @@ -32,8 +32,8 @@ void Robot::AutonomousPeriodic() {} void Robot::AutonomousExit() {} void Robot::TeleopInit() { - if (m_autonomousCommand) { - m_autonomousCommand->Cancel(); + if (autonomousCommand) { + autonomousCommand->Cancel(); } } diff --git a/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/include/Robot.hpp b/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/include/Robot.hpp index 523b71406db..08022568cb2 100644 --- a/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/templates/commandv2skeleton/include/Robot.hpp @@ -28,7 +28,7 @@ class Robot : public wpi::TimedRobot { void UtilityExit() override; private: - std::optional m_autonomousCommand; + std::optional autonomousCommand; - RobotContainer m_container; + RobotContainer container; }; diff --git a/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyAuto.cpp b/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyAuto.cpp index 746c29ab3de..3d107a1ed4f 100644 --- a/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyAuto.cpp +++ b/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyAuto.cpp @@ -7,7 +7,7 @@ #include "Robot.hpp" /** The Robot instance is passed into the opmode via the constructor. */ -MyAuto::MyAuto(Robot& robot) : m_robot{robot} { +MyAuto::MyAuto(Robot& robot) : robot{robot} { /* * Can call the base class constructor with the period to set a different * periodic time interval. diff --git a/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyTeleop.cpp b/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyTeleop.cpp index c3fac32fa46..31bc38535fe 100644 --- a/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyTeleop.cpp +++ b/wpilibcExamples/src/main/cpp/templates/opmode/cpp/opmode/MyTeleop.cpp @@ -7,7 +7,7 @@ #include "Robot.hpp" /** The Robot instance is passed into the opmode via the constructor. */ -MyTeleop::MyTeleop(Robot& robot) : m_robot{robot} {} +MyTeleop::MyTeleop(Robot& robot) : robot{robot} {} MyTeleop::~MyTeleop() { /* Called when the opmode is de-selected. */ diff --git a/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyAuto.hpp b/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyAuto.hpp index 30e93ddcf78..9d259d14e45 100644 --- a/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyAuto.hpp +++ b/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyAuto.hpp @@ -19,5 +19,5 @@ class MyAuto : public wpi::PeriodicOpMode { private: [[maybe_unused]] - Robot& m_robot; + Robot& robot; }; diff --git a/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyTeleop.hpp b/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyTeleop.hpp index be99d1d4e2e..05ba1d0938b 100644 --- a/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyTeleop.hpp +++ b/wpilibcExamples/src/main/cpp/templates/opmode/include/opmode/MyTeleop.hpp @@ -19,5 +19,5 @@ class MyTeleop : public wpi::PeriodicOpMode { private: [[maybe_unused]] - Robot& m_robot; + Robot& robot; }; diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp index dc4d55139d5..41ac4f920c2 100644 --- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp @@ -35,7 +35,7 @@ void Robot::StartCompetition() { // Tell the DS that the robot is ready to be enabled wpi::internal::DriverStationBackend::ObserveUserProgramStarting(); - while (!m_exit) { + while (!exit) { modeThread.InControl(wpi::internal::DriverStationBackend::GetControlWord()); if (IsDisabled()) { Disabled(); @@ -62,7 +62,7 @@ void Robot::StartCompetition() { } void Robot::EndCompetition() { - m_exit = true; + exit = true; } #ifndef RUNNING_WPILIB_TESTS diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.hpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.hpp index a7504220ae0..6725d993160 100644 --- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/include/Robot.hpp @@ -20,5 +20,5 @@ class Robot : public wpi::RobotBase { void EndCompetition() override; private: - std::atomic m_exit{false}; + std::atomic exit{false}; }; diff --git a/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp index 6c8203f36f2..ec067297ea8 100644 --- a/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp @@ -8,9 +8,9 @@ #include "wpi/util/print.hpp" Robot::Robot() { - m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault); - m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom); - wpi::SmartDashboard::PutData("Auto Modes", &m_chooser); + chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault); + chooser.AddOption(kAutoNameCustom, kAutoNameCustom); + wpi::SmartDashboard::PutData("Auto Modes", &chooser); } /** @@ -35,12 +35,12 @@ void Robot::RobotPeriodic() {} * make sure to add them to the chooser code above as well. */ void Robot::AutonomousInit() { - m_autoSelected = m_chooser.GetSelected(); - // m_autoSelected = SmartDashboard::GetString("Auto Selector", + autoSelected = chooser.GetSelected(); + // autoSelected = SmartDashboard::GetString("Auto Selector", // kAutoNameDefault); - wpi::util::print("Auto selected: {}\n", m_autoSelected); + wpi::util::print("Auto selected: {}\n", autoSelected); - if (m_autoSelected == kAutoNameCustom) { + if (autoSelected == kAutoNameCustom) { // Custom Auto goes here } else { // Default Auto goes here @@ -48,7 +48,7 @@ void Robot::AutonomousInit() { } void Robot::AutonomousPeriodic() { - if (m_autoSelected == kAutoNameCustom) { + if (autoSelected == kAutoNameCustom) { // Custom Auto goes here } else { // Default Auto goes here diff --git a/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.hpp b/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.hpp index df918341095..6908000a22c 100644 --- a/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/templates/timed/include/Robot.hpp @@ -25,8 +25,8 @@ class Robot : public wpi::TimedRobot { void SimulationPeriodic() override; private: - wpi::SendableChooser m_chooser; + wpi::SendableChooser chooser; const std::string kAutoNameDefault = "Default"; const std::string kAutoNameCustom = "My Auto"; - std::string m_autoSelected; + std::string autoSelected; }; diff --git a/wpilibcExamples/src/main/cpp/templates/timeslice/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/timeslice/cpp/Robot.cpp index ef489a9f029..16a791eaf21 100644 --- a/wpilibcExamples/src/main/cpp/templates/timeslice/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/timeslice/cpp/Robot.cpp @@ -19,9 +19,9 @@ Robot::Robot() : wpi::TimesliceRobot{5_ms, 10_ms} { // 5 ms (robot) + 2 ms (controller 1) + 2 ms (controller 2) = 9 ms // 9 ms / 10 ms -> 90% allocated - m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault); - m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom); - wpi::SmartDashboard::PutData("Auto Modes", &m_chooser); + chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault); + chooser.AddOption(kAutoNameCustom, kAutoNameCustom); + wpi::SmartDashboard::PutData("Auto Modes", &chooser); } /** @@ -46,12 +46,12 @@ void Robot::RobotPeriodic() {} * make sure to add them to the chooser code above as well. */ void Robot::AutonomousInit() { - m_autoSelected = m_chooser.GetSelected(); - // m_autoSelected = SmartDashboard::GetString("Auto Selector", + autoSelected = chooser.GetSelected(); + // autoSelected = SmartDashboard::GetString("Auto Selector", // kAutoNameDefault); - wpi::util::print("Auto selected: {}\n", m_autoSelected); + wpi::util::print("Auto selected: {}\n", autoSelected); - if (m_autoSelected == kAutoNameCustom) { + if (autoSelected == kAutoNameCustom) { // Custom Auto goes here } else { // Default Auto goes here @@ -59,7 +59,7 @@ void Robot::AutonomousInit() { } void Robot::AutonomousPeriodic() { - if (m_autoSelected == kAutoNameCustom) { + if (autoSelected == kAutoNameCustom) { // Custom Auto goes here } else { // Default Auto goes here diff --git a/wpilibcExamples/src/main/cpp/templates/timeslice/include/Robot.hpp b/wpilibcExamples/src/main/cpp/templates/timeslice/include/Robot.hpp index 7921465de83..992a0a3e0c4 100644 --- a/wpilibcExamples/src/main/cpp/templates/timeslice/include/Robot.hpp +++ b/wpilibcExamples/src/main/cpp/templates/timeslice/include/Robot.hpp @@ -23,8 +23,8 @@ class Robot : public wpi::TimesliceRobot { void UtilityPeriodic() override; private: - wpi::SendableChooser m_chooser; + wpi::SendableChooser chooser; const std::string kAutoNameDefault = "Default"; const std::string kAutoNameCustom = "My Auto"; - std::string m_autoSelected; + std::string autoSelected; }; diff --git a/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp b/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp index 36a1016e79c..65f0d5067cc 100644 --- a/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp +++ b/wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp @@ -18,29 +18,29 @@ #include "wpi/util/Preferences.hpp" class ArmSimulationTest : public testing::TestWithParam { - Robot m_robot; - std::optional m_thread; + Robot robot; + std::optional thread; protected: - wpi::sim::PWMMotorControllerSim m_motorSim{kMotorPort}; - wpi::sim::EncoderSim m_encoderSim = + wpi::sim::PWMMotorControllerSim motorSim{kMotorPort}; + wpi::sim::EncoderSim encoderSim = wpi::sim::EncoderSim::CreateForChannel(kEncoderAChannel); - wpi::sim::JoystickSim m_joystickSim{kJoystickPort}; + wpi::sim::JoystickSim joystickSim{kJoystickPort}; public: void SetUp() override { wpi::sim::PauseTiming(); wpi::sim::SetProgramStarted(false); - m_thread = std::thread([&] { m_robot.StartCompetition(); }); + thread = std::thread([&] { robot.StartCompetition(); }); wpi::sim::WaitForProgramStart(); } void TearDown() override { - m_robot.EndCompetition(); - m_thread->join(); + robot.EndCompetition(); + thread->join(); - m_encoderSim.ResetData(); + encoderSim.ResetData(); wpi::sim::DriverStationSim::ResetData(); wpi::Preferences::RemoveAll(); } @@ -60,25 +60,25 @@ TEST_P(ArmSimulationTest, Teleop) { wpi::sim::DriverStationSim::SetEnabled(true); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(m_encoderSim.GetInitialized()); + EXPECT_TRUE(encoderSim.GetInitialized()); } { wpi::sim::StepTiming(3_s); // Ensure arm is still at minimum angle. - EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0); + EXPECT_NEAR(kMinAngle.value(), encoderSim.GetDistance(), 2.0); } { // Press button to reach setpoint - m_joystickSim.SetTrigger(true); - m_joystickSim.NotifyNewData(); + joystickSim.SetTrigger(true); + joystickSim.NotifyNewData(); wpi::sim::StepTiming(1.5_s); EXPECT_NEAR(setpoint.value(), - wpi::units::radian_t(m_encoderSim.GetDistance()) + wpi::units::radian_t(encoderSim.GetDistance()) .convert() .value(), 2.0); @@ -87,7 +87,7 @@ TEST_P(ArmSimulationTest, Teleop) { wpi::sim::StepTiming(0.5_s); EXPECT_NEAR(setpoint.value(), - wpi::units::radian_t(m_encoderSim.GetDistance()) + wpi::units::radian_t(encoderSim.GetDistance()) .convert() .value(), 2.0); @@ -95,24 +95,24 @@ TEST_P(ArmSimulationTest, Teleop) { { // Unpress the button to go back down - m_joystickSim.SetTrigger(false); - m_joystickSim.NotifyNewData(); + joystickSim.SetTrigger(false); + joystickSim.NotifyNewData(); wpi::sim::StepTiming(3_s); - EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0); + EXPECT_NEAR(kMinAngle.value(), encoderSim.GetDistance(), 2.0); } { // Press button to go back up - m_joystickSim.SetTrigger(true); - m_joystickSim.NotifyNewData(); + joystickSim.SetTrigger(true); + joystickSim.NotifyNewData(); // advance 75 timesteps wpi::sim::StepTiming(1.5_s); EXPECT_NEAR(setpoint.value(), - wpi::units::radian_t(m_encoderSim.GetDistance()) + wpi::units::radian_t(encoderSim.GetDistance()) .convert() .value(), 2.0); @@ -121,7 +121,7 @@ TEST_P(ArmSimulationTest, Teleop) { wpi::sim::StepTiming(0.5_s); EXPECT_NEAR(setpoint.value(), - wpi::units::radian_t(m_encoderSim.GetDistance()) + wpi::units::radian_t(encoderSim.GetDistance()) .convert() .value(), 2.0); @@ -134,8 +134,8 @@ TEST_P(ArmSimulationTest, Teleop) { wpi::sim::StepTiming(3_s); - ASSERT_NEAR(0.0, m_motorSim.GetThrottle(), 0.05); - EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0); + ASSERT_NEAR(0.0, motorSim.GetThrottle(), 0.05); + EXPECT_NEAR(kMinAngle.value(), encoderSim.GetDistance(), 2.0); } } diff --git a/wpilibcExamples/src/test/cpp/examples/ElevatorSimulation/cpp/ElevatorSimulationTest.cpp b/wpilibcExamples/src/test/cpp/examples/ElevatorSimulation/cpp/ElevatorSimulationTest.cpp index 2998b62c5be..3e0e237a030 100644 --- a/wpilibcExamples/src/test/cpp/examples/ElevatorSimulation/cpp/ElevatorSimulationTest.cpp +++ b/wpilibcExamples/src/test/cpp/examples/ElevatorSimulation/cpp/ElevatorSimulationTest.cpp @@ -22,29 +22,29 @@ using namespace Constants; class ElevatorSimulationTest : public testing::Test { - Robot m_robot; - std::optional m_thread; + Robot robot; + std::optional thread; protected: - wpi::sim::PWMMotorControllerSim m_motorSim{Constants::kMotorPort}; - wpi::sim::EncoderSim m_encoderSim = + wpi::sim::PWMMotorControllerSim motorSim{Constants::kMotorPort}; + wpi::sim::EncoderSim encoderSim = wpi::sim::EncoderSim::CreateForChannel(Constants::kEncoderAChannel); - wpi::sim::JoystickSim m_joystickSim{Constants::kJoystickPort}; + wpi::sim::JoystickSim joystickSim{Constants::kJoystickPort}; public: void SetUp() override { wpi::sim::PauseTiming(); wpi::sim::SetProgramStarted(false); - m_thread = std::thread([&] { m_robot.StartCompetition(); }); + thread = std::thread([&] { robot.StartCompetition(); }); wpi::sim::WaitForProgramStart(); } void TearDown() override { - m_robot.EndCompetition(); - m_thread->join(); + robot.EndCompetition(); + thread->join(); - m_encoderSim.ResetData(); + encoderSim.ResetData(); wpi::sim::DriverStationSim::ResetData(); } }; @@ -56,7 +56,7 @@ TEST_F(ElevatorSimulationTest, Teleop) { wpi::sim::DriverStationSim::SetEnabled(true); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(m_encoderSim.GetInitialized()); + EXPECT_TRUE(encoderSim.GetInitialized()); } { @@ -64,50 +64,50 @@ TEST_F(ElevatorSimulationTest, Teleop) { wpi::sim::StepTiming(1_s); // Ensure elevator is still at 0. - EXPECT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05); + EXPECT_NEAR(0.0, encoderSim.GetDistance(), 0.05); } { // Press button to reach setpoint - m_joystickSim.SetTrigger(true); - m_joystickSim.NotifyNewData(); + joystickSim.SetTrigger(true); + joystickSim.NotifyNewData(); // advance 75 timesteps wpi::sim::StepTiming(1.5_s); - EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05); + EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05); // advance 25 timesteps to see setpoint is held. wpi::sim::StepTiming(0.5_s); - EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05); + EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05); } { // Unpress the button to go back down - m_joystickSim.SetTrigger(false); - m_joystickSim.NotifyNewData(); + joystickSim.SetTrigger(false); + joystickSim.NotifyNewData(); // advance 75 timesteps wpi::sim::StepTiming(1.5_s); - EXPECT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05); + EXPECT_NEAR(0.0, encoderSim.GetDistance(), 0.05); } { // Press button to go back up - m_joystickSim.SetTrigger(true); - m_joystickSim.NotifyNewData(); + joystickSim.SetTrigger(true); + joystickSim.NotifyNewData(); // advance 75 timesteps wpi::sim::StepTiming(1.5_s); - EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05); + EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05); // advance 25 timesteps to see setpoint is held. wpi::sim::StepTiming(0.5_s); - EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05); + EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05); } { @@ -118,7 +118,7 @@ TEST_F(ElevatorSimulationTest, Teleop) { // advance 75 timesteps wpi::sim::StepTiming(1.5_s); - ASSERT_NEAR(0.0, m_motorSim.GetThrottle(), 0.05); - ASSERT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05); + ASSERT_NEAR(0.0, motorSim.GetThrottle(), 0.05); + ASSERT_NEAR(0.0, encoderSim.GetDistance(), 0.05); } } diff --git a/wpilibcExamples/src/test/cpp/snippets/DigitalCommunication/cpp/DigitalCommunicationTest.cpp b/wpilibcExamples/src/test/cpp/snippets/DigitalCommunication/cpp/DigitalCommunicationTest.cpp index 8ddb1e01647..52b12cbd49e 100644 --- a/wpilibcExamples/src/test/cpp/snippets/DigitalCommunication/cpp/DigitalCommunicationTest.cpp +++ b/wpilibcExamples/src/test/cpp/snippets/DigitalCommunication/cpp/DigitalCommunicationTest.cpp @@ -17,29 +17,29 @@ template class DigitalCommunicationTest : public testing::TestWithParam { public: - wpi::sim::DIOSim m_allianceOutput{Robot::kAlliancePort}; - wpi::sim::DIOSim m_enabledOutput{Robot::kEnabledPort}; - wpi::sim::DIOSim m_autonomousOutput{Robot::kAutonomousPort}; - wpi::sim::DIOSim m_alertOutput{Robot::kAlertPort}; - Robot m_robot; - std::optional m_thread; + wpi::sim::DIOSim allianceOutput{Robot::kAlliancePort}; + wpi::sim::DIOSim enabledOutput{Robot::kEnabledPort}; + wpi::sim::DIOSim autonomousOutput{Robot::kAutonomousPort}; + wpi::sim::DIOSim alertOutput{Robot::kAlertPort}; + Robot robot; + std::optional thread; void SetUp() override { wpi::sim::PauseTiming(); wpi::sim::SetProgramStarted(false); wpi::sim::DriverStationSim::ResetData(); - m_thread = std::thread([&] { m_robot.StartCompetition(); }); + thread = std::thread([&] { robot.StartCompetition(); }); wpi::sim::WaitForProgramStart(); } void TearDown() override { - m_robot.EndCompetition(); - m_thread->join(); - m_allianceOutput.ResetData(); - m_enabledOutput.ResetData(); - m_autonomousOutput.ResetData(); - m_alertOutput.ResetData(); + robot.EndCompetition(); + thread->join(); + allianceOutput.ResetData(); + enabledOutput.ResetData(); + autonomousOutput.ResetData(); + alertOutput.ResetData(); } }; @@ -50,8 +50,8 @@ TEST_P(AllianceTest, Alliance) { wpi::sim::DriverStationSim::SetAllianceStationId(alliance); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(m_allianceOutput.GetInitialized()); - EXPECT_FALSE(m_allianceOutput.GetIsInput()); + EXPECT_TRUE(allianceOutput.GetInitialized()); + EXPECT_FALSE(allianceOutput.GetIsInput()); wpi::sim::StepTiming(20_ms); @@ -69,7 +69,7 @@ TEST_P(AllianceTest, Alliance) { isRed = true; break; } - EXPECT_EQ(isRed, m_allianceOutput.GetValue()); + EXPECT_EQ(isRed, allianceOutput.GetValue()); } INSTANTIATE_TEST_SUITE_P( @@ -106,12 +106,12 @@ TEST_P(EnabledTest, Enabled) { wpi::sim::DriverStationSim::SetEnabled(enabled); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(m_enabledOutput.GetInitialized()); - EXPECT_FALSE(m_enabledOutput.GetIsInput()); + EXPECT_TRUE(enabledOutput.GetInitialized()); + EXPECT_FALSE(enabledOutput.GetIsInput()); wpi::sim::StepTiming(20_ms); - EXPECT_EQ(enabled, m_enabledOutput.GetValue()); + EXPECT_EQ(enabled, enabledOutput.GetValue()); } INSTANTIATE_TEST_SUITE_P(DigitalCommunicationTests, EnabledTest, @@ -125,12 +125,12 @@ TEST_P(AutonomousTest, Autonomous) { autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(m_autonomousOutput.GetInitialized()); - EXPECT_FALSE(m_autonomousOutput.GetIsInput()); + EXPECT_TRUE(autonomousOutput.GetInitialized()); + EXPECT_FALSE(autonomousOutput.GetIsInput()); wpi::sim::StepTiming(20_ms); - EXPECT_EQ(autonomous, m_autonomousOutput.GetValue()); + EXPECT_EQ(autonomous, autonomousOutput.GetValue()); } INSTANTIATE_TEST_SUITE_P(DigitalCommunicationTests, AutonomousTest, @@ -143,12 +143,12 @@ TEST_P(AlertTest, Alert) { wpi::sim::DriverStationSim::SetMatchTime(matchTime); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(m_alertOutput.GetInitialized()); - EXPECT_FALSE(m_alertOutput.GetIsInput()); + EXPECT_TRUE(alertOutput.GetInitialized()); + EXPECT_FALSE(alertOutput.GetIsInput()); wpi::sim::StepTiming(20_ms); - EXPECT_EQ(matchTime <= 30 && matchTime >= 25, m_alertOutput.GetValue()); + EXPECT_EQ(matchTime <= 30 && matchTime >= 25, alertOutput.GetValue()); } INSTANTIATE_TEST_SUITE_P( diff --git a/wpilibcExamples/src/test/cpp/snippets/I2CCommunication/cpp/I2CCommunicationTest.cpp b/wpilibcExamples/src/test/cpp/snippets/I2CCommunication/cpp/I2CCommunicationTest.cpp index e4ee4550670..5c1642abd84 100644 --- a/wpilibcExamples/src/test/cpp/snippets/I2CCommunication/cpp/I2CCommunicationTest.cpp +++ b/wpilibcExamples/src/test/cpp/snippets/I2CCommunication/cpp/I2CCommunicationTest.cpp @@ -25,30 +25,30 @@ void callback(const char* name, void* param, const unsigned char* buffer, template class I2CCommunicationTest : public testing::TestWithParam { public: - Robot m_robot; - std::optional m_thread; - int32_t m_callback; - int32_t m_port; + Robot robot; + std::optional thread; + int32_t callbackHandle; + int32_t port; void SetUp() override { gString = std::string(); wpi::sim::PauseTiming(); wpi::sim::SetProgramStarted(false); wpi::sim::DriverStationSim::ResetData(); - m_port = static_cast(Robot::kPort); + port = static_cast(Robot::kPort); - m_callback = HALSIM_RegisterI2CWriteCallback(m_port, &callback, nullptr); + callbackHandle = HALSIM_RegisterI2CWriteCallback(port, &callback, nullptr); - m_thread = std::thread([&] { m_robot.StartCompetition(); }); + thread = std::thread([&] { robot.StartCompetition(); }); wpi::sim::WaitForProgramStart(); } void TearDown() override { - m_robot.EndCompetition(); - m_thread->join(); + robot.EndCompetition(); + thread->join(); - HALSIM_CancelI2CWriteCallback(m_port, m_callback); - HALSIM_ResetI2CData(m_port); + HALSIM_CancelI2CWriteCallback(port, callbackHandle); + HALSIM_ResetI2CData(port); } }; @@ -59,7 +59,7 @@ TEST_P(AllianceTest, Alliance) { wpi::sim::DriverStationSim::SetAllianceStationId(alliance); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port)); + EXPECT_TRUE(HALSIM_GetI2CInitialized(port)); wpi::sim::StepTiming(20_ms); @@ -116,7 +116,7 @@ TEST_P(EnabledTest, Enabled) { wpi::sim::DriverStationSim::SetEnabled(enabled); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port)); + EXPECT_TRUE(HALSIM_GetI2CInitialized(port)); wpi::sim::StepTiming(20_ms); @@ -135,7 +135,7 @@ TEST_P(AutonomousTest, Autonomous) { autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port)); + EXPECT_TRUE(HALSIM_GetI2CInitialized(port)); wpi::sim::StepTiming(20_ms); @@ -153,7 +153,7 @@ TEST_P(MatchTimeTest, Alert) { wpi::sim::DriverStationSim::SetMatchTime(matchTime); wpi::sim::DriverStationSim::NotifyNewData(); - EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port)); + EXPECT_TRUE(HALSIM_GetI2CInitialized(port)); wpi::sim::StepTiming(20_ms); diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/arcadedrivegamepad/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/arcadedrivegamepad/Robot.java index a7fe831b9cc..e6d50c5e438 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/arcadedrivegamepad/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/arcadedrivegamepad/Robot.java @@ -15,21 +15,21 @@ * arcade steering and a gamepad. */ public class Robot extends TimedRobot { - private final PWMSparkMax m_leftMotor = new PWMSparkMax(0); - private final PWMSparkMax m_rightMotor = new PWMSparkMax(1); - private final DifferentialDrive m_robotDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); - private final Gamepad m_driverController = new Gamepad(0); + private final PWMSparkMax leftMotor = new PWMSparkMax(0); + private final PWMSparkMax rightMotor = new PWMSparkMax(1); + private final DifferentialDrive robotDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); + private final Gamepad driverController = new Gamepad(0); /** Called once at the beginning of the robot program. */ public Robot() { - SendableRegistry.addChild(m_robotDrive, m_leftMotor); - SendableRegistry.addChild(m_robotDrive, m_rightMotor); + SendableRegistry.addChild(robotDrive, leftMotor); + SendableRegistry.addChild(robotDrive, rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } @Override @@ -37,6 +37,6 @@ public void teleopPeriodic() { // Drive with split arcade drive. // That means that the Y axis of the left stick moves forward // and backward, and the X of the right stick turns left and right. - m_robotDrive.arcadeDrive(-m_driverController.getLeftY(), -m_driverController.getRightX()); + robotDrive.arcadeDrive(-driverController.getLeftY(), -driverController.getRightX()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/Robot.java index 39e2a53db09..243ed8a8ee2 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/Robot.java @@ -10,41 +10,41 @@ /** This is a sample program to demonstrate the use of arm simulation with existing code. */ public class Robot extends TimedRobot { - private final Arm m_arm = new Arm(); - private final Joystick m_joystick = new Joystick(Constants.kJoystickPort); + private final Arm arm = new Arm(); + private final Joystick joystick = new Joystick(Constants.kJoystickPort); public Robot() {} @Override public void simulationPeriodic() { - m_arm.simulationPeriodic(); + arm.simulationPeriodic(); } @Override public void teleopInit() { - m_arm.loadPreferences(); + arm.loadPreferences(); } @Override public void teleopPeriodic() { - if (m_joystick.getTrigger()) { + if (joystick.getTrigger()) { // Here, we run PID control like normal. - m_arm.reachSetpoint(); + arm.reachSetpoint(); } else { // Otherwise, we disable the motor. - m_arm.stop(); + arm.stop(); } } @Override public void close() { - m_arm.close(); + arm.close(); super.close(); } @Override public void disabledInit() { // This just makes sure that our simulation code knows that the motor's off. - m_arm.stop(); + arm.stop(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/subsystems/Arm.java b/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/subsystems/Arm.java index fda913c301f..ddc2dc112f4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/subsystems/Arm.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/armsimulation/subsystems/Arm.java @@ -25,24 +25,24 @@ public class Arm implements AutoCloseable { // The P gain for the PID controller that drives this arm. - private double m_armKp = Constants.kDefaultArmKp; - private double m_armSetpointDegrees = Constants.kDefaultArmSetpointDegrees; + private double armKp = Constants.kDefaultArmKp; + private double armSetpointDegrees = Constants.kDefaultArmSetpointDegrees; // The arm gearbox represents a gearbox containing two Vex 775pro motors. - private final DCMotor m_armGearbox = DCMotor.getVex775Pro(2); + private final DCMotor armGearbox = DCMotor.getVex775Pro(2); // Standard classes for controlling our arm - private final PIDController m_controller = new PIDController(m_armKp, 0, 0); - private final Encoder m_encoder = + private final PIDController controller = new PIDController(armKp, 0, 0); + private final Encoder encoder = new Encoder(Constants.kEncoderAChannel, Constants.kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(Constants.kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(Constants.kMotorPort); // Simulation classes help us simulate what's going on, including gravity. // This arm sim represents an arm that can travel from -75 degrees (rotated down front) // to 255 degrees (rotated down in the back). - private final SingleJointedArmSim m_armSim = + private final SingleJointedArmSim armSim = new SingleJointedArmSim( - m_armGearbox, + armGearbox, Constants.kArmReduction, SingleJointedArmSim.estimateMOI(Constants.kArmLength, Constants.kArmMass), Constants.kArmLength, @@ -53,83 +53,82 @@ public class Arm implements AutoCloseable { Constants.kArmEncoderDistPerPulse, 0.0 // Add noise with a std-dev of 1 tick ); - private final EncoderSim m_encoderSim = new EncoderSim(m_encoder); + private final EncoderSim encoderSim = new EncoderSim(encoder); // Create a Mechanism2d display of an Arm with a fixed ArmTower and moving Arm. - private final Mechanism2d m_mech2d = new Mechanism2d(60, 60); - private final MechanismRoot2d m_armPivot = m_mech2d.getRoot("ArmPivot", 30, 30); - private final MechanismLigament2d m_armTower = - m_armPivot.append(new MechanismLigament2d("ArmTower", 30, -90)); - private final MechanismLigament2d m_arm = - m_armPivot.append( + private final Mechanism2d mech2d = new Mechanism2d(60, 60); + private final MechanismRoot2d armPivot = mech2d.getRoot("ArmPivot", 30, 30); + private final MechanismLigament2d armTower = + armPivot.append(new MechanismLigament2d("ArmTower", 30, -90)); + private final MechanismLigament2d arm = + armPivot.append( new MechanismLigament2d( "Arm", 30, - Units.radiansToDegrees(m_armSim.getAngle()), + Units.radiansToDegrees(armSim.getAngle()), 6, new Color8Bit(Color.YELLOW))); /** Subsystem constructor. */ public Arm() { - m_encoder.setDistancePerPulse(Constants.kArmEncoderDistPerPulse); + encoder.setDistancePerPulse(Constants.kArmEncoderDistPerPulse); // Put Mechanism 2d to SmartDashboard - SmartDashboard.putData("Arm Sim", m_mech2d); - m_armTower.setColor(new Color8Bit(Color.BLUE)); + SmartDashboard.putData("Arm Sim", mech2d); + armTower.setColor(new Color8Bit(Color.BLUE)); // Set the Arm position setpoint and P constant to Preferences if the keys don't already exist - Preferences.initDouble(Constants.kArmPositionKey, m_armSetpointDegrees); - Preferences.initDouble(Constants.kArmPKey, m_armKp); + Preferences.initDouble(Constants.kArmPositionKey, armSetpointDegrees); + Preferences.initDouble(Constants.kArmPKey, armKp); } /** Update the simulation model. */ public void simulationPeriodic() { // In this method, we update our simulation of what our arm is doing // First, we set our "inputs" (voltages) - m_armSim.setInput(m_motor.getThrottle() * RobotController.getBatteryVoltage()); + armSim.setInput(motor.getThrottle() * RobotController.getBatteryVoltage()); // Next, we update it. The standard loop time is 20ms. - m_armSim.update(0.020); + armSim.update(0.020); // Finally, we set our simulated encoder's readings and simulated battery voltage - m_encoderSim.setDistance(m_armSim.getAngle()); + encoderSim.setDistance(armSim.getAngle()); // SimBattery estimates loaded battery voltages RoboRioSim.setVInVoltage( - BatterySim.calculateDefaultBatteryLoadedVoltage(m_armSim.getCurrentDraw())); + BatterySim.calculateDefaultBatteryLoadedVoltage(armSim.getCurrentDraw())); // Update the Mechanism Arm angle based on the simulated arm angle - m_arm.setAngle(Units.radiansToDegrees(m_armSim.getAngle())); + arm.setAngle(Units.radiansToDegrees(armSim.getAngle())); } /** Load setpoint and kP from preferences. */ public void loadPreferences() { // Read Preferences for Arm setpoint and kP on entering Teleop - m_armSetpointDegrees = Preferences.getDouble(Constants.kArmPositionKey, m_armSetpointDegrees); - if (m_armKp != Preferences.getDouble(Constants.kArmPKey, m_armKp)) { - m_armKp = Preferences.getDouble(Constants.kArmPKey, m_armKp); - m_controller.setP(m_armKp); + armSetpointDegrees = Preferences.getDouble(Constants.kArmPositionKey, armSetpointDegrees); + if (armKp != Preferences.getDouble(Constants.kArmPKey, armKp)) { + armKp = Preferences.getDouble(Constants.kArmPKey, armKp); + controller.setP(armKp); } } /** Run the control loop to reach and maintain the setpoint from the preferences. */ public void reachSetpoint() { var pidOutput = - m_controller.calculate( - m_encoder.getDistance(), Units.degreesToRadians(m_armSetpointDegrees)); - m_motor.setVoltage(pidOutput); + controller.calculate(encoder.getDistance(), Units.degreesToRadians(armSetpointDegrees)); + motor.setVoltage(pidOutput); } public void stop() { - m_motor.setThrottle(0.0); + motor.setThrottle(0.0); } @Override public void close() { - m_motor.close(); - m_encoder.close(); - m_mech2d.close(); - m_armPivot.close(); - m_controller.close(); - m_arm.close(); + motor.close(); + encoder.close(); + mech2d.close(); + armPivot.close(); + controller.close(); + arm.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Drivetrain.java index 5c4682d4e0b..821ef452c6a 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Drivetrain.java @@ -23,54 +23,54 @@ public class Drivetrain { private static final double kWheelRadius = 0.0508; // meters private static final int kEncoderResolution = 4096; - private final PWMSparkMax m_leftLeader = new PWMSparkMax(1); - private final PWMSparkMax m_leftFollower = new PWMSparkMax(2); - private final PWMSparkMax m_rightLeader = new PWMSparkMax(3); - private final PWMSparkMax m_rightFollower = new PWMSparkMax(4); + private final PWMSparkMax leftLeader = new PWMSparkMax(1); + private final PWMSparkMax leftFollower = new PWMSparkMax(2); + private final PWMSparkMax rightLeader = new PWMSparkMax(3); + private final PWMSparkMax rightFollower = new PWMSparkMax(4); - private final Encoder m_leftEncoder = new Encoder(0, 1); - private final Encoder m_rightEncoder = new Encoder(2, 3); + private final Encoder leftEncoder = new Encoder(0, 1); + private final Encoder rightEncoder = new Encoder(2, 3); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final PIDController m_leftPIDController = new PIDController(1, 0, 0); - private final PIDController m_rightPIDController = new PIDController(1, 0, 0); + private final PIDController leftPIDController = new PIDController(1, 0, 0); + private final PIDController rightPIDController = new PIDController(1, 0, 0); - private final DifferentialDriveKinematics m_kinematics = + private final DifferentialDriveKinematics kinematics = new DifferentialDriveKinematics(kTrackwidth); - private final DifferentialDriveOdometry m_odometry; + private final DifferentialDriveOdometry odometry; // Gains are for example purposes only - must be determined for your own robot! - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 3); /** * Constructs a differential drive object. Sets the encoder distance per pulse and resets the * gyro. */ public Drivetrain() { - m_imu.resetYaw(); + imu.resetYaw(); - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_leftEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); - m_rightEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + leftEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + rightEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); - m_odometry = + odometry = new DifferentialDriveOdometry( - m_imu.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance()); + imu.getRotation2d(), leftEncoder.getDistance(), rightEncoder.getDistance()); } /** @@ -79,15 +79,14 @@ public Drivetrain() { * @param velocities The desired wheel velocities. */ public void setVelocities(DifferentialDriveWheelVelocities velocities) { - final double leftFeedforward = m_feedforward.calculate(velocities.left); - final double rightFeedforward = m_feedforward.calculate(velocities.right); + final double leftFeedforward = feedforward.calculate(velocities.left); + final double rightFeedforward = feedforward.calculate(velocities.right); - final double leftOutput = - m_leftPIDController.calculate(m_leftEncoder.getRate(), velocities.left); + final double leftOutput = leftPIDController.calculate(leftEncoder.getRate(), velocities.left); final double rightOutput = - m_rightPIDController.calculate(m_rightEncoder.getRate(), velocities.right); - m_leftLeader.setVoltage(leftOutput + leftFeedforward); - m_rightLeader.setVoltage(rightOutput + rightFeedforward); + rightPIDController.calculate(rightEncoder.getRate(), velocities.right); + leftLeader.setVoltage(leftOutput + leftFeedforward); + rightLeader.setVoltage(rightOutput + rightFeedforward); } /** @@ -97,14 +96,12 @@ public void setVelocities(DifferentialDriveWheelVelocities velocities) { * @param rot Angular velocity in rad/s. */ public void drive(double xVelocity, double rot) { - var wheelVelocities = - m_kinematics.toWheelVelocities(new ChassisVelocities(xVelocity, 0.0, rot)); + var wheelVelocities = kinematics.toWheelVelocities(new ChassisVelocities(xVelocity, 0.0, rot)); setVelocities(wheelVelocities); } /** Updates the field-relative position. */ public void updateOdometry() { - m_odometry.update( - m_imu.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance()); + odometry.update(imu.getRotation2d(), leftEncoder.getDistance(), rightEncoder.getDistance()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Robot.java index 425dd3f908e..b21ac40c553 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdrivebot/Robot.java @@ -9,17 +9,17 @@ import org.wpilib.math.filter.SlewRateLimiter; public class Robot extends TimedRobot { - private final Gamepad m_controller = new Gamepad(0); - private final Drivetrain m_drive = new Drivetrain(); + private final Gamepad controller = new Gamepad(0); + private final Drivetrain drive = new Drivetrain(); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 to 1. - private final SlewRateLimiter m_velocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter velocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); @Override public void autonomousPeriodic() { teleopPeriodic(); - m_drive.updateOdometry(); + drive.updateOdometry(); } @Override @@ -27,15 +27,14 @@ public void teleopPeriodic() { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. final var xVelocity = - -m_velocityLimiter.calculate(m_controller.getLeftY()) * Drivetrain.kMaxVelocity; + -velocityLimiter.calculate(controller.getLeftY()) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - final var rot = - -m_rotLimiter.calculate(m_controller.getRightX()) * Drivetrain.kMaxAngularVelocity; + final var rot = -rotLimiter.calculate(controller.getRightX()) * Drivetrain.kMaxAngularVelocity; - m_drive.drive(xVelocity, rot); + drive.drive(xVelocity, rot); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Drivetrain.java index 6aa067264d5..7e138975e48 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Drivetrain.java @@ -46,89 +46,89 @@ public class Drivetrain { private static final double kWheelRadius = 0.0508; // meters private static final int kEncoderResolution = 4096; - private final PWMSparkMax m_leftLeader = new PWMSparkMax(1); - private final PWMSparkMax m_leftFollower = new PWMSparkMax(2); - private final PWMSparkMax m_rightLeader = new PWMSparkMax(3); - private final PWMSparkMax m_rightFollower = new PWMSparkMax(4); + private final PWMSparkMax leftLeader = new PWMSparkMax(1); + private final PWMSparkMax leftFollower = new PWMSparkMax(2); + private final PWMSparkMax rightLeader = new PWMSparkMax(3); + private final PWMSparkMax rightFollower = new PWMSparkMax(4); - private final Encoder m_leftEncoder = new Encoder(0, 1); - private final Encoder m_rightEncoder = new Encoder(2, 3); + private final Encoder leftEncoder = new Encoder(0, 1); + private final Encoder rightEncoder = new Encoder(2, 3); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final PIDController m_leftPIDController = new PIDController(1, 0, 0); - private final PIDController m_rightPIDController = new PIDController(1, 0, 0); + private final PIDController leftPIDController = new PIDController(1, 0, 0); + private final PIDController rightPIDController = new PIDController(1, 0, 0); - private final DifferentialDriveKinematics m_kinematics = + private final DifferentialDriveKinematics kinematics = new DifferentialDriveKinematics(kTrackwidth); - private final Pose3d m_objectInField; + private final Pose3d objectInField; - private final Transform3d m_robotToCamera = + private final Transform3d robotToCamera = new Transform3d(new Translation3d(1, 1, 1), new Rotation3d(0, 0, Math.PI / 2)); - private final DoubleArrayEntry m_cameraToObjectEntry; + private final DoubleArrayEntry cameraToObjectEntry; - private final double[] m_defaultVal = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + private final double[] defaultVal = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - private final Field2d m_fieldSim = new Field2d(); - private final Field2d m_fieldApproximation = new Field2d(); + private final Field2d fieldSim = new Field2d(); + private final Field2d fieldApproximation = new Field2d(); /* Here we use DifferentialDrivePoseEstimator so that we can fuse odometry readings. The numbers used below are robot specific, and should be tuned. */ - private final DifferentialDrivePoseEstimator m_poseEstimator = + private final DifferentialDrivePoseEstimator poseEstimator = new DifferentialDrivePoseEstimator( - m_kinematics, - m_imu.getRotation2d(), - m_leftEncoder.getDistance(), - m_rightEncoder.getDistance(), + kinematics, + imu.getRotation2d(), + leftEncoder.getDistance(), + rightEncoder.getDistance(), Pose2d.kZero, VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5)), VecBuilder.fill(0.5, 0.5, Units.degreesToRadians(30))); // Gains are for example purposes only - must be determined for your own robot! - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 3); // Simulation classes - private final EncoderSim m_leftEncoderSim = new EncoderSim(m_leftEncoder); - private final EncoderSim m_rightEncoderSim = new EncoderSim(m_rightEncoder); - private final LinearSystem m_drivetrainSystem = + private final EncoderSim leftEncoderSim = new EncoderSim(leftEncoder); + private final EncoderSim rightEncoderSim = new EncoderSim(rightEncoder); + private final LinearSystem drivetrainSystem = Models.differentialDriveFromSysId(1.98, 0.2, 1.5, 0.3); - private final DifferentialDrivetrainSim m_drivetrainSimulator = + private final DifferentialDrivetrainSim drivetrainSimulator = new DifferentialDrivetrainSim( - m_drivetrainSystem, DCMotor.getCIM(2), 8, kTrackwidth, kWheelRadius, null); + drivetrainSystem, DCMotor.getCIM(2), 8, kTrackwidth, kWheelRadius, null); /** * Constructs a differential drive object. Sets the encoder distance per pulse and resets the * gyro. */ public Drivetrain(DoubleArrayTopic cameraToObjectTopic) { - m_imu.resetYaw(); + imu.resetYaw(); - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_leftEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); - m_rightEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + leftEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + rightEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); - m_cameraToObjectEntry = cameraToObjectTopic.getEntry(m_defaultVal); + cameraToObjectEntry = cameraToObjectTopic.getEntry(defaultVal); - m_objectInField = + objectInField = AprilTagFieldLayout.loadField(AprilTagFields.k2024Crescendo).getTagPose(0).get(); - SmartDashboard.putData("Field", m_fieldSim); - SmartDashboard.putData("FieldEstimation", m_fieldApproximation); + SmartDashboard.putData("Field", fieldSim); + SmartDashboard.putData("FieldEstimation", fieldApproximation); } /** @@ -137,15 +137,14 @@ public Drivetrain(DoubleArrayTopic cameraToObjectTopic) { * @param velocities The desired wheel velocities. */ public void setVelocities(DifferentialDriveWheelVelocities velocities) { - final double leftFeedforward = m_feedforward.calculate(velocities.left); - final double rightFeedforward = m_feedforward.calculate(velocities.right); + final double leftFeedforward = feedforward.calculate(velocities.left); + final double rightFeedforward = feedforward.calculate(velocities.right); - final double leftOutput = - m_leftPIDController.calculate(m_leftEncoder.getRate(), velocities.left); + final double leftOutput = leftPIDController.calculate(leftEncoder.getRate(), velocities.left); final double rightOutput = - m_rightPIDController.calculate(m_rightEncoder.getRate(), velocities.right); - m_leftLeader.setVoltage(leftOutput + leftFeedforward); - m_rightLeader.setVoltage(rightOutput + rightFeedforward); + rightPIDController.calculate(rightEncoder.getRate(), velocities.right); + leftLeader.setVoltage(leftOutput + leftFeedforward); + rightLeader.setVoltage(rightOutput + rightFeedforward); } /** @@ -155,8 +154,7 @@ public void setVelocities(DifferentialDriveWheelVelocities velocities) { * @param rot Angular velocity in rad/s. */ public void drive(double xVelocity, double rot) { - var wheelVelocities = - m_kinematics.toWheelVelocities(new ChassisVelocities(xVelocity, 0.0, rot)); + var wheelVelocities = kinematics.toWheelVelocities(new ChassisVelocities(xVelocity, 0.0, rot)); setVelocities(wheelVelocities); } @@ -221,25 +219,24 @@ public Pose3d objectToRobotPose( /** Updates the field-relative position. */ public void updateOdometry() { - m_poseEstimator.update( - m_imu.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance()); + poseEstimator.update( + imu.getRotation2d(), leftEncoder.getDistance(), rightEncoder.getDistance()); // Publish cameraToObject transformation to networktables --this would normally be handled by // the // computer vision solution. - publishCameraToObject( - m_objectInField, m_robotToCamera, m_cameraToObjectEntry, m_drivetrainSimulator); + publishCameraToObject(objectInField, robotToCamera, cameraToObjectEntry, drivetrainSimulator); // Compute the robot's field-relative position exclusively from vision measurements. Pose3d visionMeasurement3d = - objectToRobotPose(m_objectInField, m_robotToCamera, m_cameraToObjectEntry); + objectToRobotPose(objectInField, robotToCamera, cameraToObjectEntry); // Convert robot pose from Pose3d to Pose2d needed to apply vision measurements. Pose2d visionMeasurement2d = visionMeasurement3d.toPose2d(); // Apply vision measurements. For simulation purposes only, we don't input a latency delay -- on // a real robot, this must be calculated based either on known latency or timestamps. - m_poseEstimator.addVisionMeasurement(visionMeasurement2d, Timer.getTimestamp()); + poseEstimator.addVisionMeasurement(visionMeasurement2d, Timer.getTimestamp()); } /** This function is called periodically during simulation. */ @@ -247,23 +244,23 @@ public void simulationPeriodic() { // To update our simulation, we set motor voltage inputs, update the // simulation, and write the simulated positions and velocities to our // simulated encoder and gyro. - m_drivetrainSimulator.setInputs( - m_leftLeader.getThrottle() * RobotController.getInputVoltage(), - m_rightLeader.getThrottle() * RobotController.getInputVoltage()); - m_drivetrainSimulator.update(0.02); - - m_leftEncoderSim.setDistance(m_drivetrainSimulator.getLeftPosition()); - m_leftEncoderSim.setRate(m_drivetrainSimulator.getLeftVelocity()); - m_rightEncoderSim.setDistance(m_drivetrainSimulator.getRightPosition()); - m_rightEncoderSim.setRate(m_drivetrainSimulator.getRightVelocity()); - // m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); // TODO(Ryan): fixup + drivetrainSimulator.setInputs( + leftLeader.getThrottle() * RobotController.getInputVoltage(), + rightLeader.getThrottle() * RobotController.getInputVoltage()); + drivetrainSimulator.update(0.02); + + leftEncoderSim.setDistance(drivetrainSimulator.getLeftPosition()); + leftEncoderSim.setRate(drivetrainSimulator.getLeftVelocity()); + rightEncoderSim.setDistance(drivetrainSimulator.getRightPosition()); + rightEncoderSim.setRate(drivetrainSimulator.getRightVelocity()); + // gyroSim.setAngle(-drivetrainSimulator.getHeading().getDegrees()); // TODO(Ryan): fixup // when sim implemented } /** This function is called periodically, no matter the mode. */ public void periodic() { updateOdometry(); - m_fieldSim.setRobotPose(m_drivetrainSimulator.getPose()); - m_fieldApproximation.setRobotPose(m_poseEstimator.getEstimatedPosition()); + fieldSim.setRobotPose(drivetrainSimulator.getPose()); + fieldApproximation.setRobotPose(poseEstimator.getEstimatedPosition()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Robot.java index 83ccebbba29..cfba054d103 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/differentialdriveposeestimator/Robot.java @@ -11,31 +11,30 @@ import org.wpilib.networktables.NetworkTableInstance; public class Robot extends TimedRobot { - private final NetworkTableInstance m_inst = NetworkTableInstance.getDefault(); - private final DoubleArrayTopic m_doubleArrayTopic = - m_inst.getDoubleArrayTopic("m_doubleArrayTopic"); + private final NetworkTableInstance inst = NetworkTableInstance.getDefault(); + private final DoubleArrayTopic doubleArrayTopic = inst.getDoubleArrayTopic("doubleArrayTopic"); - private final Gamepad m_controller = new Gamepad(0); - private final Drivetrain m_drive = new Drivetrain(m_doubleArrayTopic); + private final Gamepad controller = new Gamepad(0); + private final Drivetrain drive = new Drivetrain(doubleArrayTopic); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 to 1. - private final SlewRateLimiter m_velocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter velocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); @Override public void autonomousPeriodic() { teleopPeriodic(); - m_drive.updateOdometry(); + drive.updateOdometry(); } @Override public void simulationPeriodic() { - m_drive.simulationPeriodic(); + drive.simulationPeriodic(); } @Override public void robotPeriodic() { - m_drive.periodic(); + drive.periodic(); } @Override @@ -43,15 +42,14 @@ public void teleopPeriodic() { // Get the x velocity. We are inverting this because gamepad return // negative values when we push forward. final var xVelocity = - -m_velocityLimiter.calculate(m_controller.getLeftY()) * Drivetrain.kMaxVelocity; + -velocityLimiter.calculate(controller.getLeftY()) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - final var rot = - -m_rotLimiter.calculate(m_controller.getRightX()) * Drivetrain.kMaxAngularVelocity; + final var rot = -rotLimiter.calculate(controller.getRightX()) * Drivetrain.kMaxAngularVelocity; - m_drive.drive(xVelocity, rot); + drive.drive(xVelocity, rot); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/ExampleSmartMotorController.java b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/ExampleSmartMotorController.java index a84dfef45bf..0e226629c77 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/ExampleSmartMotorController.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/ExampleSmartMotorController.java @@ -16,7 +16,7 @@ public enum PIDMode { kMovementWitchcraft } - double m_value; + double value; /** * Creates a new ExampleSmartMotorController. @@ -72,11 +72,11 @@ public double getEncoderRate() { public void resetEncoder() {} public void setThrottle(double throttle) { - m_value = throttle; + value = throttle; } public double getThrottle() { - return m_value; + return value; } public void setInverted(boolean isInverted) {} diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/Robot.java index 24cf9b7666e..32183712866 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -25,7 +25,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,7 +54,7 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); /* * String autoSelected = SmartDashboard.getString("Auto Selector", @@ -64,8 +64,8 @@ public void autonomousInit() { */ // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -79,8 +79,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/RobotContainer.java index 98ae778f677..17f4344b2b4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/RobotContainer.java @@ -19,15 +19,14 @@ */ public class RobotContainer { // The robot's subsystems - private final DriveSubsystem m_robotDrive = new DriveSubsystem(); + private final DriveSubsystem robotDrive = new DriveSubsystem(); // Retained command references - private final Command m_driveFullVelocity = Commands.runOnce(() -> m_robotDrive.setMaxOutput(1)); - private final Command m_driveHalfVelocity = - Commands.runOnce(() -> m_robotDrive.setMaxOutput(0.5)); + private final Command driveFullVelocity = Commands.runOnce(() -> robotDrive.setMaxOutput(1)); + private final Command driveHalfVelocity = Commands.runOnce(() -> robotDrive.setMaxOutput(0.5)); // The driver's controller - CommandGamepad m_driverController = new CommandGamepad(OIConstants.kDriverControllerPort); + CommandGamepad driverController = new CommandGamepad(OIConstants.kDriverControllerPort); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { @@ -36,14 +35,13 @@ public RobotContainer() { // Configure default commands // Set the default drive command to split-stick arcade drive - m_robotDrive.setDefaultCommand( + robotDrive.setDefaultCommand( // A split-stick arcade command, with forward/backward controlled by the left // hand, and turning controlled by the right. Commands.run( () -> - m_robotDrive.arcadeDrive( - -m_driverController.getLeftY(), -m_driverController.getRightX()), - m_robotDrive)); + robotDrive.arcadeDrive(-driverController.getLeftY(), -driverController.getRightX()), + robotDrive)); } /** @@ -54,17 +52,15 @@ public RobotContainer() { */ private void configureButtonBindings() { // Drive at half velocity when the bumper is held - m_driverController.rightBumper().onTrue(m_driveHalfVelocity).onFalse(m_driveFullVelocity); + driverController.rightBumper().onTrue(driveHalfVelocity).onFalse(driveFullVelocity); // Drive forward by 3 meters when the 'South Face' button is pressed, with a timeout of 10 // seconds - m_driverController.southFace().onTrue(m_robotDrive.profiledDriveDistance(3).withTimeout(10)); + driverController.southFace().onTrue(robotDrive.profiledDriveDistance(3).withTimeout(10)); // Do the same thing as above when the 'East Face' button is pressed, but without resetting the // encoders - m_driverController - .eastFace() - .onTrue(m_robotDrive.dynamicProfiledDriveDistance(3).withTimeout(10)); + driverController.eastFace().onTrue(robotDrive.dynamicProfiledDriveDistance(3).withTimeout(10)); } /** diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java index 7604dfd0cd1..0cb5d7d88d7 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/drivedistanceoffboard/subsystems/DriveSubsystem.java @@ -18,51 +18,51 @@ public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final ExampleSmartMotorController m_leftLeader = + private final ExampleSmartMotorController leftLeader = new ExampleSmartMotorController(DriveConstants.kLeftMotor1Port); - private final ExampleSmartMotorController m_leftFollower = + private final ExampleSmartMotorController leftFollower = new ExampleSmartMotorController(DriveConstants.kLeftMotor2Port); // The motors on the right side of the drive. - private final ExampleSmartMotorController m_rightLeader = + private final ExampleSmartMotorController rightLeader = new ExampleSmartMotorController(DriveConstants.kRightMotor1Port); - private final ExampleSmartMotorController m_rightFollower = + private final ExampleSmartMotorController rightFollower = new ExampleSmartMotorController(DriveConstants.kRightMotor2Port); // The feedforward controller. - private final SimpleMotorFeedforward m_feedforward = + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(DriveConstants.ks, DriveConstants.kv, DriveConstants.ka); // The robot's drive - private final DifferentialDrive m_drive = - new DifferentialDrive(m_leftLeader::setThrottle, m_rightLeader::setThrottle); + private final DifferentialDrive drive = + new DifferentialDrive(leftLeader::setThrottle, rightLeader::setThrottle); // The trapezoid profile - private final TrapezoidProfile m_profile = + private final TrapezoidProfile profile = new TrapezoidProfile( new TrapezoidProfile.Constraints( DriveConstants.kMaxVelocity, DriveConstants.kMaxAcceleration)); // The timer - private final Timer m_timer = new Timer(); + private final Timer timer = new Timer(); /** Creates a new DriveSubsystem. */ public DriveSubsystem() { - SendableRegistry.addChild(m_drive, m_leftLeader); - SendableRegistry.addChild(m_drive, m_rightLeader); + SendableRegistry.addChild(drive, leftLeader); + SendableRegistry.addChild(drive, rightLeader); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); - m_leftFollower.follow(m_leftLeader); - m_rightFollower.follow(m_rightLeader); + leftFollower.follow(leftLeader); + rightFollower.follow(rightLeader); - m_leftLeader.setPID(DriveConstants.kp, 0, 0); - m_rightLeader.setPID(DriveConstants.kp, 0, 0); + leftLeader.setPID(DriveConstants.kp, 0, 0); + rightLeader.setPID(DriveConstants.kp, 0, 0); } /** @@ -72,7 +72,7 @@ public DriveSubsystem() { * @param rot the commanded rotation */ public void arcadeDrive(double fwd, double rot) { - m_drive.arcadeDrive(fwd, rot); + drive.arcadeDrive(fwd, rot); } /** @@ -89,15 +89,15 @@ public void setDriveStates( TrapezoidProfile.State nextLeft, TrapezoidProfile.State nextRight) { // Feedforward is divided by battery voltage to normalize it to [-1, 1] - m_leftLeader.setSetpoint( + leftLeader.setSetpoint( ExampleSmartMotorController.PIDMode.kPosition, currentLeft.position, - m_feedforward.calculate(currentLeft.velocity, nextLeft.velocity) + feedforward.calculate(currentLeft.velocity, nextLeft.velocity) / RobotController.getBatteryVoltage()); - m_rightLeader.setSetpoint( + rightLeader.setSetpoint( ExampleSmartMotorController.PIDMode.kPosition, currentRight.position, - m_feedforward.calculate(currentLeft.velocity, nextLeft.velocity) + feedforward.calculate(currentLeft.velocity, nextLeft.velocity) / RobotController.getBatteryVoltage()); } @@ -107,7 +107,7 @@ public void setDriveStates( * @return the left encoder distance */ public double getLeftEncoderDistance() { - return m_leftLeader.getEncoderDistance(); + return leftLeader.getEncoderDistance(); } /** @@ -116,13 +116,13 @@ public double getLeftEncoderDistance() { * @return the right encoder distance */ public double getRightEncoderDistance() { - return m_rightLeader.getEncoderDistance(); + return rightLeader.getEncoderDistance(); } /** Resets the drive encoders. */ public void resetEncoders() { - m_leftLeader.resetEncoder(); - m_rightLeader.resetEncoder(); + leftLeader.resetEncoder(); + rightLeader.resetEncoder(); } /** @@ -131,7 +131,7 @@ public void resetEncoders() { * @param maxOutput the maximum output to which the drive will be constrained */ public void setMaxOutput(double maxOutput) { - m_drive.setMaxOutput(maxOutput); + drive.setMaxOutput(maxOutput); } /** @@ -144,25 +144,25 @@ public Command profiledDriveDistance(double distance) { return startRun( () -> { // Restart timer so profile setpoints start at the beginning - m_timer.restart(); + timer.restart(); resetEncoders(); }, () -> { // Current state never changes, so we need to use a timer to get the setpoints we need // to be at - var currentTime = m_timer.get(); + var currentTime = timer.get(); var currentSetpoint = - m_profile.calculate(currentTime, new State(), new State(distance, 0)); + profile.calculate(currentTime, new State(), new State(distance, 0)); var nextSetpoint = - m_profile.calculate( + profile.calculate( currentTime + DriveConstants.kDt, new State(), new State(distance, 0)); setDriveStates(currentSetpoint, currentSetpoint, nextSetpoint, nextSetpoint); }) - .until(() -> m_profile.isFinished(0)); + .until(() -> profile.isFinished(0)); } - private double m_initialLeftDistance; - private double m_initialRightDistance; + private double initialLeftDistance; + private double initialRightDistance; /** * Creates a command to drive forward a specified distance using a motion profile without @@ -175,38 +175,38 @@ public Command dynamicProfiledDriveDistance(double distance) { return startRun( () -> { // Restart timer so profile setpoints start at the beginning - m_timer.restart(); + timer.restart(); // Store distance so we know the target distance for each encoder - m_initialLeftDistance = getLeftEncoderDistance(); - m_initialRightDistance = getRightEncoderDistance(); + initialLeftDistance = getLeftEncoderDistance(); + initialRightDistance = getRightEncoderDistance(); }, () -> { // Current state never changes for the duration of the command, so we need to use a // timer to get the setpoints we need to be at - var currentTime = m_timer.get(); + var currentTime = timer.get(); var currentLeftSetpoint = - m_profile.calculate( + profile.calculate( currentTime, - new State(m_initialLeftDistance, 0), - new State(m_initialLeftDistance + distance, 0)); + new State(initialLeftDistance, 0), + new State(initialLeftDistance + distance, 0)); var currentRightSetpoint = - m_profile.calculate( + profile.calculate( currentTime, - new State(m_initialRightDistance, 0), - new State(m_initialRightDistance + distance, 0)); + new State(initialRightDistance, 0), + new State(initialRightDistance + distance, 0)); var nextLeftSetpoint = - m_profile.calculate( + profile.calculate( currentTime + DriveConstants.kDt, - new State(m_initialLeftDistance, 0), - new State(m_initialLeftDistance + distance, 0)); + new State(initialLeftDistance, 0), + new State(initialLeftDistance + distance, 0)); var nextRightSetpoint = - m_profile.calculate( + profile.calculate( currentTime + DriveConstants.kDt, - new State(m_initialRightDistance, 0), - new State(m_initialRightDistance + distance, 0)); + new State(initialRightDistance, 0), + new State(initialRightDistance + distance, 0)); setDriveStates( currentLeftSetpoint, currentRightSetpoint, nextLeftSetpoint, nextRightSetpoint); }) - .until(() -> m_profile.isFinished(0)); + .until(() -> profile.isFinished(0)); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/dutycycleencoder/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/dutycycleencoder/Robot.java index e556456d9d7..06b0bd1081d 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/dutycycleencoder/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/dutycycleencoder/Robot.java @@ -11,9 +11,9 @@ /** This example shows how to use a duty cycle encoder for devices such as an arm or elevator. */ public class Robot extends TimedRobot { - private final DutyCycleEncoder m_dutyCycleEncoder; - private static final double m_fullRange = 1.3; - private static final double m_expectedZero = 0; + private final DutyCycleEncoder dutyCycleEncoder; + private static final double fullRange = 1.3; + private static final double expectedZero = 0; /** Called once at the beginning of the robot program. */ public Robot() { @@ -23,7 +23,7 @@ public Robot() { // to measure this is fairly easy. Set the value to 0, place the mechanism // where you want "0" to be, and observe the value on the dashboard, That // is the value to enter for the 3rd parameter. - m_dutyCycleEncoder = new DutyCycleEncoder(0, m_fullRange, m_expectedZero); + dutyCycleEncoder = new DutyCycleEncoder(0, fullRange, expectedZero); // If you know the frequency of your sensor, uncomment the following // method, and set the method to the frequency of your sensor. @@ -36,19 +36,19 @@ public Robot() { // those values. This number doesn't have to be perfect, // just having a fairly close value will make the output readings // much more stable. - m_dutyCycleEncoder.setAssumedFrequency(967.8); + dutyCycleEncoder.setAssumedFrequency(967.8); } @Override public void robotPeriodic() { // Connected can be checked, and uses the frequency of the encoder - boolean connected = m_dutyCycleEncoder.isConnected(); + boolean connected = dutyCycleEncoder.isConnected(); // Duty Cycle Frequency in Hz - double frequency = m_dutyCycleEncoder.getFrequency(); + double frequency = dutyCycleEncoder.getFrequency(); // Output of encoder - double output = m_dutyCycleEncoder.get(); + double output = dutyCycleEncoder.get(); // By default, the output will wrap around to the full range value // when the sensor goes below 0. However, for moving mechanisms this @@ -60,9 +60,9 @@ public void robotPeriodic() { // can go a bit negative before wrapping. Usually 10% or so is fine. // This does not change where "0" is, so no calibration numbers need // to be changed. - double percentOfRange = m_fullRange * 0.1; + double percentOfRange = fullRange * 0.1; double shiftedOutput = - MathUtil.inputModulus(output, 0 - percentOfRange, m_fullRange - percentOfRange); + MathUtil.inputModulus(output, 0 - percentOfRange, fullRange - percentOfRange); SmartDashboard.putBoolean("Connected", connected); SmartDashboard.putNumber("Frequency", frequency); diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialprofile/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialprofile/Robot.java index 5127c54d621..8f2c68f97c4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialprofile/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialprofile/Robot.java @@ -12,41 +12,41 @@ public class Robot extends TimedRobot { private static double kDt = 0.02; - private final Joystick m_joystick = new Joystick(1); - private final ExampleSmartMotorController m_motor = new ExampleSmartMotorController(1); + private final Joystick joystick = new Joystick(1); + private final ExampleSmartMotorController motor = new ExampleSmartMotorController(1); // Note: These gains are fake, and will have to be tuned for your robot. - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 1, 1); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 1, 1); // Create a motion profile with the given maximum voltage and characteristics kV, kA // These gains should match your feedforward kV, kA for best results. - private final ExponentialProfile m_profile = + private final ExponentialProfile profile = new ExponentialProfile(ExponentialProfile.Constraints.fromCharacteristics(10, 1, 1)); - private ExponentialProfile.State m_goal = new ExponentialProfile.State(0, 0); - private ExponentialProfile.State m_setpoint = new ExponentialProfile.State(0, 0); + private ExponentialProfile.State goal = new ExponentialProfile.State(0, 0); + private ExponentialProfile.State setpoint = new ExponentialProfile.State(0, 0); public Robot() { // Note: These gains are fake, and will have to be tuned for your robot. - m_motor.setPID(1.3, 0.0, 0.7); + motor.setPID(1.3, 0.0, 0.7); } @Override public void teleopPeriodic() { - if (m_joystick.getRawButtonPressed(2)) { - m_goal = new ExponentialProfile.State(5, 0); - } else if (m_joystick.getRawButtonPressed(3)) { - m_goal = new ExponentialProfile.State(0, 0); + if (joystick.getRawButtonPressed(2)) { + goal = new ExponentialProfile.State(5, 0); + } else if (joystick.getRawButtonPressed(3)) { + goal = new ExponentialProfile.State(0, 0); } // Retrieve the profiled setpoint for the next timestep. This setpoint moves // toward the goal while obeying the constraints. - ExponentialProfile.State next = m_profile.calculate(kDt, m_setpoint, m_goal); + ExponentialProfile.State next = profile.calculate(kDt, setpoint, goal); // Send setpoint to offboard controller PID - m_motor.setSetpoint( + motor.setSetpoint( ExampleSmartMotorController.PIDMode.kPosition, - m_setpoint.position, - m_feedforward.calculate(next.velocity) / 12.0); + setpoint.position, + feedforward.calculate(next.velocity) / 12.0); - m_setpoint = next; + setpoint = next; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/Robot.java index e17ee1dea34..54d1a2125b2 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/Robot.java @@ -10,8 +10,8 @@ /** This is a sample program to demonstrate the use of elevator simulation. */ public class Robot extends TimedRobot { - private final Joystick m_joystick = new Joystick(Constants.kJoystickPort); - private final Elevator m_elevator = new Elevator(); + private final Joystick joystick = new Joystick(Constants.kJoystickPort); + private final Elevator elevator = new Elevator(); public Robot() { super(0.020); @@ -20,40 +20,40 @@ public Robot() { @Override public void robotPeriodic() { // Update the telemetry, including mechanism visualization, regardless of mode. - m_elevator.updateTelemetry(); + elevator.updateTelemetry(); } @Override public void simulationPeriodic() { // Update the simulation model. - m_elevator.simulationPeriodic(); + elevator.simulationPeriodic(); } @Override public void teleopInit() { - m_elevator.reset(); + elevator.reset(); } @Override public void teleopPeriodic() { - if (m_joystick.getTrigger()) { + if (joystick.getTrigger()) { // Here, we set the constant setpoint of 10 meters. - m_elevator.reachGoal(Constants.kSetpoint); + elevator.reachGoal(Constants.kSetpoint); } else { // Otherwise, we update the setpoint to 1 meter. - m_elevator.reachGoal(Constants.kLowerkSetpoint); + elevator.reachGoal(Constants.kLowerkSetpoint); } } @Override public void disabledInit() { // This just makes sure that our simulation code knows that the motor's off. - m_elevator.stop(); + elevator.stop(); } @Override public void close() { - m_elevator.close(); + elevator.close(); super.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/subsystems/Elevator.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/subsystems/Elevator.java index 33dabafae8c..9d539646a0d 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/subsystems/Elevator.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorexponentialsimulation/subsystems/Elevator.java @@ -25,33 +25,33 @@ public class Elevator implements AutoCloseable { // This gearbox represents a gearbox containing 4 Vex 775pro motors. - private final DCMotor m_elevatorGearbox = DCMotor.getNEO(2); + private final DCMotor elevatorGearbox = DCMotor.getNEO(2); - private final ExponentialProfile m_profile = + private final ExponentialProfile profile = new ExponentialProfile( ExponentialProfile.Constraints.fromCharacteristics( Constants.kElevatorMaxV, Constants.kElevatorkV, Constants.kElevatorkA)); - private ExponentialProfile.State m_setpoint = new ExponentialProfile.State(0, 0); + private ExponentialProfile.State setpoint = new ExponentialProfile.State(0, 0); // Standard classes for controlling our elevator - private final PIDController m_pidController = + private final PIDController pidController = new PIDController(Constants.kElevatorKp, Constants.kElevatorKi, Constants.kElevatorKd); - ElevatorFeedforward m_feedforward = + ElevatorFeedforward feedforward = new ElevatorFeedforward( Constants.kElevatorkS, Constants.kElevatorkG, Constants.kElevatorkV, Constants.kElevatorkA); - private final Encoder m_encoder = + private final Encoder encoder = new Encoder(Constants.kEncoderAChannel, Constants.kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(Constants.kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(Constants.kMotorPort); // Simulation classes help us simulate what's going on, including gravity. - private final ElevatorSim m_elevatorSim = + private final ElevatorSim elevatorSim = new ElevatorSim( - m_elevatorGearbox, + elevatorGearbox, Constants.kElevatorGearing, Constants.kCarriageMass, Constants.kElevatorDrumRadius, @@ -61,40 +61,40 @@ public class Elevator implements AutoCloseable { 0, 0.005, 0.0); - private final EncoderSim m_encoderSim = new EncoderSim(m_encoder); - private final PWMMotorControllerSim m_motorSim = new PWMMotorControllerSim(m_motor); + private final EncoderSim encoderSim = new EncoderSim(encoder); + private final PWMMotorControllerSim motorSim = new PWMMotorControllerSim(motor); // Create a Mechanism2d visualization of the elevator - private final Mechanism2d m_mech2d = + private final Mechanism2d mech2d = new Mechanism2d(Units.inchesToMeters(10), Units.inchesToMeters(51)); - private final MechanismRoot2d m_mech2dRoot = - m_mech2d.getRoot("Elevator Root", Units.inchesToMeters(5), Units.inchesToMeters(0.5)); - private final MechanismLigament2d m_elevatorMech2d = - m_mech2dRoot.append(new MechanismLigament2d("Elevator", m_elevatorSim.getPosition(), 90)); + private final MechanismRoot2d mech2dRoot = + mech2d.getRoot("Elevator Root", Units.inchesToMeters(5), Units.inchesToMeters(0.5)); + private final MechanismLigament2d elevatorMech2d = + mech2dRoot.append(new MechanismLigament2d("Elevator", elevatorSim.getPosition(), 90)); /** Subsystem constructor. */ public Elevator() { - m_encoder.setDistancePerPulse(Constants.kElevatorEncoderDistPerPulse); + encoder.setDistancePerPulse(Constants.kElevatorEncoderDistPerPulse); // Publish Mechanism2d to SmartDashboard // To view the Elevator visualization, select Network Tables -> SmartDashboard -> Elevator Sim - SmartDashboard.putData("Elevator Sim", m_mech2d); + SmartDashboard.putData("Elevator Sim", mech2d); } /** Advance the simulation. */ public void simulationPeriodic() { // In this method, we update our simulation of what our elevator is doing // First, we set our "inputs" (voltages) - m_elevatorSim.setInput(m_motorSim.getThrottle() * RobotController.getBatteryVoltage()); + elevatorSim.setInput(motorSim.getThrottle() * RobotController.getBatteryVoltage()); // Next, we update it. The standard loop time is 20ms. - m_elevatorSim.update(0.020); + elevatorSim.update(0.020); // Finally, we set our simulated encoder's readings and simulated battery voltage - m_encoderSim.setDistance(m_elevatorSim.getPosition()); + encoderSim.setDistance(elevatorSim.getPosition()); // SimBattery estimates loaded battery voltages RoboRioSim.setVInVoltage( - BatterySim.calculateDefaultBatteryLoadedVoltage(m_elevatorSim.getCurrentDraw())); + BatterySim.calculateDefaultBatteryLoadedVoltage(elevatorSim.getCurrentDraw())); } /** @@ -105,37 +105,37 @@ public void simulationPeriodic() { public void reachGoal(double goal) { var goalState = new ExponentialProfile.State(goal, 0); - var next = m_profile.calculate(0.020, m_setpoint, goalState); + var next = profile.calculate(0.020, setpoint, goalState); // With the setpoint value we run PID control like normal - double pidOutput = m_pidController.calculate(m_encoder.getDistance(), m_setpoint.position); - double feedforwardOutput = m_feedforward.calculate(m_setpoint.velocity, next.velocity); + double pidOutput = pidController.calculate(encoder.getDistance(), setpoint.position); + double feedforwardOutput = feedforward.calculate(setpoint.velocity, next.velocity); - m_motor.setVoltage(pidOutput + feedforwardOutput); + motor.setVoltage(pidOutput + feedforwardOutput); - m_setpoint = next; + setpoint = next; } /** Stop the control loop and motor output. */ public void stop() { - m_motor.setThrottle(0.0); + motor.setThrottle(0.0); } /** Reset Exponential profile to begin from current position on enable. */ public void reset() { - m_setpoint = new ExponentialProfile.State(m_encoder.getDistance(), 0); + setpoint = new ExponentialProfile.State(encoder.getDistance(), 0); } /** Update telemetry, including the mechanism visualization. */ public void updateTelemetry() { // Update elevator visualization with position - m_elevatorMech2d.setLength(m_encoder.getDistance()); + elevatorMech2d.setLength(encoder.getDistance()); } @Override public void close() { - m_encoder.close(); - m_motor.close(); - m_mech2d.close(); + encoder.close(); + motor.close(); + mech2d.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorprofiledpid/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorprofiledpid/Robot.java index 1dfe05abfaf..914edf8df24 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorprofiledpid/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorprofiledpid/Robot.java @@ -23,33 +23,33 @@ public class Robot extends TimedRobot { private static double kG = 1.2; private static double kV = 1.3; - private final Joystick m_joystick = new Joystick(1); - private final Encoder m_encoder = new Encoder(1, 2); - private final PWMSparkMax m_motor = new PWMSparkMax(1); + private final Joystick joystick = new Joystick(1); + private final Encoder encoder = new Encoder(1, 2); + private final PWMSparkMax motor = new PWMSparkMax(1); // Create a PID controller whose setpoint's change is subject to maximum // velocity and acceleration constraints. - private final TrapezoidProfile.Constraints m_constraints = + private final TrapezoidProfile.Constraints constraints = new TrapezoidProfile.Constraints(kMaxVelocity, kMaxAcceleration); - private final ProfiledPIDController m_controller = - new ProfiledPIDController(kP, kI, kD, m_constraints, kDt); - private final ElevatorFeedforward m_feedforward = new ElevatorFeedforward(kS, kG, kV); + private final ProfiledPIDController controller = + new ProfiledPIDController(kP, kI, kD, constraints, kDt); + private final ElevatorFeedforward feedforward = new ElevatorFeedforward(kS, kG, kV); public Robot() { - m_encoder.setDistancePerPulse(1.0 / 360.0 * 2.0 * Math.PI * 1.5); + encoder.setDistancePerPulse(1.0 / 360.0 * 2.0 * Math.PI * 1.5); } @Override public void teleopPeriodic() { - if (m_joystick.getRawButtonPressed(2)) { - m_controller.setGoal(5); - } else if (m_joystick.getRawButtonPressed(3)) { - m_controller.setGoal(0); + if (joystick.getRawButtonPressed(2)) { + controller.setGoal(5); + } else if (joystick.getRawButtonPressed(3)) { + controller.setGoal(0); } // Run controller and update motor output - m_motor.setVoltage( - m_controller.calculate(m_encoder.getDistance()) - + m_feedforward.calculate(m_controller.getSetpoint().velocity)); + motor.setVoltage( + controller.calculate(encoder.getDistance()) + + feedforward.calculate(controller.getSetpoint().velocity)); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/Robot.java index 3186cf716a4..ee554587cea 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/Robot.java @@ -10,43 +10,43 @@ /** This is a sample program to demonstrate the use of elevator simulation. */ public class Robot extends TimedRobot { - private final Joystick m_joystick = new Joystick(Constants.kJoystickPort); - private final Elevator m_elevator = new Elevator(); + private final Joystick joystick = new Joystick(Constants.kJoystickPort); + private final Elevator elevator = new Elevator(); public Robot() {} @Override public void robotPeriodic() { // Update the telemetry, including mechanism visualization, regardless of mode. - m_elevator.updateTelemetry(); + elevator.updateTelemetry(); } @Override public void simulationPeriodic() { // Update the simulation model. - m_elevator.simulationPeriodic(); + elevator.simulationPeriodic(); } @Override public void teleopPeriodic() { - if (m_joystick.getTrigger()) { + if (joystick.getTrigger()) { // Here, we set the constant setpoint of 0.75 meters. - m_elevator.reachGoal(Constants.kSetpoint); + elevator.reachGoal(Constants.kSetpoint); } else { // Otherwise, we update the setpoint to 0. - m_elevator.reachGoal(0.0); + elevator.reachGoal(0.0); } } @Override public void disabledInit() { // This just makes sure that our simulation code knows that the motor's off. - m_elevator.stop(); + elevator.stop(); } @Override public void close() { - m_elevator.close(); + elevator.close(); super.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/subsystems/Elevator.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/subsystems/Elevator.java index dc2cd935db8..46635fcca6b 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/subsystems/Elevator.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatorsimulation/subsystems/Elevator.java @@ -24,29 +24,29 @@ public class Elevator implements AutoCloseable { // This gearbox represents a gearbox containing 4 Vex 775pro motors. - private final DCMotor m_elevatorGearbox = DCMotor.getVex775Pro(4); + private final DCMotor elevatorGearbox = DCMotor.getVex775Pro(4); // Standard classes for controlling our elevator - private final ProfiledPIDController m_controller = + private final ProfiledPIDController controller = new ProfiledPIDController( Constants.kElevatorKp, Constants.kElevatorKi, Constants.kElevatorKd, new TrapezoidProfile.Constraints(2.45, 2.45)); - ElevatorFeedforward m_feedforward = + ElevatorFeedforward feedforward = new ElevatorFeedforward( Constants.kElevatorkS, Constants.kElevatorkG, Constants.kElevatorkV, Constants.kElevatorkA); - private final Encoder m_encoder = + private final Encoder encoder = new Encoder(Constants.kEncoderAChannel, Constants.kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(Constants.kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(Constants.kMotorPort); // Simulation classes help us simulate what's going on, including gravity. - private final ElevatorSim m_elevatorSim = + private final ElevatorSim elevatorSim = new ElevatorSim( - m_elevatorGearbox, + elevatorGearbox, Constants.kElevatorGearing, Constants.kCarriageMass, Constants.kElevatorDrumRadius, @@ -56,38 +56,38 @@ public class Elevator implements AutoCloseable { 0, 0.01, 0.0); - private final EncoderSim m_encoderSim = new EncoderSim(m_encoder); - private final PWMMotorControllerSim m_motorSim = new PWMMotorControllerSim(m_motor); + private final EncoderSim encoderSim = new EncoderSim(encoder); + private final PWMMotorControllerSim motorSim = new PWMMotorControllerSim(motor); // Create a Mechanism2d visualization of the elevator - private final Mechanism2d m_mech2d = new Mechanism2d(20, 50); - private final MechanismRoot2d m_mech2dRoot = m_mech2d.getRoot("Elevator Root", 10, 0); - private final MechanismLigament2d m_elevatorMech2d = - m_mech2dRoot.append(new MechanismLigament2d("Elevator", m_elevatorSim.getPosition(), 90)); + private final Mechanism2d mech2d = new Mechanism2d(20, 50); + private final MechanismRoot2d mech2dRoot = mech2d.getRoot("Elevator Root", 10, 0); + private final MechanismLigament2d elevatorMech2d = + mech2dRoot.append(new MechanismLigament2d("Elevator", elevatorSim.getPosition(), 90)); /** Subsystem constructor. */ public Elevator() { - m_encoder.setDistancePerPulse(Constants.kElevatorEncoderDistPerPulse); + encoder.setDistancePerPulse(Constants.kElevatorEncoderDistPerPulse); // Publish Mechanism2d to SmartDashboard // To view the Elevator visualization, select Network Tables -> SmartDashboard -> Elevator Sim - SmartDashboard.putData("Elevator Sim", m_mech2d); + SmartDashboard.putData("Elevator Sim", mech2d); } /** Advance the simulation. */ public void simulationPeriodic() { // In this method, we update our simulation of what our elevator is doing // First, we set our "inputs" (voltages) - m_elevatorSim.setInput(m_motorSim.getThrottle() * RobotController.getBatteryVoltage()); + elevatorSim.setInput(motorSim.getThrottle() * RobotController.getBatteryVoltage()); // Next, we update it. The standard loop time is 20ms. - m_elevatorSim.update(0.020); + elevatorSim.update(0.020); // Finally, we set our simulated encoder's readings and simulated battery voltage - m_encoderSim.setDistance(m_elevatorSim.getPosition()); + encoderSim.setDistance(elevatorSim.getPosition()); // SimBattery estimates loaded battery voltages RoboRioSim.setVInVoltage( - BatterySim.calculateDefaultBatteryLoadedVoltage(m_elevatorSim.getCurrentDraw())); + BatterySim.calculateDefaultBatteryLoadedVoltage(elevatorSim.getCurrentDraw())); } /** @@ -96,30 +96,30 @@ public void simulationPeriodic() { * @param goal the position to maintain */ public void reachGoal(double goal) { - m_controller.setGoal(goal); + controller.setGoal(goal); // With the setpoint value we run PID control like normal - double pidOutput = m_controller.calculate(m_encoder.getDistance()); - double feedforwardOutput = m_feedforward.calculate(m_controller.getSetpoint().velocity); - m_motor.setVoltage(pidOutput + feedforwardOutput); + double pidOutput = controller.calculate(encoder.getDistance()); + double feedforwardOutput = feedforward.calculate(controller.getSetpoint().velocity); + motor.setVoltage(pidOutput + feedforwardOutput); } /** Stop the control loop and motor output. */ public void stop() { - m_controller.setGoal(0.0); - m_motor.setThrottle(0.0); + controller.setGoal(0.0); + motor.setThrottle(0.0); } /** Update telemetry, including the mechanism visualization. */ public void updateTelemetry() { // Update elevator visualization with position - m_elevatorMech2d.setLength(m_encoder.getDistance()); + elevatorMech2d.setLength(encoder.getDistance()); } @Override public void close() { - m_encoder.close(); - m_motor.close(); - m_mech2d.close(); + encoder.close(); + motor.close(); + mech2d.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatortrapezoidprofile/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatortrapezoidprofile/Robot.java index e13a74f30f0..da705627127 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/elevatortrapezoidprofile/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/elevatortrapezoidprofile/Robot.java @@ -12,39 +12,39 @@ public class Robot extends TimedRobot { private static double kDt = 0.02; - private final Joystick m_joystick = new Joystick(1); - private final ExampleSmartMotorController m_motor = new ExampleSmartMotorController(1); + private final Joystick joystick = new Joystick(1); + private final ExampleSmartMotorController motor = new ExampleSmartMotorController(1); // Note: These gains are fake, and will have to be tuned for your robot. - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 1.5); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 1.5); // Create a motion profile with the given maximum velocity and maximum // acceleration constraints for the next setpoint. - private final TrapezoidProfile m_profile = + private final TrapezoidProfile profile = new TrapezoidProfile(new TrapezoidProfile.Constraints(1.75, 0.75)); - private TrapezoidProfile.State m_goal = new TrapezoidProfile.State(); - private TrapezoidProfile.State m_setpoint = new TrapezoidProfile.State(); + private TrapezoidProfile.State goal = new TrapezoidProfile.State(); + private TrapezoidProfile.State setpoint = new TrapezoidProfile.State(); public Robot() { // Note: These gains are fake, and will have to be tuned for your robot. - m_motor.setPID(1.3, 0.0, 0.7); + motor.setPID(1.3, 0.0, 0.7); } @Override public void teleopPeriodic() { - if (m_joystick.getRawButtonPressed(2)) { - m_goal = new TrapezoidProfile.State(5, 0); - } else if (m_joystick.getRawButtonPressed(3)) { - m_goal = new TrapezoidProfile.State(); + if (joystick.getRawButtonPressed(2)) { + goal = new TrapezoidProfile.State(5, 0); + } else if (joystick.getRawButtonPressed(3)) { + goal = new TrapezoidProfile.State(); } // Retrieve the profiled setpoint for the next timestep. This setpoint moves // toward the goal while obeying the constraints. - m_setpoint = m_profile.calculate(kDt, m_setpoint, m_goal); + setpoint = profile.calculate(kDt, setpoint, goal); // Send setpoint to offboard controller PID - m_motor.setSetpoint( + motor.setSetpoint( ExampleSmartMotorController.PIDMode.kPosition, - m_setpoint.position, - m_feedforward.calculate(m_setpoint.velocity) / 12.0); + setpoint.position, + feedforward.calculate(setpoint.velocity) / 12.0); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/encoder/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/encoder/Robot.java index 4085536c874..810433493cd 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/encoder/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/encoder/Robot.java @@ -32,7 +32,7 @@ public class Robot extends TimedRobot { * defaults to k4X. Faster (k4X) encoding gives greater positional precision but more noise in the * rate. */ - private final Encoder m_encoder = new Encoder(1, 2, false, CounterBase.EncodingType.X4); + private final Encoder encoder = new Encoder(1, 2, false, CounterBase.EncodingType.X4); /** Called once at the beginning of the robot program. */ public Robot() { @@ -42,7 +42,7 @@ public Robot() { * larger values result in smoother but potentially * less accurate rates than lower values. */ - m_encoder.setSamplesToAverage(5); + encoder.setSamplesToAverage(5); /* * Defines how far the mechanism attached to the encoder moves per pulse. In @@ -50,7 +50,7 @@ public Robot() { * attached to a 3 inch diameter (1.5inch radius) wheel, * and that we want to measure distance in inches. */ - m_encoder.setDistancePerPulse(1.0 / 360.0 * 2.0 * Math.PI * 1.5); + encoder.setDistancePerPulse(1.0 / 360.0 * 2.0 * Math.PI * 1.5); /* * Defines the lowest rate at which the encoder will @@ -59,12 +59,12 @@ public Robot() { * where distance refers to the units of distance * that you are using, in this case inches. */ - m_encoder.setMinRate(1.0); + encoder.setMinRate(1.0); } @Override public void teleopPeriodic() { - SmartDashboard.putNumber("Encoder Distance", m_encoder.getDistance()); - SmartDashboard.putNumber("Encoder Rate", m_encoder.getRate()); + SmartDashboard.putNumber("Encoder Distance", encoder.getDistance()); + SmartDashboard.putNumber("Encoder Rate", encoder.getRate()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/gettingstarted/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/gettingstarted/Robot.java index cc682b641f0..d62d334a0c9 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/gettingstarted/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/gettingstarted/Robot.java @@ -17,39 +17,39 @@ * this project, you must also update the manifest file in the resource directory. */ public class Robot extends TimedRobot { - private final PWMSparkMax m_leftDrive = new PWMSparkMax(0); - private final PWMSparkMax m_rightDrive = new PWMSparkMax(1); - private final DifferentialDrive m_robotDrive = - new DifferentialDrive(m_leftDrive::setThrottle, m_rightDrive::setThrottle); - private final Gamepad m_controller = new Gamepad(0); - private final Timer m_timer = new Timer(); + private final PWMSparkMax leftDrive = new PWMSparkMax(0); + private final PWMSparkMax rightDrive = new PWMSparkMax(1); + private final DifferentialDrive robotDrive = + new DifferentialDrive(leftDrive::setThrottle, rightDrive::setThrottle); + private final Gamepad controller = new Gamepad(0); + private final Timer timer = new Timer(); /** Called once at the beginning of the robot program. */ public Robot() { - SendableRegistry.addChild(m_robotDrive, m_leftDrive); - SendableRegistry.addChild(m_robotDrive, m_rightDrive); + SendableRegistry.addChild(robotDrive, leftDrive); + SendableRegistry.addChild(robotDrive, rightDrive); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightDrive.setInverted(true); + rightDrive.setInverted(true); } /** This function is run once each time the robot enters autonomous mode. */ @Override public void autonomousInit() { - m_timer.restart(); + timer.restart(); } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { // Drive for 2 seconds - if (m_timer.get() < 2.0) { + if (timer.get() < 2.0) { // Drive forwards half velocity, make sure to turn input squaring off - m_robotDrive.arcadeDrive(0.5, 0.0, false); + robotDrive.arcadeDrive(0.5, 0.0, false); } else { - m_robotDrive.stopMotor(); // stop robot + robotDrive.stopMotor(); // stop robot } } @@ -60,7 +60,7 @@ public void teleopInit() {} /** This function is called periodically during teleoperated mode. */ @Override public void teleopPeriodic() { - m_robotDrive.arcadeDrive(-m_controller.getLeftY(), -m_controller.getRightX()); + robotDrive.arcadeDrive(-controller.getLeftY(), -controller.getRightX()); } /** This function is called once each time the robot enters utility mode. */ diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/gyro/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/gyro/Robot.java index 5dffe8d44de..2173aa900c4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/gyro/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/gyro/Robot.java @@ -26,22 +26,22 @@ public class Robot extends TimedRobot { OnboardIMU.MountOrientation.FLAT; private static final int kJoystickPort = 0; - private final PWMSparkMax m_leftDrive = new PWMSparkMax(kLeftMotorPort); - private final PWMSparkMax m_rightDrive = new PWMSparkMax(kRightMotorPort); - private final DifferentialDrive m_robotDrive = - new DifferentialDrive(m_leftDrive::setThrottle, m_rightDrive::setThrottle); - private final OnboardIMU m_imu = new OnboardIMU(kIMUMountOrientation); - private final Joystick m_joystick = new Joystick(kJoystickPort); + private final PWMSparkMax leftDrive = new PWMSparkMax(kLeftMotorPort); + private final PWMSparkMax rightDrive = new PWMSparkMax(kRightMotorPort); + private final DifferentialDrive robotDrive = + new DifferentialDrive(leftDrive::setThrottle, rightDrive::setThrottle); + private final OnboardIMU imu = new OnboardIMU(kIMUMountOrientation); + private final Joystick joystick = new Joystick(kJoystickPort); /** Called once at the beginning of the robot program. */ public Robot() { - SendableRegistry.addChild(m_robotDrive, m_leftDrive); - SendableRegistry.addChild(m_robotDrive, m_rightDrive); + SendableRegistry.addChild(robotDrive, leftDrive); + SendableRegistry.addChild(robotDrive, rightDrive); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightDrive.setInverted(true); + rightDrive.setInverted(true); } /** @@ -50,7 +50,7 @@ public Robot() { */ @Override public void teleopPeriodic() { - double turningValue = (kAngleSetpoint - m_imu.getRotation2d().getDegrees()) * kP; - m_robotDrive.arcadeDrive(-m_joystick.getY(), -turningValue); + double turningValue = (kAngleSetpoint - imu.getRotation2d().getDegrees()) * kP; + robotDrive.arcadeDrive(-joystick.getY(), -turningValue); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/Robot.java index 634bf9d8d06..3ab91d2deed 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/Robot.java @@ -16,9 +16,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -27,7 +27,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); // Start recording to data log DataLogManager.start(); @@ -63,11 +63,11 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -81,8 +81,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/RobotContainer.java index 0969e19befb..27feae7617f 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/RobotContainer.java @@ -23,22 +23,22 @@ */ public class RobotContainer { // The robot's subsystems - private final DriveSubsystem m_robotDrive = new DriveSubsystem(); - private final HatchSubsystem m_hatchSubsystem = new HatchSubsystem(); + private final DriveSubsystem robotDrive = new DriveSubsystem(); + private final HatchSubsystem hatchSubsystem = new HatchSubsystem(); // Retained command handles // The autonomous routines // A simple auto routine that drives forward a specified distance, and then stops. - private final Command m_simpleAuto = Autos.simpleAuto(m_robotDrive); + private final Command simpleAuto = Autos.simpleAuto(robotDrive); // A complex auto routine that drives forward, drops a hatch, and then drives backward. - private final Command m_complexAuto = Autos.complexAuto(m_robotDrive, m_hatchSubsystem); + private final Command complexAuto = Autos.complexAuto(robotDrive, hatchSubsystem); // A chooser for autonomous commands - SendableChooser m_chooser = new SendableChooser<>(); + SendableChooser chooser = new SendableChooser<>(); // The driver's controller - CommandGamepad m_driverController = new CommandGamepad(OIConstants.kDriverControllerPort); + CommandGamepad driverController = new CommandGamepad(OIConstants.kDriverControllerPort); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { @@ -47,25 +47,24 @@ public RobotContainer() { // Configure default commands // Set the default drive command to split-stick arcade drive - m_robotDrive.setDefaultCommand( + robotDrive.setDefaultCommand( // A split-stick arcade command, with forward/backward controlled by the left // hand, and turning controlled by the right. Commands.run( () -> - m_robotDrive.arcadeDrive( - -m_driverController.getLeftY(), -m_driverController.getRightX()), - m_robotDrive)); + robotDrive.arcadeDrive(-driverController.getLeftY(), -driverController.getRightX()), + robotDrive)); // Add commands to the autonomous command chooser - m_chooser.setDefaultOption("Simple Auto", m_simpleAuto); - m_chooser.addOption("Complex Auto", m_complexAuto); + chooser.setDefaultOption("Simple Auto", simpleAuto); + chooser.addOption("Complex Auto", complexAuto); // Put the chooser on the dashboard - SmartDashboard.putData("Autonomous", m_chooser); + SmartDashboard.putData("Autonomous", chooser); // Put subsystems to dashboard. - SmartDashboard.putData("Drivetrain", m_robotDrive); - SmartDashboard.putData("HatchSubsystem", m_hatchSubsystem); + SmartDashboard.putData("Drivetrain", robotDrive); + SmartDashboard.putData("HatchSubsystem", hatchSubsystem); } /** @@ -76,14 +75,14 @@ public RobotContainer() { */ private void configureButtonBindings() { // Grab the hatch when the east face button is pressed. - m_driverController.eastFace().onTrue(m_hatchSubsystem.grabHatchCommand()); + driverController.eastFace().onTrue(hatchSubsystem.grabHatchCommand()); // Release the hatch when the west face button is pressed. - m_driverController.westFace().onTrue(m_hatchSubsystem.releaseHatchCommand()); + driverController.westFace().onTrue(hatchSubsystem.releaseHatchCommand()); // While holding right bumper, drive at half velocity - m_driverController + driverController .rightBumper() - .onTrue(Commands.runOnce(() -> m_robotDrive.setMaxOutput(0.5))) - .onFalse(Commands.runOnce(() -> m_robotDrive.setMaxOutput(1))); + .onTrue(Commands.runOnce(() -> robotDrive.setMaxOutput(0.5))) + .onFalse(Commands.runOnce(() -> robotDrive.setMaxOutput(1))); } /** @@ -92,6 +91,6 @@ private void configureButtonBindings() { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_chooser.getSelected(); + return chooser.getSelected(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/DriveSubsystem.java index e59465c92fc..98f7ae17b27 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/DriveSubsystem.java @@ -14,26 +14,26 @@ public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final PWMSparkMax m_leftLeader = new PWMSparkMax(DriveConstants.kLeftMotor1Port); - private final PWMSparkMax m_leftFollower = new PWMSparkMax(DriveConstants.kLeftMotor2Port); + private final PWMSparkMax leftLeader = new PWMSparkMax(DriveConstants.kLeftMotor1Port); + private final PWMSparkMax leftFollower = new PWMSparkMax(DriveConstants.kLeftMotor2Port); // The motors on the right side of the drive. - private final PWMSparkMax m_rightLeader = new PWMSparkMax(DriveConstants.kRightMotor1Port); - private final PWMSparkMax m_rightFollower = new PWMSparkMax(DriveConstants.kRightMotor2Port); + private final PWMSparkMax rightLeader = new PWMSparkMax(DriveConstants.kRightMotor1Port); + private final PWMSparkMax rightFollower = new PWMSparkMax(DriveConstants.kRightMotor2Port); // The robot's drive - private final DifferentialDrive m_drive = - new DifferentialDrive(m_leftLeader::setThrottle, m_rightLeader::setThrottle); + private final DifferentialDrive drive = + new DifferentialDrive(leftLeader::setThrottle, rightLeader::setThrottle); // The left-side drive encoder - private final Encoder m_leftEncoder = + private final Encoder leftEncoder = new Encoder( DriveConstants.kLeftEncoderPorts[0], DriveConstants.kLeftEncoderPorts[1], DriveConstants.kLeftEncoderReversed); // The right-side drive encoder - private final Encoder m_rightEncoder = + private final Encoder rightEncoder = new Encoder( DriveConstants.kRightEncoderPorts[0], DriveConstants.kRightEncoderPorts[1], @@ -41,20 +41,20 @@ public class DriveSubsystem extends SubsystemBase { /** Creates a new DriveSubsystem. */ public DriveSubsystem() { - SendableRegistry.addChild(m_drive, m_leftLeader); - SendableRegistry.addChild(m_drive, m_rightLeader); + SendableRegistry.addChild(drive, leftLeader); + SendableRegistry.addChild(drive, rightLeader); - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Sets the distance per pulse for the encoders - m_leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); - m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); } /** @@ -64,13 +64,13 @@ public DriveSubsystem() { * @param rot the commanded rotation */ public void arcadeDrive(double fwd, double rot) { - m_drive.arcadeDrive(fwd, rot); + drive.arcadeDrive(fwd, rot); } /** Resets the drive encoders to currently read a position of 0. */ public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } /** @@ -79,7 +79,7 @@ public void resetEncoders() { * @return the average of the TWO encoder readings */ public double getAverageEncoderDistance() { - return (m_leftEncoder.getDistance() + m_rightEncoder.getDistance()) / 2.0; + return (leftEncoder.getDistance() + rightEncoder.getDistance()) / 2.0; } /** @@ -88,14 +88,14 @@ public double getAverageEncoderDistance() { * @param maxOutput the maximum output to which the drive will be constrained */ public void setMaxOutput(double maxOutput) { - m_drive.setMaxOutput(maxOutput); + drive.setMaxOutput(maxOutput); } @Override public void initSendable(SendableBuilder builder) { super.initSendable(builder); // Publish encoder distances to telemetry. - builder.addDoubleProperty("leftDistance", m_leftEncoder::getDistance, null); - builder.addDoubleProperty("rightDistance", m_rightEncoder::getDistance, null); + builder.addDoubleProperty("leftDistance", leftEncoder::getDistance, null); + builder.addDoubleProperty("rightDistance", rightEncoder::getDistance, null); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/HatchSubsystem.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/HatchSubsystem.java index efecfd3f546..53a8e855fdc 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/HatchSubsystem.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbotinlined/subsystems/HatchSubsystem.java @@ -16,7 +16,7 @@ /** A hatch mechanism actuated by a single {@link org.wpilib.hardware.pneumatic.DoubleSolenoid}. */ public class HatchSubsystem extends SubsystemBase { - private final DoubleSolenoid m_hatchSolenoid = + private final DoubleSolenoid hatchSolenoid = new DoubleSolenoid( 0, PneumaticsModuleType.CTRE_PCM, @@ -26,19 +26,19 @@ public class HatchSubsystem extends SubsystemBase { /** Grabs the hatch. */ public Command grabHatchCommand() { // implicitly require `this` - return this.runOnce(() -> m_hatchSolenoid.set(FORWARD)); + return this.runOnce(() -> hatchSolenoid.set(FORWARD)); } /** Releases the hatch. */ public Command releaseHatchCommand() { // implicitly require `this` - return this.runOnce(() -> m_hatchSolenoid.set(REVERSE)); + return this.runOnce(() -> hatchSolenoid.set(REVERSE)); } @Override public void initSendable(SendableBuilder builder) { super.initSendable(builder); // Publish the solenoid state to telemetry. - builder.addBooleanProperty("extended", () -> m_hatchSolenoid.get() == FORWARD, null); + builder.addBooleanProperty("extended", () -> hatchSolenoid.get() == FORWARD, null); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/Robot.java index ccab66ed8bd..70b90d4ad7e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/Robot.java @@ -16,9 +16,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -27,7 +27,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); // Start recording to data log DataLogManager.start(); @@ -63,7 +63,7 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); /* * String autoSelected = SmartDashboard.getString("Auto Selector", @@ -73,8 +73,8 @@ public void autonomousInit() { */ // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -88,8 +88,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/RobotContainer.java index 395669067e3..745ce1cd3a0 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/RobotContainer.java @@ -30,24 +30,24 @@ */ public class RobotContainer { // The robot's subsystems - private final DriveSubsystem m_robotDrive = new DriveSubsystem(); - private final HatchSubsystem m_hatchSubsystem = new HatchSubsystem(); + private final DriveSubsystem robotDrive = new DriveSubsystem(); + private final HatchSubsystem hatchSubsystem = new HatchSubsystem(); // The autonomous routines // A simple auto routine that drives forward a specified distance, and then stops. - private final Command m_simpleAuto = + private final Command simpleAuto = new DriveDistance( - AutoConstants.kAutoDriveDistanceInches, AutoConstants.kAutoDriveVelocity, m_robotDrive); + AutoConstants.kAutoDriveDistanceInches, AutoConstants.kAutoDriveVelocity, robotDrive); // A complex auto routine that drives forward, drops a hatch, and then drives backward. - private final Command m_complexAuto = new ComplexAuto(m_robotDrive, m_hatchSubsystem); + private final Command complexAuto = new ComplexAuto(robotDrive, hatchSubsystem); // A chooser for autonomous commands - SendableChooser m_chooser = new SendableChooser<>(); + SendableChooser chooser = new SendableChooser<>(); // The driver's controller - Gamepad m_driverController = new Gamepad(OIConstants.kDriverControllerPort); + Gamepad driverController = new Gamepad(OIConstants.kDriverControllerPort); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { @@ -56,23 +56,21 @@ public RobotContainer() { // Configure default commands // Set the default drive command to split-stick arcade drive - m_robotDrive.setDefaultCommand( + robotDrive.setDefaultCommand( // A split-stick arcade command, with forward/backward controlled by the left // hand, and turning controlled by the right. new DefaultDrive( - m_robotDrive, - () -> -m_driverController.getLeftY(), - () -> -m_driverController.getRightX())); + robotDrive, () -> -driverController.getLeftY(), () -> -driverController.getRightX())); // Add commands to the autonomous command chooser - m_chooser.setDefaultOption("Simple Auto", m_simpleAuto); - m_chooser.addOption("Complex Auto", m_complexAuto); + chooser.setDefaultOption("Simple Auto", simpleAuto); + chooser.addOption("Complex Auto", complexAuto); // Put the chooser on the dashboard - SmartDashboard.putData("Autonomous", m_chooser); + SmartDashboard.putData("Autonomous", chooser); // Put subsystems to dashboard. - SmartDashboard.putData("Drivetrain", m_robotDrive); - SmartDashboard.putData("HatchSubsystem", m_hatchSubsystem); + SmartDashboard.putData("Drivetrain", robotDrive); + SmartDashboard.putData("HatchSubsystem", hatchSubsystem); } /** @@ -83,14 +81,12 @@ public RobotContainer() { */ private void configureButtonBindings() { // Grab the hatch when the 'South Face' button is pressed. - new GamepadButton(m_driverController, Button.SOUTH_FACE) - .onTrue(new GrabHatch(m_hatchSubsystem)); + new GamepadButton(driverController, Button.SOUTH_FACE).onTrue(new GrabHatch(hatchSubsystem)); // Release the hatch when the 'East Face' button is pressed. - new GamepadButton(m_driverController, Button.EAST_FACE) - .onTrue(new ReleaseHatch(m_hatchSubsystem)); + new GamepadButton(driverController, Button.EAST_FACE).onTrue(new ReleaseHatch(hatchSubsystem)); // While holding the bumper button, drive at half velocity - new GamepadButton(m_driverController, Button.RIGHT_BUMPER) - .whileTrue(new HalveDriveVelocity(m_robotDrive)); + new GamepadButton(driverController, Button.RIGHT_BUMPER) + .whileTrue(new HalveDriveVelocity(robotDrive)); } /** @@ -99,6 +95,6 @@ private void configureButtonBindings() { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_chooser.getSelected(); + return chooser.getSelected(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DefaultDrive.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DefaultDrive.java index ed7ac70eeb0..2ba85b95696 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DefaultDrive.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DefaultDrive.java @@ -14,9 +14,9 @@ * org.wpilib.command2.RunCommand}. */ public class DefaultDrive extends Command { - private final DriveSubsystem m_drive; - private final DoubleSupplier m_forward; - private final DoubleSupplier m_rotation; + private final DriveSubsystem drive; + private final DoubleSupplier forward; + private final DoubleSupplier rotation; /** * Creates a new DefaultDrive. @@ -26,14 +26,14 @@ public class DefaultDrive extends Command { * @param rotation The control input for turning */ public DefaultDrive(DriveSubsystem subsystem, DoubleSupplier forward, DoubleSupplier rotation) { - m_drive = subsystem; - m_forward = forward; - m_rotation = rotation; - addRequirements(m_drive); + drive = subsystem; + this.forward = forward; + this.rotation = rotation; + addRequirements(drive); } @Override public void execute() { - m_drive.arcadeDrive(m_forward.getAsDouble(), m_rotation.getAsDouble()); + drive.arcadeDrive(forward.getAsDouble(), rotation.getAsDouble()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DriveDistance.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DriveDistance.java index 7575a6534a9..b9683c2667e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DriveDistance.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/DriveDistance.java @@ -8,9 +8,9 @@ import org.wpilib.examples.hatchbottraditional.subsystems.DriveSubsystem; public class DriveDistance extends Command { - private final DriveSubsystem m_drive; - private final double m_distance; - private final double m_velocity; + private final DriveSubsystem drive; + private final double distance; + private final double velocity; /** * Creates a new DriveDistance. @@ -20,30 +20,30 @@ public class DriveDistance extends Command { * @param drive The drive subsystem on which this command will run */ public DriveDistance(double inches, double velocity, DriveSubsystem drive) { - m_distance = inches; - m_velocity = velocity; - m_drive = drive; - addRequirements(m_drive); + distance = inches; + this.velocity = velocity; + this.drive = drive; + addRequirements(drive); } @Override public void initialize() { - m_drive.resetEncoders(); - m_drive.arcadeDrive(m_velocity, 0); + drive.resetEncoders(); + drive.arcadeDrive(velocity, 0); } @Override public void execute() { - m_drive.arcadeDrive(m_velocity, 0); + drive.arcadeDrive(velocity, 0); } @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } @Override public boolean isFinished() { - return Math.abs(m_drive.getAverageEncoderDistance()) >= m_distance; + return Math.abs(drive.getAverageEncoderDistance()) >= distance; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/GrabHatch.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/GrabHatch.java index a2b5802bc00..804537876d3 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/GrabHatch.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/GrabHatch.java @@ -14,16 +14,16 @@ */ public class GrabHatch extends Command { // The subsystem the command runs on - private final HatchSubsystem m_hatchSubsystem; + private final HatchSubsystem hatchSubsystem; public GrabHatch(HatchSubsystem subsystem) { - m_hatchSubsystem = subsystem; - addRequirements(m_hatchSubsystem); + hatchSubsystem = subsystem; + addRequirements(hatchSubsystem); } @Override public void initialize() { - m_hatchSubsystem.grabHatch(); + hatchSubsystem.grabHatch(); } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/HalveDriveVelocity.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/HalveDriveVelocity.java index d700109c756..d4dfe9c6621 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/HalveDriveVelocity.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/commands/HalveDriveVelocity.java @@ -8,19 +8,19 @@ import org.wpilib.examples.hatchbottraditional.subsystems.DriveSubsystem; public class HalveDriveVelocity extends Command { - private final DriveSubsystem m_drive; + private final DriveSubsystem drive; public HalveDriveVelocity(DriveSubsystem drive) { - m_drive = drive; + this.drive = drive; } @Override public void initialize() { - m_drive.setMaxOutput(0.5); + drive.setMaxOutput(0.5); } @Override public void end(boolean interrupted) { - m_drive.setMaxOutput(1); + drive.setMaxOutput(1); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/DriveSubsystem.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/DriveSubsystem.java index d7f7795ded8..e355fc47965 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/DriveSubsystem.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/DriveSubsystem.java @@ -14,26 +14,26 @@ public class DriveSubsystem extends SubsystemBase { // The motors on the left side of the drive. - private final PWMSparkMax m_leftLeader = new PWMSparkMax(DriveConstants.kLeftMotor1Port); - private final PWMSparkMax m_leftFollower = new PWMSparkMax(DriveConstants.kLeftMotor2Port); + private final PWMSparkMax leftLeader = new PWMSparkMax(DriveConstants.kLeftMotor1Port); + private final PWMSparkMax leftFollower = new PWMSparkMax(DriveConstants.kLeftMotor2Port); // The motors on the right side of the drive. - private final PWMSparkMax m_rightLeader = new PWMSparkMax(DriveConstants.kRightMotor1Port); - private final PWMSparkMax m_rightFollower = new PWMSparkMax(DriveConstants.kRightMotor2Port); + private final PWMSparkMax rightLeader = new PWMSparkMax(DriveConstants.kRightMotor1Port); + private final PWMSparkMax rightFollower = new PWMSparkMax(DriveConstants.kRightMotor2Port); // The robot's drive - private final DifferentialDrive m_drive = - new DifferentialDrive(m_leftLeader::setThrottle, m_rightLeader::setThrottle); + private final DifferentialDrive drive = + new DifferentialDrive(leftLeader::setThrottle, rightLeader::setThrottle); // The left-side drive encoder - private final Encoder m_leftEncoder = + private final Encoder leftEncoder = new Encoder( DriveConstants.kLeftEncoderPorts[0], DriveConstants.kLeftEncoderPorts[1], DriveConstants.kLeftEncoderReversed); // The right-side drive encoder - private final Encoder m_rightEncoder = + private final Encoder rightEncoder = new Encoder( DriveConstants.kRightEncoderPorts[0], DriveConstants.kRightEncoderPorts[1], @@ -41,20 +41,20 @@ public class DriveSubsystem extends SubsystemBase { /** Creates a new DriveSubsystem. */ public DriveSubsystem() { - SendableRegistry.addChild(m_drive, m_leftLeader); - SendableRegistry.addChild(m_drive, m_rightLeader); + SendableRegistry.addChild(drive, leftLeader); + SendableRegistry.addChild(drive, rightLeader); - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Sets the distance per pulse for the encoders - m_leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); - m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); } /** @@ -64,13 +64,13 @@ public DriveSubsystem() { * @param rot the commanded rotation */ public void arcadeDrive(double fwd, double rot) { - m_drive.arcadeDrive(fwd, rot); + drive.arcadeDrive(fwd, rot); } /** Resets the drive encoders to currently read a position of 0. */ public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } /** @@ -79,7 +79,7 @@ public void resetEncoders() { * @return the average of the TWO encoder readings */ public double getAverageEncoderDistance() { - return (m_leftEncoder.getDistance() + m_rightEncoder.getDistance()) / 2.0; + return (leftEncoder.getDistance() + rightEncoder.getDistance()) / 2.0; } /** @@ -88,14 +88,14 @@ public double getAverageEncoderDistance() { * @param maxOutput the maximum output to which the drive will be constrained */ public void setMaxOutput(double maxOutput) { - m_drive.setMaxOutput(maxOutput); + drive.setMaxOutput(maxOutput); } @Override public void initSendable(SendableBuilder builder) { super.initSendable(builder); // Publish encoder distances to telemetry. - builder.addDoubleProperty("leftDistance", m_leftEncoder::getDistance, null); - builder.addDoubleProperty("rightDistance", m_rightEncoder::getDistance, null); + builder.addDoubleProperty("leftDistance", leftEncoder::getDistance, null); + builder.addDoubleProperty("rightDistance", rightEncoder::getDistance, null); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/HatchSubsystem.java b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/HatchSubsystem.java index ce0f0e217dc..8d33de0cfe5 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/HatchSubsystem.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/hatchbottraditional/subsystems/HatchSubsystem.java @@ -15,7 +15,7 @@ /** A hatch mechanism actuated by a single {@link DoubleSolenoid}. */ public class HatchSubsystem extends SubsystemBase { - private final DoubleSolenoid m_hatchSolenoid = + private final DoubleSolenoid hatchSolenoid = new DoubleSolenoid( 0, PneumaticsModuleType.CTRE_PCM, @@ -24,18 +24,18 @@ public class HatchSubsystem extends SubsystemBase { /** Grabs the hatch. */ public void grabHatch() { - m_hatchSolenoid.set(FORWARD); + hatchSolenoid.set(FORWARD); } /** Releases the hatch. */ public void releaseHatch() { - m_hatchSolenoid.set(REVERSE); + hatchSolenoid.set(REVERSE); } @Override public void initSendable(SendableBuilder builder) { super.initSendable(builder); // Publish the solenoid state to telemetry. - builder.addBooleanProperty("extended", () -> m_hatchSolenoid.get() == FORWARD, null); + builder.addBooleanProperty("extended", () -> hatchSolenoid.get() == FORWARD, null); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Drivetrain.java index f6648d111d0..084057d8153 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Drivetrain.java @@ -21,46 +21,46 @@ public class Drivetrain { public static final double kMaxVelocity = 3.0; // 3 meters per second public static final double kMaxAngularVelocity = Math.PI; // 1/2 rotation per second - private final PWMSparkMax m_frontLeftMotor = new PWMSparkMax(1); - private final PWMSparkMax m_frontRightMotor = new PWMSparkMax(2); - private final PWMSparkMax m_backLeftMotor = new PWMSparkMax(3); - private final PWMSparkMax m_backRightMotor = new PWMSparkMax(4); + private final PWMSparkMax frontLeftMotor = new PWMSparkMax(1); + private final PWMSparkMax frontRightMotor = new PWMSparkMax(2); + private final PWMSparkMax backLeftMotor = new PWMSparkMax(3); + private final PWMSparkMax backRightMotor = new PWMSparkMax(4); - private final Encoder m_frontLeftEncoder = new Encoder(0, 1); - private final Encoder m_frontRightEncoder = new Encoder(2, 3); - private final Encoder m_backLeftEncoder = new Encoder(4, 5); - private final Encoder m_backRightEncoder = new Encoder(6, 7); + private final Encoder frontLeftEncoder = new Encoder(0, 1); + private final Encoder frontRightEncoder = new Encoder(2, 3); + private final Encoder backLeftEncoder = new Encoder(4, 5); + private final Encoder backRightEncoder = new Encoder(6, 7); - private final Translation2d m_frontLeftLocation = new Translation2d(0.381, 0.381); - private final Translation2d m_frontRightLocation = new Translation2d(0.381, -0.381); - private final Translation2d m_backLeftLocation = new Translation2d(-0.381, 0.381); - private final Translation2d m_backRightLocation = new Translation2d(-0.381, -0.381); + private final Translation2d frontLeftLocation = new Translation2d(0.381, 0.381); + private final Translation2d frontRightLocation = new Translation2d(0.381, -0.381); + private final Translation2d backLeftLocation = new Translation2d(-0.381, 0.381); + private final Translation2d backRightLocation = new Translation2d(-0.381, -0.381); - private final PIDController m_frontLeftPIDController = new PIDController(1, 0, 0); - private final PIDController m_frontRightPIDController = new PIDController(1, 0, 0); - private final PIDController m_backLeftPIDController = new PIDController(1, 0, 0); - private final PIDController m_backRightPIDController = new PIDController(1, 0, 0); + private final PIDController frontLeftPIDController = new PIDController(1, 0, 0); + private final PIDController frontRightPIDController = new PIDController(1, 0, 0); + private final PIDController backLeftPIDController = new PIDController(1, 0, 0); + private final PIDController backRightPIDController = new PIDController(1, 0, 0); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final MecanumDriveKinematics m_kinematics = + private final MecanumDriveKinematics kinematics = new MecanumDriveKinematics( - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation); + frontLeftLocation, frontRightLocation, backLeftLocation, backRightLocation); - private final MecanumDriveOdometry m_odometry = - new MecanumDriveOdometry(m_kinematics, m_imu.getRotation2d(), getCurrentWheelDistances()); + private final MecanumDriveOdometry odometry = + new MecanumDriveOdometry(kinematics, imu.getRotation2d(), getCurrentWheelDistances()); // Gains are for example purposes only - must be determined for your own robot! - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 3); /** Constructs a MecanumDrive and resets the gyro. */ public Drivetrain() { - m_imu.resetYaw(); + imu.resetYaw(); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_frontRightMotor.setInverted(true); - m_backRightMotor.setInverted(true); + frontRightMotor.setInverted(true); + backRightMotor.setInverted(true); } /** @@ -70,10 +70,10 @@ public Drivetrain() { */ public MecanumDriveWheelPositions getCurrentWheelDistances() { return new MecanumDriveWheelPositions( - m_frontLeftEncoder.getDistance(), - m_frontRightEncoder.getDistance(), - m_backLeftEncoder.getDistance(), - m_backRightEncoder.getDistance()); + frontLeftEncoder.getDistance(), + frontRightEncoder.getDistance(), + backLeftEncoder.getDistance(), + backRightEncoder.getDistance()); } /** @@ -83,10 +83,10 @@ public MecanumDriveWheelPositions getCurrentWheelDistances() { */ public MecanumDriveWheelVelocities getCurrentWheelVelocities() { return new MecanumDriveWheelVelocities( - m_frontLeftEncoder.getRate(), - m_frontRightEncoder.getRate(), - m_backLeftEncoder.getRate(), - m_backRightEncoder.getRate()); + frontLeftEncoder.getRate(), + frontRightEncoder.getRate(), + backLeftEncoder.getRate(), + backRightEncoder.getRate()); } /** @@ -95,24 +95,24 @@ public MecanumDriveWheelVelocities getCurrentWheelVelocities() { * @param velocities The desired wheel velocities. */ public void setVelocities(MecanumDriveWheelVelocities velocities) { - final double frontLeftFeedforward = m_feedforward.calculate(velocities.frontLeft); - final double frontRightFeedforward = m_feedforward.calculate(velocities.frontRight); - final double backLeftFeedforward = m_feedforward.calculate(velocities.rearLeft); - final double backRightFeedforward = m_feedforward.calculate(velocities.rearRight); + final double frontLeftFeedforward = feedforward.calculate(velocities.frontLeft); + final double frontRightFeedforward = feedforward.calculate(velocities.frontRight); + final double backLeftFeedforward = feedforward.calculate(velocities.rearLeft); + final double backRightFeedforward = feedforward.calculate(velocities.rearRight); final double frontLeftOutput = - m_frontLeftPIDController.calculate(m_frontLeftEncoder.getRate(), velocities.frontLeft); + frontLeftPIDController.calculate(frontLeftEncoder.getRate(), velocities.frontLeft); final double frontRightOutput = - m_frontRightPIDController.calculate(m_frontRightEncoder.getRate(), velocities.frontRight); + frontRightPIDController.calculate(frontRightEncoder.getRate(), velocities.frontRight); final double backLeftOutput = - m_backLeftPIDController.calculate(m_backLeftEncoder.getRate(), velocities.rearLeft); + backLeftPIDController.calculate(backLeftEncoder.getRate(), velocities.rearLeft); final double backRightOutput = - m_backRightPIDController.calculate(m_backRightEncoder.getRate(), velocities.rearRight); + backRightPIDController.calculate(backRightEncoder.getRate(), velocities.rearRight); - m_frontLeftMotor.setVoltage(frontLeftOutput + frontLeftFeedforward); - m_frontRightMotor.setVoltage(frontRightOutput + frontRightFeedforward); - m_backLeftMotor.setVoltage(backLeftOutput + backLeftFeedforward); - m_backRightMotor.setVoltage(backRightOutput + backRightFeedforward); + frontLeftMotor.setVoltage(frontLeftOutput + frontLeftFeedforward); + frontRightMotor.setVoltage(frontRightOutput + frontRightFeedforward); + backLeftMotor.setVoltage(backLeftOutput + backLeftFeedforward); + backRightMotor.setVoltage(backRightOutput + backRightFeedforward); } /** @@ -127,16 +127,16 @@ public void drive( double xVelocity, double yVelocity, double rot, boolean fieldRelative, double period) { var chassisVelocities = new ChassisVelocities(xVelocity, yVelocity, rot); if (fieldRelative) { - chassisVelocities = chassisVelocities.toRobotRelative(m_imu.getRotation2d()); + chassisVelocities = chassisVelocities.toRobotRelative(imu.getRotation2d()); } setVelocities( - m_kinematics + kinematics .toWheelVelocities(chassisVelocities.discretize(period)) .desaturate(kMaxVelocity)); } /** Updates the field relative position of the robot. */ public void updateOdometry() { - m_odometry.update(m_imu.getRotation2d(), getCurrentWheelDistances()); + odometry.update(imu.getRotation2d(), getCurrentWheelDistances()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Robot.java index 1645e29e630..62b8f245c53 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumbot/Robot.java @@ -9,18 +9,18 @@ import org.wpilib.math.filter.SlewRateLimiter; public class Robot extends TimedRobot { - private final Gamepad m_controller = new Gamepad(0); - private final Drivetrain m_mecanum = new Drivetrain(); + private final Gamepad controller = new Gamepad(0); + private final Drivetrain mecanum = new Drivetrain(); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 to 1. - private final SlewRateLimiter m_xVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_yVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter xVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter yVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); @Override public void autonomousPeriodic() { driveWithJoystick(false); - m_mecanum.updateOdometry(); + mecanum.updateOdometry(); } @Override @@ -32,21 +32,20 @@ private void driveWithJoystick(boolean fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. final var xVelocity = - -m_xVelocityLimiter.calculate(m_controller.getLeftY()) * Drivetrain.kMaxVelocity; + -xVelocityLimiter.calculate(controller.getLeftY()) * Drivetrain.kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this because // we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. final var yVelocity = - -m_yVelocityLimiter.calculate(m_controller.getLeftX()) * Drivetrain.kMaxVelocity; + -yVelocityLimiter.calculate(controller.getLeftX()) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - final var rot = - -m_rotLimiter.calculate(m_controller.getRightX()) * Drivetrain.kMaxAngularVelocity; + final var rot = -rotLimiter.calculate(controller.getRightX()) * Drivetrain.kMaxAngularVelocity; - m_mecanum.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); + mecanum.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdrive/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdrive/Robot.java index d03d9e421a7..30c2884837e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdrive/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdrive/Robot.java @@ -24,9 +24,9 @@ public class Robot extends TimedRobot { OnboardIMU.MountOrientation.FLAT; private static final int kJoystickPort = 0; - private final MecanumDrive m_robotDrive; - private final OnboardIMU m_imu = new OnboardIMU(kIMUMountOrientation); - private final Joystick m_joystick = new Joystick(kJoystickPort); + private final MecanumDrive robotDrive; + private final OnboardIMU imu = new OnboardIMU(kIMUMountOrientation); + private final Joystick joystick = new Joystick(kJoystickPort); /** Called once at the beginning of the robot program. */ public Robot() { @@ -40,17 +40,17 @@ public Robot() { frontRight.setInverted(true); rearRight.setInverted(true); - m_robotDrive = + robotDrive = new MecanumDrive( frontLeft::setThrottle, rearLeft::setThrottle, frontRight::setThrottle, rearRight::setThrottle); - SendableRegistry.addChild(m_robotDrive, frontLeft); - SendableRegistry.addChild(m_robotDrive, rearLeft); - SendableRegistry.addChild(m_robotDrive, frontRight); - SendableRegistry.addChild(m_robotDrive, rearRight); + SendableRegistry.addChild(robotDrive, frontLeft); + SendableRegistry.addChild(robotDrive, rearLeft); + SendableRegistry.addChild(robotDrive, frontRight); + SendableRegistry.addChild(robotDrive, rearRight); } /** Mecanum drive is used with the gyro angle as an input. */ @@ -58,7 +58,7 @@ public Robot() { public void teleopPeriodic() { // Use the joystick Y axis for forward movement, X axis for lateral // movement, and Z axis for rotation. - m_robotDrive.driveCartesian( - -m_joystick.getY(), -m_joystick.getX(), -m_joystick.getZ(), m_imu.getRotation2d()); + robotDrive.driveCartesian( + -joystick.getY(), -joystick.getX(), -joystick.getZ(), imu.getRotation2d()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Drivetrain.java index 650d0b99ad4..f000d7530c2 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Drivetrain.java @@ -25,54 +25,54 @@ public class Drivetrain { public static final double kMaxVelocity = 3.0; // 3 meters per second public static final double kMaxAngularVelocity = Math.PI; // 1/2 rotation per second - private final PWMSparkMax m_frontLeftMotor = new PWMSparkMax(1); - private final PWMSparkMax m_frontRightMotor = new PWMSparkMax(2); - private final PWMSparkMax m_backLeftMotor = new PWMSparkMax(3); - private final PWMSparkMax m_backRightMotor = new PWMSparkMax(4); + private final PWMSparkMax frontLeftMotor = new PWMSparkMax(1); + private final PWMSparkMax frontRightMotor = new PWMSparkMax(2); + private final PWMSparkMax backLeftMotor = new PWMSparkMax(3); + private final PWMSparkMax backRightMotor = new PWMSparkMax(4); - private final Encoder m_frontLeftEncoder = new Encoder(0, 1); - private final Encoder m_frontRightEncoder = new Encoder(2, 3); - private final Encoder m_backLeftEncoder = new Encoder(4, 5); - private final Encoder m_backRightEncoder = new Encoder(6, 7); + private final Encoder frontLeftEncoder = new Encoder(0, 1); + private final Encoder frontRightEncoder = new Encoder(2, 3); + private final Encoder backLeftEncoder = new Encoder(4, 5); + private final Encoder backRightEncoder = new Encoder(6, 7); - private final Translation2d m_frontLeftLocation = new Translation2d(0.381, 0.381); - private final Translation2d m_frontRightLocation = new Translation2d(0.381, -0.381); - private final Translation2d m_backLeftLocation = new Translation2d(-0.381, 0.381); - private final Translation2d m_backRightLocation = new Translation2d(-0.381, -0.381); + private final Translation2d frontLeftLocation = new Translation2d(0.381, 0.381); + private final Translation2d frontRightLocation = new Translation2d(0.381, -0.381); + private final Translation2d backLeftLocation = new Translation2d(-0.381, 0.381); + private final Translation2d backRightLocation = new Translation2d(-0.381, -0.381); - private final PIDController m_frontLeftPIDController = new PIDController(1, 0, 0); - private final PIDController m_frontRightPIDController = new PIDController(1, 0, 0); - private final PIDController m_backLeftPIDController = new PIDController(1, 0, 0); - private final PIDController m_backRightPIDController = new PIDController(1, 0, 0); + private final PIDController frontLeftPIDController = new PIDController(1, 0, 0); + private final PIDController frontRightPIDController = new PIDController(1, 0, 0); + private final PIDController backLeftPIDController = new PIDController(1, 0, 0); + private final PIDController backRightPIDController = new PIDController(1, 0, 0); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final MecanumDriveKinematics m_kinematics = + private final MecanumDriveKinematics kinematics = new MecanumDriveKinematics( - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation); + frontLeftLocation, frontRightLocation, backLeftLocation, backRightLocation); /* Here we use MecanumDrivePoseEstimator so that we can fuse odometry readings. The numbers used below are robot specific, and should be tuned. */ - private final MecanumDrivePoseEstimator m_poseEstimator = + private final MecanumDrivePoseEstimator poseEstimator = new MecanumDrivePoseEstimator( - m_kinematics, - m_imu.getRotation2d(), + kinematics, + imu.getRotation2d(), getCurrentWheelDistances(), Pose2d.kZero, VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5)), VecBuilder.fill(0.5, 0.5, Units.degreesToRadians(30))); // Gains are for example purposes only - must be determined for your own robot! - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 3); /** Constructs a MecanumDrive and resets the gyro. */ public Drivetrain() { - m_imu.resetYaw(); + imu.resetYaw(); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_frontRightMotor.setInverted(true); - m_backRightMotor.setInverted(true); + frontRightMotor.setInverted(true); + backRightMotor.setInverted(true); } /** @@ -82,10 +82,10 @@ public Drivetrain() { */ public MecanumDriveWheelPositions getCurrentWheelDistances() { return new MecanumDriveWheelPositions( - m_frontLeftEncoder.getDistance(), - m_frontRightEncoder.getDistance(), - m_backLeftEncoder.getDistance(), - m_backRightEncoder.getDistance()); + frontLeftEncoder.getDistance(), + frontRightEncoder.getDistance(), + backLeftEncoder.getDistance(), + backRightEncoder.getDistance()); } /** @@ -95,10 +95,10 @@ public MecanumDriveWheelPositions getCurrentWheelDistances() { */ public MecanumDriveWheelVelocities getCurrentWheelVelocities() { return new MecanumDriveWheelVelocities( - m_frontLeftEncoder.getRate(), - m_frontRightEncoder.getRate(), - m_backLeftEncoder.getRate(), - m_backRightEncoder.getRate()); + frontLeftEncoder.getRate(), + frontRightEncoder.getRate(), + backLeftEncoder.getRate(), + backRightEncoder.getRate()); } /** @@ -107,24 +107,24 @@ public MecanumDriveWheelVelocities getCurrentWheelVelocities() { * @param velocities The desired wheel velocities. */ public void setVelocities(MecanumDriveWheelVelocities velocities) { - final double frontLeftFeedforward = m_feedforward.calculate(velocities.frontLeft); - final double frontRightFeedforward = m_feedforward.calculate(velocities.frontRight); - final double backLeftFeedforward = m_feedforward.calculate(velocities.rearLeft); - final double backRightFeedforward = m_feedforward.calculate(velocities.rearRight); + final double frontLeftFeedforward = feedforward.calculate(velocities.frontLeft); + final double frontRightFeedforward = feedforward.calculate(velocities.frontRight); + final double backLeftFeedforward = feedforward.calculate(velocities.rearLeft); + final double backRightFeedforward = feedforward.calculate(velocities.rearRight); final double frontLeftOutput = - m_frontLeftPIDController.calculate(m_frontLeftEncoder.getRate(), velocities.frontLeft); + frontLeftPIDController.calculate(frontLeftEncoder.getRate(), velocities.frontLeft); final double frontRightOutput = - m_frontRightPIDController.calculate(m_frontRightEncoder.getRate(), velocities.frontRight); + frontRightPIDController.calculate(frontRightEncoder.getRate(), velocities.frontRight); final double backLeftOutput = - m_backLeftPIDController.calculate(m_backLeftEncoder.getRate(), velocities.rearLeft); + backLeftPIDController.calculate(backLeftEncoder.getRate(), velocities.rearLeft); final double backRightOutput = - m_backRightPIDController.calculate(m_backRightEncoder.getRate(), velocities.rearRight); + backRightPIDController.calculate(backRightEncoder.getRate(), velocities.rearRight); - m_frontLeftMotor.setVoltage(frontLeftOutput + frontLeftFeedforward); - m_frontRightMotor.setVoltage(frontRightOutput + frontRightFeedforward); - m_backLeftMotor.setVoltage(backLeftOutput + backLeftFeedforward); - m_backRightMotor.setVoltage(backRightOutput + backRightFeedforward); + frontLeftMotor.setVoltage(frontLeftOutput + frontLeftFeedforward); + frontRightMotor.setVoltage(frontRightOutput + frontRightFeedforward); + backLeftMotor.setVoltage(backLeftOutput + backLeftFeedforward); + backRightMotor.setVoltage(backRightOutput + backRightFeedforward); } /** @@ -140,23 +140,22 @@ public void drive( var chassisVelocities = new ChassisVelocities(xVelocity, yVelocity, rot); if (fieldRelative) { chassisVelocities = - chassisVelocities.toRobotRelative(m_poseEstimator.getEstimatedPosition().getRotation()); + chassisVelocities.toRobotRelative(poseEstimator.getEstimatedPosition().getRotation()); } setVelocities( - m_kinematics + kinematics .toWheelVelocities(chassisVelocities.discretize(period)) .desaturate(kMaxVelocity)); } /** Updates the field relative position of the robot. */ public void updateOdometry() { - m_poseEstimator.update(m_imu.getRotation2d(), getCurrentWheelDistances()); + poseEstimator.update(imu.getRotation2d(), getCurrentWheelDistances()); // Also apply vision measurements. We use 0.3 seconds in the past as an example -- on // a real robot, this must be calculated based either on latency or timestamps. - m_poseEstimator.addVisionMeasurement( - ExampleGlobalMeasurementSensor.getEstimatedGlobalPose( - m_poseEstimator.getEstimatedPosition()), + poseEstimator.addVisionMeasurement( + ExampleGlobalMeasurementSensor.getEstimatedGlobalPose(poseEstimator.getEstimatedPosition()), Timer.getTimestamp() - 0.3); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Robot.java index 32b5ac07665..563eb76fe76 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/mecanumdriveposeestimator/Robot.java @@ -9,18 +9,18 @@ import org.wpilib.math.filter.SlewRateLimiter; public class Robot extends TimedRobot { - private final Gamepad m_controller = new Gamepad(0); - private final Drivetrain m_mecanum = new Drivetrain(); + private final Gamepad controller = new Gamepad(0); + private final Drivetrain mecanum = new Drivetrain(); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 to 1. - private final SlewRateLimiter m_xVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_yVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter xVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter yVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); @Override public void autonomousPeriodic() { driveWithJoystick(false); - m_mecanum.updateOdometry(); + mecanum.updateOdometry(); } @Override @@ -32,21 +32,20 @@ private void driveWithJoystick(boolean fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. final var xVelocity = - -m_xVelocityLimiter.calculate(m_controller.getLeftY()) * Drivetrain.kMaxVelocity; + -xVelocityLimiter.calculate(controller.getLeftY()) * Drivetrain.kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this because // we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. final var yVelocity = - -m_yVelocityLimiter.calculate(m_controller.getLeftX()) * Drivetrain.kMaxVelocity; + -yVelocityLimiter.calculate(controller.getLeftX()) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - final var rot = - -m_rotLimiter.calculate(m_controller.getRightX()) * Drivetrain.kMaxAngularVelocity; + final var rot = -rotLimiter.calculate(controller.getRightX()) * Drivetrain.kMaxAngularVelocity; - m_mecanum.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); + mecanum.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/mechanism2d/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/mechanism2d/Robot.java index ad7197b9076..5a197a2665a 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/mechanism2d/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/mechanism2d/Robot.java @@ -27,18 +27,18 @@ public class Robot extends TimedRobot { private static final double kMetersPerPulse = 0.01; private static final double kElevatorMinimumLength = 0.5; - private final PWMSparkMax m_elevatorMotor = new PWMSparkMax(0); - private final PWMSparkMax m_wristMotor = new PWMSparkMax(1); - private final AnalogPotentiometer m_wristPot = new AnalogPotentiometer(1, 90); - private final Encoder m_elevatorEncoder = new Encoder(0, 1); - private final Joystick m_joystick = new Joystick(0); + private final PWMSparkMax elevatorMotor = new PWMSparkMax(0); + private final PWMSparkMax wristMotor = new PWMSparkMax(1); + private final AnalogPotentiometer wristPot = new AnalogPotentiometer(1, 90); + private final Encoder elevatorEncoder = new Encoder(0, 1); + private final Joystick joystick = new Joystick(0); - private final MechanismLigament2d m_elevator; - private final MechanismLigament2d m_wrist; + private final MechanismLigament2d elevator; + private final MechanismLigament2d wrist; /** Called once at the beginning of the robot program. */ public Robot() { - m_elevatorEncoder.setDistancePerPulse(kMetersPerPulse); + elevatorEncoder.setDistancePerPulse(kMetersPerPulse); // the main mechanism object Mechanism2d mech = new Mechanism2d(3, 3); @@ -47,10 +47,9 @@ public Robot() { // MechanismLigament2d objects represent each "section"/"stage" of the mechanism, and are based // off the root node or another ligament object - m_elevator = root.append(new MechanismLigament2d("elevator", kElevatorMinimumLength, 90)); - m_wrist = - m_elevator.append( - new MechanismLigament2d("wrist", 0.5, 90, 6, new Color8Bit(Color.PURPLE))); + elevator = root.append(new MechanismLigament2d("elevator", kElevatorMinimumLength, 90)); + wrist = + elevator.append(new MechanismLigament2d("wrist", 0.5, 90, 6, new Color8Bit(Color.PURPLE))); // post the mechanism to the dashboard SmartDashboard.putData("Mech2d", mech); @@ -59,13 +58,13 @@ public Robot() { @Override public void robotPeriodic() { // update the dashboard mechanism's state - m_elevator.setLength(kElevatorMinimumLength + m_elevatorEncoder.getDistance()); - m_wrist.setAngle(m_wristPot.get()); + elevator.setLength(kElevatorMinimumLength + elevatorEncoder.getDistance()); + wrist.setAngle(wristPot.get()); } @Override public void teleopPeriodic() { - m_elevatorMotor.setThrottle(m_joystick.getRawAxis(0)); - m_wristMotor.setThrottle(m_joystick.getRawAxis(1)); + elevatorMotor.setThrottle(joystick.getRawAxis(0)); + wristMotor.setThrottle(joystick.getRawAxis(1)); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/RapidReactCommandBot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/RapidReactCommandBot.java index 32a3cb6ce8f..ce28a4f9679 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/RapidReactCommandBot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/RapidReactCommandBot.java @@ -28,14 +28,14 @@ @Logged(name = "Rapid React Command Robot Container") public class RapidReactCommandBot { // The robot's subsystems - private final Drive m_drive = new Drive(); - private final Intake m_intake = new Intake(); - private final Storage m_storage = new Storage(); - private final Shooter m_shooter = new Shooter(); - private final Pneumatics m_pneumatics = new Pneumatics(); + private final Drive drive = new Drive(); + private final Intake intake = new Intake(); + private final Storage storage = new Storage(); + private final Shooter shooter = new Shooter(); + private final Pneumatics pneumatics = new Pneumatics(); // The driver's controller - CommandGamepad m_driverController = new CommandGamepad(OIConstants.kDriverControllerPort); + CommandGamepad driverController = new CommandGamepad(OIConstants.kDriverControllerPort); /** * Use this method to define bindings between conditions and commands. These are useful for @@ -49,33 +49,31 @@ public void configureBindings() { // Automatically run the storage motor whenever the ball storage is not full, // and turn it off whenever it fills. Uses subsystem-hosted trigger to // improve readability and make inter-subsystem communication easier. - m_storage.hasCargo.whileFalse(m_storage.runCommand()); + storage.hasCargo.whileFalse(storage.runCommand()); // Automatically disable and retract the intake whenever the ball storage is full. - m_storage.hasCargo.onTrue(m_intake.retractCommand()); + storage.hasCargo.onTrue(intake.retractCommand()); // Control the drive with split-stick arcade controls - m_drive.setDefaultCommand( - m_drive.arcadeDriveCommand( - () -> -m_driverController.getLeftY(), () -> -m_driverController.getRightX())); + drive.setDefaultCommand( + drive.arcadeDriveCommand( + () -> -driverController.getLeftY(), () -> -driverController.getRightX())); // Deploy the intake with the west face button - m_driverController.westFace().onTrue(m_intake.intakeCommand()); + driverController.westFace().onTrue(intake.intakeCommand()); // Retract the intake with the north face button - m_driverController.northFace().onTrue(m_intake.retractCommand()); + driverController.northFace().onTrue(intake.retractCommand()); // Fire the shooter with the south face button - m_driverController + driverController .southFace() .onTrue( - parallel( - m_shooter.shootCommand(ShooterConstants.kShooterTargetRPS), - m_storage.runCommand()) + parallel(shooter.shootCommand(ShooterConstants.kShooterTargetRPS), storage.runCommand()) // Since we composed this inline we should give it a name .withName("Shoot")); // Toggle compressor with the Start button - m_driverController.start().toggleOnTrue(m_pneumatics.disableCompressorCommand()); + driverController.start().toggleOnTrue(pneumatics.disableCompressorCommand()); } /** @@ -85,7 +83,7 @@ public void configureBindings() { */ public Command getAutonomousCommand() { // Drive forward for 2 meters at half velocity with a 3 second timeout - return m_drive + return drive .driveDistanceCommand(AutoConstants.kDriveDistance, AutoConstants.kDriveVelocity) .withTimeout(AutoConstants.kTimeout); } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/Robot.java index 62060dcc701..a32bcd40610 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/Robot.java @@ -18,9 +18,9 @@ */ @Logged(name = "Rapid React Command Robot") public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RapidReactCommandBot m_robot = new RapidReactCommandBot(); + private final RapidReactCommandBot robot = new RapidReactCommandBot(); /** * This function is run when the robot is first started up and should be used for any @@ -28,7 +28,7 @@ public class Robot extends TimedRobot { */ public Robot() { // Configure default commands and condition bindings on robot startup - m_robot.configureBindings(); + robot.configureBindings(); // Initialize data logging. DataLogManager.start(); @@ -60,10 +60,10 @@ public void disabledPeriodic() {} @Override public void autonomousInit() { - m_autonomousCommand = m_robot.getAutonomousCommand(); + autonomousCommand = robot.getAutonomousCommand(); - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -77,8 +77,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Drive.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Drive.java index b6655c8e04d..77168e34acb 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Drive.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Drive.java @@ -23,34 +23,34 @@ @Logged public class Drive extends SubsystemBase { // The motors on the left side of the drive. - private final PWMSparkMax m_leftLeader = new PWMSparkMax(DriveConstants.kLeftMotor1Port); - private final PWMSparkMax m_leftFollower = new PWMSparkMax(DriveConstants.kLeftMotor2Port); + private final PWMSparkMax leftLeader = new PWMSparkMax(DriveConstants.kLeftMotor1Port); + private final PWMSparkMax leftFollower = new PWMSparkMax(DriveConstants.kLeftMotor2Port); // The motors on the right side of the drive. - private final PWMSparkMax m_rightLeader = new PWMSparkMax(DriveConstants.kRightMotor1Port); - private final PWMSparkMax m_rightFollower = new PWMSparkMax(DriveConstants.kRightMotor2Port); + private final PWMSparkMax rightLeader = new PWMSparkMax(DriveConstants.kRightMotor1Port); + private final PWMSparkMax rightFollower = new PWMSparkMax(DriveConstants.kRightMotor2Port); // The robot's drive @NotLogged // Would duplicate motor data, there's no point sending it twice - private final DifferentialDrive m_drive = - new DifferentialDrive(m_leftLeader::setThrottle, m_rightLeader::setThrottle); + private final DifferentialDrive drive = + new DifferentialDrive(leftLeader::setThrottle, rightLeader::setThrottle); // The left-side drive encoder - private final Encoder m_leftEncoder = + private final Encoder leftEncoder = new Encoder( DriveConstants.kLeftEncoderPorts[0], DriveConstants.kLeftEncoderPorts[1], DriveConstants.kLeftEncoderReversed); // The right-side drive encoder - private final Encoder m_rightEncoder = + private final Encoder rightEncoder = new Encoder( DriveConstants.kRightEncoderPorts[0], DriveConstants.kRightEncoderPorts[1], DriveConstants.kRightEncoderReversed); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final ProfiledPIDController m_controller = + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final ProfiledPIDController controller = new ProfiledPIDController( DriveConstants.kTurnP, DriveConstants.kTurnI, @@ -58,31 +58,31 @@ public class Drive extends SubsystemBase { new TrapezoidProfile.Constraints( DriveConstants.kMaxTurnRateDegPerS, DriveConstants.kMaxTurnAccelerationDegPerSSquared)); - private final SimpleMotorFeedforward m_feedforward = + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(DriveConstants.ks, DriveConstants.kv, DriveConstants.ka); /** Creates a new Drive subsystem. */ public Drive() { - SendableRegistry.addChild(m_drive, m_leftLeader); - SendableRegistry.addChild(m_drive, m_rightLeader); + SendableRegistry.addChild(drive, leftLeader); + SendableRegistry.addChild(drive, rightLeader); - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Sets the distance per pulse for the encoders - m_leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); - m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); // Set the controller to be continuous (because it is an angle controller) - m_controller.enableContinuousInput(-180, 180); + controller.enableContinuousInput(-180, 180); // Set the controller tolerance - the delta tolerance ensures the robot is stationary at the // setpoint before it is considered as having reached the reference - m_controller.setTolerance( + controller.setTolerance( DriveConstants.kTurnToleranceDeg, DriveConstants.kTurnRateToleranceDegPerS); } @@ -95,7 +95,7 @@ public Drive() { public Command arcadeDriveCommand(DoubleSupplier fwd, DoubleSupplier rot) { // A split-stick arcade command, with forward/backward controlled by the left // hand, and turning controlled by the right. - return run(() -> m_drive.arcadeDrive(fwd.getAsDouble(), rot.getAsDouble())) + return run(() -> drive.arcadeDrive(fwd.getAsDouble(), rot.getAsDouble())) .withName("arcadeDrive"); } @@ -109,16 +109,15 @@ public Command driveDistanceCommand(double distance, double velocity) { return runOnce( () -> { // Reset encoders at the start of the command - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); }) // Drive forward at specified velocity - .andThen(run(() -> m_drive.arcadeDrive(velocity, 0))) + .andThen(run(() -> drive.arcadeDrive(velocity, 0))) // End command when we've traveled the specified distance - .until( - () -> Math.max(m_leftEncoder.getDistance(), m_rightEncoder.getDistance()) >= distance) + .until(() -> Math.max(leftEncoder.getDistance(), rightEncoder.getDistance()) >= distance) // Stop the drive when the command ends - .finallyDo(interrupted -> m_drive.stopMotor()); + .finallyDo(interrupted -> drive.stopMotor()); } /** @@ -129,15 +128,15 @@ public Command driveDistanceCommand(double distance, double velocity) { */ public Command turnToAngleCommand(double angleDeg) { return startRun( - () -> m_controller.reset(m_imu.getRotation2d().getDegrees()), + () -> controller.reset(imu.getRotation2d().getDegrees()), () -> - m_drive.arcadeDrive( + drive.arcadeDrive( 0, - m_controller.calculate(m_imu.getRotation2d().getDegrees(), angleDeg) + controller.calculate(imu.getRotation2d().getDegrees(), angleDeg) // Divide feedforward voltage by battery voltage to normalize it to [-1, 1] - + m_feedforward.calculate(m_controller.getSetpoint().velocity) + + feedforward.calculate(controller.getSetpoint().velocity) / RobotController.getBatteryVoltage())) - .until(m_controller::atGoal) - .finallyDo(() -> m_drive.arcadeDrive(0, 0)); + .until(controller::atGoal) + .finallyDo(() -> drive.arcadeDrive(0, 0)); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Intake.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Intake.java index 6c9dce7bfe5..18c447e1e09 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Intake.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Intake.java @@ -16,10 +16,10 @@ @Logged public class Intake extends SubsystemBase { - private final PWMSparkMax m_motor = new PWMSparkMax(IntakeConstants.kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(IntakeConstants.kMotorPort); // Double solenoid connected to two channels of a PCM with the default CAN ID - private final DoubleSolenoid m_pistons = + private final DoubleSolenoid pistons = new DoubleSolenoid( 0, PneumaticsModuleType.CTRE_PCM, @@ -28,8 +28,8 @@ public class Intake extends SubsystemBase { /** Returns a command that deploys the intake, and then runs the intake motor indefinitely. */ public Command intakeCommand() { - return runOnce(() -> m_pistons.set(DoubleSolenoid.Value.FORWARD)) - .andThen(run(() -> m_motor.setThrottle(1.0))) + return runOnce(() -> pistons.set(DoubleSolenoid.Value.FORWARD)) + .andThen(run(() -> motor.setThrottle(1.0))) .withName("Intake"); } @@ -37,8 +37,8 @@ public Command intakeCommand() { public Command retractCommand() { return runOnce( () -> { - m_motor.disable(); - m_pistons.set(DoubleSolenoid.Value.REVERSE); + motor.disable(); + pistons.set(DoubleSolenoid.Value.REVERSE); }) .withName("Retract"); } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Pneumatics.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Pneumatics.java index 12caca5af91..2bf2fe70a8b 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Pneumatics.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Pneumatics.java @@ -21,11 +21,11 @@ public class Pneumatics extends SubsystemBase { // so if r is the raw AnalogPotentiometer output, the pressure is 250r-25 static final double kScale = 250; static final double kOffset = -25; - private final AnalogPotentiometer m_pressureTransducer = + private final AnalogPotentiometer pressureTransducer = new AnalogPotentiometer(/* the AnalogIn port*/ 2, kScale, kOffset); // Compressor connected to a PCM with a default CAN ID (0) - private final Compressor m_compressor = new Compressor(0, PneumaticsModuleType.CTRE_PCM); + private final Compressor compressor = new Compressor(0, PneumaticsModuleType.CTRE_PCM); /** * Query the analog pressure sensor. @@ -34,7 +34,7 @@ public class Pneumatics extends SubsystemBase { */ public double getPressure() { // Get the pressure (in PSI) from an analog pressure sensor connected to the RIO. - return m_pressureTransducer.get(); + return pressureTransducer.get(); } /** @@ -47,11 +47,11 @@ public double getPressure() { public Command disableCompressorCommand() { return startEnd( // Disable closed-loop mode on the compressor. - m_compressor::disable, + compressor::disable, // Enable closed-loop mode based on the digital pressure switch connected to the // PCM/PH. // The switch is open when the pressure is over ~120 PSI. - m_compressor::enableDigital) + compressor::enableDigital) .withName("Compressor Disabled"); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Shooter.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Shooter.java index 58582d1d17e..d80a475dc6e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Shooter.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Shooter.java @@ -18,28 +18,28 @@ @Logged public class Shooter extends SubsystemBase { - private final PWMSparkMax m_shooterMotor = new PWMSparkMax(ShooterConstants.kShooterMotorPort); - private final PWMSparkMax m_feederMotor = new PWMSparkMax(ShooterConstants.kFeederMotorPort); - private final Encoder m_shooterEncoder = + private final PWMSparkMax shooterMotor = new PWMSparkMax(ShooterConstants.kShooterMotorPort); + private final PWMSparkMax feederMotor = new PWMSparkMax(ShooterConstants.kFeederMotorPort); + private final Encoder shooterEncoder = new Encoder( ShooterConstants.kEncoderPorts[0], ShooterConstants.kEncoderPorts[1], ShooterConstants.kEncoderReversed); - private final SimpleMotorFeedforward m_shooterFeedforward = + private final SimpleMotorFeedforward shooterFeedforward = new SimpleMotorFeedforward(ShooterConstants.kS, ShooterConstants.kV); - private final PIDController m_shooterFeedback = new PIDController(ShooterConstants.kP, 0.0, 0.0); + private final PIDController shooterFeedback = new PIDController(ShooterConstants.kP, 0.0, 0.0); /** The shooter subsystem for the robot. */ public Shooter() { - m_shooterFeedback.setTolerance(ShooterConstants.kShooterToleranceRPS); - m_shooterEncoder.setDistancePerPulse(ShooterConstants.kEncoderDistancePerPulse); + shooterFeedback.setTolerance(ShooterConstants.kShooterToleranceRPS); + shooterEncoder.setDistancePerPulse(ShooterConstants.kEncoderDistancePerPulse); // Set default command to turn off both the shooter and feeder motors, and then idle setDefaultCommand( runOnce( () -> { - m_shooterMotor.disable(); - m_feederMotor.disable(); + shooterMotor.disable(); + feederMotor.disable(); }) .andThen(run(() -> {})) .withName("Idle")); @@ -56,14 +56,14 @@ public Command shootCommand(double setpointRotationsPerSecond) { // Run the shooter flywheel at the desired setpoint using feedforward and feedback run( () -> { - m_shooterMotor.setThrottle( - m_shooterFeedforward.calculate(setpointRotationsPerSecond) - + m_shooterFeedback.calculate( - m_shooterEncoder.getRate(), setpointRotationsPerSecond)); + shooterMotor.setThrottle( + shooterFeedforward.calculate(setpointRotationsPerSecond) + + shooterFeedback.calculate( + shooterEncoder.getRate(), setpointRotationsPerSecond)); }), // Wait until the shooter has reached the setpoint, and then run the feeder - waitUntil(m_shooterFeedback::atSetpoint).andThen(() -> m_feederMotor.setThrottle(1))) + waitUntil(shooterFeedback::atSetpoint).andThen(() -> feederMotor.setThrottle(1))) .withName("Shoot"); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java index 94fec8a24ff..a84447e903d 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/rapidreactcommandbot/subsystems/Storage.java @@ -15,24 +15,24 @@ @Logged public class Storage extends SubsystemBase { - private final PWMSparkMax m_motor = new PWMSparkMax(StorageConstants.kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(StorageConstants.kMotorPort); @NotLogged // We'll log a more meaningful boolean instead - private final DigitalInput m_ballSensor = new DigitalInput(StorageConstants.kBallSensorPort); + private final DigitalInput ballSensor = new DigitalInput(StorageConstants.kBallSensorPort); // Expose trigger from subsystem to improve readability and ease // inter-subsystem communications /** Whether the ball storage is full. */ @Logged(name = "Has Cargo") - public final Trigger hasCargo = new Trigger(m_ballSensor::get); + public final Trigger hasCargo = new Trigger(ballSensor::get); /** Create a new Storage subsystem. */ public Storage() { // Set default command to turn off the storage motor and then idle - setDefaultCommand(runOnce(m_motor::disable).andThen(run(() -> {})).withName("Idle")); + setDefaultCommand(runOnce(motor::disable).andThen(run(() -> {})).withName("Idle")); } /** Returns a command that runs the storage motor indefinitely. */ public Command runCommand() { - return run(() -> m_motor.setThrottle(1)).withName("run"); + return run(() -> motor.setThrottle(1)).withName("run"); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/Robot.java index 15e6eac3122..e2bb17bfa67 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/Robot.java @@ -14,8 +14,8 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; - private final RobotContainer m_robotContainer; + private Command autonomousCommand; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -24,7 +24,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,11 +54,11 @@ public void disabledPeriodic() {} @Override public void autonomousInit() { // Get selected routine from the SmartDashboard - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -72,8 +72,8 @@ public void teleopInit() { // use the default command which is ArcadeDrive. If you want the autonomous // to continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/RobotContainer.java index 2a0897feea1..310634379a2 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/RobotContainer.java @@ -27,14 +27,14 @@ */ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final Drivetrain m_drivetrain = new Drivetrain(); - private final OnBoardIO m_onboardIO = new OnBoardIO(ChannelMode.INPUT, ChannelMode.INPUT); + private final Drivetrain drivetrain = new Drivetrain(); + private final OnBoardIO onboardIO = new OnBoardIO(ChannelMode.INPUT, ChannelMode.INPUT); // Assumes a gamepad plugged into channel 0 - private final Joystick m_controller = new Joystick(0); + private final Joystick controller = new Joystick(0); // Create SmartDashboard chooser for autonomous routines - private final SendableChooser m_chooser = new SendableChooser<>(); + private final SendableChooser chooser = new SendableChooser<>(); // NOTE: The I/O pin functionality of the 5 exposed I/O pins depends on the hardware "overlay" // that is specified when launching the wpilib-ws server on the Romi raspberry pi. @@ -62,18 +62,18 @@ public RobotContainer() { private void configureButtonBindings() { // Default command is arcade drive. This will run unless another command // is scheduled over it. - m_drivetrain.setDefaultCommand(getArcadeDriveCommand()); + drivetrain.setDefaultCommand(getArcadeDriveCommand()); // Example of how to use the onboard IO - Trigger onboardButtonA = new Trigger(m_onboardIO::getButtonAPressed); + Trigger onboardButtonA = new Trigger(onboardIO::getButtonAPressed); onboardButtonA .onTrue(new PrintCommand("Button A Pressed")) .onFalse(new PrintCommand("Button A Released")); // Setup SmartDashboard options - m_chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(m_drivetrain)); - m_chooser.addOption("Auto Routine Time", new AutonomousTime(m_drivetrain)); - SmartDashboard.putData(m_chooser); + chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(drivetrain)); + chooser.addOption("Auto Routine Time", new AutonomousTime(drivetrain)); + SmartDashboard.putData(chooser); } /** @@ -82,7 +82,7 @@ private void configureButtonBindings() { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_chooser.getSelected(); + return chooser.getSelected(); } /** @@ -92,6 +92,6 @@ public Command getAutonomousCommand() { */ public Command getArcadeDriveCommand() { return new ArcadeDrive( - m_drivetrain, () -> -m_controller.getRawAxis(1), () -> -m_controller.getRawAxis(2)); + drivetrain, () -> -controller.getRawAxis(1), () -> -controller.getRawAxis(2)); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/ArcadeDrive.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/ArcadeDrive.java index bd39ed42a81..4bb6f530125 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/ArcadeDrive.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/ArcadeDrive.java @@ -9,9 +9,9 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain; public class ArcadeDrive extends Command { - private final Drivetrain m_drivetrain; - private final Supplier m_xaxisVelocitySupplier; - private final Supplier m_zaxisRotateSupplier; + private final Drivetrain drivetrain; + private final Supplier xaxisVelocitySupplier; + private final Supplier zaxisRotateSupplier; /** * Creates a new ArcadeDrive. This command will drive your robot according to the velocity @@ -25,9 +25,9 @@ public ArcadeDrive( Drivetrain drivetrain, Supplier xaxisVelocitySupplier, Supplier zaxisRotateSupplier) { - m_drivetrain = drivetrain; - m_xaxisVelocitySupplier = xaxisVelocitySupplier; - m_zaxisRotateSupplier = zaxisRotateSupplier; + this.drivetrain = drivetrain; + this.xaxisVelocitySupplier = xaxisVelocitySupplier; + this.zaxisRotateSupplier = zaxisRotateSupplier; addRequirements(drivetrain); } @@ -38,7 +38,7 @@ public void initialize() {} // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drivetrain.arcadeDrive(m_xaxisVelocitySupplier.get(), m_zaxisRotateSupplier.get()); + drivetrain.arcadeDrive(xaxisVelocitySupplier.get(), zaxisRotateSupplier.get()); } // Called once the command ends or is interrupted. diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveDistance.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveDistance.java index 751080c705d..2b1ca572975 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveDistance.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveDistance.java @@ -8,9 +8,9 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain; public class DriveDistance extends Command { - private final Drivetrain m_drive; - private final double m_distance; - private final double m_velocity; + private final Drivetrain drive; + private final double distance; + private final double velocity; /** * Creates a new DriveDistance. This command will drive your your robot for a desired distance at @@ -21,35 +21,35 @@ public class DriveDistance extends Command { * @param drive The drivetrain subsystem on which this command will run */ public DriveDistance(double velocity, double inches, Drivetrain drive) { - m_distance = inches; - m_velocity = velocity; - m_drive = drive; + distance = inches; + this.velocity = velocity; + this.drive = drive; addRequirements(drive); } // Called when the command is initially scheduled. @Override public void initialize() { - m_drive.arcadeDrive(0, 0); - m_drive.resetEncoders(); + drive.arcadeDrive(0, 0); + drive.resetEncoders(); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(m_velocity, 0); + drive.arcadeDrive(velocity, 0); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @Override public boolean isFinished() { // Compare distance travelled from start to desired distance - return Math.abs(m_drive.getAverageDistanceInch()) >= m_distance; + return Math.abs(drive.getAverageDistanceInch()) >= distance; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveTime.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveTime.java index 08ee8e6ec50..16267838a0a 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveTime.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/DriveTime.java @@ -8,10 +8,10 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain; public class DriveTime extends Command { - private final double m_duration; - private final double m_velocity; - private final Drivetrain m_drive; - private long m_startTime; + private final double duration; + private final double velocity; + private final Drivetrain drive; + private long startTime; /** * Creates a new DriveTime. This command will drive your robot for a desired velocity and time. @@ -21,34 +21,34 @@ public class DriveTime extends Command { * @param drive The drivetrain subsystem on which this command will run */ public DriveTime(double velocity, double time, Drivetrain drive) { - m_velocity = velocity; - m_duration = time * 1000; - m_drive = drive; + this.velocity = velocity; + duration = time * 1000; + this.drive = drive; addRequirements(drive); } // Called when the command is initially scheduled. @Override public void initialize() { - m_startTime = System.currentTimeMillis(); - m_drive.arcadeDrive(0, 0); + startTime = System.currentTimeMillis(); + drive.arcadeDrive(0, 0); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(m_velocity, 0); + drive.arcadeDrive(velocity, 0); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @Override public boolean isFinished() { - return (System.currentTimeMillis() - m_startTime) >= m_duration; + return (System.currentTimeMillis() - startTime) >= duration; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnDegrees.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnDegrees.java index 8aa7502d7a3..42099d912b1 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnDegrees.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnDegrees.java @@ -8,9 +8,9 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain; public class TurnDegrees extends Command { - private final Drivetrain m_drive; - private final double m_degrees; - private final double m_velocity; + private final Drivetrain drive; + private final double degrees; + private final double velocity; /** * Creates a new TurnDegrees. This command will turn your robot for a desired rotation (in @@ -21,9 +21,9 @@ public class TurnDegrees extends Command { * @param drive The drive subsystem on which this command will run */ public TurnDegrees(double velocity, double degrees, Drivetrain drive) { - m_degrees = degrees; - m_velocity = velocity; - m_drive = drive; + this.degrees = degrees; + this.velocity = velocity; + this.drive = drive; addRequirements(drive); } @@ -31,20 +31,20 @@ public TurnDegrees(double velocity, double degrees, Drivetrain drive) { @Override public void initialize() { // Set motors to stop, read encoder values for starting point - m_drive.arcadeDrive(0, 0); - m_drive.resetEncoders(); + drive.arcadeDrive(0, 0); + drive.resetEncoders(); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(0, m_velocity); + drive.arcadeDrive(0, velocity); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @@ -57,12 +57,12 @@ has a wheel placement diameter (149 mm) - width of the wheel (8 mm) = 141 mm */ double inchPerDegree = Math.PI * 5.551 / 360; // Compare distance travelled from start to distance based on degree turn - return getAverageTurningDistance() >= (inchPerDegree * m_degrees); + return getAverageTurningDistance() >= (inchPerDegree * degrees); } private double getAverageTurningDistance() { - double leftDistance = Math.abs(m_drive.getLeftDistanceInch()); - double rightDistance = Math.abs(m_drive.getRightDistanceInch()); + double leftDistance = Math.abs(drive.getLeftDistanceInch()); + double rightDistance = Math.abs(drive.getRightDistanceInch()); return (leftDistance + rightDistance) / 2.0; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnTime.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnTime.java index 2dcd878c212..cd9004a8c54 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnTime.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/commands/TurnTime.java @@ -12,10 +12,10 @@ * desired rotational velocity and time. */ public class TurnTime extends Command { - private final double m_duration; - private final double m_rotationalVelocity; - private final Drivetrain m_drive; - private long m_startTime; + private final double duration; + private final double rotationalVelocity; + private final Drivetrain drive; + private long startTime; /** * Creates a new TurnTime. @@ -25,34 +25,34 @@ public class TurnTime extends Command { * @param drive The drive subsystem on which this command will run */ public TurnTime(double velocity, double time, Drivetrain drive) { - m_rotationalVelocity = velocity; - m_duration = time * 1000; - m_drive = drive; + rotationalVelocity = velocity; + duration = time * 1000; + this.drive = drive; addRequirements(drive); } // Called when the command is initially scheduled. @Override public void initialize() { - m_startTime = System.currentTimeMillis(); - m_drive.arcadeDrive(0, 0); + startTime = System.currentTimeMillis(); + drive.arcadeDrive(0, 0); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(0, m_rotationalVelocity); + drive.arcadeDrive(0, rotationalVelocity); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @Override public boolean isFinished() { - return (System.currentTimeMillis() - m_startTime) >= m_duration; + return (System.currentTimeMillis() - startTime) >= duration; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/subsystems/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/subsystems/Drivetrain.java index 26c5940af4b..52d83c435e8 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/subsystems/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/romireference/subsystems/Drivetrain.java @@ -17,60 +17,60 @@ public class Drivetrain extends SubsystemBase { // The Romi has the left and right motors set to // PWM channels 0 and 1 respectively - private final Spark m_leftMotor = new Spark(0); - private final Spark m_rightMotor = new Spark(1); + private final Spark leftMotor = new Spark(0); + private final Spark rightMotor = new Spark(1); // The Romi has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); // Set up the RomiGyro - private final RomiGyro m_gyro = new RomiGyro(); + private final RomiGyro gyro = new RomiGyro(); /** Creates a new Drivetrain. */ public Drivetrain() { - SendableRegistry.addChild(m_diffDrive, m_leftMotor); - SendableRegistry.addChild(m_diffDrive, m_rightMotor); + SendableRegistry.addChild(diffDrive, leftMotor); + SendableRegistry.addChild(diffDrive, rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public int getLeftEncoderCount() { - return m_leftEncoder.get(); + return leftEncoder.get(); } public int getRightEncoderCount() { - return m_rightEncoder.get(); + return rightEncoder.get(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } public double getAverageDistanceInch() { @@ -83,7 +83,7 @@ public double getAverageDistanceInch() { * @return The current angle of the Romi in degrees */ public double getGyroAngleX() { - return m_gyro.getAngleX(); + return gyro.getAngleX(); } /** @@ -92,7 +92,7 @@ public double getGyroAngleX() { * @return The current angle of the Romi in degrees */ public double getGyroAngleY() { - return m_gyro.getAngleY(); + return gyro.getAngleY(); } /** @@ -101,12 +101,12 @@ public double getGyroAngleY() { * @return The current angle of the Romi in degrees */ public double getGyroAngleZ() { - return m_gyro.getAngleZ(); + return gyro.getAngleZ(); } /** Reset the gyro. */ public void resetGyro() { - m_gyro.reset(); + gyro.reset(); } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Drivetrain.java index f138ba2646f..8cc49eeaa8b 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Drivetrain.java @@ -34,71 +34,71 @@ public class Drivetrain { private static final double kWheelRadius = 0.0508; private static final int kEncoderResolution = -4096; - private final PWMSparkMax m_leftLeader = new PWMSparkMax(1); - private final PWMSparkMax m_leftFollower = new PWMSparkMax(2); - private final PWMSparkMax m_rightLeader = new PWMSparkMax(3); - private final PWMSparkMax m_rightFollower = new PWMSparkMax(4); + private final PWMSparkMax leftLeader = new PWMSparkMax(1); + private final PWMSparkMax leftFollower = new PWMSparkMax(2); + private final PWMSparkMax rightLeader = new PWMSparkMax(3); + private final PWMSparkMax rightFollower = new PWMSparkMax(4); - private final Encoder m_leftEncoder = new Encoder(0, 1); - private final Encoder m_rightEncoder = new Encoder(2, 3); + private final Encoder leftEncoder = new Encoder(0, 1); + private final Encoder rightEncoder = new Encoder(2, 3); - private final PIDController m_leftPIDController = new PIDController(8.5, 0, 0); - private final PIDController m_rightPIDController = new PIDController(8.5, 0, 0); + private final PIDController leftPIDController = new PIDController(8.5, 0, 0); + private final PIDController rightPIDController = new PIDController(8.5, 0, 0); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final DifferentialDriveKinematics m_kinematics = + private final DifferentialDriveKinematics kinematics = new DifferentialDriveKinematics(kTrackwidth); - private final DifferentialDriveOdometry m_odometry = + private final DifferentialDriveOdometry odometry = new DifferentialDriveOdometry( - m_imu.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance()); + imu.getRotation2d(), leftEncoder.getDistance(), rightEncoder.getDistance()); // Gains are for example purposes only - must be determined for your own // robot! - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(1, 3); // Simulation classes help us simulate our robot - private final EncoderSim m_leftEncoderSim = new EncoderSim(m_leftEncoder); - private final EncoderSim m_rightEncoderSim = new EncoderSim(m_rightEncoder); - private final Field2d m_fieldSim = new Field2d(); - private final LinearSystem m_drivetrainSystem = + private final EncoderSim leftEncoderSim = new EncoderSim(leftEncoder); + private final EncoderSim rightEncoderSim = new EncoderSim(rightEncoder); + private final Field2d fieldSim = new Field2d(); + private final LinearSystem drivetrainSystem = Models.differentialDriveFromSysId(1.98, 0.2, 1.5, 0.3); - private final DifferentialDrivetrainSim m_drivetrainSimulator = + private final DifferentialDrivetrainSim drivetrainSimulator = new DifferentialDrivetrainSim( - m_drivetrainSystem, DCMotor.getCIM(2), 8, kTrackwidth, kWheelRadius, null); + drivetrainSystem, DCMotor.getCIM(2), 8, kTrackwidth, kWheelRadius, null); /** Subsystem constructor. */ public Drivetrain() { - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Set the distance per pulse for the drive encoders. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_leftEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); - m_rightEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + leftEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + rightEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); - m_rightLeader.setInverted(true); - SmartDashboard.putData("Field", m_fieldSim); + rightLeader.setInverted(true); + SmartDashboard.putData("Field", fieldSim); } /** Sets velocities to the drivetrain motors. */ public void setVelocities(DifferentialDriveWheelVelocities velocities) { - final double leftFeedforward = m_feedforward.calculate(velocities.left); - final double rightFeedforward = m_feedforward.calculate(velocities.right); - double leftOutput = m_leftPIDController.calculate(m_leftEncoder.getRate(), velocities.left); - double rightOutput = m_rightPIDController.calculate(m_rightEncoder.getRate(), velocities.right); + final double leftFeedforward = feedforward.calculate(velocities.left); + final double rightFeedforward = feedforward.calculate(velocities.right); + double leftOutput = leftPIDController.calculate(leftEncoder.getRate(), velocities.left); + double rightOutput = rightPIDController.calculate(rightEncoder.getRate(), velocities.right); - m_leftLeader.setVoltage(leftOutput + leftFeedforward); - m_rightLeader.setVoltage(rightOutput + rightFeedforward); + leftLeader.setVoltage(leftOutput + leftFeedforward); + rightLeader.setVoltage(rightOutput + rightFeedforward); } /** @@ -108,25 +108,24 @@ public void setVelocities(DifferentialDriveWheelVelocities velocities) { * @param rot the rotation */ public void drive(double xVelocity, double rot) { - setVelocities(m_kinematics.toWheelVelocities(new ChassisVelocities(xVelocity, 0, rot))); + setVelocities(kinematics.toWheelVelocities(new ChassisVelocities(xVelocity, 0, rot))); } /** Update robot odometry. */ public void updateOdometry() { - m_odometry.update( - m_imu.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance()); + odometry.update(imu.getRotation2d(), leftEncoder.getDistance(), rightEncoder.getDistance()); } /** Resets robot odometry. */ public void resetOdometry(Pose2d pose) { - m_drivetrainSimulator.setPose(pose); - m_odometry.resetPosition( - m_imu.getRotation2d(), m_leftEncoder.getDistance(), m_rightEncoder.getDistance(), pose); + drivetrainSimulator.setPose(pose); + odometry.resetPosition( + imu.getRotation2d(), leftEncoder.getDistance(), rightEncoder.getDistance(), pose); } /** Check the current robot pose. */ public Pose2d getPose() { - return m_odometry.getPose(); + return odometry.getPose(); } /** Update our simulation. This should be run every robot loop in simulation. */ @@ -135,21 +134,21 @@ public void simulationPeriodic() { // simulation, and write the simulated positions and velocities to our // simulated encoder and gyro. We negate the right side so that positive // voltages make the right side move forward. - m_drivetrainSimulator.setInputs( - m_leftLeader.getThrottle() * RobotController.getInputVoltage(), - m_rightLeader.getThrottle() * RobotController.getInputVoltage()); - m_drivetrainSimulator.update(0.02); - - m_leftEncoderSim.setDistance(m_drivetrainSimulator.getLeftPosition()); - m_leftEncoderSim.setRate(m_drivetrainSimulator.getLeftVelocity()); - m_rightEncoderSim.setDistance(m_drivetrainSimulator.getRightPosition()); - m_rightEncoderSim.setRate(m_drivetrainSimulator.getRightVelocity()); - // m_gyroSim.setAngle(-m_drivetrainSimulator.getHeading().getDegrees()); + drivetrainSimulator.setInputs( + leftLeader.getThrottle() * RobotController.getInputVoltage(), + rightLeader.getThrottle() * RobotController.getInputVoltage()); + drivetrainSimulator.update(0.02); + + leftEncoderSim.setDistance(drivetrainSimulator.getLeftPosition()); + leftEncoderSim.setRate(drivetrainSimulator.getLeftVelocity()); + rightEncoderSim.setDistance(drivetrainSimulator.getRightPosition()); + rightEncoderSim.setRate(drivetrainSimulator.getRightVelocity()); + // gyroSim.setAngle(-drivetrainSimulator.getHeading().getDegrees()); } /** Update odometry - this should be run every robot loop. */ public void periodic() { updateOdometry(); - m_fieldSim.setRobotPose(m_odometry.getPose()); + fieldSim.setRobotPose(odometry.getPose()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Robot.java index 192684998c9..c168bf88ed8 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/simpledifferentialdrivesimulation/Robot.java @@ -18,21 +18,21 @@ import org.wpilib.system.Timer; public class Robot extends TimedRobot { - private final Gamepad m_controller = new Gamepad(0); + private final Gamepad controller = new Gamepad(0); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // to 1. - private final SlewRateLimiter m_velocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter velocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); - private final Drivetrain m_drive = new Drivetrain(); - private final LTVUnicycleController m_feedback = new LTVUnicycleController(0.020); - private final Timer m_timer = new Timer(); - private final Trajectory m_trajectory; + private final Drivetrain drive = new Drivetrain(); + private final LTVUnicycleController feedback = new LTVUnicycleController(0.020); + private final Timer timer = new Timer(); + private final Trajectory trajectory; /** Called once at the beginning of the robot program. */ public Robot() { - m_trajectory = + trajectory = TrajectoryGenerator.generateTrajectory( new Pose2d(2, 2, Rotation2d.kZero), List.of(), @@ -42,40 +42,39 @@ public Robot() { @Override public void robotPeriodic() { - m_drive.periodic(); + drive.periodic(); } @Override public void autonomousInit() { - m_timer.restart(); - m_drive.resetOdometry(m_trajectory.getInitialPose()); + timer.restart(); + drive.resetOdometry(trajectory.getInitialPose()); } @Override public void autonomousPeriodic() { - double elapsed = m_timer.get(); - Trajectory.State reference = m_trajectory.sample(elapsed); - ChassisVelocities velocities = m_feedback.calculate(m_drive.getPose(), reference); - m_drive.drive(velocities.vx, velocities.omega); + double elapsed = timer.get(); + Trajectory.State reference = trajectory.sample(elapsed); + ChassisVelocities velocities = feedback.calculate(drive.getPose(), reference); + drive.drive(velocities.vx, velocities.omega); } @Override public void teleopPeriodic() { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. - double xVelocity = - -m_velocityLimiter.calculate(m_controller.getLeftY()) * Drivetrain.kMaxVelocity; + double xVelocity = -velocityLimiter.calculate(controller.getLeftY()) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Xbox controllers return positive values when you pull to // the right by default. - double rot = -m_rotLimiter.calculate(m_controller.getRightX()) * Drivetrain.kMaxAngularVelocity; - m_drive.drive(xVelocity, rot); + double rot = -rotLimiter.calculate(controller.getRightX()) * Drivetrain.kMaxAngularVelocity; + drive.drive(xVelocity, rot); } @Override public void simulationPeriodic() { - m_drive.simulationPeriodic(); + drive.simulationPeriodic(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/statespacearm/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/statespacearm/Robot.java index 8d280eed77a..ce508d4bd90 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/statespacearm/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/statespacearm/Robot.java @@ -40,28 +40,28 @@ public class Robot extends TimedRobot { // the motors, this number should be greater than one. private static final double kArmGearing = 10.0; - private final TrapezoidProfile m_profile = + private final TrapezoidProfile profile = new TrapezoidProfile( new TrapezoidProfile.Constraints( Units.degreesToRadians(45), Units.degreesToRadians(90))); // Max arm velocity and acceleration. - private TrapezoidProfile.State m_lastProfiledReference = new TrapezoidProfile.State(); + private TrapezoidProfile.State lastProfiledReference = new TrapezoidProfile.State(); // The plant holds a state-space model of our arm. This system has the following properties: // // States: [position, velocity], in radians and radians per second. // Inputs (what we can "put in"): [voltage], in volts. // Outputs (what we can measure): [position], in radians. - private final LinearSystem m_armPlant = + private final LinearSystem armPlant = Models.singleJointedArmFromPhysicalConstants(DCMotor.getNEO(2), kArmMOI, kArmGearing); // The observer fuses our encoder data and voltage inputs to reject noise. @SuppressWarnings("unchecked") - private final KalmanFilter m_observer = + private final KalmanFilter observer = new KalmanFilter<>( Nat.N2(), Nat.N1(), - (LinearSystem) m_armPlant.slice(0), + (LinearSystem) armPlant.slice(0), VecBuilder.fill(0.015, 0.17), // How accurate we // think our model is, in radians and radians/sec VecBuilder.fill(0.01), // How accurate we think our encoder position @@ -70,9 +70,9 @@ public class Robot extends TimedRobot { // A LQR uses feedback to create voltage commands. @SuppressWarnings("unchecked") - private final LinearQuadraticRegulator m_controller = + private final LinearQuadraticRegulator controller = new LinearQuadraticRegulator<>( - (LinearSystem) m_armPlant.slice(0), + (LinearSystem) armPlant.slice(0), VecBuilder.fill(Units.degreesToRadians(1.0), Units.degreesToRadians(10.0)), // qelms. // Position and velocity error tolerances, in radians and radians per second. Decrease // this @@ -89,31 +89,30 @@ public class Robot extends TimedRobot { // The state-space loop combines a controller, observer, feedforward and plant for easy control. @SuppressWarnings("unchecked") - private final LinearSystemLoop m_loop = + private final LinearSystemLoop loop = new LinearSystemLoop<>( - (LinearSystem) m_armPlant.slice(0), m_controller, m_observer, 12.0, 0.020); + (LinearSystem) armPlant.slice(0), controller, observer, 12.0, 0.020); // An encoder set up to measure arm position in radians. - private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); + private final Encoder encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. - private final Joystick m_joystick = new Joystick(kJoystickPort); + private final Joystick joystick = new Joystick(kJoystickPort); public Robot() { // We go 2 pi radians in 1 rotation, or 4096 counts. - m_encoder.setDistancePerPulse(Math.PI * 2 / 4096.0); + encoder.setDistancePerPulse(Math.PI * 2 / 4096.0); } @Override public void teleopInit() { // Reset our loop to make sure it's in a known state. - m_loop.reset(VecBuilder.fill(m_encoder.getDistance(), m_encoder.getRate())); + loop.reset(VecBuilder.fill(encoder.getDistance(), encoder.getRate())); // Reset our last reference to the current state. - m_lastProfiledReference = - new TrapezoidProfile.State(m_encoder.getDistance(), m_encoder.getRate()); + lastProfiledReference = new TrapezoidProfile.State(encoder.getDistance(), encoder.getRate()); } @Override @@ -121,7 +120,7 @@ public void teleopPeriodic() { // Sets the target position of our arm. This is similar to setting the setpoint of a // PID controller. TrapezoidProfile.State goal; - if (m_joystick.getTrigger()) { + if (joystick.getTrigger()) { // the trigger is pressed, so we go to the high goal. goal = new TrapezoidProfile.State(kRaisedPosition, 0.0); } else { @@ -129,19 +128,19 @@ public void teleopPeriodic() { goal = new TrapezoidProfile.State(kLoweredPosition, 0.0); } // Step our TrapezoidalProfile forward 20ms and set it as our next reference - m_lastProfiledReference = m_profile.calculate(0.020, m_lastProfiledReference, goal); - m_loop.setNextR(m_lastProfiledReference.position, m_lastProfiledReference.velocity); + lastProfiledReference = profile.calculate(0.020, lastProfiledReference, goal); + loop.setNextR(lastProfiledReference.position, lastProfiledReference.velocity); // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.correct(VecBuilder.fill(m_encoder.getDistance())); + loop.correct(VecBuilder.fill(encoder.getDistance())); // Update our LQR to generate new voltage commands and use the voltages to predict the next // state with out Kalman filter. - m_loop.predict(0.020); + loop.predict(0.020); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - double nextVoltage = m_loop.getU(0); - m_motor.setVoltage(nextVoltage); + double nextVoltage = loop.getU(0); + motor.setVoltage(nextVoltage); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceelevator/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceelevator/Robot.java index ef19654e9b2..263f73fdd49 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceelevator/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceelevator/Robot.java @@ -42,12 +42,12 @@ public class Robot extends TimedRobot { // the motors, this number should be greater than one. private static final double kElevatorGearing = 6.0; - private final TrapezoidProfile m_profile = + private final TrapezoidProfile profile = new TrapezoidProfile( new TrapezoidProfile.Constraints( Units.feetToMeters(3.0), Units.feetToMeters(6.0))); // Max elevator velocity and acceleration. - private TrapezoidProfile.State m_lastProfiledReference = new TrapezoidProfile.State(); + private TrapezoidProfile.State lastProfiledReference = new TrapezoidProfile.State(); /* The plant holds a state-space model of our elevator. This system has the following properties: @@ -57,17 +57,17 @@ public class Robot extends TimedRobot { This elevator is driven by two NEO motors. */ - private final LinearSystem m_elevatorPlant = + private final LinearSystem elevatorPlant = Models.elevatorFromPhysicalConstants( DCMotor.getNEO(2), kCarriageMass, kDrumRadius, kElevatorGearing); // The observer fuses our encoder data and voltage inputs to reject noise. @SuppressWarnings("unchecked") - private final KalmanFilter m_observer = + private final KalmanFilter observer = new KalmanFilter<>( Nat.N2(), Nat.N1(), - (LinearSystem) m_elevatorPlant.slice(0), + (LinearSystem) elevatorPlant.slice(0), VecBuilder.fill(Units.inchesToMeters(2), Units.inchesToMeters(40)), // How accurate we // think our model is, in meters and meters/second. VecBuilder.fill(0.001), // How accurate we think our encoder position @@ -76,9 +76,9 @@ public class Robot extends TimedRobot { // A LQR uses feedback to create voltage commands. @SuppressWarnings("unchecked") - private final LinearQuadraticRegulator m_controller = + private final LinearQuadraticRegulator controller = new LinearQuadraticRegulator<>( - (LinearSystem) m_elevatorPlant.slice(0), + (LinearSystem) elevatorPlant.slice(0), VecBuilder.fill(Units.inchesToMeters(1.0), Units.inchesToMeters(10.0)), // qelms. Position // and velocity error tolerances, in meters and meters per second. Decrease this to more // heavily penalize state excursion, or make the controller behave more aggressively. In @@ -93,35 +93,30 @@ public class Robot extends TimedRobot { // The state-space loop combines a controller, observer, feedforward and plant for easy control. @SuppressWarnings("unchecked") - private final LinearSystemLoop m_loop = + private final LinearSystemLoop loop = new LinearSystemLoop<>( - (LinearSystem) m_elevatorPlant.slice(0), - m_controller, - m_observer, - 12.0, - 0.020); + (LinearSystem) elevatorPlant.slice(0), controller, observer, 12.0, 0.020); // An encoder set up to measure elevator height in meters. - private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); + private final Encoder encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. - private final Joystick m_joystick = new Joystick(kJoystickPort); + private final Joystick joystick = new Joystick(kJoystickPort); public Robot() { // Circumference = pi * d, so distance per click = pi * d / counts - m_encoder.setDistancePerPulse(Math.PI * 2 * kDrumRadius / 4096.0); + encoder.setDistancePerPulse(Math.PI * 2 * kDrumRadius / 4096.0); } @Override public void teleopInit() { // Reset our loop to make sure it's in a known state. - m_loop.reset(VecBuilder.fill(m_encoder.getDistance(), m_encoder.getRate())); + loop.reset(VecBuilder.fill(encoder.getDistance(), encoder.getRate())); // Reset our last reference to the current state. - m_lastProfiledReference = - new TrapezoidProfile.State(m_encoder.getDistance(), m_encoder.getRate()); + lastProfiledReference = new TrapezoidProfile.State(encoder.getDistance(), encoder.getRate()); } @Override @@ -129,7 +124,7 @@ public void teleopPeriodic() { // Sets the target position of our arm. This is similar to setting the setpoint of a // PID controller. TrapezoidProfile.State goal; - if (m_joystick.getTrigger()) { + if (joystick.getTrigger()) { // the trigger is pressed, so we go to the high goal. goal = new TrapezoidProfile.State(kHighGoalPosition, 0.0); } else { @@ -137,20 +132,20 @@ public void teleopPeriodic() { goal = new TrapezoidProfile.State(kLowGoalPosition, 0.0); } // Step our TrapezoidalProfile forward 20ms and set it as our next reference - m_lastProfiledReference = m_profile.calculate(0.020, m_lastProfiledReference, goal); - m_loop.setNextR(m_lastProfiledReference.position, m_lastProfiledReference.velocity); + lastProfiledReference = profile.calculate(0.020, lastProfiledReference, goal); + loop.setNextR(lastProfiledReference.position, lastProfiledReference.velocity); // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.correct(VecBuilder.fill(m_encoder.getDistance())); + loop.correct(VecBuilder.fill(encoder.getDistance())); // Update our LQR to generate new voltage commands and use the voltages to predict the next // state with out Kalman filter. - m_loop.predict(0.020); + loop.predict(0.020); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - double nextVoltage = m_loop.getU(0); - m_motor.setVoltage(nextVoltage); + double nextVoltage = loop.getU(0); + motor.setVoltage(nextVoltage); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheel/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheel/Robot.java index 696d181e515..e7ca94623c4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheel/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheel/Robot.java @@ -41,25 +41,25 @@ public class Robot extends TimedRobot { // States: [velocity], in radians per second. // Inputs (what we can "put in"): [voltage], in volts. // Outputs (what we can measure): [velocity], in radians per second. - private final LinearSystem m_flywheelPlant = + private final LinearSystem flywheelPlant = Models.flywheelFromPhysicalConstants( DCMotor.getNEO(2), kFlywheelMomentOfInertia, kFlywheelGearing); // The observer fuses our encoder data and voltage inputs to reject noise. - private final KalmanFilter m_observer = + private final KalmanFilter observer = new KalmanFilter<>( Nat.N1(), Nat.N1(), - m_flywheelPlant, + flywheelPlant, VecBuilder.fill(3.0), // How accurate we think our model is VecBuilder.fill(0.01), // How accurate we think our encoder // data is 0.020); // A LQR uses feedback to create voltage commands. - private final LinearQuadraticRegulator m_controller = + private final LinearQuadraticRegulator controller = new LinearQuadraticRegulator<>( - m_flywheelPlant, + flywheelPlant, VecBuilder.fill(8.0), // qelms. Velocity error tolerance, in radians per second. Decrease // this to more heavily penalize state excursion, or make the controller behave more // aggressively. @@ -70,50 +70,50 @@ public class Robot extends TimedRobot { // lower if using notifiers. // The state-space loop combines a controller, observer, feedforward and plant for easy control. - private final LinearSystemLoop m_loop = - new LinearSystemLoop<>(m_flywheelPlant, m_controller, m_observer, 12.0, 0.020); + private final LinearSystemLoop loop = + new LinearSystemLoop<>(flywheelPlant, controller, observer, 12.0, 0.020); // An encoder set up to measure flywheel velocity in radians per second. - private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); + private final Encoder encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. - private final Joystick m_joystick = new Joystick(kJoystickPort); + private final Joystick joystick = new Joystick(kJoystickPort); public Robot() { // We go 2 pi radians per 4096 clicks. - m_encoder.setDistancePerPulse(2.0 * Math.PI / 4096.0); + encoder.setDistancePerPulse(2.0 * Math.PI / 4096.0); } @Override public void teleopInit() { - m_loop.reset(VecBuilder.fill(m_encoder.getRate())); + loop.reset(VecBuilder.fill(encoder.getRate())); } @Override public void teleopPeriodic() { // Sets the target velocity of our flywheel. This is similar to setting the setpoint of a // PID controller. - if (m_joystick.getTriggerPressed()) { + if (joystick.getTriggerPressed()) { // We just pressed the trigger, so let's set our next reference - m_loop.setNextR(VecBuilder.fill(kSpinupRadPerSec)); - } else if (m_joystick.getTriggerReleased()) { + loop.setNextR(VecBuilder.fill(kSpinupRadPerSec)); + } else if (joystick.getTriggerReleased()) { // We just released the trigger, so let's spin down - m_loop.setNextR(VecBuilder.fill(0.0)); + loop.setNextR(VecBuilder.fill(0.0)); } // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.correct(VecBuilder.fill(m_encoder.getRate())); + loop.correct(VecBuilder.fill(encoder.getRate())); // Update our LQR to generate new voltage commands and use the voltages to predict the next // state with out Kalman filter. - m_loop.predict(0.020); + loop.predict(0.020); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - double nextVoltage = m_loop.getU(0); - m_motor.setVoltage(nextVoltage); + double nextVoltage = loop.getU(0); + motor.setVoltage(nextVoltage); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheelsysid/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheelsysid/Robot.java index 23e8d202b33..3c953ac15d4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheelsysid/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/statespaceflywheelsysid/Robot.java @@ -42,74 +42,74 @@ public class Robot extends TimedRobot { // Outputs (what we can measure): [velocity], in radians per second. // // The Kv and Ka constants are found using the FRC Characterization toolsuite. - private final LinearSystem m_flywheelPlant = + private final LinearSystem flywheelPlant = Models.flywheelFromSysId(kFlywheelKv, kFlywheelKa); // The observer fuses our encoder data and voltage inputs to reject noise. - private final KalmanFilter m_observer = + private final KalmanFilter observer = new KalmanFilter<>( Nat.N1(), Nat.N1(), - m_flywheelPlant, + flywheelPlant, VecBuilder.fill(3.0), // How accurate we think our model is VecBuilder.fill(0.01), // How accurate we think our encoder // data is 0.020); // A LQR uses feedback to create voltage commands. - private final LinearQuadraticRegulator m_controller = + private final LinearQuadraticRegulator controller = new LinearQuadraticRegulator<>( - m_flywheelPlant, + flywheelPlant, VecBuilder.fill(8.0), // Velocity error tolerance VecBuilder.fill(12.0), // Control effort (voltage) tolerance 0.020); // The state-space loop combines a controller, observer, feedforward and plant for easy control. - private final LinearSystemLoop m_loop = - new LinearSystemLoop<>(m_flywheelPlant, m_controller, m_observer, 12.0, 0.020); + private final LinearSystemLoop loop = + new LinearSystemLoop<>(flywheelPlant, controller, observer, 12.0, 0.020); // An encoder set up to measure flywheel velocity in radians per second. - private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); + private final Encoder encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final PWMSparkMax m_motor = new PWMSparkMax(kMotorPort); + private final PWMSparkMax motor = new PWMSparkMax(kMotorPort); // A joystick to read the trigger from. - private final Joystick m_joystick = new Joystick(kJoystickPort); + private final Joystick joystick = new Joystick(kJoystickPort); public Robot() { // We go 2 pi radians per 4096 clicks. - m_encoder.setDistancePerPulse(2.0 * Math.PI / 4096.0); + encoder.setDistancePerPulse(2.0 * Math.PI / 4096.0); } @Override public void teleopInit() { // Reset our loop to make sure it's in a known state. - m_loop.reset(VecBuilder.fill(m_encoder.getRate())); + loop.reset(VecBuilder.fill(encoder.getRate())); } @Override public void teleopPeriodic() { // Sets the target velocity of our flywheel. This is similar to setting the setpoint of a // PID controller. - if (m_joystick.getTriggerPressed()) { + if (joystick.getTriggerPressed()) { // We just pressed the trigger, so let's set our next reference - m_loop.setNextR(VecBuilder.fill(kSpinupRadPerSec)); - } else if (m_joystick.getTriggerReleased()) { + loop.setNextR(VecBuilder.fill(kSpinupRadPerSec)); + } else if (joystick.getTriggerReleased()) { // We just released the trigger, so let's spin down - m_loop.setNextR(VecBuilder.fill(0.0)); + loop.setNextR(VecBuilder.fill(0.0)); } // Correct our Kalman filter's state vector estimate with encoder data. - m_loop.correct(VecBuilder.fill(m_encoder.getRate())); + loop.correct(VecBuilder.fill(encoder.getRate())); // Update our LQR to generate new voltage commands and use the voltages to predict the next // state with out Kalman filter. - m_loop.predict(0.020); + loop.predict(0.020); // Send the new calculated voltage to the motors. // voltage = duty cycle * battery voltage, so // duty cycle = voltage / battery voltage - double nextVoltage = m_loop.getU(0); - m_motor.setVoltage(nextVoltage); + double nextVoltage = loop.getU(0); + motor.setVoltage(nextVoltage); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Drivetrain.java index 4c0d28d03e7..50738dea9b3 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Drivetrain.java @@ -16,35 +16,35 @@ public class Drivetrain { public static final double kMaxVelocity = 3.0; // 3 meters per second public static final double kMaxAngularVelocity = Math.PI; // 1/2 rotation per second - private final Translation2d m_frontLeftLocation = new Translation2d(0.381, 0.381); - private final Translation2d m_frontRightLocation = new Translation2d(0.381, -0.381); - private final Translation2d m_backLeftLocation = new Translation2d(-0.381, 0.381); - private final Translation2d m_backRightLocation = new Translation2d(-0.381, -0.381); + private final Translation2d frontLeftLocation = new Translation2d(0.381, 0.381); + private final Translation2d frontRightLocation = new Translation2d(0.381, -0.381); + private final Translation2d backLeftLocation = new Translation2d(-0.381, 0.381); + private final Translation2d backRightLocation = new Translation2d(-0.381, -0.381); - private final SwerveModule m_frontLeft = new SwerveModule(1, 2, 0, 1, 2, 3); - private final SwerveModule m_frontRight = new SwerveModule(3, 4, 4, 5, 6, 7); - private final SwerveModule m_backLeft = new SwerveModule(5, 6, 8, 9, 10, 11); - private final SwerveModule m_backRight = new SwerveModule(7, 8, 12, 13, 14, 15); + private final SwerveModule frontLeft = new SwerveModule(1, 2, 0, 1, 2, 3); + private final SwerveModule frontRight = new SwerveModule(3, 4, 4, 5, 6, 7); + private final SwerveModule backLeft = new SwerveModule(5, 6, 8, 9, 10, 11); + private final SwerveModule backRight = new SwerveModule(7, 8, 12, 13, 14, 15); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final SwerveDriveKinematics m_kinematics = + private final SwerveDriveKinematics kinematics = new SwerveDriveKinematics( - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation); + frontLeftLocation, frontRightLocation, backLeftLocation, backRightLocation); - private final SwerveDriveOdometry m_odometry = + private final SwerveDriveOdometry odometry = new SwerveDriveOdometry( - m_kinematics, - m_imu.getRotation2d(), + kinematics, + imu.getRotation2d(), new SwerveModulePosition[] { - m_frontLeft.getPosition(), - m_frontRight.getPosition(), - m_backLeft.getPosition(), - m_backRight.getPosition() + frontLeft.getPosition(), + frontRight.getPosition(), + backLeft.getPosition(), + backRight.getPosition() }); public Drivetrain() { - m_imu.resetYaw(); + imu.resetYaw(); } /** @@ -59,29 +59,29 @@ public void drive( double xVelocity, double yVelocity, double rot, boolean fieldRelative, double period) { var chassisVelocities = new ChassisVelocities(xVelocity, yVelocity, rot); if (fieldRelative) { - chassisVelocities = chassisVelocities.toRobotRelative(m_imu.getRotation2d()); + chassisVelocities = chassisVelocities.toRobotRelative(imu.getRotation2d()); } chassisVelocities = chassisVelocities.discretize(period); var velocities = SwerveDriveKinematics.desaturateWheelVelocities( - m_kinematics.toWheelVelocities(chassisVelocities), kMaxVelocity); + kinematics.toWheelVelocities(chassisVelocities), kMaxVelocity); - m_frontLeft.setDesiredVelocity(velocities[0]); - m_frontRight.setDesiredVelocity(velocities[1]); - m_backLeft.setDesiredVelocity(velocities[2]); - m_backRight.setDesiredVelocity(velocities[3]); + frontLeft.setDesiredVelocity(velocities[0]); + frontRight.setDesiredVelocity(velocities[1]); + backLeft.setDesiredVelocity(velocities[2]); + backRight.setDesiredVelocity(velocities[3]); } /** Updates the field relative position of the robot. */ public void updateOdometry() { - m_odometry.update( - m_imu.getRotation2d(), + odometry.update( + imu.getRotation2d(), new SwerveModulePosition[] { - m_frontLeft.getPosition(), - m_frontRight.getPosition(), - m_backLeft.getPosition(), - m_backRight.getPosition() + frontLeft.getPosition(), + frontRight.getPosition(), + backLeft.getPosition(), + backRight.getPosition() }); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Robot.java index 623fafcfd3a..7cdd0f9d050 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/Robot.java @@ -10,18 +10,18 @@ import org.wpilib.math.util.MathUtil; public class Robot extends TimedRobot { - private final Gamepad m_controller = new Gamepad(0); - private final Drivetrain m_swerve = new Drivetrain(); + private final Gamepad controller = new Gamepad(0); + private final Drivetrain swerve = new Drivetrain(); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 to 1. - private final SlewRateLimiter m_xVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_yVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter xVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter yVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); @Override public void autonomousPeriodic() { driveWithJoystick(false); - m_swerve.updateOdometry(); + swerve.updateOdometry(); } @Override @@ -33,14 +33,14 @@ private void driveWithJoystick(boolean fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. final var xVelocity = - -m_xVelocityLimiter.calculate(MathUtil.applyDeadband(m_controller.getLeftY(), 0.02)) + -xVelocityLimiter.calculate(MathUtil.applyDeadband(controller.getLeftY(), 0.02)) * Drivetrain.kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this because // we want a positive value when we pull to the left. Xbox controllers // return positive values when you pull to the right by default. final var yVelocity = - -m_yVelocityLimiter.calculate(MathUtil.applyDeadband(m_controller.getLeftX(), 0.02)) + -yVelocityLimiter.calculate(MathUtil.applyDeadband(controller.getLeftX(), 0.02)) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a @@ -48,9 +48,9 @@ private void driveWithJoystick(boolean fieldRelative) { // mathematics). Xbox controllers return positive values when you pull to // the right by default. final var rot = - -m_rotLimiter.calculate(MathUtil.applyDeadband(m_controller.getRightX(), 0.02)) + -rotLimiter.calculate(MathUtil.applyDeadband(controller.getRightX(), 0.02)) * Drivetrain.kMaxAngularVelocity; - m_swerve.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); + swerve.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/SwerveModule.java b/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/SwerveModule.java index bcf68dc27ff..ec876187e06 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/SwerveModule.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/swervebot/SwerveModule.java @@ -22,17 +22,17 @@ public class SwerveModule { private static final double kModuleMaxAngularAcceleration = 2 * Math.PI; // radians per second squared - private final PWMSparkMax m_driveMotor; - private final PWMSparkMax m_turningMotor; + private final PWMSparkMax driveMotor; + private final PWMSparkMax turningMotor; - private final Encoder m_driveEncoder; - private final Encoder m_turningEncoder; + private final Encoder driveEncoder; + private final Encoder turningEncoder; // Gains are for example purposes only - must be determined for your own robot! - private final PIDController m_drivePIDController = new PIDController(1, 0, 0); + private final PIDController drivePIDController = new PIDController(1, 0, 0); // Gains are for example purposes only - must be determined for your own robot! - private final ProfiledPIDController m_turningPIDController = + private final ProfiledPIDController turningPIDController = new ProfiledPIDController( 1, 0, @@ -41,8 +41,8 @@ public class SwerveModule { kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration)); // Gains are for example purposes only - must be determined for your own robot! - private final SimpleMotorFeedforward m_driveFeedforward = new SimpleMotorFeedforward(1, 3); - private final SimpleMotorFeedforward m_turnFeedforward = new SimpleMotorFeedforward(1, 0.5); + private final SimpleMotorFeedforward driveFeedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward turnFeedforward = new SimpleMotorFeedforward(1, 0.5); /** * Constructs a SwerveModule with a drive motor, turning motor, drive encoder and turning encoder. @@ -61,25 +61,25 @@ public SwerveModule( int driveEncoderChannelB, int turningEncoderChannelA, int turningEncoderChannelB) { - m_driveMotor = new PWMSparkMax(driveMotorChannel); - m_turningMotor = new PWMSparkMax(turningMotorChannel); + driveMotor = new PWMSparkMax(driveMotorChannel); + turningMotor = new PWMSparkMax(turningMotorChannel); - m_driveEncoder = new Encoder(driveEncoderChannelA, driveEncoderChannelB); - m_turningEncoder = new Encoder(turningEncoderChannelA, turningEncoderChannelB); + driveEncoder = new Encoder(driveEncoderChannelA, driveEncoderChannelB); + turningEncoder = new Encoder(turningEncoderChannelA, turningEncoderChannelB); // Set the distance per pulse for the drive encoder. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_driveEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + driveEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); // Set the distance (in this case, angle) in radians per pulse for the turning encoder. // This is the the angle through an entire rotation (2 * pi) divided by the // encoder resolution. - m_turningEncoder.setDistancePerPulse(2 * Math.PI / kEncoderResolution); + turningEncoder.setDistancePerPulse(2 * Math.PI / kEncoderResolution); // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. - m_turningPIDController.enableContinuousInput(-Math.PI, Math.PI); + turningPIDController.enableContinuousInput(-Math.PI, Math.PI); } /** @@ -89,7 +89,7 @@ public SwerveModule( */ public SwerveModulePosition getPosition() { return new SwerveModulePosition( - m_driveEncoder.getDistance(), new Rotation2d(m_turningEncoder.getDistance())); + driveEncoder.getDistance(), new Rotation2d(turningEncoder.getDistance())); } /** @@ -99,7 +99,7 @@ public SwerveModulePosition getPosition() { */ public SwerveModuleVelocity getVelocity() { return new SwerveModuleVelocity( - m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.getDistance())); + driveEncoder.getRate(), new Rotation2d(turningEncoder.getDistance())); } /** @@ -108,7 +108,7 @@ public SwerveModuleVelocity getVelocity() { * @param desiredVelocity Desired velocity. */ public void setDesiredVelocity(SwerveModuleVelocity desiredVelocity) { - var encoderRotation = new Rotation2d(m_turningEncoder.getDistance()); + var encoderRotation = new Rotation2d(turningEncoder.getDistance()); // Optimize the desired velocity to avoid spinning further than 90 degrees, then scale velocity // by cosine of angle error. This scales down movement perpendicular to the desired direction of @@ -116,22 +116,18 @@ public void setDesiredVelocity(SwerveModuleVelocity desiredVelocity) { SwerveModuleVelocity velocity = desiredVelocity.optimize(encoderRotation).cosineScale(encoderRotation); - // Calculate the drive output from the drive PID controller. + // Calculate the drive output from the drive PID controller and feedforward. final double driveOutput = - m_drivePIDController.calculate(m_driveEncoder.getRate(), velocity.velocity); + drivePIDController.calculate(driveEncoder.getRate(), velocity.velocity) + + driveFeedforward.calculate(desiredVelocity.velocity); - final double driveFeedforward = m_driveFeedforward.calculate(velocity.velocity); - - // Calculate the turning motor output from the turning PID controller. + // Calculate the turning motor output from the turning PID controller and feedforward. final double turnOutput = - m_turningPIDController.calculate( - m_turningEncoder.getDistance(), velocity.angle.getRadians()); - - final double turnFeedforward = - m_turnFeedforward.calculate(m_turningPIDController.getSetpoint().velocity); + turningPIDController.calculate(turningEncoder.getDistance(), velocity.angle.getRadians()) + + turnFeedforward.calculate(turningPIDController.getSetpoint().velocity); - m_driveMotor.setVoltage(driveOutput + driveFeedforward); - m_turningMotor.setVoltage(turnOutput + turnFeedforward); + driveMotor.setVoltage(driveOutput); + turningMotor.setVoltage(turnOutput); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Drivetrain.java index bceaeb58ca5..3ecafaef46f 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Drivetrain.java @@ -20,40 +20,40 @@ public class Drivetrain { public static final double kMaxVelocity = 3.0; // 3 meters per second public static final double kMaxAngularVelocity = Math.PI; // 1/2 rotation per second - private final Translation2d m_frontLeftLocation = new Translation2d(0.381, 0.381); - private final Translation2d m_frontRightLocation = new Translation2d(0.381, -0.381); - private final Translation2d m_backLeftLocation = new Translation2d(-0.381, 0.381); - private final Translation2d m_backRightLocation = new Translation2d(-0.381, -0.381); + private final Translation2d frontLeftLocation = new Translation2d(0.381, 0.381); + private final Translation2d frontRightLocation = new Translation2d(0.381, -0.381); + private final Translation2d backLeftLocation = new Translation2d(-0.381, 0.381); + private final Translation2d backRightLocation = new Translation2d(-0.381, -0.381); - private final SwerveModule m_frontLeft = new SwerveModule(1, 2, 0, 1, 2, 3); - private final SwerveModule m_frontRight = new SwerveModule(3, 4, 4, 5, 6, 7); - private final SwerveModule m_backLeft = new SwerveModule(5, 6, 8, 9, 10, 11); - private final SwerveModule m_backRight = new SwerveModule(7, 8, 12, 13, 14, 15); + private final SwerveModule frontLeft = new SwerveModule(1, 2, 0, 1, 2, 3); + private final SwerveModule frontRight = new SwerveModule(3, 4, 4, 5, 6, 7); + private final SwerveModule backLeft = new SwerveModule(5, 6, 8, 9, 10, 11); + private final SwerveModule backRight = new SwerveModule(7, 8, 12, 13, 14, 15); - private final OnboardIMU m_imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); + private final OnboardIMU imu = new OnboardIMU(OnboardIMU.MountOrientation.FLAT); - private final SwerveDriveKinematics m_kinematics = + private final SwerveDriveKinematics kinematics = new SwerveDriveKinematics( - m_frontLeftLocation, m_frontRightLocation, m_backLeftLocation, m_backRightLocation); + frontLeftLocation, frontRightLocation, backLeftLocation, backRightLocation); /* Here we use SwerveDrivePoseEstimator so that we can fuse odometry readings. The numbers used below are robot specific, and should be tuned. */ - private final SwerveDrivePoseEstimator m_poseEstimator = + private final SwerveDrivePoseEstimator poseEstimator = new SwerveDrivePoseEstimator( - m_kinematics, - m_imu.getRotation2d(), + kinematics, + imu.getRotation2d(), new SwerveModulePosition[] { - m_frontLeft.getPosition(), - m_frontRight.getPosition(), - m_backLeft.getPosition(), - m_backRight.getPosition() + frontLeft.getPosition(), + frontRight.getPosition(), + backLeft.getPosition(), + backRight.getPosition() }, Pose2d.kZero, VecBuilder.fill(0.05, 0.05, Units.degreesToRadians(5)), VecBuilder.fill(0.5, 0.5, Units.degreesToRadians(30))); public Drivetrain() { - m_imu.resetYaw(); + imu.resetYaw(); } /** @@ -69,37 +69,36 @@ public void drive( var chassisVelocities = new ChassisVelocities(xVelocity, yVelocity, rot); if (fieldRelative) { chassisVelocities = - chassisVelocities.toRobotRelative(m_poseEstimator.getEstimatedPosition().getRotation()); + chassisVelocities.toRobotRelative(poseEstimator.getEstimatedPosition().getRotation()); } chassisVelocities = chassisVelocities.discretize(period); var velocities = SwerveDriveKinematics.desaturateWheelVelocities( - m_kinematics.toWheelVelocities(chassisVelocities), kMaxVelocity); + kinematics.toWheelVelocities(chassisVelocities), kMaxVelocity); - m_frontLeft.setDesiredVelocity(velocities[0]); - m_frontRight.setDesiredVelocity(velocities[1]); - m_backLeft.setDesiredVelocity(velocities[2]); - m_backRight.setDesiredVelocity(velocities[3]); + frontLeft.setDesiredVelocity(velocities[0]); + frontRight.setDesiredVelocity(velocities[1]); + backLeft.setDesiredVelocity(velocities[2]); + backRight.setDesiredVelocity(velocities[3]); } /** Updates the field relative position of the robot. */ public void updateOdometry() { - m_poseEstimator.update( - m_imu.getRotation2d(), + poseEstimator.update( + imu.getRotation2d(), new SwerveModulePosition[] { - m_frontLeft.getPosition(), - m_frontRight.getPosition(), - m_backLeft.getPosition(), - m_backRight.getPosition() + frontLeft.getPosition(), + frontRight.getPosition(), + backLeft.getPosition(), + backRight.getPosition() }); // Also apply vision measurements. We use 0.3 seconds in the past as an example -- on // a real robot, this must be calculated based either on latency or timestamps. - m_poseEstimator.addVisionMeasurement( - ExampleGlobalMeasurementSensor.getEstimatedGlobalPose( - m_poseEstimator.getEstimatedPosition()), + poseEstimator.addVisionMeasurement( + ExampleGlobalMeasurementSensor.getEstimatedGlobalPose(poseEstimator.getEstimatedPosition()), Timer.getTimestamp() - 0.3); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Robot.java index bf8f9a79e4f..560833a49fc 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/Robot.java @@ -9,18 +9,18 @@ import org.wpilib.math.filter.SlewRateLimiter; public class Robot extends TimedRobot { - private final Gamepad m_controller = new Gamepad(0); - private final Drivetrain m_swerve = new Drivetrain(); + private final Gamepad controller = new Gamepad(0); + private final Drivetrain swerve = new Drivetrain(); // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 to 1. - private final SlewRateLimiter m_xVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_yVelocityLimiter = new SlewRateLimiter(3); - private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter xVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter yVelocityLimiter = new SlewRateLimiter(3); + private final SlewRateLimiter rotLimiter = new SlewRateLimiter(3); @Override public void autonomousPeriodic() { driveWithJoystick(false); - m_swerve.updateOdometry(); + swerve.updateOdometry(); } @Override @@ -32,21 +32,20 @@ private void driveWithJoystick(boolean fieldRelative) { // Get the x velocity. We are inverting this because gamepads return // negative values when we push forward. final var xVelocity = - -m_xVelocityLimiter.calculate(m_controller.getLeftY()) * Drivetrain.kMaxVelocity; + -xVelocityLimiter.calculate(controller.getLeftY()) * Drivetrain.kMaxVelocity; // Get the y velocity or sideways/strafe velocity. We are inverting this because // we want a positive value when we pull to the left. Gamepads // return positive values when you pull to the right by default. final var yVelocity = - -m_yVelocityLimiter.calculate(m_controller.getLeftX()) * Drivetrain.kMaxVelocity; + -yVelocityLimiter.calculate(controller.getLeftX()) * Drivetrain.kMaxVelocity; // Get the rate of angular rotation. We are inverting this because we want a // positive value when we pull to the left (remember, CCW is positive in // mathematics). Gamepads return positive values when you pull to // the right by default. - final var rot = - -m_rotLimiter.calculate(m_controller.getRightX()) * Drivetrain.kMaxAngularVelocity; + final var rot = -rotLimiter.calculate(controller.getRightX()) * Drivetrain.kMaxAngularVelocity; - m_swerve.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); + swerve.drive(xVelocity, yVelocity, rot, fieldRelative, getPeriod()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/SwerveModule.java b/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/SwerveModule.java index 2b4df5008eb..f0bb36c43eb 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/SwerveModule.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/swervedriveposeestimator/SwerveModule.java @@ -22,17 +22,17 @@ public class SwerveModule { private static final double kModuleMaxAngularAcceleration = 2 * Math.PI; // radians per second squared - private final PWMSparkMax m_driveMotor; - private final PWMSparkMax m_turningMotor; + private final PWMSparkMax driveMotor; + private final PWMSparkMax turningMotor; - private final Encoder m_driveEncoder; - private final Encoder m_turningEncoder; + private final Encoder driveEncoder; + private final Encoder turningEncoder; // Gains are for example purposes only - must be determined for your own robot! - private final PIDController m_drivePIDController = new PIDController(1, 0, 0); + private final PIDController drivePIDController = new PIDController(1, 0, 0); // Gains are for example purposes only - must be determined for your own robot! - private final ProfiledPIDController m_turningPIDController = + private final ProfiledPIDController turningPIDController = new ProfiledPIDController( 1, 0, @@ -41,8 +41,8 @@ public class SwerveModule { kModuleMaxAngularVelocity, kModuleMaxAngularAcceleration)); // Gains are for example purposes only - must be determined for your own robot! - private final SimpleMotorFeedforward m_driveFeedforward = new SimpleMotorFeedforward(1, 3); - private final SimpleMotorFeedforward m_turnFeedforward = new SimpleMotorFeedforward(1, 0.5); + private final SimpleMotorFeedforward driveFeedforward = new SimpleMotorFeedforward(1, 3); + private final SimpleMotorFeedforward turnFeedforward = new SimpleMotorFeedforward(1, 0.5); /** * Constructs a SwerveModule with a drive motor, turning motor, drive encoder and turning encoder. @@ -61,25 +61,25 @@ public SwerveModule( int driveEncoderChannelB, int turningEncoderChannelA, int turningEncoderChannelB) { - m_driveMotor = new PWMSparkMax(driveMotorChannel); - m_turningMotor = new PWMSparkMax(turningMotorChannel); + driveMotor = new PWMSparkMax(driveMotorChannel); + turningMotor = new PWMSparkMax(turningMotorChannel); - m_driveEncoder = new Encoder(driveEncoderChannelA, driveEncoderChannelB); - m_turningEncoder = new Encoder(turningEncoderChannelA, turningEncoderChannelB); + driveEncoder = new Encoder(driveEncoderChannelA, driveEncoderChannelB); + turningEncoder = new Encoder(turningEncoderChannelA, turningEncoderChannelB); // Set the distance per pulse for the drive encoder. We can simply use the // distance traveled for one rotation of the wheel divided by the encoder // resolution. - m_driveEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); + driveEncoder.setDistancePerPulse(2 * Math.PI * kWheelRadius / kEncoderResolution); // Set the distance (in this case, angle) in radians per pulse for the turning encoder. // This is the the angle through an entire rotation (2 * pi) divided by the // encoder resolution. - m_turningEncoder.setDistancePerPulse(2 * Math.PI / kEncoderResolution); + turningEncoder.setDistancePerPulse(2 * Math.PI / kEncoderResolution); // Limit the PID Controller's input range between -pi and pi and set the input // to be continuous. - m_turningPIDController.enableContinuousInput(-Math.PI, Math.PI); + turningPIDController.enableContinuousInput(-Math.PI, Math.PI); } /** @@ -89,7 +89,7 @@ public SwerveModule( */ public SwerveModuleVelocity getState() { return new SwerveModuleVelocity( - m_driveEncoder.getRate(), new Rotation2d(m_turningEncoder.getDistance())); + driveEncoder.getRate(), new Rotation2d(turningEncoder.getDistance())); } /** @@ -99,7 +99,7 @@ public SwerveModuleVelocity getState() { */ public SwerveModulePosition getPosition() { return new SwerveModulePosition( - m_driveEncoder.getDistance(), new Rotation2d(m_turningEncoder.getDistance())); + driveEncoder.getDistance(), new Rotation2d(turningEncoder.getDistance())); } /** @@ -108,7 +108,7 @@ public SwerveModulePosition getPosition() { * @param desiredVelocity Desired velocity. */ public void setDesiredVelocity(SwerveModuleVelocity desiredVelocity) { - var encoderRotation = new Rotation2d(m_turningEncoder.getDistance()); + var encoderRotation = new Rotation2d(turningEncoder.getDistance()); // Optimize the desired velocity to avoid spinning further than 90 degrees, then scale velocity // by cosine of angle error. This scales down movement perpendicular to the desired direction of @@ -116,21 +116,17 @@ public void setDesiredVelocity(SwerveModuleVelocity desiredVelocity) { SwerveModuleVelocity velocity = desiredVelocity.optimize(encoderRotation).cosineScale(encoderRotation); - // Calculate the drive output from the drive PID controller. + // Calculate the drive output from the drive PID controller and feedforward. final double driveOutput = - m_drivePIDController.calculate(m_driveEncoder.getRate(), velocity.velocity); + drivePIDController.calculate(driveEncoder.getRate(), velocity.velocity) + + driveFeedforward.calculate(desiredVelocity.velocity); - final double driveFeedforward = m_driveFeedforward.calculate(velocity.velocity); - - // Calculate the turning motor output from the turning PID controller. + // Calculate the turning motor output from the turning PID controller and feedforward. final double turnOutput = - m_turningPIDController.calculate( - m_turningEncoder.getDistance(), velocity.angle.getRadians()); - - final double turnFeedforward = - m_turnFeedforward.calculate(m_turningPIDController.getSetpoint().velocity); + turningPIDController.calculate(turningEncoder.getDistance(), velocity.angle.getRadians()) + + turnFeedforward.calculate(turningPIDController.getSetpoint().velocity); - m_driveMotor.setVoltage(driveOutput + driveFeedforward); - m_turningMotor.setVoltage(turnOutput + turnFeedforward); + driveMotor.setVoltage(driveOutput); + turningMotor.setVoltage(turnOutput); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/Robot.java index 161c0b0d1c0..484daf35517 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final SysIdRoutineBot m_robot = new SysIdRoutineBot(); + private final SysIdRoutineBot robot = new SysIdRoutineBot(); /** * This function is run when the robot is first started up and should be used for any @@ -24,7 +24,7 @@ public class Robot extends TimedRobot { */ public Robot() { // Configure default commands and condition bindings on robot startup - m_robot.configureBindings(); + robot.configureBindings(); } /** @@ -52,10 +52,10 @@ public void disabledPeriodic() {} @Override public void autonomousInit() { - m_autonomousCommand = m_robot.getAutonomousCommand(); + autonomousCommand = robot.getAutonomousCommand(); - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -69,8 +69,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/SysIdRoutineBot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/SysIdRoutineBot.java index 04a623c6195..4bd489ef21c 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/SysIdRoutineBot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/SysIdRoutineBot.java @@ -20,11 +20,11 @@ */ public class SysIdRoutineBot { // The robot's subsystems - private final Drive m_drive = new Drive(); - private final Shooter m_shooter = new Shooter(); + private final Drive drive = new Drive(); + private final Shooter shooter = new Shooter(); // The driver's controller - CommandGamepad m_driverController = new CommandGamepad(OIConstants.kDriverControllerPort); + CommandGamepad driverController = new CommandGamepad(OIConstants.kDriverControllerPort); /** * Use this method to define bindings between conditions and commands. These are useful for @@ -36,50 +36,50 @@ public class SysIdRoutineBot { */ public void configureBindings() { // Control the drive with split-stick arcade controls - m_drive.setDefaultCommand( - m_drive.arcadeDriveCommand( - () -> -m_driverController.getLeftY(), () -> -m_driverController.getRightX())); + drive.setDefaultCommand( + drive.arcadeDriveCommand( + () -> -driverController.getLeftY(), () -> -driverController.getRightX())); // Bind full set of SysId routine tests to buttons; a complete routine should run each of these // once. // Using bumpers as a modifier and combining it with the buttons so that we can have both sets // of bindings at once - m_driverController + driverController .southFace() - .and(m_driverController.rightBumper()) - .whileTrue(m_drive.sysIdQuasistatic(SysIdRoutine.Direction.kForward)); - m_driverController + .and(driverController.rightBumper()) + .whileTrue(drive.sysIdQuasistatic(SysIdRoutine.Direction.kForward)); + driverController .eastFace() - .and(m_driverController.rightBumper()) - .whileTrue(m_drive.sysIdQuasistatic(SysIdRoutine.Direction.kReverse)); - m_driverController + .and(driverController.rightBumper()) + .whileTrue(drive.sysIdQuasistatic(SysIdRoutine.Direction.kReverse)); + driverController .westFace() - .and(m_driverController.rightBumper()) - .whileTrue(m_drive.sysIdDynamic(SysIdRoutine.Direction.kForward)); - m_driverController + .and(driverController.rightBumper()) + .whileTrue(drive.sysIdDynamic(SysIdRoutine.Direction.kForward)); + driverController .northFace() - .and(m_driverController.rightBumper()) - .whileTrue(m_drive.sysIdDynamic(SysIdRoutine.Direction.kReverse)); + .and(driverController.rightBumper()) + .whileTrue(drive.sysIdDynamic(SysIdRoutine.Direction.kReverse)); // Control the shooter wheel with the left trigger - m_shooter.setDefaultCommand(m_shooter.runShooter(m_driverController::getLeftTriggerAxis)); + shooter.setDefaultCommand(shooter.runShooter(driverController::getLeftTriggerAxis)); - m_driverController + driverController .southFace() - .and(m_driverController.leftBumper()) - .whileTrue(m_shooter.sysIdQuasistatic(SysIdRoutine.Direction.kForward)); - m_driverController + .and(driverController.leftBumper()) + .whileTrue(shooter.sysIdQuasistatic(SysIdRoutine.Direction.kForward)); + driverController .eastFace() - .and(m_driverController.leftBumper()) - .whileTrue(m_shooter.sysIdQuasistatic(SysIdRoutine.Direction.kReverse)); - m_driverController + .and(driverController.leftBumper()) + .whileTrue(shooter.sysIdQuasistatic(SysIdRoutine.Direction.kReverse)); + driverController .westFace() - .and(m_driverController.leftBumper()) - .whileTrue(m_shooter.sysIdDynamic(SysIdRoutine.Direction.kForward)); - m_driverController + .and(driverController.leftBumper()) + .whileTrue(shooter.sysIdDynamic(SysIdRoutine.Direction.kForward)); + driverController .northFace() - .and(m_driverController.leftBumper()) - .whileTrue(m_shooter.sysIdDynamic(SysIdRoutine.Direction.kReverse)); + .and(driverController.leftBumper()) + .whileTrue(shooter.sysIdDynamic(SysIdRoutine.Direction.kReverse)); } /** @@ -89,6 +89,6 @@ public void configureBindings() { */ public Command getAutonomousCommand() { // Do nothing - return m_drive.run(() -> {}); + return drive.run(() -> {}); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Drive.java b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Drive.java index 58804fc6f71..e248b5799ca 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Drive.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Drive.java @@ -20,39 +20,39 @@ public class Drive extends SubsystemBase { // The motors on the left side of the drive. - private final PWMSparkMax m_leftMotor = new PWMSparkMax(DriveConstants.kLeftMotor1Port); + private final PWMSparkMax leftMotor = new PWMSparkMax(DriveConstants.kLeftMotor1Port); // The motors on the right side of the drive. - private final PWMSparkMax m_rightMotor = new PWMSparkMax(DriveConstants.kRightMotor1Port); + private final PWMSparkMax rightMotor = new PWMSparkMax(DriveConstants.kRightMotor1Port); // The robot's drive - private final DifferentialDrive m_drive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive drive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); // The left-side drive encoder - private final Encoder m_leftEncoder = + private final Encoder leftEncoder = new Encoder( DriveConstants.kLeftEncoderPorts[0], DriveConstants.kLeftEncoderPorts[1], DriveConstants.kLeftEncoderReversed); // The right-side drive encoder - private final Encoder m_rightEncoder = + private final Encoder rightEncoder = new Encoder( DriveConstants.kRightEncoderPorts[0], DriveConstants.kRightEncoderPorts[1], DriveConstants.kRightEncoderReversed); // Create a new SysId routine for characterizing the drive. - private final SysIdRoutine m_sysIdRoutine = + private final SysIdRoutine sysIdRoutine = new SysIdRoutine( // Empty config defaults to 1 volt/second ramp rate and 7 volt step voltage. new SysIdRoutine.Config(), new SysIdRoutine.Mechanism( // Tell SysId how to plumb the driving voltage to the motors. voltage -> { - m_leftMotor.setVoltage(voltage); - m_rightMotor.setVoltage(voltage); + leftMotor.setVoltage(voltage); + rightMotor.setVoltage(voltage); }, // Tell SysId how to record a frame of data for each motor on the mechanism being // characterized. @@ -61,16 +61,16 @@ public class Drive extends SubsystemBase { // the entire group to be one motor. log.motor("drive-left") .voltage( - Volts.of(m_leftMotor.getThrottle() * RobotController.getBatteryVoltage())) - .linearPosition(Meters.of(m_leftEncoder.getDistance())) - .linearVelocity(MetersPerSecond.of(m_leftEncoder.getRate())); + Volts.of(leftMotor.getThrottle() * RobotController.getBatteryVoltage())) + .linearPosition(Meters.of(leftEncoder.getDistance())) + .linearVelocity(MetersPerSecond.of(leftEncoder.getRate())); // Record a frame for the right motors. Since these share an encoder, we consider // the entire group to be one motor. log.motor("drive-right") .voltage( - Volts.of(m_rightMotor.getThrottle() * RobotController.getBatteryVoltage())) - .linearPosition(Meters.of(m_rightEncoder.getDistance())) - .linearVelocity(MetersPerSecond.of(m_rightEncoder.getRate())); + Volts.of(rightMotor.getThrottle() * RobotController.getBatteryVoltage())) + .linearPosition(Meters.of(rightEncoder.getDistance())) + .linearVelocity(MetersPerSecond.of(rightEncoder.getRate())); }, // Tell SysId to make generated commands require this subsystem, suffix test state in // WPILog with this subsystem's name ("drive") @@ -79,17 +79,17 @@ public class Drive extends SubsystemBase { /** Creates a new Drive subsystem. */ public Drive() { // Add the second motors on each side of the drivetrain - m_leftMotor.addFollower(new PWMSparkMax(DriveConstants.kLeftMotor2Port)); - m_rightMotor.addFollower(new PWMSparkMax(DriveConstants.kRightMotor2Port)); + leftMotor.addFollower(new PWMSparkMax(DriveConstants.kLeftMotor2Port)); + rightMotor.addFollower(new PWMSparkMax(DriveConstants.kRightMotor2Port)); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); // Sets the distance per pulse for the encoders - m_leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); - m_rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + leftEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); + rightEncoder.setDistancePerPulse(DriveConstants.kEncoderDistancePerPulse); } /** @@ -101,7 +101,7 @@ public Drive() { public Command arcadeDriveCommand(DoubleSupplier fwd, DoubleSupplier rot) { // A split-stick arcade command, with forward/backward controlled by the left // hand, and turning controlled by the right. - return run(() -> m_drive.arcadeDrive(fwd.getAsDouble(), rot.getAsDouble())) + return run(() -> drive.arcadeDrive(fwd.getAsDouble(), rot.getAsDouble())) .withName("arcadeDrive"); } @@ -111,7 +111,7 @@ public Command arcadeDriveCommand(DoubleSupplier fwd, DoubleSupplier rot) { * @param direction The direction (forward or reverse) to run the test in */ public Command sysIdQuasistatic(SysIdRoutine.Direction direction) { - return m_sysIdRoutine.quasistatic(direction); + return sysIdRoutine.quasistatic(direction); } /** @@ -120,6 +120,6 @@ public Command sysIdQuasistatic(SysIdRoutine.Direction direction) { * @param direction The direction (forward or reverse) to run the test in */ public Command sysIdDynamic(SysIdRoutine.Direction direction) { - return m_sysIdRoutine.dynamic(direction); + return sysIdRoutine.dynamic(direction); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Shooter.java b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Shooter.java index 1c62532ece0..03782a9b320 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Shooter.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/sysidroutine/subsystems/Shooter.java @@ -21,52 +21,51 @@ public class Shooter extends SubsystemBase { // The motor on the shooter wheel . - private final PWMSparkMax m_shooterMotor = new PWMSparkMax(ShooterConstants.kShooterMotorPort); + private final PWMSparkMax shooterMotor = new PWMSparkMax(ShooterConstants.kShooterMotorPort); // The motor on the feeder wheels. - private final PWMSparkMax m_feederMotor = new PWMSparkMax(ShooterConstants.kFeederMotorPort); + private final PWMSparkMax feederMotor = new PWMSparkMax(ShooterConstants.kFeederMotorPort); // The shooter wheel encoder - private final Encoder m_shooterEncoder = + private final Encoder shooterEncoder = new Encoder( ShooterConstants.kEncoderPorts[0], ShooterConstants.kEncoderPorts[1], ShooterConstants.kEncoderReversed); // Create a new SysId routine for characterizing the shooter. - private final SysIdRoutine m_sysIdRoutine = + private final SysIdRoutine sysIdRoutine = new SysIdRoutine( // Empty config defaults to 1 volt/second ramp rate and 7 volt step voltage. new SysIdRoutine.Config(), new SysIdRoutine.Mechanism( // Tell SysId how to plumb the driving voltage to the motor(s). - m_shooterMotor::setVoltage, + shooterMotor::setVoltage, // Tell SysId how to record a frame of data for each motor on the mechanism being // characterized. log -> { // Record a frame for the shooter motor. log.motor("shooter-wheel") .voltage( - Volts.of( - m_shooterMotor.getThrottle() * RobotController.getBatteryVoltage())) - .angularPosition(Rotations.of(m_shooterEncoder.getDistance())) - .angularVelocity(RotationsPerSecond.of(m_shooterEncoder.getRate())); + Volts.of(shooterMotor.getThrottle() * RobotController.getBatteryVoltage())) + .angularPosition(Rotations.of(shooterEncoder.getDistance())) + .angularVelocity(RotationsPerSecond.of(shooterEncoder.getRate())); }, // Tell SysId to make generated commands require this subsystem, suffix test state in // WPILog with this subsystem's name ("shooter") this)); // PID controller to run the shooter wheel in closed-loop, set the constants equal to those // calculated by SysId - private final PIDController m_shooterFeedback = new PIDController(ShooterConstants.kP, 0, 0); + private final PIDController shooterFeedback = new PIDController(ShooterConstants.kP, 0, 0); // Feedforward controller to run the shooter wheel in closed-loop, set the constants equal to // those calculated by SysId - private final SimpleMotorFeedforward m_shooterFeedforward = + private final SimpleMotorFeedforward shooterFeedforward = new SimpleMotorFeedforward(ShooterConstants.kS, ShooterConstants.kV, ShooterConstants.kA); /** Creates a new Shooter subsystem. */ public Shooter() { // Sets the distance per pulse for the encoders - m_shooterEncoder.setDistancePerPulse(ShooterConstants.kEncoderDistancePerPulse); + shooterEncoder.setDistancePerPulse(ShooterConstants.kEncoderDistancePerPulse); } /** @@ -77,15 +76,15 @@ public Shooter() { public Command runShooter(DoubleSupplier shooterVelocity) { // Run shooter wheel at the desired velocity using a PID controller and feedforward. return run(() -> { - m_shooterMotor.setVoltage( - m_shooterFeedback.calculate(m_shooterEncoder.getRate(), shooterVelocity.getAsDouble()) - + m_shooterFeedforward.calculate(shooterVelocity.getAsDouble())); - m_feederMotor.setThrottle(ShooterConstants.kFeederVelocity); + shooterMotor.setVoltage( + shooterFeedback.calculate(shooterEncoder.getRate(), shooterVelocity.getAsDouble()) + + shooterFeedforward.calculate(shooterVelocity.getAsDouble())); + feederMotor.setThrottle(ShooterConstants.kFeederVelocity); }) .finallyDo( () -> { - m_shooterMotor.stopMotor(); - m_feederMotor.stopMotor(); + shooterMotor.stopMotor(); + feederMotor.stopMotor(); }) .withName("runShooter"); } @@ -96,7 +95,7 @@ public Command runShooter(DoubleSupplier shooterVelocity) { * @param direction The direction (forward or reverse) to run the test in */ public Command sysIdQuasistatic(SysIdRoutine.Direction direction) { - return m_sysIdRoutine.quasistatic(direction); + return sysIdRoutine.quasistatic(direction); } /** @@ -105,6 +104,6 @@ public Command sysIdQuasistatic(SysIdRoutine.Direction direction) { * @param direction The direction (forward or reverse) to run the test in */ public Command sysIdDynamic(SysIdRoutine.Direction direction) { - return m_sysIdRoutine.dynamic(direction); + return sysIdRoutine.dynamic(direction); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/tankdrivegamepad/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/tankdrivegamepad/Robot.java index ccb50c60794..bcae93bb68b 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/tankdrivegamepad/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/tankdrivegamepad/Robot.java @@ -15,21 +15,21 @@ * steering and a gamepad. */ public class Robot extends TimedRobot { - private final PWMSparkMax m_leftMotor = new PWMSparkMax(0); - private final PWMSparkMax m_rightMotor = new PWMSparkMax(1); - private final DifferentialDrive m_robotDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); - private final Gamepad m_driverController = new Gamepad(0); + private final PWMSparkMax leftMotor = new PWMSparkMax(0); + private final PWMSparkMax rightMotor = new PWMSparkMax(1); + private final DifferentialDrive robotDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); + private final Gamepad driverController = new Gamepad(0); /** Called once at the beginning of the robot program. */ public Robot() { - SendableRegistry.addChild(m_robotDrive, m_leftMotor); - SendableRegistry.addChild(m_robotDrive, m_rightMotor); + SendableRegistry.addChild(robotDrive, leftMotor); + SendableRegistry.addChild(robotDrive, rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } @Override @@ -38,6 +38,6 @@ public void teleopPeriodic() { // That means that the Y axis of the left stick moves the left side // of the robot forward and backward, and the Y axis of the right stick // moves the right side of the robot forward and backward. - m_robotDrive.tankDrive(-m_driverController.getLeftY(), -m_driverController.getRightY()); + robotDrive.tankDrive(-driverController.getLeftY(), -driverController.getRightY()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/Robot.java index e982965767b..c987c11e1a3 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/Robot.java @@ -15,25 +15,25 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private final Intake m_intake = new Intake(); - private final Joystick m_joystick = new Joystick(Constants.kJoystickIndex); + private final Intake intake = new Intake(); + private final Joystick joystick = new Joystick(Constants.kJoystickIndex); /** This function is called periodically during operator control. */ @Override public void teleopPeriodic() { // Activate the intake while the trigger is held - if (m_joystick.getTrigger()) { - m_intake.activate(IntakeConstants.kIntakeVelocity); + if (joystick.getTrigger()) { + intake.activate(IntakeConstants.kIntakeVelocity); } else { - m_intake.activate(0); + intake.activate(0); } // Toggle deploying the intake when the top button is pressed - if (m_joystick.getTop()) { - if (m_intake.isDeployed()) { - m_intake.retract(); + if (joystick.getTop()) { + if (intake.isDeployed()) { + intake.retract(); } else { - m_intake.deploy(); + intake.deploy(); } } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/subsystems/Intake.java b/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/subsystems/Intake.java index 5bb8bfcf581..34e79cb5419 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/subsystems/Intake.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/unittest/subsystems/Intake.java @@ -10,12 +10,12 @@ import org.wpilib.hardware.pneumatic.PneumaticsModuleType; public class Intake implements AutoCloseable { - private final PWMSparkMax m_motor; - private final DoubleSolenoid m_piston; + private final PWMSparkMax motor; + private final DoubleSolenoid piston; public Intake() { - m_motor = new PWMSparkMax(IntakeConstants.kMotorPort); - m_piston = + motor = new PWMSparkMax(IntakeConstants.kMotorPort); + piston = new DoubleSolenoid( 0, PneumaticsModuleType.CTRE_PCM, @@ -24,29 +24,29 @@ public Intake() { } public void deploy() { - m_piston.set(DoubleSolenoid.Value.FORWARD); + piston.set(DoubleSolenoid.Value.FORWARD); } public void retract() { - m_piston.set(DoubleSolenoid.Value.REVERSE); - m_motor.setThrottle(0); // turn off the motor + piston.set(DoubleSolenoid.Value.REVERSE); + motor.setThrottle(0); // turn off the motor } public void activate(double velocity) { if (isDeployed()) { - m_motor.setThrottle(velocity); + motor.setThrottle(velocity); } else { // if piston isn't open, do nothing - m_motor.setThrottle(0); + motor.setThrottle(0); } } public boolean isDeployed() { - return m_piston.get() == DoubleSolenoid.Value.FORWARD; + return piston.get() == DoubleSolenoid.Value.FORWARD; } @Override public void close() { - m_piston.close(); - m_motor.close(); + piston.close(); + motor.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/Robot.java index 312b0d8e89d..4a716352e41 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -25,7 +25,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,11 +54,11 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -72,8 +72,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/RobotContainer.java index ab3ef480df1..e7143bf1077 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/RobotContainer.java @@ -29,15 +29,15 @@ */ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final Drivetrain m_drivetrain = new Drivetrain(); - private final XRPOnBoardIO m_onboardIO = new XRPOnBoardIO(); - private final Arm m_arm = new Arm(); + private final Drivetrain drivetrain = new Drivetrain(); + private final XRPOnBoardIO onboardIO = new XRPOnBoardIO(); + private final Arm arm = new Arm(); // Assumes a gamepad plugged into channel 0 - private final Joystick m_controller = new Joystick(0); + private final Joystick controller = new Joystick(0); // Create SmartDashboard chooser for autonomous routines - private final SendableChooser m_chooser = new SendableChooser<>(); + private final SendableChooser chooser = new SendableChooser<>(); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { @@ -54,28 +54,28 @@ public RobotContainer() { private void configureButtonBindings() { // Default command is arcade drive. This will run unless another command // is scheduled over it. - m_drivetrain.setDefaultCommand(getArcadeDriveCommand()); + drivetrain.setDefaultCommand(getArcadeDriveCommand()); // Example of how to use the onboard IO - Trigger userButton = new Trigger(m_onboardIO::getUserButtonPressed); + Trigger userButton = new Trigger(onboardIO::getUserButtonPressed); userButton .onTrue(new PrintCommand("USER Button Pressed")) .onFalse(new PrintCommand("USER Button Released")); - JoystickButton joystickAButton = new JoystickButton(m_controller, 1); + JoystickButton joystickAButton = new JoystickButton(controller, 1); joystickAButton - .onTrue(new InstantCommand(() -> m_arm.setAngle(45.0), m_arm)) - .onFalse(new InstantCommand(() -> m_arm.setAngle(0.0), m_arm)); + .onTrue(new InstantCommand(() -> arm.setAngle(45.0), arm)) + .onFalse(new InstantCommand(() -> arm.setAngle(0.0), arm)); - JoystickButton joystickBButton = new JoystickButton(m_controller, 2); + JoystickButton joystickBButton = new JoystickButton(controller, 2); joystickBButton - .onTrue(new InstantCommand(() -> m_arm.setAngle(90.0), m_arm)) - .onFalse(new InstantCommand(() -> m_arm.setAngle(0.0), m_arm)); + .onTrue(new InstantCommand(() -> arm.setAngle(90.0), arm)) + .onFalse(new InstantCommand(() -> arm.setAngle(0.0), arm)); // Setup SmartDashboard options - m_chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(m_drivetrain)); - m_chooser.addOption("Auto Routine Time", new AutonomousTime(m_drivetrain)); - SmartDashboard.putData(m_chooser); + chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(drivetrain)); + chooser.addOption("Auto Routine Time", new AutonomousTime(drivetrain)); + SmartDashboard.putData(chooser); } /** @@ -84,7 +84,7 @@ private void configureButtonBindings() { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_chooser.getSelected(); + return chooser.getSelected(); } /** @@ -94,6 +94,6 @@ public Command getAutonomousCommand() { */ public Command getArcadeDriveCommand() { return new ArcadeDrive( - m_drivetrain, () -> -m_controller.getRawAxis(1), () -> -m_controller.getRawAxis(2)); + drivetrain, () -> -controller.getRawAxis(1), () -> -controller.getRawAxis(2)); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/ArcadeDrive.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/ArcadeDrive.java index 898f4e51873..4071ef68f78 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/ArcadeDrive.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/ArcadeDrive.java @@ -9,9 +9,9 @@ import org.wpilib.examples.xrpreference.subsystems.Drivetrain; public class ArcadeDrive extends Command { - private final Drivetrain m_drivetrain; - private final Supplier m_xaxisVelocitySupplier; - private final Supplier m_zaxisRotateSupplier; + private final Drivetrain drivetrain; + private final Supplier xaxisVelocitySupplier; + private final Supplier zaxisRotateSupplier; /** * Creates a new ArcadeDrive. This command will drive your robot according to the velocity @@ -25,9 +25,9 @@ public ArcadeDrive( Drivetrain drivetrain, Supplier xaxisVelocitySupplier, Supplier zaxisRotateSupplier) { - m_drivetrain = drivetrain; - m_xaxisVelocitySupplier = xaxisVelocitySupplier; - m_zaxisRotateSupplier = zaxisRotateSupplier; + this.drivetrain = drivetrain; + this.xaxisVelocitySupplier = xaxisVelocitySupplier; + this.zaxisRotateSupplier = zaxisRotateSupplier; addRequirements(drivetrain); } @@ -38,7 +38,7 @@ public void initialize() {} // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drivetrain.arcadeDrive(m_xaxisVelocitySupplier.get(), m_zaxisRotateSupplier.get()); + drivetrain.arcadeDrive(xaxisVelocitySupplier.get(), zaxisRotateSupplier.get()); } // Called once the command ends or is interrupted. diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveDistance.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveDistance.java index e8d5176b83a..0e98a0675d5 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveDistance.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveDistance.java @@ -8,9 +8,9 @@ import org.wpilib.examples.xrpreference.subsystems.Drivetrain; public class DriveDistance extends Command { - private final Drivetrain m_drive; - private final double m_distance; - private final double m_velocity; + private final Drivetrain drive; + private final double distance; + private final double velocity; /** * Creates a new DriveDistance. This command will drive your your robot for a desired distance at @@ -21,35 +21,35 @@ public class DriveDistance extends Command { * @param drive The drivetrain subsystem on which this command will run */ public DriveDistance(double velocity, double inches, Drivetrain drive) { - m_distance = inches; - m_velocity = velocity; - m_drive = drive; + distance = inches; + this.velocity = velocity; + this.drive = drive; addRequirements(drive); } // Called when the command is initially scheduled. @Override public void initialize() { - m_drive.arcadeDrive(0, 0); - m_drive.resetEncoders(); + drive.arcadeDrive(0, 0); + drive.resetEncoders(); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(m_velocity, 0); + drive.arcadeDrive(velocity, 0); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @Override public boolean isFinished() { // Compare distance travelled from start to desired distance - return Math.abs(m_drive.getAverageDistanceInch()) >= m_distance; + return Math.abs(drive.getAverageDistanceInch()) >= distance; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveTime.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveTime.java index bf59231b785..df8c82bfb82 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveTime.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/DriveTime.java @@ -8,10 +8,10 @@ import org.wpilib.examples.xrpreference.subsystems.Drivetrain; public class DriveTime extends Command { - private final double m_duration; - private final double m_velocity; - private final Drivetrain m_drive; - private long m_startTime; + private final double duration; + private final double velocity; + private final Drivetrain drive; + private long startTime; /** * Creates a new DriveTime. This command will drive your robot for a desired velocity and time. @@ -21,34 +21,34 @@ public class DriveTime extends Command { * @param drive The drivetrain subsystem on which this command will run */ public DriveTime(double velocity, double time, Drivetrain drive) { - m_velocity = velocity; - m_duration = time * 1000; - m_drive = drive; + this.velocity = velocity; + duration = time * 1000; + this.drive = drive; addRequirements(drive); } // Called when the command is initially scheduled. @Override public void initialize() { - m_startTime = System.currentTimeMillis(); - m_drive.arcadeDrive(0, 0); + startTime = System.currentTimeMillis(); + drive.arcadeDrive(0, 0); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(m_velocity, 0); + drive.arcadeDrive(velocity, 0); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @Override public boolean isFinished() { - return (System.currentTimeMillis() - m_startTime) >= m_duration; + return (System.currentTimeMillis() - startTime) >= duration; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnDegrees.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnDegrees.java index a08b2fa8b4e..6d76536b9d3 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnDegrees.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnDegrees.java @@ -8,9 +8,9 @@ import org.wpilib.examples.xrpreference.subsystems.Drivetrain; public class TurnDegrees extends Command { - private final Drivetrain m_drive; - private final double m_degrees; - private final double m_velocity; + private final Drivetrain drive; + private final double degrees; + private final double velocity; /** * Creates a new TurnDegrees. This command will turn your robot for a desired rotation (in @@ -21,9 +21,9 @@ public class TurnDegrees extends Command { * @param drive The drive subsystem on which this command will run */ public TurnDegrees(double velocity, double degrees, Drivetrain drive) { - m_degrees = degrees; - m_velocity = velocity; - m_drive = drive; + this.degrees = degrees; + this.velocity = velocity; + this.drive = drive; addRequirements(drive); } @@ -31,20 +31,20 @@ public TurnDegrees(double velocity, double degrees, Drivetrain drive) { @Override public void initialize() { // Set motors to stop, read encoder values for starting point - m_drive.arcadeDrive(0, 0); - m_drive.resetEncoders(); + drive.arcadeDrive(0, 0); + drive.resetEncoders(); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(0, m_velocity); + drive.arcadeDrive(0, velocity); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @@ -57,12 +57,12 @@ has a wheel placement diameter (163 mm) - width of the wheel (8 mm) = 155 mm */ double inchPerDegree = Math.PI * 6.102 / 360; // Compare distance travelled from start to distance based on degree turn - return getAverageTurningDistance() >= (inchPerDegree * m_degrees); + return getAverageTurningDistance() >= (inchPerDegree * degrees); } private double getAverageTurningDistance() { - double leftDistance = Math.abs(m_drive.getLeftDistanceInch()); - double rightDistance = Math.abs(m_drive.getRightDistanceInch()); + double leftDistance = Math.abs(drive.getLeftDistanceInch()); + double rightDistance = Math.abs(drive.getRightDistanceInch()); return (leftDistance + rightDistance) / 2.0; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnTime.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnTime.java index b12c0d7f2f4..39629fc30d2 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnTime.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/commands/TurnTime.java @@ -12,10 +12,10 @@ * desired rotational velocity and time. */ public class TurnTime extends Command { - private final double m_duration; - private final double m_rotationalVelocity; - private final Drivetrain m_drive; - private long m_startTime; + private final double duration; + private final double rotationalVelocity; + private final Drivetrain drive; + private long startTime; /** * Creates a new TurnTime. @@ -25,34 +25,34 @@ public class TurnTime extends Command { * @param drive The drive subsystem on which this command will run */ public TurnTime(double velocity, double time, Drivetrain drive) { - m_rotationalVelocity = velocity; - m_duration = time * 1000; - m_drive = drive; + rotationalVelocity = velocity; + duration = time * 1000; + this.drive = drive; addRequirements(drive); } // Called when the command is initially scheduled. @Override public void initialize() { - m_startTime = System.currentTimeMillis(); - m_drive.arcadeDrive(0, 0); + startTime = System.currentTimeMillis(); + drive.arcadeDrive(0, 0); } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - m_drive.arcadeDrive(0, m_rotationalVelocity); + drive.arcadeDrive(0, rotationalVelocity); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - m_drive.arcadeDrive(0, 0); + drive.arcadeDrive(0, 0); } // Returns true when the command should end. @Override public boolean isFinished() { - return (System.currentTimeMillis() - m_startTime) >= m_duration; + return (System.currentTimeMillis() - startTime) >= duration; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Arm.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Arm.java index d4187706cb1..b660e3b21e1 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Arm.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Arm.java @@ -8,12 +8,12 @@ import org.wpilib.xrp.XRPServo; public class Arm extends SubsystemBase { - private final XRPServo m_armServo; + private final XRPServo armServo; /** Creates a new Arm. */ public Arm() { // Device number 4 maps to the physical Servo 1 port on the XRP - m_armServo = new XRPServo(4); + armServo = new XRPServo(4); } @Override @@ -27,6 +27,6 @@ public void periodic() { * @param angleDeg Desired arm angle in degrees */ public void setAngle(double angleDeg) { - m_armServo.setAngle(angleDeg); + armServo.setAngle(angleDeg); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Drivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Drivetrain.java index 289fcd0b080..830943d27ad 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Drivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrpreference/subsystems/Drivetrain.java @@ -20,60 +20,60 @@ public class Drivetrain extends SubsystemBase { // The XRP has the left and right motors set to // channels 0 and 1 respectively - private final XRPMotor m_leftMotor = new XRPMotor(0); - private final XRPMotor m_rightMotor = new XRPMotor(1); + private final XRPMotor leftMotor = new XRPMotor(0); + private final XRPMotor rightMotor = new XRPMotor(1); // The XRP has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); // Set up the XRPGyro - private final XRPGyro m_gyro = new XRPGyro(); + private final XRPGyro gyro = new XRPGyro(); /** Creates a new Drivetrain. */ public Drivetrain() { - SendableRegistry.addChild(m_diffDrive, m_leftMotor); - SendableRegistry.addChild(m_diffDrive, m_rightMotor); + SendableRegistry.addChild(diffDrive, leftMotor); + SendableRegistry.addChild(diffDrive, rightMotor); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public int getLeftEncoderCount() { - return m_leftEncoder.get(); + return leftEncoder.get(); } public int getRightEncoderCount() { - return m_rightEncoder.get(); + return rightEncoder.get(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } public double getAverageDistanceInch() { @@ -86,7 +86,7 @@ public double getAverageDistanceInch() { * @return The current angle of the XRP in degrees */ public double getGyroAngleX() { - return m_gyro.getAngleX(); + return gyro.getAngleX(); } /** @@ -95,7 +95,7 @@ public double getGyroAngleX() { * @return The current angle of the XRP in degrees */ public double getGyroAngleY() { - return m_gyro.getAngleY(); + return gyro.getAngleY(); } /** @@ -104,12 +104,12 @@ public double getGyroAngleY() { * @return The current angle of the XRP in degrees */ public double getGyroAngleZ() { - return m_gyro.getAngleZ(); + return gyro.getAngleZ(); } /** Reset the gyro. */ public void resetGyro() { - m_gyro.reset(); + gyro.reset(); } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/examples/xrptimed/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/examples/xrptimed/Robot.java index 8a2dd0e999e..974cd48052e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/examples/xrptimed/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/examples/xrptimed/Robot.java @@ -17,40 +17,40 @@ * this project, you must also update the manifest file in the resource directory. */ public class Robot extends TimedRobot { - private final XRPMotor m_leftDrive = new XRPMotor(0); - private final XRPMotor m_rightDrive = new XRPMotor(1); - private final DifferentialDrive m_robotDrive = - new DifferentialDrive(m_leftDrive::setThrottle, m_rightDrive::setThrottle); + private final XRPMotor leftDrive = new XRPMotor(0); + private final XRPMotor rightDrive = new XRPMotor(1); + private final DifferentialDrive robotDrive = + new DifferentialDrive(leftDrive::setThrottle, rightDrive::setThrottle); // Assumes a gamepad plugged into channel 0 - private final Joystick m_controller = new Joystick(0); - private final Timer m_timer = new Timer(); + private final Joystick controller = new Joystick(0); + private final Timer timer = new Timer(); /** Called once at the beginning of the robot program. */ public Robot() { - SendableRegistry.addChild(m_robotDrive, m_leftDrive); - SendableRegistry.addChild(m_robotDrive, m_rightDrive); + SendableRegistry.addChild(robotDrive, leftDrive); + SendableRegistry.addChild(robotDrive, rightDrive); // We need to invert one side of the drivetrain so that positive voltages // result in both sides moving forward. Depending on how your robot's // gearbox is constructed, you might have to invert the left side instead. - m_rightDrive.setInverted(true); + rightDrive.setInverted(true); } /** This function is run once each time the robot enters autonomous mode. */ @Override public void autonomousInit() { - m_timer.restart(); + timer.restart(); } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { // Drive for 2 seconds - if (m_timer.get() < 2.0) { + if (timer.get() < 2.0) { // Drive forwards half speed, make sure to turn input squaring off - m_robotDrive.arcadeDrive(0.5, 0.0, false); + robotDrive.arcadeDrive(0.5, 0.0, false); } else { - m_robotDrive.stopMotor(); // stop robot + robotDrive.stopMotor(); // stop robot } } @@ -61,7 +61,7 @@ public void teleopInit() {} /** This function is called periodically during teleoperated mode. */ @Override public void teleopPeriodic() { - m_robotDrive.arcadeDrive(-m_controller.getRawAxis(2), -m_controller.getRawAxis(1)); + robotDrive.arcadeDrive(-controller.getRawAxis(2), -controller.getRawAxis(1)); } /** This function is called once each time the robot enters utility mode. */ diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometercollision/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometercollision/Robot.java index ebb5e8ab759..f8de5323c3a 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometercollision/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometercollision/Robot.java @@ -15,21 +15,21 @@ */ @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance") public class Robot extends TimedRobot { - double m_prevXAccel; - double m_prevYAccel; - OnboardIMU m_accelerometer = new OnboardIMU(MountOrientation.FLAT); + double prevXAccel; + double prevYAccel; + OnboardIMU accelerometer = new OnboardIMU(MountOrientation.FLAT); @Override public void robotPeriodic() { // Gets the current accelerations in the X and Y directions - double xAccel = m_accelerometer.getAccelX(); - double yAccel = m_accelerometer.getAccelY(); + double xAccel = accelerometer.getAccelX(); + double yAccel = accelerometer.getAccelY(); // Calculates the jerk in the X and Y directions // Divides by .02 because default loop timing is 20ms - double xJerk = (xAccel - m_prevXAccel) / 0.02; - double yJerk = (yAccel - m_prevYAccel) / 0.02; - m_prevXAccel = xAccel; - m_prevYAccel = yAccel; + double xJerk = (xAccel - prevXAccel) / 0.02; + double yJerk = (yAccel - prevYAccel) / 0.02; + prevXAccel = xAccel; + prevYAccel = yAccel; SmartDashboard.putNumber("X Jerk", xJerk); SmartDashboard.putNumber("Y Jerk", yJerk); diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometerfilter/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometerfilter/Robot.java index 508a7950c82..7dfaa0c5ccc 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometerfilter/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/accelerometerfilter/Robot.java @@ -15,16 +15,16 @@ * https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html */ public class Robot extends TimedRobot { - OnboardIMU m_accelerometer = new OnboardIMU(MountOrientation.FLAT); + OnboardIMU accelerometer = new OnboardIMU(MountOrientation.FLAT); // Create a LinearFilter that will calculate a moving average of the measured X acceleration over // the past 10 iterations of the main loop - LinearFilter m_xAccelFilter = LinearFilter.movingAverage(10); + LinearFilter xAccelFilter = LinearFilter.movingAverage(10); @Override public void robotPeriodic() { - double xAccel = m_accelerometer.getAccelX(); + double xAccel = accelerometer.getAccelX(); // Get the filtered X acceleration - double filteredXAccel = m_xAccelFilter.calculate(xAccel); + double filteredXAccel = xAccelFilter.calculate(xAccel); SmartDashboard.putNumber("X Acceleration", xAccel); SmartDashboard.putNumber("Filtered X Acceleration", filteredXAccel); diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/addressableled/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/addressableled/Robot.java index 4d38df734e4..8628707ce79 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/addressableled/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/addressableled/Robot.java @@ -14,12 +14,12 @@ import org.wpilib.units.measure.Distance; public class Robot extends TimedRobot { - private final AddressableLED m_led; - private final AddressableLEDBuffer m_ledBuffer; + private final AddressableLED led; + private final AddressableLEDBuffer ledBuffer; // Create an LED pattern that will display a rainbow across // all hues at maximum saturation and half brightness - private final LEDPattern m_rainbow = LEDPattern.rainbow(255, 128); + private final LEDPattern rainbow = LEDPattern.rainbow(255, 128); // Our LED strip has a density of 120 LEDs per meter private static final Distance kLedSpacing = Meters.of(1 / 120.0); @@ -27,28 +27,28 @@ public class Robot extends TimedRobot { // Create a new pattern that scrolls the rainbow pattern across the LED strip, moving at a // velocity // of 1 meter per second. - private final LEDPattern m_scrollingRainbow = - m_rainbow.scrollAtAbsoluteVelocity(MetersPerSecond.of(1), kLedSpacing); + private final LEDPattern scrollingRainbow = + rainbow.scrollAtAbsoluteVelocity(MetersPerSecond.of(1), kLedSpacing); /** Called once at the beginning of the robot program. */ public Robot() { // SmartIO port 1 - m_led = new AddressableLED(1); + led = new AddressableLED(1); // Reuse buffer // Default to a length of 60 - m_ledBuffer = new AddressableLEDBuffer(60); - m_led.setLength(m_ledBuffer.getLength()); + ledBuffer = new AddressableLEDBuffer(60); + led.setLength(ledBuffer.getLength()); // Set the data - m_led.setData(m_ledBuffer); + led.setData(ledBuffer); } @Override public void robotPeriodic() { // Update the buffer with the rainbow animation - m_scrollingRainbow.applyTo(m_ledBuffer); + scrollingRainbow.applyTo(ledBuffer); // Set the LEDs - m_led.setData(m_ledBuffer); + led.setData(ledBuffer); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/adxlaccelerometers/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/adxlaccelerometers/Robot.java index a12a919eb6f..769df78322d 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/adxlaccelerometers/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/adxlaccelerometers/Robot.java @@ -14,7 +14,7 @@ */ public class Robot extends TimedRobot { // Creates an ADXL345 accelerometer object with a measurement range from -8 to 8 G's - ADXL345_I2C m_accelerometer345I2C = new ADXL345_I2C(I2C.Port.PORT_0, 8); + ADXL345_I2C accelerometer345I2C = new ADXL345_I2C(I2C.Port.PORT_0, 8); /** Called once at the beginning of the robot program. */ public Robot() {} @@ -22,10 +22,10 @@ public Robot() {} @Override public void teleopPeriodic() { // Gets the current acceleration in the X axis - m_accelerometer345I2C.getX(); + accelerometer345I2C.getX(); // Gets the current acceleration in the Y axis - m_accelerometer345I2C.getY(); + accelerometer345I2C.getY(); // Gets the current acceleration in the Z axis - m_accelerometer345I2C.getZ(); + accelerometer345I2C.getZ(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogaccelerometer/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogaccelerometer/Robot.java index 562e8ed2a68..b43000ad394 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogaccelerometer/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogaccelerometer/Robot.java @@ -13,19 +13,19 @@ */ public class Robot extends TimedRobot { // Creates an analog accelerometer on analog input 0 - AnalogAccelerometer m_accelerometer = new AnalogAccelerometer(0); + AnalogAccelerometer accelerometer = new AnalogAccelerometer(0); /** Called once at the beginning of the robot program. */ public Robot() { // Sets the sensitivity of the accelerometer to 1 volt per G - m_accelerometer.setSensitivity(1); + accelerometer.setSensitivity(1); // Sets the zero voltage of the accelerometer to 3 volts - m_accelerometer.setZero(3); + accelerometer.setZero(3); } @Override public void teleopPeriodic() { // Gets the current acceleration - m_accelerometer.getAcceleration(); + accelerometer.getAcceleration(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogencoder/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogencoder/Robot.java index 6a549e21b81..69cde8cbbf3 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogencoder/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogencoder/Robot.java @@ -13,12 +13,12 @@ */ public class Robot extends TimedRobot { // Initializes an analog encoder on Analog Input pin 0 - AnalogEncoder m_encoder = new AnalogEncoder(0); + AnalogEncoder encoder = new AnalogEncoder(0); // Initializes an analog encoder on DIO pins 0 to return a value of 4 for // a full rotation, with the encoder reporting 0 half way through rotation (2 // out of 4) - AnalogEncoder m_encoderFR = new AnalogEncoder(0, 4.0, 2.0); + AnalogEncoder encoderFR = new AnalogEncoder(0, 4.0, 2.0); /** Called once at the beginning of the robot program. */ public Robot() {} @@ -26,8 +26,8 @@ public Robot() {} @Override public void teleopPeriodic() { // Gets the rotation - m_encoder.get(); + encoder.get(); - m_encoderFR.get(); + encoderFR.get(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java index dfd12a225cf..a654cff57de 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/analoginput/Robot.java @@ -13,7 +13,7 @@ */ public class Robot extends TimedRobot { // Initializes an AnalogInput on port 0 - AnalogInput m_analog = new AnalogInput(0); + AnalogInput analog = new AnalogInput(0); /** Called once at the beginning of the robot program. */ public Robot() {} @@ -23,10 +23,10 @@ public void teleopPeriodic() { // Gets the raw instantaneous measured value from the analog input, without // applying any calibration and ignoring oversampling and averaging // settings. - m_analog.getValue(); + analog.getValue(); // Gets the instantaneous measured voltage from the analog input. // Oversampling and averaging settings are ignored - m_analog.getVoltage(); + analog.getVoltage(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java index f4f979dc523..cd8d0ead7f7 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/analogpotentiometer/Robot.java @@ -18,16 +18,16 @@ public class Robot extends TimedRobot { // instance) // The "starting point" of the motion, i.e. where the mechanism is located when the potentiometer // reads 0v, is 30. - AnalogPotentiometer m_pot = new AnalogPotentiometer(0, 180, 30); + AnalogPotentiometer pot = new AnalogPotentiometer(0, 180, 30); // Initializes an AnalogInput on port 1 - AnalogInput m_input = new AnalogInput(0); + AnalogInput input = new AnalogInput(0); // Initializes an AnalogPotentiometer with the given AnalogInput // The full range of motion (in meaningful external units) is 0-180 (this could be degrees, for // instance) // The "starting point" of the motion, i.e. where the mechanism is located when the potentiometer // reads 0v, is 30. - AnalogPotentiometer m_pot1 = new AnalogPotentiometer(m_input, 180, 30); + AnalogPotentiometer pot1 = new AnalogPotentiometer(input, 180, 30); /** Called once at the beginning of the robot program. */ public Robot() {} @@ -35,8 +35,8 @@ public Robot() {} @Override public void teleopPeriodic() { // Get the value of the potentiometer - m_pot.get(); + pot.get(); - m_pot1.get(); + pot1.get(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/canpdp/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/canpdp/Robot.java index 07788fdf836..a7666ab79b6 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/canpdp/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/canpdp/Robot.java @@ -13,11 +13,11 @@ * via CAN. The information will be displayed under variables through the SmartDashboard. */ public class Robot extends TimedRobot { - private final PowerDistribution m_pdp = new PowerDistribution(0); + private final PowerDistribution pdp = new PowerDistribution(0); public Robot() { // Put the PDP itself to the dashboard - SmartDashboard.putData("PDP", m_pdp); + SmartDashboard.putData("PDP", pdp); } @Override @@ -25,30 +25,30 @@ public void robotPeriodic() { // Get the current going through channel 7, in Amperes. // The PDP returns the current in increments of 0.125A. // At low currents the current readings tend to be less accurate. - double current7 = m_pdp.getCurrent(7); + double current7 = pdp.getCurrent(7); SmartDashboard.putNumber("Current Channel 7", current7); // Get the voltage going into the PDP, in Volts. // The PDP returns the voltage in increments of 0.05 Volts. - double voltage = m_pdp.getVoltage(); + double voltage = pdp.getVoltage(); SmartDashboard.putNumber("Voltage", voltage); // Retrieves the temperature of the PDP, in degrees Celsius. - double temperatureCelsius = m_pdp.getTemperature(); + double temperatureCelsius = pdp.getTemperature(); SmartDashboard.putNumber("Temperature", temperatureCelsius); // Get the total current of all channels. - double totalCurrent = m_pdp.getTotalCurrent(); + double totalCurrent = pdp.getTotalCurrent(); SmartDashboard.putNumber("Total Current", totalCurrent); // Get the total power of all channels. // Power is the bus voltage multiplied by the current with the units Watts. - double totalPower = m_pdp.getTotalPower(); + double totalPower = pdp.getTotalPower(); SmartDashboard.putNumber("Total Power", totalPower); // Get the total energy of all channels. // Energy is the power summed over time with units Joules. - double totalEnergy = m_pdp.getTotalEnergy(); + double totalEnergy = pdp.getTotalEnergy(); SmartDashboard.putNumber("Total Energy", totalEnergy); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalcommunication/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalcommunication/Robot.java index 6fb792157c9..6975db09865 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalcommunication/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalcommunication/Robot.java @@ -22,10 +22,10 @@ public class Robot extends TimedRobot { static final int kAutonomousPort = 2; static final int kAlertPort = 3; - private final DigitalOutput m_allianceOutput = new DigitalOutput(kAlliancePort); - private final DigitalOutput m_enabledOutput = new DigitalOutput(kEnabledPort); - private final DigitalOutput m_autonomousOutput = new DigitalOutput(kAutonomousPort); - private final DigitalOutput m_alertOutput = new DigitalOutput(kAlertPort); + private final DigitalOutput allianceOutput = new DigitalOutput(kAlliancePort); + private final DigitalOutput enabledOutput = new DigitalOutput(kEnabledPort); + private final DigitalOutput autonomousOutput = new DigitalOutput(kAutonomousPort); + private final DigitalOutput alertOutput = new DigitalOutput(kAlertPort); @Override public void robotPeriodic() { @@ -36,26 +36,26 @@ public void robotPeriodic() { } // pull alliance port high if on red alliance, pull low if on blue alliance - m_allianceOutput.set(setAlliance); + allianceOutput.set(setAlliance); // pull enabled port high if enabled, low if disabled - m_enabledOutput.set(RobotState.isEnabled()); + enabledOutput.set(RobotState.isEnabled()); // pull auto port high if in autonomous, low if in teleop (or disabled) - m_autonomousOutput.set(RobotState.isAutonomous()); + autonomousOutput.set(RobotState.isAutonomous()); // pull alert port high if match time remaining is between 30 and 25 seconds var matchTime = MatchState.getMatchTime(); - m_alertOutput.set(matchTime <= 30 && matchTime >= 25); + alertOutput.set(matchTime <= 30 && matchTime >= 25); } /** Close all resources. */ @Override public void close() { - m_allianceOutput.close(); - m_enabledOutput.close(); - m_autonomousOutput.close(); - m_alertOutput.close(); + allianceOutput.close(); + enabledOutput.close(); + autonomousOutput.close(); + alertOutput.close(); super.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalinput/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalinput/Robot.java index 52d1246e1c2..d8785a6862a 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalinput/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/digitalinput/Robot.java @@ -13,11 +13,11 @@ */ public class Robot extends TimedRobot { // Initializes a DigitalInput on DIO 0 - DigitalInput m_input = new DigitalInput(0); + DigitalInput input = new DigitalInput(0); @Override public void teleopPeriodic() { // Gets the value of the digital input. Returns true if the circuit is open. - m_input.get(); + input.get(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleencoder/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleencoder/Robot.java index de694afcb09..e73a86d69b7 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleencoder/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleencoder/Robot.java @@ -13,12 +13,12 @@ */ public class Robot extends TimedRobot { // Initializes a duty cycle encoder on DIO pins 0 - DutyCycleEncoder m_encoder = new DutyCycleEncoder(0); + DutyCycleEncoder encoder = new DutyCycleEncoder(0); // Initializes a duty cycle encoder on DIO pins 0 to return a value of 4 for // a full rotation, with the encoder reporting 0 half way through rotation (2 // out of 4) - DutyCycleEncoder m_encoderFR = new DutyCycleEncoder(0, 4.0, 2.0); + DutyCycleEncoder encoderFR = new DutyCycleEncoder(0, 4.0, 2.0); /** Called once at the beginning of the robot program. */ public Robot() {} @@ -26,11 +26,11 @@ public Robot() {} @Override public void teleopPeriodic() { // Gets the rotation - m_encoder.get(); + encoder.get(); // Gets if the encoder is connected - m_encoder.isConnected(); + encoder.isConnected(); - m_encoderFR.get(); + encoderFR.get(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleinput/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleinput/Robot.java index 9e46e496eb8..6c186087dfa 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleinput/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/dutycycleinput/Robot.java @@ -9,20 +9,20 @@ import org.wpilib.smartdashboard.SmartDashboard; public class Robot extends TimedRobot { - private final DutyCycle m_dutyCycle; + private final DutyCycle dutyCycle; public Robot() { - m_dutyCycle = new DutyCycle(0); + dutyCycle = new DutyCycle(0); } @Override public void robotPeriodic() { // Duty Cycle Frequency in Hz - double frequency = m_dutyCycle.getFrequency(); + double frequency = dutyCycle.getFrequency(); // Output of duty cycle, ranging from 0 to 1 // 1 is fully on, 0 is fully off - double output = m_dutyCycle.getOutput(); + double output = dutyCycle.getOutput(); SmartDashboard.putNumber("Frequency", frequency); SmartDashboard.putNumber("Duty Cycle", output); diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/encoder/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/encoder/Robot.java index 3ce39d3c701..3cee5542f87 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/encoder/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/encoder/Robot.java @@ -15,48 +15,48 @@ public class Robot extends TimedRobot { // Initializes an encoder on DIO pins 0 and 1 // Defaults to 4X decoding and non-inverted - Encoder m_encoder = new Encoder(0, 1); + Encoder encoder = new Encoder(0, 1); // Initializes an encoder on DIO pins 0 and 1 // 2X encoding and non-inverted - Encoder m_encoder2x = new Encoder(0, 1, false, Encoder.EncodingType.X2); + Encoder encoder2x = new Encoder(0, 1, false, Encoder.EncodingType.X2); /** Called once at the beginning of the robot program. */ public Robot() { // Configures the encoder to return a distance of 4 for every 256 pulses // Also changes the units of getRate - m_encoder.setDistancePerPulse(4.0 / 256.0); + encoder.setDistancePerPulse(4.0 / 256.0); // Configures the encoder to consider itself stopped after .1 seconds - m_encoder.setMaxPeriod(0.1); + encoder.setMaxPeriod(0.1); // Configures the encoder to consider itself stopped when its rate is below 10 - m_encoder.setMinRate(10); + encoder.setMinRate(10); // Reverses the direction of the encoder - m_encoder.setReverseDirection(true); + encoder.setReverseDirection(true); // Configures an encoder to average its period measurement over 5 samples // Can be between 1 and 127 samples - m_encoder.setSamplesToAverage(5); + encoder.setSamplesToAverage(5); - m_encoder2x.getRate(); + encoder2x.getRate(); } @Override public void teleopPeriodic() { // Gets the distance traveled - m_encoder.getDistance(); + encoder.getDistance(); // Gets the current rate of the encoder - m_encoder.getRate(); + encoder.getRate(); // Gets whether the encoder is stopped - m_encoder.getStopped(); + encoder.getStopped(); // Gets the last direction in which the encoder moved - m_encoder.getDirection(); + encoder.getDirection(); // Gets the current period of the encoder - m_encoder.getPeriod(); + encoder.getPeriod(); // Resets the encoder to read a distance of zero - m_encoder.reset(); + encoder.reset(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderdrive/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderdrive/Robot.java index 02dfa40ba9a..3cd2c1f1458 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderdrive/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderdrive/Robot.java @@ -15,35 +15,35 @@ */ public class Robot extends TimedRobot { // Creates an encoder on DIO ports 0 and 1 - Encoder m_encoder = new Encoder(0, 1); + Encoder encoder = new Encoder(0, 1); // Initialize motor controllers and drive - Spark m_leftLeader = new Spark(0); - Spark m_leftFollower = new Spark(1); - Spark m_rightLeader = new Spark(2); - Spark m_rightFollower = new Spark(3); - DifferentialDrive m_drive = - new DifferentialDrive(m_leftLeader::setThrottle, m_rightLeader::setThrottle); + Spark leftLeader = new Spark(0); + Spark leftFollower = new Spark(1); + Spark rightLeader = new Spark(2); + Spark rightFollower = new Spark(3); + DifferentialDrive drive = + new DifferentialDrive(leftLeader::setThrottle, rightLeader::setThrottle); /** Called once at the beginning of the robot program. */ public Robot() { // Configures the encoder's distance-per-pulse // The robot moves forward 1 foot per encoder rotation // There are 256 pulses per encoder rotation - m_encoder.setDistancePerPulse(1.0 / 256.0); + encoder.setDistancePerPulse(1.0 / 256.0); // Invert the right side of the drivetrain. You might have to invert the other side - m_rightLeader.setInverted(true); + rightLeader.setInverted(true); // Configure the followers to follow the leaders - m_leftLeader.addFollower(m_leftFollower); - m_rightLeader.addFollower(m_rightFollower); + leftLeader.addFollower(leftFollower); + rightLeader.addFollower(rightFollower); } /** Drives forward at half velocity until the robot has moved 5 feet, then stops. */ @Override public void autonomousPeriodic() { - if (m_encoder.getDistance() < 5.0) { - m_drive.tankDrive(0.5, 0.5); + if (encoder.getDistance() < 5.0) { + drive.tankDrive(0.5, 0.5); } else { - m_drive.tankDrive(0.0, 0.0); + drive.tankDrive(0.0, 0.0); } } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderhoming/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderhoming/Robot.java index 24c42dcfc0c..bf68106d016 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderhoming/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/encoderhoming/Robot.java @@ -14,10 +14,10 @@ * https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/encoders-software.html */ public class Robot extends TimedRobot { - Encoder m_encoder = new Encoder(0, 1); - Spark m_spark = new Spark(0); + Encoder encoder = new Encoder(0, 1); + Spark spark = new Spark(0); // Limit switch on DIO 2 - DigitalInput m_limit = new DigitalInput(2); + DigitalInput limit = new DigitalInput(2); /** * Runs the motor backwards at half velocity until the limit switch is pressed then turn off the @@ -25,11 +25,11 @@ public class Robot extends TimedRobot { */ @Override public void autonomousPeriodic() { - if (!m_limit.get()) { - m_spark.setThrottle(-0.5); + if (!limit.get()) { + spark.setThrottle(-0.5); } else { - m_spark.setThrottle(0.0); - m_encoder.reset(); + spark.setThrottle(0.0); + encoder.reset(); } } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/eventloop/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/eventloop/Robot.java index 1c180083dc2..9244ccf71f6 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/eventloop/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/eventloop/Robot.java @@ -17,32 +17,32 @@ public class Robot extends TimedRobot { public static final double SHOT_VELOCITY = 200; // rpm public static final double TOLERANCE = 8; // rpm - private final PWMSparkMax m_shooter = new PWMSparkMax(0); - private final Encoder m_shooterEncoder = new Encoder(0, 1); - private final PIDController m_controller = new PIDController(0.3, 0, 0); - private final SimpleMotorFeedforward m_ff = new SimpleMotorFeedforward(0.1, 0.065); + private final PWMSparkMax shooter = new PWMSparkMax(0); + private final Encoder shooterEncoder = new Encoder(0, 1); + private final PIDController controller = new PIDController(0.3, 0, 0); + private final SimpleMotorFeedforward ff = new SimpleMotorFeedforward(0.1, 0.065); - private final PWMSparkMax m_kicker = new PWMSparkMax(1); + private final PWMSparkMax kicker = new PWMSparkMax(1); - private final PWMSparkMax m_intake = new PWMSparkMax(2); + private final PWMSparkMax intake = new PWMSparkMax(2); - private final EventLoop m_loop = new EventLoop(); - private final Joystick m_joystick = new Joystick(0); + private final EventLoop loop = new EventLoop(); + private final Joystick joystick = new Joystick(0); /** Called once at the beginning of the robot program. */ public Robot() { - m_controller.setTolerance(TOLERANCE); + controller.setTolerance(TOLERANCE); BooleanEvent isBallAtKicker = - new BooleanEvent(m_loop, () -> false); // m_kickerSensor.getRange() < KICKER_THRESHOLD); - BooleanEvent intakeButton = new BooleanEvent(m_loop, () -> m_joystick.getRawButton(2)); + new BooleanEvent(loop, () -> false); // kickerSensor.getRange() < KICKER_THRESHOLD); + BooleanEvent intakeButton = new BooleanEvent(loop, () -> joystick.getRawButton(2)); // if the thumb button is held intakeButton // and there is not a ball at the kicker .and(isBallAtKicker.negate()) // activate the intake - .ifHigh(() -> m_intake.setThrottle(0.5)); + .ifHigh(() -> intake.setThrottle(0.5)); // if the thumb button is not held intakeButton @@ -50,41 +50,41 @@ public Robot() { // or there is a ball in the kicker .or(isBallAtKicker) // stop the intake - .ifHigh(m_intake::stopMotor); + .ifHigh(intake::stopMotor); - BooleanEvent shootTrigger = new BooleanEvent(m_loop, m_joystick::getTrigger); + BooleanEvent shootTrigger = new BooleanEvent(loop, joystick::getTrigger); // if the trigger is held shootTrigger // accelerate the shooter wheel .ifHigh( () -> { - m_shooter.setVoltage( - m_controller.calculate(m_shooterEncoder.getRate(), SHOT_VELOCITY) - + m_ff.calculate(SHOT_VELOCITY)); + shooter.setVoltage( + controller.calculate(shooterEncoder.getRate(), SHOT_VELOCITY) + + ff.calculate(SHOT_VELOCITY)); }); // if not, stop - shootTrigger.negate().ifHigh(m_shooter::stopMotor); + shootTrigger.negate().ifHigh(shooter::stopMotor); BooleanEvent atTargetVelocity = - new BooleanEvent(m_loop, m_controller::atSetpoint) + new BooleanEvent(loop, controller::atSetpoint) // debounce for more stability .debounce(0.2); // if we're at the target velocity, kick the ball into the shooter wheel - atTargetVelocity.ifHigh(() -> m_kicker.setThrottle(0.7)); + atTargetVelocity.ifHigh(() -> kicker.setThrottle(0.7)); // when we stop being at the target velocity, it means the ball was shot atTargetVelocity .falling() // so stop the kicker - .ifHigh(m_kicker::stopMotor); + .ifHigh(kicker::stopMotor); } @Override public void robotPeriodic() { // poll all the bindings - m_loop.poll(); + loop.poll(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/flywheelbangbangcontroller/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/flywheelbangbangcontroller/Robot.java index 2deb9e0bee8..50a2eae2ec0 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/flywheelbangbangcontroller/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/flywheelbangbangcontroller/Robot.java @@ -33,18 +33,18 @@ public class Robot extends TimedRobot { private static final double kMaxSetpointValue = 6000.0; // Joystick to control setpoint - private final Joystick m_joystick = new Joystick(0); + private final Joystick joystick = new Joystick(0); - private final PWMSparkMax m_flywheelMotor = new PWMSparkMax(kMotorPort); - private final Encoder m_encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); + private final PWMSparkMax flywheelMotor = new PWMSparkMax(kMotorPort); + private final Encoder encoder = new Encoder(kEncoderAChannel, kEncoderBChannel); - private final BangBangController m_bangBangController = new BangBangController(); + private final BangBangController bangBangController = new BangBangController(); // Gains are for example purposes only - must be determined for your own robot! public static final double kFlywheelKs = 0.0001; // V public static final double kFlywheelKv = 0.000195; // V/RPM public static final double kFlywheelKa = 0.0003; // V/(RPM/s) - private final SimpleMotorFeedforward m_feedforward = + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(kFlywheelKs, kFlywheelKv, kFlywheelKa); // Simulation classes help us simulate our robot @@ -57,17 +57,17 @@ public class Robot extends TimedRobot { private static final double kFlywheelMomentOfInertia = 0.5 * Units.lbsToKilograms(1.5) * Math.pow(Units.inchesToMeters(4), 2); - private final DCMotor m_gearbox = DCMotor.getNEO(1); + private final DCMotor gearbox = DCMotor.getNEO(1); - private final LinearSystem m_plant = - Models.flywheelFromPhysicalConstants(m_gearbox, kFlywheelGearing, kFlywheelMomentOfInertia); + private final LinearSystem plant = + Models.flywheelFromPhysicalConstants(gearbox, kFlywheelGearing, kFlywheelMomentOfInertia); - private final FlywheelSim m_flywheelSim = new FlywheelSim(m_plant, m_gearbox); - private final EncoderSim m_encoderSim = new EncoderSim(m_encoder); + private final FlywheelSim flywheelSim = new FlywheelSim(plant, gearbox); + private final EncoderSim encoderSim = new EncoderSim(encoder); public Robot() { // Add bang-bang controller to SmartDashboard and networktables. - SmartDashboard.putData(m_bangBangController); + SmartDashboard.putData(bangBangController); } /** Controls flywheel to a set velocity (RPM) controlled by a joystick. */ @@ -77,16 +77,15 @@ public void teleopPeriodic() { double setpoint = Math.max( 0.0, - m_joystick.getRawAxis(0) - * Units.rotationsPerMinuteToRadiansPerSecond(kMaxSetpointValue)); + joystick.getRawAxis(0) * Units.rotationsPerMinuteToRadiansPerSecond(kMaxSetpointValue)); // Set setpoint and measurement of the bang-bang controller - double bangOutput = m_bangBangController.calculate(m_encoder.getRate(), setpoint) * 12.0; + double bangOutput = bangBangController.calculate(encoder.getRate(), setpoint) * 12.0; // Controls a motor with the output of the BangBang controller and a // feedforward. The feedforward is reduced slightly to avoid overspeeding // the shooter. - m_flywheelMotor.setVoltage(bangOutput + 0.9 * m_feedforward.calculate(setpoint)); + flywheelMotor.setVoltage(bangOutput + 0.9 * feedforward.calculate(setpoint)); } /** Update our simulation. This should be run every robot loop in simulation. */ @@ -94,9 +93,8 @@ public void teleopPeriodic() { public void simulationPeriodic() { // To update our simulation, we set motor voltage inputs, update the // simulation, and write the simulated velocities to our simulated encoder - m_flywheelSim.setInputVoltage( - m_flywheelMotor.getThrottle() * RobotController.getInputVoltage()); - m_flywheelSim.update(0.02); - m_encoderSim.setRate(m_flywheelSim.getAngularVelocity()); + flywheelSim.setInputVoltage(flywheelMotor.getThrottle() * RobotController.getInputVoltage()); + flywheelSim.update(0.02); + encoderSim.setRate(flywheelSim.getAngularVelocity()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/httpcamera/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/httpcamera/Robot.java index 3285abed9fa..a4f8eadd816 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/httpcamera/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/httpcamera/Robot.java @@ -20,11 +20,11 @@ * many methods for different types of processing. */ public class Robot extends TimedRobot { - Thread m_visionThread; + Thread visionThread; /** Called once at the beginning of the robot program. */ public Robot() { - m_visionThread = + visionThread = new Thread( () -> { // Create an HTTP camera. The address will need to be modified to have the correct @@ -63,7 +63,7 @@ public Robot() { outputStream.putFrame(mat); } }); - m_visionThread.setDaemon(true); - m_visionThread.start(); + visionThread.setDaemon(true); + visionThread.start(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/i2ccommunication/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/i2ccommunication/Robot.java index 1512f9a735e..6f26129d944 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/i2ccommunication/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/i2ccommunication/Robot.java @@ -20,7 +20,7 @@ public class Robot extends TimedRobot { static final Port kPort = Port.PORT_0; private static final int kDeviceAddress = 4; - private final I2C m_arduino = new I2C(kPort, kDeviceAddress); + private final I2C arduino = new I2C(kPort, kDeviceAddress); private void writeString(String input) { // Creates a char array from the input string @@ -35,7 +35,7 @@ private void writeString(String input) { } // Writes bytes over I2C - m_arduino.transaction(data, data.length, new byte[] {}, 0); + arduino.transaction(data, data.length, new byte[] {}, 0); } @Override @@ -70,7 +70,7 @@ public void robotPeriodic() { /** Close all resources. */ @Override public void close() { - m_arduino.close(); + arduino.close(); super.close(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/intermediatevision/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/intermediatevision/Robot.java index ed48ee4e71e..3918e5b78ee 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/intermediatevision/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/intermediatevision/Robot.java @@ -20,11 +20,11 @@ * many methods for different types of processing. */ public class Robot extends TimedRobot { - Thread m_visionThread; + Thread visionThread; /** Called once at the beginning of the robot program. */ public Robot() { - m_visionThread = + visionThread = new Thread( () -> { // Get the UsbCamera from CameraServer @@ -59,7 +59,7 @@ public Robot() { outputStream.putFrame(mat); } }); - m_visionThread.setDaemon(true); - m_visionThread.start(); + visionThread.setDaemon(true); + visionThread.start(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/limitswitch/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/limitswitch/Robot.java index e4faff1b98d..43d173688ce 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/limitswitch/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/limitswitch/Robot.java @@ -14,14 +14,14 @@ * https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/limit-switch.html */ public class Robot extends TimedRobot { - DigitalInput m_toplimitSwitch = new DigitalInput(0); - DigitalInput m_bottomlimitSwitch = new DigitalInput(1); - PWMVictorSPX m_motor = new PWMVictorSPX(0); - Joystick m_joystick = new Joystick(0); + DigitalInput toplimitSwitch = new DigitalInput(0); + DigitalInput bottomlimitSwitch = new DigitalInput(1); + PWMVictorSPX motor = new PWMVictorSPX(0); + Joystick joystick = new Joystick(0); @Override public void teleopPeriodic() { - setMotorVelocity(m_joystick.getRawAxis(2)); + setMotorVelocity(joystick.getRawAxis(2)); } /** @@ -31,20 +31,20 @@ public void teleopPeriodic() { */ public void setMotorVelocity(double velocity) { if (velocity > 0) { - if (m_toplimitSwitch.get()) { + if (toplimitSwitch.get()) { // We are going up and top limit is tripped so stop - m_motor.setThrottle(0); + motor.setThrottle(0); } else { // We are going up but top limit is not tripped so go at commanded velocity - m_motor.setThrottle(velocity); + motor.setThrottle(velocity); } } else { - if (m_bottomlimitSwitch.get()) { + if (bottomlimitSwitch.get()) { // We are going down and bottom limit is tripped so stop - m_motor.setThrottle(0); + motor.setThrottle(0); } else { // We are going down but bottom limit is not tripped so go at commanded velocity - m_motor.setThrottle(velocity); + motor.setThrottle(velocity); } } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/motorcontrol/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/motorcontrol/Robot.java index 5119bfdd070..92b9c9d51d1 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/motorcontrol/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/motorcontrol/Robot.java @@ -26,18 +26,18 @@ public class Robot extends TimedRobot { private static final int kEncoderPortA = 0; private static final int kEncoderPortB = 1; - private final PWMSparkMax m_motor; - private final Joystick m_joystick; - private final Encoder m_encoder; + private final PWMSparkMax motor; + private final Joystick joystick; + private final Encoder encoder; /** Called once at the beginning of the robot program. */ public Robot() { - m_motor = new PWMSparkMax(kMotorPort); - m_joystick = new Joystick(kJoystickPort); - m_encoder = new Encoder(kEncoderPortA, kEncoderPortB); + motor = new PWMSparkMax(kMotorPort); + joystick = new Joystick(kJoystickPort); + encoder = new Encoder(kEncoderPortA, kEncoderPortB); // Use SetDistancePerPulse to set the multiplier for GetDistance // This is set up assuming a 6 inch wheel with a 360 CPR encoder. - m_encoder.setDistancePerPulse((Math.PI * 6) / 360.0); + encoder.setDistancePerPulse((Math.PI * 6) / 360.0); } /* @@ -46,12 +46,12 @@ public Robot() { */ @Override public void robotPeriodic() { - SmartDashboard.putNumber("Encoder", m_encoder.getDistance()); + SmartDashboard.putNumber("Encoder", encoder.getDistance()); } /** The teleop periodic function is called every control packet in teleop. */ @Override public void teleopPeriodic() { - m_motor.setThrottle(m_joystick.getY()); + motor.setThrottle(joystick.getY()); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/onboardimu/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/onboardimu/Robot.java index 294c40807db..4dcfc58ac6e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/onboardimu/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/onboardimu/Robot.java @@ -14,7 +14,7 @@ */ public class Robot extends TimedRobot { // Creates an object for the on board IMU - OnboardIMU m_iMU = new OnboardIMU(MountOrientation.FLAT); + OnboardIMU iMU = new OnboardIMU(MountOrientation.FLAT); /** Called once at the beginning of the robot program. */ public Robot() {} @@ -22,20 +22,20 @@ public Robot() {} @Override public void teleopPeriodic() { // Gets the current acceleration in the X axis - m_iMU.getAccelX(); + iMU.getAccelX(); // Gets the current acceleration in the Y axis - m_iMU.getAccelY(); + iMU.getAccelY(); // Gets the current acceleration in the Z axis - m_iMU.getAccelZ(); + iMU.getAccelZ(); // Gets the current angle in the X axis - m_iMU.getAngleX(); + iMU.getAngleX(); // Gets the current angle in the Y axis - m_iMU.getAngleY(); + iMU.getAngleY(); // Gets the current angle in the Z axis - m_iMU.getAngleZ(); + iMU.getAngleZ(); // Gets the current angle as a Rotation2D - m_iMU.getRotation2d(); + iMU.getRotation2d(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/profiledpidfeedforward/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/profiledpidfeedforward/Robot.java index 64946713ac9..a7c9c303c2e 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/profiledpidfeedforward/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/profiledpidfeedforward/Robot.java @@ -16,17 +16,17 @@ * https://docs.wpilib.org/en/stable/docs/software/advanced-controls/controllers/profiled-pidcontroller.html */ public class Robot extends TimedRobot { - private final ProfiledPIDController m_controller = + private final ProfiledPIDController controller = new ProfiledPIDController(1.0, 0.0, 0.0, new TrapezoidProfile.Constraints(5.0, 10.0)); - private final SimpleMotorFeedforward m_feedforward = new SimpleMotorFeedforward(0.5, 1.5, 0.3); - private final Encoder m_encoder = new Encoder(0, 1); - private final PWMSparkMax m_motor = new PWMSparkMax(0); + private final SimpleMotorFeedforward feedforward = new SimpleMotorFeedforward(0.5, 1.5, 0.3); + private final Encoder encoder = new Encoder(0, 1); + private final PWMSparkMax motor = new PWMSparkMax(0); - double m_lastVelocity; + double lastVelocity; /** Called once at the beginning of the robot program. */ public Robot() { - m_encoder.setDistancePerPulse(1.0 / 256.0); + encoder.setDistancePerPulse(1.0 / 256.0); } /** @@ -35,10 +35,10 @@ public Robot() { * @param goalPosition the desired position */ public void goToPosition(double goalPosition) { - double pidVal = m_controller.calculate(m_encoder.getDistance(), goalPosition); - m_motor.setVoltage( - pidVal + m_feedforward.calculate(m_lastVelocity, m_controller.getSetpoint().velocity)); - m_lastVelocity = m_controller.getSetpoint().velocity; + double pidVal = controller.calculate(encoder.getDistance(), goalPosition); + motor.setVoltage( + pidVal + feedforward.calculate(lastVelocity, controller.getSetpoint().velocity)); + lastVelocity = controller.getSetpoint().velocity; } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/Robot.java index ec7b3718a08..d4003f82d22 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -25,7 +25,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,7 +54,7 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); /* * String autoSelected = SmartDashboard.getString("Auto Selector", @@ -64,8 +64,8 @@ public void autonomousInit() { */ // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -79,8 +79,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/RobotContainer.java index ab98c431ddf..e72cb6e6ac3 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/selectcommand/RobotContainer.java @@ -35,7 +35,7 @@ private CommandSelector select() { // by the selector method at runtime. Note that selectcommand works on Object(), so the // selector does not have to be an enum; it could be any desired type (string, integer, // boolean, double...) - private final Command m_exampleSelectCommand = + private final Command exampleSelectCommand = new SelectCommand<>( // Maps selector values to commands Map.ofEntries( @@ -63,6 +63,6 @@ private void configureButtonBindings() {} * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_exampleSelectCommand; + return exampleSelectCommand; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/snippets/solenoid/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/snippets/solenoid/Robot.java index 430dbedb00d..b577589e0d9 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/snippets/solenoid/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/snippets/solenoid/Robot.java @@ -24,19 +24,19 @@ * only take a single channel. */ public class Robot extends TimedRobot { - private final Joystick m_stick = new Joystick(0); + private final Joystick stick = new Joystick(0); // Solenoid corresponds to a single solenoid. // In this case, it's connected to channel 0 of a PH with the default CAN ID. - private final Solenoid m_solenoid = new Solenoid(0, PneumaticsModuleType.REV_PH, 0); + private final Solenoid solenoid = new Solenoid(0, PneumaticsModuleType.REV_PH, 0); // DoubleSolenoid corresponds to a double solenoid. // In this case, it's connected to channels 1 and 2 of a PH with the default CAN ID. - private final DoubleSolenoid m_doubleSolenoid = + private final DoubleSolenoid doubleSolenoid = new DoubleSolenoid(0, PneumaticsModuleType.REV_PH, 1, 2); // Compressor connected to a PH with a default CAN ID (1) - private final Compressor m_compressor = new Compressor(0, PneumaticsModuleType.REV_PH); + private final Compressor compressor = new Compressor(0, PneumaticsModuleType.REV_PH); static final int kSolenoidButton = 1; static final int kDoubleSolenoidForwardButton = 2; @@ -46,9 +46,9 @@ public class Robot extends TimedRobot { /** Called once at the beginning of the robot program. */ public Robot() { // Publish elements to dashboard. - SmartDashboard.putData("Single Solenoid", m_solenoid); - SmartDashboard.putData("Double Solenoid", m_doubleSolenoid); - SmartDashboard.putData("Compressor", m_compressor); + SmartDashboard.putData("Single Solenoid", solenoid); + SmartDashboard.putData("Double Solenoid", doubleSolenoid); + SmartDashboard.putData("Compressor", compressor); } @SuppressWarnings("PMD.UnconditionalIfStatement") @@ -58,52 +58,52 @@ public void teleopPeriodic() { // Get the pressure (in PSI) from the analog sensor connected to the PH. // This function is supported only on the PH! // On a PCM, this function will return 0. - SmartDashboard.putNumber("PH Pressure [PSI]", m_compressor.getPressure()); + SmartDashboard.putNumber("PH Pressure [PSI]", compressor.getPressure()); // Get compressor current draw. - SmartDashboard.putNumber("Compressor Current", m_compressor.getCurrent()); + SmartDashboard.putNumber("Compressor Current", compressor.getCurrent()); // Get whether the compressor is active. - SmartDashboard.putBoolean("Compressor Active", m_compressor.isEnabled()); + SmartDashboard.putBoolean("Compressor Active", compressor.isEnabled()); // Get the digital pressure switch connected to the PCM/PH. // The switch is open when the pressure is over ~120 PSI. - SmartDashboard.putBoolean("Pressure Switch", m_compressor.getPressureSwitchValue()); + SmartDashboard.putBoolean("Pressure Switch", compressor.getPressureSwitchValue()); /* * The output of GetRawButton is true/false depending on whether * the button is pressed; Set takes a boolean for whether * to retract the solenoid (false) or extend it (true). */ - m_solenoid.set(m_stick.getRawButton(kSolenoidButton)); + solenoid.set(stick.getRawButton(kSolenoidButton)); /* * GetRawButtonPressed will only return true once per press. * If a button is pressed, set the solenoid to the respective channel. */ - if (m_stick.getRawButtonPressed(kDoubleSolenoidForwardButton)) { - m_doubleSolenoid.set(DoubleSolenoid.Value.FORWARD); - } else if (m_stick.getRawButtonPressed(kDoubleSolenoidReverseButton)) { - m_doubleSolenoid.set(DoubleSolenoid.Value.REVERSE); + if (stick.getRawButtonPressed(kDoubleSolenoidForwardButton)) { + doubleSolenoid.set(DoubleSolenoid.Value.FORWARD); + } else if (stick.getRawButtonPressed(kDoubleSolenoidReverseButton)) { + doubleSolenoid.set(DoubleSolenoid.Value.REVERSE); } // On button press, toggle the compressor. - if (m_stick.getRawButtonPressed(kCompressorButton)) { + if (stick.getRawButtonPressed(kCompressorButton)) { // Check whether the compressor is currently enabled. - boolean isCompressorEnabled = m_compressor.isEnabled(); + boolean isCompressorEnabled = compressor.isEnabled(); if (isCompressorEnabled) { // Disable closed-loop mode on the compressor. - m_compressor.disable(); + compressor.disable(); } else { // Change the if statements to select the closed-loop you want to use: if (false) { // Enable closed-loop mode based on the digital pressure switch connected to the PCM/PH. // The switch is open when the pressure is over ~120 PSI. - m_compressor.enableDigital(); + compressor.enableDigital(); } if (true) { // Enable closed-loop mode based on the analog pressure sensor connected to the PH. // The compressor will run while the pressure reported by the sensor is in the // specified range ([70 PSI, 120 PSI] in this example). // Analog mode exists only on the PH! On the PCM, this enables digital control. - m_compressor.enableAnalog(70, 120); + compressor.enableAnalog(70, 120); } if (false) { // Enable closed-loop mode based on both the digital pressure switch AND the analog @@ -112,7 +112,7 @@ public void teleopPeriodic() { // specified range ([70 PSI, 120 PSI] in this example) AND the digital switch reports // that the system is not full. // Hybrid mode exists only on the PH! On the PCM, this enables digital control. - m_compressor.enableHybrid(70, 120); + compressor.enableHybrid(70, 120); } } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/Robot.java index c0ecbb3eb08..7b76b436866 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -25,7 +25,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,11 +54,11 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -72,8 +72,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/RobotContainer.java index e6984909106..975ea2439f5 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/RobotContainer.java @@ -20,9 +20,9 @@ */ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem(); + private final ExampleSubsystem exampleSubsystem = new ExampleSubsystem(); - private final CommandGamepad m_driverController = + private final CommandGamepad driverController = new CommandGamepad(OperatorConstants.kDriverControllerPort); /** The container for the robot. Contains subsystems, OI devices, and commands. */ @@ -40,12 +40,11 @@ public RobotContainer() { */ private void configureBindings() { // Schedule `ExampleCommand` when `exampleCondition` changes to `true` - new Trigger(m_exampleSubsystem::exampleCondition) - .onTrue(new ExampleCommand(m_exampleSubsystem)); + new Trigger(exampleSubsystem::exampleCondition).onTrue(new ExampleCommand(exampleSubsystem)); // Schedule `exampleMethodCommand` when the Gamepad's east face button is pressed, // cancelling on release. - m_driverController.eastFace().whileTrue(m_exampleSubsystem.exampleMethodCommand()); + driverController.eastFace().whileTrue(exampleSubsystem.exampleMethodCommand()); } /** @@ -55,6 +54,6 @@ private void configureBindings() { */ public Command getAutonomousCommand() { // An example command will be run in autonomous - return Autos.exampleAuto(m_exampleSubsystem); + return Autos.exampleAuto(exampleSubsystem); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/commands/ExampleCommand.java b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/commands/ExampleCommand.java index 800a188906c..c6f44e966c1 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/commands/ExampleCommand.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2/commands/ExampleCommand.java @@ -10,7 +10,7 @@ /** An example command that uses an example subsystem. */ public class ExampleCommand extends Command { @SuppressWarnings("PMD.UnusedPrivateField") - private final ExampleSubsystem m_subsystem; + private final ExampleSubsystem subsystem; /** * Creates a new ExampleCommand. @@ -18,7 +18,7 @@ public class ExampleCommand extends Command { * @param subsystem The subsystem used by this command. */ public ExampleCommand(ExampleSubsystem subsystem) { - m_subsystem = subsystem; + this.subsystem = subsystem; // Use addRequirements() here to declare subsystem dependencies. addRequirements(subsystem); } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2skeleton/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2skeleton/Robot.java index 58c83afcad8..f0cec556a26 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2skeleton/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/commandv2skeleton/Robot.java @@ -9,12 +9,12 @@ import org.wpilib.framework.TimedRobot; public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; public Robot() { - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } @Override @@ -33,10 +33,10 @@ public void disabledExit() {} @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -48,8 +48,8 @@ public void autonomousExit() {} @Override public void teleopInit() { - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/educational/EducationalRobot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/educational/EducationalRobot.java index 2c75aafce0b..9255d667da5 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/educational/EducationalRobot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/educational/EducationalRobot.java @@ -32,7 +32,7 @@ public void utility() { run(); } - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -52,7 +52,7 @@ public void startCompetition() { // Tell the DS that the robot is ready to be enabled DriverStationBackend.observeUserProgramStarting(); - while (!Thread.currentThread().isInterrupted() && !m_exit) { + while (!Thread.currentThread().isInterrupted() && !exit) { DriverStationBackend.refreshControlWordFromCache(word); modeThread.inControl(word); if (isDisabled()) { @@ -100,6 +100,6 @@ public void startCompetition() { @Override public void endCompetition() { - m_exit = true; + exit = true; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyAuto.java b/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyAuto.java index 5ae1d4f4879..47e5e9a2745 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyAuto.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyAuto.java @@ -10,11 +10,11 @@ @Autonomous(name = "My Auto", group = "Group 1") public class MyAuto extends PeriodicOpMode { - private final Robot m_robot; + private final Robot robot; /** The Robot instance is passed into the opmode via the constructor. */ public MyAuto(Robot robot) { - m_robot = robot; + this.robot = robot; } /* diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyTeleop.java b/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyTeleop.java index 1a91977adca..50c433520de 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyTeleop.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/opmode/opmode/MyTeleop.java @@ -10,11 +10,11 @@ @Teleop public class MyTeleop extends PeriodicOpMode { - private final Robot m_robot; + private final Robot robot; /** The Robot instance is passed into the opmode via the constructor. */ public MyTeleop(Robot robot) { - m_robot = robot; + this.robot = robot; } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/robotbaseskeleton/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/robotbaseskeleton/Robot.java index 135ab43cb7d..10d157e8248 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/robotbaseskeleton/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/robotbaseskeleton/Robot.java @@ -27,7 +27,7 @@ public void teleop() {} public void utility() {} - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -47,7 +47,7 @@ public void startCompetition() { // Tell the DS that the robot is ready to be enabled DriverStationBackend.observeUserProgramStarting(); - while (!Thread.currentThread().isInterrupted() && !m_exit) { + while (!Thread.currentThread().isInterrupted() && !exit) { DriverStationBackend.refreshControlWordFromCache(word); modeThread.inControl(word); if (isDisabled()) { @@ -95,6 +95,6 @@ public void startCompetition() { @Override public void endCompetition() { - m_exit = true; + exit = true; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/Robot.java index fbe78e7c39a..32a736cf2c5 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -25,7 +25,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,11 +54,11 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -72,8 +72,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/RobotContainer.java index 5994d1914cf..858a6012eef 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/RobotContainer.java @@ -17,9 +17,9 @@ */ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final RomiDrivetrain m_romiDrivetrain = new RomiDrivetrain(); + private final RomiDrivetrain romiDrivetrain = new RomiDrivetrain(); - private final ExampleCommand m_autoCommand = new ExampleCommand(m_romiDrivetrain); + private final ExampleCommand autoCommand = new ExampleCommand(romiDrivetrain); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { @@ -42,6 +42,6 @@ private void configureButtonBindings() {} */ public Command getAutonomousCommand() { // An ExampleCommand will run in autonomous - return m_autoCommand; + return autoCommand; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/commands/ExampleCommand.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/commands/ExampleCommand.java index f21a9aee0d8..02607b3cc3d 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/commands/ExampleCommand.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/commands/ExampleCommand.java @@ -10,7 +10,7 @@ /** An example command that uses an example subsystem. */ public class ExampleCommand extends Command { @SuppressWarnings("PMD.UnusedPrivateField") - private final RomiDrivetrain m_subsystem; + private final RomiDrivetrain subsystem; /** * Creates a new ExampleCommand. @@ -18,7 +18,7 @@ public class ExampleCommand extends Command { * @param subsystem The subsystem used by this command. */ public ExampleCommand(RomiDrivetrain subsystem) { - m_subsystem = subsystem; + this.subsystem = subsystem; // Use addRequirements() here to declare subsystem dependencies. addRequirements(subsystem); } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/subsystems/RomiDrivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/subsystems/RomiDrivetrain.java index 60f8c5e15e9..d6b62603114 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/subsystems/RomiDrivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romicommandv2/subsystems/RomiDrivetrain.java @@ -15,44 +15,44 @@ public class RomiDrivetrain extends SubsystemBase { // The Romi has the left and right motors set to // PWM channels 0 and 1 respectively - private final Spark m_leftMotor = new Spark(0); - private final Spark m_rightMotor = new Spark(1); + private final Spark leftMotor = new Spark(0); + private final Spark rightMotor = new Spark(1); // The Romi has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); /** Creates a new RomiDrivetrain. */ public RomiDrivetrain() { // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); // Invert right side since motor is flipped - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/EducationalRobot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/EducationalRobot.java index 5041fb9df7c..96f0a6eea18 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/EducationalRobot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/EducationalRobot.java @@ -32,7 +32,7 @@ public void utility() { run(); } - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -52,7 +52,7 @@ public void startCompetition() { // Tell the DS that the robot is ready to be enabled DriverStationBackend.observeUserProgramStarting(); - while (!Thread.currentThread().isInterrupted() && !m_exit) { + while (!Thread.currentThread().isInterrupted() && !exit) { DriverStationBackend.refreshControlWordFromCache(word); modeThread.inControl(word); if (isDisabled()) { @@ -100,6 +100,6 @@ public void startCompetition() { @Override public void endCompetition() { - m_exit = true; + exit = true; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/RomiDrivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/RomiDrivetrain.java index 3bcf03dda96..352f400381c 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/RomiDrivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romieducational/RomiDrivetrain.java @@ -14,46 +14,46 @@ public class RomiDrivetrain { // The Romi has the left and right motors set to // PWM channels 0 and 1 respectively - private final Spark m_leftMotor = new Spark(0); - private final Spark m_rightMotor = new Spark(1); + private final Spark leftMotor = new Spark(0); + private final Spark rightMotor = new Spark(1); // The Romi has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); /** Creates a new RomiDrivetrain. */ public RomiDrivetrain() { // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); // Invert right side since motor is flipped - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); // Disable motor safety - m_diffDrive.setSafetyEnabled(false); + diffDrive.setSafetyEnabled(false); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/Robot.java index 61e52bdde8a..3fd1b301bb4 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/Robot.java @@ -16,19 +16,19 @@ public class Robot extends TimedRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; - private String m_autoSelected; - private final SendableChooser m_chooser = new SendableChooser<>(); + private String autoSelected; + private final SendableChooser chooser = new SendableChooser<>(); - private final RomiDrivetrain m_drivetrain = new RomiDrivetrain(); + private final RomiDrivetrain drivetrain = new RomiDrivetrain(); /** * This function is run when the robot is first started up and should be used for any * initialization code. */ public Robot() { - m_chooser.setDefaultOption("Default Auto", kDefaultAuto); - m_chooser.addOption("My Auto", kCustomAuto); - SmartDashboard.putData("Auto choices", m_chooser); + chooser.setDefaultOption("Default Auto", kDefaultAuto); + chooser.addOption("My Auto", kCustomAuto); + SmartDashboard.putData("Auto choices", chooser); } /** @@ -53,17 +53,17 @@ public void robotPeriodic() {} */ @Override public void autonomousInit() { - m_autoSelected = m_chooser.getSelected(); - // m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); - System.out.println("Auto selected: " + m_autoSelected); + autoSelected = chooser.getSelected(); + // autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); + System.out.println("Auto selected: " + autoSelected); - m_drivetrain.resetEncoders(); + drivetrain.resetEncoders(); } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { - switch (m_autoSelected) { + switch (autoSelected) { case kCustomAuto: // Put custom auto code here break; diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/RomiDrivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/RomiDrivetrain.java index f0bd81d7630..022c72713f2 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/RomiDrivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/romitimed/RomiDrivetrain.java @@ -14,43 +14,43 @@ public class RomiDrivetrain { // The Romi has the left and right motors set to // PWM channels 0 and 1 respectively - private final Spark m_leftMotor = new Spark(0); - private final Spark m_rightMotor = new Spark(1); + private final Spark leftMotor = new Spark(0); + private final Spark rightMotor = new Spark(1); // The Romi has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); /** Creates a new RomiDrivetrain. */ public RomiDrivetrain() { // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); // Invert right side since motor is flipped - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/timed/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/timed/Robot.java index 605d85de966..40852376489 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/timed/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/timed/Robot.java @@ -16,17 +16,17 @@ public class Robot extends TimedRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; - private String m_autoSelected; - private final SendableChooser m_chooser = new SendableChooser<>(); + private String autoSelected; + private final SendableChooser chooser = new SendableChooser<>(); /** * This function is run when the robot is first started up and should be used for any * initialization code. */ public Robot() { - m_chooser.setDefaultOption("Default Auto", kDefaultAuto); - m_chooser.addOption("My Auto", kCustomAuto); - SmartDashboard.putData("Auto choices", m_chooser); + chooser.setDefaultOption("Default Auto", kDefaultAuto); + chooser.addOption("My Auto", kCustomAuto); + SmartDashboard.putData("Auto choices", chooser); } /** @@ -51,15 +51,15 @@ public void robotPeriodic() {} */ @Override public void autonomousInit() { - m_autoSelected = m_chooser.getSelected(); - // m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); - System.out.println("Auto selected: " + m_autoSelected); + autoSelected = chooser.getSelected(); + // autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); + System.out.println("Auto selected: " + autoSelected); } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { - switch (m_autoSelected) { + switch (autoSelected) { case kCustomAuto: // Put custom auto code here break; diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/timeslice/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/timeslice/Robot.java index 6c510a19237..dfea75c96d0 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/timeslice/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/timeslice/Robot.java @@ -16,8 +16,8 @@ public class Robot extends TimesliceRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; - private String m_autoSelected; - private final SendableChooser m_chooser = new SendableChooser<>(); + private String autoSelected; + private final SendableChooser chooser = new SendableChooser<>(); /** Robot constructor. */ public Robot() { @@ -33,9 +33,9 @@ public Robot() { // Total usage: 5 ms (robot) + 2 ms (controller 1) + 2 ms (controller 2) // = 9 ms -> 90% allocated - m_chooser.setDefaultOption("Default Auto", kDefaultAuto); - m_chooser.addOption("My Auto", kCustomAuto); - SmartDashboard.putData("Auto choices", m_chooser); + chooser.setDefaultOption("Default Auto", kDefaultAuto); + chooser.addOption("My Auto", kCustomAuto); + SmartDashboard.putData("Auto choices", chooser); } /** @@ -60,15 +60,15 @@ public void robotPeriodic() {} */ @Override public void autonomousInit() { - m_autoSelected = m_chooser.getSelected(); - // m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); - System.out.println("Auto selected: " + m_autoSelected); + autoSelected = chooser.getSelected(); + // autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); + System.out.println("Auto selected: " + autoSelected); } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { - switch (m_autoSelected) { + switch (autoSelected) { case kCustomAuto: // Put custom auto code here break; diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/Robot.java index 9044b98232e..0403d31121a 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/Robot.java @@ -14,9 +14,9 @@ * this project, you must also update the Main.java file in the project. */ public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private final RobotContainer m_robotContainer; + private final RobotContainer robotContainer; /** * This function is run when the robot is first started up and should be used for any @@ -25,7 +25,7 @@ public class Robot extends TimedRobot { public Robot() { // Instantiate our RobotContainer. This will perform all our button bindings, and put our // autonomous chooser on the dashboard. - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } /** @@ -54,11 +54,11 @@ public void disabledPeriodic() {} /** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); // schedule the autonomous command (example) - if (m_autonomousCommand != null) { - CommandScheduler.getInstance().schedule(m_autonomousCommand); + if (autonomousCommand != null) { + CommandScheduler.getInstance().schedule(autonomousCommand); } } @@ -72,8 +72,8 @@ public void teleopInit() { // teleop starts running. If you want the autonomous to // continue until interrupted by another command, remove // this line or comment it out. - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/RobotContainer.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/RobotContainer.java index 193189ff5a0..15cddc68ce1 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/RobotContainer.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/RobotContainer.java @@ -17,9 +17,9 @@ */ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final XRPDrivetrain m_xrpDrivetrain = new XRPDrivetrain(); + private final XRPDrivetrain xrpDrivetrain = new XRPDrivetrain(); - private final ExampleCommand m_autoCommand = new ExampleCommand(m_xrpDrivetrain); + private final ExampleCommand autoCommand = new ExampleCommand(xrpDrivetrain); /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { @@ -42,6 +42,6 @@ private void configureButtonBindings() {} */ public Command getAutonomousCommand() { // An ExampleCommand will run in autonomous - return m_autoCommand; + return autoCommand; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/commands/ExampleCommand.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/commands/ExampleCommand.java index f44d6c017c6..d7dec635e8c 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/commands/ExampleCommand.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/commands/ExampleCommand.java @@ -10,7 +10,7 @@ /** An example command that uses an example subsystem. */ public class ExampleCommand extends Command { @SuppressWarnings("PMD.UnusedPrivateField") - private final XRPDrivetrain m_subsystem; + private final XRPDrivetrain subsystem; /** * Creates a new ExampleCommand. @@ -18,7 +18,7 @@ public class ExampleCommand extends Command { * @param subsystem The subsystem used by this command. */ public ExampleCommand(XRPDrivetrain subsystem) { - m_subsystem = subsystem; + this.subsystem = subsystem; // Use addRequirements() here to declare subsystem dependencies. addRequirements(subsystem); } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/subsystems/XRPDrivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/subsystems/XRPDrivetrain.java index daa425c0409..09cb8ac494b 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/subsystems/XRPDrivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpcommandv2/subsystems/XRPDrivetrain.java @@ -18,44 +18,44 @@ public class XRPDrivetrain extends SubsystemBase { // The XRP has the left and right motors set to // channels 0 and 1 respectively - private final XRPMotor m_leftMotor = new XRPMotor(0); - private final XRPMotor m_rightMotor = new XRPMotor(1); + private final XRPMotor leftMotor = new XRPMotor(0); + private final XRPMotor rightMotor = new XRPMotor(1); // The XRP has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); /** Creates a new XRPDrivetrain. */ public XRPDrivetrain() { // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); // Invert right side since motor is flipped - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } @Override diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/EducationalRobot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/EducationalRobot.java index b200d25884c..3babe6b82bc 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/EducationalRobot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/EducationalRobot.java @@ -32,7 +32,7 @@ public void utility() { run(); } - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -52,7 +52,7 @@ public void startCompetition() { // Tell the DS that the robot is ready to be enabled DriverStationBackend.observeUserProgramStarting(); - while (!Thread.currentThread().isInterrupted() && !m_exit) { + while (!Thread.currentThread().isInterrupted() && !exit) { DriverStationBackend.refreshControlWordFromCache(word); modeThread.inControl(word); if (isDisabled()) { @@ -100,6 +100,6 @@ public void startCompetition() { @Override public void endCompetition() { - m_exit = true; + exit = true; } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/XRPDrivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/XRPDrivetrain.java index 7192bea5205..5d896b8b7b0 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/XRPDrivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrpeducational/XRPDrivetrain.java @@ -17,43 +17,43 @@ public class XRPDrivetrain { // The XRP has the left and right motors set to // channels 0 and 1 respectively - private final XRPMotor m_leftMotor = new XRPMotor(0); - private final XRPMotor m_rightMotor = new XRPMotor(1); + private final XRPMotor leftMotor = new XRPMotor(0); + private final XRPMotor rightMotor = new XRPMotor(1); // The XRP has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); /** Creates a new XRPDrivetrain. */ public XRPDrivetrain() { // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); // Invert right side since motor is flipped - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } } diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/Robot.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/Robot.java index 98c0d13080c..b28b0dd0571 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/Robot.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/Robot.java @@ -16,19 +16,19 @@ public class Robot extends TimedRobot { private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; - private String m_autoSelected; - private final SendableChooser m_chooser = new SendableChooser<>(); + private String autoSelected; + private final SendableChooser chooser = new SendableChooser<>(); - private final XRPDrivetrain m_drivetrain = new XRPDrivetrain(); + private final XRPDrivetrain drivetrain = new XRPDrivetrain(); /** * This function is run when the robot is first started up and should be used for any * initialization code. */ public Robot() { - m_chooser.setDefaultOption("Default Auto", kDefaultAuto); - m_chooser.addOption("My Auto", kCustomAuto); - SmartDashboard.putData("Auto choices", m_chooser); + chooser.setDefaultOption("Default Auto", kDefaultAuto); + chooser.addOption("My Auto", kCustomAuto); + SmartDashboard.putData("Auto choices", chooser); } /** @@ -53,17 +53,17 @@ public void robotPeriodic() {} */ @Override public void autonomousInit() { - m_autoSelected = m_chooser.getSelected(); - // m_autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); - System.out.println("Auto selected: " + m_autoSelected); + autoSelected = chooser.getSelected(); + // autoSelected = SmartDashboard.getString("Auto Selector", kDefaultAuto); + System.out.println("Auto selected: " + autoSelected); - m_drivetrain.resetEncoders(); + drivetrain.resetEncoders(); } /** This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { - switch (m_autoSelected) { + switch (autoSelected) { case kCustomAuto: // Put custom auto code here break; diff --git a/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/XRPDrivetrain.java b/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/XRPDrivetrain.java index 21f86df29b6..64469c70975 100644 --- a/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/XRPDrivetrain.java +++ b/wpilibjExamples/src/main/java/org/wpilib/templates/xrptimed/XRPDrivetrain.java @@ -17,43 +17,43 @@ public class XRPDrivetrain { // The XRP has the left and right motors set to // channels 0 and 1 respectively - private final XRPMotor m_leftMotor = new XRPMotor(0); - private final XRPMotor m_rightMotor = new XRPMotor(1); + private final XRPMotor leftMotor = new XRPMotor(0); + private final XRPMotor rightMotor = new XRPMotor(1); // The XRP has onboard encoders that are hardcoded // to use DIO pins 4/5 and 6/7 for the left and right - private final Encoder m_leftEncoder = new Encoder(4, 5); - private final Encoder m_rightEncoder = new Encoder(6, 7); + private final Encoder leftEncoder = new Encoder(4, 5); + private final Encoder rightEncoder = new Encoder(6, 7); // Set up the differential drive controller - private final DifferentialDrive m_diffDrive = - new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle); + private final DifferentialDrive diffDrive = + new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle); /** Creates a new XRPDrivetrain. */ public XRPDrivetrain() { // Use inches as unit for encoder distances - m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); - m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); + rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution); resetEncoders(); // Invert right side since motor is flipped - m_rightMotor.setInverted(true); + rightMotor.setInverted(true); } public void arcadeDrive(double xaxisVelocity, double zaxisRotate) { - m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); + diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate); } public void resetEncoders() { - m_leftEncoder.reset(); - m_rightEncoder.reset(); + leftEncoder.reset(); + rightEncoder.reset(); } public double getLeftDistanceInch() { - return m_leftEncoder.getDistance(); + return leftEncoder.getDistance(); } public double getRightDistanceInch() { - return m_rightEncoder.getDistance(); + return rightEncoder.getDistance(); } } diff --git a/wpilibjExamples/src/test/java/org/wpilib/examples/armsimulation/ArmSimulationTest.java b/wpilibjExamples/src/test/java/org/wpilib/examples/armsimulation/ArmSimulationTest.java index db3e45e30d7..1fe1ec284cc 100644 --- a/wpilibjExamples/src/test/java/org/wpilib/examples/armsimulation/ArmSimulationTest.java +++ b/wpilibjExamples/src/test/java/org/wpilib/examples/armsimulation/ArmSimulationTest.java @@ -25,12 +25,12 @@ @ResourceLock("timing") class ArmSimulationTest { - private Robot m_robot; - private Thread m_thread; + private Robot robot; + private Thread thread; - private PWMMotorControllerSim m_motorSim; - private EncoderSim m_encoderSim; - private JoystickSim m_joystickSim; + private PWMMotorControllerSim motorSim; + private EncoderSim encoderSim; + private JoystickSim joystickSim; @BeforeEach void startThread() { @@ -38,27 +38,27 @@ void startThread() { SimHooks.pauseTiming(); SimHooks.setProgramStarted(false); DriverStationSim.resetData(); - m_robot = new Robot(); - m_thread = new Thread(m_robot::startCompetition); - m_encoderSim = EncoderSim.createForChannel(Constants.kEncoderAChannel); - m_motorSim = new PWMMotorControllerSim(Constants.kMotorPort); - m_joystickSim = new JoystickSim(Constants.kJoystickPort); + robot = new Robot(); + thread = new Thread(robot::startCompetition); + encoderSim = EncoderSim.createForChannel(Constants.kEncoderAChannel); + motorSim = new PWMMotorControllerSim(Constants.kMotorPort); + joystickSim = new JoystickSim(Constants.kJoystickPort); - m_thread.start(); + thread.start(); SimHooks.waitForProgramStart(); } @AfterEach void stopThread() { - m_robot.endCompetition(); + robot.endCompetition(); try { - m_thread.interrupt(); - m_thread.join(); + thread.interrupt(); + thread.join(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } - m_robot.close(); - m_encoderSim.resetData(); + robot.close(); + encoderSim.resetData(); Preferences.remove(Constants.kArmPKey); Preferences.remove(Constants.kArmPositionKey); Preferences.removeAll(); @@ -80,7 +80,7 @@ void teleopTest(double setpoint) { DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - assertTrue(m_encoderSim.getInitialized()); + assertTrue(encoderSim.getInitialized()); } { @@ -88,50 +88,50 @@ void teleopTest(double setpoint) { SimHooks.stepTiming(3); // Ensure arm is still at minimum angle. - assertEquals(Constants.kMinAngleRads, m_encoderSim.getDistance(), 2.0); + assertEquals(Constants.kMinAngleRads, encoderSim.getDistance(), 2.0); } { // Press button to reach setpoint - m_joystickSim.setTrigger(true); - m_joystickSim.notifyNewData(); + joystickSim.setTrigger(true); + joystickSim.notifyNewData(); // advance 75 timesteps SimHooks.stepTiming(1.5); - assertEquals(setpoint, Units.radiansToDegrees(m_encoderSim.getDistance()), 2.0); + assertEquals(setpoint, Units.radiansToDegrees(encoderSim.getDistance()), 2.0); // advance 25 timesteps to see setpoint is held. SimHooks.stepTiming(0.5); - assertEquals(setpoint, Units.radiansToDegrees(m_encoderSim.getDistance()), 2.0); + assertEquals(setpoint, Units.radiansToDegrees(encoderSim.getDistance()), 2.0); } { // Unpress the button to go back down - m_joystickSim.setTrigger(false); - m_joystickSim.notifyNewData(); + joystickSim.setTrigger(false); + joystickSim.notifyNewData(); // advance 150 timesteps SimHooks.stepTiming(3.0); - assertEquals(Constants.kMinAngleRads, m_encoderSim.getDistance(), 2.0); + assertEquals(Constants.kMinAngleRads, encoderSim.getDistance(), 2.0); } { // Press button to go back up - m_joystickSim.setTrigger(true); - m_joystickSim.notifyNewData(); + joystickSim.setTrigger(true); + joystickSim.notifyNewData(); // advance 75 timesteps SimHooks.stepTiming(1.5); - assertEquals(setpoint, Units.radiansToDegrees(m_encoderSim.getDistance()), 2.0); + assertEquals(setpoint, Units.radiansToDegrees(encoderSim.getDistance()), 2.0); // advance 25 timesteps to see setpoint is held. SimHooks.stepTiming(0.5); - assertEquals(setpoint, Units.radiansToDegrees(m_encoderSim.getDistance()), 2.0); + assertEquals(setpoint, Units.radiansToDegrees(encoderSim.getDistance()), 2.0); } { @@ -142,8 +142,8 @@ void teleopTest(double setpoint) { // advance 75 timesteps SimHooks.stepTiming(3.5); - assertEquals(0.0, m_motorSim.getThrottle(), 0.01); - assertEquals(Constants.kMinAngleRads, m_encoderSim.getDistance(), 2.0); + assertEquals(0.0, motorSim.getThrottle(), 0.01); + assertEquals(Constants.kMinAngleRads, encoderSim.getDistance(), 2.0); } } } diff --git a/wpilibjExamples/src/test/java/org/wpilib/examples/elevatorsimulation/ElevatorSimulationTest.java b/wpilibjExamples/src/test/java/org/wpilib/examples/elevatorsimulation/ElevatorSimulationTest.java index ec9b775004b..ca75b5d9403 100644 --- a/wpilibjExamples/src/test/java/org/wpilib/examples/elevatorsimulation/ElevatorSimulationTest.java +++ b/wpilibjExamples/src/test/java/org/wpilib/examples/elevatorsimulation/ElevatorSimulationTest.java @@ -22,12 +22,12 @@ @ResourceLock("timing") class ElevatorSimulationTest { - private Robot m_robot; - private Thread m_thread; + private Robot robot; + private Thread thread; - private PWMMotorControllerSim m_motorSim; - private EncoderSim m_encoderSim; - private JoystickSim m_joystickSim; + private PWMMotorControllerSim motorSim; + private EncoderSim encoderSim; + private JoystickSim joystickSim; @BeforeEach void startThread() { @@ -35,27 +35,27 @@ void startThread() { SimHooks.pauseTiming(); SimHooks.setProgramStarted(false); DriverStationSim.resetData(); - m_robot = new Robot(); - m_thread = new Thread(m_robot::startCompetition); - m_encoderSim = EncoderSim.createForChannel(Constants.kEncoderAChannel); - m_motorSim = new PWMMotorControllerSim(Constants.kMotorPort); - m_joystickSim = new JoystickSim(Constants.kJoystickPort); + robot = new Robot(); + thread = new Thread(robot::startCompetition); + encoderSim = EncoderSim.createForChannel(Constants.kEncoderAChannel); + motorSim = new PWMMotorControllerSim(Constants.kMotorPort); + joystickSim = new JoystickSim(Constants.kJoystickPort); - m_thread.start(); + thread.start(); SimHooks.waitForProgramStart(); } @AfterEach void stopThread() { - m_robot.endCompetition(); + robot.endCompetition(); try { - m_thread.interrupt(); - m_thread.join(); + thread.interrupt(); + thread.join(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } - m_robot.close(); - m_encoderSim.resetData(); + robot.close(); + encoderSim.resetData(); RoboRioSim.resetData(); DriverStationSim.resetData(); DriverStationSim.notifyNewData(); @@ -69,7 +69,7 @@ void teleopTest() { DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - assertTrue(m_encoderSim.getInitialized()); + assertTrue(encoderSim.getInitialized()); } { @@ -77,50 +77,50 @@ void teleopTest() { SimHooks.stepTiming(1); // Ensure elevator is still at 0. - assertEquals(0.0, m_encoderSim.getDistance(), 0.05); + assertEquals(0.0, encoderSim.getDistance(), 0.05); } { // Press button to reach setpoint - m_joystickSim.setTrigger(true); - m_joystickSim.notifyNewData(); + joystickSim.setTrigger(true); + joystickSim.notifyNewData(); // advance 75 timesteps SimHooks.stepTiming(1.5); - assertEquals(Constants.kSetpoint, m_encoderSim.getDistance(), 0.05); + assertEquals(Constants.kSetpoint, encoderSim.getDistance(), 0.05); // advance 25 timesteps to see setpoint is held. SimHooks.stepTiming(0.5); - assertEquals(Constants.kSetpoint, m_encoderSim.getDistance(), 0.05); + assertEquals(Constants.kSetpoint, encoderSim.getDistance(), 0.05); } { // Unpress the button to go back down - m_joystickSim.setTrigger(false); - m_joystickSim.notifyNewData(); + joystickSim.setTrigger(false); + joystickSim.notifyNewData(); // advance 75 timesteps SimHooks.stepTiming(1.5); - assertEquals(0.0, m_encoderSim.getDistance(), 0.05); + assertEquals(0.0, encoderSim.getDistance(), 0.05); } { // Press button to go back up - m_joystickSim.setTrigger(true); - m_joystickSim.notifyNewData(); + joystickSim.setTrigger(true); + joystickSim.notifyNewData(); // advance 75 timesteps SimHooks.stepTiming(1.5); - assertEquals(Constants.kSetpoint, m_encoderSim.getDistance(), 0.05); + assertEquals(Constants.kSetpoint, encoderSim.getDistance(), 0.05); // advance 25 timesteps to see setpoint is held. SimHooks.stepTiming(0.5); - assertEquals(Constants.kSetpoint, m_encoderSim.getDistance(), 0.05); + assertEquals(Constants.kSetpoint, encoderSim.getDistance(), 0.05); } { @@ -131,8 +131,8 @@ void teleopTest() { // advance 75 timesteps SimHooks.stepTiming(1.5); - assertEquals(0.0, m_motorSim.getThrottle(), 0.05); - assertEquals(0.0, m_encoderSim.getDistance(), 0.05); + assertEquals(0.0, motorSim.getThrottle(), 0.05); + assertEquals(0.0, encoderSim.getDistance(), 0.05); } } } diff --git a/wpilibjExamples/src/test/java/org/wpilib/examples/unittest/subsystems/IntakeTest.java b/wpilibjExamples/src/test/java/org/wpilib/examples/unittest/subsystems/IntakeTest.java index dbe57359ca2..ebf549d5af9 100644 --- a/wpilibjExamples/src/test/java/org/wpilib/examples/unittest/subsystems/IntakeTest.java +++ b/wpilibjExamples/src/test/java/org/wpilib/examples/unittest/subsystems/IntakeTest.java @@ -18,18 +18,18 @@ class IntakeTest { static final double DELTA = 1e-2; // acceptable deviation range - Intake m_intake; - PWMMotorControllerSim m_simMotor; - DoubleSolenoidSim m_simPiston; + Intake intake; + PWMMotorControllerSim simMotor; + DoubleSolenoidSim simPiston; @BeforeEach // this method will run before each test void setup() { assert HAL.initialize(500, 0); // initialize the HAL, crash if failed - m_intake = new Intake(); // create our intake - m_simMotor = + intake = new Intake(); // create our intake + simMotor = new PWMMotorControllerSim( IntakeConstants.kMotorPort); // create our simulation PWM motor controller - m_simPiston = + simPiston = new DoubleSolenoidSim( PneumaticsModuleType.CTRE_PCM, IntakeConstants.kPistonFwdChannel, @@ -39,33 +39,33 @@ void setup() { @SuppressWarnings("PMD.SignatureDeclareThrowsException") @AfterEach // this method will run after each test void shutdown() throws Exception { - m_intake.close(); // destroy our intake object + intake.close(); // destroy our intake object } @Test // marks this method as a test void doesntWorkWhenClosed() { - m_intake.retract(); // close the intake - m_intake.activate(0.5); // try to activate the motor + intake.retract(); // close the intake + intake.activate(0.5); // try to activate the motor assertEquals( - 0.0, m_simMotor.getThrottle(), DELTA); // make sure that the value set to the motor is 0 + 0.0, simMotor.getThrottle(), DELTA); // make sure that the value set to the motor is 0 } @Test void worksWhenOpen() { - m_intake.deploy(); - m_intake.activate(0.5); - assertEquals(0.5, m_simMotor.getThrottle(), DELTA); + intake.deploy(); + intake.activate(0.5); + assertEquals(0.5, simMotor.getThrottle(), DELTA); } @Test void retractTest() { - m_intake.retract(); - assertEquals(DoubleSolenoid.Value.REVERSE, m_simPiston.get()); + intake.retract(); + assertEquals(DoubleSolenoid.Value.REVERSE, simPiston.get()); } @Test void deployTest() { - m_intake.deploy(); - assertEquals(DoubleSolenoid.Value.FORWARD, m_simPiston.get()); + intake.deploy(); + assertEquals(DoubleSolenoid.Value.FORWARD, simPiston.get()); } } diff --git a/wpilibjExamples/src/test/java/org/wpilib/snippets/digitalcommunication/DigitalCommunicationTest.java b/wpilibjExamples/src/test/java/org/wpilib/snippets/digitalcommunication/DigitalCommunicationTest.java index 51051b649f4..1c9c985803e 100644 --- a/wpilibjExamples/src/test/java/org/wpilib/snippets/digitalcommunication/DigitalCommunicationTest.java +++ b/wpilibjExamples/src/test/java/org/wpilib/snippets/digitalcommunication/DigitalCommunicationTest.java @@ -23,12 +23,12 @@ @ResourceLock("timing") class DigitalCommunicationTest { - private Robot m_robot; - private Thread m_thread; - private final DIOSim m_allianceOutput = new DIOSim(Robot.kAlliancePort); - private final DIOSim m_enabledOutput = new DIOSim(Robot.kEnabledPort); - private final DIOSim m_autonomousOutput = new DIOSim(Robot.kAutonomousPort); - private final DIOSim m_alertOutput = new DIOSim(Robot.kAlertPort); + private Robot robot; + private Thread thread; + private final DIOSim allianceOutput = new DIOSim(Robot.kAlliancePort); + private final DIOSim enabledOutput = new DIOSim(Robot.kEnabledPort); + private final DIOSim autonomousOutput = new DIOSim(Robot.kAutonomousPort); + private final DIOSim alertOutput = new DIOSim(Robot.kAlertPort); @BeforeEach void startThread() { @@ -36,26 +36,26 @@ void startThread() { SimHooks.pauseTiming(); SimHooks.setProgramStarted(false); DriverStationSim.resetData(); - m_robot = new Robot(); - m_thread = new Thread(m_robot::startCompetition); - m_thread.start(); + robot = new Robot(); + thread = new Thread(robot::startCompetition); + thread.start(); SimHooks.waitForProgramStart(); } @AfterEach void stopThread() { - m_robot.endCompetition(); + robot.endCompetition(); try { - m_thread.interrupt(); - m_thread.join(); + thread.interrupt(); + thread.join(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } - m_robot.close(); - m_allianceOutput.resetData(); - m_enabledOutput.resetData(); - m_autonomousOutput.resetData(); - m_alertOutput.resetData(); + robot.close(); + allianceOutput.resetData(); + enabledOutput.resetData(); + autonomousOutput.resetData(); + alertOutput.resetData(); } @EnumSource(AllianceStationID.class) @@ -64,12 +64,12 @@ void allianceTest(AllianceStationID alliance) { DriverStationSim.setAllianceStationId(alliance); DriverStationSim.notifyNewData(); - assertTrue(m_allianceOutput.getInitialized()); - assertFalse(m_allianceOutput.getIsInput()); + assertTrue(allianceOutput.getInitialized()); + assertFalse(allianceOutput.getIsInput()); SimHooks.stepTiming(0.02); - assertEquals(alliance.name().startsWith("RED"), m_allianceOutput.getValue()); + assertEquals(alliance.name().startsWith("RED"), allianceOutput.getValue()); } @ValueSource(booleans = {true, false}) @@ -78,12 +78,12 @@ void enabledTest(boolean enabled) { DriverStationSim.setEnabled(enabled); DriverStationSim.notifyNewData(); - assertTrue(m_enabledOutput.getInitialized()); - assertFalse(m_enabledOutput.getIsInput()); + assertTrue(enabledOutput.getInitialized()); + assertFalse(enabledOutput.getIsInput()); SimHooks.stepTiming(0.02); - assertEquals(enabled, m_enabledOutput.getValue()); + assertEquals(enabled, enabledOutput.getValue()); } @ValueSource(booleans = {true, false}) @@ -92,12 +92,12 @@ void autonomousTest(boolean autonomous) { DriverStationSim.setRobotMode(autonomous ? RobotMode.AUTONOMOUS : RobotMode.TELEOPERATED); DriverStationSim.notifyNewData(); - assertTrue(m_autonomousOutput.getInitialized()); - assertFalse(m_autonomousOutput.getIsInput()); + assertTrue(autonomousOutput.getInitialized()); + assertFalse(autonomousOutput.getIsInput()); SimHooks.stepTiming(0.02); - assertEquals(autonomous, m_autonomousOutput.getValue()); + assertEquals(autonomous, autonomousOutput.getValue()); } @ValueSource(doubles = {45.0, 27.0, 23.0}) @@ -106,11 +106,11 @@ void alertTest(double matchTime) { DriverStationSim.setMatchTime(matchTime); DriverStationSim.notifyNewData(); - assertTrue(m_alertOutput.getInitialized()); - assertFalse(m_alertOutput.getIsInput()); + assertTrue(alertOutput.getInitialized()); + assertFalse(alertOutput.getIsInput()); SimHooks.stepTiming(0.02); - assertEquals(matchTime <= 30 && matchTime >= 25, m_alertOutput.getValue()); + assertEquals(matchTime <= 30 && matchTime >= 25, alertOutput.getValue()); } } diff --git a/wpilibjExamples/src/test/java/org/wpilib/snippets/i2ccommunication/I2CCommunicationTest.java b/wpilibjExamples/src/test/java/org/wpilib/snippets/i2ccommunication/I2CCommunicationTest.java index f2313df8869..d1e493ae4e5 100644 --- a/wpilibjExamples/src/test/java/org/wpilib/snippets/i2ccommunication/I2CCommunicationTest.java +++ b/wpilibjExamples/src/test/java/org/wpilib/snippets/i2ccommunication/I2CCommunicationTest.java @@ -28,11 +28,11 @@ @ResourceLock("timing") class I2CCommunicationTest { - private Robot m_robot; - private Thread m_thread; - private final I2CSim m_i2c = new I2CSim(Robot.kPort.value); - private CompletableFuture m_future; - private CallbackStore m_callback; + private Robot robot; + private Thread thread; + private final I2CSim i2c = new I2CSim(Robot.kPort.value); + private CompletableFuture future; + private CallbackStore callback; @BeforeEach void startThread() { @@ -40,29 +40,29 @@ void startThread() { SimHooks.pauseTiming(); SimHooks.setProgramStarted(false); DriverStationSim.resetData(); - m_future = new CompletableFuture<>(); - m_callback = - m_i2c.registerWriteCallback( + future = new CompletableFuture<>(); + callback = + i2c.registerWriteCallback( (name, buffer, count) -> - m_future.complete(new String(buffer, 0, count, StandardCharsets.UTF_8))); - m_robot = new Robot(); - m_thread = new Thread(m_robot::startCompetition); - m_thread.start(); + future.complete(new String(buffer, 0, count, StandardCharsets.UTF_8))); + robot = new Robot(); + thread = new Thread(robot::startCompetition); + thread.start(); SimHooks.waitForProgramStart(); } @AfterEach void stopThread() { - m_robot.endCompetition(); + robot.endCompetition(); try { - m_thread.interrupt(); - m_thread.join(); + thread.interrupt(); + thread.join(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } - m_robot.close(); - m_callback.close(); - m_i2c.resetData(); + robot.close(); + callback.close(); + i2c.resetData(); } @EnumSource(AllianceStationID.class) @@ -71,11 +71,11 @@ void allianceTest(AllianceStationID alliance) { DriverStationSim.setAllianceStationId(alliance); DriverStationSim.notifyNewData(); - assertTrue(m_i2c.getInitialized()); + assertTrue(i2c.getInitialized()); SimHooks.stepTiming(0.02); - String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> m_future.get()); + String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> future.get()); char expected = alliance.name().startsWith("RED") ? 'R' : 'B'; if (alliance.name().startsWith("UNKNOWN")) { expected = 'U'; @@ -90,11 +90,11 @@ void enabledTest(boolean enabled) { DriverStationSim.setEnabled(enabled); DriverStationSim.notifyNewData(); - assertTrue(m_i2c.getInitialized()); + assertTrue(i2c.getInitialized()); SimHooks.stepTiming(0.02); - String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> m_future.get()); + String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> future.get()); char expected = enabled ? 'E' : 'D'; assertEquals(expected, str.charAt(1)); @@ -106,11 +106,11 @@ void autonomousTest(boolean autonomous) { DriverStationSim.setRobotMode(autonomous ? RobotMode.AUTONOMOUS : RobotMode.TELEOPERATED); DriverStationSim.notifyNewData(); - assertTrue(m_i2c.getInitialized()); + assertTrue(i2c.getInitialized()); SimHooks.stepTiming(0.02); - String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> m_future.get()); + String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> future.get()); char expected = autonomous ? 'A' : 'T'; assertEquals(expected, str.charAt(2)); @@ -121,11 +121,11 @@ void autonomousTest(boolean autonomous) { void matchTimeTest(double matchTime) { DriverStationSim.setMatchTime(matchTime); DriverStationSim.notifyNewData(); - assertTrue(m_i2c.getInitialized()); + assertTrue(i2c.getInitialized()); SimHooks.stepTiming(0.02); - String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> m_future.get()); + String str = assertTimeoutPreemptively(Duration.ofMillis(20L), () -> future.get()); String expected = String.format("%03d", (int) MatchState.getMatchTime()); assertEquals(expected, str.substring(3));