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

62 lines
2.3 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 com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
import com.ctre.phoenix.sensors.WPI_Pigeon2;
import edu.wpi.first.math.MathUtil;
2023-01-12 18:49:21 -07:00
import edu.wpi.first.math.controller.PIDController;
2023-01-13 20:24:38 -07:00
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2023-01-12 18:49:21 -07:00
import edu.wpi.first.wpilibj2.command.PIDCommand;
2023-01-13 20:24:38 -07:00
import frc4388.robot.Robot;
import frc4388.utility.RobotGyro;
2023-01-12 18:49:21 -07:00
// 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 AutoBalanceTF2 extends PIDCommand {
2023-01-13 20:24:38 -07:00
// private TalonSRX frontLeft;
// private TalonSRX frontRight;
// private TalonSRX backLeft;
// private TalonSRX backRight;
2023-01-12 18:49:21 -07:00
/** Creates a new AutoBalanceTF2. */
2023-01-13 20:24:38 -07:00
public AutoBalanceTF2(TalonSRX frontLeft, TalonSRX frontRight, TalonSRX backLeft, TalonSRX backRight, RobotGyro gyro, Robot.MicroBot bot) {
2023-01-12 18:49:21 -07:00
super(
// The controller that the command will use
2023-01-13 20:24:38 -07:00
new PIDController(.7, .02, .1),
2023-01-12 18:49:21 -07:00
// This should return the measurement
2023-01-13 20:24:38 -07:00
() -> Math.abs(gyro.getPitch()) < 3 ? 0 : gyro.getPitch(),
2023-01-12 18:49:21 -07:00
// This should return the setpoint (can also be a constant)
() -> 0,
// This uses the output
output -> {
// Use the output here
2023-01-13 20:24:38 -07:00
double out2 = -MathUtil.clamp(output / 20, -1, 1);
if (Math.abs(gyro.getPitch()) < 3) out2 = 0;
SmartDashboard.putNumber("Output", out2);
frontLeft.set(ControlMode.PercentOutput, out2);
frontRight.set(ControlMode.PercentOutput, out2);
backRight.set(ControlMode.PercentOutput, out2);
backLeft.set(ControlMode.PercentOutput, out2);
2023-01-12 18:49:21 -07:00
});
2023-01-13 20:24:38 -07:00
gyro.reset();
addRequirements(bot);
2023-01-12 18:49:21 -07:00
// Use addRequirements() here to declare subsystem dependencies.
// Configure additional PID options by calling `getController` here.
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}