Class FollowerExecutor
public class FollowerExecutor
extends java.lang.Object
In order to compensate for the computationally-expensive nature of complex pathfinding and trajectory generation, important following code is offloaded to a secondary thread. This ensures that the main thread stays freed enough to allow a user to still have control over the program.
As with any threaded things, however, they suck to conceptualize. The aim of this class is to make it easier to follow along with how the pathfinder actually generates and follows paths and trajectories.
- Since:
- 0.1.0
- Author:
- Colin Robertson
- 
Field SummaryFields Modifier and Type Field Description private me.wobblyyyy.edt.StaticArray<java.lang.Runnable>actionsActions to execute.private DrivedriveThe robot's drivetrain.private java.lang.RunnableexecutorExecution thread.private java.util.ArrayList<Follower>followersThe currently-executed followers.private me.wobblyyyy.edt.DynamicArray<Follower>hasCalculatedA list of all of the followers that have run their calculation method already.private booleanshouldRunShould the thread continue its execution.
- 
Constructor SummaryConstructors Constructor Description FollowerExecutor(Drive drive)Create a new follower executor and initialize the executor thread.
- 
Method SummaryModifier and Type Method Description voidaddActions()Thread-safe method to generate actions.voidclear()Clear all of the followers and runnables, essentially resetting the FollowerExecutor instance.voidclearActions()Thread-safe method to clear all of the actions.voidclose()Stop thisFollowerExecutor's execution, or at least attempt to do so.me.wobblyyyy.edt.StaticArray<java.lang.Runnable>generateRunnables()Generate a list of Runnable elements to be executed by the execution thread.me.wobblyyyy.edt.StaticArray<java.lang.Runnable>getActions()Thread-safe way to get all of the actions.booleanisEmpty()Check whether or not both of the follower array lists are empty, indicating that there's nothing for the pathfinder to do.voidlock()Lock the current thread until the pathfinder has finished its execution.private java.lang.RunnablemoveUp(Follower f)Generate a Runnable that can be executed to progress past the current follower and onto the next one.voidqueueFollower(Follower f)Queue a single follower element.voidqueueFollowers(me.wobblyyyy.edt.DynamicArray<Follower> followers)Queue a collection of follower elements.voidstart()Start the follower executor's thread.voidstop()Stop the follower executor's thread.voidtick()Run the follower executor once.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Field Details- 
executorprivate final java.lang.Runnable executorExecution thread.
- 
followersThe currently-executed followers.
- 
hasCalculatedA list of all of the followers that have run their calculation method already.Depending on for how long the pathfinder is run for, this array list may eventually overflow. In order to compensate for this potential overflow, we should add some code that clears this list at some point. 
- 
actionsprivate me.wobblyyyy.edt.StaticArray<java.lang.Runnable> actionsActions to execute. MUST BE THREAD SAFE!Modification should only be handled through synchronized methods to ensure no bad stuff happens. 
- 
shouldRunprivate boolean shouldRunShould the thread continue its execution.
- 
driveThe robot's drivetrain.This is used for enabling and disabling user control when the pathfinder is enabled or disabled. 
 
- 
- 
Constructor Details- 
FollowerExecutorCreate a new follower executor and initialize the executor thread.PLEASE NOTE: Nothing's going to happen after you construct a new instance of this executor. The thread must be enabled with the start method prior to having any function. To disable the thread, you can run the stop method. At this point, the thread hasn't been started yet. If you're interfacing directly with this class rather than using a pathfinder manager instance as a proxy, you'll need to remember to start the threads before trying to follow paths. - Parameters:
- drive- the robot's drivetrain.
 
 
- 
- 
Method Details- 
startpublic void start()Start the follower executor's thread.Threads should not be started after they're already running. 
- 
tickpublic void tick()Run the follower executor once.
- 
stoppublic void stop()Stop the follower executor's thread.Thread.stop() has been a deprecated method for a while - is there an effective alternative we can use? THIS DOES NOT ACTUALLY STOP THE THREAD! Rather, it updates the flag indicating whether or not the follower should be run as intended. 
- 
getActionspublic me.wobblyyyy.edt.StaticArray<java.lang.Runnable> getActions()Thread-safe way to get all of the actions.- Returns:
- actions to be executed.
 
- 
addActionspublic void addActions()Thread-safe method to generate actions.
- 
clearActionspublic void clearActions()Thread-safe method to clear all of the actions.
- 
clearpublic void clear()Clear all of the followers and runnables, essentially resetting the FollowerExecutor instance.
- 
generateRunnablespublic me.wobblyyyy.edt.StaticArray<java.lang.Runnable> generateRunnables()Generate a list of Runnable elements to be executed by the execution thread.If a follower has not finished its execution yet, we disable user control for the robot's drivetrain as a precautionary measure. If the follower HAS finished its execution, we can then enable user control once again. - Returns:
- to-be-executed Runnable elements.
 
- 
moveUpGenerate a Runnable that can be executed to progress past the current follower and onto the next one.- Parameters:
- f- the current follower.
- Returns:
- a Runnable to move upwards in the execution order.
 
- 
queueFollowerQueue a single follower element.Queuing followers isn't a complicated process. Note, however, that if the thread that executes the followers IS NOT active, nothing will actually happen to the followers. After a follower has been queued, it won't take effect immediately. After the current bank of followers has been exhausted, it'll move on to newly-queued followers, such as the follower that you may have just provided. How cool! - Parameters:
- f- the follower to queue.
 
- 
queueFollowersQueue a collection of follower elements.Queuing followers isn't a complicated process. Note, however, that if the thread that executes the followers IS NOT active, nothing will actually happen to the followers. After a follower has been queued, it won't take effect immediately. After the current bank of followers has been exhausted, it'll move on to newly-queued followers, such as the follower that you may have just provided. How cool! - Parameters:
- followers- the follower elements to queue.
 
- 
isEmptypublic boolean isEmpty()Check whether or not both of the follower array lists are empty, indicating that there's nothing for the pathfinder to do.- Returns:
- whether or not the pathfinder is idle.
 
- 
lockpublic void lock()Lock the current thread until the pathfinder has finished its execution.Unfortunately, we can't use a Thread.join() like method because of the way Pathfinder handles multithreading, especially path following. This should be (roughly) the same. As a locking operation, the calling thread will not be able to progress until the execution of this thread has finished. If you'd like to queue another follower while the system is active, you can do so. Yay! 
- 
closepublic void close()Stop thisFollowerExecutor's execution, or at least attempt to do so. This method won't actually stop the execution of the thread - rather, it'll signal the thread's execution to come to a stop.- See Also:
- stop()
 
 
-