This repository was archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
HelixFollower
notmattlythgoe edited this page Nov 13, 2019
·
13 revisions
HelixFollower is a path following command used to follow paths generated by BobTrajectory using the FRC Java Command Structure.
- Add the following to your
build.gradle, This allows you to pull the dependencies needed from a github repository:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
- Add these lines to the dependencies block:
compile 'com.github.TripleHelixProgramming:HelixUtilities:master-SNAPSHOT'
compile 'com.github.Team319:BobTrajectory:master-SNAPSHOT'
To integrate the path follower into our robot you will need to create a class that extends HelixFollower and implement the required methods.
public class PathFollower extends HelixFollower {
private Drivetrain drivetrain = Drivetrain.getDrivetrain();
// These are the 2 PID controllers that will handle error for your total travel distance and heading
private PIDController headingController = new PIDController(15, 0, 0, 0.001);
private PIDController distanceController = new PIDController(10, 0, 0, 0.001);
public PathFollower(Path path) {
super(path);
// Make sure to require your subsystem so you don't have conflicting commands
requires(drivetrain);
}
@Override
public void resetDistance() {
// We need to reset the encoders back to 0 at the start of the path
drivetrain.resetEncoders();
}
@Override
public PIDController getHeadingController() {
// Here we return the PID controller that we're using to correct the heading error through the path
return headingController;
}
@Override
public PIDController getDistanceController() {
// Here we return the PID controller that we're using to correct the distance error through the path
return distanceController;
}
@Override
public double getCurrentDistance() {
// Here we need to return the overall robot distance traveled in FEET in this example we are averaging
the two sides of the drivetrain to give is the robot's distance travelled
return (drivetrain.getLeftPosition() + drivetrain.getRightPosition()) / 2.0;
}
@Override
public double getCurrentHeading() {
// Here we need to return the current heading of the robot in RADIANS (positive counter-clockwise).
return Math.toRadians(drivetrain.getHeading());
}
@Override
public void useOutputs(double left, double right) {
// Here we will use the values in FPS and send them off to our drivetrain. In this example the max velocity
of our drivetrain is 12 FPS. We are dividing the two provided parameters by the max veocity to convert them
into a percentage and sending them off to our drivetrain.
drivetrain.setRawPercentOutput(left/12.0, right/12.0);
}
}