Skip to content

Commit

Permalink
Started Implementing PhotonVision code
Browse files Browse the repository at this point in the history
There are still many errors.
  • Loading branch information
joshuman committed Jan 20, 2024
1 parent 1c4e7c4 commit 4486cf6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/DriveSwerveYAGSL.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package frc.robot.subsystems.drive;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.Kinematics;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Filesystem;
import java.io.File;

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 swervelib.SwerveDrive;
import swervelib.parser.SwerveParser;

Expand All @@ -14,13 +23,47 @@ public class DriveSwerveYAGSL extends DriveBase {
new File(Filesystem.getDeployDirectory(), "swervePracticeBot");
private SwerveDrive swerveDrive;
private boolean fieldOrientedDrive = false;
public Pose2d getPose(){
return swerveDrive.getPose();
}
public void resetodometry(){}
public ChassisSpeeds getRobotVelocity()
{
return Kinematics.toChassisSpeeds(getStates());
}

public DriveSwerveYAGSL() {
try {
swerveDrive = new SwerveParser(swerveJsonDirectory).createSwerveDrive(maximumSpeed);
} catch (Exception e) {
throw new RuntimeException(e);
}

AutoBuilder.configureHolonomic(
this::getPose, // Robot pose supplier
this::resetodometry, // Method to reset odometry (will be called if your auto has a starting pose)
this::getRobotVelocity, // ChassisSpeeds supplier. MUST BE ROBOT RELATIVE
this::driveRobotRelative, // Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds
new HolonomicPathFollowerConfig( // HolonomicPathFollowerConfig, this should likely live in your Constants class
new PIDConstants(5.0, 0.0, 0.0), // Translation PID constants
new PIDConstants(5.0, 0.0, 0.0), // Rotation PID constants
4.5, // Max module speed, in m/s
0.4, // Drive base radius in meters. Distance from robot center to furthest module.
new ReplanningConfig() // Default path replanning config. See the API for the options here
),
() -> {
// Boolean supplier that controls when the path will be mirrored for the red alliance
// This will flip the path being followed to the red side of the field.
// THE ORIGIN WILL REMAIN ON THE BLUE SIDE

var alliance = DriverStation.getAlliance();
if (alliance.isPresent()) {
return alliance.get() == DriverStation.Alliance.Red;
}
return false;
},
this // Reference to this subsystem to set requirements
);
}

@Override
Expand Down

0 comments on commit 4486cf6

Please sign in to comment.