-
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.
- Loading branch information
1 parent
345ca4b
commit aa4a11a
Showing
5 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/frc/team449/control/holonomic/OdometryThread.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package frc.team449.control.holonomic | ||
|
||
import edu.wpi.first.wpilibj.Notifier | ||
import frc.team449.robot2024.constants.RobotConstants | ||
import java.util.Queue | ||
import java.util.concurrent.ArrayBlockingQueue | ||
import java.util.concurrent.locks.ReentrantLock | ||
import java.util.function.DoubleSupplier | ||
|
||
|
||
open class OdometryThread ( | ||
val odometryLock: ReentrantLock | ||
) { | ||
private var signals = ArrayList<DoubleSupplier>() | ||
private var queues = ArrayList<Queue<Double>>() | ||
private var notifier = Notifier { this.periodic() } | ||
|
||
init { | ||
notifier.setName("OdometryThread") | ||
notifier.startPeriodic(1.0 / RobotConstants.ODOMETRY_FREQUENCY) | ||
} | ||
|
||
open fun registerSignal(signal: DoubleSupplier): Queue<Double> { | ||
val queue: Queue<Double> = ArrayBlockingQueue(100) | ||
odometryLock.lock() | ||
try { | ||
signals.add(signal) | ||
queues.add(queue) | ||
} finally { | ||
odometryLock.unlock() | ||
} | ||
return queue | ||
} | ||
|
||
private fun periodic() { | ||
odometryLock.lock() | ||
try { | ||
for (i in signals.indices) { | ||
queues[i].add(signals[i].asDouble) | ||
} | ||
} finally { | ||
odometryLock.unlock() | ||
} | ||
} | ||
} |
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
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