41
41
import edu .wpi .first .units .Units ;
42
42
import edu .wpi .first .units .measure .Current ;
43
43
import edu .wpi .first .units .measure .Frequency ;
44
+ import edu .wpi .first .units .measure .MutCurrent ;
44
45
import edu .wpi .first .wpilibj .RobotBase ;
45
46
import edu .wpi .first .wpilibj .RobotController ;
46
47
import edu .wpi .first .wpilibj .Timer ;
@@ -120,6 +121,8 @@ public static class SparkInputs {
120
121
public double absoluteEncoderVelocity = 0.0 ;
121
122
public boolean forwardLimitSwitch = false ;
122
123
public boolean reverseLimitSwitch = false ;
124
+ public MutCurrent supplyCurrent = Units .Amps .zero ().mutableCopy ();
125
+ public MutCurrent statorCurrent = Units .Amps .zero ().mutableCopy ();
123
126
}
124
127
125
128
private static final String LOG_TAG = "Spark" ;
@@ -136,8 +139,6 @@ public static class SparkInputs {
136
139
private static final String ARB_FF_LOG_ENTRY = "/ArbitraryFF" ;
137
140
private static final String ARB_FF_UNITS_LOG_ENTRY = "/ArbitraryFFUnits" ;
138
141
private static final String IDLE_MODE_LOG_ENTRY = "/IdleMode" ;
139
- private static final String INPUT_CURRENT_LOG_ENTRY = "/InputCurrent" ;
140
- private static final String OUTPUT_CURRENT_LOG_ENTRY = "/OutputCurrent" ;
141
142
private static final String HEALTH_STATUS_LOG_ENTRY = "/IsHealthy" ;
142
143
private static final String TEMPERATURE_LOG_ENTRY = "/Temperature" ;
143
144
private static final ClosedLoopSlot PID_SLOT = ClosedLoopSlot .kSlot0 ;
@@ -346,6 +347,22 @@ private boolean getReverseLimitSwitch() {
346
347
return (RobotBase .isReal ()) ? m_spark .getReverseLimitSwitch ().isPressed () : m_sparkSim .getReverseLimitSwitchSim ().getPressed ();
347
348
}
348
349
350
+ /**
351
+ * Spark approximate supply current
352
+ * @return Supply current
353
+ */
354
+ private Current getSupplyCurrent () {
355
+ return getStatorCurrent ().times (m_spark .getAppliedOutput ());
356
+ }
357
+
358
+ /**
359
+ * Spark stator current
360
+ * @return stator current
361
+ */
362
+ private Current getStatorCurrent () {
363
+ return Units .Amps .of (m_spark .getOutputCurrent ());
364
+ }
365
+
349
366
/**
350
367
* Update sensor input readings
351
368
*/
@@ -359,6 +376,8 @@ protected void updateInputs() {
359
376
m_inputs .absoluteEncoderVelocity = getAbsoluteEncoderVelocity ();
360
377
m_inputs .forwardLimitSwitch = getForwardLimitSwitch ();
361
378
m_inputs .reverseLimitSwitch = getReverseLimitSwitch ();
379
+ m_inputs .supplyCurrent .mut_replace (getSupplyCurrent ());
380
+ m_inputs .statorCurrent .mut_replace (getStatorCurrent ());
362
381
363
382
// Get motor encoder
364
383
if (!getMotorType ().equals (MotorType .kBrushed )) {
@@ -371,9 +390,6 @@ protected void updateInputs() {
371
390
@ Override
372
391
protected void periodic () {
373
392
synchronized (m_inputs ) { Logger .processInputs (m_id .name , m_inputs ); }
374
-
375
- Logger .recordOutput (m_id .name + INPUT_CURRENT_LOG_ENTRY , getInputCurrent ());
376
- Logger .recordOutput (m_id .name + OUTPUT_CURRENT_LOG_ENTRY , getOutputCurrent ());
377
393
Logger .recordOutput (m_id .name + HEALTH_STATUS_LOG_ENTRY , isHealthy ());
378
394
379
395
if (getMotorType () == MotorType .kBrushed ) return ;
@@ -750,21 +766,6 @@ public REVLibError follow(Spark leader) {
750
766
}
751
767
}
752
768
753
- /**
754
- * Spark approximate input current
755
- * @return
756
- */
757
- public Current getInputCurrent () {
758
- return getOutputCurrent ().times (m_spark .getAppliedOutput ());
759
- }
760
-
761
- /**
762
- * Spark output current
763
- * @return Output current
764
- */
765
- public Current getOutputCurrent () {
766
- return Units .Amps .of (m_spark .getOutputCurrent ());
767
- }
768
769
769
770
/**
770
771
* Get applied output of Spark
0 commit comments