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 b2f36c1d0c..394014381b 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.util.RawFrame; 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("PMD.PublicFieldNamingConvention") 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 6bba9cc671..22aa4f09b6 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 @@ import org.wpilib.vision.apriltag.jni.AprilTagJNI; */ 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 class AprilTagDetector implements AutoCloseable { } /** 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 62b878ed9b..00aca6bb1f 100644 --- a/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFieldLayout.java @@ -216,19 +216,19 @@ public class AprilTagFieldLayout { * @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.m_resourceFile); + field.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 return new AprilTagFieldLayout( - field.m_fieldLayout.getTags(), - field.m_fieldLayout.getFieldLength(), - field.m_fieldLayout.getFieldWidth()); + field.fieldLayout.getTags(), + field.fieldLayout.getFieldLength(), + field.fieldLayout.getFieldWidth()); } /** @@ -264,11 +264,9 @@ public class AprilTagFieldLayout { } 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/AprilTagFields.java b/apriltag/src/main/java/org/wpilib/vision/apriltag/AprilTagFields.java index f0c75bc2b2..fe3ce21a47 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; + AprilTagFieldLayout fieldLayout; AprilTagFields(String resourceFile) { - m_resourceFile = kBaseResourceDir + resourceFile; + this.resourceFile = kBaseResourceDir + resourceFile; } } 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 54727e1a4f..2025e069c8 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 @@ package org.wpilib.vision.apriltag; 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 224b78f3ef..2c9c3f1d31 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 @@ import org.wpilib.vision.apriltag.jni.AprilTagJNI; /** 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/apriltag/src/test/java/org/wpilib/vision/apriltag/AprilTagDetectorTest.java b/apriltag/src/test/java/org/wpilib/vision/apriltag/AprilTagDetectorTest.java index 1678997f1e..b6aeab39fc 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.math.util.Units; import org.wpilib.util.runtime.RuntimeLoader; class AprilTagDetectorTest { - @SuppressWarnings("MemberName") AprilTagDetector detector; @BeforeAll diff --git a/cameraserver/multiCameraServer/src/main/java/org/wpilib/Main.java b/cameraserver/multiCameraServer/src/main/java/org/wpilib/Main.java index 8da41bb340..0ab2e7c226 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 @@ import org.wpilib.vision.stream.CameraServer; 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/commandsv2/src/main/java/org/wpilib/command2/sysid/SysIdRoutine.java b/commandsv2/src/main/java/org/wpilib/command2/sysid/SysIdRoutine.java index 56fdd5c90d..30d67e0021 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 class SysIdRoutine extends SysIdRoutineLog { 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 class SysIdRoutine extends SysIdRoutineLog { */ 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 class SysIdRoutine extends SysIdRoutineLog { */ 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 class SysIdRoutine extends SysIdRoutineLog { 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 class SysIdRoutine extends SysIdRoutineLog { 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/commandsv2/src/main/native/cpp/frc2/command/sysid/SysIdRoutine.cpp b/commandsv2/src/main/native/cpp/frc2/command/sysid/SysIdRoutine.cpp index 089fdb8c92..07ae68f2dc 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 9b78ee611f..bcfff9a3d5 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/cscore/src/main/java/org/wpilib/vision/camera/UsbCameraInfo.java b/cscore/src/main/java/org/wpilib/vision/camera/UsbCameraInfo.java index dc164b4854..503a27e752 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 61657eb413..9977af91fd 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 24f9e98fe6..34e8650380 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 java.util.Objects; 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 b2f0638851..c7af37d341 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 class DataLogRecord { * 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 class DataLogRecord { * 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/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java b/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java index 1e0f33acfe..3bc33cc0b4 100644 --- a/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java +++ b/datalog/src/test/java/org/wpilib/datalog/DataLogTest.java @@ -119,7 +119,6 @@ class DataLogTest { } } - @SuppressWarnings("MemberName") private static int cloneCalls; static class CloneableThing implements StructSerializable, Cloneable { @@ -201,10 +200,8 @@ class DataLogTest { public static final ThingStruct struct = new ThingStruct(); } - @SuppressWarnings("MemberName") private ByteArrayOutputStream data; - @SuppressWarnings("MemberName") private DataLog log; @BeforeEach 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 5e046eb87a..91d9753bc3 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 @@ import org.wpilib.units.measure.Time; * 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/fields/src/main/java/org/wpilib/fields/FieldConfig.java b/fields/src/main/java/org/wpilib/fields/FieldConfig.java index bdbfd6668c..9891602fac 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 @@ import java.nio.file.Path; 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 b0f7c50642..9a46992283 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/CANAPITypes.java b/hal/src/main/java/org/wpilib/hardware/hal/CANAPITypes.java index df13e5c67f..403bc8ce53 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 final class CANAPITypes { FIRMWARE_UPDATE(31); /** The device type ID. */ - @SuppressWarnings("MemberName") public final int id; CANDeviceType(int id) { @@ -118,7 +117,6 @@ public final class CANAPITypes { 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 3b8eb6aee7..2c73881376 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/OpModeOption.java b/hal/src/main/java/org/wpilib/hardware/hal/OpModeOption.java index 0e471823d8..c003cc1a7b 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 @@ package org.wpilib.hardware.hal; /** 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 2a796f0682..701b2c9f9c 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionFaults.java @@ -8,88 +8,87 @@ package org.wpilib.hardware.hal; * Faults for a PowerDistribution device. These faults are only active while the condition is * active. */ -@SuppressWarnings("MemberName") public class PowerDistributionFaults { /** Breaker fault on channel 0. */ - public final boolean Channel0BreakerFault; + public final boolean channel0BreakerFault; /** Breaker fault on channel 1. */ - public final boolean Channel1BreakerFault; + public final boolean channel1BreakerFault; /** Breaker fault on channel 2. */ - public final boolean Channel2BreakerFault; + public final boolean channel2BreakerFault; /** Breaker fault on channel 3. */ - public final boolean Channel3BreakerFault; + public final boolean channel3BreakerFault; /** Breaker fault on channel 4. */ - public final boolean Channel4BreakerFault; + public final boolean channel4BreakerFault; /** Breaker fault on channel 5. */ - public final boolean Channel5BreakerFault; + public final boolean channel5BreakerFault; /** Breaker fault on channel 6. */ - public final boolean Channel6BreakerFault; + public final boolean channel6BreakerFault; /** Breaker fault on channel 7. */ - public final boolean Channel7BreakerFault; + public final boolean channel7BreakerFault; /** Breaker fault on channel 8. */ - public final boolean Channel8BreakerFault; + public final boolean channel8BreakerFault; /** Breaker fault on channel 9. */ - public final boolean Channel9BreakerFault; + public final boolean channel9BreakerFault; /** Breaker fault on channel 10. */ - public final boolean Channel10BreakerFault; + public final boolean channel10BreakerFault; /** Breaker fault on channel 11. */ - public final boolean Channel11BreakerFault; + public final boolean channel11BreakerFault; /** Breaker fault on channel 12. */ - public final boolean Channel12BreakerFault; + public final boolean channel12BreakerFault; /** Breaker fault on channel 13. */ - public final boolean Channel13BreakerFault; + public final boolean channel13BreakerFault; /** Breaker fault on channel 14. */ - public final boolean Channel14BreakerFault; + public final boolean channel14BreakerFault; /** Breaker fault on channel 15. */ - public final boolean Channel15BreakerFault; + public final boolean channel15BreakerFault; /** Breaker fault on channel 16. */ - public final boolean Channel16BreakerFault; + public final boolean channel16BreakerFault; /** Breaker fault on channel 17. */ - public final boolean Channel17BreakerFault; + public final boolean channel17BreakerFault; /** Breaker fault on channel 18. */ - public final boolean Channel18BreakerFault; + public final boolean channel18BreakerFault; /** Breaker fault on channel 19. */ - public final boolean Channel19BreakerFault; + public final boolean channel19BreakerFault; /** Breaker fault on channel 20. */ - public final boolean Channel20BreakerFault; + public final boolean channel20BreakerFault; /** Breaker fault on channel 21. */ - public final boolean Channel21BreakerFault; + public final boolean channel21BreakerFault; /** Breaker fault on channel 22. */ - public final boolean Channel22BreakerFault; + public final boolean channel22BreakerFault; /** Breaker fault on channel 23. */ - public final boolean Channel23BreakerFault; + public final boolean channel23BreakerFault; /** The input voltage is below the minimum voltage. */ - public final boolean Brownout; + public final boolean brownout; /** A warning was raised by the device's CAN controller. */ - public final boolean CanWarning; + public final boolean canWarning; /** The hardware on the device has malfunctioned. */ - public final boolean HardwareFault; + public final boolean hardwareFault; /** * Gets whether there is a breaker fault at the specified channel. @@ -101,30 +100,30 @@ public class PowerDistributionFaults { */ public final boolean getBreakerFault(int channel) { return switch (channel) { - case 0 -> Channel0BreakerFault; - case 1 -> Channel1BreakerFault; - case 2 -> Channel2BreakerFault; - case 3 -> Channel3BreakerFault; - case 4 -> Channel4BreakerFault; - case 5 -> Channel5BreakerFault; - case 6 -> Channel6BreakerFault; - case 7 -> Channel7BreakerFault; - case 8 -> Channel8BreakerFault; - case 9 -> Channel9BreakerFault; - case 10 -> Channel10BreakerFault; - case 11 -> Channel11BreakerFault; - case 12 -> Channel12BreakerFault; - case 13 -> Channel13BreakerFault; - case 14 -> Channel14BreakerFault; - case 15 -> Channel15BreakerFault; - case 16 -> Channel16BreakerFault; - case 17 -> Channel17BreakerFault; - case 18 -> Channel18BreakerFault; - case 19 -> Channel19BreakerFault; - case 20 -> Channel20BreakerFault; - case 21 -> Channel21BreakerFault; - case 22 -> Channel22BreakerFault; - case 23 -> Channel23BreakerFault; + case 0 -> channel0BreakerFault; + case 1 -> channel1BreakerFault; + case 2 -> channel2BreakerFault; + case 3 -> channel3BreakerFault; + case 4 -> channel4BreakerFault; + case 5 -> channel5BreakerFault; + case 6 -> channel6BreakerFault; + case 7 -> channel7BreakerFault; + case 8 -> channel8BreakerFault; + case 9 -> channel9BreakerFault; + case 10 -> channel10BreakerFault; + case 11 -> channel11BreakerFault; + case 12 -> channel12BreakerFault; + case 13 -> channel13BreakerFault; + case 14 -> channel14BreakerFault; + case 15 -> channel15BreakerFault; + case 16 -> channel16BreakerFault; + case 17 -> channel17BreakerFault; + case 18 -> channel18BreakerFault; + case 19 -> channel19BreakerFault; + case 20 -> channel20BreakerFault; + case 21 -> channel21BreakerFault; + case 22 -> channel22BreakerFault; + case 23 -> channel23BreakerFault; default -> throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!"); }; @@ -136,32 +135,32 @@ public class PowerDistributionFaults { * @param faults faults */ public PowerDistributionFaults(int faults) { - Channel0BreakerFault = (faults & 0x1) != 0; - Channel1BreakerFault = (faults & 0x2) != 0; - Channel2BreakerFault = (faults & 0x4) != 0; - Channel3BreakerFault = (faults & 0x8) != 0; - Channel4BreakerFault = (faults & 0x10) != 0; - Channel5BreakerFault = (faults & 0x20) != 0; - Channel6BreakerFault = (faults & 0x40) != 0; - Channel7BreakerFault = (faults & 0x80) != 0; - Channel8BreakerFault = (faults & 0x100) != 0; - Channel9BreakerFault = (faults & 0x200) != 0; - Channel10BreakerFault = (faults & 0x400) != 0; - Channel11BreakerFault = (faults & 0x800) != 0; - Channel12BreakerFault = (faults & 0x1000) != 0; - Channel13BreakerFault = (faults & 0x2000) != 0; - Channel14BreakerFault = (faults & 0x4000) != 0; - Channel15BreakerFault = (faults & 0x8000) != 0; - Channel16BreakerFault = (faults & 0x10000) != 0; - Channel17BreakerFault = (faults & 0x20000) != 0; - Channel18BreakerFault = (faults & 0x40000) != 0; - Channel19BreakerFault = (faults & 0x80000) != 0; - Channel20BreakerFault = (faults & 0x100000) != 0; - Channel21BreakerFault = (faults & 0x200000) != 0; - Channel22BreakerFault = (faults & 0x400000) != 0; - Channel23BreakerFault = (faults & 0x800000) != 0; - Brownout = (faults & 0x1000000) != 0; - CanWarning = (faults & 0x2000000) != 0; - HardwareFault = (faults & 0x4000000) != 0; + channel0BreakerFault = (faults & 0x1) != 0; + channel1BreakerFault = (faults & 0x2) != 0; + channel2BreakerFault = (faults & 0x4) != 0; + channel3BreakerFault = (faults & 0x8) != 0; + channel4BreakerFault = (faults & 0x10) != 0; + channel5BreakerFault = (faults & 0x20) != 0; + channel6BreakerFault = (faults & 0x40) != 0; + channel7BreakerFault = (faults & 0x80) != 0; + channel8BreakerFault = (faults & 0x100) != 0; + channel9BreakerFault = (faults & 0x200) != 0; + channel10BreakerFault = (faults & 0x400) != 0; + channel11BreakerFault = (faults & 0x800) != 0; + channel12BreakerFault = (faults & 0x1000) != 0; + channel13BreakerFault = (faults & 0x2000) != 0; + channel14BreakerFault = (faults & 0x4000) != 0; + channel15BreakerFault = (faults & 0x8000) != 0; + channel16BreakerFault = (faults & 0x10000) != 0; + channel17BreakerFault = (faults & 0x20000) != 0; + channel18BreakerFault = (faults & 0x40000) != 0; + channel19BreakerFault = (faults & 0x80000) != 0; + channel20BreakerFault = (faults & 0x100000) != 0; + channel21BreakerFault = (faults & 0x200000) != 0; + channel22BreakerFault = (faults & 0x400000) != 0; + channel23BreakerFault = (faults & 0x800000) != 0; + brownout = (faults & 0x1000000) != 0; + canWarning = (faults & 0x2000000) != 0; + hardwareFault = (faults & 0x4000000) != 0; } } 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 32eca38281..6baa24e926 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionStickyFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/PowerDistributionStickyFaults.java @@ -8,97 +8,96 @@ package org.wpilib.hardware.hal; * Sticky faults for a PowerDistribution device. These faults will remain active until they are * reset by the user. */ -@SuppressWarnings("MemberName") public class PowerDistributionStickyFaults { /** Breaker fault on channel 0. */ - public final boolean Channel0BreakerFault; + public final boolean channel0BreakerFault; /** Breaker fault on channel 1. */ - public final boolean Channel1BreakerFault; + public final boolean channel1BreakerFault; /** Breaker fault on channel 2. */ - public final boolean Channel2BreakerFault; + public final boolean channel2BreakerFault; /** Breaker fault on channel 3. */ - public final boolean Channel3BreakerFault; + public final boolean channel3BreakerFault; /** Breaker fault on channel 4. */ - public final boolean Channel4BreakerFault; + public final boolean channel4BreakerFault; /** Breaker fault on channel 5. */ - public final boolean Channel5BreakerFault; + public final boolean channel5BreakerFault; /** Breaker fault on channel 6. */ - public final boolean Channel6BreakerFault; + public final boolean channel6BreakerFault; /** Breaker fault on channel 7. */ - public final boolean Channel7BreakerFault; + public final boolean channel7BreakerFault; /** Breaker fault on channel 8. */ - public final boolean Channel8BreakerFault; + public final boolean channel8BreakerFault; /** Breaker fault on channel 9. */ - public final boolean Channel9BreakerFault; + public final boolean channel9BreakerFault; /** Breaker fault on channel 10. */ - public final boolean Channel10BreakerFault; + public final boolean channel10BreakerFault; /** Breaker fault on channel 11. */ - public final boolean Channel11BreakerFault; + public final boolean channel11BreakerFault; /** Breaker fault on channel 12. */ - public final boolean Channel12BreakerFault; + public final boolean channel12BreakerFault; /** Breaker fault on channel 13. */ - public final boolean Channel13BreakerFault; + public final boolean channel13BreakerFault; /** Breaker fault on channel 14. */ - public final boolean Channel14BreakerFault; + public final boolean channel14BreakerFault; /** Breaker fault on channel 15. */ - public final boolean Channel15BreakerFault; + public final boolean channel15BreakerFault; /** Breaker fault on channel 16. */ - public final boolean Channel16BreakerFault; + public final boolean channel16BreakerFault; /** Breaker fault on channel 17. */ - public final boolean Channel17BreakerFault; + public final boolean channel17BreakerFault; /** Breaker fault on channel 18. */ - public final boolean Channel18BreakerFault; + public final boolean channel18BreakerFault; /** Breaker fault on channel 19. */ - public final boolean Channel19BreakerFault; + public final boolean channel19BreakerFault; /** Breaker fault on channel 20. */ - public final boolean Channel20BreakerFault; + public final boolean channel20BreakerFault; /** Breaker fault on channel 21. */ - public final boolean Channel21BreakerFault; + public final boolean channel21BreakerFault; /** Breaker fault on channel 22. */ - public final boolean Channel22BreakerFault; + public final boolean channel22BreakerFault; /** Breaker fault on channel 23. */ - public final boolean Channel23BreakerFault; + public final boolean channel23BreakerFault; /** The input voltage was below the minimum voltage. */ - public final boolean Brownout; + public final boolean brownout; /** A warning was raised by the device's CAN controller. */ - public final boolean CanWarning; + public final boolean canWarning; /** The device's CAN controller experienced a "Bus Off" event. */ - public final boolean CanBusOff; + public final boolean canBusOff; /** The hardware on the device has malfunctioned. */ - public final boolean HardwareFault; + public final boolean hardwareFault; /** The firmware on the device has malfunctioned. */ - public final boolean FirmwareFault; + public final boolean firmwareFault; /** The device has rebooted. */ - public final boolean HasReset; + public final boolean hasReset; /** * Gets whether there is a sticky breaker fault at the specified channel. @@ -110,30 +109,30 @@ public class PowerDistributionStickyFaults { */ public final boolean getBreakerFault(int channel) { return switch (channel) { - case 0 -> Channel0BreakerFault; - case 1 -> Channel1BreakerFault; - case 2 -> Channel2BreakerFault; - case 3 -> Channel3BreakerFault; - case 4 -> Channel4BreakerFault; - case 5 -> Channel5BreakerFault; - case 6 -> Channel6BreakerFault; - case 7 -> Channel7BreakerFault; - case 8 -> Channel8BreakerFault; - case 9 -> Channel9BreakerFault; - case 10 -> Channel10BreakerFault; - case 11 -> Channel11BreakerFault; - case 12 -> Channel12BreakerFault; - case 13 -> Channel13BreakerFault; - case 14 -> Channel14BreakerFault; - case 15 -> Channel15BreakerFault; - case 16 -> Channel16BreakerFault; - case 17 -> Channel17BreakerFault; - case 18 -> Channel18BreakerFault; - case 19 -> Channel19BreakerFault; - case 20 -> Channel20BreakerFault; - case 21 -> Channel21BreakerFault; - case 22 -> Channel22BreakerFault; - case 23 -> Channel23BreakerFault; + case 0 -> channel0BreakerFault; + case 1 -> channel1BreakerFault; + case 2 -> channel2BreakerFault; + case 3 -> channel3BreakerFault; + case 4 -> channel4BreakerFault; + case 5 -> channel5BreakerFault; + case 6 -> channel6BreakerFault; + case 7 -> channel7BreakerFault; + case 8 -> channel8BreakerFault; + case 9 -> channel9BreakerFault; + case 10 -> channel10BreakerFault; + case 11 -> channel11BreakerFault; + case 12 -> channel12BreakerFault; + case 13 -> channel13BreakerFault; + case 14 -> channel14BreakerFault; + case 15 -> channel15BreakerFault; + case 16 -> channel16BreakerFault; + case 17 -> channel17BreakerFault; + case 18 -> channel18BreakerFault; + case 19 -> channel19BreakerFault; + case 20 -> channel20BreakerFault; + case 21 -> channel21BreakerFault; + case 22 -> channel22BreakerFault; + case 23 -> channel23BreakerFault; default -> throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!"); }; @@ -145,35 +144,35 @@ public class PowerDistributionStickyFaults { * @param faults faults */ public PowerDistributionStickyFaults(int faults) { - Channel0BreakerFault = (faults & 0x1) != 0; - Channel1BreakerFault = (faults & 0x2) != 0; - Channel2BreakerFault = (faults & 0x4) != 0; - Channel3BreakerFault = (faults & 0x8) != 0; - Channel4BreakerFault = (faults & 0x10) != 0; - Channel5BreakerFault = (faults & 0x20) != 0; - Channel6BreakerFault = (faults & 0x40) != 0; - Channel7BreakerFault = (faults & 0x80) != 0; - Channel8BreakerFault = (faults & 0x100) != 0; - Channel9BreakerFault = (faults & 0x200) != 0; - Channel10BreakerFault = (faults & 0x400) != 0; - Channel11BreakerFault = (faults & 0x800) != 0; - Channel12BreakerFault = (faults & 0x1000) != 0; - Channel13BreakerFault = (faults & 0x2000) != 0; - Channel14BreakerFault = (faults & 0x4000) != 0; - Channel15BreakerFault = (faults & 0x8000) != 0; - Channel16BreakerFault = (faults & 0x10000) != 0; - Channel17BreakerFault = (faults & 0x20000) != 0; - Channel18BreakerFault = (faults & 0x40000) != 0; - Channel19BreakerFault = (faults & 0x80000) != 0; - Channel20BreakerFault = (faults & 0x100000) != 0; - Channel21BreakerFault = (faults & 0x200000) != 0; - Channel22BreakerFault = (faults & 0x400000) != 0; - Channel23BreakerFault = (faults & 0x800000) != 0; - Brownout = (faults & 0x1000000) != 0; - CanWarning = (faults & 0x2000000) != 0; - CanBusOff = (faults & 0x4000000) != 0; - HardwareFault = (faults & 0x8000000) != 0; - FirmwareFault = (faults & 0x10000000) != 0; - HasReset = (faults & 0x20000000) != 0; + channel0BreakerFault = (faults & 0x1) != 0; + channel1BreakerFault = (faults & 0x2) != 0; + channel2BreakerFault = (faults & 0x4) != 0; + channel3BreakerFault = (faults & 0x8) != 0; + channel4BreakerFault = (faults & 0x10) != 0; + channel5BreakerFault = (faults & 0x20) != 0; + channel6BreakerFault = (faults & 0x40) != 0; + channel7BreakerFault = (faults & 0x80) != 0; + channel8BreakerFault = (faults & 0x100) != 0; + channel9BreakerFault = (faults & 0x200) != 0; + channel10BreakerFault = (faults & 0x400) != 0; + channel11BreakerFault = (faults & 0x800) != 0; + channel12BreakerFault = (faults & 0x1000) != 0; + channel13BreakerFault = (faults & 0x2000) != 0; + channel14BreakerFault = (faults & 0x4000) != 0; + channel15BreakerFault = (faults & 0x8000) != 0; + channel16BreakerFault = (faults & 0x10000) != 0; + channel17BreakerFault = (faults & 0x20000) != 0; + channel18BreakerFault = (faults & 0x40000) != 0; + channel19BreakerFault = (faults & 0x80000) != 0; + channel20BreakerFault = (faults & 0x100000) != 0; + channel21BreakerFault = (faults & 0x200000) != 0; + channel22BreakerFault = (faults & 0x400000) != 0; + channel23BreakerFault = (faults & 0x800000) != 0; + brownout = (faults & 0x1000000) != 0; + canWarning = (faults & 0x2000000) != 0; + canBusOff = (faults & 0x4000000) != 0; + hardwareFault = (faults & 0x8000000) != 0; + firmwareFault = (faults & 0x10000000) != 0; + hasReset = (faults & 0x20000000) != 0; } } 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 086ed42f78..62f221e4d9 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/REVPHFaults.java b/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java index d61da9c512..b0ff80eacb 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/REVPHFaults.java @@ -5,73 +5,72 @@ package org.wpilib.hardware.hal; /** Faults for a REV PH. These faults are only active while the condition is active. */ -@SuppressWarnings("MemberName") public class REVPHFaults { /** Fault on channel 0. */ - public final boolean Channel0Fault; + public final boolean channel0Fault; /** Fault on channel 1. */ - public final boolean Channel1Fault; + public final boolean channel1Fault; /** Fault on channel 2. */ - public final boolean Channel2Fault; + public final boolean channel2Fault; /** Fault on channel 3. */ - public final boolean Channel3Fault; + public final boolean channel3Fault; /** Fault on channel 4. */ - public final boolean Channel4Fault; + public final boolean channel4Fault; /** Fault on channel 5. */ - public final boolean Channel5Fault; + public final boolean channel5Fault; /** Fault on channel 6. */ - public final boolean Channel6Fault; + public final boolean channel6Fault; /** Fault on channel 7. */ - public final boolean Channel7Fault; + public final boolean channel7Fault; /** Fault on channel 8. */ - public final boolean Channel8Fault; + public final boolean channel8Fault; /** Fault on channel 9. */ - public final boolean Channel9Fault; + public final boolean channel9Fault; /** Fault on channel 10. */ - public final boolean Channel10Fault; + public final boolean channel10Fault; /** Fault on channel 11. */ - public final boolean Channel11Fault; + public final boolean channel11Fault; /** Fault on channel 12. */ - public final boolean Channel12Fault; + public final boolean channel12Fault; /** Fault on channel 13. */ - public final boolean Channel13Fault; + public final boolean channel13Fault; /** Fault on channel 14. */ - public final boolean Channel14Fault; + public final boolean channel14Fault; /** Fault on channel 15. */ - public final boolean Channel15Fault; + public final boolean channel15Fault; /** An overcurrent event occurred on the compressor output. */ - public final boolean CompressorOverCurrent; + public final boolean compressorOverCurrent; /** The compressor output has an open circuit. */ - public final boolean CompressorOpen; + public final boolean compressorOpen; /** An overcurrent event occurred on a solenoid output. */ - public final boolean SolenoidOverCurrent; + public final boolean solenoidOverCurrent; /** The input voltage is below the minimum voltage. */ - public final boolean Brownout; + public final boolean brownout; /** A warning was raised by the device's CAN controller. */ - public final boolean CanWarning; + public final boolean canWarning; /** The hardware on the device has malfunctioned. */ - public final boolean HardwareFault; + public final boolean hardwareFault; /** * Gets whether there is a fault at the specified channel. @@ -81,24 +80,24 @@ public class REVPHFaults { * @throws IndexOutOfBoundsException if the provided channel is outside of the range supported by * the hardware. */ - public final boolean getChannelFault(int channel) { + public final boolean getchannelFault(int channel) { return switch (channel) { - case 0 -> Channel0Fault; - case 1 -> Channel1Fault; - case 2 -> Channel2Fault; - case 3 -> Channel3Fault; - case 4 -> Channel4Fault; - case 5 -> Channel5Fault; - case 6 -> Channel6Fault; - case 7 -> Channel7Fault; - case 8 -> Channel8Fault; - case 9 -> Channel9Fault; - case 10 -> Channel10Fault; - case 11 -> Channel11Fault; - case 12 -> Channel12Fault; - case 13 -> Channel13Fault; - case 14 -> Channel14Fault; - case 15 -> Channel15Fault; + case 0 -> channel0Fault; + case 1 -> channel1Fault; + case 2 -> channel2Fault; + case 3 -> channel3Fault; + case 4 -> channel4Fault; + case 5 -> channel5Fault; + case 6 -> channel6Fault; + case 7 -> channel7Fault; + case 8 -> channel8Fault; + case 9 -> channel9Fault; + case 10 -> channel10Fault; + case 11 -> channel11Fault; + case 12 -> channel12Fault; + case 13 -> channel13Fault; + case 14 -> channel14Fault; + case 15 -> channel15Fault; default -> throw new IndexOutOfBoundsException("Pneumatics fault channel out of bounds!"); }; } @@ -109,27 +108,27 @@ public class REVPHFaults { * @param faults the fault bitfields */ public REVPHFaults(int faults) { - Channel0Fault = (faults & (1 << 0)) != 0; - Channel1Fault = (faults & (1 << 1)) != 0; - Channel2Fault = (faults & (1 << 2)) != 0; - Channel3Fault = (faults & (1 << 3)) != 0; - Channel4Fault = (faults & (1 << 4)) != 0; - Channel5Fault = (faults & (1 << 5)) != 0; - Channel6Fault = (faults & (1 << 6)) != 0; - Channel7Fault = (faults & (1 << 7)) != 0; - Channel8Fault = (faults & (1 << 8)) != 0; - Channel9Fault = (faults & (1 << 9)) != 0; - Channel10Fault = (faults & (1 << 10)) != 0; - Channel11Fault = (faults & (1 << 11)) != 0; - Channel12Fault = (faults & (1 << 12)) != 0; - Channel13Fault = (faults & (1 << 13)) != 0; - Channel14Fault = (faults & (1 << 14)) != 0; - Channel15Fault = (faults & (1 << 15)) != 0; - CompressorOverCurrent = (faults & (1 << 16)) != 0; - CompressorOpen = (faults & (1 << 17)) != 0; - SolenoidOverCurrent = (faults & (1 << 18)) != 0; - Brownout = (faults & (1 << 19)) != 0; - CanWarning = (faults & (1 << 20)) != 0; - HardwareFault = (faults & (1 << 21)) != 0; + channel0Fault = (faults & (1 << 0)) != 0; + channel1Fault = (faults & (1 << 1)) != 0; + channel2Fault = (faults & (1 << 2)) != 0; + channel3Fault = (faults & (1 << 3)) != 0; + channel4Fault = (faults & (1 << 4)) != 0; + channel5Fault = (faults & (1 << 5)) != 0; + channel6Fault = (faults & (1 << 6)) != 0; + channel7Fault = (faults & (1 << 7)) != 0; + channel8Fault = (faults & (1 << 8)) != 0; + channel9Fault = (faults & (1 << 9)) != 0; + channel10Fault = (faults & (1 << 10)) != 0; + channel11Fault = (faults & (1 << 11)) != 0; + channel12Fault = (faults & (1 << 12)) != 0; + channel13Fault = (faults & (1 << 13)) != 0; + channel14Fault = (faults & (1 << 14)) != 0; + channel15Fault = (faults & (1 << 15)) != 0; + compressorOverCurrent = (faults & (1 << 16)) != 0; + compressorOpen = (faults & (1 << 17)) != 0; + solenoidOverCurrent = (faults & (1 << 18)) != 0; + brownout = (faults & (1 << 19)) != 0; + canWarning = (faults & (1 << 20)) != 0; + hardwareFault = (faults & (1 << 21)) != 0; } } 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 945d88e5d4..3570b24e92 100644 --- a/hal/src/main/java/org/wpilib/hardware/hal/REVPHStickyFaults.java +++ b/hal/src/main/java/org/wpilib/hardware/hal/REVPHStickyFaults.java @@ -5,34 +5,33 @@ 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") public class REVPHStickyFaults { /** An overcurrent event occurred on the compressor output. */ - public final boolean CompressorOverCurrent; + public final boolean compressorOverCurrent; /** The compressor output has an open circuit. */ - public final boolean CompressorOpen; + public final boolean compressorOpen; /** An overcurrent event occurred on a solenoid output. */ - public final boolean SolenoidOverCurrent; + public final boolean solenoidOverCurrent; /** The input voltage is below the minimum voltage. */ - public final boolean Brownout; + public final boolean brownout; /** A warning was raised by the device's CAN controller. */ - public final boolean CanWarning; + public final boolean canWarning; /** The device's CAN controller experienced a "Bus Off" event. */ - public final boolean CanBusOff; + public final boolean canBusOff; /** The hardware on the device has malfunctioned. */ - public final boolean HardwareFault; + public final boolean hardwareFault; /** The firmware on the device has malfunctioned. */ - public final boolean FirmwareFault; + public final boolean firmwareFault; /** The device has rebooted. */ - public final boolean HasReset; + public final boolean hasReset; /** * Called from HAL. @@ -40,14 +39,14 @@ public class REVPHStickyFaults { * @param faults sticky fault bit mask */ public REVPHStickyFaults(int faults) { - CompressorOverCurrent = (faults & 0x1) != 0; - CompressorOpen = (faults & 0x2) != 0; - SolenoidOverCurrent = (faults & 0x4) != 0; - Brownout = (faults & 0x8) != 0; - CanWarning = (faults & 0x10) != 0; - CanBusOff = (faults & 0x20) != 0; - HardwareFault = (faults & 0x40) != 0; - FirmwareFault = (faults & 0x80) != 0; - HasReset = (faults & 0x100) != 0; + compressorOverCurrent = (faults & 0x1) != 0; + compressorOpen = (faults & 0x2) != 0; + solenoidOverCurrent = (faults & 0x4) != 0; + brownout = (faults & 0x8) != 0; + canWarning = (faults & 0x10) != 0; + canBusOff = (faults & 0x20) != 0; + hardwareFault = (faults & 0x40) != 0; + firmwareFault = (faults & 0x80) != 0; + hasReset = (faults & 0x100) != 0; } } 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 1dbd075f54..d63860839a 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/SimDevice.java b/hal/src/main/java/org/wpilib/hardware/hal/SimDevice.java index 373613fd31..91a9c49cf7 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 class SimDevice implements AutoCloseable { 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 class SimDevice implements AutoCloseable { * @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 class SimDevice implements AutoCloseable { * @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 class SimDevice implements AutoCloseable { * @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 class SimDevice implements AutoCloseable { * @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 class SimDevice implements AutoCloseable { */ 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 class SimDevice implements AutoCloseable { 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 class SimDevice implements AutoCloseable { * @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/hal/src/main/java/org/wpilib/hardware/hal/can/CANReceiveMessage.java b/hal/src/main/java/org/wpilib/hardware/hal/can/CANReceiveMessage.java index 1be388b017..d17a80f1dd 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 @@ package org.wpilib.hardware.hal.can; /** 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/can/CANStatus.java b/hal/src/main/java/org/wpilib/hardware/hal/can/CANStatus.java index e5aeb1e064..badd06e39f 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 d268103820..e7c491ed7a 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 @@ package org.wpilib.hardware.hal.can; /** 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/AlertDataJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/simulation/AlertDataJNI.java index 9d65a3898b..f25055dc7c 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 class AlertDataJNI extends JNIWrapper { 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/hal/src/main/java/org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java b/hal/src/main/java/org/wpilib/hardware/hal/simulation/SimDeviceDataJNI.java index 89fd771cb9..cd6c343048 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 class SimDeviceDataJNI extends JNIWrapper { public static native int getSimValueDeviceHandle(int handle); - @SuppressWarnings("MemberName") public static class SimDeviceInfo { public String name; public int handle; @@ -74,7 +73,6 @@ public class SimDeviceDataJNI extends JNIWrapper { 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 144cc5023d..580037dc22 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 aa8590d213..7104e08880 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 final class TimestampedBoolean { /** * 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 24218f6535..c027f725b1 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 final class TimestampedBooleanArray { /** * 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 7a5ceaf50e..7a9e46d67b 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 final class TimestampedDouble { /** * 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 ff8d3c0206..9da8fdb87f 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 final class TimestampedDoubleArray { /** * 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 3ecf2c32d2..f12f87149b 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 final class TimestampedFloat { /** * 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 70dbc9d6a8..1c9a5f826b 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 final class TimestampedFloatArray { /** * 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 56cee7539b..2eec442622 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 final class TimestampedInteger { /** * 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 9221386eed..91f2966f2c 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 final class TimestampedIntegerArray { /** * 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 a54e54b4c1..74984d9324 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 final class TimestampedRaw { /** * 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 860d352763..1e275580c3 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 final class TimestampedString { /** * 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 29d094683f..87fb72c185 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 final class TimestampedStringArray { /** * 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 33ef2525db..aeedd02e1b 100644 --- a/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java +++ b/ntcore/src/main/java/org/wpilib/networktables/ConnectionInfo.java @@ -5,31 +5,30 @@ package org.wpilib.networktables; /** NetworkTables Connection information. */ -@SuppressWarnings("MemberName") 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. @@ -42,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/ntcore/src/main/java/org/wpilib/networktables/LogMessage.java b/ntcore/src/main/java/org/wpilib/networktables/LogMessage.java index f35599b699..a7faa20f4c 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 401ac50535..49c1c9a1e3 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 @@ package org.wpilib.networktables; *

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 2bf16c7d75..b50cae5cb8 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 bc3d96f8ed..b1dbc2dfdc 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 7ecc94d09e..a2726c4152 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 final class TimestampedObject { } /** 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 754ec4d67f..71eedbb046 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 ba381f58e1..c59f83a0d9 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/robotpyExamples/DifferentialDrivePoseEstimator/robot.py b/robotpyExamples/DifferentialDrivePoseEstimator/robot.py index 5cde89e2b1..301aef0a80 100644 --- a/robotpyExamples/DifferentialDrivePoseEstimator/robot.py +++ b/robotpyExamples/DifferentialDrivePoseEstimator/robot.py @@ -17,7 +17,7 @@ class MyRobot(wpilib.TimedRobot): 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 5f0aa9e210..2d74f282bb 100644 --- a/robotpyExamples/SwerveDrivePoseEstimator/swervemodule.py +++ b/robotpyExamples/SwerveDrivePoseEstimator/swervemodule.py @@ -112,21 +112,17 @@ class SwerveModule: 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 - ) + ) + self.driveFeedforward.calculate(velocity.velocity) - driveFeedforward = 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/styleguide/checkstyle-suppressions.xml b/styleguide/checkstyle-suppressions.xml index 0b4c2fa99f..bc14fc29d7 100644 --- a/styleguide/checkstyle-suppressions.xml +++ b/styleguide/checkstyle-suppressions.xml @@ -7,12 +7,12 @@ suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" + checks="(LocalVariableName|MethodName|MethodTypeParameterName|ParameterName)" /> + checks="(CustomImportOrder|EmptyLineSeparator|LeftCurly|LineLength|JavadocParagraph|MissingJavadocMethod|OverloadMethodsDeclarationOrder|SummaryJavadoc|UnnecessaryParentheses|OperatorWrap|JavadocMethod|JavadocTagContinuationIndentation)" /> diff --git a/styleguide/checkstyle.xml b/styleguide/checkstyle.xml index 9ebe62c3c2..2ca946b294 100644 --- a/styleguide/checkstyle.xml +++ b/styleguide/checkstyle.xml @@ -168,12 +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 9bbebd1eff..4ddac8e085 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.* @@ -143,4 +143,22 @@ ]]> + + + + + 3 + + + + + + + + diff --git a/styleguide/spotbugs-exclude.xml b/styleguide/spotbugs-exclude.xml index 7f8c641dcd..e9ed00d855 100644 --- a/styleguide/spotbugs-exclude.xml +++ b/styleguide/spotbugs-exclude.xml @@ -150,6 +150,10 @@ + + + + diff --git a/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp b/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp index 00155f374a..78f3c1f734 100644 --- a/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp +++ b/wpilibc/src/main/native/cpp/hardware/pneumatic/PneumaticHub.cpp @@ -329,37 +329,37 @@ PneumaticHub::StickyFaults PneumaticHub::GetStickyFaults() const { bool PneumaticHub::Faults::GetChannelFault(int channel) const { switch (channel) { case 0: - return Channel0Fault != 0; + return channel0Fault != 0; case 1: - return Channel1Fault != 0; + return channel1Fault != 0; case 2: - return Channel2Fault != 0; + return channel2Fault != 0; case 3: - return Channel3Fault != 0; + return channel3Fault != 0; case 4: - return Channel4Fault != 0; + return channel4Fault != 0; case 5: - return Channel5Fault != 0; + return channel5Fault != 0; case 6: - return Channel6Fault != 0; + return channel6Fault != 0; case 7: - return Channel7Fault != 0; + return channel7Fault != 0; case 8: - return Channel8Fault != 0; + return channel8Fault != 0; case 9: - return Channel9Fault != 0; + return channel9Fault != 0; case 10: - return Channel10Fault != 0; + return channel10Fault != 0; case 11: - return Channel11Fault != 0; + return channel11Fault != 0; case 12: - return Channel12Fault != 0; + return channel12Fault != 0; case 13: - return Channel13Fault != 0; + return channel13Fault != 0; case 14: - return Channel14Fault != 0; + return channel14Fault != 0; case 15: - return Channel15Fault != 0; + return channel15Fault != 0; default: throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Pneumatics fault channel out of bounds!"); diff --git a/wpilibc/src/main/native/cpp/hardware/power/PowerDistribution.cpp b/wpilibc/src/main/native/cpp/hardware/power/PowerDistribution.cpp index a1048f0d82..29940998c9 100644 --- a/wpilibc/src/main/native/cpp/hardware/power/PowerDistribution.cpp +++ b/wpilibc/src/main/native/cpp/hardware/power/PowerDistribution.cpp @@ -196,53 +196,53 @@ PowerDistribution::Faults PowerDistribution::GetFaults() const { bool PowerDistribution::Faults::GetBreakerFault(int channel) const { switch (channel) { case 0: - return Channel0BreakerFault != 0; + return channel0BreakerFault != 0; case 1: - return Channel1BreakerFault != 0; + return channel1BreakerFault != 0; case 2: - return Channel2BreakerFault != 0; + return channel2BreakerFault != 0; case 3: - return Channel3BreakerFault != 0; + return channel3BreakerFault != 0; case 4: - return Channel4BreakerFault != 0; + return channel4BreakerFault != 0; case 5: - return Channel5BreakerFault != 0; + return channel5BreakerFault != 0; case 6: - return Channel6BreakerFault != 0; + return channel6BreakerFault != 0; case 7: - return Channel7BreakerFault != 0; + return channel7BreakerFault != 0; case 8: - return Channel8BreakerFault != 0; + return channel8BreakerFault != 0; case 9: - return Channel9BreakerFault != 0; + return channel9BreakerFault != 0; case 10: - return Channel10BreakerFault != 0; + return channel10BreakerFault != 0; case 11: - return Channel11BreakerFault != 0; + return channel11BreakerFault != 0; case 12: - return Channel12BreakerFault != 0; + return channel12BreakerFault != 0; case 13: - return Channel13BreakerFault != 0; + return channel13BreakerFault != 0; case 14: - return Channel14BreakerFault != 0; + return channel14BreakerFault != 0; case 15: - return Channel15BreakerFault != 0; + return channel15BreakerFault != 0; case 16: - return Channel16BreakerFault != 0; + return channel16BreakerFault != 0; case 17: - return Channel17BreakerFault != 0; + return channel17BreakerFault != 0; case 18: - return Channel18BreakerFault != 0; + return channel18BreakerFault != 0; case 19: - return Channel19BreakerFault != 0; + return channel19BreakerFault != 0; case 20: - return Channel20BreakerFault != 0; + return channel20BreakerFault != 0; case 21: - return Channel21BreakerFault != 0; + return channel21BreakerFault != 0; case 22: - return Channel22BreakerFault != 0; + return channel22BreakerFault != 0; case 23: - return Channel23BreakerFault != 0; + return channel23BreakerFault != 0; default: throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Power distribution fault channel out of bounds!"); @@ -252,53 +252,53 @@ bool PowerDistribution::Faults::GetBreakerFault(int channel) const { bool PowerDistribution::StickyFaults::GetBreakerFault(int channel) const { switch (channel) { case 0: - return Channel0BreakerFault != 0; + return channel0BreakerFault != 0; case 1: - return Channel1BreakerFault != 0; + return channel1BreakerFault != 0; case 2: - return Channel2BreakerFault != 0; + return channel2BreakerFault != 0; case 3: - return Channel3BreakerFault != 0; + return channel3BreakerFault != 0; case 4: - return Channel4BreakerFault != 0; + return channel4BreakerFault != 0; case 5: - return Channel5BreakerFault != 0; + return channel5BreakerFault != 0; case 6: - return Channel6BreakerFault != 0; + return channel6BreakerFault != 0; case 7: - return Channel7BreakerFault != 0; + return channel7BreakerFault != 0; case 8: - return Channel8BreakerFault != 0; + return channel8BreakerFault != 0; case 9: - return Channel9BreakerFault != 0; + return channel9BreakerFault != 0; case 10: - return Channel10BreakerFault != 0; + return channel10BreakerFault != 0; case 11: - return Channel11BreakerFault != 0; + return channel11BreakerFault != 0; case 12: - return Channel12BreakerFault != 0; + return channel12BreakerFault != 0; case 13: - return Channel13BreakerFault != 0; + return channel13BreakerFault != 0; case 14: - return Channel14BreakerFault != 0; + return channel14BreakerFault != 0; case 15: - return Channel15BreakerFault != 0; + return channel15BreakerFault != 0; case 16: - return Channel16BreakerFault != 0; + return channel16BreakerFault != 0; case 17: - return Channel17BreakerFault != 0; + return channel17BreakerFault != 0; case 18: - return Channel18BreakerFault != 0; + return channel18BreakerFault != 0; case 19: - return Channel19BreakerFault != 0; + return channel19BreakerFault != 0; case 20: - return Channel20BreakerFault != 0; + return channel20BreakerFault != 0; case 21: - return Channel21BreakerFault != 0; + return channel21BreakerFault != 0; case 22: - return Channel22BreakerFault != 0; + return channel22BreakerFault != 0; case 23: - return Channel23BreakerFault != 0; + return channel23BreakerFault != 0; default: throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Power distribution fault channel out of bounds!"); diff --git a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp index 67e9cbd054..0b75a9227d 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/pneumatic/PneumaticHub.hpp @@ -154,49 +154,49 @@ class PneumaticHub : public PneumaticsBase { */ struct Faults { /** Fault on channel 0. */ - uint32_t Channel0Fault : 1; + uint32_t channel0Fault : 1; /** Fault on channel 1. */ - uint32_t Channel1Fault : 1; + uint32_t channel1Fault : 1; /** Fault on channel 2. */ - uint32_t Channel2Fault : 1; + uint32_t channel2Fault : 1; /** Fault on channel 3. */ - uint32_t Channel3Fault : 1; + uint32_t channel3Fault : 1; /** Fault on channel 4. */ - uint32_t Channel4Fault : 1; + uint32_t channel4Fault : 1; /** Fault on channel 5. */ - uint32_t Channel5Fault : 1; + uint32_t channel5Fault : 1; /** Fault on channel 6. */ - uint32_t Channel6Fault : 1; + uint32_t channel6Fault : 1; /** Fault on channel 7. */ - uint32_t Channel7Fault : 1; + uint32_t channel7Fault : 1; /** Fault on channel 8. */ - uint32_t Channel8Fault : 1; + uint32_t channel8Fault : 1; /** Fault on channel 9. */ - uint32_t Channel9Fault : 1; + uint32_t channel9Fault : 1; /** Fault on channel 10. */ - uint32_t Channel10Fault : 1; + uint32_t channel10Fault : 1; /** Fault on channel 11. */ - uint32_t Channel11Fault : 1; + uint32_t channel11Fault : 1; /** Fault on channel 12. */ - uint32_t Channel12Fault : 1; + uint32_t channel12Fault : 1; /** Fault on channel 13. */ - uint32_t Channel13Fault : 1; + uint32_t channel13Fault : 1; /** Fault on channel 14. */ - uint32_t Channel14Fault : 1; + uint32_t channel14Fault : 1; /** Fault on channel 15. */ - uint32_t Channel15Fault : 1; + uint32_t channel15Fault : 1; /** An overcurrent event occurred on the compressor output. */ - uint32_t CompressorOverCurrent : 1; + uint32_t compressorOverCurrent : 1; /** The compressor output has an open circuit. */ - uint32_t CompressorOpen : 1; + uint32_t compressorOpen : 1; /** An overcurrent event occurred on a solenoid output. */ - uint32_t SolenoidOverCurrent : 1; + uint32_t solenoidOverCurrent : 1; /** The input voltage is below the minimum voltage. */ - uint32_t Brownout : 1; + uint32_t brownout : 1; /** A warning was raised by the device's CAN controller. */ - uint32_t CanWarning : 1; + uint32_t canWarning : 1; /** The hardware on the device has malfunctioned. */ - uint32_t HardwareFault : 1; + uint32_t hardwareFault : 1; /** * Gets whether there is a fault at the specified channel. @@ -221,23 +221,23 @@ class PneumaticHub : public PneumaticsBase { */ struct StickyFaults { /** An overcurrent event occurred on the compressor output. */ - uint32_t CompressorOverCurrent : 1; + uint32_t compressorOverCurrent : 1; /** The compressor output has an open circuit. */ - uint32_t CompressorOpen : 1; + uint32_t compressorOpen : 1; /** An overcurrent event occurred on a solenoid output. */ - uint32_t SolenoidOverCurrent : 1; + uint32_t solenoidOverCurrent : 1; /** The input voltage is below the minimum voltage. */ - uint32_t Brownout : 1; + uint32_t brownout : 1; /** A warning was raised by the device's CAN controller. */ - uint32_t CanWarning : 1; + uint32_t canWarning : 1; /** The device's CAN controller experienced a "Bus Off" event. */ - uint32_t CanBusOff : 1; + uint32_t canBusOff : 1; /** The hardware on the device has malfunctioned. */ - uint32_t HardwareFault : 1; + uint32_t hardwareFault : 1; /** The firmware on the device has malfunctioned. */ - uint32_t FirmwareFault : 1; + uint32_t firmwareFault : 1; /** The device has rebooted. */ - uint32_t HasReset : 1; + uint32_t hasReset : 1; }; /** diff --git a/wpilibc/src/main/native/include/wpi/hardware/power/PowerDistribution.hpp b/wpilibc/src/main/native/include/wpi/hardware/power/PowerDistribution.hpp index 3de7624d9e..092a4bbef1 100644 --- a/wpilibc/src/main/native/include/wpi/hardware/power/PowerDistribution.hpp +++ b/wpilibc/src/main/native/include/wpi/hardware/power/PowerDistribution.hpp @@ -184,59 +184,59 @@ class PowerDistribution : public wpi::util::Sendable, */ struct Faults { /** Breaker fault on channel 0. */ - uint32_t Channel0BreakerFault : 1; + uint32_t channel0BreakerFault : 1; /** Breaker fault on channel 1. */ - uint32_t Channel1BreakerFault : 1; + uint32_t channel1BreakerFault : 1; /** Breaker fault on channel 2. */ - uint32_t Channel2BreakerFault : 1; + uint32_t channel2BreakerFault : 1; /** Breaker fault on channel 3. */ - uint32_t Channel3BreakerFault : 1; + uint32_t channel3BreakerFault : 1; /** Breaker fault on channel 4. */ - uint32_t Channel4BreakerFault : 1; + uint32_t channel4BreakerFault : 1; /** Breaker fault on channel 5. */ - uint32_t Channel5BreakerFault : 1; + uint32_t channel5BreakerFault : 1; /** Breaker fault on channel 6. */ - uint32_t Channel6BreakerFault : 1; + uint32_t channel6BreakerFault : 1; /** Breaker fault on channel 7. */ - uint32_t Channel7BreakerFault : 1; + uint32_t channel7BreakerFault : 1; /** Breaker fault on channel 8. */ - uint32_t Channel8BreakerFault : 1; + uint32_t channel8BreakerFault : 1; /** Breaker fault on channel 9. */ - uint32_t Channel9BreakerFault : 1; + uint32_t channel9BreakerFault : 1; /** Breaker fault on channel 10. */ - uint32_t Channel10BreakerFault : 1; + uint32_t channel10BreakerFault : 1; /** Breaker fault on channel 12. */ - uint32_t Channel11BreakerFault : 1; + uint32_t channel11BreakerFault : 1; /** Breaker fault on channel 13. */ - uint32_t Channel12BreakerFault : 1; + uint32_t channel12BreakerFault : 1; /** Breaker fault on channel 14. */ - uint32_t Channel13BreakerFault : 1; + uint32_t channel13BreakerFault : 1; /** Breaker fault on channel 15. */ - uint32_t Channel14BreakerFault : 1; + uint32_t channel14BreakerFault : 1; /** Breaker fault on channel 16. */ - uint32_t Channel15BreakerFault : 1; + uint32_t channel15BreakerFault : 1; /** Breaker fault on channel 17. */ - uint32_t Channel16BreakerFault : 1; + uint32_t channel16BreakerFault : 1; /** Breaker fault on channel 18. */ - uint32_t Channel17BreakerFault : 1; + uint32_t channel17BreakerFault : 1; /** Breaker fault on channel 19. */ - uint32_t Channel18BreakerFault : 1; + uint32_t channel18BreakerFault : 1; /** Breaker fault on channel 20. */ - uint32_t Channel19BreakerFault : 1; + uint32_t channel19BreakerFault : 1; /** Breaker fault on channel 21. */ - uint32_t Channel20BreakerFault : 1; + uint32_t channel20BreakerFault : 1; /** Breaker fault on channel 22. */ - uint32_t Channel21BreakerFault : 1; + uint32_t channel21BreakerFault : 1; /** Breaker fault on channel 23. */ - uint32_t Channel22BreakerFault : 1; + uint32_t channel22BreakerFault : 1; /** Breaker fault on channel 24. */ - uint32_t Channel23BreakerFault : 1; + uint32_t channel23BreakerFault : 1; /** The input voltage is below the minimum voltage. */ - uint32_t Brownout : 1; + uint32_t brownout : 1; /** A warning was raised by the device's CAN controller. */ - uint32_t CanWarning : 1; + uint32_t canWarning : 1; /** The hardware on the device has malfunctioned. */ - uint32_t HardwareFault : 1; + uint32_t hardwareFault : 1; /** * Gets whether there is a breaker fault at a specified channel. @@ -263,65 +263,65 @@ class PowerDistribution : public wpi::util::Sendable, */ struct StickyFaults { /** Breaker fault on channel 0. */ - uint32_t Channel0BreakerFault : 1; + uint32_t channel0BreakerFault : 1; /** Breaker fault on channel 1. */ - uint32_t Channel1BreakerFault : 1; + uint32_t channel1BreakerFault : 1; /** Breaker fault on channel 2. */ - uint32_t Channel2BreakerFault : 1; + uint32_t channel2BreakerFault : 1; /** Breaker fault on channel 3. */ - uint32_t Channel3BreakerFault : 1; + uint32_t channel3BreakerFault : 1; /** Breaker fault on channel 4. */ - uint32_t Channel4BreakerFault : 1; + uint32_t channel4BreakerFault : 1; /** Breaker fault on channel 5. */ - uint32_t Channel5BreakerFault : 1; + uint32_t channel5BreakerFault : 1; /** Breaker fault on channel 6. */ - uint32_t Channel6BreakerFault : 1; + uint32_t channel6BreakerFault : 1; /** Breaker fault on channel 7. */ - uint32_t Channel7BreakerFault : 1; + uint32_t channel7BreakerFault : 1; /** Breaker fault on channel 8. */ - uint32_t Channel8BreakerFault : 1; + uint32_t channel8BreakerFault : 1; /** Breaker fault on channel 9. */ - uint32_t Channel9BreakerFault : 1; + uint32_t channel9BreakerFault : 1; /** Breaker fault on channel 10. */ - uint32_t Channel10BreakerFault : 1; + uint32_t channel10BreakerFault : 1; /** Breaker fault on channel 12. */ - uint32_t Channel11BreakerFault : 1; + uint32_t channel11BreakerFault : 1; /** Breaker fault on channel 13. */ - uint32_t Channel12BreakerFault : 1; + uint32_t channel12BreakerFault : 1; /** Breaker fault on channel 14. */ - uint32_t Channel13BreakerFault : 1; + uint32_t channel13BreakerFault : 1; /** Breaker fault on channel 15. */ - uint32_t Channel14BreakerFault : 1; + uint32_t channel14BreakerFault : 1; /** Breaker fault on channel 16. */ - uint32_t Channel15BreakerFault : 1; + uint32_t channel15BreakerFault : 1; /** Breaker fault on channel 17. */ - uint32_t Channel16BreakerFault : 1; + uint32_t channel16BreakerFault : 1; /** Breaker fault on channel 18. */ - uint32_t Channel17BreakerFault : 1; + uint32_t channel17BreakerFault : 1; /** Breaker fault on channel 19. */ - uint32_t Channel18BreakerFault : 1; + uint32_t channel18BreakerFault : 1; /** Breaker fault on channel 20. */ - uint32_t Channel19BreakerFault : 1; + uint32_t channel19BreakerFault : 1; /** Breaker fault on channel 21. */ - uint32_t Channel20BreakerFault : 1; + uint32_t channel20BreakerFault : 1; /** Breaker fault on channel 22. */ - uint32_t Channel21BreakerFault : 1; + uint32_t channel21BreakerFault : 1; /** Breaker fault on channel 23. */ - uint32_t Channel22BreakerFault : 1; + uint32_t channel22BreakerFault : 1; /** Breaker fault on channel 24. */ - uint32_t Channel23BreakerFault : 1; + uint32_t channel23BreakerFault : 1; /** The input voltage is below the minimum voltage. */ - uint32_t Brownout : 1; + uint32_t brownout : 1; /** A warning was raised by the device's CAN controller. */ - uint32_t CanWarning : 1; + uint32_t canWarning : 1; /** The device's CAN controller experienced a "Bus Off" event. */ - uint32_t CanBusOff : 1; + uint32_t canBusOff : 1; /** The hardware on the device has malfunctioned. */ - uint32_t HardwareFault : 1; + uint32_t hardwareFault : 1; /** The firmware on the device has malfunctioned. */ - uint32_t FirmwareFault : 1; + uint32_t firmwareFault : 1; /** The device has rebooted. */ - uint32_t HasReset : 1; + uint32_t hasReset : 1; /** * Gets whether there is a sticky breaker fault at the specified channel. diff --git a/wpilibc/src/main/python/semiwrap/PneumaticHub.yml b/wpilibc/src/main/python/semiwrap/PneumaticHub.yml index b6f7576fc7..c08cee07e2 100644 --- a/wpilibc/src/main/python/semiwrap/PneumaticHub.yml +++ b/wpilibc/src/main/python/semiwrap/PneumaticHub.yml @@ -54,38 +54,38 @@ classes: UniqueId: wpi::PneumaticHub::Faults: attributes: - Channel0Fault: - Channel1Fault: - Channel2Fault: - Channel3Fault: - Channel4Fault: - Channel5Fault: - Channel6Fault: - Channel7Fault: - Channel8Fault: - Channel9Fault: - Channel10Fault: - Channel11Fault: - Channel12Fault: - Channel13Fault: - Channel14Fault: - Channel15Fault: - CompressorOverCurrent: - CompressorOpen: - SolenoidOverCurrent: - Brownout: - CanWarning: - HardwareFault: + channel0Fault: + channel1Fault: + channel2Fault: + channel3Fault: + channel4Fault: + channel5Fault: + channel6Fault: + channel7Fault: + channel8Fault: + channel9Fault: + channel10Fault: + channel11Fault: + channel12Fault: + channel13Fault: + channel14Fault: + channel15Fault: + compressorOverCurrent: + compressorOpen: + solenoidOverCurrent: + brownout: + canWarning: + hardwareFault: methods: GetChannelFault: wpi::PneumaticHub::StickyFaults: attributes: - CompressorOverCurrent: - CompressorOpen: - SolenoidOverCurrent: - Brownout: - CanWarning: - CanBusOff: - HasReset: - HardwareFault: - FirmwareFault: + compressorOverCurrent: + compressorOpen: + solenoidOverCurrent: + brownout: + canWarning: + canBusOff: + hasReset: + hardwareFault: + firmwareFault: diff --git a/wpilibc/src/main/python/semiwrap/PowerDistribution.yml b/wpilibc/src/main/python/semiwrap/PowerDistribution.yml index 66109fc036..177d231465 100644 --- a/wpilibc/src/main/python/semiwrap/PowerDistribution.yml +++ b/wpilibc/src/main/python/semiwrap/PowerDistribution.yml @@ -42,66 +42,66 @@ classes: UniqueId: wpi::PowerDistribution::Faults: attributes: - Channel0BreakerFault: - Channel1BreakerFault: - Channel2BreakerFault: - Channel3BreakerFault: - Channel4BreakerFault: - Channel5BreakerFault: - Channel6BreakerFault: - Channel7BreakerFault: - Channel8BreakerFault: - Channel9BreakerFault: - Channel10BreakerFault: - Channel11BreakerFault: - Channel12BreakerFault: - Channel13BreakerFault: - Channel14BreakerFault: - Channel15BreakerFault: - Channel16BreakerFault: - Channel17BreakerFault: - Channel18BreakerFault: - Channel19BreakerFault: - Channel20BreakerFault: - Channel21BreakerFault: - Channel22BreakerFault: - Channel23BreakerFault: - Brownout: - CanWarning: - HardwareFault: + channel0BreakerFault: + channel1BreakerFault: + channel2BreakerFault: + channel3BreakerFault: + channel4BreakerFault: + channel5BreakerFault: + channel6BreakerFault: + channel7BreakerFault: + channel8BreakerFault: + channel9BreakerFault: + channel10BreakerFault: + channel11BreakerFault: + channel12BreakerFault: + channel13BreakerFault: + channel14BreakerFault: + channel15BreakerFault: + channel16BreakerFault: + channel17BreakerFault: + channel18BreakerFault: + channel19BreakerFault: + channel20BreakerFault: + channel21BreakerFault: + channel22BreakerFault: + channel23BreakerFault: + brownout: + canWarning: + hardwareFault: methods: GetBreakerFault: wpi::PowerDistribution::StickyFaults: attributes: - Channel0BreakerFault: - Channel1BreakerFault: - Channel2BreakerFault: - Channel3BreakerFault: - Channel4BreakerFault: - Channel5BreakerFault: - Channel6BreakerFault: - Channel7BreakerFault: - Channel8BreakerFault: - Channel9BreakerFault: - Channel10BreakerFault: - Channel11BreakerFault: - Channel12BreakerFault: - Channel13BreakerFault: - Channel14BreakerFault: - Channel15BreakerFault: - Channel16BreakerFault: - Channel17BreakerFault: - Channel18BreakerFault: - Channel19BreakerFault: - Channel20BreakerFault: - Channel21BreakerFault: - Channel22BreakerFault: - Channel23BreakerFault: - Brownout: - CanWarning: - CanBusOff: - HasReset: - HardwareFault: - FirmwareFault: + channel0BreakerFault: + channel1BreakerFault: + channel2BreakerFault: + channel3BreakerFault: + channel4BreakerFault: + channel5BreakerFault: + channel6BreakerFault: + channel7BreakerFault: + channel8BreakerFault: + channel9BreakerFault: + channel10BreakerFault: + channel11BreakerFault: + channel12BreakerFault: + channel13BreakerFault: + channel14BreakerFault: + channel15BreakerFault: + channel16BreakerFault: + channel17BreakerFault: + channel18BreakerFault: + channel19BreakerFault: + channel20BreakerFault: + channel21BreakerFault: + channel22BreakerFault: + channel23BreakerFault: + brownout: + canWarning: + canBusOff: + hasReset: + hardwareFault: + firmwareFault: methods: GetBreakerFault: diff --git a/wpilibcExamples/src/main/cpp/examples/ArcadeDriveGamepad/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ArcadeDriveGamepad/cpp/Robot.cpp index d0cd3b477e..2737143403 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 ef04ceb39e..612235f61f 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 0d2e4f9800..73b639b2da 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 3db1531146..0165bdaa07 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 3abba312fc..49160fac4f 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 1e8d8033b3..130e3913f9 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 0724059492..c90cf424b2 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 66865080b6..238d1d2dd8 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 ddf698a202..8a48593c8f 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()); + 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::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); + drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage(), + wpi::units::volt_t{rightLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage()); + 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()); + 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 2a71a00e0f..df3626f038 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 e047396a59..694415b61f 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 0dc98a27e5..ee3bc8fd01 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 6d39814f00..0cbc94bc43 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 6dc25fce99..07c6ad73ce 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 currentTime = 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 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 = 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 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 ffbc667087..aafa85b6c0 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 0e9c426305..48afbcff88 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 98daed3f92..8b388c870e 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 d03185828c..d291b1f577 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 d8c58f2ab0..4af02f14b7 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 41e0502a1b..8dc89f9216 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 30ac839b98..1f406d5906 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 82e249ce3c..71a60e64d7 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 6a1add7288..4f4ee9cb91 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 07828f57dd..4d7a0c880b 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 c605aca226..af72778efb 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 d71256a8ce..58fdedde09 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 2f9f595e66..0ea914fe3b 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 4dfa94cb27..dd47cf34f4 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 3fdf7269cd..925eddef4c 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 4903f48755..d7ed37c4a9 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 60d5d31311..245a6c9e4b 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 71ad9ec71e..1ccd9ccb7f 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 75cfbc6612..23631e2207 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 9fc2a216c4..f39fcb031e 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 052f1a5cc5..b79c16cecc 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 8bae9bdad2..feaa942b87 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); + : 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); - m_left1.AddFollower(m_left2); - m_right1.AddFollower(m_right2); + 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 be653352f4..445959ecd8 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 377ae1bfc2..c59dc48dc3 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 27b5326b3e..d614f2b2f4 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 0367dd2409..f3c23f6ac3 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 d1fd94643c..0be87fc907 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 9fc2a216c4..f39fcb031e 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 b984ddf91b..4014810c72 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 fce831d9c3..13ebd9d786 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 d86e797bf8..9b32feb884 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 001229cc95..e6ebe5b3dd 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 4278ad5c9f..6df4ff982c 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 4dbca0e7ef..c05ecf04ec 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 8bae9bdad2..feaa942b87 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); + : 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); - m_left1.AddFollower(m_left2); - m_right1.AddFollower(m_right2); + 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 1a3e6bc986..3a4c02fc01 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 377ae1bfc2..c59dc48dc3 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 ff38bc36b9..4a82e45432 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 a45a1b2ce3..3c7ed8a9a0 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 756f127138..72138d7d83 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 d01746d498..87ba12ab0d 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 7440ba265d..ab23156729 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 f6e14c70e6..d5b4730bf3 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 0367dd2409..f3c23f6ac3 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 7560a28c81..0908b1162f 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 76d35011da..2d7b6daaf1 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 34bde68ea8..fd0d5cf8ed 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 dc18c7e4e4..601e6213d7 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 5bc01edabf..8b52aba075 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 70019bc794..86f8ce08e4 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 34bde68ea8..fd0d5cf8ed 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 8715083f16..dee0009cd5 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 2d965a1dd5..39fc5715a2 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 371179f7fd..e3272a9e1e 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 ef39cfe6dd..c86a0f0cb2 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 c5104a5ce3..ebc8644845 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 bf6e51f904..1246a1883c 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 ddd3ac76be..a9bd132f0e 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 0373c6b59d..3f011971fd 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 6ff8553290..eb56bcf51d 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 c8aa9ad9ff..e60b4413ac 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 151282ce6f..5ca3e74694 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 8ac5b46f1b..d0ee5d0a37 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 d8b393dc10..7c5f182d85 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 6f6763f5a4..c42e61b554 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 df6496d254..9bb4d30e42 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 40227711da..52facc1f42 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 2ec33e6770..dd9c9161d4 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 793af12753..88a44eb0af 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 a34b01b1af..d3d186cff2 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 f1be542fdd..68adcd297b 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 5a9f0bdd24..3df5d9d85e 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 bb19d62fa7..27a25e1591 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 fb04061475..88e8f63bf7 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 91369791c1..e447cbf379 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 2d2e802c16..afb6d52b14 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 cd97b5fa50..b9a410b338 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 e5ea1cc2c9..9b2a3f3379 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 f0b05af0d4..fc3a458268 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 b5ab55d0a0..b46029f595 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 c1fbbe72a3..2b049ae67a 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 c7fe21f761..24e179c8c6 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 104584f57f..d4716e7a43 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 e32dcf358f..501edea82c 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()); + 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()); - 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()}); } 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); + drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage(), + wpi::units::volt_t{rightLeader.GetThrottle()} * + wpi::RobotController::GetInputVoltage()); + 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()); + 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 410d539cb1..77670bbb56 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 3445331cb9..65ec0340b1 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 0fd1d0d805..3188ed7d88 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 080cb6cb5b..4660be5297 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 06d07b99bd..8a5bc8c6cf 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 712dfe4ca8..7668ed8987 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 150c4e86e5..2934ee3753 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 77e5382637..1bf4630c81 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 319b407096..076b972499 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 261bbaf705..b6c59696b1 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}; + 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}; - 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::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 27b3d7c677..78d68e5724 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 b29e456794..ce5561c93d 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 602cb5a2d6..c28f4d2807 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 c6c025958b..06a3db8338 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 211b569821..f2b50e5521 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 d57b709972..08787fb9f0 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 3dd2cac83b..132624950e 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 c9f1e14494..a99edb6e53 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()) - .WhileTrue( - m_drive.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); - (m_driverController.EastFace() && m_driverController.RightBumper()) - .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)); + (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)); - m_shooter.SetDefaultCommand(m_shooter.RunShooterCommand( - [this] { return m_driverController.GetLeftTriggerAxis(); })); + shooter.SetDefaultCommand(shooter.RunShooterCommand( + [this] { return driverController.GetLeftTriggerAxis(); })); - (m_driverController.SouthFace() && m_driverController.LeftBumper()) + (driverController.SouthFace() && driverController.LeftBumper()) .WhileTrue( - m_shooter.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); - (m_driverController.EastFace() && m_driverController.LeftBumper()) + shooter.SysIdQuasistatic(wpi::cmd::sysid::Direction::kForward)); + (driverController.EastFace() && 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 5c1d2c34e4..30c0f21365 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 06548fe3d8..d21f1a6c64 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 0eb843e390..0998e52c1c 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 dd5d208fb0..f86b8b6c34 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 bf47d51768..ca36bffe88 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 ce9c393347..a78950f87c 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 a4a8e57d89..ad87de56f4 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 3eec6fb6d2..fe1c7e1466 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 4b929ee93c..28629e3b57 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 00091b1deb..8faad9e842 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 3d0c33b5f1..00730443f2 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 2ec33e6770..dd9c9161d4 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 bc68d85967..f7516fe868 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 a34b01b1af..d3d186cff2 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 f1be542fdd..68adcd297b 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 76d0d8bd4f..f8006fd8f4 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 93ebe880d3..b2e09655f5 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 fb04061475..88e8f63bf7 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 ad3c122a7e..4dcd1d5d37 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 8904985feb..f57d0b02af 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 2d2e802c16..afb6d52b14 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 a82f8a5d9e..be8a94a5af 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 e5ea1cc2c9..9b2a3f3379 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 f0b05af0d4..fc3a458268 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 b5ab55d0a0..b46029f595 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 770781b4e9..42d1add8e4 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 c7fe21f761..24e179c8c6 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 ea33711440..d7b11493fa 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 9481144319..421d583d97 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 5254620c9c..8bc48fc276 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 9c536e4ff9..5b1f7522d0 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 fc808d93b7..e69f0ec3db 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 ab1f7278b3..3c32c93eb0 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 ac6ebaf457..112adf5780 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 69349427c5..cbdd1e7f1d 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 c5e7422a7a..33c3966516 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 d3874dbd48..67e0876a75 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 2bf4dd9efb..a3f03f4d54 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 79a8e25488..47edf6fda3 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 f4b4e87b37..26c727b499 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 b12634b8f3..e1e490bc92 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 0e78d207d9..bdb04f0094 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 a19dda2f9e..f813219812 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 249528a61b..5a4194c4b1 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 a702798ab3..f69ae88fac 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 41819c92fa..6506e0162c 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 f9e0322856..a445b26df3 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 8fae070107..e13e2885af 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 8525d7da90..1f01c5addd 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 667eb737e3..3f7007ace2 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 d3fb7ca084..41870068fb 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 33259d0bba..7f5468c12c 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 f63e8bdc43..960150779e 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 6e4563aa3a..3b9359c85b 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 864408b1e5..4cb1eb4763 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 98d76a7228..c6aff44dd3 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 9bb102d21c..42434a06bd 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 377ae1bfc2..c59dc48dc3 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 417f164989..6ae318c25b 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 3c2c1e2d93..f56e7ad2cd 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 7cc42500cd..ced4cbb525 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 9af2838a50..2610b1366a 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 e8720c0149..81bee18aea 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 212ed41ac6..745221cada 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 9c2241d1e1..a91570d7c2 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 e9c311e867..62c6daa3f2 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 049e7591dc..b24518e17b 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 3dd2cac83b..132624950e 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 523b71406d..08022568cb 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 746c29ab3d..3d107a1ed4 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 c3fac32fa4..31bc38535f 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 30e93ddcf7..9d259d14e4 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 be99d1d4e2..05ba1d0938 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 dc4d55139d..41ac4f920c 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 a7504220ae..6725d99316 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 6c8203f36f..ec067297ea 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 df91834109..6908000a22 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 ef489a9f02..16a791eaf2 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 7921465de8..992a0a3e0c 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 36a1016e79..65f0d5067c 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 2998b62c5b..3e0e237a03 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 8ddb1e0164..52b12cbd49 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 e4ee455067..5c1642abd8 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/wpilibj/src/main/java/org/wpilib/counter/EdgeConfiguration.java b/wpilibj/src/main/java/org/wpilib/counter/EdgeConfiguration.java index d16c8cc5b4..040aa6b6d2 100644 --- a/wpilibj/src/main/java/org/wpilib/counter/EdgeConfiguration.java +++ b/wpilibj/src/main/java/org/wpilib/counter/EdgeConfiguration.java @@ -12,7 +12,6 @@ public enum EdgeConfiguration { FALLING_EDGE(false); /** True if triggering on rising edge. */ - @SuppressWarnings("MemberName") public final boolean rising; EdgeConfiguration(boolean rising) { diff --git a/wpilibj/src/main/java/org/wpilib/drive/DifferentialDrive.java b/wpilibj/src/main/java/org/wpilib/drive/DifferentialDrive.java index 03fae9a8e3..686face276 100644 --- a/wpilibj/src/main/java/org/wpilib/drive/DifferentialDrive.java +++ b/wpilibj/src/main/java/org/wpilib/drive/DifferentialDrive.java @@ -68,7 +68,6 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC * *

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 8badcfb676..05e9469109 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/wpilibj/src/main/java/org/wpilib/driverstation/TouchpadFinger.java b/wpilibj/src/main/java/org/wpilib/driverstation/TouchpadFinger.java index b4c7b1fbab..bff57bcf3b 100644 --- a/wpilibj/src/main/java/org/wpilib/driverstation/TouchpadFinger.java +++ b/wpilibj/src/main/java/org/wpilib/driverstation/TouchpadFinger.java @@ -5,7 +5,6 @@ package org.wpilib.driverstation; /** Represents a finger on a touchpad. */ -@SuppressWarnings("MemberName") public final class TouchpadFinger { /** Whether the finger is touching the touchpad. */ public final boolean down; 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 94c38a270d..7e7d39e117 100644 --- a/wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java +++ b/wpilibj/src/main/java/org/wpilib/driverstation/internal/DriverStationBackend.java @@ -66,15 +66,15 @@ public final class DriverStationBackend { } private static final class HALJoystickTouchpadFinger { - public float m_x; - public float m_y; - public boolean m_down; + float m_x; + float m_y; + boolean m_down; } private static class HALJoystickTouchpad { - public final HALJoystickTouchpadFinger[] m_fingers = + final HALJoystickTouchpadFinger[] m_fingers = new HALJoystickTouchpadFinger[DriverStationJNI.MAX_JOYSTICK_TOUCHPAD_FINGERS]; - public int m_count; + int m_count; HALJoystickTouchpad() { for (int i = 0; i < m_fingers.length; i++) { @@ -84,9 +84,9 @@ public final class DriverStationBackend { } private static class HALJoystickTouchpads { - public final HALJoystickTouchpad[] m_touchpads = + final HALJoystickTouchpad[] m_touchpads = new HALJoystickTouchpad[DriverStationJNI.MAX_JOYSTICK_TOUCHPADS]; - public int m_count; + int m_count; HALJoystickTouchpads() { for (int i = 0; i < m_touchpads.length; i++) { @@ -96,13 +96,13 @@ public final class DriverStationBackend { } private static final class HALJoystickButtons { - public long m_buttons; - public long m_available; + long m_buttons; + long m_available; } private static class HALJoystickAxes { - public final float[] m_axes; - public int m_available; + final float[] m_axes; + int m_available; HALJoystickAxes(int count) { m_axes = new float[count]; @@ -110,10 +110,10 @@ public final class DriverStationBackend { } private static class HALJoystickAxesRaw { - public final short[] m_axes; + final short[] m_axes; @SuppressWarnings("unused") - public int m_available; + int m_available; HALJoystickAxesRaw(int count) { m_axes = new short[count]; @@ -121,8 +121,8 @@ public final class DriverStationBackend { } private static class HALJoystickPOVs { - public final byte[] m_povs; - public int m_available; + final byte[] m_povs; + int m_available; HALJoystickPOVs(int count) { m_povs = new byte[count]; @@ -151,7 +151,6 @@ public final class DriverStationBackend { return "<" + id + ">"; } - @SuppressWarnings("MemberName") private static class MatchDataSender { private static final String kSmartDashboardType = "FMSInfo"; diff --git a/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java b/wpilibj/src/main/java/org/wpilib/framework/RobotBase.java index 16aef6abe9..a73a6aa67a 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 @@ public abstract class RobotBase implements AutoCloseable { 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 446ee60fd4..abd58246d2 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 @@ import org.wpilib.units.measure.Time; */ 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 8473e5c4a2..dc9c69375d 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 class ADXL345_I2C implements NTSendable, AutoCloseable { } /** 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/expansionhub/ExpansionHub.java b/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java index fdea4fb9fa..4883d756cf 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/expansionhub/ExpansionHub.java @@ -13,7 +13,7 @@ import org.wpilib.system.Timer; /** 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 final int m_usbId; private int m_refCount; private int m_reservedMotorMask; private int m_reservedServoMask; 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 35e5e4a12b..30c8e8a822 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticHub.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticHub.java @@ -17,13 +17,13 @@ import org.wpilib.system.SensorUtil; /** 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_module; + private 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 int[] m_oneShotDurMs = new int[PortsJNI.getNumREVPHChannels()]; private final Object m_reserveLock = new Object(); DataStore(int busId, int module) { 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 da16079f77..465524c615 100644 --- a/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticsControlModule.java +++ b/wpilibj/src/main/java/org/wpilib/hardware/pneumatic/PneumaticsControlModule.java @@ -14,8 +14,8 @@ import org.wpilib.system.SensorUtil; /** 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_module; + private final int m_handle; private final int m_busId; private int m_refCount; private int m_reservedMask; diff --git a/wpilibj/src/main/java/org/wpilib/internal/PeriodicPriorityQueue.java b/wpilibj/src/main/java/org/wpilib/internal/PeriodicPriorityQueue.java index 2d4eeca958..389117d3e9 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 class PeriodicPriorityQueue { * @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 class PeriodicPriorityQueue { "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 class PeriodicPriorityQueue { 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 class PeriodicPriorityQueue { */ 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 class PeriodicPriorityQueue { * @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 class PeriodicPriorityQueue { */ @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 class PeriodicPriorityQueue { */ @Override public int hashCode() { - return Long.hashCode(m_expirationTime); + return Long.hashCode(expirationTime); } /** @@ -306,7 +304,7 @@ public class PeriodicPriorityQueue { 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 b3eee54011..f31ce4ed1c 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 final class AlertSim { } /** 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/test/java/org/wpilib/framework/OpModeRobotTest.java b/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java index 74c4c5fcf0..db832da7af 100644 --- a/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java +++ b/wpilibj/src/test/java/org/wpilib/framework/OpModeRobotTest.java @@ -25,6 +25,7 @@ import org.wpilib.util.Color; class OpModeRobotTest { static final double kPeriod = 0.02; + @SuppressWarnings("PMD.PublicFieldNamingConvention") public static class MockOpMode implements OpMode { public final AtomicInteger m_disabledPeriodicCount = new AtomicInteger(0); public final AtomicInteger m_startCount = new AtomicInteger(0); @@ -65,6 +66,7 @@ class OpModeRobotTest { OneArgOpMode(MockRobot robot) {} } + @SuppressWarnings("PMD.PublicFieldNamingConvention") static class MockRobot extends OpModeRobot { public final AtomicInteger m_driverStationConnectedCount = new AtomicInteger(0); public final AtomicInteger m_nonePeriodicCount = new AtomicInteger(0); diff --git a/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java b/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java index c90e0a83b9..b5230e6e7e 100644 --- a/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java +++ b/wpilibj/src/test/java/org/wpilib/framework/TimedRobotTest.java @@ -18,6 +18,7 @@ import org.wpilib.simulation.SimHooks; class TimedRobotTest { static final double kPeriod = 0.02; + @SuppressWarnings("PMD.PublicFieldNamingConvention") static class MockRobot extends TimedRobot { public final AtomicInteger m_simulationInitCount = new AtomicInteger(0); public final AtomicInteger m_disabledInitCount = new AtomicInteger(0); diff --git a/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java b/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java index 17fcdbafde..e6cfbbfdd2 100644 --- a/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java +++ b/wpilibj/src/test/java/org/wpilib/framework/TimesliceRobotTest.java @@ -16,6 +16,7 @@ import org.wpilib.simulation.DriverStationSim; import org.wpilib.simulation.SimHooks; class TimesliceRobotTest { + @SuppressWarnings("PMD.PublicFieldNamingConvention") static class MockRobot extends TimesliceRobot { public final AtomicInteger m_robotPeriodicCount = new AtomicInteger(0); 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 a7fe831b9c..e6d50c5e43 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 @@ import org.wpilib.util.sendable.SendableRegistry; * 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 class Robot extends TimedRobot { // 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 39e2a53db0..243ed8a8ee 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 @@ import org.wpilib.framework.TimedRobot; /** 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 fda913c301..ddc2dc112f 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 @@ import org.wpilib.util.Preferences; 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 5c4682d4e0..821ef452c6 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 class 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 class Drivetrain { * @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 425dd3f908..b21ac40c55 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.framework.TimedRobot; 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 class Robot extends TimedRobot { // 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 6aa067264d..7e138975e4 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 class 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); } /** @@ -155,8 +154,7 @@ public class Drivetrain { * @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 class Drivetrain { /** 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 class Drivetrain { // 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); + drivetrainSimulator.setInputs( + leftLeader.getThrottle() * RobotController.getInputVoltage(), + rightLeader.getThrottle() * RobotController.getInputVoltage()); + 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 + 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 83ccebbba2..cfba054d10 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.DoubleArrayTopic; 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 class Robot extends TimedRobot { // 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 a84dfef45b..0e226629c7 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 class ExampleSmartMotorController { kMovementWitchcraft } - double m_value; + double value; /** * Creates a new ExampleSmartMotorController. @@ -72,11 +72,11 @@ public class ExampleSmartMotorController { 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 24cf9b7666..3218371286 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { */ // 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 class Robot extends TimedRobot { // 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 98ae778f67..17f4344b2b 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 @@ import org.wpilib.examples.drivedistanceoffboard.subsystems.DriveSubsystem; */ 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 class 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 class 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 7604dfd0cd..0cb5d7d88d 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 @@ import org.wpilib.util.sendable.SendableRegistry; 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 class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { 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 class DriveSubsystem extends SubsystemBase { * @return the left encoder distance */ public double getLeftEncoderDistance() { - return m_leftLeader.getEncoderDistance(); + return leftLeader.getEncoderDistance(); } /** @@ -116,13 +116,13 @@ public class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { 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 class DriveSubsystem extends SubsystemBase { 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 e556456d9d..06b0bd1081 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 @@ import org.wpilib.smartdashboard.SmartDashboard; /** 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 class Robot extends 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. - 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 class Robot extends 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); + 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 class Robot extends TimedRobot { // 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 5127c54d62..8f2c68f97c 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 @@ import org.wpilib.math.trajectory.ExponentialProfile; 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 e17ee1dea3..54d1a2125b 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 @@ import org.wpilib.framework.TimedRobot; /** 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 class Robot extends TimedRobot { @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 33dabafae8..9d539646a0 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 @@ import org.wpilib.system.RobotController; 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 class Elevator implements AutoCloseable { 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 1dfe05abfa..914edf8df2 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 3186cf716a..ee554587ce 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 @@ import org.wpilib.framework.TimedRobot; /** 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 dc2cd935db..46635fcca6 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 @@ import org.wpilib.system.RobotController; 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 class Elevator implements AutoCloseable { * @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 e13a74f30f..da70562712 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 @@ import org.wpilib.math.trajectory.TrapezoidProfile; 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 4085536c87..810433493c 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 class Robot extends TimedRobot { * 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 class Robot extends TimedRobot { * 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 class Robot extends TimedRobot { * 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 cc682b641f..d62d334a0c 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 @@ import org.wpilib.util.sendable.SendableRegistry; * 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 class Robot extends TimedRobot { /** 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 5dffe8d44d..2173aa900c 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 class Robot extends TimedRobot { */ @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 634bf9d8d0..3ab91d2dee 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 @@ import org.wpilib.system.DataLogManager; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { // 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 0969e19bef..27feae7617 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 @@ import org.wpilib.smartdashboard.SmartDashboard; */ 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 class 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 class 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 @@ public class RobotContainer { * @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 e59465c92f..98f7ae17b2 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 @@ import org.wpilib.util.sendable.SendableRegistry; 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 class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { * @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 efecfd3f54..53a8e855fd 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 @@ import org.wpilib.util.sendable.SendableBuilder; /** 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 ccab66ed8b..70b90d4ad7 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 @@ import org.wpilib.system.DataLogManager; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { */ // 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 class Robot extends TimedRobot { // 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 395669067e..745ce1cd3a 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 @@ import org.wpilib.smartdashboard.SmartDashboard; */ 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 class 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 class 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 @@ public class RobotContainer { * @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 ed7ac70eeb..2ba85b9569 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 @@ import org.wpilib.examples.hatchbottraditional.subsystems.DriveSubsystem; * 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 7575a6534a..b9683c2667 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.command2.Command; 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 a2b5802bc0..804537876d 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 @@ import org.wpilib.examples.hatchbottraditional.subsystems.HatchSubsystem; */ 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 d700109c75..d4dfe9c662 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.command2.Command; 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 d7f7795ded..e355fc4796 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 @@ import org.wpilib.util.sendable.SendableRegistry; 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 class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { * @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 class DriveSubsystem extends SubsystemBase { * @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 ce0f0e217d..8d33de0cfe 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 @@ import org.wpilib.util.sendable.SendableBuilder; /** 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 f6648d111d..084057d815 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 class 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 class Drivetrain { */ 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 class Drivetrain { * @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 class Drivetrain { 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 1645e29e63..62b8f245c5 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.framework.TimedRobot; 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 @@ public class Robot extends TimedRobot { // 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 d03d9e421a..30c2884837 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 class Robot extends TimedRobot { 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 class Robot extends TimedRobot { 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 650d0b99ad..f000d7530c 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 class 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 class Drivetrain { */ 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 class Drivetrain { * @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 class Drivetrain { 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 32b5ac0766..563eb76fe7 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.framework.TimedRobot; 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 @@ public class Robot extends TimedRobot { // 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 ad7197b907..5a197a2665 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 class Robot extends TimedRobot { // 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 class Robot extends TimedRobot { @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 32a3cb6ce8..ce28a4f967 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 @@ import org.wpilib.examples.rapidreactcommandbot.subsystems.Storage; @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 class RapidReactCommandBot { // 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 class RapidReactCommandBot { */ 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 62060dcc70..a32bcd4061 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 @@ import org.wpilib.system.DataLogManager; */ @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 class Robot extends TimedRobot { @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 class Robot extends TimedRobot { // 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 b6655c8e04..77168e34ac 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 @@ import org.wpilib.util.sendable.SendableRegistry; @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 class Drive extends SubsystemBase { 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 class Drive extends SubsystemBase { 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 class Drive extends SubsystemBase { */ 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 6c9dce7bfe..18c447e1e0 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 @@ import org.wpilib.hardware.pneumatic.PneumaticsModuleType; @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 class Intake extends SubsystemBase { 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 12caca5af9..2bf2fe70a8 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 class Pneumatics extends SubsystemBase { 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 58582d1d17..d80a475dc6 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 @@ import org.wpilib.math.controller.SimpleMotorFeedforward; @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 class Shooter extends SubsystemBase { // 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 17e197f28e..a84447e903 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,25 +15,24 @@ import org.wpilib.hardware.motor.PWMSparkMax; @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") - @SuppressWarnings("checkstyle:MemberName") - 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 15e6eac312..e2bb17bfa6 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { @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 class Robot extends TimedRobot { // 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 2a0897feea..310634379a 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 @@ import org.wpilib.smartdashboard.SmartDashboard; */ 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 class 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 @@ public class RobotContainer { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_chooser.getSelected(); + return chooser.getSelected(); } /** @@ -92,6 +92,6 @@ public class RobotContainer { */ 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 bd39ed42a8..4bb6f53012 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.command2.Command; 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 class ArcadeDrive extends Command { 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 class ArcadeDrive extends Command { // 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 751080c705..2b1ca57297 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.command2.Command; 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 08ee8e6ec5..16267838a0 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.command2.Command; 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 8aa7502d7a..42099d912b 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.command2.Command; 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 class TurnDegrees extends Command { @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 @@ public class TurnDegrees extends Command { */ 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 2dcd878c21..cd9004a8c5 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 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain; * 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 26c5940af4..52d83c435e 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 class Drivetrain extends SubsystemBase { * @return The current angle of the Romi in degrees */ public double getGyroAngleX() { - return m_gyro.getAngleX(); + return gyro.getAngleX(); } /** @@ -92,7 +92,7 @@ public class Drivetrain extends SubsystemBase { * @return The current angle of the Romi in degrees */ public double getGyroAngleY() { - return m_gyro.getAngleY(); + return gyro.getAngleY(); } /** @@ -101,12 +101,12 @@ public class Drivetrain extends SubsystemBase { * @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 f138ba2646..8cc49eeaa8 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 class Drivetrain { * @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 class Drivetrain { // 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); + drivetrainSimulator.setInputs( + leftLeader.getThrottle() * RobotController.getInputVoltage(), + rightLeader.getThrottle() * RobotController.getInputVoltage()); + 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()); + 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 192684998c..c168bf88ed 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.math.trajectory.TrajectoryGenerator; 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 class Robot extends TimedRobot { @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 8d280eed77..ce508d4bd9 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 class Robot extends TimedRobot { // 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 class Robot extends TimedRobot { 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 ef19654e9b..263f73fdd4 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 class Robot extends TimedRobot { // 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 class Robot extends TimedRobot { 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 696d181e51..e7ca94623c 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 23e8d202b3..3c953ac15d 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 4c0d28d03e..50738dea9b 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 class Drivetrain { 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 623fafcfd3..7cdd0f9d05 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.filter.SlewRateLimiter; 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 @@ public class Robot extends TimedRobot { // 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 @@ public class Robot extends TimedRobot { // 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 bcf68dc27f..ec876187e0 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 class 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 class 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 class SwerveModule { */ 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 class SwerveModule { * @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 class SwerveModule { 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()); + turningPIDController.calculate(turningEncoder.getDistance(), velocity.angle.getRadians()) + + turnFeedforward.calculate(turningPIDController.getSetpoint().velocity); - final double turnFeedforward = - m_turnFeedforward.calculate(m_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 bceaeb58ca..3ecafaef46 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 class Drivetrain { 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 bf8f9a79e4..560833a49f 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.framework.TimedRobot; 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 @@ public class Robot extends TimedRobot { // 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 2b4df5008e..f0bb36c43e 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 class 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 class 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 class SwerveModule { */ 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 class SwerveModule { * @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 class SwerveModule { 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()); + turningPIDController.calculate(turningEncoder.getDistance(), velocity.angle.getRadians()) + + turnFeedforward.calculate(turningPIDController.getSetpoint().velocity); - final double turnFeedforward = - m_turnFeedforward.calculate(m_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 161c0b0d1c..484daf3551 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { @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 class Robot extends TimedRobot { // 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 04a623c619..4bd489ef21 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 @@ import org.wpilib.examples.sysidroutine.subsystems.Shooter; */ 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 class SysIdRoutineBot { */ 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 58804fc6f7..e248b5799c 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 @@ import org.wpilib.system.RobotController; 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 class Drive extends SubsystemBase { 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 class Drive extends SubsystemBase { * @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 class Drive extends SubsystemBase { * @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 1c62532ece..03782a9b32 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 @@ import org.wpilib.system.RobotController; 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 class Shooter extends SubsystemBase { 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 class Shooter extends SubsystemBase { * @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 class Shooter extends SubsystemBase { * @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 ccb50c6079..bcae93bb68 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 @@ import org.wpilib.util.sendable.SendableRegistry; * 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 class Robot extends TimedRobot { // 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 e982965767..c987c11e1a 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 @@ import org.wpilib.framework.TimedRobot; * 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 5bb8bfcf58..34e79cb541 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.DoubleSolenoid; 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 class Intake implements AutoCloseable { } 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 312b0d8e89..4a716352e4 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { // 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 ab3ef480df..e7143bf107 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 @@ import org.wpilib.xrp.XRPOnBoardIO; */ 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 class 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 @@ public class RobotContainer { * @return the command to run in autonomous */ public Command getAutonomousCommand() { - return m_chooser.getSelected(); + return chooser.getSelected(); } /** @@ -94,6 +94,6 @@ public class RobotContainer { */ 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 898f4e5187..4071ef68f7 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.command2.Command; 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 class ArcadeDrive extends Command { 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 class ArcadeDrive extends Command { // 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 e8d5176b83..0e98a0675d 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.command2.Command; 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 bf59231b78..df8c82bfb8 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.command2.Command; 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 a08b2fa8b4..6d76536b9d 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.command2.Command; 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 class TurnDegrees extends Command { @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 @@ public class TurnDegrees extends Command { */ 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 b12c0d7f2f..39629fc30d 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 @@ import org.wpilib.examples.xrpreference.subsystems.Drivetrain; * 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 d4187706cb..b660e3b21e 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.command2.SubsystemBase; 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 class Arm extends SubsystemBase { * @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 289fcd0b08..830943d27a 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 class Drivetrain extends SubsystemBase { * @return The current angle of the XRP in degrees */ public double getGyroAngleX() { - return m_gyro.getAngleX(); + return gyro.getAngleX(); } /** @@ -95,7 +95,7 @@ public class Drivetrain extends SubsystemBase { * @return The current angle of the XRP in degrees */ public double getGyroAngleY() { - return m_gyro.getAngleY(); + return gyro.getAngleY(); } /** @@ -104,12 +104,12 @@ public class Drivetrain extends SubsystemBase { * @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 8a2dd0e999..974cd48052 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 @@ import org.wpilib.xrp.XRPMotor; * 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 class Robot extends TimedRobot { /** 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 ebb5e8ab75..f8de5323c3 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 @@ import org.wpilib.smartdashboard.SmartDashboard; */ @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 508a7950c8..7dfaa0c5cc 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 @@ import org.wpilib.smartdashboard.SmartDashboard; * 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 4d38df734e..8628707ce7 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.hardware.led.LEDPattern; 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 a12a919eb6..769df78322 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 @@ import org.wpilib.hardware.bus.I2C; */ 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 class Robot extends TimedRobot { @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 562e8ed2a6..b43000ad39 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 @@ import org.wpilib.hardware.accelerometer.AnalogAccelerometer; */ 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 6a549e21b8..69cde8cbbf 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 @@ import org.wpilib.hardware.rotation.AnalogEncoder; */ 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 class Robot extends TimedRobot { @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 dfd12a225c..a654cff57d 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 @@ import org.wpilib.hardware.discrete.AnalogInput; */ 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 class Robot extends 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(); } } 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 f4f979dc52..cd8d0ead7f 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 class Robot extends TimedRobot { @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 07788fdf83..a7666ab79b 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 @@ import org.wpilib.smartdashboard.SmartDashboard; * 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 class Robot extends TimedRobot { // 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 6fb792157c..6975db0986 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 class Robot extends TimedRobot { } // 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 52d1246e1c..d8785a6862 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 @@ import org.wpilib.hardware.discrete.DigitalInput; */ 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 de694afcb0..e73a86d69b 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 @@ import org.wpilib.hardware.rotation.DutyCycleEncoder; */ 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 class Robot extends TimedRobot { @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 9e46e496eb..6c186087df 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.hardware.rotation.DutyCycle; 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 3ce39d3c70..3cee5542f8 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 @@ import org.wpilib.hardware.rotation.Encoder; 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 02dfa40ba9..3cd2c1f145 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 @@ import org.wpilib.hardware.rotation.Encoder; */ 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 24c42dcfc0..bf68106d01 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 @@ import org.wpilib.hardware.rotation.Encoder; * 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 1c180083dc..9244ccf71f 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 class Robot extends TimedRobot { // 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 2deb9e0bee..50a2eae2ec 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 class Robot extends TimedRobot { 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 class Robot extends TimedRobot { 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 3285abed9f..a4f8eadd81 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 @@ import org.wpilib.vision.stream.CameraServer; * 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 class Robot extends TimedRobot { 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 1512f9a735..6f26129d94 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 @@ public class Robot extends TimedRobot { } // 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 class Robot extends TimedRobot { /** 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 ed48ee4e71..3918e5b78e 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 @@ import org.wpilib.vision.stream.CameraServer; * 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 class Robot extends TimedRobot { 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 e4faff1b98..43d173688c 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 @@ import org.wpilib.hardware.motor.PWMVictorSPX; * 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 class Robot extends TimedRobot { */ 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 5119bfdd07..92b9c9d51d 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 class Robot extends TimedRobot { */ @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 294c40807d..4dcfc58ac6 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 @@ import org.wpilib.hardware.imu.OnboardIMU.MountOrientation; */ 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 class Robot extends TimedRobot { @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 64946713ac..a7c9c303c2 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 @@ import org.wpilib.math.trajectory.TrapezoidProfile; * 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 class Robot extends TimedRobot { * @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 ec7b3718a0..d4003f82d2 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { */ // 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 class Robot extends TimedRobot { // 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 ab98c431dd..e72cb6e6ac 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 @@ public class RobotContainer { // 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 @@ public class RobotContainer { * @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 430dbedb00..b577589e0d 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 @@ import org.wpilib.smartdashboard.SmartDashboard; * 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 class Robot extends TimedRobot { // 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 class Robot extends TimedRobot { // 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 c0ecbb3eb0..7b76b43686 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { // 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 e698490910..975ea2439f 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 @@ import org.wpilib.templates.commandv2.subsystems.ExampleSubsystem; */ 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 class 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 @@ public class RobotContainer { */ 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 800a188906..c6f44e966c 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 @@ import org.wpilib.templates.commandv2.subsystems.ExampleSubsystem; /** 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 58c83afcad..f0cec556a2 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.command2.CommandScheduler; 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 class Robot extends TimedRobot { @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 class Robot extends TimedRobot { @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 2c75aafce0..9255d667da 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 class EducationalRobot extends RobotBase { run(); } - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -52,7 +52,7 @@ public class EducationalRobot extends RobotBase { // 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 class EducationalRobot extends RobotBase { @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 5ae1d4f487..47e5e9a274 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 @@ import org.wpilib.templates.opmode.Robot; @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 1a91977adc..50c433520d 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 @@ import org.wpilib.templates.opmode.Robot; @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 135ab43cb7..10d157e824 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 class Robot extends RobotBase { public void utility() {} - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -47,7 +47,7 @@ public class Robot extends RobotBase { // 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 class Robot extends RobotBase { @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 fbe78e7c39..32a736cf2c 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { // 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 5994d1914c..858a6012ee 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 @@ import org.wpilib.templates.romicommandv2.subsystems.RomiDrivetrain; */ 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 @@ public class RobotContainer { */ 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 f21a9aee0d..02607b3cc3 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 @@ import org.wpilib.templates.romicommandv2.subsystems.RomiDrivetrain; /** 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 60f8c5e15e..d6b6260311 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 5041fb9df7..96f0a6eea1 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 class EducationalRobot extends RobotBase { run(); } - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -52,7 +52,7 @@ public class EducationalRobot extends RobotBase { // 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 class EducationalRobot extends RobotBase { @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 3bcf03dda9..352f400381 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 61e52bdde8..3fd1b301bb 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 @@ import org.wpilib.smartdashboard.SmartDashboard; 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 class Robot extends TimedRobot { */ @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 f0bd81d763..022c72713f 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 605d85de96..4085237648 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 @@ import org.wpilib.smartdashboard.SmartDashboard; 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 class Robot extends TimedRobot { */ @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 6c510a1923..dfea75c96d 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 @@ import org.wpilib.smartdashboard.SmartDashboard; 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 class Robot extends TimesliceRobot { // 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 class Robot extends TimesliceRobot { */ @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 9044b98232..0403d31121 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 @@ import org.wpilib.framework.TimedRobot; * 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 class Robot extends TimedRobot { /** 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 class Robot extends TimedRobot { // 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 193189ff5a..15cddc68ce 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 @@ import org.wpilib.templates.xrpcommandv2.subsystems.XRPDrivetrain; */ 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 @@ public class RobotContainer { */ 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 f44d6c017c..d7dec635e8 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 @@ import org.wpilib.templates.xrpcommandv2.subsystems.XRPDrivetrain; /** 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 daa425c040..09cb8ac494 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 b200d25884..3babe6b82b 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 class EducationalRobot extends RobotBase { run(); } - private volatile boolean m_exit; + private volatile boolean exit; @Override public void startCompetition() { @@ -52,7 +52,7 @@ public class EducationalRobot extends RobotBase { // 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 class EducationalRobot extends RobotBase { @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 7192bea520..5d896b8b7b 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 98c0d13080..b28b0dd057 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 @@ import org.wpilib.smartdashboard.SmartDashboard; 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 class Robot extends TimedRobot { */ @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 21f86df29b..64469c7097 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 db3e45e30d..1fe1ec284c 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 @@ import org.wpilib.util.Preferences; @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 @@ class ArmSimulationTest { 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 @@ class ArmSimulationTest { DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - assertTrue(m_encoderSim.getInitialized()); + assertTrue(encoderSim.getInitialized()); } { @@ -88,50 +88,50 @@ class ArmSimulationTest { 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 @@ class ArmSimulationTest { // 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 ec9b775004..ca75b5d940 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 @@ import org.wpilib.simulation.SimHooks; @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 @@ class ElevatorSimulationTest { 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 @@ class ElevatorSimulationTest { DriverStationSim.setEnabled(true); DriverStationSim.notifyNewData(); - assertTrue(m_encoderSim.getInitialized()); + assertTrue(encoderSim.getInitialized()); } { @@ -77,50 +77,50 @@ class ElevatorSimulationTest { 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 @@ class ElevatorSimulationTest { // 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 dbe57359ca..ebf549d5af 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 @@ import org.wpilib.simulation.PWMMotorControllerSim; 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 @@ class IntakeTest { @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 51051b649f..1c9c985803 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 @@ import org.wpilib.simulation.SimHooks; @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 @@ class DigitalCommunicationTest { 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 @@ class DigitalCommunicationTest { 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 @@ class DigitalCommunicationTest { 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 @@ class DigitalCommunicationTest { 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 @@ class DigitalCommunicationTest { 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 f2313df886..d1e493ae4e 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 @@ import org.wpilib.simulation.SimHooks; @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 @@ class I2CCommunicationTest { 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 @@ class I2CCommunicationTest { 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 @@ class I2CCommunicationTest { 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 @@ class I2CCommunicationTest { 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 @@ class I2CCommunicationTest { 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)); 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 d15c54388a..71273e97cd 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 class DifferentialDriveFeedforward implements ProtobufSerializable, Struc 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 f1a2cfa8e0..8cd51ebd6b 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 final class DifferentialDriveFeedforwardProto @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 66fc9a5e2a..48dc9132f4 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 final class DifferentialDriveFeedforwardStruct @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 742a27d1d1..703a8960a7 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 de924ac96a..3275befefd 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 0b320ad9fc..90b1bfb4a5 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 6abe7270d8..c4b2169ccd 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 a1da6199cb..982905c526 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 1d95b5405b..04bc82e19e 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 StructTestBaseLimited 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 d33ca81f34..8aed51822c 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 @@ package org.wpilib.util; 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 d550dd8dca..4140055a97 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 5b7a5e09bc..e2aeaccbcb 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 @@ import java.util.Map; /** 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 767765a88d..72c816108e 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 @@ import java.util.List; /** Raw struct schema. */ public class ParsedSchema { /** Declarations. */ - @SuppressWarnings("MemberName") public List declarations = new ArrayList<>(); /** Default constructor. */ 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 688fe803fe..0e15fbd1bb 100644 --- a/wpiutil/src/test/java/org/wpilib/util/cleanup/CleanupPoolTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/cleanup/CleanupPoolTest.java @@ -13,6 +13,7 @@ import java.util.List; import org.junit.jupiter.api.Test; class CleanupPoolTest { + @SuppressWarnings("PMD.PublicFieldNamingConvention") static class AutoCloseableObject implements AutoCloseable { public boolean m_closed; 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 786e8e5c9c..aa8ac7c086 100644 --- a/wpiutil/src/test/java/org/wpilib/util/cleanup/ReflectionCleanupTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/cleanup/ReflectionCleanupTest.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; class ReflectionCleanupTest { + @SuppressWarnings("PMD.PublicFieldNamingConvention") static class CleanupClass implements AutoCloseable { public boolean m_closed; @@ -19,7 +20,7 @@ class ReflectionCleanupTest { } } - @SuppressWarnings("PMD.TestClassWithoutTestCases") + @SuppressWarnings({"PMD.TestClassWithoutTestCases", "PMD.PublicFieldNamingConvention"}) static class CleanupTest implements ReflectionCleanup { public CleanupClass m_class1 = new CleanupClass(); public CleanupClass m_class2 = new CleanupClass(); @@ -32,6 +33,7 @@ class ReflectionCleanupTest { } } + @SuppressWarnings("PMD.PublicFieldNamingConvention") static class CleanupTest2 extends CleanupTest { @SkipCleanup public CleanupClass m_class3 = new CleanupClass(); public CleanupClass m_class4 = new CleanupClass(); 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 b0c2fdb019..db4e794835 100644 --- a/wpiutil/src/test/java/org/wpilib/util/struct/DynamicStructTest.java +++ b/wpiutil/src/test/java/org/wpilib/util/struct/DynamicStructTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.params.provider.MethodSource; @SuppressWarnings("AvoidEscapedUnicodeCharacters") class DynamicStructTest { - @SuppressWarnings("MemberName") private StructDescriptorDatabase db; @BeforeEach