Skip to content

Commit

Permalink
Merge branch 'main' into 75-neojava-health-and-wellness-isFlex
Browse files Browse the repository at this point in the history
  • Loading branch information
GalexY727 authored Jan 28, 2024
2 parents 36dbdae + ed43196 commit 63afb23
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.util.Neo;
import frc.robot.util.Constants.AutoConstants;
import frc.robot.util.Constants.DriveConstants;
import frc.robot.util.Constants.FieldConstants;
import frc.robot.util.Constants.NeoMotorConstants;
import monologue.Monologue;

/**
Expand Down Expand Up @@ -41,7 +43,7 @@ public void robotInit() {
public void robotPeriodic() {
Monologue.updateAll();
CommandScheduler.getInstance().run();

DriverUI.previousTimestmap = DriverUI.currentTimestamp;
DriverUI.currentTimestamp = Timer.getFPGATimestamp();
}
Expand Down Expand Up @@ -114,5 +116,9 @@ public void simulationInit() { }
@Override
public void simulationPeriodic() {
REVPhysicsSim.getInstance().run();

for (Neo neo : NeoMotorConstants.motors) {
neo.tick();
}
}
}
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/Climb.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.util.Neo;
import frc.robot.util.Constants.ClimbConstants;
import frc.robot.util.Constants.FieldConstants;
import frc.robot.util.Constants.FieldConstants.ChainPosition;
import monologue.Logged;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/Intake.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.util.Neo;
import frc.robot.util.Constants.FieldConstants;
import frc.robot.util.Constants.IntakeConstants;

public class Intake extends SubsystemBase {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/frc/robot/subsystems/Shooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public void configMotors() {

}

@Override
public void periodic() {
// This method will be called once per scheduler run
}

public Command shoot(Pose2d position, boolean shootingAtSpeaker) {
SpeedAnglePair pair = calculateSpeed(position, shootingAtSpeaker);
return runOnce(() -> motorLeft.setTargetPercent(1));
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/frc/robot/subsystems/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ public void periodic() {

public void logPositions() {

if (FieldConstants.IS_SIMULATION) {
for (MAXSwerveModule mod : swerveModules) {
mod.tick();
}
}

swerveMeasuredStates = new SwerveModuleState[] {
frontLeft.getState(), frontRight.getState(), rearLeft.getState(), rearRight.getState()
};
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/frc/robot/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ 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 ArrayList<CANSparkBase> motors = new ArrayList<>();
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<>();
}

public static final class IntakeConstants {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/frc/robot/util/MAXSwerveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ public void setBrakeMode() {
turningSpark.setIdleMode(CANSparkBase.IdleMode.kBrake);
}

public void tick() {
drivingSpark.tick();
turningSpark.tick();
}

public void configMotors() {
turningSpark.restoreFactoryDefaults();
drivingSpark.restoreFactoryDefaults();
Expand Down
58 changes: 55 additions & 3 deletions src/main/java/frc/robot/util/Neo.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ public REVLibError resetStatusFrame(StatusFrame frame) {
public enum StatusFrame {
APPLIED_FAULTS_FOLLOWER(PeriodicFrame.kStatus0, 10),
VELO_TEMP_VOLTAGE_CURRENT(PeriodicFrame.kStatus1, 20),
MOTOR_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 @@ -548,4 +548,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 63afb23

Please sign in to comment.