Skip to content

Commit

Permalink
should have written configuration code for swerve. Everything should …
Browse files Browse the repository at this point in the history
…work :)
  • Loading branch information
cuttestkittensrule committed Jan 12, 2024
1 parent 687aaa9 commit c77a432
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.team2813.lib.swerve.controllers;
package com.team2813.lib2813.swerve.controllers;

import com.swervedrivespecialties.swervelib.SteerController;
import com.team2813.lib.swerve.controllers.drive.DriveController;
import com.team2813.lib2813.swerve.controllers.drive.DriveController;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.kinematics.SwerveModuleState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team2813.lib.swerve.controllers.drive;
package com.team2813.lib2813.swerve.controllers.drive;

import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardContainer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team2813.lib.swerve.controllers.steer;
package com.team2813.lib2813.swerve.controllers.steer;

import com.swervedrivespecialties.swervelib.ctre.CanCoderAbsoluteConfiguration;

Expand Down
32 changes: 32 additions & 0 deletions Robot2024/src/main/java/com/team2813/subsystems/Drive.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.team2813.subsystems;

import com.ctre.phoenix.sensors.Pigeon2;
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.util.HolonomicPathFollowerConfig;
import com.pathplanner.lib.util.PIDConstants;
import com.pathplanner.lib.util.ReplanningConfig;
import com.swervedrivespecialties.swervelib.Mk4iSwerveModuleHelper.GearRatio;
import com.swervedrivespecialties.swervelib.SdsModuleConfigurations;

Expand All @@ -12,6 +16,8 @@
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.*;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
Expand Down Expand Up @@ -127,8 +133,34 @@ public Drive() {
);

pigeon.configMountPose(Pigeon2.AxisDirection.PositiveY, Pigeon2.AxisDirection.PositiveZ);

AutoBuilder.configureHolonomic(
this::getPose,
this::resetOdometry,
this::getChassisSpeeds,
this::drive,
new HolonomicPathFollowerConfig(
new PIDConstants(0),
new PIDConstants(0),
MAX_VELOCITY,
0.4,
new ReplanningConfig()
),
Drive::onRed,
this);
}

/**
* A method that gets whether you are on red alliance. If there is not an alliance,
* returns false
* @return {@code true} if you are on the red alliance
*/
private static boolean onRed() {
return DriverStation.getAlliance()
.<Boolean>map((j) -> j == Alliance.Red)
.orElse(false);
}

public Rotation2d getRotation() {
return Rotation2d.fromDegrees(pigeon.getHeading());
}
Expand Down

0 comments on commit c77a432

Please sign in to comment.