From a67da0f8f478314ba2980a3d02196391a4c18f48 Mon Sep 17 00:00:00 2001 From: Ben Scholar Date: Thu, 27 Dec 2018 17:28:28 -0800 Subject: [PATCH 1/2] initial --- src/main/kotlin/org/team5499/monkeyLib/Controller.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/team5499/monkeyLib/Controller.kt b/src/main/kotlin/org/team5499/monkeyLib/Controller.kt index 2ada49a..9680573 100644 --- a/src/main/kotlin/org/team5499/monkeyLib/Controller.kt +++ b/src/main/kotlin/org/team5499/monkeyLib/Controller.kt @@ -1,7 +1,9 @@ package org.team5499.monkeyLib public abstract class Controller { - + /** + * function called to start the controller + */ abstract fun start() abstract fun update() From d9cb150f5723bacb9afee44158a3054aae46d166 Mon Sep 17 00:00:00 2001 From: Sam Bradley Date: Fri, 18 Jan 2019 18:01:22 -0800 Subject: [PATCH 2/2] wrote documentation for auto stuff --- .../org/team5499/monkeyLib/auto/Action.kt | 21 +++++++++++++++ .../team5499/monkeyLib/auto/NothingAction.kt | 4 +++ .../team5499/monkeyLib/auto/ParallelAction.kt | 5 ++++ .../org/team5499/monkeyLib/auto/Routine.kt | 26 ++++++++++++++++++- .../team5499/monkeyLib/auto/SerialAction.kt | 4 +++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/team5499/monkeyLib/auto/Action.kt b/src/main/kotlin/org/team5499/monkeyLib/auto/Action.kt index 7d7dddd..1c062f5 100644 --- a/src/main/kotlin/org/team5499/monkeyLib/auto/Action.kt +++ b/src/main/kotlin/org/team5499/monkeyLib/auto/Action.kt @@ -2,6 +2,10 @@ package org.team5499.monkeyLib.auto import edu.wpi.first.wpilibj.Timer +/** + * A single auto command such as a motor movement, etc to be inserted into a Routine + * @param timeoutSeconds The amount of time to wait before aborting the action + */ public open class Action(timeoutSeconds: Double) { private val mTimer: Timer private val mTimeoutSeconds: Double @@ -11,22 +15,39 @@ public open class Action(timeoutSeconds: Double) { mTimeoutSeconds = timeoutSeconds } + /** + * Called when the action starts + */ public open fun start() { mTimer.stop() mTimer.reset() mTimer.start() } + /** + * Called every tick while the action is active + */ public open fun update() {} + /** + * Checks if this action has timed out. + * @return Is timed out? + */ protected fun timedOut(): Boolean { val t = mTimer.get() return (t >= mTimeoutSeconds) } + /** + * Checks if this action is finished and ready to move on to the next one + * @return Is finished? + */ public open fun next(): Boolean { return timedOut() } + /** + * Called when the auto command is finished in order clean up resources + */ public open fun finish() {} } diff --git a/src/main/kotlin/org/team5499/monkeyLib/auto/NothingAction.kt b/src/main/kotlin/org/team5499/monkeyLib/auto/NothingAction.kt index 421c20c..2a94c3f 100644 --- a/src/main/kotlin/org/team5499/monkeyLib/auto/NothingAction.kt +++ b/src/main/kotlin/org/team5499/monkeyLib/auto/NothingAction.kt @@ -1,3 +1,7 @@ package org.team5499.monkeyLib.auto +/** + * This Action does nothing. Use it as a delay between actions. + * @param timeout How long to wait before proceeding + */ public class NothingAction(timeout: Double) : Action(timeout) diff --git a/src/main/kotlin/org/team5499/monkeyLib/auto/ParallelAction.kt b/src/main/kotlin/org/team5499/monkeyLib/auto/ParallelAction.kt index 564c70c..b801dc6 100644 --- a/src/main/kotlin/org/team5499/monkeyLib/auto/ParallelAction.kt +++ b/src/main/kotlin/org/team5499/monkeyLib/auto/ParallelAction.kt @@ -1,5 +1,10 @@ package org.team5499.monkeyLib.auto +/** + * An action that runs multiple Actions at once + * @param actions The Actions to run + */ + class ParallelAction(vararg actions: Action) : Action(0.0) { private val mActions: Array diff --git a/src/main/kotlin/org/team5499/monkeyLib/auto/Routine.kt b/src/main/kotlin/org/team5499/monkeyLib/auto/Routine.kt index f252dd8..2459767 100644 --- a/src/main/kotlin/org/team5499/monkeyLib/auto/Routine.kt +++ b/src/main/kotlin/org/team5499/monkeyLib/auto/Routine.kt @@ -2,6 +2,12 @@ package org.team5499.monkeyLib.auto import org.team5499.monkeyLib.math.geometry.Rotation2d +/** + * A list of Actions to run sequentially + * @param name The name of the routine + * @param startHeading The rotation the robot starts (used to callibrate gyro) + * @param actions The actions to run, in order of execution + */ class Routine(name: String, startHeading: Rotation2d, vararg actions: Action) { val actions: Array @@ -27,10 +33,18 @@ class Routine(name: String, startHeading: Rotation2d, vararg actions: Action) { vararg actions: Action ): this(name, Rotation2d.fromDegrees(degreesHeading), *actions) + /** + * Returns the action the robot is currently executing + * @return Current action + */ public fun getCurrentAction(): Action { return actions.get(stepNumber) } + /** + * Forces the robot to move to the next action + * @return Is the last step in the routine + */ public fun advanceRoutine(): Boolean { if (isLastStep()) { return false @@ -39,14 +53,24 @@ class Routine(name: String, startHeading: Rotation2d, vararg actions: Action) { return true } + /** + * Abort the current action and run the sequence from the given action index + */ public fun setActionIndex(index: Int) { stepNumber = index } + /** + * Reset to the first action + */ public fun reset() { - this.stepNumber = 0 + stepNumber = 0 } + /** + * Gets whether the sequence is currently on it's last step + * @return is last step? + */ public fun isLastStep(): Boolean { return (stepNumber >= (actions.size - 1)) } diff --git a/src/main/kotlin/org/team5499/monkeyLib/auto/SerialAction.kt b/src/main/kotlin/org/team5499/monkeyLib/auto/SerialAction.kt index baa0a55..d80424e 100644 --- a/src/main/kotlin/org/team5499/monkeyLib/auto/SerialAction.kt +++ b/src/main/kotlin/org/team5499/monkeyLib/auto/SerialAction.kt @@ -1,6 +1,10 @@ package org.team5499.monkeyLib.auto +/** + * An Action that runs multiple actions sequentially + * @param actions The actions to run + */ public class SerialAction(vararg actions: Action) : Action(0.0) { private val childActions: Array