This commit is contained in:
Olivier Dubois 2023-03-08 19:11:46 -05:00
parent 4e6c8413d9
commit 99ce225dc6

View File

@ -7,22 +7,25 @@ package frc.robot.subsystems;
import com.kauailabs.navx.frc.AHRS;
import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;
public class BasePilotable extends SubsystemBase {
final CANSparkMax avantd = new CANSparkMax(Constants.avantdroit, MotorType.kBrushless);
final CANSparkMax avantdroit = new CANSparkMax(Constants.avantdroit, MotorType.kBrushless);
final CANSparkMax avantgauche = new CANSparkMax(Constants.avantgauche, MotorType.kBrushless);
final CANSparkMax arrieredroit = new CANSparkMax(Constants.arrieredroit, MotorType.kBrushless);
final CANSparkMax arrieregauche = new CANSparkMax(Constants.arrieregauche, MotorType.kBrushless);
final MotorControllerGroup droit = new MotorControllerGroup(avantd, arrieredroit);
final MotorControllerGroup droit = new MotorControllerGroup(avantdroit, arrieredroit);
final MotorControllerGroup gauche = new MotorControllerGroup(avantgauche, arrieregauche);
final DifferentialDrive drive = new DifferentialDrive(gauche, droit);
@ -31,26 +34,35 @@ public class BasePilotable extends SubsystemBase {
private DoubleSolenoid brakegauche = new DoubleSolenoid(PneumaticsModuleType.CTREPCM,Constants.brakegauche, Constants.brakegauche);
//gyro
ShuffleboardTab teb = Shuffleboard.getTab("teb");
ShuffleboardLayout layout = Shuffleboard.getTab("teb")
.getLayout ("encodeurs base pilotable", BuiltInLayouts.kList)
.withSize(2, 2);
private AHRS gyroscope = new AHRS();public double getangle() {return gyroscope.getAngle();}
public double getpitch() {
return gyroscope.getPitch();
}
public void drive(double xSpeed, double zRotation){
public void drive(double xSpeed, double zRotation, int i){
drive.arcadeDrive(xSpeed, zRotation);
}
public double distance(){
return (-avantd.getEncoder().getPosition()
teb .add ("distance",0.1);
return (-avantdroit.getEncoder().getPosition()
+avantgauche.getEncoder().getPosition()
-arrieredroit.getEncoder().getPosition()
+arrieregauche.getEncoder().getPosition()) / 4;
}
public void Reset() {
avantd.getEncoder().setPosition(0);
avantdroit.getEncoder().setPosition(0);
avantgauche.getEncoder().setPosition(0);
arrieredroit.getEncoder().setPosition(0);
arrieregauche.getEncoder().setPosition(0);
}
public void resetGyro(){
{gyroscope.reset();
}
}
public void BrakeOuvre(){
brakedroit.set(Value.kForward);
brakegauche.set(Value.kForward);
@ -59,24 +71,13 @@ public void BrakeFerme(){
brakedroit.set(Value.kReverse);
brakegauche.set(Value.kReverse);
}
public void resetGyro(){
{gyroscope.reset();}
}
/** Creates a new BasePilotable. */
public BasePilotable() {
droit.setInverted(true);
teb .addDouble("distance", this::distance);
}
@Override
public void periodic() {
//teb .add("encodeuravantdroit",0.1);
//teb .add("encodeurarrieregauche",0.1);
//teb .add("encodeurarrieredroit",0.1);
//teb .add("encodeuravantgauche",0.1);
//teb .add("distance",0.1);
//teb .add("brakedroit",0.1);
//teb .add("brakegauche", 0.1);
}
}
}