Files
2023WayOfTheRobot/src/main/java/frc4388/robot/commands/AutoBalance.java
T

42 lines
1.1 KiB
Java
Raw Normal View History

2023-01-12 18:49:21 -07:00
// 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 frc4388.robot.commands;
2023-01-13 20:24:38 -07:00
import edu.wpi.first.math.MathUtil;
2023-02-27 18:25:59 -07:00
import edu.wpi.first.math.geometry.Translation2d;
2023-02-02 19:11:10 -07:00
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc4388.robot.subsystems.SwerveDrive;
import frc4388.utility.RobotGyro;
2023-01-12 18:49:21 -07:00
2023-01-15 20:25:07 -07:00
public class AutoBalance extends PelvicInflammatoryDisease {
2023-02-02 19:11:10 -07:00
RobotGyro gyro;
SwerveDrive drive;
2023-01-14 10:37:09 -07:00
2023-03-14 15:21:46 -06:00
/** Creates a new AutoBalance. */
2023-02-02 19:11:10 -07:00
public AutoBalance(RobotGyro gyro, SwerveDrive drive) {
2023-03-14 10:47:17 -06:00
super(0.6, 0, 0, 0, 0);
2023-02-02 19:43:47 -07:00
this.gyro = gyro;
this.drive = drive;
2023-02-02 19:11:10 -07:00
addRequirements(drive);
2023-01-14 10:37:09 -07:00
}
@Override
public double getError() {
2023-02-25 09:52:33 -07:00
var pitch = gyro.getRoll();
2023-02-02 19:11:10 -07:00
SmartDashboard.putNumber("pitch", pitch);
return pitch;
2023-01-14 10:37:09 -07:00
}
@Override
public void runWithOutput(double output) {
2023-01-14 14:26:17 -07:00
double out2 = MathUtil.clamp(output / 40, -.5, .5);
2023-02-25 09:52:33 -07:00
if (Math.abs(getError()) < 3) out2 = 0;
2023-02-25 12:30:20 -07:00
drive.driveWithInput(new Translation2d(0, out2), new Translation2d(), false);
2023-01-14 10:37:09 -07:00
}
2023-01-12 18:49:21 -07:00
}