Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/kotlin/org/team5499/monkeyLib/Controller.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.team5499.monkeyLib

public abstract class Controller {

/**
* function called to start the controller
*/
abstract fun start()

abstract fun update()
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/org/team5499/monkeyLib/auto/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/org/team5499/monkeyLib/auto/NothingAction.kt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions src/main/kotlin/org/team5499/monkeyLib/auto/ParallelAction.kt
Original file line number Diff line number Diff line change
@@ -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<out Action>
Expand Down
26 changes: 25 additions & 1 deletion src/main/kotlin/org/team5499/monkeyLib/auto/Routine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<out Action>
Expand All @@ -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
Expand All @@ -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))
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/org/team5499/monkeyLib/auto/SerialAction.kt
Original file line number Diff line number Diff line change
@@ -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<out Action>
Expand Down