Skip to content

Commit 4bd089e

Browse files
committed
feat: pedro docs
1 parent 174952a commit 4bd089e

7 files changed

Lines changed: 287 additions & 129 deletions

File tree

.vitepress/sidebar/extensions.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export default [
88
},
99
{
1010
text: "Pedro Pathing", items: [
11-
{text: "PedroPathing Extension", link: "/extensions/pedro/"},
11+
{text: "Installation", link: "/extensions/pedro/"},
12+
{text: "Getting Started", link: "/extensions/pedro/getting-started"},
13+
{text: "Following Paths", link: "/extensions/pedro/following-paths"},
14+
{text: "Turning", link: "/extensions/pedro/turning"},
15+
{text: "TeleOp Driving", link: "/extensions/pedro/teleop"},
1216
]
1317
},
1418
{
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Following Paths
2+
3+
To follow a path, use the `FollowPath` command. You use this instead of
4+
`follower.followPath`, which you would use if you were not using NextFTC.
5+
The `FollowPath` command waits for the path to finish before continuing,
6+
which means that it will work as expected in sequential groups.
7+
8+
:::tabs key:code
9+
10+
== Kotlin
11+
12+
```kotlin
13+
FollowPath(path)
14+
FollowPath(pathChain)
15+
```
16+
17+
== Java
18+
19+
```java
20+
new FollowPath(path);
21+
new FollowPath(pathChain);
22+
```
23+
24+
:::
25+
26+
## `holdEnd` and `maxPower`
27+
28+
The `FollowPath` command accepts two additional optional parameters: `holdEnd`
29+
and `maxPower`. The `holdEnd` parameter defaults to `automaticHoldEnd` in
30+
`FollowerConstants`, which itself defaults to `true`. The `maxPower` parameter
31+
defaults to `maxPower` in `FollowerConstants`, which defaults to `1.0`.
32+
33+
:::tabs key:code
34+
35+
== Kotlin
36+
37+
```kotlin
38+
FollowPath(path, holdEnd = true)
39+
FollowPath(path, holdEnd = true, maxPower = 0.5)
40+
```
41+
42+
== Java
43+
44+
```java
45+
new FollowPath(path, true);
46+
new FollowPath(path, true, 0.5);
47+
```
48+
49+
:::
50+
51+
::: danger IMPORTANT
52+
53+
You **may not** pass `maxPower` without also passing `holdEnd`. This is
54+
because `follower.followPath`, which `FollowPath` uses internally, does not
55+
accept `maxPower` without `holdEnd`.
56+
57+
:::
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Getting Started
2+
3+
The first step to using the Pedro extension is to add the Pedro component to
4+
your OpMode. Add the following code to your existing components.
5+
6+
:::tabs key:code
7+
8+
== Kotlin
9+
10+
```kotlin
11+
addComponents(
12+
/* existing components */
13+
PedroComponent(Constants::createFollower)
14+
)
15+
```
16+
17+
== Java
18+
19+
```java
20+
addComponents(
21+
/* existing components */
22+
new PedroComponent(Constants::createFollower)
23+
);
24+
```
25+
26+
:::
27+
28+
Adding this does two things:
29+
30+
- Automatically creates the follower on initialization.
31+
- Automatically updates the follower every loop.
32+
33+
## Accessing the Follower
34+
35+
To access the automatically created follower, use `PedroComponent.follower`.
36+
Alternatively, you can use a static import to access the follower directly:
37+
38+
:::tabs key:code
39+
40+
== Kotlin
41+
42+
```kotlin
43+
// at the top of the file:
44+
import dev.nextftc.extensions.pedro.PedroComponent.follower
45+
46+
// you can then access the follower as follower
47+
// for example:
48+
follower.breakFollowing()
49+
```
50+
51+
== Java
52+
53+
```java
54+
// at the top of the file:
55+
import static dev.nextftc.extensions.pedro.PedroComponent.follower;
56+
57+
// you can then access the follower as follower()
58+
// for example:
59+
follower().breakFollowing();
60+
```
61+
62+
:::

src/extensions/pedro/index.md

Lines changed: 17 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,36 @@
11
# Pedro Pathing Extension
22

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.
3+
This is our extension to add built-in support
4+
for [Pedro Pathing](https://pedropathing.com), a GVF-based path-planning and
5+
following library for FTC.
116

127
## Installation
138

14-
To install the Pedro Pathing extension,
15-
add the following line to your `build.gradle` file:
9+
In the TeamCode `build.gradle`, go to the `dependencies` block.
10+
Add the following lines:
11+
12+
::: tabs key:gradle
13+
14+
== .gradle
1615

1716
```groovy
1817
implementation 'dev.nextftc.extensions:pedro:1.0.0'
1918
```
2019

21-
::: warning
22-
Version `1.0.0` supports Pedro Pathing `2.0.0`,
23-
and is not compatible with earlier versions.
24-
25-
This guide also assumes you are using
26-
the QuickStart for Pedro Pathing.
27-
:::
28-
29-
## Usage
20+
== .gradle.kts
3021

31-
### `PedroComponent`
32-
33-
To use the Pedro Pathing extension,
34-
add a `PedroComponent` object to the `addComponents` call
35-
in your `NextFtcOpMode`, using `createFollower` from your
36-
`Constants` class.
37-
38-
::: tabs key:code
39-
40-
== Kotlin
4122
```kotlin
42-
class MyOpModeKt : NextFTCOpMode() {
43-
init {
44-
addComponents(
45-
PedroComponent(Constants::createFollower)
46-
)
47-
}
48-
}
23+
implementation("dev.nextftc.extensions:pedro:1.0.0")
4924
```
5025

51-
== Java
52-
```java
53-
public class MyOpModeJava extends NextFTCOpMode {
54-
public MyOpModeJava() {
55-
addComponents(
56-
new PedroComponent(Constants::createFollower)
57-
);
58-
}
59-
}
60-
```
6126
:::
6227

63-
### The Follower
64-
65-
Once you've added the `PedroComponent`,
66-
you can access the `Follower` instance
67-
as a static property of the `PedroComponent` class
68-
(`PedroComponent.follower` in Kotlin, or `PedroComponent.follower()` in Java).
69-
70-
### Creating Path Commands
28+
Then, press the `Sync Now` button that appeared as a banner at the top of your
29+
Gradle file.
7130

72-
To create path commands, you can use the `FollowPath` command,
73-
passing in a `Path` or a `PathChain` argument.
74-
75-
::: tabs key:code
76-
== Kotlin
77-
```kotlin
78-
private val startPose = Pose(9.0, 111.0, Math.Math.toRadians(-90.0))
79-
private val scorePose = Pose(16.0, 128.0, Math.Math.toRadians(-45.0))
80-
private val pickup1Pose = Pose(30.0, 121.0, Math.Math.toRadians(0.0))
81-
private val pickup2Pose = Pose(30.0, 131.0, Math.Math.toRadians(0.0))
82-
private val pickup3Pose = Pose(45.0, 128.0, Math.Math.toRadians(90.0))
83-
private val parkPose = Pose(68.0, 96.0, Math.Math.toRadians(-90.0))
84-
85-
class MyOpModeKt : NextFTCOpMode() {
86-
init {
87-
addComponents(
88-
PedroComponent(Constants::createFollower)
89-
)
90-
}
91-
92-
val pathCommand by onInit {
93-
FollowPath(PedroComponent.follower.pathBuilder()
94-
.addPath(BezierLine(startPose, scorePose))
95-
.setLinearHeadingInterpolation(startPose.heading, scorePose.heading)
96-
.build())
97-
}
98-
99-
override fun onWaitForStart() {
100-
pathCommand.schedule()
101-
}
102-
}
103-
```
104-
105-
== Java
106-
```java
107-
public class MyOpMode extends NextFTCOpMode {
108-
private final Pose startPose = new Pose(9.0, 111.0, Math.toRadians(-90.0));
109-
private final Pose scorePose = new Pose(16.0, 128.0, Math.toRadians(-45.0));
110-
private final Pose pickup1Pose = new Pose(30.0, 121.0, Math.toRadians(0.0));
111-
private final Pose pickup2Pose = new Pose(30.0, 131.0, Math.toRadians(0.0));
112-
private final Pose pickup3Pose = new Pose(45.0, 128.0, Math.toRadians(90.0));
113-
private final Pose parkPose = new Pose(68.0, 96.0, Math.toRadians(-90.0));
114-
115-
private FollowPath pathCommand;
116-
117-
public MyOpMode() {
118-
addComponents(
119-
new PedroComponent(Constants::createFollower)
120-
);
121-
}
122-
123-
@Override
124-
public void onInit() {
125-
pathCommand = new FollowPath(PedroComponent.follower().pathBuilder()
126-
.addPath(new BezierLine(startPose, scorePose))
127-
.setLinearHeadingInterpolation(startPose.getHeading(), scorePose.getHeading())
128-
.build());
129-
}
130-
131-
@Override
132-
public void onWaitForStart() {
133-
pathCommand.schedule();
134-
}
135-
}
136-
```
137-
138-
:::
31+
*You're good to go!*
13932

140-
## KDoc
33+
## Credit
14134

142-
This guide is a work-in-progress,
143-
so we recommend checking the KDoc [here](https://javadoc.io/doc/dev.nextftc.extensions/pedro/latest/index.html).
35+
Thanks so much to the Pedro Pathing team for creating such an amazing pathing
36+
library!

src/extensions/pedro/teleop.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# TeleOp Driving
2+
3+
> [!IMPORTANT]
4+
> This page outlines how to use the Pedro drivetrain command to control your
5+
> robot in TeleOp. It uses Pedro's built-in TeleOp driving feature to
6+
> control a holonomic drivetrain with centripetal force correction.
7+
8+
> [!TIP] INFO
9+
> Any holonomic drive can be controlled in one of two ways: robot centric or
10+
> field centric.
11+
>
12+
> Robot-centric assumes that each push of the joystick is in relation to the
13+
> local position of the robot—this means that whenever the user pushes the drive
14+
> stick forward, the robot will drive in the direction of its front-facing side.
15+
>
16+
> Field-centric assumes that each push of the joystick is in relation to the
17+
> global position of the robot—this means that whenever the user pushes the
18+
> drive stick forward, the robot will move away from the driver no matter its
19+
> orientation. This is done by rotating the direction of the joystick clockwise by
20+
> an angle measurement equivalent to the global heading of the robot.
21+
22+
## Usage
23+
24+
Using `PedroDriverControlled` is as simple as:
25+
26+
:::tabs key:code
27+
28+
== Kotlin
29+
30+
```kotlin
31+
val driverControlled = PedroDriverControlled(
32+
Gamepads.gamepad1.leftStickY,
33+
Gamepads.gamepad1.leftStickX,
34+
Gamepads.gamepad1.rightStickX
35+
)
36+
driverControlled()
37+
```
38+
39+
== Java
40+
41+
```java
42+
DriverControlledCommand driverControlled = new PedroDriverControlled(
43+
Gamepads.gamepad1().leftStickY(),
44+
Gamepads.gamepad1().leftStickX(),
45+
Gamepads.gamepad1().rightStickX()
46+
);
47+
driverControlled.schedule();
48+
```
49+
50+
:::
51+
52+
You can also run it field-centric by passing `false` for the optional `robotCentric`
53+
parameter:
54+
55+
:::tabs key:code
56+
57+
== Kotlin
58+
59+
```kotlin
60+
val driverControlled = PedroDriverControlled(
61+
Gamepads.gamepad1.leftStickY,
62+
Gamepads.gamepad1.leftStickX,
63+
Gamepads.gamepad1.rightStickX,
64+
false
65+
)
66+
driverControlled()
67+
```
68+
69+
== Java
70+
71+
```java
72+
DriverControlledCommand driverControlled = new PedroDriverControlled(
73+
Gamepads.gamepad1().leftStickY(),
74+
Gamepads.gamepad1().leftStickX(),
75+
Gamepads.gamepad1().rightStickX(),
76+
false
77+
);
78+
driverControlled.schedule();
79+
```
80+
81+
:::

0 commit comments

Comments
 (0)