Class PathfinderManager
public class PathfinderManager
extends java.lang.Object
Unlike the more refined Pathfinder, this class is filled with all sorts of different methods for all sorts of different purposes. Unless you have a pretty strong reason to be working directly with the manager, it's most certainly a better idea to stick to the most abstract form of Pathfinder that you can possibly get to.
With that being said, however, you can still feel free to do whatever you'd like here - I'm not gonna stop you. All of the public-facing methods in this class are fairly well-documented, so I'd suggest you read that documentation before trying something pointless.
Best of luck in your pathfinding adventures!
- Since:
- 0.1.0
- Author:
- Colin Robertson
-
Field Summary
Fields Modifier and Type Field Description private PathfinderConfig
config
The pathfinder's configuration.private FollowerExecutor
exec
The follower execution system.private GeneratorManager
finder
A reference to the pathfinding pathfinder.private int
height
The robot's height.private MainThread
mainThread
Main Pathfinder thread - optionally used.private Map
map
The field's map.private int
specificity
The specificity of the field.private PathfinderThreadManager
thread
Manager used for updating loaded odometry systems.private int
width
The robot's width. -
Constructor Summary
Constructors Constructor Description PathfinderManager(PathfinderConfig config)
Create a new PathfinderManager. -
Method Summary
Modifier and Type Method Description void
close()
Finish this instance of thePathfinderManager
's execution.PromisedFinder
followPath(me.wobblyyyy.edt.DynamicArray<HeadingPoint> points)
Generate a path based on a set of target points, rather than start and end positions.PromisedFinder
followPath(HeadingPoint... points)
Generate a path based on a set of target points, rather than start and end positions.PromisedFinder
generateAndQueueFollowers(HeadingPoint start, HeadingPoint end)
Find a path, generate followers, and queue those followers.me.wobblyyyy.edt.DynamicArray<Follower>
generateFollowers(me.wobblyyyy.edt.DynamicArray<HeadingPoint> path)
Generate a list of followers to complete a given path.PathfinderConfig
getConfig()
Get the pathfinder's configuration.FollowerExecutor
getExecutor()
Get the pathfinder's follower executor.int
getHeight()
Get the height of the robot.me.wobblyyyy.edt.DynamicArray<Point>
getPath(HeadingPoint start, HeadingPoint end)
Get a path of points between two points.int
getSpecificity()
Get the specificity of the field.me.wobblyyyy.edt.DynamicArray<Follower>
getTrajectoryFollowers(me.wobblyyyy.edt.Arrayable<Trajectory> trajectories)
Get followers for a specified set of trajectories.me.wobblyyyy.edt.DynamicArray<Point>
getWaypointPath(me.wobblyyyy.edt.DynamicArray<HeadingPoint> points)
Get an extended path between two or more points.int
getWidth()
Get the width of the robot.PromisedFinder
goToPosition(HeadingPoint end)
Go to a position from the robot's current position.void
lock()
Lock the current thread and prevent it from progressing until the pathfinder's execution thread is idle.me.wobblyyyy.edt.DynamicArray<Point>
merge(me.wobblyyyy.edt.DynamicArray<me.wobblyyyy.edt.DynamicArray<Point>> paths)
Merge several paths into a single path by adding the DynamicArray of points of each of the paths together and then removing any duplicates.void
open()
Open thePathfinderManager
's threads and make it start doing its thing.void
pauseOdometry()
Pause the odometry updater, temporarily stopping it from updating the values of the odometry system based one encoder values.void
queueFollowers(me.wobblyyyy.edt.DynamicArray<Follower> followers)
Don't find any path - instead, simply queue the inputted followers.void
stopRobot()
Stop the robot's drivetrain.void
tick()
Tick the Pathfinder once.void
unpauseOdometry()
Unpause the odometry system, allowing it to function normally once again.me.wobblyyyy.edt.DynamicArray<HeadingPoint>
withHeading(me.wobblyyyy.edt.DynamicArray<Point> points, HeadingPoint start, HeadingPoint end)
Convert an DynamicArray of Point instances to an DynamicArray of HeadingPoint instances.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
config
The pathfinder's configuration. -
width
private final int widthThe robot's width.- See Also:
PathfinderConfig.getRobotX()
-
height
private final int heightThe robot's height.- See Also:
PathfinderConfig.getRobotY()
-
specificity
private final int specificityThe specificity of the field. -
map
The field's map. -
finder
A reference to the pathfinding pathfinder. -
exec
The follower execution system. -
thread
Manager used for updating loaded odometry systems. -
mainThread
Main Pathfinder thread - optionally used.
-
-
Constructor Details
-
PathfinderManager
Create a new PathfinderManager.All of the Core subcomponents are initialized here as well. Although they should work perfectly fine, if you're getting initialization errors, you're probably doing something wrong with your pathfinder configuration.
- Parameters:
config
- the pathfinder's configuration class.
-
-
Method Details
-
open
public void open()Open thePathfinderManager
's threads and make it start doing its thing. ThePathfinderManager
orPathfinder
MUST be opened before it can be used - not opening thePathfinderManager
will result inNullPointerException
s being thrown. And we all know those aren't very fun. -
merge
public final me.wobblyyyy.edt.DynamicArray<Point> merge(me.wobblyyyy.edt.DynamicArray<me.wobblyyyy.edt.DynamicArray<Point>> paths)Merge several paths into a single path by adding the DynamicArray of points of each of the paths together and then removing any duplicates.This method assumes that any end user already has all of the paths they plan on following in order. If the paths are not in order, the final merged path won't be either.
- Parameters:
paths
- several pre-sorted array lists of target points.- Returns:
- a merged array list of several different paths.
- See Also:
Extra.removeDuplicatePoints(DynamicArray)
-
getPath
Get a path of points between two points.Path generation is expensive in terms of CPU time - don't generate any paths that you don't absolutely need (or want) to.
Generated paths are always notated in Point form. Most controllers and followers would prefer to use HeadingPoint - actually, they require it. In order to convert Point to HeadingPoint, you can use the withHeading() method in conjunction with two HeadingPoint(s) to generate a much more usable list.
- Parameters:
start
- starting position.end
- ending position.- Returns:
- a path between two given points.
- See Also:
GeneratorManager.getCoordinatePath(Point, Point)
-
getWaypointPath
public me.wobblyyyy.edt.DynamicArray<Point> getWaypointPath(me.wobblyyyy.edt.DynamicArray<HeadingPoint> points)Get an extended path between two or more points.This method works by finding individual paths for each waypoint segment and then merging all of the paths together to form a single large path. This is by far the most useful when combined with trajectory following, such as by using the SwerveFollower class.
If the length of the array list of points that have been provided is less than 2, meaning there's only a single point or so, tell the user that they're stupid and COOL - COOL, of course, meaning...
- Constipated
- Over-rated
- Out-of-style
- Loser!
- Parameters:
points
- a list of target points that must be met.- Returns:
- an extended path based off of waypoints.
- See Also:
getPath(HeadingPoint, HeadingPoint)
-
generateFollowers
public me.wobblyyyy.edt.DynamicArray<Follower> generateFollowers(me.wobblyyyy.edt.DynamicArray<HeadingPoint> path)Generate a list of followers to complete a given path.Depending on the selected follower type, the followers that are generated may be slightly different. However, all followers should (hopefully) accomplish the same goal of moving the robot from point A to point B in a fairly reasonable manner.
- Parameters:
path
- a list of points, comprising a path.- Returns:
- a list of followers to follow that path.
- See Also:
PathfinderConfig.getFollowerType()
-
getTrajectoryFollowers
public me.wobblyyyy.edt.DynamicArray<Follower> getTrajectoryFollowers(me.wobblyyyy.edt.Arrayable<Trajectory> trajectories)Get followers for a specified set of trajectories.- Parameters:
trajectories
- the trajectories that should be followed.- Returns:
- generated followers for each of the provided trajectories.
-
generateAndQueueFollowers
Find a path, generate followers, and queue those followers.The path that's generated is later converted to a heading path. If the path is only a single step, which it shouldn't ever be, there may be some issues with the robot's heading.
- Parameters:
start
- the starting position.end
- the ending position.- Returns:
- a chainable PromisedFinder object.
- See Also:
getPath(HeadingPoint, HeadingPoint)
,generateFollowers(DynamicArray)
,FollowerExecutor.queueFollower(Follower)
-
queueFollowers
Don't find any path - instead, simply queue the inputted followers.If you'd like to get a little bit more control over the way followers are handled, you can feel free to manually queue them like this. It's worth noting, however, that this probably isn't the most incredibly fantastical idea, as it can be difficult to ensure everything is happening at the right time, especially in a multi-threaded environment.
- Parameters:
followers
- followers to be queued.- See Also:
FollowerExecutor.queueFollower(Follower)
-
withHeading
public me.wobblyyyy.edt.DynamicArray<HeadingPoint> withHeading(me.wobblyyyy.edt.DynamicArray<Point> points, HeadingPoint start, HeadingPoint end)Convert an DynamicArray of Point instances to an DynamicArray of HeadingPoint instances.If the size of the input list is only 1, it'll have the ending heading.
If the size of the list is greater than 1, the first of the points in the list will have the START heading, and every other point will have the same ending as the END HeadingPoint.
- Parameters:
points
- the list of points.start
- the start point.end
- the end point.- Returns:
- a new array list.
-
goToPosition
Go to a position from the robot's current position.This method finds the robot's current position by getting the odometry system and querying it, and then plans and executes paths and followers to follow along that path.
- Parameters:
end
- the target position.- Returns:
- a chainable PromisedFinder object.
- See Also:
generateAndQueueFollowers(HeadingPoint, HeadingPoint)
-
followPath
Generate a path based on a set of target points, rather than start and end positions.In addition to generating a path along a set of waypoints, this method will begin following the path by adding any generated followers to the follower execution thread's queue.
This method is especially useful when you're making use of trajectories. Generating an extended path to follow and creating a follower designed to run at its maximum possible speed as much as possible ensures that the robot moves incredibly quickly.
- Parameters:
points
- the waypoints that should be used in path generation.- Returns:
- a chainable PromisedFinder object.
- See Also:
followPath(DynamicArray)
-
followPath
Generate a path based on a set of target points, rather than start and end positions.In addition to generating a path along a set of waypoints, this method will begin following the path by adding any generated followers to the follower execution thread's queue.
This method is especially useful when you're making use of trajectories. Generating an extended path to follow and creating a follower designed to run at its maximum possible speed as much as possible ensures that the robot moves incredibly quickly.
- Parameters:
points
- the waypoints that should be used in path generation.- Returns:
- a chainable PromisedFinder object.
- See Also:
getWaypointPath(DynamicArray)
,generateFollowers(DynamicArray)
,queueFollowers(DynamicArray)
-
lock
public void lock()Lock the current thread and prevent it from progressing until the pathfinder's execution thread is idle.This is used in situations such as an autonomous program where you don't know how long the execution of a path will take. You can tell the pathfinder to follow a path or go to a point, then call this method, which will prevent the method from progressing until the pathfinder indicates that it has finished moving.
This can also be used during tele-operated parts of matches - say you'd like to drive the robot to a certain point using the most mathematically optimized route. You can tell the pathfinder to go to your target point and then lock the tele-operated thread until the pathfinder has reached its destination.
This type of code is known as blocking code, meaning that nothing on the current thread can happen until a certain thing has happened.
- See Also:
FollowerExecutor.lock()
-
stopRobot
public void stopRobot()Stop the robot's drivetrain. This is useful when you're trying to make sure the robot stops at a target point - ie, if you don't stop the robot at that target point, it'll miss the point entirely. -
pauseOdometry
public void pauseOdometry()Pause the odometry updater, temporarily stopping it from updating the values of the odometry system based one encoder values.By default, odometry updating is enabled. In order to disable it, you need to pause it. And in order to re-enable it from there, you need to unpause it. Lovely, right?
-
unpauseOdometry
public void unpauseOdometry()Unpause the odometry system, allowing it to function normally once again.By default, odometry updating is enabled. In order to disable it, you need to pause it. And in order to re-enable it from there, you need to unpause it. Lovely, right?
-
getWidth
public int getWidth()Get the width of the robot.- Returns:
- the robot's width.
-
getHeight
public int getHeight()Get the height of the robot.- Returns:
- the robot's height.
-
getSpecificity
public int getSpecificity()Get the specificity of the field.- Returns:
- the field's specificity.
-
getConfig
Get the pathfinder's configuration.- Returns:
- the pathfinder's configuration.
-
close
public void close()Finish this instance of thePathfinderManager
's execution. This will stop any of the threads that are still active, or at least try to do so. Threads spawned by followers can't be managed through here, but follower execution and general execution/odometry updating can be.This method will close both the execution and general pathfinder threads. Before finishing using a pathfinder, remember to call the close methods. Otherwise, you might have dangling threads that can eat up a lot of CPU.
-
tick
public void tick()Tick the Pathfinder once. Ticking it will execute all of the code contained in theFollowerExecutor
as well as odometry update runnable once. You should call this as often as needed while Pathfinder is active. -
getExecutor
Get the pathfinder's follower executor.- Returns:
- the pathfinder's follower executor.
-