-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/SFUnity/Mayhem-2024-Offseason
- Loading branch information
Showing
7 changed files
with
131 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2021-2024 FRC 6328 | ||
// http://github.com/Mechanical-Advantage | ||
// | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License | ||
// version 3 as published by the Free Software Foundation or | ||
// available in the root directory of this project. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
package frc.robot.subsystems.drive; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface GyroIO { | ||
@AutoLog | ||
public static class GyroIOInputs { | ||
public boolean connected = false; // instantiated as false bc | ||
// https://www.chiefdelphi.com/t/frc-6328-mechanical-advantage-2024-build-thread/442736 | ||
public Rotation2d yawPosition = new Rotation2d(); | ||
public double yawVelocityRadPerSec = 0.0; | ||
} | ||
|
||
public default void updateInputs(GyroIOInputs inputs) {} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/frc/robot/subsystems/drive/GyroIOPigeon2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2021-2024 FRC 6328 | ||
// http://github.com/Mechanical-Advantage | ||
// | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License | ||
// version 3 as published by the Free Software Foundation or | ||
// available in the root directory of this project. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
package frc.robot.subsystems.drive; | ||
|
||
import com.ctre.phoenix6.BaseStatusSignal; | ||
import com.ctre.phoenix6.StatusCode; | ||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.Pigeon2Configuration; | ||
import com.ctre.phoenix6.hardware.Pigeon2; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.util.Units; | ||
|
||
/** IO implementation for Pigeon2 */ | ||
public class GyroIOPigeon2 implements GyroIO { | ||
private final Pigeon2 pigeon = new Pigeon2(20); | ||
private final StatusSignal<Double> yaw = pigeon.getYaw(); | ||
private final StatusSignal<Double> yawVelocity = pigeon.getAngularVelocityZWorld(); | ||
|
||
public GyroIOPigeon2() { | ||
pigeon.getConfigurator().apply(new Pigeon2Configuration()); | ||
pigeon.getConfigurator().setYaw(0.0); | ||
yaw.setUpdateFrequency(100.0); | ||
yawVelocity.setUpdateFrequency(100.0); | ||
pigeon.optimizeBusUtilization(); | ||
} | ||
|
||
@Override | ||
public void updateInputs(GyroIOInputs inputs) { | ||
inputs.connected = BaseStatusSignal.refreshAll(yaw, yawVelocity).equals(StatusCode.OK); | ||
inputs.yawPosition = Rotation2d.fromDegrees(yaw.getValueAsDouble()); | ||
inputs.yawVelocityRadPerSec = Units.degreesToRadians(yawVelocity.getValueAsDouble()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package frc.robot.util; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public abstract class GeneralUtil { | ||
public static void logSubsystem(SubsystemBase s, String sName) { | ||
String key = sName + "/command"; | ||
Logger.recordOutput( | ||
key, s.getCurrentCommand() != null ? s.getCurrentCommand().getName() : "none"); | ||
} | ||
|
||
public static void logFullSubsystem(SubsystemBase s, String sName) { | ||
sName += "/cmdInfo/"; | ||
Logger.recordOutput(sName + "hasDefault", s.getDefaultCommand() != null); | ||
Logger.recordOutput( | ||
sName + "default", | ||
s.getDefaultCommand() != null ? s.getDefaultCommand().getName() : "none"); | ||
Logger.recordOutput(sName + "hasCommand", s.getCurrentCommand() != null); | ||
Logger.recordOutput( | ||
sName + "command", | ||
s.getCurrentCommand() != null ? s.getCurrentCommand().getName() : "none"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters