Skip to content

Commit

Permalink
fixed is motion magic flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PGgit08 committed Feb 8, 2025
1 parent 08728e5 commit cea76c9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/frc/robot/subsystems/Wristevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public class Wristevator extends AdvancedSubsystem {
private final DynamicMotionMagicVoltage _angleSetter =
new DynamicMotionMagicVoltage(HOME.getAngle().in(Rotations), 0, 0, 0);

private final StatusSignal<MotionMagicIsRunningValue> _isMotionMagic =
_leftMotor.getMotionMagicIsRunning();
@Logged(name = "Is Motion Magic")
private boolean _isMotionMagic = false;

private final StatusSignal<Double> _elevatorReference = _leftMotor.getClosedLoopReference();
private final StatusSignal<Double> _elevatorReferenceSlope =
Expand Down Expand Up @@ -329,7 +329,12 @@ private double distance(Setpoint b) {

// refresh the references of the talonfx profiles
private void refreshProfileReferences() {
if (_isMotionMagic.getValue() == MotionMagicIsRunningValue.Disabled) return;
_isMotionMagic =
_leftMotor.getMotionMagicIsRunning().getValue() == MotionMagicIsRunningValue.Enabled
&& _wristMotor.getMotionMagicIsRunning().getValue()
== MotionMagicIsRunningValue.Enabled;

if (!_isMotionMagic) return;

BaseStatusSignal.refreshAll(
_elevatorReference, _elevatorReferenceSlope, _wristReference, _wristReferenceSlope);
Expand Down Expand Up @@ -458,7 +463,7 @@ public Command setGoal(Setpoint goal) {

refreshProfileReferences();

if (_isManual) _isManual = false;
if (_isMotionMagic) _isManual = false;

// once the next setpoint is reached, re-find the next one
if (finishedProfiles(_nextSetpoint)) {
Expand Down Expand Up @@ -514,11 +519,11 @@ public Command setSpeeds(DoubleSupplier elevatorSpeed, DoubleSupplier wristSpeed
public void periodic() {
super.periodic();

_isMotionMagic.refresh();
_isMotionMagic =
_leftMotor.getMotionMagicIsRunning().getValue() == MotionMagicIsRunningValue.Enabled
&& _wristMotor.getMotionMagicIsRunning().getValue()
== MotionMagicIsRunningValue.Enabled;

DogLog.log(
"Wristevator/Is Motion Magic",
_isMotionMagic.getValue() == MotionMagicIsRunningValue.Enabled);
DogLog.log(
"Wristevator/Elevator Reference",
Units.rotationsToRadians(_elevatorReference.getValueAsDouble()));
Expand Down

0 comments on commit cea76c9

Please sign in to comment.