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

47 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;
import frc4388.robot.Robot;
2023-01-12 18:49:21 -07:00
2023-01-14 10:37:09 -07:00
// NOTE: Consider using this command inline, rather than writing a subclass. For more
2023-01-12 18:49:21 -07:00
// information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
2023-01-14 15:35:21 -07:00
public class AutoBalance extends PelvicInflamitoryDisease {
2023-01-14 10:37:09 -07:00
Robot.MicroBot bot;
/** Creates a new AutoBalanceTF2. */
2023-01-14 15:35:21 -07:00
public AutoBalance(Robot.MicroBot bot) {
2023-01-14 14:26:17 -07:00
super(.7, .1, 15, 0);
2023-01-14 10:37:09 -07:00
addRequirements(bot);
this.bot = bot;
}
@Override
public double getError() {
return bot.gyro.getPitch();
}
@Override
public void runWithOutput(double output) {
2023-01-14 14:26:17 -07:00
double out2 = MathUtil.clamp(output / 40, -.5, .5);
2023-01-14 10:37:09 -07:00
if (Math.abs(bot.gyro.getPitch()) < 3) out2 = 0;
bot.setOutput(out2);
}
2023-01-14 14:26:17 -07:00
@Override
public void initialize() {
super.initialize();
this.bot.gyro.reset();
}
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
}