Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

71 neosettypeneotype type #77

Merged
merged 4 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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<CANSparkBase> 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the following: should "pos" and "velo" be used here or should it be "position" and "velocity"?


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

public enum TelemtryPreference {
ABSOLUTE_ENCODER,
RELATIVE_ENCODER,
NO_TELEMETRY,
NO_ENCODER
}
derp00monsta marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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 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 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;
}
}
}
Loading