-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Demo Commands * Fix Translate.java & Add JavaDocs * Bontia Sim
- Loading branch information
Showing
10 changed files
with
354 additions
and
42 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
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
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,50 @@ | ||
// 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 edu.wpi.first.units.Units; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
import frc.robot.subsystems.Drivetrain; | ||
|
||
public class ExampleAuto extends SequentialCommandGroup { | ||
Drivetrain subDrivetrain; | ||
|
||
/** Creates a new ExampleAuto. */ | ||
public ExampleAuto(Drivetrain subDrivetrain) { | ||
/* | ||
* @formatter:off | ||
* | ||
* Self-Driving Robot Workshop Usage: | ||
* 1. Build your self-driving robot command using the following commands: | ||
* a. RotateInPlace | ||
* b. Translate | ||
* c. Commands.waitSeconds | ||
* An example is already done for you below, but feel free to remove it and get creative! | ||
* | ||
* 2. View a simulation of your robot driving! | ||
* a. Press Ctrl+Shift+P or click the WPILib logo in the top right to open the command pallette. | ||
* b. Type or select "WPILib: Simulate Robot Code". | ||
* c. Once the code is done building, select "SIM GUI" from the pop-up window. | ||
* d. Use Field2d or AdvantageScope to view your robot | ||
* e. Run the autonomous by selecting "Autonomous" from Glass | ||
* | ||
* 3. Run your path on the real robot | ||
* a. Place the robot in our specified starting location | ||
* b. Connect to the robot using a DriverStation laptop | ||
* c. Run FRC DriverStation | ||
* d. When you're ready, enable the robot in Autonomous | ||
* | ||
* @formatter:on | ||
*/ | ||
|
||
addCommands( | ||
new Translate(subDrivetrain, Units.Meters.of(1), Units.Degrees.of(45), Units.Percent.of(1)), | ||
Commands.waitSeconds(0.5), | ||
new RotateInPlace(subDrivetrain, Units.Degrees.of(45)), | ||
Commands.waitSeconds(0.5), | ||
new Translate(subDrivetrain, Units.Meters.of(2), Units.Degrees.of(-45), Units.Percent.of(0.5))); | ||
} | ||
} |
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,69 @@ | ||
// 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 edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.units.Angle; | ||
import edu.wpi.first.units.Measure; | ||
import edu.wpi.first.units.Units; | ||
import edu.wpi.first.units.Velocity; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Constants.constDrivetrain; | ||
import frc.robot.subsystems.Drivetrain; | ||
|
||
public class RotateInPlace extends Command { | ||
Drivetrain subDrivetrain; | ||
Measure<Angle> desiredRotation; | ||
Measure<Velocity<Angle>> rVelocity; | ||
final boolean isOpenLoop = false; | ||
|
||
/** | ||
* Rotates the robot in place to face a given Field-Relative rotation. | ||
* | ||
* @param subDrivetrain The instance of the subsystem we are making run this | ||
* command | ||
* @param desiredRotation The desired angle you would like to rotate towards | ||
* (Field-Relative Angle) | ||
* | ||
* @see <a href= | ||
* "https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html">Field | ||
* Coordinate System</a> | ||
* | ||
*/ | ||
public RotateInPlace(Drivetrain subDrivetrain, Measure<Angle> desiredRotation) { | ||
this.subDrivetrain = subDrivetrain; | ||
this.desiredRotation = desiredRotation; | ||
|
||
// Use addRequirements() here to declare subsystem dependencies. | ||
addRequirements(subDrivetrain); | ||
} | ||
|
||
// 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() { | ||
rVelocity = subDrivetrain.getVelocityToRotate(desiredRotation); | ||
|
||
subDrivetrain.drive(new Translation2d(0, 0), rVelocity.in(Units.RadiansPerSecond), isOpenLoop); | ||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) { | ||
subDrivetrain.drive(new Translation2d(0, 0), 0, isOpenLoop); | ||
} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
return subDrivetrain.getRotationMeasure().isNear(desiredRotation, | ||
constDrivetrain.AT_ROTATION_TOLERANCE); | ||
} | ||
} |
Oops, something went wrong.