Class LinearFollower

java.lang.Object
me.wobblyyyy.pathfinder.followers.LinearFollower
All Implemented Interfaces:
Follower

public class LinearFollower
extends java.lang.Object
implements Follower
The most incredibly simple trajectory follower you could possible imagine. This follower works by linearly driving the drivetrain in a given direction. The follower's speed coefficient (how fast the robot moves out of a possible 100% power) can be modified on construction, allowing the follower to be either faster or slower. After the follower's execution has finished entirely, the follower should stop the robot by setting power to each of the drivetrain's motors to 0. Please note that this follower doesn't have any dynamic correction - if the robot is in the wrong place, the follower won't work, and your pathfinder will have a hard time... pathfinding.
Since:
0.1.0
Author:
Colin Robertson
  • Field Summary

    Fields
    Modifier and Type Field Description
    private double coefficient
    The follower's speed multiplier.
    private Drive drive
    A reference to the follower's drivetrain.
    private HeadingPoint end
    The follower's end/target point.
    private Odometry odometry
    The follower's odometry system.
    private HeadingPoint start
    The follower's start point.
  • Constructor Summary

    Constructors
    Constructor Description
    LinearFollower​(Drive drive, Odometry odometry, HeadingPoint start, HeadingPoint end, double coefficient)
    Create a new linear follower.
  • Method Summary

    Modifier and Type Method Description
    void calculate()
    In this case, we don't need to do anything - there are no calculations needed to drive the robot.
    void drive()
    Drive the robot.
    double getCoefficient()
    Get the linear follower's drive speed coefficient.
    Odometry getOdometry()
    Get a reference to the odometry system used by the follower.
    HeadingPoint getTargetPos()
    Get the follower's target/goal/end position.
    boolean isDone()
    Has the follower finished yet? The follower's finish qualification is determined by whether or not the robot is close enough to the target position.
    void setCoefficient​(double coefficient)
    Set the linear follower's drive speed coefficient.
    void update()
    We don't need to do anything here, either - all of the driving that needs to get done is done through the drivetrain itself.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • drive

      private final Drive drive
      A reference to the follower's drivetrain.
    • odometry

      private final Odometry odometry
      The follower's odometry system. This system is only used for determining if the follower is close to the target position.
    • start

      private final HeadingPoint start
      The follower's start point.
    • end

      private final HeadingPoint end
      The follower's end/target point.
    • coefficient

      private double coefficient
      The follower's speed multiplier. The higher this value is, the faster the LinearFollower will execute. This value can be changed through either configuration options or the Factory class.
  • Constructor Details

    • LinearFollower

      public LinearFollower​(Drive drive, Odometry odometry, HeadingPoint start, HeadingPoint end, double coefficient)
      Create a new linear follower.
      Parameters:
      drive - the robot's drivetrain.
      odometry - the robot's odometry system.
      start - the start position.
      end - the end position.
      coefficient - the robot's speed (0 to 1).
  • Method Details

    • getCoefficient

      public double getCoefficient()
      Get the linear follower's drive speed coefficient.
      Returns:
      the linear follower's drive speed coefficient.
    • setCoefficient

      public void setCoefficient​(double coefficient)
      Set the linear follower's drive speed coefficient.
      Parameters:
      coefficient - the linear follower's new drive speed coefficient.
    • getOdometry

      public Odometry getOdometry()
      Get a reference to the odometry system used by the follower.
      Returns:
      the follower's odometry system.
    • getTargetPos

      public HeadingPoint getTargetPos()
      Get the follower's target/goal/end position.
      Returns:
      the follower's target/goal/end position.
    • update

      public void update()
      We don't need to do anything here, either - all of the driving that needs to get done is done through the drivetrain itself. This method will do absolutely nothing, but it has to be called anyways.
      Specified by:
      update in interface Follower
    • calculate

      public void calculate()
      In this case, we don't need to do anything - there are no calculations needed to drive the robot. All of the translational calculations that are needed should be handled by the internal kinematics of the implemented drivetrain of choice.
      Specified by:
      calculate in interface Follower
    • drive

      public void drive()
      Drive the robot. This method attempts to power the robot by calling the drive method of the drivetrain.
      Specified by:
      drive in interface Follower
    • isDone

      public boolean isDone()
      Has the follower finished yet? The follower's finish qualification is determined by whether or not the robot is close enough to the target position. This tolerance is, by default, 4 units - often inches.
      Specified by:
      isDone in interface Follower
      Returns:
      whether or not the follower has finished.