Skip to content

Commit d994b78

Browse files
add: NextFTC Pedro Extension (#1)
* refactor: remove unit and instrumented tests from pedro module * chore: change group id to dev.nextftc.extensions * feat: add PedroComponent * chore: remove unused import in build.gradle.kts * feat: add FollowPath * feat: add PedroComponent.gyro * feat: add PedroDriverControlled * feat: add Turn and TurnTo * fix: move files from src/main to src/main/kotlin * feat: add descriptive name to Turn and TurnTo - name of Turn is Turn(angle) - name of TurnTo is TurnTo(angle) * refactor: change PedroComponent to an object * fix: make PedroComponent a class again * fix(pedro): fix gradle - make displayName and description correct - use versions.pedro property for version * refactor: rename Turn to TurnBy * fix: rename Turn to TurnBy in the command name --------- Co-authored-by: Zach Harel <zach@zharel.me>
1 parent 730ed92 commit d994b78

11 files changed

Lines changed: 144 additions & 49 deletions

File tree

.idea/misc.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ plugins {
1212
}
1313

1414
allprojects {
15-
version = property("version") as String
1615
group = "dev.nextftc.extensions"
1716
}
1817

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ automaticMavenCentralSync=true
66

77
android.useAndroidX=true
88

9-
versions.roadrunner=0.1.25-1-local.3
9+
versions.roadrunner=1.0.0
10+
versions.pedro=1.0.0

pedro/build.gradle.kts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ dependencies {
3030
implementation(libs.bundles.nextftc)
3131
implementation(libs.pedro)
3232
compileOnly(libs.bundles.ftc)
33-
34-
testImplementation(libs.bundles.kotest)
35-
testImplementation(libs.mockk)
3633
}
3734

35+
version = property("versions.pedro") as String
3836
description =
39-
"The hardware library for NextFTC, a user-friendly library for FTC. Includes hardware interfaces, wrapper implementations, and hardware commands."
37+
"NextFTC's extension to add support for Pedro Pathing."
4038

4139
nextFTCPublishing {
42-
displayName = "NextFTC Hardware"
40+
displayName = "NextFTC Extensions - Pedro"
4341
logoPath = "../assets/logo-icon.svg"
4442
}

pedro/src/androidTest/java/dev/nextftc/extensions/ExampleInstrumentedTest.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.nextftc.extensions.pedro
2+
3+
import com.pedropathing.paths.Path
4+
import com.pedropathing.paths.PathChain
5+
import dev.nextftc.core.commands.Command
6+
import dev.nextftc.extensions.pedro.PedroComponent.Companion.follower
7+
8+
class FollowPath @JvmOverloads constructor(
9+
private val path: PathChain,
10+
private val holdEnd: Boolean? = null,
11+
private val maxPower: Double? = null
12+
) : Command() {
13+
14+
init {
15+
require(maxPower == null || holdEnd != null) { "If maxPower is passed, holdEnd must be passed as well." }
16+
}
17+
18+
@JvmOverloads
19+
constructor(path: Path, holdEnd: Boolean? = null, maxPower: Double? = null) : this(
20+
PathChain(path),
21+
holdEnd,
22+
maxPower
23+
)
24+
25+
override val isDone: Boolean
26+
get() = !follower.isBusy
27+
28+
override fun start() {
29+
if (holdEnd !== null && maxPower !== null) follower.followPath(path, maxPower, holdEnd)
30+
else if (holdEnd !== null) follower.followPath(path, holdEnd)
31+
else follower.followPath(path)
32+
}
33+
34+
override fun stop(interrupted: Boolean) {
35+
if (interrupted) follower.breakFollowing()
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.nextftc.extensions.pedro
2+
3+
import com.pedropathing.follower.Follower
4+
import com.qualcomm.robotcore.hardware.HardwareMap
5+
import dev.nextftc.core.components.Component
6+
import dev.nextftc.core.units.Angle
7+
import dev.nextftc.core.units.rad
8+
import dev.nextftc.ftc.ActiveOpMode
9+
import java.util.function.Supplier
10+
11+
class PedroComponent(private val followerFactory: (HardwareMap) -> Follower) : Component {
12+
13+
override fun preInit() {
14+
_follower = followerFactory(ActiveOpMode.hardwareMap)
15+
}
16+
17+
override fun preWaitForStart() = follower.update()
18+
override fun preUpdate() = follower.update()
19+
20+
override fun postStop() {
21+
_follower = null
22+
}
23+
24+
companion object {
25+
private var _follower: Follower? = null
26+
27+
@get:JvmName("follower")
28+
@JvmStatic
29+
val follower: Follower
30+
get() = _follower ?: error("Follower not initialized! Make sure you added PedroComponent to your OpMode.")
31+
32+
@get:JvmName("gyro")
33+
@JvmStatic
34+
val gyro: Supplier<Angle> = Supplier { follower.totalHeading.rad.normalized }
35+
36+
}
37+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package dev.nextftc.extensions.pedro
2+
3+
import dev.nextftc.extensions.pedro.PedroComponent.Companion.follower
4+
import dev.nextftc.hardware.driving.DriverControlledCommand
5+
import java.util.function.Supplier
6+
7+
class PedroDriverControlled @JvmOverloads constructor(
8+
drivePower: Supplier<Double>,
9+
strafePower: Supplier<Double>,
10+
turnPower: Supplier<Double>,
11+
private val robotCentric: Boolean = true
12+
) : DriverControlledCommand(drivePower, strafePower, turnPower) {
13+
14+
override fun start() {
15+
follower.startTeleopDrive()
16+
}
17+
18+
override fun calculateAndSetPowers(powers: DoubleArray) {
19+
val (drive, strafe, turn) = powers
20+
follower.setTeleOpDrive(drive, strafe, turn, robotCentric)
21+
}
22+
23+
override fun stop(interrupted: Boolean) {
24+
if (interrupted) follower.breakFollowing()
25+
}
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package dev.nextftc.extensions.pedro
2+
3+
import dev.nextftc.core.commands.Command
4+
import dev.nextftc.core.units.Angle
5+
import dev.nextftc.core.units.abs
6+
import dev.nextftc.extensions.pedro.PedroComponent.Companion.follower
7+
8+
class TurnBy(private val angle: Angle) : Command() {
9+
10+
init {
11+
named("TurnBy($angle)")
12+
}
13+
14+
override val isDone: Boolean
15+
get() = !follower.isTurning
16+
17+
override fun start() {
18+
follower.turn(abs(angle).inRad, angle.sign > 0)
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package dev.nextftc.extensions.pedro
2+
3+
import dev.nextftc.core.commands.Command
4+
import dev.nextftc.core.units.Angle
5+
import dev.nextftc.extensions.pedro.PedroComponent.Companion.follower
6+
7+
class TurnTo(private val angle: Angle) : Command() {
8+
9+
init {
10+
named("TurnTo($angle)")
11+
}
12+
13+
override val isDone: Boolean
14+
get() = !follower.isTurning
15+
16+
override fun start() {
17+
follower.turnTo(angle.inRad)
18+
}
19+
}

0 commit comments

Comments
 (0)