|
| 1 | +# Pedro Pathing Extension |
| 2 | + |
| 3 | +::: info |
| 4 | +This guide is a work-in-progress. |
| 5 | +Check back later for updates! |
| 6 | +::: |
| 7 | + |
| 8 | +This extension provides integration with the |
| 9 | +[Pedro Pathing Library](https://pedropathing.com/), |
| 10 | +allowing you to use its features within your NextFTC projects. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +To install the Pedro Pathing extension, |
| 15 | +add the following line to your `build.gradle` file: |
| 16 | + |
| 17 | +```groovy |
| 18 | +implementation 'dev.nextftc.extensions:pedro:1.0.0' |
| 19 | +``` |
| 20 | + |
| 21 | +::: warning |
| 22 | +Version `1.0.0` supports Pedro Pathing `2.0.0`, |
| 23 | +and is not compatible with earlier versions. |
| 24 | +::: |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +### `PedroComponent` |
| 29 | + |
| 30 | +To use the Pedro Pathing extension, |
| 31 | +add a `PedroComponent` object to the `addComponents` call |
| 32 | +in your `NextFtcOpMode`, using `createFollower` from your |
| 33 | +`Constants` class. |
| 34 | + |
| 35 | +::: tabs key:code |
| 36 | + |
| 37 | +== Kotlin |
| 38 | +```kotlin |
| 39 | +class MyOpModeKt : NextFTCOpMode() { |
| 40 | + init { |
| 41 | + addComponents( |
| 42 | + PedroComponent(Constants::createFollower) |
| 43 | + ) |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +== Java |
| 49 | +```java |
| 50 | +public class MyOpModeJava extends NextFTCOpMode { |
| 51 | + public MyOpModeJava() { |
| 52 | + addComponents( |
| 53 | + new PedroComponent(Constants::createFollower) |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | +::: |
| 59 | + |
| 60 | +### The Follower |
| 61 | + |
| 62 | +Once you've added the `PedroComponent`, |
| 63 | +you can access the `Follower` instance |
| 64 | +as a static property of the `PedroComponent` class |
| 65 | +(`PedroComponent.follower` in Kotlin, or `PedroComponent.follower()` in Java). |
| 66 | + |
| 67 | +### Creating Path Commands |
| 68 | + |
| 69 | +To create path commands, you can use the `FollowPath` command, |
| 70 | +passing in a `Path` or a `PathChain` argument. |
| 71 | + |
| 72 | +::: tabs key:code |
| 73 | +== Kotlin |
| 74 | +```kotlin |
| 75 | +private val startPose = Pose(9.0, 111.0, Math.Math.toRadians(-90.0)) |
| 76 | +private val scorePose = Pose(16.0, 128.0, Math.Math.toRadians(-45.0)) |
| 77 | +private val pickup1Pose = Pose(30.0, 121.0, Math.Math.toRadians(0.0)) |
| 78 | +private val pickup2Pose = Pose(30.0, 131.0, Math.Math.toRadians(0.0)) |
| 79 | +private val pickup3Pose = Pose(45.0, 128.0, Math.Math.toRadians(90.0)) |
| 80 | +private val parkPose = Pose(68.0, 96.0, Math.Math.toRadians(-90.0)) |
| 81 | + |
| 82 | +class MyOpModeKt : NextFTCOpMode() { |
| 83 | + init { |
| 84 | + addComponents( |
| 85 | + PedroComponent(Constants::createFollower) |
| 86 | + ) |
| 87 | + } |
| 88 | + |
| 89 | + val pathCommand = FollowPath(PedroComponent.follower.pathBuilder() |
| 90 | + .addPath(BezierLine(startPose, scorePose)) |
| 91 | + .setLinearHeadingInterpolation(startPose.heading, scorePose.heading) |
| 92 | + .build()) |
| 93 | + |
| 94 | + override fun onWaitForStart() { |
| 95 | + pathCommand.schedule() |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +== Java |
| 101 | +```java |
| 102 | +public class MyOpMode extends NextFTCOpMode { |
| 103 | + private final Pose startPose = new Pose(9.0, 111.0, Math.toRadians(-90.0)); |
| 104 | + private final Pose scorePose = new Pose(16.0, 128.0, Math.toRadians(-45.0)); |
| 105 | + private final Pose pickup1Pose = new Pose(30.0, 121.0, Math.toRadians(0.0)); |
| 106 | + private final Pose pickup2Pose = new Pose(30.0, 131.0, Math.toRadians(0.0)); |
| 107 | + private final Pose pickup3Pose = new Pose(45.0, 128.0, Math.toRadians(90.0)); |
| 108 | + private final Pose parkPose = new Pose(68.0, 96.0, Math.toRadians(-90.0)); |
| 109 | + |
| 110 | + public MyOpMode() { |
| 111 | + addComponents( |
| 112 | + new PedroComponent(Constants::createFollower) |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + private final FollowPath pathCommand = new FollowPath(PedroComponent.follower().pathBuilder() |
| 117 | + .addPath(new BezierLine(startPose, scorePose)) |
| 118 | + .setLinearHeadingInterpolation(startPose.getHeading(), scorePose.getHeading()) |
| 119 | + .build()); |
| 120 | + |
| 121 | + @Override |
| 122 | + public void onWaitForStart() { |
| 123 | + pathCommand.schedule(); |
| 124 | + } |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +::: |
| 129 | + |
| 130 | +## KDoc |
| 131 | + |
| 132 | +This guide is a work-in-progress, |
| 133 | +so we recommend checking the KDoc [here](https://javadoc.io/doc/dev.nextftc.extensions/pedro/latest/index.html). |
0 commit comments