Class PathEmulator


  • public class PathEmulator
    extends java.lang.Object
    Big brain that does the path trajectory calculations.

    This class is used by the Hyperdrive class to perform the calculations pertaining to path emulation. That is, this class is what figures out what the robot needs to do to stay on course.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Trajectory calculateTrajectory​(Point2D robotPosition)
      Calculates the trajectory that the robot needs to take in order for it to stay on course with the Path that it is currently running.
      void end()
      Frees up resources used by the PathEmulator during path emulation.
      int getCurrentPoint()
      Returns the index of the current point that the robot is trying to achieve.
      Path getDrivenPath()
      Returns the Path that the robot just took while trying to drive the path supplied to this class.
      IEmulateParams getParameters()
      Returns the IEmulateParams That are currently being used to make the robot drive its path.
      Path getPath()
      Returns the Path that the robot is currently running.
      boolean isFinished()
      Returns whether or not the robot has completed the Path.
      boolean isLoaded()
      Determines whether or not this PathEmulator has both a path and parameters to do trajectory calculations with.
      void load​(Path path, IEmulateParams parameters)
      Loads the PathEmulator with the given Path and IEmulateParams.
      void performInitialCalculations​(Point2D robotPosition)
      Performs calculations that are required for Hyperdrive to drive a path to the best of its ability.
      void specifyResultsFile​(java.lang.String filePath)
      Changes the location of the file where results are stored.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PathEmulator

        public PathEmulator​(DriveStyle driveStyle,
                            double motorUnitsPerUnit,
                            Units.LENGTH lengthUnit,
                            double robotWeight,
                            Units.FORCE weightUnit,
                            Path path,
                            IEmulateParams parameters)
        Creates a new PathEmulator that is pre-loaded with the given Path and IEmulateParams. Any call to the isLoaded() method will return true unless the load(Path, IEmulateParams) method is called with null objects.
        Parameters:
        driveStyle - The drivetrain style of the robot.
        motorUnitsPerUnit - The number of motor units that equate to one actual unit. For full explanation, see the constructor for the Hyperdrive class.
        lengthUnit - The unit of distance that will be used.
        robotWeight - The weight of the robot in either pounds, newtons, or kilogram-force.
        weightUnit - The unit of weight that the robot is measured in.
        path - The Path to pre-load
        parameters - The IEmulateParams to pre-load
      • PathEmulator

        public PathEmulator​(DriveStyle driveStyle,
                            double motorUnitsPerUnit,
                            Units.LENGTH lengthUnit,
                            double robotWeight,
                            Units.FORCE weightUnit)
        Creates an empty PathEmulator. The object will not do anything or return any non-zero calculation until its path and parameters are set using load(Path, IEmulateParams). Users can check the state of the PathEmulator using the isLoaded() method.
        Parameters:
        driveStyle - The drivetrain style of the robot.
        motorUnitsPerUnit - The number of motor units that equate to one actual unit.
        lengthUnit - The unit of distance that should be used. The motorUnitsPerUnit value should convert For full explantion, see the constructor for the Hyperdrive class.
        robotWeight - The weight of the robot in either pounds, newtons, or kilogram-force.
        weightUnit - The unit of weight that the robot was measured in. motor units to this unit.
    • Method Detail

      • load

        public void load​(Path path,
                         IEmulateParams parameters)
        Loads the PathEmulator with the given Path and IEmulateParams. All trajectories calculated after this call will then align the robot to this Path, rather than the one before it. After calling this with non-null objects, all subsequent calls to isLoaded() should return true until this method is called again with null objects.
        Parameters:
        path - The new Path to drive.
        parameters - The parameters to use while emulating the path.
      • specifyResultsFile

        public void specifyResultsFile​(java.lang.String filePath)
        Changes the location of the file where results are stored.
        Parameters:
        filePath - The new file to record path results to.
      • getDrivenPath

        public Path getDrivenPath()
        Returns the Path that the robot just took while trying to drive the path supplied to this class.
        Returns:
        Previously driven Path.
      • performInitialCalculations

        public void performInitialCalculations​(Point2D robotPosition)
        Performs calculations that are required for Hyperdrive to drive a path to the best of its ability. Mainly, this method uses the current robot position to figure out if it should start going forwards or backwards.
        Parameters:
        robotPosition - The current position of the robot.
      • end

        public void end()
        Frees up resources used by the PathEmulator during path emulation.
      • getPath

        public Path getPath()
        Returns the Path that the robot is currently running.
        Returns:
        The path that the robot is driving.
      • getCurrentPoint

        public int getCurrentPoint()
        Returns the index of the current point that the robot is trying to achieve. A value of 0 indicates that the robot is at the beginning of the path.
        Returns:
        Current point index.
      • getParameters

        public IEmulateParams getParameters()
        Returns the IEmulateParams That are currently being used to make the robot drive its path.
        Returns:
        Path emulation parameters.
      • isLoaded

        public boolean isLoaded()
        Determines whether or not this PathEmulator has both a path and parameters to do trajectory calculations with. If this method returns false, any calls to calculateTrajectory(Point2D) will return trajectories with 0 speed, 0 displacement, and 0 turn, which will cause the robot to stand still. Should this happen, this PathEmulator's load(Path, IEmulateParams) method must be called with non-null objects.
        Returns:
        true if the PathEmulator is ready to do trajectory calculations, and false otherwise.
      • isFinished

        public boolean isFinished()
        Returns whether or not the robot has completed the Path.
        Returns:
        True if the path is complete, false otherwise.
      • calculateTrajectory

        public Trajectory calculateTrajectory​(Point2D robotPosition)
        Calculates the trajectory that the robot needs to take in order for it to stay on course with the Path that it is currently running.
        Parameters:
        robotPosition - The current position of the robot on the field.
        Returns:
        The Trajectory that the robot needs to use to stay on course with its Path.