mirror of
https://github.com/Team4388/2025RidgeScape.git
synced 2026-06-09 00:38:02 -06:00
Improve lidar align accuracy
This commit is contained in:
@@ -8,9 +8,11 @@ import java.util.Optional;
|
||||
import java.util.function.DoubleSupplier;
|
||||
|
||||
import com.ctre.phoenix6.Utils;
|
||||
import com.ctre.phoenix6.configs.TalonFXConfiguration;
|
||||
import com.ctre.phoenix6.hardware.CANcoder;
|
||||
import com.ctre.phoenix6.hardware.TalonFX;
|
||||
import com.ctre.phoenix6.swerve.SwerveDrivetrain;
|
||||
import com.ctre.phoenix6.swerve.SwerveModule;
|
||||
import com.ctre.phoenix6.swerve.SwerveRequest;
|
||||
import com.ctre.phoenix6.swerve.SwerveRequest.ForwardPerspectiveValue;
|
||||
|
||||
@@ -227,6 +229,26 @@ public class SwerveDrive extends Subsystem {
|
||||
swerveDriveTrain.setControl(ctrl);
|
||||
}
|
||||
|
||||
public void setLimits(double limitInAmps) {
|
||||
for (SwerveModule<TalonFX, TalonFX, CANcoder> module : swerveDriveTrain.getModules()) {
|
||||
var talonFXConfigurator = module.getDriveMotor().getConfigurator();
|
||||
var talonFXConfigs = new TalonFXConfiguration();
|
||||
|
||||
talonFXConfigurator.refresh(talonFXConfigs);
|
||||
talonFXConfigs.CurrentLimits.StatorCurrentLimit = limitInAmps;
|
||||
talonFXConfigs.CurrentLimits.SupplyCurrentLimit = limitInAmps+10;
|
||||
talonFXConfigurator.apply(talonFXConfigs);
|
||||
}
|
||||
}
|
||||
|
||||
public void activateLuigiMode() {
|
||||
setLimits(20);
|
||||
}
|
||||
|
||||
public void deactivateLuigiMode() {
|
||||
setLimits(SwerveDriveConstants.Configurations.SLIP_CURRENT);
|
||||
}
|
||||
|
||||
public boolean rotateToTarget(double angle) {
|
||||
swerveDriveTrain.setControl(new SwerveRequest.FieldCentricFacingAngle()
|
||||
.withVelocityX(0)
|
||||
@@ -258,7 +280,11 @@ public class SwerveDrive extends Subsystem {
|
||||
}
|
||||
|
||||
public double getGyroAngle() {
|
||||
return swerveDriveTrain.getRotation3d().getAngle();
|
||||
return getPose2d().getRotation().getRadians();
|
||||
}
|
||||
|
||||
public Pose2d getPose2d() {
|
||||
return swerveDriveTrain.samplePoseAt(Vision.getTime()).orElse(initalPose2d);
|
||||
}
|
||||
|
||||
public void resetGyro() {
|
||||
@@ -283,7 +309,7 @@ public class SwerveDrive extends Subsystem {
|
||||
@Override
|
||||
public void periodic() {
|
||||
// This method will be called once per scheduler run\
|
||||
SmartDashboard.putNumber("Gyro", getGyroAngle());
|
||||
SmartDashboard.putNumber("Gyro", (getGyroAngle() * 180) / Math.PI);
|
||||
SmartDashboard.putNumber("RotTartget", rotTarget);
|
||||
|
||||
double time = Vision.getTime();
|
||||
|
||||
Reference in New Issue
Block a user