Don't force public variables to use Hungarian notation (#8774)

People generally have expressed a dislike for the Hungarian notation
used in member variables, especially in examples/templates, and our
styleguide shouldn't be forced on downstream consumers, so this removes
all Hungarian notation from the examples/templates.

There are _some_ benefits to Hungarian for private member variables
(like knowing what's a member vs. local in a PR review) so we'll keep
private member variables the same for now, but public variables should
no longer use Hungarian notation, since it looks much worse. A new PMD
XPath rule has been added to accomplish this goal. Some other
non-compliant variables were fixed for the new rule.
This commit is contained in:
Gold856
2026-04-25 14:32:08 -04:00
committed by GitHub
parent e7e51c9c05
commit 35e8abedeb
443 changed files with 4584 additions and 4789 deletions

View File

@@ -11,11 +11,11 @@ import org.wpilib.util.RawFrame;
import org.wpilib.vision.apriltag.jni.AprilTagJNI; import org.wpilib.vision.apriltag.jni.AprilTagJNI;
/** Represents an AprilTag's metadata. */ /** Represents an AprilTag's metadata. */
@SuppressWarnings("MemberName")
@Json @Json
public class AprilTag { public class AprilTag {
/** The tag's ID. */ /** The tag's ID. */
@Json.Property("ID") @Json.Property("ID")
@SuppressWarnings("PMD.PublicFieldNamingConvention")
public int ID; public int ID;
/** The tag's pose. */ /** The tag's pose. */

View File

@@ -14,7 +14,6 @@ import org.wpilib.vision.apriltag.jni.AprilTagJNI;
*/ */
public class AprilTagDetector implements AutoCloseable { public class AprilTagDetector implements AutoCloseable {
/** Detector configuration. */ /** Detector configuration. */
@SuppressWarnings("MemberName")
public static class Config { public static class Config {
/** /**
* How many threads should be used for computation. Default is single-threaded operation (1 * 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. */ /** Quad threshold parameters. */
@SuppressWarnings("MemberName")
public static class QuadThresholdParameters { public static class QuadThresholdParameters {
/** Threshold used to reject quads containing too few pixels. Default is 300 pixels. */ /** Threshold used to reject quads containing too few pixels. Default is 300 pixels. */
public int minClusterPixels = 300; public int minClusterPixels = 300;

View File

@@ -216,19 +216,19 @@ public class AprilTagFieldLayout {
* @throws UncheckedIOException If the layout does not exist. * @throws UncheckedIOException If the layout does not exist.
*/ */
public static AprilTagFieldLayout loadField(AprilTagFields field) { public static AprilTagFieldLayout loadField(AprilTagFields field) {
if (field.m_fieldLayout == null) { if (field.fieldLayout == null) {
try { try {
field.m_fieldLayout = loadFromResource(field.m_resourceFile); field.fieldLayout = loadFromResource(field.resourceFile);
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException( 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 // Copy layout because the layout's origin is mutable
return new AprilTagFieldLayout( return new AprilTagFieldLayout(
field.m_fieldLayout.getTags(), field.fieldLayout.getTags(),
field.m_fieldLayout.getFieldLength(), field.fieldLayout.getFieldLength(),
field.m_fieldLayout.getFieldWidth()); field.fieldLayout.getFieldWidth());
} }
/** /**
@@ -264,11 +264,9 @@ public class AprilTagFieldLayout {
} }
static class FieldDimensions { static class FieldDimensions {
@SuppressWarnings("MemberName")
@Json.Property(value = "length") @Json.Property(value = "length")
public final double fieldLength; public final double fieldLength;
@SuppressWarnings("MemberName")
@Json.Property(value = "width") @Json.Property(value = "width")
public final double fieldWidth; public final double fieldWidth;

View File

@@ -28,11 +28,11 @@ public enum AprilTagFields {
public static final AprilTagFields kDefaultField = k2026RebuiltWelded; public static final AprilTagFields kDefaultField = k2026RebuiltWelded;
/** Resource filename. */ /** Resource filename. */
public final String m_resourceFile; public final String resourceFile;
AprilTagFieldLayout m_fieldLayout; AprilTagFieldLayout fieldLayout;
AprilTagFields(String resourceFile) { AprilTagFields(String resourceFile) {
m_resourceFile = kBaseResourceDir + resourceFile; this.resourceFile = kBaseResourceDir + resourceFile;
} }
} }

View File

@@ -7,7 +7,6 @@ package org.wpilib.vision.apriltag;
import org.wpilib.math.geometry.Transform3d; import org.wpilib.math.geometry.Transform3d;
/** A pair of AprilTag pose estimates. */ /** A pair of AprilTag pose estimates. */
@SuppressWarnings("MemberName")
public class AprilTagPoseEstimate { public class AprilTagPoseEstimate {
/** /**
* Constructs a pose estimate. * Constructs a pose estimate.

View File

@@ -10,7 +10,6 @@ import org.wpilib.vision.apriltag.jni.AprilTagJNI;
/** Pose estimators for AprilTag tags. */ /** Pose estimators for AprilTag tags. */
public class AprilTagPoseEstimator { public class AprilTagPoseEstimator {
/** Configuration for the pose estimator. */ /** Configuration for the pose estimator. */
@SuppressWarnings("MemberName")
public static class Config { public static class Config {
/** /**
* Creates a pose estimator configuration. * Creates a pose estimator configuration.

View File

@@ -25,7 +25,6 @@ import org.wpilib.math.util.Units;
import org.wpilib.util.runtime.RuntimeLoader; import org.wpilib.util.runtime.RuntimeLoader;
class AprilTagDetectorTest { class AprilTagDetectorTest {
@SuppressWarnings("MemberName")
AprilTagDetector detector; AprilTagDetector detector;
@BeforeAll @BeforeAll

View File

@@ -49,7 +49,6 @@ import org.wpilib.vision.stream.CameraServer;
public final class Main { public final class Main {
private static String configFile = "/boot/CameraServerConfig.json"; private static String configFile = "/boot/CameraServerConfig.json";
@SuppressWarnings("MemberName")
public static class CameraConfig { public static class CameraConfig {
public String name; public String name;
public String path; public String path;

View File

@@ -50,25 +50,25 @@ public class SysIdRoutine extends SysIdRoutineLog {
* @param mechanism Hardware interface for the SysId routine. * @param mechanism Hardware interface for the SysId routine.
*/ */
public SysIdRoutine(Config config, Mechanism mechanism) { public SysIdRoutine(Config config, Mechanism mechanism) {
super(mechanism.m_name); super(mechanism.name);
m_config = config; m_config = config;
m_mechanism = mechanism; 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. */ /** Hardware-independent configuration for a SysId test routine. */
public static class Config { public static class Config {
/** The voltage ramp rate used for quasistatic test routines. */ /** The voltage ramp rate used for quasistatic test routines. */
public final Velocity<VoltageUnit> m_rampRate; public final Velocity<VoltageUnit> rampRate;
/** The step voltage output used for dynamic test routines. */ /** 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. */ /** 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. */ /** Optional handle for recording test state in a third-party logging solution. */
public final Consumer<State> m_recordState; public final Consumer<State> recordState;
/** /**
* Create a new configuration for a SysId test routine. * Create a new configuration for a SysId test routine.
@@ -88,10 +88,10 @@ public class SysIdRoutine extends SysIdRoutineLog {
Voltage stepVoltage, Voltage stepVoltage,
Time timeout, Time timeout,
Consumer<State> recordState) { Consumer<State> recordState) {
m_rampRate = rampRate != null ? rampRate : Volts.of(1).per(Second); this.rampRate = rampRate != null ? rampRate : Volts.of(1).per(Second);
m_stepVoltage = stepVoltage != null ? stepVoltage : Volts.of(7); this.stepVoltage = stepVoltage != null ? stepVoltage : Volts.of(7);
m_timeout = timeout != null ? timeout : Seconds.of(10); this.timeout = timeout != null ? timeout : Seconds.of(10);
m_recordState = recordState; this.recordState = recordState;
} }
/** /**
@@ -128,19 +128,19 @@ public class SysIdRoutine extends SysIdRoutineLog {
*/ */
public static class Mechanism { public static class Mechanism {
/** Sends the SysId-specified drive signal to the mechanism motors during test routines. */ /** Sends the SysId-specified drive signal to the mechanism motors during test routines. */
public final Consumer<? super Voltage> m_drive; public final Consumer<? super Voltage> drive;
/** /**
* Returns measured data (voltages, positions, velocities) of the mechanism motors during test * Returns measured data (voltages, positions, velocities) of the mechanism motors during test
* routines. * routines.
*/ */
public final Consumer<SysIdRoutineLog> m_log; public final Consumer<SysIdRoutineLog> log;
/** The subsystem containing the motor(s) that is (or are) being characterized. */ /** 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. */ /** 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. * Create a new mechanism specification for a SysId routine.
@@ -160,10 +160,10 @@ public class SysIdRoutine extends SysIdRoutineLog {
*/ */
public Mechanism( public Mechanism(
Consumer<Voltage> drive, Consumer<SysIdRoutineLog> log, Subsystem subsystem, String name) { Consumer<Voltage> drive, Consumer<SysIdRoutineLog> log, Subsystem subsystem, String name) {
m_drive = drive; this.drive = drive;
m_log = log != null ? log : l -> {}; this.log = log != null ? log : l -> {};
m_subsystem = subsystem; this.subsystem = subsystem;
m_name = name != null ? name : subsystem.getName(); this.name = name != null ? name : subsystem.getName();
} }
/** /**
@@ -217,24 +217,24 @@ public class SysIdRoutine extends SysIdRoutineLog {
Timer timer = new Timer(); Timer timer = new Timer();
return m_mechanism return m_mechanism
.m_subsystem .subsystem
.runOnce(timer::restart) .runOnce(timer::restart)
.andThen( .andThen(
m_mechanism.m_subsystem.run( m_mechanism.subsystem.run(
() -> { () -> {
m_mechanism.m_drive.accept( m_mechanism.drive.accept(
(Voltage) m_config.m_rampRate.times(Seconds.of(timer.get() * outputSign))); (Voltage) m_config.rampRate.times(Seconds.of(timer.get() * outputSign)));
m_mechanism.m_log.accept(this); m_mechanism.log.accept(this);
m_recordState.accept(state); m_recordState.accept(state);
})) }))
.finallyDo( .finallyDo(
() -> { () -> {
m_mechanism.m_drive.accept(Volts.of(0)); m_mechanism.drive.accept(Volts.of(0));
m_recordState.accept(State.NONE); m_recordState.accept(State.NONE);
timer.stop(); timer.stop();
}) })
.withName("sysid-" + state.toString() + "-" + m_mechanism.m_name) .withName("sysid-" + state.toString() + "-" + m_mechanism.name)
.withTimeout(m_config.m_timeout.in(Seconds)); .withTimeout(m_config.timeout.in(Seconds));
} }
/** /**
@@ -257,21 +257,21 @@ public class SysIdRoutine extends SysIdRoutineLog {
Voltage[] output = {Volts.zero()}; Voltage[] output = {Volts.zero()};
return m_mechanism return m_mechanism
.m_subsystem .subsystem
.runOnce(() -> output[0] = m_config.m_stepVoltage.times(outputSign)) .runOnce(() -> output[0] = m_config.stepVoltage.times(outputSign))
.andThen( .andThen(
m_mechanism.m_subsystem.run( m_mechanism.subsystem.run(
() -> { () -> {
m_mechanism.m_drive.accept(output[0]); m_mechanism.drive.accept(output[0]);
m_mechanism.m_log.accept(this); m_mechanism.log.accept(this);
m_recordState.accept(state); m_recordState.accept(state);
})) }))
.finallyDo( .finallyDo(
() -> { () -> {
m_mechanism.m_drive.accept(Volts.of(0)); m_mechanism.drive.accept(Volts.of(0));
m_recordState.accept(State.NONE); m_recordState.accept(State.NONE);
}) })
.withName("sysid-" + state.toString() + "-" + m_mechanism.m_name) .withName("sysid-" + state.toString() + "-" + m_mechanism.name)
.withTimeout(m_config.m_timeout.in(Seconds)); .withTimeout(m_config.timeout.in(Seconds));
} }
} }

View File

@@ -18,24 +18,24 @@ wpi::cmd::CommandPtr SysIdRoutine::Quasistatic(Direction direction) {
double outputSign = direction == Direction::kForward ? 1.0 : -1.0; 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( .AndThen(
m_mechanism.m_subsystem m_mechanism.subsystem
->Run([this, state, outputSign] { ->Run([this, state, outputSign] {
m_outputVolts = outputSign * timer.Get() * m_config.m_rampRate; m_outputVolts = outputSign * timer.Get() * m_config.rampRate;
m_mechanism.m_drive(m_outputVolts); m_mechanism.drive(m_outputVolts);
m_mechanism.m_log(this); m_mechanism.log(this);
m_recordState(state); m_recordState(state);
}) })
.FinallyDo([this] { .FinallyDo([this] {
m_mechanism.m_drive(0_V); m_mechanism.drive(0_V);
m_recordState(wpi::sysid::State::NONE); m_recordState(wpi::sysid::State::NONE);
timer.Stop(); timer.Stop();
}) })
.WithName("sysid-" + .WithName("sysid-" +
wpi::sysid::SysIdRoutineLog::StateEnumToString(state) + wpi::sysid::SysIdRoutineLog::StateEnumToString(state) +
"-" + m_mechanism.m_name) "-" + m_mechanism.name)
.WithTimeout(m_config.m_timeout)); .WithTimeout(m_config.timeout));
} }
wpi::cmd::CommandPtr SysIdRoutine::Dynamic(Direction direction) { 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; double outputSign = direction == Direction::kForward ? 1.0 : -1.0;
return m_mechanism.m_subsystem return m_mechanism.subsystem
->RunOnce([this] { m_outputVolts = m_config.m_stepVoltage; }) ->RunOnce([this] { m_outputVolts = m_config.stepVoltage; })
.AndThen(m_mechanism.m_subsystem->Run([this, state, outputSign] { .AndThen(m_mechanism.subsystem->Run([this, state, outputSign] {
m_mechanism.m_drive(m_outputVolts * outputSign); m_mechanism.drive(m_outputVolts * outputSign);
m_mechanism.m_log(this); m_mechanism.log(this);
m_recordState(state); m_recordState(state);
})) }))
.FinallyDo([this] { .FinallyDo([this] {
m_mechanism.m_drive(0_V); m_mechanism.drive(0_V);
m_recordState(wpi::sysid::State::NONE); m_recordState(wpi::sysid::State::NONE);
}) })
.WithName("sysid-" + .WithName("sysid-" +
wpi::sysid::SysIdRoutineLog::StateEnumToString(state) + "-" + wpi::sysid::SysIdRoutineLog::StateEnumToString(state) + "-" +
m_mechanism.m_name) m_mechanism.name)
.WithTimeout(m_config.m_timeout); .WithTimeout(m_config.timeout);
} }

View File

@@ -23,17 +23,17 @@ using ramp_rate_t = wpi::units::unit_t<wpi::units::compound_unit<
class Config { class Config {
public: public:
/// The voltage ramp rate used for quasistatic test routines. /// The voltage ramp rate used for quasistatic test routines.
ramp_rate_t m_rampRate{1_V / 1_s}; ramp_rate_t rampRate{1_V / 1_s};
/// The step voltage output used for dynamic test routines. /// The step voltage output used for dynamic test routines.
wpi::units::volt_t m_stepVoltage{7_V}; wpi::units::volt_t stepVoltage{7_V};
/// Safety timeout for the test routine commands. /// Safety timeout for the test routine commands.
wpi::units::second_t m_timeout{10_s}; wpi::units::second_t timeout{10_s};
/// Optional handle for recording test state in a third-party logging /// Optional handle for recording test state in a third-party logging
/// solution. /// solution.
std::function<void(wpi::sysid::State)> m_recordState; std::function<void(wpi::sysid::State)> recordState;
/** /**
* Create a new configuration for a SysId test routine. * Create a new configuration for a SysId test routine.
@@ -52,15 +52,15 @@ class Config {
std::optional<wpi::units::volt_t> stepVoltage, std::optional<wpi::units::volt_t> stepVoltage,
std::optional<wpi::units::second_t> timeout, std::optional<wpi::units::second_t> timeout,
std::function<void(wpi::sysid::State)> recordState) std::function<void(wpi::sysid::State)> recordState)
: m_recordState{std::move(recordState)} { : recordState{std::move(recordState)} {
if (rampRate) { if (rampRate) {
m_rampRate = rampRate.value(); this->rampRate = rampRate.value();
} }
if (stepVoltage) { if (stepVoltage) {
m_stepVoltage = stepVoltage.value(); this->stepVoltage = stepVoltage.value();
} }
if (timeout) { if (timeout) {
m_timeout = timeout.value(); this->timeout = timeout.value();
} }
} }
}; };
@@ -69,19 +69,19 @@ class Mechanism {
public: public:
/// Sends the SysId-specified drive signal to the mechanism motors during test /// Sends the SysId-specified drive signal to the mechanism motors during test
/// routines. /// routines.
std::function<void(wpi::units::volt_t)> m_drive; std::function<void(wpi::units::volt_t)> drive;
/// Returns measured data (voltages, positions, velocities) of the mechanism /// Returns measured data (voltages, positions, velocities) of the mechanism
/// motors during test routines. /// motors during test routines.
std::function<void(wpi::sysid::SysIdRoutineLog*)> m_log; std::function<void(wpi::sysid::SysIdRoutineLog*)> log;
/// The subsystem containing the motor(s) that is (or are) being /// The subsystem containing the motor(s) that is (or are) being
/// characterized. /// characterized.
wpi::cmd::Subsystem* m_subsystem; wpi::cmd::Subsystem* subsystem;
/// The name of the mechanism being tested. Will be appended to the log entry /// 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". /// 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. * Create a new mechanism specification for a SysId routine.
@@ -105,10 +105,10 @@ class Mechanism {
Mechanism(std::function<void(wpi::units::volt_t)> drive, Mechanism(std::function<void(wpi::units::volt_t)> drive,
std::function<void(wpi::sysid::SysIdRoutineLog*)> log, std::function<void(wpi::sysid::SysIdRoutineLog*)> log,
wpi::cmd::Subsystem* subsystem, std::string_view name) wpi::cmd::Subsystem* subsystem, std::string_view name)
: m_drive{std::move(drive)}, : drive{std::move(drive)},
m_log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}}, log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}},
m_subsystem{subsystem}, subsystem{subsystem},
m_name{name} {} name{name} {}
/** /**
* Create a new mechanism specification for a SysId routine. Defaults the * Create a new mechanism specification for a SysId routine. Defaults the
@@ -130,10 +130,10 @@ class Mechanism {
Mechanism(std::function<void(wpi::units::volt_t)> drive, Mechanism(std::function<void(wpi::units::volt_t)> drive,
std::function<void(wpi::sysid::SysIdRoutineLog*)> log, std::function<void(wpi::sysid::SysIdRoutineLog*)> log,
wpi::cmd::Subsystem* subsystem) wpi::cmd::Subsystem* subsystem)
: m_drive{std::move(drive)}, : drive{std::move(drive)},
m_log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}}, log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}},
m_subsystem{subsystem}, subsystem{subsystem},
m_name{m_subsystem->GetName()} {} name{subsystem->GetName()} {}
}; };
/** /**
@@ -176,13 +176,13 @@ class SysIdRoutine : public wpi::sysid::SysIdRoutineLog {
* @param mechanism Hardware interface for the SysId routine. * @param mechanism Hardware interface for the SysId routine.
*/ */
SysIdRoutine(Config config, Mechanism mechanism) SysIdRoutine(Config config, Mechanism mechanism)
: SysIdRoutineLog(mechanism.m_name), : SysIdRoutineLog(mechanism.name),
m_config(config), m_config(config),
m_mechanism(mechanism), m_mechanism(mechanism),
m_recordState(config.m_recordState ? config.m_recordState m_recordState(config.recordState ? config.recordState
: [this](wpi::sysid::State state) { : [this](wpi::sysid::State state) {
this->RecordState(state); this->RecordState(state);
}) {} }) {}
wpi::cmd::CommandPtr Quasistatic(Direction direction); wpi::cmd::CommandPtr Quasistatic(Direction direction);
wpi::cmd::CommandPtr Dynamic(Direction direction); wpi::cmd::CommandPtr Dynamic(Direction direction);

View File

@@ -5,7 +5,6 @@
package org.wpilib.vision.camera; package org.wpilib.vision.camera;
/** USB camera information. */ /** USB camera information. */
@SuppressWarnings("MemberName")
public class UsbCameraInfo { public class UsbCameraInfo {
/** /**
* Create a new set of UsbCameraInfo. * Create a new set of UsbCameraInfo.

View File

@@ -5,7 +5,6 @@
package org.wpilib.vision.camera; package org.wpilib.vision.camera;
/** Video event. */ /** Video event. */
@SuppressWarnings("MemberName")
public class VideoEvent { public class VideoEvent {
/** VideoEvent kind. */ /** VideoEvent kind. */
public enum Kind { public enum Kind {

View File

@@ -8,7 +8,6 @@ import java.util.Objects;
import org.wpilib.util.PixelFormat; import org.wpilib.util.PixelFormat;
/** Video mode. */ /** Video mode. */
@SuppressWarnings("MemberName")
public class VideoMode { public class VideoMode {
/** /**
* Create a new video mode. * Create a new video mode.

View File

@@ -124,7 +124,6 @@ public class DataLogRecord {
* Data contained in a start control record as created by DataLog.start() when writing the log. * Data contained in a start control record as created by DataLog.start() when writing the log.
* This can be read by calling getStartData(). * This can be read by calling getStartData().
*/ */
@SuppressWarnings("MemberName")
public static class StartRecordData { public static class StartRecordData {
StartRecordData(int entry, String name, String type, String metadata) { StartRecordData(int entry, String name, String type, String metadata) {
this.entry = entry; 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 * Data contained in a set metadata control record as created by DataLog.setMetadata(). This can
* be read by calling getSetMetadataData(). * be read by calling getSetMetadataData().
*/ */
@SuppressWarnings("MemberName")
public static class MetadataRecordData { public static class MetadataRecordData {
MetadataRecordData(int entry, String metadata) { MetadataRecordData(int entry, String metadata) {
this.entry = entry; this.entry = entry;

View File

@@ -119,7 +119,6 @@ class DataLogTest {
} }
} }
@SuppressWarnings("MemberName")
private static int cloneCalls; private static int cloneCalls;
static class CloneableThing implements StructSerializable, Cloneable { static class CloneableThing implements StructSerializable, Cloneable {
@@ -201,10 +200,8 @@ class DataLogTest {
public static final ThingStruct struct = new ThingStruct(); public static final ThingStruct struct = new ThingStruct();
} }
@SuppressWarnings("MemberName")
private ByteArrayOutputStream data; private ByteArrayOutputStream data;
@SuppressWarnings("MemberName")
private DataLog log; private DataLog log;
@BeforeEach @BeforeEach

View File

@@ -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 * A configuration object to be used by the generated {@code Epilogue} class to customize its
* behavior. * behavior.
*/ */
@SuppressWarnings("checkstyle:MemberName")
public class EpilogueConfiguration { public class EpilogueConfiguration {
/** /**
* The backend implementation for Epilogue to use. By default, this will log data directly to * The backend implementation for Epilogue to use. By default, this will log data directly to

View File

@@ -17,39 +17,38 @@ import java.nio.file.Path;
public class FieldConfig { public class FieldConfig {
public static class Corners { public static class Corners {
@Json.Property("top-left") @Json.Property("top-left")
public double[] m_topLeft; public double[] topLeft;
@Json.Property("bottom-right") @Json.Property("bottom-right")
public double[] m_bottomRight; public double[] bottomRight;
} }
@Json.Property("game") @Json.Property("game")
public String m_game; public String game;
@Json.Property("field-image") @Json.Property("field-image")
public String m_fieldImage; public String fieldImage;
@Json.Property("field-corners") @Json.Property("field-corners")
public Corners m_fieldCorners; public Corners fieldCorners;
@Json.Property("field-size") @Json.Property("field-size")
public double[] m_fieldSize; public double[] fieldSize;
@Json.Property("field-unit") @Json.Property("field-unit")
public String m_fieldUnit; public String fieldUnit;
@Json.Property("program") @Json.Property("program")
public String m_program; public String program;
public FieldConfig() {} public FieldConfig() {}
public URL getImageUrl() { 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() { public InputStream getImageAsStream() {
return getClass() return getClass().getResourceAsStream(Fields.BASE_RESOURCE_DIR + program + "/" + fieldImage);
.getResourceAsStream(Fields.BASE_RESOURCE_DIR + m_program + "/" + m_fieldImage);
} }
/** /**

View File

@@ -24,7 +24,6 @@ public enum Fields {
public static final String BASE_RESOURCE_DIR = "/org/wpilib/fields/"; public static final String BASE_RESOURCE_DIR = "/org/wpilib/fields/";
@SuppressWarnings("MemberName")
public final String resourceFile; public final String resourceFile;
Fields(String resourceFile) { Fields(String resourceFile) {

View File

@@ -55,7 +55,6 @@ public final class CANAPITypes {
FIRMWARE_UPDATE(31); FIRMWARE_UPDATE(31);
/** The device type ID. */ /** The device type ID. */
@SuppressWarnings("MemberName")
public final int id; public final int id;
CANDeviceType(int id) { CANDeviceType(int id) {
@@ -118,7 +117,6 @@ public final class CANAPITypes {
BRUSHLAND_LABS(20); BRUSHLAND_LABS(20);
/** The manufacturer ID. */ /** The manufacturer ID. */
@SuppressWarnings("MemberName")
public final int id; public final int id;
CANManufacturer(int id) { CANManufacturer(int id) {

View File

@@ -5,7 +5,6 @@
package org.wpilib.hardware.hal; package org.wpilib.hardware.hal;
/** Structure for holding the match info data request. */ /** Structure for holding the match info data request. */
@SuppressWarnings("MemberName")
public class MatchInfoData { public class MatchInfoData {
/** Stores the event name. */ /** Stores the event name. */
public String eventName = ""; public String eventName = "";

View File

@@ -7,22 +7,16 @@ package org.wpilib.hardware.hal;
/** An individual opmode option. */ /** An individual opmode option. */
public class OpModeOption { public class OpModeOption {
/** Unique id. Encodes robot mode in bits 57-56, LSB 56 bits is hash of name. */ /** Unique id. Encodes robot mode in bits 57-56, LSB 56 bits is hash of name. */
@SuppressWarnings("MemberName")
public final long id; public final long id;
@SuppressWarnings("MemberName")
public final String name; public final String name;
@SuppressWarnings("MemberName")
public final String group; public final String group;
@SuppressWarnings("MemberName")
public final String description; public final String description;
@SuppressWarnings("MemberName")
public final int textColor; public final int textColor;
@SuppressWarnings("MemberName")
public final int backgroundColor; public final int backgroundColor;
/** /**

View File

@@ -8,88 +8,87 @@ package org.wpilib.hardware.hal;
* Faults for a PowerDistribution device. These faults are only active while the condition is * Faults for a PowerDistribution device. These faults are only active while the condition is
* active. * active.
*/ */
@SuppressWarnings("MemberName")
public class PowerDistributionFaults { public class PowerDistributionFaults {
/** Breaker fault on channel 0. */ /** Breaker fault on channel 0. */
public final boolean Channel0BreakerFault; public final boolean channel0BreakerFault;
/** Breaker fault on channel 1. */ /** Breaker fault on channel 1. */
public final boolean Channel1BreakerFault; public final boolean channel1BreakerFault;
/** Breaker fault on channel 2. */ /** Breaker fault on channel 2. */
public final boolean Channel2BreakerFault; public final boolean channel2BreakerFault;
/** Breaker fault on channel 3. */ /** Breaker fault on channel 3. */
public final boolean Channel3BreakerFault; public final boolean channel3BreakerFault;
/** Breaker fault on channel 4. */ /** Breaker fault on channel 4. */
public final boolean Channel4BreakerFault; public final boolean channel4BreakerFault;
/** Breaker fault on channel 5. */ /** Breaker fault on channel 5. */
public final boolean Channel5BreakerFault; public final boolean channel5BreakerFault;
/** Breaker fault on channel 6. */ /** Breaker fault on channel 6. */
public final boolean Channel6BreakerFault; public final boolean channel6BreakerFault;
/** Breaker fault on channel 7. */ /** Breaker fault on channel 7. */
public final boolean Channel7BreakerFault; public final boolean channel7BreakerFault;
/** Breaker fault on channel 8. */ /** Breaker fault on channel 8. */
public final boolean Channel8BreakerFault; public final boolean channel8BreakerFault;
/** Breaker fault on channel 9. */ /** Breaker fault on channel 9. */
public final boolean Channel9BreakerFault; public final boolean channel9BreakerFault;
/** Breaker fault on channel 10. */ /** Breaker fault on channel 10. */
public final boolean Channel10BreakerFault; public final boolean channel10BreakerFault;
/** Breaker fault on channel 11. */ /** Breaker fault on channel 11. */
public final boolean Channel11BreakerFault; public final boolean channel11BreakerFault;
/** Breaker fault on channel 12. */ /** Breaker fault on channel 12. */
public final boolean Channel12BreakerFault; public final boolean channel12BreakerFault;
/** Breaker fault on channel 13. */ /** Breaker fault on channel 13. */
public final boolean Channel13BreakerFault; public final boolean channel13BreakerFault;
/** Breaker fault on channel 14. */ /** Breaker fault on channel 14. */
public final boolean Channel14BreakerFault; public final boolean channel14BreakerFault;
/** Breaker fault on channel 15. */ /** Breaker fault on channel 15. */
public final boolean Channel15BreakerFault; public final boolean channel15BreakerFault;
/** Breaker fault on channel 16. */ /** Breaker fault on channel 16. */
public final boolean Channel16BreakerFault; public final boolean channel16BreakerFault;
/** Breaker fault on channel 17. */ /** Breaker fault on channel 17. */
public final boolean Channel17BreakerFault; public final boolean channel17BreakerFault;
/** Breaker fault on channel 18. */ /** Breaker fault on channel 18. */
public final boolean Channel18BreakerFault; public final boolean channel18BreakerFault;
/** Breaker fault on channel 19. */ /** Breaker fault on channel 19. */
public final boolean Channel19BreakerFault; public final boolean channel19BreakerFault;
/** Breaker fault on channel 20. */ /** Breaker fault on channel 20. */
public final boolean Channel20BreakerFault; public final boolean channel20BreakerFault;
/** Breaker fault on channel 21. */ /** Breaker fault on channel 21. */
public final boolean Channel21BreakerFault; public final boolean channel21BreakerFault;
/** Breaker fault on channel 22. */ /** Breaker fault on channel 22. */
public final boolean Channel22BreakerFault; public final boolean channel22BreakerFault;
/** Breaker fault on channel 23. */ /** Breaker fault on channel 23. */
public final boolean Channel23BreakerFault; public final boolean channel23BreakerFault;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. * Gets whether there is a breaker fault at the specified channel.
@@ -101,30 +100,30 @@ public class PowerDistributionFaults {
*/ */
public final boolean getBreakerFault(int channel) { public final boolean getBreakerFault(int channel) {
return switch (channel) { return switch (channel) {
case 0 -> Channel0BreakerFault; case 0 -> channel0BreakerFault;
case 1 -> Channel1BreakerFault; case 1 -> channel1BreakerFault;
case 2 -> Channel2BreakerFault; case 2 -> channel2BreakerFault;
case 3 -> Channel3BreakerFault; case 3 -> channel3BreakerFault;
case 4 -> Channel4BreakerFault; case 4 -> channel4BreakerFault;
case 5 -> Channel5BreakerFault; case 5 -> channel5BreakerFault;
case 6 -> Channel6BreakerFault; case 6 -> channel6BreakerFault;
case 7 -> Channel7BreakerFault; case 7 -> channel7BreakerFault;
case 8 -> Channel8BreakerFault; case 8 -> channel8BreakerFault;
case 9 -> Channel9BreakerFault; case 9 -> channel9BreakerFault;
case 10 -> Channel10BreakerFault; case 10 -> channel10BreakerFault;
case 11 -> Channel11BreakerFault; case 11 -> channel11BreakerFault;
case 12 -> Channel12BreakerFault; case 12 -> channel12BreakerFault;
case 13 -> Channel13BreakerFault; case 13 -> channel13BreakerFault;
case 14 -> Channel14BreakerFault; case 14 -> channel14BreakerFault;
case 15 -> Channel15BreakerFault; case 15 -> channel15BreakerFault;
case 16 -> Channel16BreakerFault; case 16 -> channel16BreakerFault;
case 17 -> Channel17BreakerFault; case 17 -> channel17BreakerFault;
case 18 -> Channel18BreakerFault; case 18 -> channel18BreakerFault;
case 19 -> Channel19BreakerFault; case 19 -> channel19BreakerFault;
case 20 -> Channel20BreakerFault; case 20 -> channel20BreakerFault;
case 21 -> Channel21BreakerFault; case 21 -> channel21BreakerFault;
case 22 -> Channel22BreakerFault; case 22 -> channel22BreakerFault;
case 23 -> Channel23BreakerFault; case 23 -> channel23BreakerFault;
default -> default ->
throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!"); throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!");
}; };
@@ -136,32 +135,32 @@ public class PowerDistributionFaults {
* @param faults faults * @param faults faults
*/ */
public PowerDistributionFaults(int faults) { public PowerDistributionFaults(int faults) {
Channel0BreakerFault = (faults & 0x1) != 0; channel0BreakerFault = (faults & 0x1) != 0;
Channel1BreakerFault = (faults & 0x2) != 0; channel1BreakerFault = (faults & 0x2) != 0;
Channel2BreakerFault = (faults & 0x4) != 0; channel2BreakerFault = (faults & 0x4) != 0;
Channel3BreakerFault = (faults & 0x8) != 0; channel3BreakerFault = (faults & 0x8) != 0;
Channel4BreakerFault = (faults & 0x10) != 0; channel4BreakerFault = (faults & 0x10) != 0;
Channel5BreakerFault = (faults & 0x20) != 0; channel5BreakerFault = (faults & 0x20) != 0;
Channel6BreakerFault = (faults & 0x40) != 0; channel6BreakerFault = (faults & 0x40) != 0;
Channel7BreakerFault = (faults & 0x80) != 0; channel7BreakerFault = (faults & 0x80) != 0;
Channel8BreakerFault = (faults & 0x100) != 0; channel8BreakerFault = (faults & 0x100) != 0;
Channel9BreakerFault = (faults & 0x200) != 0; channel9BreakerFault = (faults & 0x200) != 0;
Channel10BreakerFault = (faults & 0x400) != 0; channel10BreakerFault = (faults & 0x400) != 0;
Channel11BreakerFault = (faults & 0x800) != 0; channel11BreakerFault = (faults & 0x800) != 0;
Channel12BreakerFault = (faults & 0x1000) != 0; channel12BreakerFault = (faults & 0x1000) != 0;
Channel13BreakerFault = (faults & 0x2000) != 0; channel13BreakerFault = (faults & 0x2000) != 0;
Channel14BreakerFault = (faults & 0x4000) != 0; channel14BreakerFault = (faults & 0x4000) != 0;
Channel15BreakerFault = (faults & 0x8000) != 0; channel15BreakerFault = (faults & 0x8000) != 0;
Channel16BreakerFault = (faults & 0x10000) != 0; channel16BreakerFault = (faults & 0x10000) != 0;
Channel17BreakerFault = (faults & 0x20000) != 0; channel17BreakerFault = (faults & 0x20000) != 0;
Channel18BreakerFault = (faults & 0x40000) != 0; channel18BreakerFault = (faults & 0x40000) != 0;
Channel19BreakerFault = (faults & 0x80000) != 0; channel19BreakerFault = (faults & 0x80000) != 0;
Channel20BreakerFault = (faults & 0x100000) != 0; channel20BreakerFault = (faults & 0x100000) != 0;
Channel21BreakerFault = (faults & 0x200000) != 0; channel21BreakerFault = (faults & 0x200000) != 0;
Channel22BreakerFault = (faults & 0x400000) != 0; channel22BreakerFault = (faults & 0x400000) != 0;
Channel23BreakerFault = (faults & 0x800000) != 0; channel23BreakerFault = (faults & 0x800000) != 0;
Brownout = (faults & 0x1000000) != 0; brownout = (faults & 0x1000000) != 0;
CanWarning = (faults & 0x2000000) != 0; canWarning = (faults & 0x2000000) != 0;
HardwareFault = (faults & 0x4000000) != 0; hardwareFault = (faults & 0x4000000) != 0;
} }
} }

View File

@@ -8,97 +8,96 @@ package org.wpilib.hardware.hal;
* Sticky faults for a PowerDistribution device. These faults will remain active until they are * Sticky faults for a PowerDistribution device. These faults will remain active until they are
* reset by the user. * reset by the user.
*/ */
@SuppressWarnings("MemberName")
public class PowerDistributionStickyFaults { public class PowerDistributionStickyFaults {
/** Breaker fault on channel 0. */ /** Breaker fault on channel 0. */
public final boolean Channel0BreakerFault; public final boolean channel0BreakerFault;
/** Breaker fault on channel 1. */ /** Breaker fault on channel 1. */
public final boolean Channel1BreakerFault; public final boolean channel1BreakerFault;
/** Breaker fault on channel 2. */ /** Breaker fault on channel 2. */
public final boolean Channel2BreakerFault; public final boolean channel2BreakerFault;
/** Breaker fault on channel 3. */ /** Breaker fault on channel 3. */
public final boolean Channel3BreakerFault; public final boolean channel3BreakerFault;
/** Breaker fault on channel 4. */ /** Breaker fault on channel 4. */
public final boolean Channel4BreakerFault; public final boolean channel4BreakerFault;
/** Breaker fault on channel 5. */ /** Breaker fault on channel 5. */
public final boolean Channel5BreakerFault; public final boolean channel5BreakerFault;
/** Breaker fault on channel 6. */ /** Breaker fault on channel 6. */
public final boolean Channel6BreakerFault; public final boolean channel6BreakerFault;
/** Breaker fault on channel 7. */ /** Breaker fault on channel 7. */
public final boolean Channel7BreakerFault; public final boolean channel7BreakerFault;
/** Breaker fault on channel 8. */ /** Breaker fault on channel 8. */
public final boolean Channel8BreakerFault; public final boolean channel8BreakerFault;
/** Breaker fault on channel 9. */ /** Breaker fault on channel 9. */
public final boolean Channel9BreakerFault; public final boolean channel9BreakerFault;
/** Breaker fault on channel 10. */ /** Breaker fault on channel 10. */
public final boolean Channel10BreakerFault; public final boolean channel10BreakerFault;
/** Breaker fault on channel 11. */ /** Breaker fault on channel 11. */
public final boolean Channel11BreakerFault; public final boolean channel11BreakerFault;
/** Breaker fault on channel 12. */ /** Breaker fault on channel 12. */
public final boolean Channel12BreakerFault; public final boolean channel12BreakerFault;
/** Breaker fault on channel 13. */ /** Breaker fault on channel 13. */
public final boolean Channel13BreakerFault; public final boolean channel13BreakerFault;
/** Breaker fault on channel 14. */ /** Breaker fault on channel 14. */
public final boolean Channel14BreakerFault; public final boolean channel14BreakerFault;
/** Breaker fault on channel 15. */ /** Breaker fault on channel 15. */
public final boolean Channel15BreakerFault; public final boolean channel15BreakerFault;
/** Breaker fault on channel 16. */ /** Breaker fault on channel 16. */
public final boolean Channel16BreakerFault; public final boolean channel16BreakerFault;
/** Breaker fault on channel 17. */ /** Breaker fault on channel 17. */
public final boolean Channel17BreakerFault; public final boolean channel17BreakerFault;
/** Breaker fault on channel 18. */ /** Breaker fault on channel 18. */
public final boolean Channel18BreakerFault; public final boolean channel18BreakerFault;
/** Breaker fault on channel 19. */ /** Breaker fault on channel 19. */
public final boolean Channel19BreakerFault; public final boolean channel19BreakerFault;
/** Breaker fault on channel 20. */ /** Breaker fault on channel 20. */
public final boolean Channel20BreakerFault; public final boolean channel20BreakerFault;
/** Breaker fault on channel 21. */ /** Breaker fault on channel 21. */
public final boolean Channel21BreakerFault; public final boolean channel21BreakerFault;
/** Breaker fault on channel 22. */ /** Breaker fault on channel 22. */
public final boolean Channel22BreakerFault; public final boolean channel22BreakerFault;
/** Breaker fault on channel 23. */ /** Breaker fault on channel 23. */
public final boolean Channel23BreakerFault; public final boolean channel23BreakerFault;
/** The input voltage was below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. */ /** The hardware on the device has malfunctioned. */
public final boolean HardwareFault; public final boolean hardwareFault;
/** The firmware on the device has malfunctioned. */ /** The firmware on the device has malfunctioned. */
public final boolean FirmwareFault; public final boolean firmwareFault;
/** The device has rebooted. */ /** The device has rebooted. */
public final boolean HasReset; public final boolean hasReset;
/** /**
* Gets whether there is a sticky breaker fault at the specified channel. * 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) { public final boolean getBreakerFault(int channel) {
return switch (channel) { return switch (channel) {
case 0 -> Channel0BreakerFault; case 0 -> channel0BreakerFault;
case 1 -> Channel1BreakerFault; case 1 -> channel1BreakerFault;
case 2 -> Channel2BreakerFault; case 2 -> channel2BreakerFault;
case 3 -> Channel3BreakerFault; case 3 -> channel3BreakerFault;
case 4 -> Channel4BreakerFault; case 4 -> channel4BreakerFault;
case 5 -> Channel5BreakerFault; case 5 -> channel5BreakerFault;
case 6 -> Channel6BreakerFault; case 6 -> channel6BreakerFault;
case 7 -> Channel7BreakerFault; case 7 -> channel7BreakerFault;
case 8 -> Channel8BreakerFault; case 8 -> channel8BreakerFault;
case 9 -> Channel9BreakerFault; case 9 -> channel9BreakerFault;
case 10 -> Channel10BreakerFault; case 10 -> channel10BreakerFault;
case 11 -> Channel11BreakerFault; case 11 -> channel11BreakerFault;
case 12 -> Channel12BreakerFault; case 12 -> channel12BreakerFault;
case 13 -> Channel13BreakerFault; case 13 -> channel13BreakerFault;
case 14 -> Channel14BreakerFault; case 14 -> channel14BreakerFault;
case 15 -> Channel15BreakerFault; case 15 -> channel15BreakerFault;
case 16 -> Channel16BreakerFault; case 16 -> channel16BreakerFault;
case 17 -> Channel17BreakerFault; case 17 -> channel17BreakerFault;
case 18 -> Channel18BreakerFault; case 18 -> channel18BreakerFault;
case 19 -> Channel19BreakerFault; case 19 -> channel19BreakerFault;
case 20 -> Channel20BreakerFault; case 20 -> channel20BreakerFault;
case 21 -> Channel21BreakerFault; case 21 -> channel21BreakerFault;
case 22 -> Channel22BreakerFault; case 22 -> channel22BreakerFault;
case 23 -> Channel23BreakerFault; case 23 -> channel23BreakerFault;
default -> default ->
throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!"); throw new IndexOutOfBoundsException("Power distribution fault channel out of bounds!");
}; };
@@ -145,35 +144,35 @@ public class PowerDistributionStickyFaults {
* @param faults faults * @param faults faults
*/ */
public PowerDistributionStickyFaults(int faults) { public PowerDistributionStickyFaults(int faults) {
Channel0BreakerFault = (faults & 0x1) != 0; channel0BreakerFault = (faults & 0x1) != 0;
Channel1BreakerFault = (faults & 0x2) != 0; channel1BreakerFault = (faults & 0x2) != 0;
Channel2BreakerFault = (faults & 0x4) != 0; channel2BreakerFault = (faults & 0x4) != 0;
Channel3BreakerFault = (faults & 0x8) != 0; channel3BreakerFault = (faults & 0x8) != 0;
Channel4BreakerFault = (faults & 0x10) != 0; channel4BreakerFault = (faults & 0x10) != 0;
Channel5BreakerFault = (faults & 0x20) != 0; channel5BreakerFault = (faults & 0x20) != 0;
Channel6BreakerFault = (faults & 0x40) != 0; channel6BreakerFault = (faults & 0x40) != 0;
Channel7BreakerFault = (faults & 0x80) != 0; channel7BreakerFault = (faults & 0x80) != 0;
Channel8BreakerFault = (faults & 0x100) != 0; channel8BreakerFault = (faults & 0x100) != 0;
Channel9BreakerFault = (faults & 0x200) != 0; channel9BreakerFault = (faults & 0x200) != 0;
Channel10BreakerFault = (faults & 0x400) != 0; channel10BreakerFault = (faults & 0x400) != 0;
Channel11BreakerFault = (faults & 0x800) != 0; channel11BreakerFault = (faults & 0x800) != 0;
Channel12BreakerFault = (faults & 0x1000) != 0; channel12BreakerFault = (faults & 0x1000) != 0;
Channel13BreakerFault = (faults & 0x2000) != 0; channel13BreakerFault = (faults & 0x2000) != 0;
Channel14BreakerFault = (faults & 0x4000) != 0; channel14BreakerFault = (faults & 0x4000) != 0;
Channel15BreakerFault = (faults & 0x8000) != 0; channel15BreakerFault = (faults & 0x8000) != 0;
Channel16BreakerFault = (faults & 0x10000) != 0; channel16BreakerFault = (faults & 0x10000) != 0;
Channel17BreakerFault = (faults & 0x20000) != 0; channel17BreakerFault = (faults & 0x20000) != 0;
Channel18BreakerFault = (faults & 0x40000) != 0; channel18BreakerFault = (faults & 0x40000) != 0;
Channel19BreakerFault = (faults & 0x80000) != 0; channel19BreakerFault = (faults & 0x80000) != 0;
Channel20BreakerFault = (faults & 0x100000) != 0; channel20BreakerFault = (faults & 0x100000) != 0;
Channel21BreakerFault = (faults & 0x200000) != 0; channel21BreakerFault = (faults & 0x200000) != 0;
Channel22BreakerFault = (faults & 0x400000) != 0; channel22BreakerFault = (faults & 0x400000) != 0;
Channel23BreakerFault = (faults & 0x800000) != 0; channel23BreakerFault = (faults & 0x800000) != 0;
Brownout = (faults & 0x1000000) != 0; brownout = (faults & 0x1000000) != 0;
CanWarning = (faults & 0x2000000) != 0; canWarning = (faults & 0x2000000) != 0;
CanBusOff = (faults & 0x4000000) != 0; canBusOff = (faults & 0x4000000) != 0;
HardwareFault = (faults & 0x8000000) != 0; hardwareFault = (faults & 0x8000000) != 0;
FirmwareFault = (faults & 0x10000000) != 0; firmwareFault = (faults & 0x10000000) != 0;
HasReset = (faults & 0x20000000) != 0; hasReset = (faults & 0x20000000) != 0;
} }
} }

View File

@@ -5,7 +5,6 @@
package org.wpilib.hardware.hal; package org.wpilib.hardware.hal;
/** Power distribution version. */ /** Power distribution version. */
@SuppressWarnings("MemberName")
public class PowerDistributionVersion { public class PowerDistributionVersion {
/** Firmware major version number. */ /** Firmware major version number. */
public final int firmwareMajor; public final int firmwareMajor;

View File

@@ -5,73 +5,72 @@
package org.wpilib.hardware.hal; package org.wpilib.hardware.hal;
/** Faults for a REV PH. These faults are only active while the condition is active. */ /** Faults for a REV PH. These faults are only active while the condition is active. */
@SuppressWarnings("MemberName")
public class REVPHFaults { public class REVPHFaults {
/** Fault on channel 0. */ /** Fault on channel 0. */
public final boolean Channel0Fault; public final boolean channel0Fault;
/** Fault on channel 1. */ /** Fault on channel 1. */
public final boolean Channel1Fault; public final boolean channel1Fault;
/** Fault on channel 2. */ /** Fault on channel 2. */
public final boolean Channel2Fault; public final boolean channel2Fault;
/** Fault on channel 3. */ /** Fault on channel 3. */
public final boolean Channel3Fault; public final boolean channel3Fault;
/** Fault on channel 4. */ /** Fault on channel 4. */
public final boolean Channel4Fault; public final boolean channel4Fault;
/** Fault on channel 5. */ /** Fault on channel 5. */
public final boolean Channel5Fault; public final boolean channel5Fault;
/** Fault on channel 6. */ /** Fault on channel 6. */
public final boolean Channel6Fault; public final boolean channel6Fault;
/** Fault on channel 7. */ /** Fault on channel 7. */
public final boolean Channel7Fault; public final boolean channel7Fault;
/** Fault on channel 8. */ /** Fault on channel 8. */
public final boolean Channel8Fault; public final boolean channel8Fault;
/** Fault on channel 9. */ /** Fault on channel 9. */
public final boolean Channel9Fault; public final boolean channel9Fault;
/** Fault on channel 10. */ /** Fault on channel 10. */
public final boolean Channel10Fault; public final boolean channel10Fault;
/** Fault on channel 11. */ /** Fault on channel 11. */
public final boolean Channel11Fault; public final boolean channel11Fault;
/** Fault on channel 12. */ /** Fault on channel 12. */
public final boolean Channel12Fault; public final boolean channel12Fault;
/** Fault on channel 13. */ /** Fault on channel 13. */
public final boolean Channel13Fault; public final boolean channel13Fault;
/** Fault on channel 14. */ /** Fault on channel 14. */
public final boolean Channel14Fault; public final boolean channel14Fault;
/** Fault on channel 15. */ /** Fault on channel 15. */
public final boolean Channel15Fault; public final boolean channel15Fault;
/** An overcurrent event occurred on the compressor output. */ /** An overcurrent event occurred on the compressor output. */
public final boolean CompressorOverCurrent; public final boolean compressorOverCurrent;
/** The compressor output has an open circuit. */ /** The compressor output has an open circuit. */
public final boolean CompressorOpen; public final boolean compressorOpen;
/** An overcurrent event occurred on a solenoid output. */ /** An overcurrent event occurred on a solenoid output. */
public final boolean SolenoidOverCurrent; public final boolean solenoidOverCurrent;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. * 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 * @throws IndexOutOfBoundsException if the provided channel is outside of the range supported by
* the hardware. * the hardware.
*/ */
public final boolean getChannelFault(int channel) { public final boolean getchannelFault(int channel) {
return switch (channel) { return switch (channel) {
case 0 -> Channel0Fault; case 0 -> channel0Fault;
case 1 -> Channel1Fault; case 1 -> channel1Fault;
case 2 -> Channel2Fault; case 2 -> channel2Fault;
case 3 -> Channel3Fault; case 3 -> channel3Fault;
case 4 -> Channel4Fault; case 4 -> channel4Fault;
case 5 -> Channel5Fault; case 5 -> channel5Fault;
case 6 -> Channel6Fault; case 6 -> channel6Fault;
case 7 -> Channel7Fault; case 7 -> channel7Fault;
case 8 -> Channel8Fault; case 8 -> channel8Fault;
case 9 -> Channel9Fault; case 9 -> channel9Fault;
case 10 -> Channel10Fault; case 10 -> channel10Fault;
case 11 -> Channel11Fault; case 11 -> channel11Fault;
case 12 -> Channel12Fault; case 12 -> channel12Fault;
case 13 -> Channel13Fault; case 13 -> channel13Fault;
case 14 -> Channel14Fault; case 14 -> channel14Fault;
case 15 -> Channel15Fault; case 15 -> channel15Fault;
default -> throw new IndexOutOfBoundsException("Pneumatics fault channel out of bounds!"); default -> throw new IndexOutOfBoundsException("Pneumatics fault channel out of bounds!");
}; };
} }
@@ -109,27 +108,27 @@ public class REVPHFaults {
* @param faults the fault bitfields * @param faults the fault bitfields
*/ */
public REVPHFaults(int faults) { public REVPHFaults(int faults) {
Channel0Fault = (faults & (1 << 0)) != 0; channel0Fault = (faults & (1 << 0)) != 0;
Channel1Fault = (faults & (1 << 1)) != 0; channel1Fault = (faults & (1 << 1)) != 0;
Channel2Fault = (faults & (1 << 2)) != 0; channel2Fault = (faults & (1 << 2)) != 0;
Channel3Fault = (faults & (1 << 3)) != 0; channel3Fault = (faults & (1 << 3)) != 0;
Channel4Fault = (faults & (1 << 4)) != 0; channel4Fault = (faults & (1 << 4)) != 0;
Channel5Fault = (faults & (1 << 5)) != 0; channel5Fault = (faults & (1 << 5)) != 0;
Channel6Fault = (faults & (1 << 6)) != 0; channel6Fault = (faults & (1 << 6)) != 0;
Channel7Fault = (faults & (1 << 7)) != 0; channel7Fault = (faults & (1 << 7)) != 0;
Channel8Fault = (faults & (1 << 8)) != 0; channel8Fault = (faults & (1 << 8)) != 0;
Channel9Fault = (faults & (1 << 9)) != 0; channel9Fault = (faults & (1 << 9)) != 0;
Channel10Fault = (faults & (1 << 10)) != 0; channel10Fault = (faults & (1 << 10)) != 0;
Channel11Fault = (faults & (1 << 11)) != 0; channel11Fault = (faults & (1 << 11)) != 0;
Channel12Fault = (faults & (1 << 12)) != 0; channel12Fault = (faults & (1 << 12)) != 0;
Channel13Fault = (faults & (1 << 13)) != 0; channel13Fault = (faults & (1 << 13)) != 0;
Channel14Fault = (faults & (1 << 14)) != 0; channel14Fault = (faults & (1 << 14)) != 0;
Channel15Fault = (faults & (1 << 15)) != 0; channel15Fault = (faults & (1 << 15)) != 0;
CompressorOverCurrent = (faults & (1 << 16)) != 0; compressorOverCurrent = (faults & (1 << 16)) != 0;
CompressorOpen = (faults & (1 << 17)) != 0; compressorOpen = (faults & (1 << 17)) != 0;
SolenoidOverCurrent = (faults & (1 << 18)) != 0; solenoidOverCurrent = (faults & (1 << 18)) != 0;
Brownout = (faults & (1 << 19)) != 0; brownout = (faults & (1 << 19)) != 0;
CanWarning = (faults & (1 << 20)) != 0; canWarning = (faults & (1 << 20)) != 0;
HardwareFault = (faults & (1 << 21)) != 0; hardwareFault = (faults & (1 << 21)) != 0;
} }
} }

View File

@@ -5,34 +5,33 @@
package org.wpilib.hardware.hal; package org.wpilib.hardware.hal;
/** Sticky faults for a REV PH. These faults will remain active until they are reset by the user. */ /** Sticky faults for a REV PH. These faults will remain active until they are reset by the user. */
@SuppressWarnings("MemberName")
public class REVPHStickyFaults { public class REVPHStickyFaults {
/** An overcurrent event occurred on the compressor output. */ /** An overcurrent event occurred on the compressor output. */
public final boolean CompressorOverCurrent; public final boolean compressorOverCurrent;
/** The compressor output has an open circuit. */ /** The compressor output has an open circuit. */
public final boolean CompressorOpen; public final boolean compressorOpen;
/** An overcurrent event occurred on a solenoid output. */ /** An overcurrent event occurred on a solenoid output. */
public final boolean SolenoidOverCurrent; public final boolean solenoidOverCurrent;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. */ /** The hardware on the device has malfunctioned. */
public final boolean HardwareFault; public final boolean hardwareFault;
/** The firmware on the device has malfunctioned. */ /** The firmware on the device has malfunctioned. */
public final boolean FirmwareFault; public final boolean firmwareFault;
/** The device has rebooted. */ /** The device has rebooted. */
public final boolean HasReset; public final boolean hasReset;
/** /**
* Called from HAL. * Called from HAL.
@@ -40,14 +39,14 @@ public class REVPHStickyFaults {
* @param faults sticky fault bit mask * @param faults sticky fault bit mask
*/ */
public REVPHStickyFaults(int faults) { public REVPHStickyFaults(int faults) {
CompressorOverCurrent = (faults & 0x1) != 0; compressorOverCurrent = (faults & 0x1) != 0;
CompressorOpen = (faults & 0x2) != 0; compressorOpen = (faults & 0x2) != 0;
SolenoidOverCurrent = (faults & 0x4) != 0; solenoidOverCurrent = (faults & 0x4) != 0;
Brownout = (faults & 0x8) != 0; brownout = (faults & 0x8) != 0;
CanWarning = (faults & 0x10) != 0; canWarning = (faults & 0x10) != 0;
CanBusOff = (faults & 0x20) != 0; canBusOff = (faults & 0x20) != 0;
HardwareFault = (faults & 0x40) != 0; hardwareFault = (faults & 0x40) != 0;
FirmwareFault = (faults & 0x80) != 0; firmwareFault = (faults & 0x80) != 0;
HasReset = (faults & 0x100) != 0; hasReset = (faults & 0x100) != 0;
} }
} }

View File

@@ -5,7 +5,6 @@
package org.wpilib.hardware.hal; package org.wpilib.hardware.hal;
/** Version and device data received from a REV PH. */ /** Version and device data received from a REV PH. */
@SuppressWarnings("MemberName")
public class REVPHVersion { public class REVPHVersion {
/** The firmware major version. */ /** The firmware major version. */
public final int firmwareMajor; public final int firmwareMajor;

View File

@@ -26,10 +26,10 @@ public class SimDevice implements AutoCloseable {
BIDIR(SimDeviceJNI.VALUE_BIDIR); BIDIR(SimDeviceJNI.VALUE_BIDIR);
/** The native value of this Direction. */ /** The native value of this Direction. */
public final int m_value; public final int value;
Direction(int value) { Direction(int value) {
m_value = value; this.value = value;
} }
} }
@@ -140,7 +140,7 @@ public class SimDevice implements AutoCloseable {
* @return simulated value object * @return simulated value object
*/ */
public SimValue createValue(String name, Direction direction, HALValue initialValue) { 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) { if (handle <= 0) {
return null; return null;
} }
@@ -158,7 +158,7 @@ public class SimDevice implements AutoCloseable {
* @return simulated double value object * @return simulated double value object
*/ */
public SimInt createInt(String name, Direction direction, int initialValue) { 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) { if (handle <= 0) {
return null; return null;
} }
@@ -176,7 +176,7 @@ public class SimDevice implements AutoCloseable {
* @return simulated double value object * @return simulated double value object
*/ */
public SimLong createLong(String name, Direction direction, long initialValue) { 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) { if (handle <= 0) {
return null; return null;
} }
@@ -194,7 +194,7 @@ public class SimDevice implements AutoCloseable {
* @return simulated double value object * @return simulated double value object
*/ */
public SimDouble createDouble(String name, Direction direction, double initialValue) { 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) { if (handle <= 0) {
return null; return null;
} }
@@ -216,7 +216,7 @@ public class SimDevice implements AutoCloseable {
*/ */
public SimEnum createEnum(String name, Direction direction, String[] options, int initialValue) { public SimEnum createEnum(String name, Direction direction, String[] options, int initialValue) {
int handle = int handle =
SimDeviceJNI.createSimValueEnum(m_handle, name, direction.m_value, options, initialValue); SimDeviceJNI.createSimValueEnum(m_handle, name, direction.value, options, initialValue);
if (handle <= 0) { if (handle <= 0) {
return null; return null;
} }
@@ -241,7 +241,7 @@ public class SimDevice implements AutoCloseable {
String name, Direction direction, String[] options, double[] optionValues, int initialValue) { String name, Direction direction, String[] options, double[] optionValues, int initialValue) {
int handle = int handle =
SimDeviceJNI.createSimValueEnumDouble( SimDeviceJNI.createSimValueEnumDouble(
m_handle, name, direction.m_value, options, optionValues, initialValue); m_handle, name, direction.value, options, optionValues, initialValue);
if (handle <= 0) { if (handle <= 0) {
return null; return null;
} }
@@ -259,8 +259,7 @@ public class SimDevice implements AutoCloseable {
* @return simulated boolean value object * @return simulated boolean value object
*/ */
public SimBoolean createBoolean(String name, Direction direction, boolean initialValue) { public SimBoolean createBoolean(String name, Direction direction, boolean initialValue) {
int handle = int handle = SimDeviceJNI.createSimValueBoolean(m_handle, name, direction.value, initialValue);
SimDeviceJNI.createSimValueBoolean(m_handle, name, direction.m_value, initialValue);
if (handle <= 0) { if (handle <= 0) {
return null; return null;
} }

View File

@@ -7,19 +7,15 @@ package org.wpilib.hardware.hal.can;
/** Represents a CAN message read from a stream. */ /** Represents a CAN message read from a stream. */
public class CANReceiveMessage { public class CANReceiveMessage {
/** The message data. */ /** The message data. */
@SuppressWarnings("MemberName")
public final byte[] data = new byte[64]; public final byte[] data = new byte[64];
/** The length of the data received (0-8 bytes). */ /** The length of the data received (0-8 bytes). */
@SuppressWarnings("MemberName")
public int length; public int length;
/** The flags of the message. */ /** The flags of the message. */
@SuppressWarnings("MemberName")
public int flags; public int flags;
/** Timestamp message was received, in microseconds (wpi time). */ /** Timestamp message was received, in microseconds (wpi time). */
@SuppressWarnings("MemberName")
public long timestamp; public long timestamp;
/** Default constructor. */ /** Default constructor. */

View File

@@ -5,7 +5,6 @@
package org.wpilib.hardware.hal.can; package org.wpilib.hardware.hal.can;
/** Structure for holding the result of a CAN Status request. */ /** Structure for holding the result of a CAN Status request. */
@SuppressWarnings("MemberName")
public class CANStatus { public class CANStatus {
/** The utilization of the CAN Bus. */ /** The utilization of the CAN Bus. */
public double percentBusUtilization; public double percentBusUtilization;

View File

@@ -7,23 +7,18 @@ package org.wpilib.hardware.hal.can;
/** Represents a CAN message read from a stream. */ /** Represents a CAN message read from a stream. */
public class CANStreamMessage { public class CANStreamMessage {
/** The message data. */ /** The message data. */
@SuppressWarnings("MemberName")
public final byte[] data = new byte[64]; public final byte[] data = new byte[64];
/** The length of the data received (0-64 bytes). */ /** The length of the data received (0-64 bytes). */
@SuppressWarnings("MemberName")
public int length; public int length;
/** The flags of the message. */ /** The flags of the message. */
@SuppressWarnings("MemberName")
public int flags; public int flags;
/** Timestamp message was received, in milliseconds (based off of CLOCK_MONOTONIC). */ /** Timestamp message was received, in milliseconds (based off of CLOCK_MONOTONIC). */
@SuppressWarnings("MemberName")
public long timestamp; public long timestamp;
/** The message ID. */ /** The message ID. */
@SuppressWarnings("MemberName")
public int messageId; public int messageId;
/** Default constructor. */ /** Default constructor. */

View File

@@ -18,19 +18,14 @@ public class AlertDataJNI extends JNIWrapper {
this.level = level; this.level = level;
} }
@SuppressWarnings("MemberName")
public final int handle; public final int handle;
@SuppressWarnings("MemberName")
public final String group; public final String group;
@SuppressWarnings("MemberName")
public final String text; public final String text;
@SuppressWarnings("MemberName")
public final long activeStartTime; // 0 if not active public final long activeStartTime; // 0 if not active
@SuppressWarnings("MemberName")
public final int level; // ALERT_LEVEL_HIGH, ALERT_LEVEL_MEDIUM, ALERT_LEVEL_LOW public final int level; // ALERT_LEVEL_HIGH, ALERT_LEVEL_MEDIUM, ALERT_LEVEL_LOW
} }

View File

@@ -29,7 +29,6 @@ public class SimDeviceDataJNI extends JNIWrapper {
public static native int getSimValueDeviceHandle(int handle); public static native int getSimValueDeviceHandle(int handle);
@SuppressWarnings("MemberName")
public static class SimDeviceInfo { public static class SimDeviceInfo {
public String name; public String name;
public int handle; public int handle;
@@ -74,7 +73,6 @@ public class SimDeviceDataJNI extends JNIWrapper {
public static native int getSimValueHandle(int device, String name); public static native int getSimValueHandle(int device, String name);
@SuppressWarnings("MemberName")
public static class SimValueInfo { public static class SimValueInfo {
public String name; public String name;
public int handle; public int handle;

View File

@@ -24,19 +24,16 @@ public final class Timestamped{{ TypeName }} {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final {{ java.ValueType }} value; public final {{ java.ValueType }} value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedBoolean {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final boolean value; public final boolean value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedBooleanArray {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final boolean[] value; public final boolean[] value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedDouble {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final double value; public final double value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedDoubleArray {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final double[] value; public final double[] value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedFloat {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final float value; public final float value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedFloatArray {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final float[] value; public final float[] value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedInteger {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final long value; public final long value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedIntegerArray {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final long[] value; public final long[] value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedRaw {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final byte[] value; public final byte[] value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedString {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final String value; public final String value;
} }

View File

@@ -24,18 +24,15 @@ public final class TimestampedStringArray {
/** /**
* Timestamp in local time base. * Timestamp in local time base.
*/ */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** /**
* Timestamp in server time base. May be 0 or 1 for locally set values. * Timestamp in server time base. May be 0 or 1 for locally set values.
*/ */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** /**
* Value. * Value.
*/ */
@SuppressWarnings("MemberName")
public final String[] value; public final String[] value;
} }

View File

@@ -5,31 +5,30 @@
package org.wpilib.networktables; package org.wpilib.networktables;
/** NetworkTables Connection information. */ /** NetworkTables Connection information. */
@SuppressWarnings("MemberName")
public final class ConnectionInfo { public final class ConnectionInfo {
/** /**
* The remote identifier (as set on the remote node by {@link * The remote identifier (as set on the remote node by {@link
* NetworkTableInstance#startClient(String)}). * NetworkTableInstance#startClient(String)}).
*/ */
public final String remote_id; public final String remoteId;
/** The IP address of the remote node. */ /** The IP address of the remote node. */
public final String remote_ip; public final String remoteIp;
/** The port number of the remote node. */ /** 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 * The last time any update was received from the remote node (same scale as returned by {@link
* NetworkTablesJNI#now()}). * 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 * The protocol version being used for this connection. This is in protocol layer format, so
* 0x0200 = 2.0, 0x0300 = 3.0). * 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. * Constructor. This should generally only be used internally to NetworkTables.
@@ -42,10 +41,10 @@ public final class ConnectionInfo {
*/ */
public ConnectionInfo( public ConnectionInfo(
String remoteId, String remoteIp, int remotePort, long lastUpdate, int protocolVersion) { String remoteId, String remoteIp, int remotePort, long lastUpdate, int protocolVersion) {
remote_id = remoteId; this.remoteId = remoteId;
remote_ip = remoteIp; this.remoteIp = remoteIp;
remote_port = remotePort; this.remotePort = remotePort;
last_update = lastUpdate; this.lastUpdate = lastUpdate;
protocol_version = protocolVersion; this.protocolVersion = protocolVersion;
} }
} }

View File

@@ -5,7 +5,6 @@
package org.wpilib.networktables; package org.wpilib.networktables;
/** NetworkTables log message. */ /** NetworkTables log message. */
@SuppressWarnings("MemberName")
public final class LogMessage { public final class LogMessage {
/** Critical logging level. */ /** Critical logging level. */
public static final int CRITICAL = 50; public static final int CRITICAL = 50;

View File

@@ -10,7 +10,6 @@ package org.wpilib.networktables;
* <p>There are different kinds of events. When creating a listener, a combination of event kinds * <p>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. * can be listened to by building an EnumSet of NetworkTableEvent.Kind.
*/ */
@SuppressWarnings("MemberName")
public final class NetworkTableEvent { public final class NetworkTableEvent {
/** NetworkTable event kind. */ /** NetworkTable event kind. */
public enum Kind { public enum Kind {

View File

@@ -5,7 +5,6 @@
package org.wpilib.networktables; package org.wpilib.networktables;
/** NetworkTables publish/subscribe options. */ /** NetworkTables publish/subscribe options. */
@SuppressWarnings("MemberName")
public class PubSubOptions { public class PubSubOptions {
/** /**
* Construct from a list of options. * Construct from a list of options.

View File

@@ -5,7 +5,6 @@
package org.wpilib.networktables; package org.wpilib.networktables;
/** NetworkTables time sync event data. */ /** NetworkTables time sync event data. */
@SuppressWarnings("MemberName")
public final class TimeSyncEventData { public final class TimeSyncEventData {
/** /**
* Offset between local time and server time, in microseconds. Add this value to local time to get * Offset between local time and server time, in microseconds. Add this value to local time to get

View File

@@ -24,14 +24,11 @@ public final class TimestampedObject<T> {
} }
/** Timestamp in local time base. */ /** Timestamp in local time base. */
@SuppressWarnings("MemberName")
public final long timestamp; public final long timestamp;
/** Timestamp in server time base. May be 0 or 1 for locally set values. */ /** Timestamp in server time base. May be 0 or 1 for locally set values. */
@SuppressWarnings("MemberName")
public final long serverTime; public final long serverTime;
/** Value. */ /** Value. */
@SuppressWarnings("MemberName")
public final T value; public final T value;
} }

View File

@@ -5,7 +5,6 @@
package org.wpilib.networktables; package org.wpilib.networktables;
/** NetworkTables topic information. */ /** NetworkTables topic information. */
@SuppressWarnings("MemberName")
public final class TopicInfo { public final class TopicInfo {
/** Topic handle. */ /** Topic handle. */
public final int topic; public final int topic;

View File

@@ -5,7 +5,6 @@
package org.wpilib.networktables; package org.wpilib.networktables;
/** NetworkTables value event data. */ /** NetworkTables value event data. */
@SuppressWarnings("MemberName")
public final class ValueEventData { public final class ValueEventData {
/** Topic handle. Topic.getHandle() can be used to map this to the corresponding Topic object. */ /** Topic handle. Topic.getHandle() can be used to map this to the corresponding Topic object. */
public final int topic; public final int topic;

View File

@@ -17,7 +17,7 @@ class MyRobot(wpilib.TimedRobot):
super().__init__() super().__init__()
self.inst = ntcore.NetworkTableInstance.getDefault() self.inst = ntcore.NetworkTableInstance.getDefault()
self.doubleArrayTopic = self.inst.getDoubleArrayTopic("m_doubleArrayTopic") self.doubleArrayTopic = self.inst.getDoubleArrayTopic("doubleArrayTopic")
self.controller = wpilib.NiDsXboxController(0) self.controller = wpilib.NiDsXboxController(0)
self.drive = Drivetrain(self.doubleArrayTopic) self.drive = Drivetrain(self.doubleArrayTopic)

View File

@@ -112,21 +112,17 @@ class SwerveModule:
encoderRotation 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( driveOutput = self.drivePIDController.calculate(
self.driveEncoder.getRate(), velocity.velocity 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 and feedforward.
# Calculate the turning motor output from the turning PID controller.
turnOutput = self.turningPIDController.calculate( turnOutput = self.turningPIDController.calculate(
self.turningEncoder.getDistance(), velocity.angle.radians() self.turningEncoder.getDistance(), velocity.angle.radians()
) ) + self.turnFeedforward.calculate(
turnFeedforward = self.turnFeedforward.calculate(
self.turningPIDController.getSetpoint().velocity self.turningPIDController.getSetpoint().velocity
) )
self.driveMotor.setVoltage(driveOutput + driveFeedforward) self.driveMotor.setVoltage(driveOutput)
self.turningMotor.setVoltage(turnOutput + turnFeedforward) self.turningMotor.setVoltage(turnOutput)

View File

@@ -7,12 +7,12 @@ suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
<suppress files=".*wpilibjIntegrationTests.*" <suppress files=".*wpilibjIntegrationTests.*"
checks="MissingJavadocMethod" /> checks="MissingJavadocMethod" />
<suppress files="wpimath.*" <suppress files="wpimath.*"
checks="(LocalVariableName|MemberName|MethodName|MethodTypeParameterName|ParameterName)" /> checks="(LocalVariableName|MethodName|MethodTypeParameterName|ParameterName)" />
<suppress files=".*JNI.*" <suppress files=".*JNI.*"
checks="(EmptyLineSeparator|LineLength|MissingJavadocMethod|ParameterName)" /> checks="(EmptyLineSeparator|LineLength|MissingJavadocMethod|ParameterName)" />
<!-- Disable checks for generated protobuf files --> <!-- Disable checks for generated protobuf files -->
<suppress files=".*generated[/\\].*[/\\]proto[/\\].*" <suppress files=".*generated[/\\].*[/\\]proto[/\\].*"
checks="(CustomImportOrder|EmptyLineSeparator|LeftCurly|LineLength|JavadocParagraph|MemberName|MissingJavadocMethod|OverloadMethodsDeclarationOrder|SummaryJavadoc|UnnecessaryParentheses|OperatorWrap|JavadocMethod|JavadocTagContinuationIndentation)" /> checks="(CustomImportOrder|EmptyLineSeparator|LeftCurly|LineLength|JavadocParagraph|MissingJavadocMethod|OverloadMethodsDeclarationOrder|SummaryJavadoc|UnnecessaryParentheses|OperatorWrap|JavadocMethod|JavadocTagContinuationIndentation)" />
<suppress files="wpilibj[/\\]src[/\\]generated.*" <suppress files="wpilibj[/\\]src[/\\]generated.*"
checks="MethodName" /> checks="MethodName" />
<!-- Disable checkstyle for generated unit files --> <!-- Disable checkstyle for generated unit files -->

View File

@@ -168,12 +168,6 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
<message key="name.invalidPattern" <message key="name.invalidPattern"
value="Type name ''{0}'' must match pattern ''{1}''." /> value="Type name ''{0}'' must match pattern ''{1}''." />
</module> </module>
<module name="MemberName">
<property name="format"
value="^(m_([a-zA-Z]|[a-z][a-zA-Z0-9]+)|value)$" />
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''." />
</module>
<module name="ParameterName"> <module name="ParameterName">
<property name="format" <property name="format"
value="^([a-zA-Z]|[a-z][a-zA-Z0-9]+)$" /> value="^([a-zA-Z]|[a-z][a-zA-Z0-9]+)$" />

View File

@@ -12,7 +12,7 @@
<exclude-pattern>.*/Timestamped.*\.java</exclude-pattern> <exclude-pattern>.*/Timestamped.*\.java</exclude-pattern>
<exclude-pattern>.*/units/measure/.*\.java</exclude-pattern> <exclude-pattern>.*/units/measure/.*\.java</exclude-pattern>
<exclude-pattern>.*/*IntegrationTests.*</exclude-pattern> <exclude-pattern>.*/*Examples.*</exclude-pattern>
<exclude-pattern>.*/*JNI.*</exclude-pattern> <exclude-pattern>.*/*JNI.*</exclude-pattern>
<exclude-pattern>.*/math/proto.*</exclude-pattern> <exclude-pattern>.*/math/proto.*</exclude-pattern>
<exclude-pattern>.*/command3/proto.*</exclude-pattern> <exclude-pattern>.*/command3/proto.*</exclude-pattern>
@@ -143,4 +143,22 @@
]]> ]]>
</example> </example>
</rule> </rule>
<rule name="PublicFieldNamingConvention"
language="java"
message="Public fields must follow lowerCamelCase."
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//ClassDeclaration[not(matches(@PackageName, "org.wpilib.math"))]/ClassBody/FieldDeclaration[@Visibility = 'public' and @Static = false()]/VariableDeclarator[not(matches(@Name, "^[a-z][a-zA-Z0-9]*$"))]
]]>
</value>
</property>
</properties>
</rule>
</ruleset> </ruleset>

View File

@@ -150,6 +150,10 @@
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD" /> <Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD" />
<Class name="org.wpilib.epilogue.EpilogueConfiguration" /> <Class name="org.wpilib.epilogue.EpilogueConfiguration" />
</Match> </Match>
<Match>
<Bug pattern="URF_UNREAD_FIELD" />
<Class name="org.wpilib.driverstation.internal.DriverStationBackend$HALJoystickAxesRaw" />
</Match>
<Match> <Match>
<!-- PMD will skip variables named `ignore`, but spotbugs isn't as smart --> <!-- PMD will skip variables named `ignore`, but spotbugs isn't as smart -->
<Bug pattern="DLS_DEAD_LOCAL_STORE" /> <Bug pattern="DLS_DEAD_LOCAL_STORE" />

View File

@@ -329,37 +329,37 @@ PneumaticHub::StickyFaults PneumaticHub::GetStickyFaults() const {
bool PneumaticHub::Faults::GetChannelFault(int channel) const { bool PneumaticHub::Faults::GetChannelFault(int channel) const {
switch (channel) { switch (channel) {
case 0: case 0:
return Channel0Fault != 0; return channel0Fault != 0;
case 1: case 1:
return Channel1Fault != 0; return channel1Fault != 0;
case 2: case 2:
return Channel2Fault != 0; return channel2Fault != 0;
case 3: case 3:
return Channel3Fault != 0; return channel3Fault != 0;
case 4: case 4:
return Channel4Fault != 0; return channel4Fault != 0;
case 5: case 5:
return Channel5Fault != 0; return channel5Fault != 0;
case 6: case 6:
return Channel6Fault != 0; return channel6Fault != 0;
case 7: case 7:
return Channel7Fault != 0; return channel7Fault != 0;
case 8: case 8:
return Channel8Fault != 0; return channel8Fault != 0;
case 9: case 9:
return Channel9Fault != 0; return channel9Fault != 0;
case 10: case 10:
return Channel10Fault != 0; return channel10Fault != 0;
case 11: case 11:
return Channel11Fault != 0; return channel11Fault != 0;
case 12: case 12:
return Channel12Fault != 0; return channel12Fault != 0;
case 13: case 13:
return Channel13Fault != 0; return channel13Fault != 0;
case 14: case 14:
return Channel14Fault != 0; return channel14Fault != 0;
case 15: case 15:
return Channel15Fault != 0; return channel15Fault != 0;
default: default:
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
"Pneumatics fault channel out of bounds!"); "Pneumatics fault channel out of bounds!");

View File

@@ -196,53 +196,53 @@ PowerDistribution::Faults PowerDistribution::GetFaults() const {
bool PowerDistribution::Faults::GetBreakerFault(int channel) const { bool PowerDistribution::Faults::GetBreakerFault(int channel) const {
switch (channel) { switch (channel) {
case 0: case 0:
return Channel0BreakerFault != 0; return channel0BreakerFault != 0;
case 1: case 1:
return Channel1BreakerFault != 0; return channel1BreakerFault != 0;
case 2: case 2:
return Channel2BreakerFault != 0; return channel2BreakerFault != 0;
case 3: case 3:
return Channel3BreakerFault != 0; return channel3BreakerFault != 0;
case 4: case 4:
return Channel4BreakerFault != 0; return channel4BreakerFault != 0;
case 5: case 5:
return Channel5BreakerFault != 0; return channel5BreakerFault != 0;
case 6: case 6:
return Channel6BreakerFault != 0; return channel6BreakerFault != 0;
case 7: case 7:
return Channel7BreakerFault != 0; return channel7BreakerFault != 0;
case 8: case 8:
return Channel8BreakerFault != 0; return channel8BreakerFault != 0;
case 9: case 9:
return Channel9BreakerFault != 0; return channel9BreakerFault != 0;
case 10: case 10:
return Channel10BreakerFault != 0; return channel10BreakerFault != 0;
case 11: case 11:
return Channel11BreakerFault != 0; return channel11BreakerFault != 0;
case 12: case 12:
return Channel12BreakerFault != 0; return channel12BreakerFault != 0;
case 13: case 13:
return Channel13BreakerFault != 0; return channel13BreakerFault != 0;
case 14: case 14:
return Channel14BreakerFault != 0; return channel14BreakerFault != 0;
case 15: case 15:
return Channel15BreakerFault != 0; return channel15BreakerFault != 0;
case 16: case 16:
return Channel16BreakerFault != 0; return channel16BreakerFault != 0;
case 17: case 17:
return Channel17BreakerFault != 0; return channel17BreakerFault != 0;
case 18: case 18:
return Channel18BreakerFault != 0; return channel18BreakerFault != 0;
case 19: case 19:
return Channel19BreakerFault != 0; return channel19BreakerFault != 0;
case 20: case 20:
return Channel20BreakerFault != 0; return channel20BreakerFault != 0;
case 21: case 21:
return Channel21BreakerFault != 0; return channel21BreakerFault != 0;
case 22: case 22:
return Channel22BreakerFault != 0; return channel22BreakerFault != 0;
case 23: case 23:
return Channel23BreakerFault != 0; return channel23BreakerFault != 0;
default: default:
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
"Power distribution fault channel out of bounds!"); "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 { bool PowerDistribution::StickyFaults::GetBreakerFault(int channel) const {
switch (channel) { switch (channel) {
case 0: case 0:
return Channel0BreakerFault != 0; return channel0BreakerFault != 0;
case 1: case 1:
return Channel1BreakerFault != 0; return channel1BreakerFault != 0;
case 2: case 2:
return Channel2BreakerFault != 0; return channel2BreakerFault != 0;
case 3: case 3:
return Channel3BreakerFault != 0; return channel3BreakerFault != 0;
case 4: case 4:
return Channel4BreakerFault != 0; return channel4BreakerFault != 0;
case 5: case 5:
return Channel5BreakerFault != 0; return channel5BreakerFault != 0;
case 6: case 6:
return Channel6BreakerFault != 0; return channel6BreakerFault != 0;
case 7: case 7:
return Channel7BreakerFault != 0; return channel7BreakerFault != 0;
case 8: case 8:
return Channel8BreakerFault != 0; return channel8BreakerFault != 0;
case 9: case 9:
return Channel9BreakerFault != 0; return channel9BreakerFault != 0;
case 10: case 10:
return Channel10BreakerFault != 0; return channel10BreakerFault != 0;
case 11: case 11:
return Channel11BreakerFault != 0; return channel11BreakerFault != 0;
case 12: case 12:
return Channel12BreakerFault != 0; return channel12BreakerFault != 0;
case 13: case 13:
return Channel13BreakerFault != 0; return channel13BreakerFault != 0;
case 14: case 14:
return Channel14BreakerFault != 0; return channel14BreakerFault != 0;
case 15: case 15:
return Channel15BreakerFault != 0; return channel15BreakerFault != 0;
case 16: case 16:
return Channel16BreakerFault != 0; return channel16BreakerFault != 0;
case 17: case 17:
return Channel17BreakerFault != 0; return channel17BreakerFault != 0;
case 18: case 18:
return Channel18BreakerFault != 0; return channel18BreakerFault != 0;
case 19: case 19:
return Channel19BreakerFault != 0; return channel19BreakerFault != 0;
case 20: case 20:
return Channel20BreakerFault != 0; return channel20BreakerFault != 0;
case 21: case 21:
return Channel21BreakerFault != 0; return channel21BreakerFault != 0;
case 22: case 22:
return Channel22BreakerFault != 0; return channel22BreakerFault != 0;
case 23: case 23:
return Channel23BreakerFault != 0; return channel23BreakerFault != 0;
default: default:
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
"Power distribution fault channel out of bounds!"); "Power distribution fault channel out of bounds!");

View File

@@ -154,49 +154,49 @@ class PneumaticHub : public PneumaticsBase {
*/ */
struct Faults { struct Faults {
/** Fault on channel 0. */ /** Fault on channel 0. */
uint32_t Channel0Fault : 1; uint32_t channel0Fault : 1;
/** Fault on channel 1. */ /** Fault on channel 1. */
uint32_t Channel1Fault : 1; uint32_t channel1Fault : 1;
/** Fault on channel 2. */ /** Fault on channel 2. */
uint32_t Channel2Fault : 1; uint32_t channel2Fault : 1;
/** Fault on channel 3. */ /** Fault on channel 3. */
uint32_t Channel3Fault : 1; uint32_t channel3Fault : 1;
/** Fault on channel 4. */ /** Fault on channel 4. */
uint32_t Channel4Fault : 1; uint32_t channel4Fault : 1;
/** Fault on channel 5. */ /** Fault on channel 5. */
uint32_t Channel5Fault : 1; uint32_t channel5Fault : 1;
/** Fault on channel 6. */ /** Fault on channel 6. */
uint32_t Channel6Fault : 1; uint32_t channel6Fault : 1;
/** Fault on channel 7. */ /** Fault on channel 7. */
uint32_t Channel7Fault : 1; uint32_t channel7Fault : 1;
/** Fault on channel 8. */ /** Fault on channel 8. */
uint32_t Channel8Fault : 1; uint32_t channel8Fault : 1;
/** Fault on channel 9. */ /** Fault on channel 9. */
uint32_t Channel9Fault : 1; uint32_t channel9Fault : 1;
/** Fault on channel 10. */ /** Fault on channel 10. */
uint32_t Channel10Fault : 1; uint32_t channel10Fault : 1;
/** Fault on channel 11. */ /** Fault on channel 11. */
uint32_t Channel11Fault : 1; uint32_t channel11Fault : 1;
/** Fault on channel 12. */ /** Fault on channel 12. */
uint32_t Channel12Fault : 1; uint32_t channel12Fault : 1;
/** Fault on channel 13. */ /** Fault on channel 13. */
uint32_t Channel13Fault : 1; uint32_t channel13Fault : 1;
/** Fault on channel 14. */ /** Fault on channel 14. */
uint32_t Channel14Fault : 1; uint32_t channel14Fault : 1;
/** Fault on channel 15. */ /** Fault on channel 15. */
uint32_t Channel15Fault : 1; uint32_t channel15Fault : 1;
/** An overcurrent event occurred on the compressor output. */ /** An overcurrent event occurred on the compressor output. */
uint32_t CompressorOverCurrent : 1; uint32_t compressorOverCurrent : 1;
/** The compressor output has an open circuit. */ /** The compressor output has an open circuit. */
uint32_t CompressorOpen : 1; uint32_t compressorOpen : 1;
/** An overcurrent event occurred on a solenoid output. */ /** An overcurrent event occurred on a solenoid output. */
uint32_t SolenoidOverCurrent : 1; uint32_t solenoidOverCurrent : 1;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. * Gets whether there is a fault at the specified channel.
@@ -221,23 +221,23 @@ class PneumaticHub : public PneumaticsBase {
*/ */
struct StickyFaults { struct StickyFaults {
/** An overcurrent event occurred on the compressor output. */ /** An overcurrent event occurred on the compressor output. */
uint32_t CompressorOverCurrent : 1; uint32_t compressorOverCurrent : 1;
/** The compressor output has an open circuit. */ /** The compressor output has an open circuit. */
uint32_t CompressorOpen : 1; uint32_t compressorOpen : 1;
/** An overcurrent event occurred on a solenoid output. */ /** An overcurrent event occurred on a solenoid output. */
uint32_t SolenoidOverCurrent : 1; uint32_t solenoidOverCurrent : 1;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. */ /** The hardware on the device has malfunctioned. */
uint32_t HardwareFault : 1; uint32_t hardwareFault : 1;
/** The firmware on the device has malfunctioned. */ /** The firmware on the device has malfunctioned. */
uint32_t FirmwareFault : 1; uint32_t firmwareFault : 1;
/** The device has rebooted. */ /** The device has rebooted. */
uint32_t HasReset : 1; uint32_t hasReset : 1;
}; };
/** /**

View File

@@ -184,59 +184,59 @@ class PowerDistribution : public wpi::util::Sendable,
*/ */
struct Faults { struct Faults {
/** Breaker fault on channel 0. */ /** Breaker fault on channel 0. */
uint32_t Channel0BreakerFault : 1; uint32_t channel0BreakerFault : 1;
/** Breaker fault on channel 1. */ /** Breaker fault on channel 1. */
uint32_t Channel1BreakerFault : 1; uint32_t channel1BreakerFault : 1;
/** Breaker fault on channel 2. */ /** Breaker fault on channel 2. */
uint32_t Channel2BreakerFault : 1; uint32_t channel2BreakerFault : 1;
/** Breaker fault on channel 3. */ /** Breaker fault on channel 3. */
uint32_t Channel3BreakerFault : 1; uint32_t channel3BreakerFault : 1;
/** Breaker fault on channel 4. */ /** Breaker fault on channel 4. */
uint32_t Channel4BreakerFault : 1; uint32_t channel4BreakerFault : 1;
/** Breaker fault on channel 5. */ /** Breaker fault on channel 5. */
uint32_t Channel5BreakerFault : 1; uint32_t channel5BreakerFault : 1;
/** Breaker fault on channel 6. */ /** Breaker fault on channel 6. */
uint32_t Channel6BreakerFault : 1; uint32_t channel6BreakerFault : 1;
/** Breaker fault on channel 7. */ /** Breaker fault on channel 7. */
uint32_t Channel7BreakerFault : 1; uint32_t channel7BreakerFault : 1;
/** Breaker fault on channel 8. */ /** Breaker fault on channel 8. */
uint32_t Channel8BreakerFault : 1; uint32_t channel8BreakerFault : 1;
/** Breaker fault on channel 9. */ /** Breaker fault on channel 9. */
uint32_t Channel9BreakerFault : 1; uint32_t channel9BreakerFault : 1;
/** Breaker fault on channel 10. */ /** Breaker fault on channel 10. */
uint32_t Channel10BreakerFault : 1; uint32_t channel10BreakerFault : 1;
/** Breaker fault on channel 12. */ /** Breaker fault on channel 12. */
uint32_t Channel11BreakerFault : 1; uint32_t channel11BreakerFault : 1;
/** Breaker fault on channel 13. */ /** Breaker fault on channel 13. */
uint32_t Channel12BreakerFault : 1; uint32_t channel12BreakerFault : 1;
/** Breaker fault on channel 14. */ /** Breaker fault on channel 14. */
uint32_t Channel13BreakerFault : 1; uint32_t channel13BreakerFault : 1;
/** Breaker fault on channel 15. */ /** Breaker fault on channel 15. */
uint32_t Channel14BreakerFault : 1; uint32_t channel14BreakerFault : 1;
/** Breaker fault on channel 16. */ /** Breaker fault on channel 16. */
uint32_t Channel15BreakerFault : 1; uint32_t channel15BreakerFault : 1;
/** Breaker fault on channel 17. */ /** Breaker fault on channel 17. */
uint32_t Channel16BreakerFault : 1; uint32_t channel16BreakerFault : 1;
/** Breaker fault on channel 18. */ /** Breaker fault on channel 18. */
uint32_t Channel17BreakerFault : 1; uint32_t channel17BreakerFault : 1;
/** Breaker fault on channel 19. */ /** Breaker fault on channel 19. */
uint32_t Channel18BreakerFault : 1; uint32_t channel18BreakerFault : 1;
/** Breaker fault on channel 20. */ /** Breaker fault on channel 20. */
uint32_t Channel19BreakerFault : 1; uint32_t channel19BreakerFault : 1;
/** Breaker fault on channel 21. */ /** Breaker fault on channel 21. */
uint32_t Channel20BreakerFault : 1; uint32_t channel20BreakerFault : 1;
/** Breaker fault on channel 22. */ /** Breaker fault on channel 22. */
uint32_t Channel21BreakerFault : 1; uint32_t channel21BreakerFault : 1;
/** Breaker fault on channel 23. */ /** Breaker fault on channel 23. */
uint32_t Channel22BreakerFault : 1; uint32_t channel22BreakerFault : 1;
/** Breaker fault on channel 24. */ /** Breaker fault on channel 24. */
uint32_t Channel23BreakerFault : 1; uint32_t channel23BreakerFault : 1;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. * Gets whether there is a breaker fault at a specified channel.
@@ -263,65 +263,65 @@ class PowerDistribution : public wpi::util::Sendable,
*/ */
struct StickyFaults { struct StickyFaults {
/** Breaker fault on channel 0. */ /** Breaker fault on channel 0. */
uint32_t Channel0BreakerFault : 1; uint32_t channel0BreakerFault : 1;
/** Breaker fault on channel 1. */ /** Breaker fault on channel 1. */
uint32_t Channel1BreakerFault : 1; uint32_t channel1BreakerFault : 1;
/** Breaker fault on channel 2. */ /** Breaker fault on channel 2. */
uint32_t Channel2BreakerFault : 1; uint32_t channel2BreakerFault : 1;
/** Breaker fault on channel 3. */ /** Breaker fault on channel 3. */
uint32_t Channel3BreakerFault : 1; uint32_t channel3BreakerFault : 1;
/** Breaker fault on channel 4. */ /** Breaker fault on channel 4. */
uint32_t Channel4BreakerFault : 1; uint32_t channel4BreakerFault : 1;
/** Breaker fault on channel 5. */ /** Breaker fault on channel 5. */
uint32_t Channel5BreakerFault : 1; uint32_t channel5BreakerFault : 1;
/** Breaker fault on channel 6. */ /** Breaker fault on channel 6. */
uint32_t Channel6BreakerFault : 1; uint32_t channel6BreakerFault : 1;
/** Breaker fault on channel 7. */ /** Breaker fault on channel 7. */
uint32_t Channel7BreakerFault : 1; uint32_t channel7BreakerFault : 1;
/** Breaker fault on channel 8. */ /** Breaker fault on channel 8. */
uint32_t Channel8BreakerFault : 1; uint32_t channel8BreakerFault : 1;
/** Breaker fault on channel 9. */ /** Breaker fault on channel 9. */
uint32_t Channel9BreakerFault : 1; uint32_t channel9BreakerFault : 1;
/** Breaker fault on channel 10. */ /** Breaker fault on channel 10. */
uint32_t Channel10BreakerFault : 1; uint32_t channel10BreakerFault : 1;
/** Breaker fault on channel 12. */ /** Breaker fault on channel 12. */
uint32_t Channel11BreakerFault : 1; uint32_t channel11BreakerFault : 1;
/** Breaker fault on channel 13. */ /** Breaker fault on channel 13. */
uint32_t Channel12BreakerFault : 1; uint32_t channel12BreakerFault : 1;
/** Breaker fault on channel 14. */ /** Breaker fault on channel 14. */
uint32_t Channel13BreakerFault : 1; uint32_t channel13BreakerFault : 1;
/** Breaker fault on channel 15. */ /** Breaker fault on channel 15. */
uint32_t Channel14BreakerFault : 1; uint32_t channel14BreakerFault : 1;
/** Breaker fault on channel 16. */ /** Breaker fault on channel 16. */
uint32_t Channel15BreakerFault : 1; uint32_t channel15BreakerFault : 1;
/** Breaker fault on channel 17. */ /** Breaker fault on channel 17. */
uint32_t Channel16BreakerFault : 1; uint32_t channel16BreakerFault : 1;
/** Breaker fault on channel 18. */ /** Breaker fault on channel 18. */
uint32_t Channel17BreakerFault : 1; uint32_t channel17BreakerFault : 1;
/** Breaker fault on channel 19. */ /** Breaker fault on channel 19. */
uint32_t Channel18BreakerFault : 1; uint32_t channel18BreakerFault : 1;
/** Breaker fault on channel 20. */ /** Breaker fault on channel 20. */
uint32_t Channel19BreakerFault : 1; uint32_t channel19BreakerFault : 1;
/** Breaker fault on channel 21. */ /** Breaker fault on channel 21. */
uint32_t Channel20BreakerFault : 1; uint32_t channel20BreakerFault : 1;
/** Breaker fault on channel 22. */ /** Breaker fault on channel 22. */
uint32_t Channel21BreakerFault : 1; uint32_t channel21BreakerFault : 1;
/** Breaker fault on channel 23. */ /** Breaker fault on channel 23. */
uint32_t Channel22BreakerFault : 1; uint32_t channel22BreakerFault : 1;
/** Breaker fault on channel 24. */ /** Breaker fault on channel 24. */
uint32_t Channel23BreakerFault : 1; uint32_t channel23BreakerFault : 1;
/** The input voltage is below the minimum voltage. */ /** 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. */ /** 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. */ /** 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. */ /** The hardware on the device has malfunctioned. */
uint32_t HardwareFault : 1; uint32_t hardwareFault : 1;
/** The firmware on the device has malfunctioned. */ /** The firmware on the device has malfunctioned. */
uint32_t FirmwareFault : 1; uint32_t firmwareFault : 1;
/** The device has rebooted. */ /** The device has rebooted. */
uint32_t HasReset : 1; uint32_t hasReset : 1;
/** /**
* Gets whether there is a sticky breaker fault at the specified channel. * Gets whether there is a sticky breaker fault at the specified channel.

View File

@@ -54,38 +54,38 @@ classes:
UniqueId: UniqueId:
wpi::PneumaticHub::Faults: wpi::PneumaticHub::Faults:
attributes: attributes:
Channel0Fault: channel0Fault:
Channel1Fault: channel1Fault:
Channel2Fault: channel2Fault:
Channel3Fault: channel3Fault:
Channel4Fault: channel4Fault:
Channel5Fault: channel5Fault:
Channel6Fault: channel6Fault:
Channel7Fault: channel7Fault:
Channel8Fault: channel8Fault:
Channel9Fault: channel9Fault:
Channel10Fault: channel10Fault:
Channel11Fault: channel11Fault:
Channel12Fault: channel12Fault:
Channel13Fault: channel13Fault:
Channel14Fault: channel14Fault:
Channel15Fault: channel15Fault:
CompressorOverCurrent: compressorOverCurrent:
CompressorOpen: compressorOpen:
SolenoidOverCurrent: solenoidOverCurrent:
Brownout: brownout:
CanWarning: canWarning:
HardwareFault: hardwareFault:
methods: methods:
GetChannelFault: GetChannelFault:
wpi::PneumaticHub::StickyFaults: wpi::PneumaticHub::StickyFaults:
attributes: attributes:
CompressorOverCurrent: compressorOverCurrent:
CompressorOpen: compressorOpen:
SolenoidOverCurrent: solenoidOverCurrent:
Brownout: brownout:
CanWarning: canWarning:
CanBusOff: canBusOff:
HasReset: hasReset:
HardwareFault: hardwareFault:
FirmwareFault: firmwareFault:

View File

@@ -42,66 +42,66 @@ classes:
UniqueId: UniqueId:
wpi::PowerDistribution::Faults: wpi::PowerDistribution::Faults:
attributes: attributes:
Channel0BreakerFault: channel0BreakerFault:
Channel1BreakerFault: channel1BreakerFault:
Channel2BreakerFault: channel2BreakerFault:
Channel3BreakerFault: channel3BreakerFault:
Channel4BreakerFault: channel4BreakerFault:
Channel5BreakerFault: channel5BreakerFault:
Channel6BreakerFault: channel6BreakerFault:
Channel7BreakerFault: channel7BreakerFault:
Channel8BreakerFault: channel8BreakerFault:
Channel9BreakerFault: channel9BreakerFault:
Channel10BreakerFault: channel10BreakerFault:
Channel11BreakerFault: channel11BreakerFault:
Channel12BreakerFault: channel12BreakerFault:
Channel13BreakerFault: channel13BreakerFault:
Channel14BreakerFault: channel14BreakerFault:
Channel15BreakerFault: channel15BreakerFault:
Channel16BreakerFault: channel16BreakerFault:
Channel17BreakerFault: channel17BreakerFault:
Channel18BreakerFault: channel18BreakerFault:
Channel19BreakerFault: channel19BreakerFault:
Channel20BreakerFault: channel20BreakerFault:
Channel21BreakerFault: channel21BreakerFault:
Channel22BreakerFault: channel22BreakerFault:
Channel23BreakerFault: channel23BreakerFault:
Brownout: brownout:
CanWarning: canWarning:
HardwareFault: hardwareFault:
methods: methods:
GetBreakerFault: GetBreakerFault:
wpi::PowerDistribution::StickyFaults: wpi::PowerDistribution::StickyFaults:
attributes: attributes:
Channel0BreakerFault: channel0BreakerFault:
Channel1BreakerFault: channel1BreakerFault:
Channel2BreakerFault: channel2BreakerFault:
Channel3BreakerFault: channel3BreakerFault:
Channel4BreakerFault: channel4BreakerFault:
Channel5BreakerFault: channel5BreakerFault:
Channel6BreakerFault: channel6BreakerFault:
Channel7BreakerFault: channel7BreakerFault:
Channel8BreakerFault: channel8BreakerFault:
Channel9BreakerFault: channel9BreakerFault:
Channel10BreakerFault: channel10BreakerFault:
Channel11BreakerFault: channel11BreakerFault:
Channel12BreakerFault: channel12BreakerFault:
Channel13BreakerFault: channel13BreakerFault:
Channel14BreakerFault: channel14BreakerFault:
Channel15BreakerFault: channel15BreakerFault:
Channel16BreakerFault: channel16BreakerFault:
Channel17BreakerFault: channel17BreakerFault:
Channel18BreakerFault: channel18BreakerFault:
Channel19BreakerFault: channel19BreakerFault:
Channel20BreakerFault: channel20BreakerFault:
Channel21BreakerFault: channel21BreakerFault:
Channel22BreakerFault: channel22BreakerFault:
Channel23BreakerFault: channel23BreakerFault:
Brownout: brownout:
CanWarning: canWarning:
CanBusOff: canBusOff:
HasReset: hasReset:
HardwareFault: hardwareFault:
FirmwareFault: firmwareFault:
methods: methods:
GetBreakerFault: GetBreakerFault:

View File

@@ -12,30 +12,30 @@
* Runs the motors with split arcade steering and a Gamepad. * Runs the motors with split arcade steering and a Gamepad.
*/ */
class Robot : public wpi::TimedRobot { class Robot : public wpi::TimedRobot {
wpi::PWMSparkMax m_leftMotor{0}; wpi::PWMSparkMax leftMotor{0};
wpi::PWMSparkMax m_rightMotor{1}; wpi::PWMSparkMax rightMotor{1};
wpi::DifferentialDrive m_robotDrive{ wpi::DifferentialDrive robotDrive{
[&](double output) { m_leftMotor.SetThrottle(output); }, [&](double output) { leftMotor.SetThrottle(output); },
[&](double output) { m_rightMotor.SetThrottle(output); }}; [&](double output) { rightMotor.SetThrottle(output); }};
wpi::Gamepad m_driverController{0}; wpi::Gamepad driverController{0};
public: public:
Robot() { Robot() {
wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_leftMotor); wpi::util::SendableRegistry::AddChild(&robotDrive, &leftMotor);
wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_rightMotor); wpi::util::SendableRegistry::AddChild(&robotDrive, &rightMotor);
// We need to invert one side of the drivetrain so that positive voltages // 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 // result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead. // gearbox is constructed, you might have to invert the left side instead.
m_rightMotor.SetInverted(true); rightMotor.SetInverted(true);
} }
void TeleopPeriodic() override { void TeleopPeriodic() override {
// Drive with split arcade style // Drive with split arcade style
// That means that the Y axis of the left stick moves forward // 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. // and backward, and the X of the right stick turns left and right.
m_robotDrive.ArcadeDrive(-m_driverController.GetLeftY(), robotDrive.ArcadeDrive(-driverController.GetLeftY(),
-m_driverController.GetRightX()); -driverController.GetRightX());
} }
}; };

View File

@@ -5,26 +5,26 @@
#include "Robot.hpp" #include "Robot.hpp"
void Robot::SimulationPeriodic() { void Robot::SimulationPeriodic() {
m_arm.SimulationPeriodic(); arm.SimulationPeriodic();
} }
void Robot::TeleopInit() { void Robot::TeleopInit() {
m_arm.LoadPreferences(); arm.LoadPreferences();
} }
void Robot::TeleopPeriodic() { void Robot::TeleopPeriodic() {
if (m_joystick.GetTrigger()) { if (joystick.GetTrigger()) {
// Here, we run PID control like normal. // Here, we run PID control like normal.
m_arm.ReachSetpoint(); arm.ReachSetpoint();
} else { } else {
// Otherwise, we disable the motor. // Otherwise, we disable the motor.
m_arm.Stop(); arm.Stop();
} }
} }
void Robot::DisabledInit() { void Robot::DisabledInit() {
// This just makes sure that our simulation code knows that the motor's off. // This just makes sure that our simulation code knows that the motor's off.
m_arm.Stop(); arm.Stop();
} }
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -9,55 +9,55 @@
#include "wpi/util/Preferences.hpp" #include "wpi/util/Preferences.hpp"
Arm::Arm() { Arm::Arm() {
m_encoder.SetDistancePerPulse(kArmEncoderDistPerPulse); encoder.SetDistancePerPulse(kArmEncoderDistPerPulse);
// Put Mechanism 2d to SmartDashboard // 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 // Set the Arm position setpoint and P constant to Preferences if the keys
// don't already exist // don't already exist
wpi::Preferences::InitDouble(kArmPositionKey, m_armSetpoint.value()); wpi::Preferences::InitDouble(kArmPositionKey, armSetpoint.value());
wpi::Preferences::InitDouble(kArmPKey, m_armKp); wpi::Preferences::InitDouble(kArmPKey, armKp);
} }
void Arm::SimulationPeriodic() { void Arm::SimulationPeriodic() {
// In this method, we update our simulation of what our arm is doing // In this method, we update our simulation of what our arm is doing
// First, we set our "inputs" (voltages) // First, we set our "inputs" (voltages)
m_armSim.SetInput(wpi::math::Vectord<1>{ armSim.SetInput(wpi::math::Vectord<1>{
m_motor.GetThrottle() * wpi::RobotController::GetInputVoltage()}); motor.GetThrottle() * wpi::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms. // 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 // Finally, we set our simulated encoder's readings and simulated battery
// voltage // voltage
m_encoderSim.SetDistance(m_armSim.GetAngle().value()); encoderSim.SetDistance(armSim.GetAngle().value());
// SimBattery estimates loaded battery voltages // SimBattery estimates loaded battery voltages
wpi::sim::RoboRioSim::SetVInVoltage( 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 // Update the Mechanism Arm angle based on the simulated arm angle
m_arm->SetAngle(m_armSim.GetAngle()); arm->SetAngle(armSim.GetAngle());
} }
void Arm::LoadPreferences() { void Arm::LoadPreferences() {
// Read Preferences for Arm setpoint and kP on entering Teleop // Read Preferences for Arm setpoint and kP on entering Teleop
m_armSetpoint = wpi::units::degree_t{ armSetpoint = wpi::units::degree_t{
wpi::Preferences::GetDouble(kArmPositionKey, m_armSetpoint.value())}; wpi::Preferences::GetDouble(kArmPositionKey, armSetpoint.value())};
if (m_armKp != wpi::Preferences::GetDouble(kArmPKey, m_armKp)) { if (armKp != wpi::Preferences::GetDouble(kArmPKey, armKp)) {
m_armKp = wpi::Preferences::GetDouble(kArmPKey, m_armKp); armKp = wpi::Preferences::GetDouble(kArmPKey, armKp);
m_controller.SetP(m_armKp); controller.SetP(armKp);
} }
} }
void Arm::ReachSetpoint() { void Arm::ReachSetpoint() {
// Here, we run PID control like normal, with a setpoint read from // Here, we run PID control like normal, with a setpoint read from
// preferences in degrees. // preferences in degrees.
double pidOutput = m_controller.Calculate( double pidOutput = controller.Calculate(
m_encoder.GetDistance(), (wpi::units::radian_t{m_armSetpoint}.value())); encoder.GetDistance(), (wpi::units::radian_t{armSetpoint}.value()));
m_motor.SetVoltage(wpi::units::volt_t{pidOutput}); motor.SetVoltage(wpi::units::volt_t{pidOutput});
} }
void Arm::Stop() { void Arm::Stop() {
m_motor.SetThrottle(0.0); motor.SetThrottle(0.0);
} }

View File

@@ -20,6 +20,6 @@ class Robot : public wpi::TimedRobot {
void DisabledInit() override; void DisabledInit() override;
private: private:
wpi::Joystick m_joystick{kJoystickPort}; wpi::Joystick joystick{kJoystickPort};
Arm m_arm; Arm arm;
}; };

View File

@@ -29,23 +29,23 @@ class Arm {
private: private:
// The P gain for the PID controller that drives this arm. // The P gain for the PID controller that drives this arm.
double m_armKp = kDefaultArmKp; double armKp = kDefaultArmKp;
wpi::units::degree_t m_armSetpoint = kDefaultArmSetpoint; wpi::units::degree_t armSetpoint = kDefaultArmSetpoint;
// The arm gearbox represents a gearbox containing two Vex 775pro motors. // 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 // Standard classes for controlling our arm
wpi::math::PIDController m_controller{m_armKp, 0, 0}; wpi::math::PIDController controller{armKp, 0, 0};
wpi::Encoder m_encoder{kEncoderAChannel, kEncoderBChannel}; wpi::Encoder encoder{kEncoderAChannel, kEncoderBChannel};
wpi::PWMSparkMax m_motor{kMotorPort}; wpi::PWMSparkMax motor{kMotorPort};
// Simulation classes help us simulate what's going on, including gravity. // 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, // 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 // 30in overall arm length, range of motion in [-75, 255] degrees, and noise
// with a standard deviation of 1 encoder tick. // with a standard deviation of 1 encoder tick.
wpi::sim::SingleJointedArmSim m_armSim{ wpi::sim::SingleJointedArmSim armSim{
m_armGearbox, armGearbox,
kArmReduction, kArmReduction,
wpi::sim::SingleJointedArmSim::EstimateMOI(kArmLength, kArmMass), wpi::sim::SingleJointedArmSim::EstimateMOI(kArmLength, kArmMass),
kArmLength, kArmLength,
@@ -54,16 +54,16 @@ class Arm {
true, true,
0_deg, 0_deg,
{kArmEncoderDistPerPulse}}; {kArmEncoderDistPerPulse}};
wpi::sim::EncoderSim m_encoderSim{m_encoder}; wpi::sim::EncoderSim encoderSim{encoder};
// Create a Mechanism2d display of an Arm // Create a Mechanism2d display of an Arm
wpi::Mechanism2d m_mech2d{60, 60}; wpi::Mechanism2d mech2d{60, 60};
wpi::MechanismRoot2d* m_armBase = m_mech2d.GetRoot("ArmBase", 30, 30); wpi::MechanismRoot2d* armBase = mech2d.GetRoot("ArmBase", 30, 30);
wpi::MechanismLigament2d* m_armTower = wpi::MechanismLigament2d* armTower =
m_armBase->Append<wpi::MechanismLigament2d>( armBase->Append<wpi::MechanismLigament2d>(
"Arm Tower", 30, -90_deg, 6, "Arm Tower", 30, -90_deg, 6,
wpi::util::Color8Bit{wpi::util::Color::BLUE}); wpi::util::Color8Bit{wpi::util::Color::BLUE});
wpi::MechanismLigament2d* m_arm = m_armBase->Append<wpi::MechanismLigament2d>( wpi::MechanismLigament2d* arm = armBase->Append<wpi::MechanismLigament2d>(
"Arm", 30, m_armSim.GetAngle(), 6, "Arm", 30, armSim.GetAngle(), 6,
wpi::util::Color8Bit{wpi::util::Color::YELLOW}); wpi::util::Color8Bit{wpi::util::Color::YELLOW});
}; };

View File

@@ -6,24 +6,24 @@
void Drivetrain::SetVelocities( void Drivetrain::SetVelocities(
const wpi::math::DifferentialDriveWheelVelocities& velocities) { const wpi::math::DifferentialDriveWheelVelocities& velocities) {
const auto leftFeedforward = m_feedforward.Calculate(velocities.left); const auto leftFeedforward = feedforward.Calculate(velocities.left);
const auto rightFeedforward = m_feedforward.Calculate(velocities.right); const auto rightFeedforward = feedforward.Calculate(velocities.right);
const double leftOutput = m_leftPIDController.Calculate( const double leftOutput = leftPIDController.Calculate(
m_leftEncoder.GetRate(), velocities.left.value()); leftEncoder.GetRate(), velocities.left.value());
const double rightOutput = m_rightPIDController.Calculate( const double rightOutput = rightPIDController.Calculate(
m_rightEncoder.GetRate(), velocities.right.value()); rightEncoder.GetRate(), velocities.right.value());
m_leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward);
m_rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward);
} }
void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity,
wpi::units::radians_per_second_t rot) { 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() { void Drivetrain::UpdateOdometry() {
m_odometry.Update(m_imu.GetRotation2d(), odometry.Update(imu.GetRotation2d(),
wpi::units::meter_t{m_leftEncoder.GetDistance()}, wpi::units::meter_t{leftEncoder.GetDistance()},
wpi::units::meter_t{m_rightEncoder.GetDistance()}); wpi::units::meter_t{rightEncoder.GetDistance()});
} }

View File

@@ -11,35 +11,34 @@ class Robot : public wpi::TimedRobot {
public: public:
void AutonomousPeriodic() override { void AutonomousPeriodic() override {
TeleopPeriodic(); TeleopPeriodic();
m_drive.UpdateOdometry(); drive.UpdateOdometry();
} }
void TeleopPeriodic() override { void TeleopPeriodic() override {
// Get the x velocity. We are inverting this because gamepads return // Get the x velocity. We are inverting this because gamepads return
// negative values when we push forward. // negative values when we push forward.
const auto xVelocity = const auto xVelocity = -velocityLimiter.Calculate(controller.GetLeftY()) *
-m_velocityLimiter.Calculate(m_controller.GetLeftY()) * Drivetrain::kMaxVelocity;
Drivetrain::kMaxVelocity;
// Get the rate of angular rotation. We are inverting this because we want a // 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 // positive value when we pull to the left (remember, CCW is positive in
// mathematics). Gamepads return positive values when you pull to // mathematics). Gamepads return positive values when you pull to
// the right by default. // the right by default.
const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * const auto rot = -rotLimiter.Calculate(controller.GetRightX()) *
Drivetrain::kMaxAngularVelocity; Drivetrain::kMaxAngularVelocity;
m_drive.Drive(xVelocity, rot); drive.Drive(xVelocity, rot);
} }
private: private:
wpi::Gamepad m_controller{0}; wpi::Gamepad controller{0};
// Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
// to 1. // to 1.
wpi::math::SlewRateLimiter<wpi::units::scalar> m_velocityLimiter{3 / 1_s}; wpi::math::SlewRateLimiter<wpi::units::scalar> velocityLimiter{3 / 1_s};
wpi::math::SlewRateLimiter<wpi::units::scalar> m_rotLimiter{3 / 1_s}; wpi::math::SlewRateLimiter<wpi::units::scalar> rotLimiter{3 / 1_s};
Drivetrain m_drive; Drivetrain drive;
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -24,25 +24,25 @@
class Drivetrain { class Drivetrain {
public: public:
Drivetrain() { Drivetrain() {
m_leftLeader.AddFollower(m_leftFollower); leftLeader.AddFollower(leftFollower);
m_rightLeader.AddFollower(m_rightFollower); rightLeader.AddFollower(rightFollower);
// We need to invert one side of the drivetrain so that positive voltages // 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 // result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead. // 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 // 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 // distance traveled for one rotation of the wheel divided by the encoder
// resolution. // resolution.
m_leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / leftEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution); kEncoderResolution);
m_rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius / rightEncoder.SetDistancePerPulse(2 * std::numbers::pi * kWheelRadius /
kEncoderResolution); kEncoderResolution);
m_leftEncoder.Reset(); leftEncoder.Reset();
m_rightEncoder.Reset(); rightEncoder.Reset();
} }
static constexpr wpi::units::meters_per_second_t kMaxVelocity = static constexpr wpi::units::meters_per_second_t kMaxVelocity =
@@ -61,26 +61,26 @@ class Drivetrain {
static constexpr double kWheelRadius = 0.0508; // meters static constexpr double kWheelRadius = 0.0508; // meters
static constexpr int kEncoderResolution = 4096; static constexpr int kEncoderResolution = 4096;
wpi::PWMSparkMax m_leftLeader{1}; wpi::PWMSparkMax leftLeader{1};
wpi::PWMSparkMax m_leftFollower{2}; wpi::PWMSparkMax leftFollower{2};
wpi::PWMSparkMax m_rightLeader{3}; wpi::PWMSparkMax rightLeader{3};
wpi::PWMSparkMax m_rightFollower{4}; wpi::PWMSparkMax rightFollower{4};
wpi::Encoder m_leftEncoder{0, 1}; wpi::Encoder leftEncoder{0, 1};
wpi::Encoder m_rightEncoder{2, 3}; wpi::Encoder rightEncoder{2, 3};
wpi::math::PIDController m_leftPIDController{1.0, 0.0, 0.0}; wpi::math::PIDController leftPIDController{1.0, 0.0, 0.0};
wpi::math::PIDController m_rightPIDController{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};
wpi::math::DifferentialDriveOdometry m_odometry{ wpi::math::DifferentialDriveOdometry odometry{
m_imu.GetRotation2d(), wpi::units::meter_t{m_leftEncoder.GetDistance()}, imu.GetRotation2d(), wpi::units::meter_t{leftEncoder.GetDistance()},
wpi::units::meter_t{m_rightEncoder.GetDistance()}}; wpi::units::meter_t{rightEncoder.GetDistance()}};
// Gains are for example purposes only - must be determined for your own // Gains are for example purposes only - must be determined for your own
// robot! // robot!
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward{ wpi::math::SimpleMotorFeedforward<wpi::units::meters> feedforward{
1_V, 3_V / 1_mps}; 1_V, 3_V / 1_mps};
}; };

View File

@@ -12,47 +12,47 @@
#include "wpi/system/RobotController.hpp" #include "wpi/system/RobotController.hpp"
Drivetrain::Drivetrain() { Drivetrain::Drivetrain() {
m_leftLeader.AddFollower(m_leftFollower); leftLeader.AddFollower(leftFollower);
m_rightLeader.AddFollower(m_rightFollower); rightLeader.AddFollower(rightFollower);
// We need to invert one side of the drivetrain so that positive voltages // 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 // result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead. // 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 // 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 // distance traveled for one rotation of the wheel divided by the encoder
// resolution. // resolution.
m_leftEncoder.SetDistancePerPulse( leftEncoder.SetDistancePerPulse(
(2 * std::numbers::pi * kWheelRadius / kEncoderResolution).value()); (2 * std::numbers::pi * kWheelRadius / kEncoderResolution).value());
m_rightEncoder.SetDistancePerPulse( rightEncoder.SetDistancePerPulse(
(2 * std::numbers::pi * kWheelRadius / kEncoderResolution).value()); (2 * std::numbers::pi * kWheelRadius / kEncoderResolution).value());
m_leftEncoder.Reset(); leftEncoder.Reset();
m_rightEncoder.Reset(); rightEncoder.Reset();
wpi::SmartDashboard::PutData("FieldSim", &m_fieldSim); wpi::SmartDashboard::PutData("FieldSim", &fieldSim);
wpi::SmartDashboard::PutData("Approximation", &m_fieldApproximation); wpi::SmartDashboard::PutData("Approximation", &fieldApproximation);
} }
void Drivetrain::SetVelocities( void Drivetrain::SetVelocities(
const wpi::math::DifferentialDriveWheelVelocities& velocities) { const wpi::math::DifferentialDriveWheelVelocities& velocities) {
const auto leftFeedforward = m_feedforward.Calculate(velocities.left); const auto leftFeedforward = feedforward.Calculate(velocities.left);
const auto rightFeedforward = m_feedforward.Calculate(velocities.right); const auto rightFeedforward = feedforward.Calculate(velocities.right);
const double leftOutput = m_leftPIDController.Calculate( const double leftOutput = leftPIDController.Calculate(
m_leftEncoder.GetRate(), velocities.left.value()); leftEncoder.GetRate(), velocities.left.value());
const double rightOutput = m_rightPIDController.Calculate( const double rightOutput = rightPIDController.Calculate(
m_rightEncoder.GetRate(), velocities.right.value()); rightEncoder.GetRate(), velocities.right.value());
m_leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward); leftLeader.SetVoltage(wpi::units::volt_t{leftOutput} + leftFeedforward);
m_rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward); rightLeader.SetVoltage(wpi::units::volt_t{rightOutput} + rightFeedforward);
} }
void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity, void Drivetrain::Drive(wpi::units::meters_per_second_t xVelocity,
wpi::units::radians_per_second_t rot) { 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( void Drivetrain::PublishCameraToObject(
@@ -93,19 +93,19 @@ wpi::math::Pose3d Drivetrain::ObjectToRobotPose(
} }
void Drivetrain::UpdateOdometry() { void Drivetrain::UpdateOdometry() {
m_poseEstimator.Update(m_imu.GetRotation2d(), poseEstimator.Update(imu.GetRotation2d(),
wpi::units::meter_t{m_leftEncoder.GetDistance()}, wpi::units::meter_t{leftEncoder.GetDistance()},
wpi::units::meter_t{m_rightEncoder.GetDistance()}); wpi::units::meter_t{rightEncoder.GetDistance()});
// Publish cameraToObject transformation to networktables --this would // Publish cameraToObject transformation to networktables --this would
// normally be handled by the computer vision solution. // normally be handled by the computer vision solution.
PublishCameraToObject(m_objectInField, m_robotToCamera, PublishCameraToObject(objectInField, robotToCamera, cameraToObjectEntryRef,
m_cameraToObjectEntryRef, m_drivetrainSimulator); drivetrainSimulator);
// Compute the robot's field-relative position exclusively from vision // Compute the robot's field-relative position exclusively from vision
// measurements. // measurements.
wpi::math::Pose3d visionMeasurement3d = ObjectToRobotPose( wpi::math::Pose3d visionMeasurement3d =
m_objectInField, m_robotToCamera, m_cameraToObjectEntryRef); ObjectToRobotPose(objectInField, robotToCamera, cameraToObjectEntryRef);
// Convert robot's pose from wpi::math::Pose3d to wpi::math::Pose2d needed to // Convert robot's pose from wpi::math::Pose3d to wpi::math::Pose2d needed to
// apply vision measurements. // apply vision measurements.
@@ -114,32 +114,30 @@ void Drivetrain::UpdateOdometry() {
// Apply vision measurements. For simulation purposes only, we don't input a // 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 // latency delay -- on a real robot, this must be calculated based either on
// known latency or timestamps. // known latency or timestamps.
m_poseEstimator.AddVisionMeasurement(visionMeasurement2d, poseEstimator.AddVisionMeasurement(visionMeasurement2d,
wpi::Timer::GetTimestamp()); wpi::Timer::GetTimestamp());
} }
void Drivetrain::SimulationPeriodic() { void Drivetrain::SimulationPeriodic() {
// To update our simulation, we set motor voltage inputs, update the // To update our simulation, we set motor voltage inputs, update the
// simulation, and write the simulated positions and velocities to our // simulation, and write the simulated positions and velocities to our
// simulated encoder and gyro. // simulated encoder and gyro.
m_drivetrainSimulator.SetInputs( drivetrainSimulator.SetInputs(wpi::units::volt_t{leftLeader.GetThrottle()} *
wpi::units::volt_t{m_leftLeader.GetThrottle()} * wpi::RobotController::GetInputVoltage(),
wpi::RobotController::GetInputVoltage(), wpi::units::volt_t{rightLeader.GetThrottle()} *
wpi::units::volt_t{m_rightLeader.GetThrottle()} * wpi::RobotController::GetInputVoltage());
wpi::RobotController::GetInputVoltage()); drivetrainSimulator.Update(20_ms);
m_drivetrainSimulator.Update(20_ms);
m_leftEncoderSim.SetDistance(m_drivetrainSimulator.GetLeftPosition().value()); leftEncoderSim.SetDistance(drivetrainSimulator.GetLeftPosition().value());
m_leftEncoderSim.SetRate(m_drivetrainSimulator.GetLeftVelocity().value()); leftEncoderSim.SetRate(drivetrainSimulator.GetLeftVelocity().value());
m_rightEncoderSim.SetDistance( rightEncoderSim.SetDistance(drivetrainSimulator.GetRightPosition().value());
m_drivetrainSimulator.GetRightPosition().value()); rightEncoderSim.SetRate(drivetrainSimulator.GetRightVelocity().value());
m_rightEncoderSim.SetRate(m_drivetrainSimulator.GetRightVelocity().value()); // gyroSim.SetAngle(-drivetrainSimulator.GetHeading().Degrees().value());
// m_gyroSim.SetAngle(-m_drivetrainSimulator.GetHeading().Degrees().value());
// // TODO(Ryan): fixup when sim implemented // // TODO(Ryan): fixup when sim implemented
} }
void Drivetrain::Periodic() { void Drivetrain::Periodic() {
UpdateOdometry(); UpdateOdometry();
m_fieldSim.SetRobotPose(m_drivetrainSimulator.GetPose()); fieldSim.SetRobotPose(drivetrainSimulator.GetPose());
m_fieldApproximation.SetRobotPose(m_poseEstimator.GetEstimatedPosition()); fieldApproximation.SetRobotPose(poseEstimator.GetEstimatedPosition());
} }

View File

@@ -11,39 +11,38 @@ class Robot : public wpi::TimedRobot {
public: public:
void AutonomousPeriodic() override { void AutonomousPeriodic() override {
TeleopPeriodic(); TeleopPeriodic();
m_drive.UpdateOdometry(); drive.UpdateOdometry();
} }
void RobotPeriodic() override { m_drive.Periodic(); } void RobotPeriodic() override { drive.Periodic(); }
void TeleopPeriodic() override { void TeleopPeriodic() override {
// Get the x velocity. We are inverting this because gamepads return // Get the x velocity. We are inverting this because gamepads return
// negative values when we push forward. // negative values when we push forward.
const auto xVelocity = const auto xVelocity = -velocityLimiter.Calculate(controller.GetLeftY()) *
-m_velocityLimiter.Calculate(m_controller.GetLeftY()) * Drivetrain::kMaxVelocity;
Drivetrain::kMaxVelocity;
// Get the rate of angular rotation. We are inverting this because we want a // 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 // positive value when we pull to the left (remember, CCW is positive in
// mathematics). Gamepads return positive values when you pull to // mathematics). Gamepads return positive values when you pull to
// the right by default. // the right by default.
const auto rot = -m_rotLimiter.Calculate(m_controller.GetRightX()) * const auto rot = -rotLimiter.Calculate(controller.GetRightX()) *
Drivetrain::kMaxAngularVelocity; Drivetrain::kMaxAngularVelocity;
m_drive.Drive(xVelocity, rot); drive.Drive(xVelocity, rot);
} }
void SimulationPeriodic() override { m_drive.SimulationPeriodic(); } void SimulationPeriodic() override { drive.SimulationPeriodic(); }
private: private:
wpi::Gamepad m_controller{0}; wpi::Gamepad controller{0};
// Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0 // Slew rate limiters to make joystick inputs more gentle; 1/3 sec from 0
// to 1. // to 1.
wpi::math::SlewRateLimiter<wpi::units::scalar> m_velocityLimiter{3 / 1_s}; wpi::math::SlewRateLimiter<wpi::units::scalar> velocityLimiter{3 / 1_s};
wpi::math::SlewRateLimiter<wpi::units::scalar> m_rotLimiter{3 / 1_s}; wpi::math::SlewRateLimiter<wpi::units::scalar> rotLimiter{3 / 1_s};
Drivetrain m_drive; Drivetrain drive;
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -114,64 +114,63 @@ class Drivetrain {
static constexpr std::array<double, 7> kDefaultVal{0.0, 0.0, 0.0, 0.0, static constexpr std::array<double, 7> kDefaultVal{0.0, 0.0, 0.0, 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::Translation3d{1_m, 1_m, 1_m},
wpi::math::Rotation3d{0_rad, 0_rad, wpi::math::Rotation3d{0_rad, 0_rad,
wpi::units::radian_t{std::numbers::pi / 2}}}; wpi::units::radian_t{std::numbers::pi / 2}}};
wpi::nt::NetworkTableInstance m_inst{ wpi::nt::NetworkTableInstance inst{
wpi::nt::NetworkTableInstance::GetDefault()}; wpi::nt::NetworkTableInstance::GetDefault()};
wpi::nt::DoubleArrayTopic m_cameraToObjectTopic{ wpi::nt::DoubleArrayTopic cameraToObjectTopic{
m_inst.GetDoubleArrayTopic("m_cameraToObjectTopic")}; inst.GetDoubleArrayTopic("cameraToObjectTopic")};
wpi::nt::DoubleArrayEntry m_cameraToObjectEntry = wpi::nt::DoubleArrayEntry cameraToObjectEntry =
m_cameraToObjectTopic.GetEntry(kDefaultVal); cameraToObjectTopic.GetEntry(kDefaultVal);
wpi::nt::DoubleArrayEntry& m_cameraToObjectEntryRef = m_cameraToObjectEntry; wpi::nt::DoubleArrayEntry& cameraToObjectEntryRef = cameraToObjectEntry;
wpi::apriltag::AprilTagFieldLayout m_aprilTagFieldLayout{ wpi::apriltag::AprilTagFieldLayout aprilTagFieldLayout{
wpi::apriltag::AprilTagFieldLayout::LoadField( wpi::apriltag::AprilTagFieldLayout::LoadField(
wpi::apriltag::AprilTagField::k2024Crescendo)}; wpi::apriltag::AprilTagField::k2024Crescendo)};
wpi::math::Pose3d m_objectInField{ wpi::math::Pose3d objectInField{aprilTagFieldLayout.GetTagPose(0).value()};
m_aprilTagFieldLayout.GetTagPose(0).value()};
wpi::PWMSparkMax m_leftLeader{1}; wpi::PWMSparkMax leftLeader{1};
wpi::PWMSparkMax m_leftFollower{2}; wpi::PWMSparkMax leftFollower{2};
wpi::PWMSparkMax m_rightLeader{3}; wpi::PWMSparkMax rightLeader{3};
wpi::PWMSparkMax m_rightFollower{4}; wpi::PWMSparkMax rightFollower{4};
wpi::Encoder m_leftEncoder{0, 1}; wpi::Encoder leftEncoder{0, 1};
wpi::Encoder m_rightEncoder{2, 3}; wpi::Encoder rightEncoder{2, 3};
wpi::math::PIDController m_leftPIDController{1.0, 0.0, 0.0}; wpi::math::PIDController leftPIDController{1.0, 0.0, 0.0};
wpi::math::PIDController m_rightPIDController{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 // Gains are for example purposes only - must be determined for your own
// robot! // robot!
wpi::math::DifferentialDrivePoseEstimator m_poseEstimator{ wpi::math::DifferentialDrivePoseEstimator poseEstimator{
m_kinematics, kinematics,
m_imu.GetRotation2d(), imu.GetRotation2d(),
wpi::units::meter_t{m_leftEncoder.GetDistance()}, wpi::units::meter_t{leftEncoder.GetDistance()},
wpi::units::meter_t{m_rightEncoder.GetDistance()}, wpi::units::meter_t{rightEncoder.GetDistance()},
wpi::math::Pose2d{}, wpi::math::Pose2d{},
{0.01, 0.01, 0.01}, {0.01, 0.01, 0.01},
{0.1, 0.1, 0.1}}; {0.1, 0.1, 0.1}};
// Gains are for example purposes only - must be determined for your own // Gains are for example purposes only - must be determined for your own
// robot! // robot!
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward{ wpi::math::SimpleMotorFeedforward<wpi::units::meters> feedforward{
1_V, 3_V / 1_mps}; 1_V, 3_V / 1_mps};
// Simulation classes // Simulation classes
wpi::sim::EncoderSim m_leftEncoderSim{m_leftEncoder}; wpi::sim::EncoderSim leftEncoderSim{leftEncoder};
wpi::sim::EncoderSim m_rightEncoderSim{m_rightEncoder}; wpi::sim::EncoderSim rightEncoderSim{rightEncoder};
wpi::Field2d m_fieldSim; wpi::Field2d fieldSim;
wpi::Field2d m_fieldApproximation; wpi::Field2d fieldApproximation;
wpi::math::LinearSystem<2, 2, 2> m_drivetrainSystem = wpi::math::LinearSystem<2, 2, 2> drivetrainSystem =
wpi::math::Models::DifferentialDriveFromSysId( 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); 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{ wpi::sim::DifferentialDrivetrainSim drivetrainSimulator{
m_drivetrainSystem, kTrackwidth, wpi::math::DCMotor::CIM(2), 8, 2_in}; drivetrainSystem, kTrackwidth, wpi::math::DCMotor::CIM(2), 8, 2_in};
}; };

View File

@@ -35,11 +35,11 @@ void Robot::DisabledPeriodic() {}
* RobotContainer} class. * RobotContainer} class.
*/ */
void Robot::AutonomousInit() { void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand(); autonomousCommand = container.GetAutonomousCommand();
if (m_autonomousCommand) { if (autonomousCommand) {
wpi::cmd::CommandScheduler::GetInstance().Schedule( 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 // teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove // continue until interrupted by another command, remove
// this line or comment it out. // this line or comment it out.
if (m_autonomousCommand) { if (autonomousCommand) {
m_autonomousCommand->Cancel(); autonomousCommand->Cancel();
m_autonomousCommand.reset(); autonomousCommand.reset();
} }
} }

View File

@@ -13,31 +13,31 @@ RobotContainer::RobotContainer() {
ConfigureButtonBindings(); ConfigureButtonBindings();
// Set up default drive command // Set up default drive command
m_drive.SetDefaultCommand(wpi::cmd::Run( drive.SetDefaultCommand(wpi::cmd::Run(
[this] { [this] {
m_drive.ArcadeDrive(-m_driverController.GetLeftY(), drive.ArcadeDrive(-driverController.GetLeftY(),
-m_driverController.GetRightX()); -driverController.GetRightX());
}, },
{&m_drive})); {&drive}));
} }
void RobotContainer::ConfigureButtonBindings() { void RobotContainer::ConfigureButtonBindings() {
// Configure your button bindings here // Configure your button bindings here
// While holding the bumper button, drive at half velocity // While holding the bumper button, drive at half velocity
m_driverController.RightBumper() driverController.RightBumper()
.OnTrue(m_driveHalfVelocity.get()) .OnTrue(driveHalfVelocity.get())
.OnFalse(m_driveFullVelocity.get()); .OnFalse(driveFullVelocity.get());
// Drive forward by 3 meters when the 'South Face' button is pressed, with a // Drive forward by 3 meters when the 'South Face' button is pressed, with a
// timeout of 10 seconds // timeout of 10 seconds
m_driverController.SouthFace().OnTrue( driverController.SouthFace().OnTrue(
m_drive.ProfiledDriveDistance(3_m).WithTimeout(10_s)); drive.ProfiledDriveDistance(3_m).WithTimeout(10_s));
// Do the same thing as above when the 'East Face' button is pressed, but // Do the same thing as above when the 'East Face' button is pressed, but
// without resetting the encoders // without resetting the encoders
m_driverController.EastFace().OnTrue( driverController.EastFace().OnTrue(
m_drive.DynamicProfiledDriveDistance(3_m).WithTimeout(10_s)); drive.DynamicProfiledDriveDistance(3_m).WithTimeout(10_s));
} }
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() { wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {

View File

@@ -9,24 +9,24 @@
using namespace DriveConstants; using namespace DriveConstants;
DriveSubsystem::DriveSubsystem() DriveSubsystem::DriveSubsystem()
: m_leftLeader{kLeftMotor1Port}, : leftLeader{kLeftMotor1Port},
m_leftFollower{kLeftMotor2Port}, leftFollower{kLeftMotor2Port},
m_rightLeader{kRightMotor1Port}, rightLeader{kRightMotor1Port},
m_rightFollower{kRightMotor2Port}, rightFollower{kRightMotor2Port},
m_feedforward{ks, kv, ka} { feedforward{ks, kv, ka} {
wpi::util::SendableRegistry::AddChild(&m_drive, &m_leftLeader); wpi::util::SendableRegistry::AddChild(&drive, &leftLeader);
wpi::util::SendableRegistry::AddChild(&m_drive, &m_rightLeader); wpi::util::SendableRegistry::AddChild(&drive, &rightLeader);
// We need to invert one side of the drivetrain so that positive voltages // 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 // result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead. // gearbox is constructed, you might have to invert the left side instead.
m_rightLeader.SetInverted(true); rightLeader.SetInverted(true);
m_leftFollower.Follow(m_leftLeader); leftFollower.Follow(leftLeader);
m_rightFollower.Follow(m_rightLeader); rightFollower.Follow(rightLeader);
m_leftLeader.SetPID(kp, 0, 0); leftLeader.SetPID(kp, 0, 0);
m_rightLeader.SetPID(kp, 0, 0); rightLeader.SetPID(kp, 0, 0);
} }
void DriveSubsystem::Periodic() { void DriveSubsystem::Periodic() {
@@ -39,37 +39,37 @@ void DriveSubsystem::SetDriveStates(
wpi::math::TrapezoidProfile<wpi::units::meters>::State nextLeft, wpi::math::TrapezoidProfile<wpi::units::meters>::State nextLeft,
wpi::math::TrapezoidProfile<wpi::units::meters>::State nextRight) { wpi::math::TrapezoidProfile<wpi::units::meters>::State nextRight) {
// Feedforward is divided by battery voltage to normalize it to [-1, 1] // Feedforward is divided by battery voltage to normalize it to [-1, 1]
m_leftLeader.SetSetpoint( leftLeader.SetSetpoint(
ExampleSmartMotorController::PIDMode::kPosition, ExampleSmartMotorController::PIDMode::kPosition,
currentLeft.position.value(), currentLeft.position.value(),
m_feedforward.Calculate(currentLeft.velocity, nextLeft.velocity) / feedforward.Calculate(currentLeft.velocity, nextLeft.velocity) /
wpi::RobotController::GetBatteryVoltage()); wpi::RobotController::GetBatteryVoltage());
m_rightLeader.SetSetpoint( rightLeader.SetSetpoint(
ExampleSmartMotorController::PIDMode::kPosition, ExampleSmartMotorController::PIDMode::kPosition,
currentRight.position.value(), currentRight.position.value(),
m_feedforward.Calculate(currentRight.velocity, nextRight.velocity) / feedforward.Calculate(currentRight.velocity, nextRight.velocity) /
wpi::RobotController::GetBatteryVoltage()); wpi::RobotController::GetBatteryVoltage());
} }
void DriveSubsystem::ArcadeDrive(double fwd, double rot) { void DriveSubsystem::ArcadeDrive(double fwd, double rot) {
m_drive.ArcadeDrive(fwd, rot); drive.ArcadeDrive(fwd, rot);
} }
void DriveSubsystem::ResetEncoders() { void DriveSubsystem::ResetEncoders() {
m_leftLeader.ResetEncoder(); leftLeader.ResetEncoder();
m_rightLeader.ResetEncoder(); rightLeader.ResetEncoder();
} }
wpi::units::meter_t DriveSubsystem::GetLeftEncoderDistance() { 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() { 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) { void DriveSubsystem::SetMaxOutput(double maxOutput) {
m_drive.SetMaxOutput(maxOutput); drive.SetMaxOutput(maxOutput);
} }
wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance( wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance(
@@ -77,21 +77,21 @@ wpi::cmd::CommandPtr DriveSubsystem::ProfiledDriveDistance(
return StartRun( return StartRun(
[&] { [&] {
// Restart timer so profile setpoints start at the beginning // Restart timer so profile setpoints start at the beginning
m_timer.Restart(); timer.Restart();
ResetEncoders(); ResetEncoders();
}, },
[&] { [&] {
// Current state never changes, so we need to use a timer to get // Current state never changes, so we need to use a timer to get
// the setpoints we need to be at // the setpoints we need to be at
auto currentTime = m_timer.Get(); auto currentTime = timer.Get();
auto currentSetpoint = auto currentSetpoint =
m_profile.Calculate(currentTime, {}, {distance, 0_mps}); profile.Calculate(currentTime, {}, {distance, 0_mps});
auto nextSetpoint = m_profile.Calculate(currentTime + kDt, {}, auto nextSetpoint =
{distance, 0_mps}); profile.Calculate(currentTime + kDt, {}, {distance, 0_mps});
SetDriveStates(currentSetpoint, currentSetpoint, nextSetpoint, SetDriveStates(currentSetpoint, currentSetpoint, nextSetpoint,
nextSetpoint); nextSetpoint);
}) })
.Until([&] { return m_profile.IsFinished(0_s); }); .Until([&] { return profile.IsFinished(0_s); });
} }
wpi::cmd::CommandPtr DriveSubsystem::DynamicProfiledDriveDistance( wpi::cmd::CommandPtr DriveSubsystem::DynamicProfiledDriveDistance(
@@ -99,32 +99,32 @@ wpi::cmd::CommandPtr DriveSubsystem::DynamicProfiledDriveDistance(
return StartRun( return StartRun(
[&] { [&] {
// Restart timer so profile setpoints start at the beginning // 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 // Store distance so we know the target distance for each encoder
m_initialLeftDistance = GetLeftEncoderDistance(); initialLeftDistance = GetLeftEncoderDistance();
m_initialRightDistance = GetRightEncoderDistance(); initialRightDistance = GetRightEncoderDistance();
}, },
[&] { [&] {
// Current state never changes for the duration of the command, // 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 // so we need to use a timer to get the setpoints we need to be
// at // at
auto currentTime = m_timer.Get(); auto currentTime = timer.Get();
auto currentLeftSetpoint = m_profile.Calculate( auto currentLeftSetpoint =
currentTime, {m_initialLeftDistance, 0_mps}, profile.Calculate(currentTime, {initialLeftDistance, 0_mps},
{m_initialLeftDistance + distance, 0_mps}); {initialLeftDistance + distance, 0_mps});
auto currentRightSetpoint = m_profile.Calculate( auto currentRightSetpoint =
currentTime, {m_initialRightDistance, 0_mps}, profile.Calculate(currentTime, {initialRightDistance, 0_mps},
{m_initialRightDistance + distance, 0_mps}); {initialRightDistance + distance, 0_mps});
auto nextLeftSetpoint = m_profile.Calculate( auto nextLeftSetpoint = profile.Calculate(
currentTime + kDt, {m_initialLeftDistance, 0_mps}, currentTime + kDt, {initialLeftDistance, 0_mps},
{m_initialLeftDistance + distance, 0_mps}); {initialLeftDistance + distance, 0_mps});
auto nextRightSetpoint = m_profile.Calculate( auto nextRightSetpoint = profile.Calculate(
currentTime + kDt, {m_initialRightDistance, 0_mps}, currentTime + kDt, {initialRightDistance, 0_mps},
{m_initialRightDistance + distance, 0_mps}); {initialRightDistance + distance, 0_mps});
SetDriveStates(currentLeftSetpoint, currentRightSetpoint, SetDriveStates(currentLeftSetpoint, currentRightSetpoint,
nextLeftSetpoint, nextRightSetpoint); nextLeftSetpoint, nextRightSetpoint);
}) })
.Until([&] { return m_profile.IsFinished(0_s); }); .Until([&] { return profile.IsFinished(0_s); });
} }

View File

@@ -66,9 +66,9 @@ class ExampleSmartMotorController {
*/ */
void ResetEncoder() {} 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) {} void SetInverted(bool isInverted) {}
@@ -79,5 +79,5 @@ class ExampleSmartMotorController {
void StopMotor() {} void StopMotor() {}
private: private:
double m_value = 0.0; double value = 0.0;
}; };

View File

@@ -25,7 +25,7 @@ class Robot : public wpi::TimedRobot {
private: private:
// Have it null by default so that if testing teleop it // Have it null by default so that if testing teleop it
// doesn't have undefined behavior and potentially crash. // doesn't have undefined behavior and potentially crash.
std::optional<wpi::cmd::CommandPtr> m_autonomousCommand; std::optional<wpi::cmd::CommandPtr> autonomousCommand;
RobotContainer m_container; RobotContainer container;
}; };

View File

@@ -26,19 +26,18 @@ class RobotContainer {
private: private:
// The driver's controller // The driver's controller
wpi::cmd::CommandGamepad m_driverController{ wpi::cmd::CommandGamepad driverController{OIConstants::kDriverControllerPort};
OIConstants::kDriverControllerPort};
// The robot's subsystems and commands are defined here... // The robot's subsystems and commands are defined here...
// The robot's subsystems // The robot's subsystems
DriveSubsystem m_drive; DriveSubsystem drive;
// RobotContainer-owned commands // RobotContainer-owned commands
wpi::cmd::CommandPtr m_driveHalfVelocity = wpi::cmd::CommandPtr driveHalfVelocity =
wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}); wpi::cmd::RunOnce([this] { drive.SetMaxOutput(0.5); }, {});
wpi::cmd::CommandPtr m_driveFullVelocity = wpi::cmd::CommandPtr driveFullVelocity =
wpi::cmd::RunOnce([this] { m_drive.SetMaxOutput(1); }, {}); wpi::cmd::RunOnce([this] { drive.SetMaxOutput(1); }, {});
void ConfigureButtonBindings(); void ConfigureButtonBindings();
}; };

View File

@@ -95,25 +95,24 @@ class DriveSubsystem : public wpi::cmd::SubsystemBase {
wpi::units::meter_t distance); wpi::units::meter_t distance);
private: private:
wpi::math::TrapezoidProfile<wpi::units::meters> m_profile{ wpi::math::TrapezoidProfile<wpi::units::meters> profile{
{DriveConstants::kMaxVelocity, DriveConstants::kMaxAcceleration}}; {DriveConstants::kMaxVelocity, DriveConstants::kMaxAcceleration}};
wpi::Timer m_timer; wpi::Timer timer;
wpi::units::meter_t m_initialLeftDistance; wpi::units::meter_t initialLeftDistance;
wpi::units::meter_t m_initialRightDistance; wpi::units::meter_t initialRightDistance;
// Components (e.g. motor controllers and sensors) should generally be // Components (e.g. motor controllers and sensors) should generally be
// declared private and exposed only through public methods. // declared private and exposed only through public methods.
// The motor controllers // The motor controllers
ExampleSmartMotorController m_leftLeader; ExampleSmartMotorController leftLeader;
ExampleSmartMotorController m_leftFollower; ExampleSmartMotorController leftFollower;
ExampleSmartMotorController m_rightLeader; ExampleSmartMotorController rightLeader;
ExampleSmartMotorController m_rightFollower; ExampleSmartMotorController rightFollower;
// A feedforward component for the drive // A feedforward component for the drive
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward; wpi::math::SimpleMotorFeedforward<wpi::units::meters> feedforward;
// The robot's drive // The robot's drive
wpi::DifferentialDrive m_drive{ wpi::DifferentialDrive drive{[&](double output) { leftLeader.Set(output); },
[&](double output) { m_leftLeader.Set(output); }, [&](double output) { rightLeader.Set(output); }};
[&](double output) { m_rightLeader.Set(output); }};
}; };

View File

@@ -17,7 +17,7 @@ class Robot : public wpi::TimedRobot {
// to measure this is fairly easy. Set the value to 0, place the mechanism // 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 // where you want "0" to be, and observe the value on the dashboard, That
// is the value to enter for the 3rd parameter. // is the value to enter for the 3rd parameter.
wpi::DutyCycleEncoder m_dutyCycleEncoder{0, fullRange, expectedZero}; wpi::DutyCycleEncoder dutyCycleEncoder{0, fullRange, expectedZero};
public: public:
Robot() { Robot() {
@@ -32,18 +32,18 @@ class Robot : public wpi::TimedRobot {
// those values. This number doesn't have to be perfect, // those values. This number doesn't have to be perfect,
// just having a fairly close value will make the output readings // just having a fairly close value will make the output readings
// much more stable. // much more stable.
m_dutyCycleEncoder.SetAssumedFrequency(967.8_Hz); dutyCycleEncoder.SetAssumedFrequency(967.8_Hz);
} }
void RobotPeriodic() override { void RobotPeriodic() override {
// Connected can be checked, and uses the frequency of the encoder // 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 // Duty Cycle Frequency in Hz
auto frequency = m_dutyCycleEncoder.GetFrequency(); auto frequency = dutyCycleEncoder.GetFrequency();
// Output of encoder // Output of encoder
auto output = m_dutyCycleEncoder.Get(); auto output = dutyCycleEncoder.Get();
// By default, the output will wrap around to the full range value // By default, the output will wrap around to the full range value
// when the sensor goes below 0. However, for moving mechanisms this // when the sensor goes below 0. However, for moving mechanisms this

View File

@@ -19,44 +19,44 @@ class Robot : public wpi::TimedRobot {
Robot() { Robot() {
// Note: These gains are fake, and will have to be tuned for your 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 { void TeleopPeriodic() override {
if (m_joystick.GetRawButtonPressed(2)) { if (joystick.GetRawButtonPressed(2)) {
m_goal = {5_m, 0_mps}; goal = {5_m, 0_mps};
} else if (m_joystick.GetRawButtonPressed(3)) { } else if (joystick.GetRawButtonPressed(3)) {
m_goal = {0_m, 0_mps}; goal = {0_m, 0_mps};
} }
// Retrieve the profiled setpoint for the next timestep. This setpoint moves // Retrieve the profiled setpoint for the next timestep. This setpoint moves
// toward the goal while obeying the constraints. // 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 // Send setpoint to offboard controller PID
m_motor.SetSetpoint( motor.SetSetpoint(
ExampleSmartMotorController::PIDMode::kPosition, ExampleSmartMotorController::PIDMode::kPosition,
m_setpoint.position.value(), setpoint.position.value(),
m_feedforward.Calculate(m_setpoint.velocity, next.velocity) / 12_V); feedforward.Calculate(setpoint.velocity, next.velocity) / 12_V);
m_setpoint = next; setpoint = next;
} }
private: private:
wpi::Joystick m_joystick{1}; wpi::Joystick joystick{1};
ExampleSmartMotorController m_motor{1}; ExampleSmartMotorController motor{1};
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward{ wpi::math::SimpleMotorFeedforward<wpi::units::meters> feedforward{
// Note: These gains are fake, and will have to be tuned for your robot. // 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}; 1_V, 1_V / 1_mps, 1_V / 1_mps_sq};
// Create a motion profile with the given maximum velocity and maximum // Create a motion profile with the given maximum velocity and maximum
// acceleration constraints for the next setpoint. // acceleration constraints for the next setpoint.
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts> wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts> profile{
m_profile{{10_V, 1_V / 1_mps, 1_V / 1_mps_sq}}; {10_V, 1_V / 1_mps, 1_V / 1_mps_sq}};
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State
m_goal; goal;
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State
m_setpoint; setpoint;
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -9,32 +9,32 @@
void Robot::RobotPeriodic() { void Robot::RobotPeriodic() {
// Update the telemetry, including mechanism visualization, regardless of // Update the telemetry, including mechanism visualization, regardless of
// mode. // mode.
m_elevator.UpdateTelemetry(); elevator.UpdateTelemetry();
} }
void Robot::SimulationPeriodic() { void Robot::SimulationPeriodic() {
// Update the simulation model. // Update the simulation model.
m_elevator.SimulationPeriodic(); elevator.SimulationPeriodic();
} }
void Robot::TeleopInit() { void Robot::TeleopInit() {
// This just makes sure that our simulation code knows that the motor's off. // This just makes sure that our simulation code knows that the motor's off.
m_elevator.Reset(); elevator.Reset();
} }
void Robot::TeleopPeriodic() { void Robot::TeleopPeriodic() {
if (m_joystick.GetTrigger()) { if (joystick.GetTrigger()) {
// Here, we set the constant setpoint of 0.75 meters. // Here, we set the constant setpoint of 0.75 meters.
m_elevator.ReachGoal(Constants::kSetpoint); elevator.ReachGoal(Constants::kSetpoint);
} else { } else {
// Otherwise, we update the setpoint to 0. // Otherwise, we update the setpoint to 0.
m_elevator.ReachGoal(Constants::kLowerSetpoint); elevator.ReachGoal(Constants::kLowerSetpoint);
} }
} }
void Robot::DisabledInit() { void Robot::DisabledInit() {
// This just makes sure that our simulation code knows that the motor's off. // This just makes sure that our simulation code knows that the motor's off.
m_elevator.Stop(); elevator.Stop();
} }
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -8,56 +8,56 @@
#include "wpi/system/RobotController.hpp" #include "wpi/system/RobotController.hpp"
Elevator::Elevator() { Elevator::Elevator() {
m_encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse); encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse);
// Put Mechanism 2d to SmartDashboard // Put Mechanism 2d to SmartDashboard
// To view the Elevator visualization, select Network Tables -> SmartDashboard // To view the Elevator visualization, select Network Tables -> SmartDashboard
// -> Elevator Sim // -> Elevator Sim
wpi::SmartDashboard::PutData("Elevator Sim", &m_mech2d); wpi::SmartDashboard::PutData("Elevator Sim", &mech2d);
} }
void Elevator::SimulationPeriodic() { void Elevator::SimulationPeriodic() {
// In this method, we update our simulation of what our elevator is doing // In this method, we update our simulation of what our elevator is doing
// First, we set our "inputs" (voltages) // First, we set our "inputs" (voltages)
m_elevatorSim.SetInput(wpi::math::Vectord<1>{ elevatorSim.SetInput(wpi::math::Vectord<1>{
m_motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()}); motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms. // 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 // Finally, we set our simulated encoder's readings and simulated battery
// voltage // voltage
m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value()); encoderSim.SetDistance(elevatorSim.GetPosition().value());
// SimBattery estimates loaded battery voltages // SimBattery estimates loaded battery voltages
wpi::sim::RoboRioSim::SetVInVoltage( wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()})); wpi::sim::BatterySim::Calculate({elevatorSim.GetCurrentDraw()}));
} }
void Elevator::UpdateTelemetry() { void Elevator::UpdateTelemetry() {
// Update the Elevator length based on the simulated elevator height // 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) { void Elevator::ReachGoal(wpi::units::meter_t goal) {
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State
goalState{goal, 0_mps}; 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(), auto pidOutput =
m_setpoint.position / 1_m); controller.Calculate(encoder.GetDistance(), setpoint.position / 1_m);
auto feedforwardOutput = 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() { void Elevator::Reset() {
m_setpoint = {m_encoder.GetDistance() * 1_m, 0_mps}; setpoint = {encoder.GetDistance() * 1_m, 0_mps};
} }
void Elevator::Stop() { void Elevator::Stop() {
m_motor.SetThrottle(0.0); motor.SetThrottle(0.0);
} }

View File

@@ -21,6 +21,6 @@ class Robot : public wpi::TimedRobot {
void DisabledInit() override; void DisabledInit() override;
private: private:
wpi::Joystick m_joystick{Constants::kJoystickPort}; wpi::Joystick joystick{Constants::kJoystickPort};
Elevator m_elevator; Elevator elevator;
}; };

View File

@@ -31,45 +31,45 @@ class Elevator {
private: private:
// This gearbox represents a gearbox containing 4 Vex 775pro motors. // 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 // Standard classes for controlling our elevator
wpi::math::ExponentialProfile<wpi::units::meters, wpi::math::ExponentialProfile<wpi::units::meters,
wpi::units::volts>::Constraints m_constraints{ wpi::units::volts>::Constraints constraints{
Constants::kElevatorMaxV, Constants::kElevatorkV, Constants::kElevatorkA}; Constants::kElevatorMaxV, Constants::kElevatorkV, Constants::kElevatorkA};
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts> wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts> profile{
m_profile{m_constraints}; constraints};
wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>::State
m_setpoint; setpoint;
wpi::math::PIDController m_controller{ wpi::math::PIDController controller{
Constants::kElevatorKp, Constants::kElevatorKi, Constants::kElevatorKd}; Constants::kElevatorKp, Constants::kElevatorKi, Constants::kElevatorKd};
wpi::math::ElevatorFeedforward m_feedforward{ wpi::math::ElevatorFeedforward feedforward{
Constants::kElevatorkS, Constants::kElevatorkG, Constants::kElevatorkV, Constants::kElevatorkS, Constants::kElevatorkG, Constants::kElevatorkV,
Constants::kElevatorkA}; Constants::kElevatorkA};
wpi::Encoder m_encoder{Constants::kEncoderAChannel, wpi::Encoder encoder{Constants::kEncoderAChannel,
Constants::kEncoderBChannel}; Constants::kEncoderBChannel};
wpi::PWMSparkMax m_motor{Constants::kMotorPort}; wpi::PWMSparkMax motor{Constants::kMotorPort};
wpi::sim::PWMMotorControllerSim m_motorSim{m_motor}; wpi::sim::PWMMotorControllerSim motorSim{motor};
// Simulation classes help us simulate what's going on, including gravity. // Simulation classes help us simulate what's going on, including gravity.
wpi::sim::ElevatorSim m_elevatorSim{m_elevatorGearbox, wpi::sim::ElevatorSim elevatorSim{elevatorGearbox,
Constants::kElevatorGearing, Constants::kElevatorGearing,
Constants::kCarriageMass, Constants::kCarriageMass,
Constants::kElevatorDrumRadius, Constants::kElevatorDrumRadius,
Constants::kMinElevatorHeight, Constants::kMinElevatorHeight,
Constants::kMaxElevatorHeight, Constants::kMaxElevatorHeight,
true, true,
0_m, 0_m,
{0.005}}; {0.005}};
wpi::sim::EncoderSim m_encoderSim{m_encoder}; wpi::sim::EncoderSim encoderSim{encoder};
// Create a Mechanism2d display of an elevator // Create a Mechanism2d display of an elevator
wpi::Mechanism2d m_mech2d{10_in / 1_m, 51_in / 1_m}; wpi::Mechanism2d mech2d{10_in / 1_m, 51_in / 1_m};
wpi::MechanismRoot2d* m_elevatorRoot = wpi::MechanismRoot2d* elevatorRoot =
m_mech2d.GetRoot("Elevator Root", 5_in / 1_m, 0.5_in / 1_m); mech2d.GetRoot("Elevator Root", 5_in / 1_m, 0.5_in / 1_m);
wpi::MechanismLigament2d* m_elevatorMech2d = wpi::MechanismLigament2d* elevatorMech2d =
m_elevatorRoot->Append<wpi::MechanismLigament2d>( elevatorRoot->Append<wpi::MechanismLigament2d>(
"Elevator", m_elevatorSim.GetPosition().value(), 90_deg); "Elevator", elevatorSim.GetPosition().value(), 90_deg);
}; };

View File

@@ -22,21 +22,20 @@ class Robot : public wpi::TimedRobot {
static constexpr wpi::units::second_t kDt = 20_ms; static constexpr wpi::units::second_t kDt = 20_ms;
Robot() { 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 { void TeleopPeriodic() override {
if (m_joystick.GetRawButtonPressed(2)) { if (joystick.GetRawButtonPressed(2)) {
m_controller.SetGoal(5_m); controller.SetGoal(5_m);
} else if (m_joystick.GetRawButtonPressed(3)) { } else if (joystick.GetRawButtonPressed(3)) {
m_controller.SetGoal(0_m); controller.SetGoal(0_m);
} }
// Run controller and update motor output // Run controller and update motor output
m_motor.SetVoltage( motor.SetVoltage(wpi::units::volt_t{controller.Calculate(
wpi::units::volt_t{m_controller.Calculate( wpi::units::meter_t{encoder.GetDistance()})} +
wpi::units::meter_t{m_encoder.GetDistance()})} + feedforward.Calculate(controller.GetSetpoint().velocity));
m_feedforward.Calculate(m_controller.GetSetpoint().velocity));
} }
private: private:
@@ -50,17 +49,17 @@ class Robot : public wpi::TimedRobot {
static constexpr wpi::units::volt_t kG = 1.2_V; static constexpr wpi::units::volt_t kG = 1.2_V;
static constexpr auto kV = 1.3_V / 1_mps; static constexpr auto kV = 1.3_V / 1_mps;
wpi::Joystick m_joystick{1}; wpi::Joystick joystick{1};
wpi::Encoder m_encoder{1, 2}; wpi::Encoder encoder{1, 2};
wpi::PWMSparkMax m_motor{1}; wpi::PWMSparkMax motor{1};
// Create a PID controller whose setpoint's change is subject to maximum // Create a PID controller whose setpoint's change is subject to maximum
// velocity and acceleration constraints. // velocity and acceleration constraints.
wpi::math::TrapezoidProfile<wpi::units::meters>::Constraints m_constraints{ wpi::math::TrapezoidProfile<wpi::units::meters>::Constraints constraints{
kMaxVelocity, kMaxAcceleration}; kMaxVelocity, kMaxAcceleration};
wpi::math::ProfiledPIDController<wpi::units::meters> m_controller{ wpi::math::ProfiledPIDController<wpi::units::meters> controller{
kP, kI, kD, m_constraints, kDt}; kP, kI, kD, constraints, kDt};
wpi::math::ElevatorFeedforward m_feedforward{kS, kG, kV}; wpi::math::ElevatorFeedforward feedforward{kS, kG, kV};
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -9,27 +9,27 @@
void Robot::RobotPeriodic() { void Robot::RobotPeriodic() {
// Update the telemetry, including mechanism visualization, regardless of // Update the telemetry, including mechanism visualization, regardless of
// mode. // mode.
m_elevator.UpdateTelemetry(); elevator.UpdateTelemetry();
} }
void Robot::SimulationPeriodic() { void Robot::SimulationPeriodic() {
// Update the simulation model. // Update the simulation model.
m_elevator.SimulationPeriodic(); elevator.SimulationPeriodic();
} }
void Robot::TeleopPeriodic() { void Robot::TeleopPeriodic() {
if (m_joystick.GetTrigger()) { if (joystick.GetTrigger()) {
// Here, we set the constant setpoint of 0.75 meters. // Here, we set the constant setpoint of 0.75 meters.
m_elevator.ReachGoal(Constants::kSetpoint); elevator.ReachGoal(Constants::kSetpoint);
} else { } else {
// Otherwise, we update the setpoint to 0. // Otherwise, we update the setpoint to 0.
m_elevator.ReachGoal(0.0_m); elevator.ReachGoal(0.0_m);
} }
} }
void Robot::DisabledInit() { void Robot::DisabledInit() {
// This just makes sure that our simulation code knows that the motor's off. // This just makes sure that our simulation code knows that the motor's off.
m_elevator.Stop(); elevator.Stop();
} }
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -8,47 +8,47 @@
#include "wpi/system/RobotController.hpp" #include "wpi/system/RobotController.hpp"
Elevator::Elevator() { Elevator::Elevator() {
m_encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse); encoder.SetDistancePerPulse(Constants::kArmEncoderDistPerPulse);
// Put Mechanism 2d to SmartDashboard // Put Mechanism 2d to SmartDashboard
// To view the Elevator visualization, select Network Tables -> SmartDashboard // To view the Elevator visualization, select Network Tables -> SmartDashboard
// -> Elevator Sim // -> Elevator Sim
wpi::SmartDashboard::PutData("Elevator Sim", &m_mech2d); wpi::SmartDashboard::PutData("Elevator Sim", &mech2d);
} }
void Elevator::SimulationPeriodic() { void Elevator::SimulationPeriodic() {
// In this method, we update our simulation of what our elevator is doing // In this method, we update our simulation of what our elevator is doing
// First, we set our "inputs" (voltages) // First, we set our "inputs" (voltages)
m_elevatorSim.SetInput(wpi::math::Vectord<1>{ elevatorSim.SetInput(wpi::math::Vectord<1>{
m_motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()}); motorSim.GetThrottle() * wpi::RobotController::GetInputVoltage()});
// Next, we update it. The standard loop time is 20ms. // 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 // Finally, we set our simulated encoder's readings and simulated battery
// voltage // voltage
m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value()); encoderSim.SetDistance(elevatorSim.GetPosition().value());
// SimBattery estimates loaded battery voltages // SimBattery estimates loaded battery voltages
wpi::sim::RoboRioSim::SetVInVoltage( wpi::sim::RoboRioSim::SetVInVoltage(
wpi::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()})); wpi::sim::BatterySim::Calculate({elevatorSim.GetCurrentDraw()}));
} }
void Elevator::UpdateTelemetry() { void Elevator::UpdateTelemetry() {
// Update the Elevator length based on the simulated elevator height // 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) { 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 // With the setpoint value we run PID control like normal
double pidOutput = 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 = wpi::units::volt_t feedforwardOutput =
m_feedforward.Calculate(m_controller.GetSetpoint().velocity); feedforward.Calculate(controller.GetSetpoint().velocity);
m_motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput); motor.SetVoltage(wpi::units::volt_t{pidOutput} + feedforwardOutput);
} }
void Elevator::Stop() { void Elevator::Stop() {
m_controller.SetGoal(0.0_m); controller.SetGoal(0.0_m);
m_motor.SetThrottle(0.0); motor.SetThrottle(0.0);
} }

View File

@@ -20,6 +20,6 @@ class Robot : public wpi::TimedRobot {
void DisabledInit() override; void DisabledInit() override;
private: private:
wpi::Joystick m_joystick{Constants::kJoystickPort}; wpi::Joystick joystick{Constants::kJoystickPort};
Elevator m_elevator; Elevator elevator;
}; };

View File

@@ -30,40 +30,39 @@ class Elevator {
private: private:
// This gearbox represents a gearbox containing 4 Vex 775pro motors. // 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 // Standard classes for controlling our elevator
wpi::math::TrapezoidProfile<wpi::units::meters>::Constraints m_constraints{ wpi::math::TrapezoidProfile<wpi::units::meters>::Constraints constraints{
2.45_mps, 2.45_mps_sq}; 2.45_mps, 2.45_mps_sq};
wpi::math::ProfiledPIDController<wpi::units::meters> m_controller{ wpi::math::ProfiledPIDController<wpi::units::meters> controller{
Constants::kElevatorKp, Constants::kElevatorKi, Constants::kElevatorKd, 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::kElevatorkS, Constants::kElevatorkG, Constants::kElevatorkV,
Constants::kElevatorkA}; Constants::kElevatorkA};
wpi::Encoder m_encoder{Constants::kEncoderAChannel, wpi::Encoder encoder{Constants::kEncoderAChannel,
Constants::kEncoderBChannel}; Constants::kEncoderBChannel};
wpi::PWMSparkMax m_motor{Constants::kMotorPort}; wpi::PWMSparkMax motor{Constants::kMotorPort};
wpi::sim::PWMMotorControllerSim m_motorSim{m_motor}; wpi::sim::PWMMotorControllerSim motorSim{motor};
// Simulation classes help us simulate what's going on, including gravity. // Simulation classes help us simulate what's going on, including gravity.
wpi::sim::ElevatorSim m_elevatorSim{m_elevatorGearbox, wpi::sim::ElevatorSim elevatorSim{elevatorGearbox,
Constants::kElevatorGearing, Constants::kElevatorGearing,
Constants::kCarriageMass, Constants::kCarriageMass,
Constants::kElevatorDrumRadius, Constants::kElevatorDrumRadius,
Constants::kMinElevatorHeight, Constants::kMinElevatorHeight,
Constants::kMaxElevatorHeight, Constants::kMaxElevatorHeight,
true, true,
0_m, 0_m,
{0.01}}; {0.01}};
wpi::sim::EncoderSim m_encoderSim{m_encoder}; wpi::sim::EncoderSim encoderSim{encoder};
// Create a Mechanism2d display of an elevator // Create a Mechanism2d display of an elevator
wpi::Mechanism2d m_mech2d{20, 50}; wpi::Mechanism2d mech2d{20, 50};
wpi::MechanismRoot2d* m_elevatorRoot = wpi::MechanismRoot2d* elevatorRoot = mech2d.GetRoot("Elevator Root", 10, 0);
m_mech2d.GetRoot("Elevator Root", 10, 0); wpi::MechanismLigament2d* elevatorMech2d =
wpi::MechanismLigament2d* m_elevatorMech2d = elevatorRoot->Append<wpi::MechanismLigament2d>(
m_elevatorRoot->Append<wpi::MechanismLigament2d>( "Elevator", elevatorSim.GetPosition().value(), 90_deg);
"Elevator", m_elevatorSim.GetPosition().value(), 90_deg);
}; };

View File

@@ -19,39 +19,39 @@ class Robot : public wpi::TimedRobot {
Robot() { Robot() {
// Note: These gains are fake, and will have to be tuned for your 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 { void TeleopPeriodic() override {
if (m_joystick.GetRawButtonPressed(2)) { if (joystick.GetRawButtonPressed(2)) {
m_goal = {5_m, 0_mps}; goal = {5_m, 0_mps};
} else if (m_joystick.GetRawButtonPressed(3)) { } else if (joystick.GetRawButtonPressed(3)) {
m_goal = {0_m, 0_mps}; goal = {0_m, 0_mps};
} }
// Retrieve the profiled setpoint for the next timestep. This setpoint moves // Retrieve the profiled setpoint for the next timestep. This setpoint moves
// toward the goal while obeying the constraints. // 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 // Send setpoint to offboard controller PID
m_motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition, motor.SetSetpoint(ExampleSmartMotorController::PIDMode::kPosition,
m_setpoint.position.value(), setpoint.position.value(),
m_feedforward.Calculate(m_setpoint.velocity) / 12_V); feedforward.Calculate(setpoint.velocity) / 12_V);
} }
private: private:
wpi::Joystick m_joystick{1}; wpi::Joystick joystick{1};
ExampleSmartMotorController m_motor{1}; ExampleSmartMotorController motor{1};
wpi::math::SimpleMotorFeedforward<wpi::units::meters> m_feedforward{ wpi::math::SimpleMotorFeedforward<wpi::units::meters> feedforward{
// Note: These gains are fake, and will have to be tuned for your robot. // Note: These gains are fake, and will have to be tuned for your robot.
1_V, 1.5_V * 1_s / 1_m}; 1_V, 1.5_V * 1_s / 1_m};
// Create a motion profile with the given maximum velocity and maximum // Create a motion profile with the given maximum velocity and maximum
// acceleration constraints for the next setpoint. // acceleration constraints for the next setpoint.
wpi::math::TrapezoidProfile<wpi::units::meters> m_profile{ wpi::math::TrapezoidProfile<wpi::units::meters> profile{
{1.75_mps, 0.75_mps_sq}}; {1.75_mps, 0.75_mps_sq}};
wpi::math::TrapezoidProfile<wpi::units::meters>::State m_goal; wpi::math::TrapezoidProfile<wpi::units::meters>::State goal;
wpi::math::TrapezoidProfile<wpi::units::meters>::State m_setpoint; wpi::math::TrapezoidProfile<wpi::units::meters>::State setpoint;
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -34,29 +34,29 @@ class Robot : public wpi::TimedRobot {
* On a quadrature encoder, values range from 1-255; larger values result in * On a quadrature encoder, values range from 1-255; larger values result in
* smoother but potentially less accurate rates than lower values. * 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 /* 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 * 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 * inch diameter (1.5inch radius) wheel, and that we want to measure
* distance in inches. * 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 /* Defines the lowest rate at which the encoder will not be considered
* stopped, for the purposes of the GetStopped() method. Units are in * stopped, for the purposes of the GetStopped() method. Units are in
* distance / second, where distance refers to the units of distance that * distance / second, where distance refers to the units of distance that
* you are using, in this case inches. * you are using, in this case inches.
*/ */
m_encoder.SetMinRate(1.0); encoder.SetMinRate(1.0);
} }
void TeleopPeriodic() override { void TeleopPeriodic() override {
// Retrieve the net displacement of the Encoder since the last Reset. // 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. // Retrieve the current rate of the encoder.
wpi::SmartDashboard::PutNumber("Encoder Rate", m_encoder.GetRate()); wpi::SmartDashboard::PutNumber("Encoder Rate", encoder.GetRate());
} }
private: private:
@@ -76,7 +76,7 @@ class Robot : public wpi::TimedRobot {
* and defaults to X4. Faster (X4) encoding gives greater positional * and defaults to X4. Faster (X4) encoding gives greater positional
* precision but more noise in the rate. * 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 #ifndef RUNNING_WPILIB_TESTS

View File

@@ -11,27 +11,27 @@
class Robot : public wpi::TimedRobot { class Robot : public wpi::TimedRobot {
public: public:
Robot() { Robot() {
wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_left); wpi::util::SendableRegistry::AddChild(&robotDrive, &left);
wpi::util::SendableRegistry::AddChild(&m_robotDrive, &m_right); wpi::util::SendableRegistry::AddChild(&robotDrive, &right);
// We need to invert one side of the drivetrain so that positive voltages // 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 // result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead. // gearbox is constructed, you might have to invert the left side instead.
m_right.SetInverted(true); right.SetInverted(true);
m_robotDrive.SetExpiration(100_ms); robotDrive.SetExpiration(100_ms);
m_timer.Start(); timer.Start();
} }
void AutonomousInit() override { m_timer.Restart(); } void AutonomousInit() override { timer.Restart(); }
void AutonomousPeriodic() override { void AutonomousPeriodic() override {
// Drive for 2 seconds // 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 // 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 { } else {
// Stop robot // 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 { void TeleopPeriodic() override {
// Drive with arcade style (use right stick to steer) // Drive with arcade style (use right stick to steer)
m_robotDrive.ArcadeDrive(-m_controller.GetLeftY(), robotDrive.ArcadeDrive(-controller.GetLeftY(), controller.GetRightX());
m_controller.GetRightX());
} }
void UtilityInit() override {} void UtilityInit() override {}
@@ -49,14 +48,14 @@ class Robot : public wpi::TimedRobot {
private: private:
// Robot drive system // Robot drive system
wpi::PWMSparkMax m_left{0}; wpi::PWMSparkMax left{0};
wpi::PWMSparkMax m_right{1}; wpi::PWMSparkMax right{1};
wpi::DifferentialDrive m_robotDrive{ wpi::DifferentialDrive robotDrive{
[&](double output) { m_left.SetThrottle(output); }, [&](double output) { left.SetThrottle(output); },
[&](double output) { m_right.SetThrottle(output); }}; [&](double output) { right.SetThrottle(output); }};
wpi::Gamepad m_controller{0}; wpi::Gamepad controller{0};
wpi::Timer m_timer; wpi::Timer timer;
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -21,10 +21,10 @@ class Robot : public wpi::TimedRobot {
// We need to invert one side of the drivetrain so that positive voltages // 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 // result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead. // 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(&drive, &left);
wpi::util::SendableRegistry::AddChild(&m_drive, &m_right); wpi::util::SendableRegistry::AddChild(&drive, &right);
} }
/** /**
@@ -34,8 +34,8 @@ class Robot : public wpi::TimedRobot {
*/ */
void TeleopPeriodic() override { void TeleopPeriodic() override {
double turningValue = double turningValue =
(kAngleSetpoint - m_imu.GetRotation2d().Degrees().value()) * kP; (kAngleSetpoint - imu.GetRotation2d().Degrees().value()) * kP;
m_drive.ArcadeDrive(-m_joystick.GetY(), -turningValue); drive.ArcadeDrive(-joystick.GetY(), -turningValue);
} }
private: private:
@@ -48,14 +48,14 @@ class Robot : public wpi::TimedRobot {
wpi::OnboardIMU::FLAT; wpi::OnboardIMU::FLAT;
static constexpr int kJoystickPort = 0; static constexpr int kJoystickPort = 0;
wpi::PWMSparkMax m_left{kLeftMotorPort}; wpi::PWMSparkMax left{kLeftMotorPort};
wpi::PWMSparkMax m_right{kRightMotorPort}; wpi::PWMSparkMax right{kRightMotorPort};
wpi::DifferentialDrive m_drive{ wpi::DifferentialDrive drive{
[&](double output) { m_left.SetThrottle(output); }, [&](double output) { left.SetThrottle(output); },
[&](double output) { m_right.SetThrottle(output); }}; [&](double output) { right.SetThrottle(output); }};
wpi::OnboardIMU m_imu{kIMUMountOrientation}; wpi::OnboardIMU imu{kIMUMountOrientation};
wpi::Joystick m_joystick{kJoystickPort}; wpi::Joystick joystick{kJoystickPort};
}; };
#ifndef RUNNING_WPILIB_TESTS #ifndef RUNNING_WPILIB_TESTS

View File

@@ -44,10 +44,10 @@ void Robot::DisabledPeriodic() {}
* RobotContainer} class. * RobotContainer} class.
*/ */
void Robot::AutonomousInit() { void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand(); autonomousCommand = container.GetAutonomousCommand();
if (m_autonomousCommand != nullptr) { if (autonomousCommand != nullptr) {
wpi::cmd::CommandScheduler::GetInstance().Schedule(m_autonomousCommand); wpi::cmd::CommandScheduler::GetInstance().Schedule(autonomousCommand);
} }
} }
@@ -58,9 +58,9 @@ void Robot::TeleopInit() {
// teleop starts running. If you want the autonomous to // teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove // continue until interrupted by another command, remove
// this line or comment it out. // this line or comment it out.
if (m_autonomousCommand != nullptr) { if (autonomousCommand != nullptr) {
m_autonomousCommand->Cancel(); autonomousCommand->Cancel();
m_autonomousCommand = nullptr; autonomousCommand = nullptr;
} }
} }

Some files were not shown because too many files have changed in this diff Show More