Skip to content

Commit

Permalink
Use magnet health for CANcoder health status
Browse files Browse the repository at this point in the history
  • Loading branch information
viggy96 committed Dec 30, 2024
1 parent 536fe83 commit dc4c820
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/lasarobotics/hardware/ctre/CANcoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.ctre.phoenix6.StatusCode;
import com.ctre.phoenix6.configs.CANcoderConfiguration;
import com.ctre.phoenix6.configs.CANcoderConfigurator;
import com.ctre.phoenix6.signals.MagnetHealthValue;
import com.ctre.phoenix6.sim.CANcoderSimState;

import edu.wpi.first.units.Units;
Expand Down Expand Up @@ -150,6 +151,11 @@ public CANcoderInputsAutoLogged getInputs() {
synchronized (m_inputs) { return m_inputs; }
}

@Override
public boolean isHealthy() {
return getMagnetHealth().equals(MagnetHealthValue.Magnet_Green);
}

/**
* Get device ID
* @return Device ID
Expand Down Expand Up @@ -208,6 +214,21 @@ public CANcoderSimState getSimState() {
return m_canCoder.getSimState();
}

/**
* Magnet health as measured by CANcoder.
* <p>
* Red indicates too close or too far, Orange is adequate but with
* reduced accuracy, green is ideal. Invalid means the accuracy cannot
* be determined.
*
* This refreshes and returns a cached object.
*
* @return MagnetHealth Object
*/
public MagnetHealthValue getMagnetHealth() {
return m_canCoder.getMagnetHealth().getValue();
}

/**
* Sets the period of the given status frame.
*
Expand Down

0 comments on commit dc4c820

Please sign in to comment.