Skip to content

Commit

Permalink
71 neosettypeneotype type (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
GalexY727 authored Jan 27, 2024
2 parents 552f6a9 + 71f0548 commit ed43196
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ public static final class NeoMotorConstants {
public static final double VORTEX_FREE_SPEED_RPM = 6784;
public static final double NEO_FREE_SPEED_RPM = 5676;

public static final int MAX_PERIODIC_STATUS_TIME_MS = 65535;
public static final int FAST_PERIODIC_STATUS_TIME_MS = 10;

public static ArrayList<Neo> motors = new ArrayList<>();
}

Expand Down
60 changes: 56 additions & 4 deletions src/main/java/frc/robot/util/Neo.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ public REVLibError resetStatusFrame(StatusFrame frame) {
public enum StatusFrame {
APPLIED_FAULTS_FOLLOWER(PeriodicFrame.kStatus0, 10),
VELO_TEMP_VOLTAGE_CURRENT(PeriodicFrame.kStatus1, 20),
POSITION(PeriodicFrame.kStatus2, 20),
ANALOG_VOLTAGE_VELO_POS(PeriodicFrame.kStatus3, 50),
ALTERNATE_VELO_POS(PeriodicFrame.kStatus4, 20),
ENCODER_POSITION(PeriodicFrame.kStatus2, 20),
ALL_ANALOG_ENCODER(PeriodicFrame.kStatus3, 50),
ALL_ALTERNATE_ENCODER(PeriodicFrame.kStatus4, 20),
ABSOLUTE_ENCODER_POS(PeriodicFrame.kStatus5, 200),
ABSOLUTE_ENCODER_VELO(PeriodicFrame.kStatus6, 200);

Expand Down Expand Up @@ -345,4 +345,56 @@ public void setBrakeMode() {
public void setCoastMode() {
this.setIdleMode(CANSparkBase.IdleMode.kBrake);
}
}

public enum TelemtryPreference {
ONLY_ABSOLUTE_ENCODER,
ONLY_RELATIVE_ENCODER,
NO_TELEMETRY,
NO_ENCODER
}

/**
* Set the telemetry preference of the Neo
* This will disable the telemtry status frames
* which is found at https://docs.revrobotics.com/sparkmax/operating-modes/control-interfaces#periodic-status-frames
* @param type the enum to represent the telemetry preference
* this will tell the motor to only send
* that type of telemtry
*/
public void setTelemetryPreference(TelemtryPreference type) {
final int maxDelay = NeoMotorConstants.MAX_PERIODIC_STATUS_TIME_MS;
final int minDelay = NeoMotorConstants.FAST_PERIODIC_STATUS_TIME_MS;

// No matter what preference, we don't use analog or external encoders.
changeStatusFrame(StatusFrame.ALL_ALTERNATE_ENCODER, maxDelay);
changeStatusFrame(StatusFrame.ALL_ANALOG_ENCODER, maxDelay);

switch(type) {
// Disable all telemetry that is unrelated to the encoder
case NO_ENCODER:
changeStatusFrame(StatusFrame.ENCODER_POSITION, maxDelay);
changeStatusFrame(StatusFrame.ALL_ANALOG_ENCODER, maxDelay);
changeStatusFrame(StatusFrame.ABSOLUTE_ENCODER_VELO, maxDelay);
break;
// Disable all telemetry that is unrelated to absolute encoders
case ONLY_ABSOLUTE_ENCODER:
changeStatusFrame(StatusFrame.VELO_TEMP_VOLTAGE_CURRENT, maxDelay);
changeStatusFrame(StatusFrame.ENCODER_POSITION, maxDelay);
changeStatusFrame(StatusFrame.ABSOLUTE_ENCODER_POS, minDelay);
changeStatusFrame(StatusFrame.ABSOLUTE_ENCODER_VELO, minDelay);
break;
// Disable all telemetry that is unrelated to the relative encoder
case ONLY_RELATIVE_ENCODER:
changeStatusFrame(StatusFrame.ALL_ANALOG_ENCODER, maxDelay);
changeStatusFrame(StatusFrame.ABSOLUTE_ENCODER_VELO, maxDelay);
break;
// Disable everything
case NO_TELEMETRY:
changeStatusFrame(StatusFrame.VELO_TEMP_VOLTAGE_CURRENT, maxDelay);
changeStatusFrame(StatusFrame.ENCODER_POSITION, maxDelay);
changeStatusFrame(StatusFrame.ALL_ANALOG_ENCODER, maxDelay);
changeStatusFrame(StatusFrame.ABSOLUTE_ENCODER_VELO, maxDelay);
break;
}
}
}

0 comments on commit ed43196

Please sign in to comment.