-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from frc937/auto-number-one
Auto number one
- Loading branch information
Showing
6 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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. | ||
|
||
/* | ||
* Asimov's Laws: | ||
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm. | ||
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law. | ||
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law. | ||
*/ | ||
|
||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; | ||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import edu.wpi.first.wpilibj2.command.WaitCommand; | ||
import frc.robot.Constants; | ||
import frc.robot.RobotContainer; | ||
import frc.robot.commands.mailbox.FireNoteRoutine; | ||
|
||
/** | ||
* Uses the Limelight to aim the bot to the Amp and then deposits the note into the Amp. Has a | ||
* timeout on the Note deopsit. | ||
*/ | ||
public class AimAndFireRoutine extends SequentialCommandGroup { | ||
/** Creates a new AimAndFireRoutine. */ | ||
public AimAndFireRoutine() { | ||
addCommands( | ||
new AimWithLimelight( | ||
RobotContainer.limelight, | ||
Constants.Limelight.AimingLimelight.STEER_STRENGTH, | ||
Constants.Limelight.AimingLimelight.DISTANCE_FROM_TARGET, | ||
Constants.Limelight.AimingLimelight.MOUNT_HEIGHT, | ||
Constants.Limelight.AimingLimelight.MOUNT_ANGLE, | ||
Constants.Limelight.AimingLimelight.DRIVE_STRENGTH, | ||
Constants.Limelight.AimingLimelight.SPEED_LIMIT, | ||
Constants.Limelight.AimingLimelight.TURN_DONE_THRESHOLD, | ||
Constants.Limelight.AimingLimelight.DISTANCE_DONE_THRESHOLD, | ||
Constants.Limelight.AimingLimelight.AMP_APRILTAG_HEIGHT), | ||
new ParallelDeadlineGroup( | ||
new WaitCommand(Constants.Auto.FIRE_NOTE_FOR_TIME), new FireNoteRoutine())); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/frc/robot/commands/SeekTargetWithLimelight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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. | ||
|
||
/* | ||
* Asimov's Laws: | ||
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm. | ||
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law. | ||
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law. | ||
*/ | ||
|
||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Constants; | ||
import frc.robot.RobotContainer; | ||
import frc.robot.subsystems.Drive; | ||
import frc.robot.subsystems.Limelight; | ||
|
||
/** | ||
* Seeks an unseen target with the Limelight by spinning the robot in a circle until the Limelight | ||
* sees a valid target. | ||
*/ | ||
public class SeekTargetWithLimelight extends Command { | ||
private Limelight limelight; | ||
private Drive drive; | ||
private double oldPipelineNumber; | ||
private double seekingPipelineNumber; | ||
private double rotationRadiansPerSecond; | ||
|
||
/** | ||
* Creates a new SeekTargetWithLimelight. | ||
* | ||
* @param limelight The Limelight to seek the target with. | ||
* @param pipelineNumber The pipeline to set the Limelight to while seeking. | ||
* @param rotationRadiansPerSecond The number of radians per second to rotate while seeking. | ||
*/ | ||
public SeekTargetWithLimelight( | ||
Limelight limelight, double pipelineNumber, double rotationRadiansPerSecond) { | ||
this.limelight = limelight; | ||
this.drive = RobotContainer.drive; | ||
this.seekingPipelineNumber = pipelineNumber; | ||
this.rotationRadiansPerSecond = rotationRadiansPerSecond; | ||
|
||
addRequirements(limelight, drive); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
this.oldPipelineNumber = limelight.getLimelightPipeline(); | ||
limelight.setLimelightPipeline(seekingPipelineNumber); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
if (!limelight.hasValidTarget()) { | ||
drive.driveRobotOriented(Constants.Drive.EMPTY_TRANSLATION, rotationRadiansPerSecond); | ||
} | ||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) { | ||
limelight.setLimelightPipeline(oldPipelineNumber); | ||
drive.stop(); | ||
} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
return limelight.hasValidTarget(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/frc/robot/commands/auto/MoveAwayFromAmp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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. | ||
|
||
/* | ||
* Asimov's Laws: | ||
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm. | ||
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law. | ||
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law. | ||
*/ | ||
|
||
package frc.robot.commands.auto; | ||
|
||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup; | ||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import edu.wpi.first.wpilibj2.command.WaitCommand; | ||
import frc.robot.Constants; | ||
|
||
/** | ||
* Moves the robot away from the Amp, then slams us towards the opposing alliance wall to taxi and | ||
* get out of the way of the Amp. | ||
*/ | ||
public class MoveAwayFromAmp extends SequentialCommandGroup { | ||
/** Creates a new MoveAwayFromAmp. */ | ||
public MoveAwayFromAmp() { | ||
addCommands( | ||
new ParallelDeadlineGroup( | ||
new WaitCommand(Constants.Auto.BACK_UP_FROM_AMP_TIME), | ||
new DriveAutoFieldOriented( | ||
new Translation2d(Constants.Auto.TAXI_AUTO_METERS_PER_SECOND, 0), 0)), | ||
new ParallelDeadlineGroup( | ||
new WaitCommand(Constants.Auto.DRIVE_AWAY_FROM_AMP_TIME), | ||
new DriveAutoFieldOriented( | ||
new Translation2d(0, Constants.Auto.TAXI_AUTO_METERS_PER_SECOND), 0))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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. | ||
|
||
/* | ||
* Asimov's Laws: | ||
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm. | ||
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law. | ||
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law. | ||
*/ | ||
|
||
package frc.robot.commands.auto; | ||
|
||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import frc.robot.Constants; | ||
import frc.robot.RobotContainer; | ||
import frc.robot.commands.AimAndFireRoutine; | ||
import frc.robot.commands.SeekTargetWithLimelight; | ||
|
||
/** | ||
* Auto that deposits a proloaded Note into the Amp. Does so by spinning until the Limelight sees an | ||
* AprilTag for one of the Amps, moving the bot towards the Amp with the Limelight, depositing the | ||
* note in the Amp, and finally taxiing away from the Amp. | ||
*/ | ||
public class OnePieceAuto extends SequentialCommandGroup { | ||
/** Creates a new OnePieceAuto. */ | ||
public OnePieceAuto() { | ||
addCommands( | ||
new SeekTargetWithLimelight( | ||
RobotContainer.limelight, | ||
Constants.Limelight.AimingLimelight.PipelineNumbers.AMP_PIPELINE_NUMBER, | ||
Constants.Limelight.LIMELIGHT_SEEKING_RADIANS_PER_SECOND), | ||
new AimAndFireRoutine(), | ||
new MoveAwayFromAmp()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters