This commit is contained in:
Abhi
2023-02-02 19:11:10 -07:00
parent 1e812f706b
commit 161afb4462
3 changed files with 18 additions and 10 deletions
@@ -18,6 +18,7 @@ import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import frc4388.robot.Constants.*;
import frc4388.robot.commands.AutoBalance;
import frc4388.robot.commands.DriveWithInput;
import frc4388.robot.subsystems.LED;
import frc4388.robot.subsystems.SwerveDrive;
@@ -115,6 +116,8 @@ public class RobotContainer {
// new JoystickButton(getDriverJoystick(), XboxController.Y_BUTTON)
// .onTrue()
new JoystickButton(getDriverJoystick(), XboxController.Y_BUTTON)
.onTrue(new AutoBalance(m_robotMap.gyro, m_robotSwerveDrive));
//New interupt button
new JoystickButton(getOperatorJoystick(), XboxController.X_BUTTON)
+2 -2
View File
@@ -23,8 +23,8 @@ import frc4388.utility.RobotGyro;
* testing and modularization.
*/
public class RobotMap {
// private WPI_Pigeon2 m_pigeon2 = new WPI_Pigeon2(14);
// public RobotGyro gyro = new RobotGyro(m_pigeon2);
private WPI_Pigeon2 m_pigeon2 = new WPI_Pigeon2(14);
public RobotGyro gyro = new RobotGyro(m_pigeon2);
public SwerveModule leftFront;
@@ -5,37 +5,42 @@
package frc4388.robot.commands;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc4388.robot.Robot;
import frc4388.robot.subsystems.SwerveDrive;
import frc4388.utility.RobotGyro;
// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
public class AutoBalance extends PelvicInflammatoryDisease {
Robot.MicroBot bot;
RobotGyro gyro;
SwerveDrive drive;
/** Creates a new AutoBalanceTF2. */
public AutoBalance(Robot.MicroBot bot) {
public AutoBalance(RobotGyro gyro, SwerveDrive drive) {
super(.7, .1, 15, 0);
addRequirements(bot);
this.bot = bot;
addRequirements(drive);
}
@Override
public double getError() {
return bot.gyro.getPitch();
var pitch = gyro.getPitch();
SmartDashboard.putNumber("pitch", pitch);
return pitch;
}
@Override
public void runWithOutput(double output) {
double out2 = MathUtil.clamp(output / 40, -.5, .5);
if (Math.abs(bot.gyro.getPitch()) < 3) out2 = 0;
bot.setOutput(out2);
if (Math.abs(gyro.getPitch()) < 3) out2 = 0;
drive.drive(out2, 0, 0, false);
}
@Override
public void initialize() {
super.initialize();
this.bot.gyro.reset();
this.gyro.reset();
}
// Returns true when the command should end.