4141import edu .wpi .first .units .Units ;
4242import edu .wpi .first .units .measure .Current ;
4343import edu .wpi .first .units .measure .Frequency ;
44+ import edu .wpi .first .units .measure .MutCurrent ;
4445import edu .wpi .first .wpilibj .RobotBase ;
4546import edu .wpi .first .wpilibj .RobotController ;
4647import edu .wpi .first .wpilibj .Timer ;
@@ -120,6 +121,8 @@ public static class SparkInputs {
120121 public double absoluteEncoderVelocity = 0.0 ;
121122 public boolean forwardLimitSwitch = false ;
122123 public boolean reverseLimitSwitch = false ;
124+ public MutCurrent supplyCurrent = Units .Amps .zero ().mutableCopy ();
125+ public MutCurrent statorCurrent = Units .Amps .zero ().mutableCopy ();
123126 }
124127
125128 private static final String LOG_TAG = "Spark" ;
@@ -136,8 +139,6 @@ public static class SparkInputs {
136139 private static final String ARB_FF_LOG_ENTRY = "/ArbitraryFF" ;
137140 private static final String ARB_FF_UNITS_LOG_ENTRY = "/ArbitraryFFUnits" ;
138141 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" ;
141142 private static final String HEALTH_STATUS_LOG_ENTRY = "/IsHealthy" ;
142143 private static final String TEMPERATURE_LOG_ENTRY = "/Temperature" ;
143144 private static final ClosedLoopSlot PID_SLOT = ClosedLoopSlot .kSlot0 ;
@@ -346,6 +347,22 @@ private boolean getReverseLimitSwitch() {
346347 return (RobotBase .isReal ()) ? m_spark .getReverseLimitSwitch ().isPressed () : m_sparkSim .getReverseLimitSwitchSim ().getPressed ();
347348 }
348349
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+
349366 /**
350367 * Update sensor input readings
351368 */
@@ -359,6 +376,8 @@ protected void updateInputs() {
359376 m_inputs .absoluteEncoderVelocity = getAbsoluteEncoderVelocity ();
360377 m_inputs .forwardLimitSwitch = getForwardLimitSwitch ();
361378 m_inputs .reverseLimitSwitch = getReverseLimitSwitch ();
379+ m_inputs .supplyCurrent .mut_replace (getSupplyCurrent ());
380+ m_inputs .statorCurrent .mut_replace (getStatorCurrent ());
362381
363382 // Get motor encoder
364383 if (!getMotorType ().equals (MotorType .kBrushed )) {
@@ -371,9 +390,6 @@ protected void updateInputs() {
371390 @ Override
372391 protected void periodic () {
373392 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 ());
377393 Logger .recordOutput (m_id .name + HEALTH_STATUS_LOG_ENTRY , isHealthy ());
378394
379395 if (getMotorType () == MotorType .kBrushed ) return ;
@@ -750,21 +766,6 @@ public REVLibError follow(Spark leader) {
750766 }
751767 }
752768
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- }
768769
769770 /**
770771 * Get applied output of Spark
0 commit comments