Class PathEmulator
- java.lang.Object
-
- frc.robot.util.hyperdrive.emulation.PathEmulator
-
public class PathEmulator extends java.lang.Object
Big brain that does the path trajectory calculations.
This class is used by theHyperdrive
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.
-
-
Constructor Summary
Constructors Constructor Description PathEmulator(DriveStyle driveStyle, double motorUnitsPerUnit, Units.LENGTH lengthUnit, double robotWeight, Units.FORCE weightUnit)
Creates an empty PathEmulator.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 givenPath
andIEmulateParams
.
-
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 thePath
that the robot just took while trying to drive the path supplied to this class.IEmulateParams
getParameters()
Returns theIEmulateParams
That are currently being used to make the robot drive its path.Path
getPath()
Returns thePath
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 givenPath
andIEmulateParams
.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.
-
-
-
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 givenPath
andIEmulateParams
. Any call to theisLoaded()
method will return true unless theload(Path, IEmulateParams)
method is called withnull
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 theHyperdrive
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-loadparameters
- 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 usingload(Path, IEmulateParams)
. Users can check the state of the PathEmulator using theisLoaded()
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 theHyperdrive
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 givenPath
andIEmulateParams
. 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 toisLoaded()
should returntrue
until this method is called again withnull
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 thePath
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 thePath
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 theIEmulateParams
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 tocalculateTrajectory(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'sload(Path, IEmulateParams)
method must be called with non-null objects.- Returns:
true
if the PathEmulator is ready to do trajectory calculations, andfalse
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.
-
-