-
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.
[#29] - added base code for pathfinding to a point and auton
- Loading branch information
Showing
6 changed files
with
215 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"version": 1.0, | ||
"waypoints": [ | ||
{ | ||
"anchor": { | ||
"x": 9.647717313452645, | ||
"y": 4.335765788648695 | ||
}, | ||
"prevControl": null, | ||
"nextControl": { | ||
"x": 10.647717313452642, | ||
"y": 4.335765788648695 | ||
}, | ||
"isLocked": false, | ||
"linkedName": null | ||
}, | ||
{ | ||
"anchor": { | ||
"x": 4.0, | ||
"y": 6.0 | ||
}, | ||
"prevControl": { | ||
"x": 3.0, | ||
"y": 6.0 | ||
}, | ||
"nextControl": null, | ||
"isLocked": false, | ||
"linkedName": null | ||
} | ||
], | ||
"rotationTargets": [], | ||
"constraintZones": [], | ||
"eventMarkers": [], | ||
"globalConstraints": { | ||
"maxVelocity": 3.0, | ||
"maxAcceleration": 3.0, | ||
"maxAngularVelocity": 540.0, | ||
"maxAngularAcceleration": 720.0 | ||
}, | ||
"goalEndState": { | ||
"velocity": 0, | ||
"rotation": 0, | ||
"rotateFast": false | ||
}, | ||
"reversed": false, | ||
"folder": null, | ||
"previewStartingState": { | ||
"rotation": 0, | ||
"velocity": 0 | ||
}, | ||
"useDefaultConstraints": true | ||
} |
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,74 @@ | ||
// 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.command; | ||
|
||
import com.pathplanner.lib.auto.AutoBuilder; | ||
import com.pathplanner.lib.path.PathConstraints; | ||
import com.pathplanner.lib.path.PathPlannerPath; | ||
import com.pathplanner.lib.path.PathPoint; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
import edu.wpi.first.wpilibj.DriverStation.Alliance; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Constants.AutonomousConstants; | ||
import frc.robot.Constants.PathFindingConstants; | ||
import frc.robot.subsystems.Swerve; | ||
import frc.thunder.filter.XboxControllerFilter; | ||
|
||
public class PathFindToAuton extends Command { | ||
|
||
private Swerve drivetrain; | ||
private XboxControllerFilter controller; // Driver Controller | ||
private AutoBuilder autoBuilder; | ||
private Command pathFindCommand; | ||
private PathPlannerPath autonPath; | ||
|
||
/* | ||
* Pathfinds to a specific pose given | ||
* @param pathfindingPose The pose to pathfind to | ||
* @param drivetrain The drivetrain subsystem | ||
* @param controller The driver controller | ||
*/ | ||
public PathFindToAuton(PathPlannerPath autonPath, Swerve drivetrain, XboxControllerFilter controller) { | ||
this.drivetrain = drivetrain; | ||
this.controller = controller; | ||
this.autonPath = autonPath; | ||
autoBuilder = new AutoBuilder(); | ||
|
||
addRequirements(drivetrain); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
pathFindCommand = autoBuilder.pathfindThenFollowPath( | ||
autonPath, AutonomousConstants.PATH_CONSTRAINTS); | ||
pathFindCommand.schedule(); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
|
||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) { | ||
pathFindCommand.cancel(); | ||
} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
if (pathFindCommand.isFinished()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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,72 @@ | ||
// 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.command; | ||
|
||
import com.pathplanner.lib.auto.AutoBuilder; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Constants.AutonomousConstants; | ||
import frc.robot.subsystems.Swerve; | ||
import frc.thunder.filter.XboxControllerFilter; | ||
|
||
public class PathToPose extends Command { | ||
|
||
private Swerve drivetrain; | ||
private XboxControllerFilter controller; // Driver Controller | ||
private Pose2d pathfindingPose; | ||
private AutoBuilder autoBuilder; | ||
Command pathFindCommand; | ||
|
||
/* | ||
* Pathfinds to a specific pose given | ||
* @param pathfindingPose The pose to pathfind to | ||
* @param drivetrain The drivetrain subsystem | ||
* @param controller The driver controller | ||
*/ | ||
public PathToPose(Pose2d pathfindingPose, Swerve drivetrain, XboxControllerFilter controller) { | ||
this.drivetrain = drivetrain; | ||
this.controller = controller; | ||
this.pathfindingPose = pathfindingPose; | ||
|
||
autoBuilder = new AutoBuilder(); | ||
|
||
addRequirements(drivetrain); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
pathFindCommand = autoBuilder.pathfindToPose( | ||
pathfindingPose, AutonomousConstants.PATH_CONSTRAINTS | ||
); | ||
pathFindCommand.schedule(); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
if (controller.getYButton()) { | ||
end(true); | ||
} | ||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) { | ||
if (interrupted) { | ||
pathFindCommand.cancel(); | ||
} | ||
} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
if (pathFindCommand.isFinished()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |