Skip to content

Commit 578308c

Browse files
Add API to get the applied current of a motor (#33)
* Add method to get the current of the motor * remove UnsupportedOperationException * fix javadoc * Documented that getAppliedCurrent will be there from 1.3.0 onwards * bump the version to 2.0.0-alpha.1 * update usages of since 1.3.0 to 2.0.0
1 parent 1109ede commit 578308c

6 files changed

Lines changed: 25 additions & 3 deletions

File tree

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tasks.withType(JavaCompile) {
2525
options.compilerArgs.add '-XDstringConcat=inline'
2626
}
2727

28-
version = '1.3.0-alpha.1'
28+
version = '2.0.0-alpha.1'
2929

3030
repositories {
3131
// Use Maven Central for resolving dependencies.

lib/src/main/java/com/team2813/lib2813/control/Motor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.team2813.lib2813.control;
22

3+
import edu.wpi.first.units.measure.Current;
4+
35
public interface Motor {
46
// motor control
57

@@ -19,4 +21,12 @@ public interface Motor {
1921
* @param feedForward The feedForward to apply to the motor
2022
*/
2123
void set(ControlMode mode, double demand, double feedForward);
24+
25+
/**
26+
* Gets the current that is being applied onto the motor
27+
*
28+
* @since 2.0.0
29+
* @return The current applied current
30+
*/
31+
Current getAppliedCurrent();
2232
}

lib/src/main/java/com/team2813/lib2813/control/motors/SparkMaxWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import edu.wpi.first.units.Units;
1717
import edu.wpi.first.units.measure.Angle;
1818
import edu.wpi.first.units.measure.AngularVelocity;
19+
import edu.wpi.first.units.measure.Current;
1920
import java.util.ArrayList;
2021
import java.util.List;
2122

@@ -75,6 +76,11 @@ public Angle getPositionMeasure() {
7576
return Units.Rotations.of(encoder.getPosition());
7677
}
7778

79+
@Override
80+
public Current getAppliedCurrent() {
81+
return Units.Amps.of(motor.getOutputCurrent());
82+
}
83+
7884
@Override
7985
public void setPosition(double position) {
8086
encoder.setPosition(position);

lib/src/main/java/com/team2813/lib2813/control/motors/TalonFXWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import edu.wpi.first.units.Units;
1818
import edu.wpi.first.units.measure.Angle;
1919
import edu.wpi.first.units.measure.AngularVelocity;
20+
import edu.wpi.first.units.measure.Current;
2021
import java.util.ArrayList;
2122
import java.util.List;
2223
import java.util.Objects;
@@ -132,6 +133,11 @@ public Angle getPositionMeasure() {
132133
return Units.Rotations.of(motor.getPosition().getValueAsDouble());
133134
}
134135

136+
@Override
137+
public Current getAppliedCurrent() {
138+
return motor.getStatorCurrent().getValue();
139+
}
140+
135141
@Override
136142
public void setPosition(double position) {
137143
motor.setPosition(position);

lib/src/main/java/com/team2813/lib2813/preferences/PersistedConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
* constructor; see <a href="https://www.baeldung.com/java-records-custom-constructor">Custom
9393
* Constructor in Java Records</a> for details.
9494
*
95-
* @since 1.3.0
95+
* @since 2.0.0
9696
*/
9797
public final class PersistedConfiguration {
9898
// The below package-scope fields are for the self-tests.

lib/src/main/java/com/team2813/lib2813/preferences/PreferencesInjector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @deprecated Use {@link PersistedConfiguration}
4040
*/
41-
@Deprecated(since = "1.3.0", forRemoval = true)
41+
@Deprecated(since = "2.0.0", forRemoval = true)
4242
public class PreferencesInjector {
4343
private static final char PATH_SEPARATOR = '.';
4444

0 commit comments

Comments
 (0)