1+ package org.firstinspires.ftc.teamcode.opmode.test.pedro
2+
3+ import com.bylazar.configurables.PanelsConfigurables
4+ import com.bylazar.configurables.annotations.Configurable
5+ import com.millburnx.cmdx.Command
6+ import com.millburnx.cmdx.commandGroups.Sequential
7+ import com.millburnx.cmdxpedro.paths.heading.TangentialHeading
8+ import com.millburnx.cmdxpedro.paths.path.Path
9+ import com.millburnx.cmdxpedro.util.mirror
10+ import com.millburnx.cmdxpedro.util.toPedro
11+ import com.millburnx.util.vector.Vec2d
12+ import com.pedropathing.geometry.BezierCurve
13+ import com.pedropathing.paths.PathBuilder
14+ import com.qualcomm.robotcore.eventloop.opmode.TeleOp
15+ import org.firstinspires.ftc.teamcode.common.subsystem.TeleOpDrive
16+ import org.firstinspires.ftc.teamcode.opmode.OpMode
17+ import org.firstinspires.ftc.teamcode.opmode.auton.BaseAutonManager
18+ import org.firstinspires.ftc.teamcode.pedro.Tuning
19+
20+ @Configurable
21+ @TeleOp
22+ class CentripetalTest : OpMode () {
23+ override fun run () {
24+ PanelsConfigurables .refreshClass(Tuning ::class .java)
25+
26+ val drive = TeleOpDrive (this , true )
27+
28+ val autonManager = BaseAutonManager (this , drive, false )
29+
30+ val forward = {
31+ autonManager.builder.PathCommand (
32+ drive.follower, NthBezier (
33+ listOf (
34+ Vec2d (0.0 , 0.0 ),
35+ Vec2d (distance, distance),
36+ Vec2d (distance, 0.0 ),
37+ )
38+ ),
39+ TangentialHeading (false ),
40+ { ! isStopRequested }
41+ )
42+ }
43+ val backward = {
44+ autonManager.builder.PathCommand (
45+ drive.follower, NthBezier (
46+ listOf (
47+ Vec2d (distance, 0.0 ),
48+ Vec2d (distance, distance),
49+ Vec2d (0.0 , 0.0 ),
50+ )
51+ ),
52+ TangentialHeading (true ),
53+ { ! isStopRequested }
54+ )
55+ }
56+
57+ var isBusy = false
58+
59+ scheduler.schedule(
60+ Command {
61+ while (! isStopRequested) {
62+ if (! gp1.prev.rightBumper && gp1.current.rightBumper) {
63+ isRunning = ! isRunning
64+ }
65+ if (! isBusy && isRunning) {
66+ isBusy = true
67+ scheduler.schedule(Sequential {
68+ + forward()
69+ + backward()
70+ Command { isBusy = false }
71+ })
72+ }
73+ sync()
74+ }
75+ }
76+ )
77+ }
78+
79+ companion object {
80+ @JvmField
81+ var distance = 48.0
82+
83+ @JvmField
84+ var isRunning = false
85+ }
86+ }
87+
88+ private data class NthBezier (
89+ val points : List <Vec2d >
90+ ) : Path {
91+ override fun register (pathBuilder : PathBuilder , mirrored : Boolean ): PathBuilder {
92+ return pathBuilder.apply {
93+ addPath(
94+ BezierCurve (
95+ * points.map { it.mirror(mirrored).toPedro() }.toTypedArray()
96+ )
97+ )
98+ }
99+ }
100+ }
0 commit comments