From ae4a53dcea34d6144beed2625688e7e8842053f7 Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Wed, 11 Mar 2026 15:04:08 -0400 Subject: [PATCH] Adding the beginning of CommonPIDFConfig --- .../commons/CommonMotorControllerConfig.java | 55 +++++++- .../iocore/commons/CommonPIDFConfig.java | 123 ++++++++++++++++++ .../team2648/iocore/enums/MotorIdleMode.java | 6 + 3 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/team2648/iocore/commons/CommonPIDFConfig.java create mode 100644 src/main/java/com/team2648/iocore/enums/MotorIdleMode.java diff --git a/src/main/java/com/team2648/iocore/commons/CommonMotorControllerConfig.java b/src/main/java/com/team2648/iocore/commons/CommonMotorControllerConfig.java index baee5a2..c04499f 100644 --- a/src/main/java/com/team2648/iocore/commons/CommonMotorControllerConfig.java +++ b/src/main/java/com/team2648/iocore/commons/CommonMotorControllerConfig.java @@ -1,28 +1,79 @@ package com.team2648.iocore.commons; import com.revrobotics.spark.config.SparkMaxConfig; +import com.revrobotics.spark.config.SparkBaseConfig.IdleMode; +import com.team2648.iocore.enums.MotorIdleMode; public class CommonMotorControllerConfig { private boolean isInverted; - public CommonMotorControllerConfig() { + private int supplyCurrentLimit; + private int followCANID; + private MotorIdleMode mode; + + + public CommonMotorControllerConfig() { + isInverted = false; + supplyCurrentLimit = -1; + followCANID = -1; + mode = MotorIdleMode.kCoast; } public boolean isInverted() { return isInverted; } + public int getSupplyCurrentLimit() { + return supplyCurrentLimit; + } + + public int getFollowCANID() { + return followCANID; + } + + public MotorIdleMode getIdleMode() { + return mode; + } + public CommonMotorControllerConfig setInverted(boolean inverted) { this.isInverted = inverted; return this; } + public CommonMotorControllerConfig setSupplyCurrentLimit(int supplyCurrentLimit) { + this.supplyCurrentLimit = supplyCurrentLimit; + + return this; + } + + public CommonMotorControllerConfig setFollowCANID(int followCANID) { + this.followCANID = followCANID; + + return this; + } + + public CommonMotorControllerConfig setIdleMode(MotorIdleMode mode) { + this.mode = mode; + + return this; + } + public SparkMaxConfig getAsSparkMaxConfig() { // TODO More config SparkMaxConfig config = new SparkMaxConfig(); - config.inverted(isInverted); + config.inverted(isInverted) + .idleMode(mode == MotorIdleMode.kCoast ? IdleMode.kCoast : IdleMode.kBrake); + + if(supplyCurrentLimit > 0) { + config.smartCurrentLimit(supplyCurrentLimit); + } + + if(followCANID >= 0) { + config.follow(followCANID); + } + return config; } } diff --git a/src/main/java/com/team2648/iocore/commons/CommonPIDFConfig.java b/src/main/java/com/team2648/iocore/commons/CommonPIDFConfig.java new file mode 100644 index 0000000..045ec61 --- /dev/null +++ b/src/main/java/com/team2648/iocore/commons/CommonPIDFConfig.java @@ -0,0 +1,123 @@ +package com.team2648.iocore.commons; + +public class CommonPIDFConfig { + private double p; + private double i; + private double d; + private double s; + private double v; + private double a; + private double cos; + + public CommonPIDFConfig() { + this(0, 0, 0); + } + + public CommonPIDFConfig(double p, double i, double d) { + this(p, i, d, 0); + } + + public CommonPIDFConfig(double p, double i, double d, double v) { + this(p, i, d, 0, v, 0); + } + + public CommonPIDFConfig(double p, double i, double d, double s, double v, double a) { + this(p, i, d, s, v, a, 0); + } + + public CommonPIDFConfig(double p, double i, double d, double s, double v, double a, double cos) { + this.p = p; + this.i = i; + this.d = d; + this.s = s; + this.v = v; + this.a = a; + this.cos = cos; + } + + public double getP() { + return p; + } + + public double getI() { + return i; + } + + public double getD() { + return d; + } + + public double getS() { + return s; + } + + public double getV() { + return v; + } + + public double getA() { + return a; + } + + public double getCos() { + return cos; + } + + public CommonPIDFConfig setP(double p) { + this.p = p; + + return this; + } + + public CommonPIDFConfig setI(double i) { + this.i = i; + + return this; + } + + public CommonPIDFConfig setD(double d) { + this.d = d; + + return this; + } + + public CommonPIDFConfig setS(double s) { + this.s = s; + + return this; + } + + public CommonPIDFConfig setV(double v) { + this.v = v; + + return this; + } + + public CommonPIDFConfig setA(double a) { + this.a = a; + + return this; + } + + public CommonPIDFConfig setCos(double cos) { + this.cos = cos; + + return this; + } + + public CommonPIDFConfig setPID(double p, double i, double d) { + this.p = p; + this.i = i; + this.d = d; + + return this; + } + + public CommonPIDFConfig setSVA(double s, double v, double a) { + this.s = s; + this.v = v; + this.a = a; + + return this; + } +} diff --git a/src/main/java/com/team2648/iocore/enums/MotorIdleMode.java b/src/main/java/com/team2648/iocore/enums/MotorIdleMode.java new file mode 100644 index 0000000..1c20f55 --- /dev/null +++ b/src/main/java/com/team2648/iocore/enums/MotorIdleMode.java @@ -0,0 +1,6 @@ +package com.team2648.iocore.enums; + +public enum MotorIdleMode { + kCoast, + kBrake; +}