Skip to content

Commit

Permalink
Update library, styleguide versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger committed Jul 6, 2024
1 parent 007cf9c commit 6628b14
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 43 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
plugins {
id 'java'
id 'edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin' version '2020.2'
id 'com.github.spotbugs' version '5.1.3' apply false
id 'com.github.spotbugs' version '6.0.2' apply false
id 'com.diffplug.spotless' version '6.20.0' apply false
}

import com.github.spotbugs.snom.Effort
ext.spotbugsEffort = Effort.MAX

repositories {
mavenCentral()
}
Expand Down
8 changes: 4 additions & 4 deletions build_scripts/base_java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ ext.getCurrentOs = {
}

ext {
wpiVersion = '2024.1.1'
wpiVersion = '2024.3.2'
opencvYear = '2024'
opencvVersion = '4.8.0-1'
phoenix5Version = '5.32.0-beta-5'
phoenix6Version = "24.0.0-beta-8"
revVersion = '2024.2.0'
phoenix5Version = '5.33.1'
phoenix6Version = "24.3.0"
revVersion = '2024.2.4'
navxVersion = '2024.1.0'

nativeOs = getCurrentOs() + getCurrentArch()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.snobotv2.examples.base;

@SuppressWarnings("PMD.DataClass")
public class BaseConstants
{
// PWM / CAN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Command createWithVoltage(DrivetrainSubsystem drivetrain, Trajecto
drivetrain);


Command runThenStop = ramseteCommand.andThen(() -> drivetrain.stop());
Command runThenStop = ramseteCommand.andThen(drivetrain::stop);

if (resetOnStart)
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public static Command createWithVelocity(DrivetrainSubsystem drivetrain, Traject
drivetrain);


Command runThenStop = ramseteCommand.andThen(() -> drivetrain.stop());
Command runThenStop = ramseteCommand.andThen(drivetrain::stop);

if (resetOnStart)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class TurnToAngle extends PIDCommand
{
@SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
public TurnToAngle(DrivetrainSubsystem drivetrain, double goal)
{
super(new PIDController(.02, 0, 0.001),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ final class CimDrivetrainConstants implements DrivetrainConstants
public static final DifferentialDriveKinematics kDriveKinematics =
new DifferentialDriveKinematics(kTrackwidthMeters);


public CimDrivetrainConstants()
{
}

@Override
public DifferentialDrivetrainSim createSim()
{
Expand Down Expand Up @@ -170,10 +165,6 @@ public DifferentialDrivetrainSim createSim()
null);
}

public NeoDrivetrainConstants()
{
}

@Override
public double getGearing()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ final class ElevatorSimConstants
public static ElevatorSim createSim()
{
return new ElevatorSim(
ElevatorSimConstants.kElevatorGearbox,
ElevatorSimConstants.kElevatorGearing,
ElevatorSimConstants.kCarriageMass,
ElevatorSimConstants.kElevatorDrumRadius,
ElevatorSimConstants.kMinElevatorHeight,
ElevatorSimConstants.kMaxElevatorHeight,
kElevatorGearbox,
kElevatorGearing,
kCarriageMass,
kElevatorDrumRadius,
kMinElevatorHeight,
kMaxElevatorHeight,
true,
0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public void periodic()
private void rainbow()
{
// For every pixel
for (var i = 0; i < mLedBuffer.getLength(); i++)
for (int i = 0; i < mLedBuffer.getLength(); i++)
{
// Calculate the hue - hue is easier for rainbows because the color
// shape is a circle so only one value needs to precess
final var hue = (mRainbowFirstPixelHue + (i * 180 / mLedBuffer.getLength())) % 180;
final int hue = (mRainbowFirstPixelHue + (i * 180 / mLedBuffer.getLength())) % 180;
// Set the value
mLedBuffer.setHSV(i, hue, 255, 128);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class FlywheelSimConstants

public static FlywheelSim createSim()
{
return new FlywheelSim(FlywheelSimConstants.kGearbox, FlywheelSimConstants.kGearing, FlywheelSimConstants.kInertia);
return new FlywheelSim(kGearbox, kGearing, kInertia);
}

private FlywheelSimConstants()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

public final class TrajectoryFactory
{
@SuppressWarnings("PMD.DataClass")
public static final class AutoConstants
{
public static final double kMaxSpeedMetersPerSecond = 3;
Expand Down Expand Up @@ -95,7 +96,7 @@ public static Trajectory createControlPanelToSecondShot(DrivetrainSubsystem.Driv
public static TrajectoryConfig getTrajectoryConfig(DrivetrainSubsystem.DrivetrainConstants drivetrainConstants)
{
// Create a voltage constraint to ensure we don't accelerate too fast
var autoVoltageConstraint =
DifferentialDriveVoltageConstraint autoVoltageConstraint =
new DifferentialDriveVoltageConstraint(
new SimpleMotorFeedforward(
drivetrainConstants.getKsVolts(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.snobotv2.examples.base_swerve;

@SuppressWarnings("PMD.DataClass")
public class Constants
{
public static final int FRONT_LEFT_DRIVE_MOTOR_PORT = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public void initSendable(SendableBuilder builder)
builder.setSmartDashboardType("SwerveDrive");
for (BaseSwerveModule module : mModules) // NOPMD(CloseResource)
{
builder.addDoubleProperty(module.getName() + "/CurrentStateAngle", () -> module.getState().angle.getDegrees(), null);
builder.addDoubleProperty(module.getName() + "/CurrentStateAngle", module.getState().angle::getDegrees, null);
builder.addDoubleProperty(module.getName() + "/CurrentStateSpeed", () -> module.getState().speedMetersPerSecond, null);
builder.addDoubleProperty(module.getName() + "/DesiredStateAngle", () -> module.getDesiredState().angle.getDegrees(), null);
builder.addDoubleProperty(module.getName() + "/DesiredStateAngle", module.getDesiredState().angle::getDegrees, null);
builder.addDoubleProperty(module.getName() + "/DesiredStateSpeed", () -> module.getDesiredState().speedMetersPerSecond, null);
builder.addDoubleProperty(module.getName() + "/DrivePercentage", module::getDriveMotorPercentage, null);
builder.addDoubleProperty(module.getName() + "/TurningPercentage", module::getTurningMotorPercentage, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
public interface BaseSwerveModule extends Sendable, AutoCloseable
{
// MK4i - L1
@SuppressWarnings("PMD.UselessParentheses")
double TURNING_GEAR_RATION = (50.0 / 14.0) * (60.0 / 10.0);
@SuppressWarnings("PMD.UselessParentheses")
double DRIVE_GEAR_RATION = (50.0 / 14.0) * (19.0 / 25.0) * (45.0 / 15.0);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.snobotv2.test_utils.BaseUnitTest;


@SuppressWarnings("PMD.TestClassWithoutTestCases")
public class BasePhoenix5UnitTest extends BaseUnitTest
{
protected void ctreSimLoop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public static double falconToRpm(double velocityCounts, double gearRatio)

public static double mpsToFalcon(double velocity, double circumference, double gearRatio)
{
double wheelRPM = (velocity * 60) / circumference;
double wheelRPM = velocity * 60 / circumference;
return rpmToFalcon(wheelRPM, gearRatio);
}

public static double falconToMps(double velocityCounts, double circumference, double gearRatio)
{
double wheelRPM = falconToRpm(velocityCounts, gearRatio);
return (wheelRPM * circumference) / 60;
return wheelRPM * circumference / 60;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void initSendable(SendableBuilder builder)
builder.addDoubleProperty("MotorAngle", () -> getTurningMotorAngle().getDegrees(), null);

builder.addDoubleProperty("TurnTicks", mAzimuthMotor::getSelectedSensorPosition, null);
builder.addDoubleProperty("TurnGoalDegrees", () -> mDesiredState.angle.getDegrees(), null);
builder.addDoubleProperty("TurnGoalDegrees", mDesiredState.angle::getDegrees, null);
builder.addDoubleProperty("TurnGoalTicks", () -> mTurnGoalTicks, null);

builder.addDoubleProperty("DriveVelTicks", mDriveMotor::getSelectedSensorVelocity, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class RevDrivetrain extends BaseDrivetrainSubsystem
{
private static final DrivetrainConstants DRIVETRAIN_CONSTANTS = new NeoDrivetrainConstants();
private static final double ENCODER_CONSTANT = (1.0 / DRIVETRAIN_CONSTANTS.getGearing()) * DRIVETRAIN_CONSTANTS.getkWheelDiameterMeters() * Math.PI;
private static final double ENCODER_CONSTANT = 1.0 / DRIVETRAIN_CONSTANTS.getGearing() * DRIVETRAIN_CONSTANTS.getkWheelDiameterMeters() * Math.PI;

private final SimableCANSparkMax mLeadLeft; // NOPMD
private final SimableCANSparkMax mFollowerLeft; // NOPMD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class SwerveModule implements BaseSwerveModule
{
private static final double DRIVE_ENCODER_CONSTANT = (1.0 / DRIVE_GEAR_RATION) * DriveSubsystem.kWheelCircumfranceMeters;
private static final double DRIVE_ENCODER_CONSTANT = 1.0 / DRIVE_GEAR_RATION * DriveSubsystem.kWheelCircumfranceMeters;

private static final double DEFAULT_FF = 0.34;
private static final double DEFAULT_P = 0.001;
Expand Down Expand Up @@ -210,7 +210,7 @@ public void initSendable(SendableBuilder builder)
builder.addDoubleProperty("MotorAngle", () -> getTurningMotorAngle().getDegrees(), null);

builder.addDoubleProperty("TurnDegrees", mAzimuthEncoder::getPosition, null);
builder.addDoubleProperty("TurnGoalDegrees", () -> mDesiredState.angle.getDegrees(), null);
builder.addDoubleProperty("TurnGoalDegrees", mDesiredState.angle::getDegrees, null);

builder.addDoubleProperty("DriveMps", mDriveEncoder::getVelocity, null);
builder.addDoubleProperty("DriveGoalMps", () -> mDesiredState.speedMetersPerSecond, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public static void dumpSimDevices()
builder.append("***************************************************\nDumping devices:\n");
for (SimDeviceInfo deviceInfo : SimDeviceSim.enumerateDevices(""))
{
builder.append("Got a device: \n");
builder.append(" ").append(deviceInfo.name).append('\n');
builder.append("Got a device: \n").append(" ").append(deviceInfo.name).append('\n');
for (SimDeviceDataJNI.SimValueInfo valueInfo : SimDeviceDataJNI.enumerateSimValues(deviceInfo.handle))
{
builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BaseRamseteCoordinateGuiCommand(
@Override
public void initialize() {
m_prevTime = -1;
var initialState = m_trajectory.sample(0);
Trajectory.State initialState = m_trajectory.sample(0);
m_prevSpeeds =
m_kinematics.toWheelSpeeds(
new ChassisSpeeds(
Expand All @@ -90,7 +90,7 @@ public void execute() {
double dt = curTime - m_prevTime;
Pose2d pose = getPose();

var targetWheelSpeeds =
DifferentialDriveWheelSpeeds targetWheelSpeeds =
m_kinematics.toWheelSpeeds(
m_follower.calculate(pose, m_trajectory.sample(curTime)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public class BasePhoenix5UnitTest extends BaseUnitTest
{
protected void ctreSimLoop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.wpi.first.hal.HAL;
import org.snobotv2.test_utils.BaseUnitTest;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public class BasePhoenix6UnitTest extends BaseUnitTest
{
protected void ctreSimLoop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
public class SparkSimHelper
{
private static final Logger LOGGER = Logger.getLogger(SparkSimHelper.class.getName());
Expand Down Expand Up @@ -92,6 +92,7 @@ public void reset()
}
}

@SuppressWarnings("PMD.NullAssignment")
public SparkSimHelper(SimDeviceSim deviceSim, CANSparkBase sparkMax, long sparkMaxHandle)
{
mSparkMaxHandle = sparkMaxHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public class BaseRevlibUnitTest extends BaseUnitTest
{
@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public class BaseUnitTest
{
protected static final double DEFAULT_EPSILON = 1e-3;
Expand Down
7 changes: 6 additions & 1 deletion styleguide/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<!-- temp -->
<exclude-pattern>.*/edu/wpi/first/.*</exclude-pattern>

<rule ref="category/java/bestpractices.xml/LooseCoupling">
<properties>
<property name="allowedTypes" value="java.util.TreeMap" />
</properties>
</rule>

<rule ref="category/java/bestpractices.xml">
<exclude name="GuardLogStatement" />
<exclude name="JUnitTestsShouldIncludeAssert" />
Expand Down Expand Up @@ -84,7 +90,6 @@
<!-- <exclude name="AvoidCatchingThrowable" /> -->
<!-- <exclude name="AvoidDuplicateLiterals" /> -->
<!-- <exclude name="AvoidLiteralsInIfCondition" /> -->
<exclude name="BeanMembersShouldSerialize" />
<!-- <exclude name="ConstructorCallsOverridableMethod" /> -->
<!-- <exclude name="DataflowAnomalyAnalysis" /> -->
<!-- <exclude name="DoNotCallSystemExit" /> -->
Expand Down
7 changes: 4 additions & 3 deletions styleguide/styleguide.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ jacocoTestReport {


checkstyle {
toolVersion = "10.1"
toolVersion = "10.12.2"
configDirectory = file("${project.rootDir}/styleguide")
config = resources.text.fromFile(new File(configDirectory.get().getAsFile(), "checkstyle.xml"))
}

pmd {
toolVersion = '6.39.0'
toolVersion = '7.3.0'
consoleOutput = true
reportsDir = file("${project.buildDir}/reports/pmd")
ruleSetFiles = files(file("$rootDir/styleguide/pmd-ruleset.xml"))
ruleSets = []
}


spotbugs {
toolVersion = '4.7.3'
excludeFilter = file("$rootDir/styleguide/findbugs_suppressions.xml")
effort = "max"
effort = spotbugsEffort
}

spotbugsMain {
Expand Down

0 comments on commit 6628b14

Please sign in to comment.