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

52 lines
1.2 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-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
/** Creates a new AutoBalanceTF2. */
2023-02-02 19:11:10 -07:00
public AutoBalance(RobotGyro gyro, SwerveDrive drive) {
2023-02-02 19:43:47 -07:00
super(1.0, 0, 0, 0);
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-02 19:11:10 -07:00
var pitch = gyro.getPitch();
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-02 19:11:10 -07:00
if (Math.abs(gyro.getPitch()) < 3) out2 = 0;
drive.drive(out2, 0, 0, false);
2023-01-14 10:37:09 -07:00
}
2023-01-14 14:26:17 -07:00
@Override
public void initialize() {
super.initialize();
2023-02-02 19:43:47 -07:00
// this.gyro.reset();
2023-01-14 14:26:17 -07:00
}
2023-01-14 10:37:09 -07:00
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
2023-01-12 18:49:21 -07:00
}