Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task deps #201

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ abstract class Arm {
override def onEnd(): Unit = {
arm.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(arm)
}

//move arm above target using bangbang control. When it is above target, run inner (finite) task.
Expand All @@ -76,6 +78,8 @@ abstract class Arm {
})
}
override def onEnd(): Unit = arm.resetToDefault()

override val dependencies: Set[Component[_]] = Set(arm)
}

//move arm below target using bangbang control. When it is below target, run inner (finite) task.
Expand All @@ -92,6 +96,8 @@ abstract class Arm {
})
}
override def onEnd(): Unit = arm.resetToDefault()

override val dependencies: Set[Component[_]] = Set(arm)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}


Expand All @@ -46,6 +48,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class ContinuousVelocityDrive(forward: Stream[Velocity], turn: Stream[AngularVelocity])
Expand All @@ -60,6 +64,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class DriveDistance(distance: Length, tolerance: Length)
Expand All @@ -82,6 +88,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class DriveDistanceWithTrapezoidalProfile(cruisingVelocity: Velocity,
Expand Down Expand Up @@ -128,6 +136,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

/**
Expand Down Expand Up @@ -198,6 +208,8 @@ trait UnicycleCoreTasks {
stableTicks = 0
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class DriveDistanceAtAngle(distance: Length,
Expand Down Expand Up @@ -236,6 +248,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class DriveBeyondStraight(distance: Length,
Expand Down Expand Up @@ -290,6 +304,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}


Expand Down Expand Up @@ -324,6 +340,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class RotateToAngle(absoluteAngle: Angle, tolerance: Angle)
Expand All @@ -344,6 +362,8 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class CorrectOffsetWithLatency(timestampedOffset: Stream[(Angle, Time)], tolerance: Angle)
Expand Down Expand Up @@ -384,9 +404,11 @@ trait UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class DriveToTargetWithConstantSpeed(drivetrainComponent: Drivetrain,
class DriveToTargetWithConstantSpeed(drive: Drivetrain,
distanceToTarget: Stream[Option[Length]],
angleToTarget: Stream[Angle],
forwardVelocity: Dimensionless,
Expand All @@ -408,7 +430,7 @@ trait UnicycleCoreTasks {
}
)

drivetrainComponent.setController(out.withCheckZipped(distanceToTarget){
drive.setController(out.withCheckZipped(distanceToTarget){
distanceToTarget => {
if (distanceToTarget.exists(_ <= minDistance)) {
finished()
Expand All @@ -418,7 +440,9 @@ trait UnicycleCoreTasks {
}

override def onEnd(): Unit = {
drivetrainComponent.resetToDefault()
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.lynbrookrobotics.potassium.commons.drivetrain.unicycle.control.purePursuit

import com.lynbrookrobotics.potassium.Signal
import com.lynbrookrobotics.potassium.{Component, Signal}
import com.lynbrookrobotics.potassium.commons.cartesianPosition.XYPosition
import com.lynbrookrobotics.potassium.commons.drivetrain.unicycle.control.UnicycleCoreTasks
import com.lynbrookrobotics.potassium.streams.Stream
Expand Down Expand Up @@ -65,6 +65,8 @@ trait PurePursuitTasks extends UnicycleCoreTasks {

absoluteFollow = null
}

override val dependencies: Set[Component[_]] = Set(drive)
}

class FollowWayPointsWithPosition(wayPoints: Seq[Point],
Expand Down Expand Up @@ -108,5 +110,7 @@ trait PurePursuitTasks extends UnicycleCoreTasks {
override def onEnd(): Unit = {
drive.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(drive)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ abstract class DoubleFlywheel {
override def onEnd(): Unit = {
doubleFlywheel.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(doubleFlywheel)
}

class WhileAtDoubleVelocity(leftVel: Stream[Frequency], rightVel: Stream[Frequency], tolerance: Frequency)
Expand All @@ -110,6 +112,8 @@ abstract class DoubleFlywheel {
override def onEnd(): Unit = {
doubleFlywheel.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(doubleFlywheel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ abstract class Flywheel {
override def onEnd(): Unit = {
flywheel.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(flywheel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ abstract class Lift {
override def onEnd(): Unit = {
lift.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(lift)
}

//move arm above target using bangbang control. When it is above target, run inner (finite) task.
Expand All @@ -99,6 +101,8 @@ abstract class Lift {
}

override def onEnd(): Unit = lift.resetToDefault()

override val dependencies: Set[Component[_]] = Set(lift)
}

//move arm below target using bangbang control. When it is below target, run inner (finite) task.
Expand All @@ -116,6 +120,8 @@ abstract class Lift {
}

override def onEnd(): Unit = lift.resetToDefault()

override val dependencies: Set[Component[_]] = Set(lift)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ abstract class Position[S <: Quantity[S],
override def onEnd(): Unit = {
comp.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(comp)
}

class HoldPosition(pos: S)(implicit properties: Signal[Properties], hardware: Hardware, comp: Comp) extends ContinuousTask {
Expand All @@ -71,6 +73,8 @@ abstract class Position[S <: Quantity[S],
override def onEnd(): Unit = {
comp.resetToDefault()
}

override val dependencies: Set[Component[_]] = Set(comp)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class OffloadedLiftTaskTest extends FunSuite {
}

override protected def onEnd() = Unit

override val dependencies: Set[Component[_]] = Set()
}

val task = new lift.positionTasks.WhileAbovePosition(
Expand Down Expand Up @@ -145,6 +147,8 @@ class OffloadedLiftTaskTest extends FunSuite {
}

override protected def onEnd() = Unit

override val dependencies: Set[Component[_]] = Set()
}

val task = new lift.positionTasks.WhileBelowPosition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class ContinuousEvent {
*/
def foreach(task: ContinuousTask): Unit = {
onStart.foreach { () =>
Task.abortCurrentTask()
Task.executeTask(task)
}

Expand All @@ -80,8 +79,6 @@ class ContinuousEvent {
var currentRunningTask: ContinuousTask = null

onStart.foreach { () =>
Task.abortCurrentTask()

currentRunningTask = task.get

Task.executeTask(currentRunningTask)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.lynbrookrobotics.potassium.tasks
import com.lynbrookrobotics.potassium.Component

/**
* A finite task where a continuous task is run while a finite task is running
Expand Down Expand Up @@ -28,4 +29,6 @@ class AndUntilDoneTask private[tasks](first: FiniteTask, second: ContinuousTask)

second.abort()
}

override val dependencies: Set[Component[_]] = first.dependencies ++ second.dependencies
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.lynbrookrobotics.potassium.tasks

import com.lynbrookrobotics.potassium.Component
import com.lynbrookrobotics.potassium.clock.Clock
import squants.Time

/**
* Represents a task that can only be stopped by an external impulse.
*/
abstract class ContinuousTask extends Task {
private var running = false
def isRunning: Boolean = running
protected def onStart(): Unit
protected def onEnd(): Unit

Expand All @@ -22,12 +25,22 @@ abstract class ContinuousTask extends Task {
/**
* Starts the continuous task.
*/
override def init(): Unit = onStart()
override def init(): Unit = {
if (!running) {
running = true
onStart()
}
}

/**
* Stops the continuous task.
*/
override def abort(): Unit = onEnd()
override def abort(): Unit = {
if (running) {
onEnd()
running = false
}
}

/**
* Returns a FiniteTask of this ContinuousTask running for the given duration
Expand All @@ -44,5 +57,7 @@ object ContinuousTask {
override protected def onStart(): Unit = {}

override protected def onEnd(): Unit = {}

override val dependencies: Set[Component[_]] = Set()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lynbrookrobotics.potassium.tasks

import com.lynbrookrobotics.potassium.Component
import com.lynbrookrobotics.potassium.clock.Clock
import squants.Time

Expand Down Expand Up @@ -112,6 +113,8 @@ abstract class FiniteTask extends Task { self =>
override def onStart() = self.init()

override def onEnd() = self.abort()

override val dependencies: Set[Component[_]] = self.dependencies
}
}

Expand All @@ -120,5 +123,7 @@ object FiniteTask {
override def onStart(): Unit = finished()

override def onEnd(): Unit = {}

override val dependencies: Set[Component[_]] = Set()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.lynbrookrobotics.potassium.tasks
import com.lynbrookrobotics.potassium.Component

/**
* A continuous task where two subtasks are run in parallel
Expand All @@ -16,4 +17,6 @@ class ParallelContinuousTask private[tasks](first: ContinuousTask, second: Conti
first.abort()
second.abort()
}

override val dependencies: Set[Component[_]] = first.dependencies ++ second.dependencies
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.lynbrookrobotics.potassium.tasks
import com.lynbrookrobotics.potassium.Component

/**
* A finite task where two subtasks are run in parallel
Expand Down Expand Up @@ -30,4 +31,6 @@ class ParallelFiniteTask private[tasks] (first: FiniteTask, second: FiniteTask)
second.abort()
}
}

override val dependencies: Set[Component[_]] = first.dependencies ++ second.dependencies
}
Loading