mode auto manuel
This commit is contained in:
		| @@ -28,8 +28,10 @@ import edu.wpi.first.wpilibj2.command.Commands; | ||||
| import edu.wpi.first.wpilibj2.command.InstantCommand; | ||||
| import edu.wpi.first.wpilibj2.command.RunCommand; | ||||
| import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||||
| import edu.wpi.first.wpilibj2.command.WaitUntilCommand; | ||||
| import edu.wpi.first.wpilibj2.command.button.CommandXboxController; | ||||
| import frc.robot.TunerConstants.TunerConstants; | ||||
| import frc.robot.commands.AvancerAuto; | ||||
| import frc.robot.commands.RainBow; | ||||
| import frc.robot.commands.reset; | ||||
| import frc.robot.commands.Elevateur.Depart; | ||||
| @@ -177,14 +179,19 @@ public class RobotContainer { | ||||
|   } | ||||
|      | ||||
|     public Command getAutonomousCommand() { | ||||
|       return new SequentialCommandGroup(Commands.runOnce(()->{ | ||||
|         boolean flip = DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red; | ||||
|         if(flip){ | ||||
|             drivetrain.resetPose(FlippingUtil.flipFieldPose(((PathPlannerAuto)autoChooser.getSelected()).getStartingPose())); | ||||
|         } | ||||
|         else{ | ||||
|             drivetrain.resetPose(((PathPlannerAuto)autoChooser.getSelected()).getStartingPose()); | ||||
|         } | ||||
|       }),autoChooser.getSelected(), new RainBow(bougie)); | ||||
|       return new SequentialCommandGroup( | ||||
|         new AvancerAuto(drive).withTimeout(2), | ||||
|         new L1Requin(requin, bougie).withTimeout(2), | ||||
|         new ExpireCorail(requin, bougie).withTimeout(2), | ||||
|         new RainBow(bougie)); | ||||
|       // return new SequentialCommandGroup(Commands.runOnce(()->{ | ||||
|       //   boolean flip = DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red; | ||||
|       //   if(flip){ | ||||
|       //       drivetrain.resetPose(FlippingUtil.flipFieldPose(((PathPlannerAuto)autoChooser.getSelected()).getStartingPose())); | ||||
|       //   } | ||||
|       //   else{ | ||||
|       //       drivetrain.resetPose(((PathPlannerAuto)autoChooser.getSelected()).getStartingPose()); | ||||
|       //   } | ||||
|       // }),autoChooser.getSelected(), new RainBow(bougie)); | ||||
|     }     | ||||
| } | ||||
							
								
								
									
										46
									
								
								src/main/java/frc/robot/commands/AvancerAuto.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/main/java/frc/robot/commands/AvancerAuto.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| // 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 frc.robot.commands; | ||||
|  | ||||
| import static edu.wpi.first.units.Units.*; | ||||
|  | ||||
| import com.ctre.phoenix6.swerve.SwerveRequest; | ||||
|  | ||||
| import edu.wpi.first.wpilibj2.command.Command; | ||||
| import frc.robot.TunerConstants.TunerConstants; | ||||
|  | ||||
| /* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ | ||||
| public class AvancerAuto extends Command { | ||||
|    private double MaxSpeed = TunerConstants.kSpeedAt12Volts.in(MetersPerSecond); // kSpeedAt12Volts desired top speed | ||||
|   private double MaxAngularRate = RotationsPerSecond.of(0.75).in(RadiansPerSecond); // 3/4 of | ||||
|    private final SwerveRequest.RobotCentric drive = new SwerveRequest.RobotCentric() | ||||
|     .withDeadband(MaxSpeed * 0.1).withRotationalDeadband(MaxAngularRate * 0.1); | ||||
|   /** Creates a new AvancerAuto. */ | ||||
|   public AvancerAuto(SwerveRequest.RobotCentric drive) { | ||||
|     // Use addRequirements() here to declare subsystem dependencies. | ||||
|   } | ||||
|  | ||||
|   // Called when the command is initially scheduled. | ||||
|   @Override | ||||
|   public void initialize() {} | ||||
|  | ||||
|   // Called every time the scheduler runs while the command is scheduled. | ||||
|   @Override | ||||
|   public void execute() { | ||||
|     drive.withVelocityX(0.2); | ||||
|   } | ||||
|  | ||||
|   // Called once the command ends or is interrupted. | ||||
|   @Override | ||||
|   public void end(boolean interrupted) { | ||||
|     drive.withVelocityX(0); | ||||
|   } | ||||
|  | ||||
|   // Returns true when the command should end. | ||||
|   @Override | ||||
|   public boolean isFinished() { | ||||
|     return false; | ||||
|   } | ||||
| } | ||||
| @@ -49,14 +49,16 @@ public class CommandSwerveDrivetrain extends TunerSwerveDrivetrain implements Su | ||||
|         try { | ||||
|             var config = RobotConfig.fromGUISettings(); | ||||
|             AutoBuilder.configure( | ||||
|                  | ||||
|                 () -> getState().Pose,   // Supplier of current robot pose | ||||
|                 this::resetPose,         // Consumer for seeding pose against auto | ||||
|                 () -> getState().Speeds, // Supplier of current robot speeds | ||||
|                  | ||||
|                 // Consumer of ChassisSpeeds and feedforwards to drive the robot | ||||
|                 (speeds, feedforwards) -> setControl( | ||||
|                     m_pathApplyRobotSpeeds.withSpeeds(speeds) | ||||
|                         .withWheelForceFeedforwardsX(feedforwards.robotRelativeForcesXNewtons()) | ||||
|                         .withWheelForceFeedforwardsY(feedforwards.robotRelativeForcesYNewtons()) | ||||
|                         .withWheelForceFeedforwardsY(feedforwards.robotRelativeForcesXNewtons()) | ||||
|                         .withWheelForceFeedforwardsX(feedforwards.robotRelativeForcesYNewtons()) | ||||
|                 ), | ||||
|                 new PPHolonomicDriveController( | ||||
|                     // PID constants for translation | ||||
| @@ -70,6 +72,7 @@ public class CommandSwerveDrivetrain extends TunerSwerveDrivetrain implements Su | ||||
|                 // Assume the path needs to be flipped for Red vs Blue, this is normally the case | ||||
|                 () -> DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red, | ||||
|                 this // Subsystem for requirements | ||||
|                  | ||||
|             ); | ||||
|         } catch (Exception ex) { | ||||
|             DriverStation.reportError("Failed to load PathPlanner config and configure AutoBuilder", ex.getStackTrace()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user