-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add lambda constructors * Version bump
- Loading branch information
Showing
4 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 13 additions & 11 deletions
24
src/main/kotlin/org/team5499/monkeyLib/input/SpaceDriveHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
package org.team5499.monkeyLib.input | ||
|
||
public class SpaceDriveHelper(deadband: Double, turnMult: Double, slowMult: Double) : DriveHelper() { | ||
public class SpaceDriveHelper(deadband: () -> Double, turnMult: () -> Double, slowMult: () -> Double) : DriveHelper() { | ||
|
||
private val mDeadband: Double | ||
private val mTurnMult: Double | ||
private val mSlowMult: Double | ||
private var mDeadband: () -> Double | ||
private var mTurnMult: () -> Double | ||
private var mSlowMult: () -> Double | ||
|
||
init { | ||
mDeadband = deadband | ||
mTurnMult = turnMult | ||
mSlowMult = slowMult | ||
mDeadband = { deadband() } | ||
mTurnMult = { turnMult() } | ||
mSlowMult = { slowMult() } | ||
} | ||
|
||
constructor(deadband: Double, turnMult: Double, slowMult: Double) : this({ deadband }, { turnMult }, { slowMult }) | ||
|
||
public override fun calculateOutput( | ||
throttle: Double, | ||
wheel: Double, | ||
isQuickTurn: Boolean, | ||
creep: Boolean | ||
): DriveSignal { | ||
val newThottle = super.handleDeadband(throttle, mDeadband) | ||
var newWheel = super.handleDeadband(wheel, mDeadband) | ||
val mult = if (!isQuickTurn) mTurnMult else 1.0 | ||
val newThottle = super.handleDeadband(throttle, mDeadband()) | ||
var newWheel = super.handleDeadband(wheel, mDeadband()) | ||
val mult = if (!isQuickTurn) mTurnMult() else 1.0 | ||
newWheel *= mult | ||
val slow = if (creep) mSlowMult else 1.0 | ||
val slow = if (creep) mSlowMult() else 1.0 | ||
return DriveSignal(slow * (newThottle + newWheel), slow * (newThottle - newWheel)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters