This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port over swerve from spike hector & susan
- Loading branch information
Showing
14 changed files
with
1,985 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.imu; | ||
|
||
import com.ctre.phoenix6.configs.MountPoseConfigs; | ||
import com.ctre.phoenix6.configs.Pigeon2Configuration; | ||
import com.ctre.phoenix6.hardware.Pigeon2; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import frc.robot.util.scheduling.LifecycleSubsystem; | ||
import frc.robot.util.scheduling.SubsystemPriority; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class ImuSubsystem extends LifecycleSubsystem { | ||
private final Pigeon2 imu; | ||
|
||
public ImuSubsystem(Pigeon2 imu) { | ||
super(SubsystemPriority.IMU); | ||
|
||
this.imu = imu; | ||
|
||
Pigeon2Configuration imuConfig = new Pigeon2Configuration(); | ||
|
||
imu.getConfigurator().apply(imuConfig); | ||
} | ||
|
||
public void robotPeriodic() { | ||
Logger.getInstance().recordOutput("Imu/RobotHeading", this.getRobotHeading().getDegrees()); | ||
Logger.getInstance() | ||
.recordOutput("Imu/RobotHeadingRadians", this.getRobotHeading().getRadians()); | ||
} | ||
|
||
public Rotation2d getRobotHeading() { | ||
return Rotation2d.fromDegrees(imu.getYaw().getValue()); | ||
} | ||
|
||
public Rotation2d getRoll() { | ||
return Rotation2d.fromDegrees(imu.getRoll().getValue()); | ||
} | ||
|
||
public void zero() { | ||
setAngle(new Rotation2d()); | ||
|
||
MountPoseConfigs mountPoseConfig = new MountPoseConfigs(); | ||
|
||
mountPoseConfig.MountPoseRoll = getRoll().getDegrees(); | ||
|
||
imu.getConfigurator().apply(mountPoseConfig); | ||
} | ||
|
||
public void setAngle(Rotation2d zeroAngle) { | ||
this.imu.setYaw(zeroAngle.getDegrees()); | ||
} | ||
|
||
public boolean atAngle(Rotation2d angle) { | ||
return Math.abs(getRobotHeading().minus(angle).getDegrees()) < 3; | ||
} | ||
|
||
public Command getZeroCommand() { | ||
return Commands.runOnce(() -> zero()); | ||
} | ||
} |
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,32 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.localization; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import edu.wpi.first.wpilibj.Timer; | ||
import frc.robot.localization.LimelightHelpers.LimelightResults; | ||
|
||
public class JacksonLagUtil { | ||
public static void causeLag() { | ||
ObjectMapper mapper = | ||
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
System.out.println("JacksonLagUtil: Causing lag spike..."); | ||
double time = Timer.getFPGATimestamp(); | ||
try { | ||
LimelightResults results = new LimelightResults(); | ||
mapper.readValue(mapper.writeValueAsString(results), LimelightHelpers.LimelightResults.class); | ||
} catch (JsonProcessingException e) { | ||
System.err.println("JacksonLagUtil: Failed to cause lag spike, JSON parser error:"); | ||
e.printStackTrace(); | ||
} | ||
System.out.println( | ||
"JacksonLagUtil: Lag spike caused in " + (Timer.getFPGATimestamp() - time) + "s"); | ||
} | ||
|
||
private JacksonLagUtil() {} | ||
} |
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,134 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.localization; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.util.Units; | ||
import java.util.List; | ||
|
||
public class Landmarks { | ||
public static final Pose2d APRILTAG_1 = | ||
new Pose2d( | ||
Units.inchesToMeters(610.77), Units.inchesToMeters(42.19), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d APRILTAG_2 = | ||
new Pose2d( | ||
Units.inchesToMeters(610.77), Units.inchesToMeters(108.19), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d APRILTAG_3 = | ||
new Pose2d( | ||
Units.inchesToMeters(610.77), Units.inchesToMeters(174.19), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d APRILTAG_4 = | ||
new Pose2d( | ||
Units.inchesToMeters(636.96), Units.inchesToMeters(265.74), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d APRILTAG_5 = | ||
new Pose2d( | ||
Units.inchesToMeters(14.25), Units.inchesToMeters(265.74), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d APRILTAG_6 = | ||
new Pose2d( | ||
Units.inchesToMeters(40.45), Units.inchesToMeters(174.19), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d APRILTAG_7 = | ||
new Pose2d( | ||
Units.inchesToMeters(40.45), Units.inchesToMeters(108.19), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d APRILTAG_8 = | ||
new Pose2d( | ||
Units.inchesToMeters(40.45), Units.inchesToMeters(42.19), Rotation2d.fromDegrees(0)); | ||
|
||
public static final Pose2d BLUE_GRID_RIGHT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(42), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_CENTER = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(108), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_LEFT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(174), Rotation2d.fromDegrees(0)); | ||
|
||
public static final Pose2d BLUE_GRID_LEFT_NODE_LEFT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(196), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_LEFT_NODE_CENTER = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(174), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_LEFT_NODE_RIGHT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(152), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_CENTER_NODE_LEFT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(130), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_CENTER_NODE_CENTER = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(108), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_CENTER_NODE_RIGHT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(86), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_RIGHT_NODE_LEFT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(64), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_RIGHT_NODE_CENTER = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(42), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d BLUE_GRID_RIGHT_NODE_RIGHT = | ||
new Pose2d(Units.inchesToMeters(54.05), Units.inchesToMeters(20), Rotation2d.fromDegrees(0)); | ||
|
||
public static final Pose2d RED_GRID_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(42), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_CENTER = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(108), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(174), Rotation2d.fromDegrees(180)); | ||
|
||
public static final Pose2d RED_GRID_LEFT_NODE_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(64), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_LEFT_NODE_CENTER = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(42), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_LEFT_NODE_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(20), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_CENTER_NODE_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(130), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_CENTER_NODE_CENTER = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(108), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_CENTER_NODE_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(86), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_RIGHT_NODE_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(196), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_RIGHT_NODE_CENTER = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(174), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d RED_GRID_RIGHT_NODE_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(596.77), Units.inchesToMeters(152), Rotation2d.fromDegrees(180)); | ||
|
||
public static final Pose2d BLUE_STAGING_MARK_FAR_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(278.05), Units.inchesToMeters(36.19), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d BLUE_STAGING_MARK_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(278.05), Units.inchesToMeters(84.19), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d BLUE_STAGING_MARK_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(278.05), Units.inchesToMeters(132.19), Rotation2d.fromDegrees(180)); | ||
public static final Pose2d BLUE_STAGING_MARK_FAR_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(278.05), Units.inchesToMeters(180.19), Rotation2d.fromDegrees(180)); | ||
|
||
public static final Pose2d RED_STAGING_MARK_FAR_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(372.77), Units.inchesToMeters(36.19), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d RED_STAGING_MARK_LEFT = | ||
new Pose2d( | ||
Units.inchesToMeters(372.77), Units.inchesToMeters(84.19), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d RED_STAGING_MARK_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(372.77), Units.inchesToMeters(132.19), Rotation2d.fromDegrees(0)); | ||
public static final Pose2d RED_STAGING_MARK_FAR_RIGHT = | ||
new Pose2d( | ||
Units.inchesToMeters(372.77), Units.inchesToMeters(180.19), Rotation2d.fromDegrees(0)); | ||
|
||
public static final List<Pose2d> RED_GRIDS = | ||
List.of(RED_GRID_LEFT, RED_GRID_CENTER, RED_GRID_RIGHT); | ||
public static final List<Pose2d> BLUE_GRIDS = | ||
List.of(BLUE_GRID_LEFT, BLUE_GRID_CENTER, BLUE_GRID_RIGHT); | ||
|
||
private Landmarks() {} | ||
} |
Oops, something went wrong.