Class PointTracker

java.lang.Object
me.wobblyyyy.pathfinder.tracking.PointTracker

public class PointTracker
extends java.lang.Object
Track a single point in a two-dimensional environment.

All of the math behind this is fairly easy to find - however, as a very quick overview...

The movement of a single point can be expressed as follows.

 M_xyz = T_x + T_y + R_z
 
where...
  • x is the horizontal component of the X/Y plane.
  • y is the vertical component of the X/Y plane.
  • z is a measure of rotation or direction.
  • M is a representation of the point's movement, which is a combination of the point's (a) X and Y translation and (b) rotation or direction.
  • T is a measure of the point's translational movement along a given axis.
  • R is a measure of the point's rotational movement.

Thus, the X and Y coordinates can be tracked as follows.

  • x_n = x_o * M_xy(cos(theta))
  • y_n = y_o * M_xy(sin(theta))

Since:
0.1.0
Author:
Colin Robertson
  • Field Summary

    Fields
    Modifier and Type Field Description
    private double circumference
    The circumference of the drive wheel.
    private double cpr
    The encoder's CPR (counts per rotation).
    private double diameter
    The diameter of the drive wheel.
    private Encoder encoder
    A reference to the encoder used for positional tracking.
    private double lastAngle
    The last-recorded angle.
    private int lastCount
    The last-recorded count.
    private HeadingPoint position
    An estimate of the point's current position.
    private Point startingPoint
    The point's starting position/offset.
    private double tpi
    TPI = Ticks per Inch.
  • Constructor Summary

    Constructors
    Constructor Description
    PointTracker​(Encoder encoder, double diameter)
    Create a new point tracker.
    PointTracker​(Encoder encoder, double diameter, Point startingPoint)
    Create a new point tracker.
  • Method Summary

    Modifier and Type Method Description
    double getDiameter()
    Get the diameter of the wheel.
    Encoder getEncoder()
    Get the internally-used encoder.
    double getHeading()
    Get the point's current heading.
    HeadingPoint getPosition()
    Get the point positional tracker's current position.
    double getX()
    Get the point's X value.
    double getY()
    Get the point's Y value.
    double ticksToInches​(int ticks)
    Convert between ticks and inches.
    void update​(double angle)
    Update the positional tracker according to an angle and count value.
    void update​(double angle, int count)
    Update the positional tracker according to an angle and count value.

    Methods inherited from class java.lang.Object

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

    • encoder

      private final Encoder encoder
      A reference to the encoder used for positional tracking.

      This encoder is for the DRIVE wheel on a swerve module - NOT the TURN wheel.

    • lastAngle

      private double lastAngle
      The last-recorded angle.
    • lastCount

      private int lastCount
      The last-recorded count.
    • position

      private HeadingPoint position
      An estimate of the point's current position.
    • startingPoint

      private final Point startingPoint
      The point's starting position/offset.
    • cpr

      private final double cpr
      The encoder's CPR (counts per rotation).
    • diameter

      private final double diameter
      The diameter of the drive wheel.
    • circumference

      private final double circumference
      The circumference of the drive wheel.
    • tpi

      private final double tpi
      TPI = Ticks per Inch.
  • Constructor Details

    • PointTracker

      public PointTracker​(Encoder encoder, double diameter)
      Create a new point tracker.

      Unless you have a very good reason to, you should use the other constructor with 3 arguments instead of 2.

      Parameters:
      encoder - the point tracker's internally-used encoder.
      diameter - the diameter of the point tracker's drive wheel.
    • PointTracker

      public PointTracker​(Encoder encoder, double diameter, Point startingPoint)
      Create a new point tracker.
      Parameters:
      encoder - the point tracker's internally-used encoder.
      diameter - the diameter of the point tracker's drive wheel.
      startingPoint - the tracker's starting position. Typically, this value corresponds to a drive wheel's physical positioning relative to the center of a given wheeled vehicle.
  • Method Details

    • ticksToInches

      public double ticksToInches​(int ticks)
      Convert between ticks and inches.

      If either the CPR (counts per rotation) or diameter (of a drive wheel, of course) are inaccurate, this value will also be entirely inaccurate.

      Parameters:
      ticks - the encoder's ticks.
      Returns:
      how many inches have been travelled.
    • update

      public void update​(double angle)
      Update the positional tracker according to an angle and count value.

      This method needs to be run as frequently as possible in order for it to work effectively. Because this method tracks position based on angle and distance, any issue with the angle will totally mess up the point's perceived position.

      If, for example, you had a 45 degree turn with 1,000 encoder counts, and you only updated the encoder once, the tracker would see that it's facing 45deg and it's ticked 1,000 times - meaning the tracker thinks that its currently 1,000 ticks ahead of 45deg from the point's center. Basically, my POINT is you should update this very often.

      In addition to updating the robot's position as accurately as possible, this updates the lastCount double for use in future updates.

      Parameters:
      angle - the angle which the point is currently facing. This angle should be notated in degrees, not radians. Additionally, this angle should be determined externally - you shouldn't pass a raw encoder value to this method, ever.
      See Also:
      update(double, int)
    • update

      public void update​(double angle, int count)
      Update the positional tracker according to an angle and count value.

      This method needs to be run as frequently as possible in order for it to work effectively. Because this method tracks position based on angle and distance, any issue with the angle will totally mess up the point's perceived position.

      If, for example, you had a 45 degree turn with 1,000 encoder counts, and you only updated the encoder once, the tracker would see that it's facing 45deg and it's ticked 1,000 times - meaning the tracker thinks that its currently 1,000 ticks ahead of 45deg from the point's center. Basically, my POINT is you should update this very often.

      In addition to updating the robot's position as accurately as possible, this updates the lastCount double for use in future updates.

      Parameters:
      angle - the angle which the point is currently facing. This angle should be notated in degrees, not radians. Additionally, this angle should be determined externally - you shouldn't pass a raw encoder value to this method, ever.
      count - the encoder's current count. This should be the value directly reported from the encoder, not any other value or offset. This method already accounts for the difference in value and offsets.
    • getX

      public double getX()
      Get the point's X value.
      Returns:
      the point's X value.
    • getY

      public double getY()
      Get the point's Y value.
      Returns:
      the point's Y value.
    • getHeading

      public double getHeading()
      Get the point's current heading.

      Just as a note, you probably shouldn't be using this method. Rather, odometric tracking of a point's heading can be accomplished by simply querying whatever encoder, gyroscope, or tracker is used to change the angle of the wheel.

      Returns:
      the point's heading.
    • getPosition

      public HeadingPoint getPosition()
      Get the point positional tracker's current position.

      This position is an estimate of the point's position based on the math highlighted earlier in the Java file - the class' JavaDoc, actually.

      Returns:
      the tracker's current position.
    • getEncoder

      public Encoder getEncoder()
      Get the internally-used encoder.
      Returns:
      the point tracker's encoder.
    • getDiameter

      public double getDiameter()
      Get the diameter of the wheel.
      Returns:
      the wheel's diameter.