Skip to content

Commit f6d4ac9

Browse files
committed
feat: add FateWeaver extension with FateComponent and publishers
1 parent eef08fc commit f6d4ac9

5 files changed

Lines changed: 201 additions & 1 deletion

File tree

.vitepress/sidebar/extensions.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@ export default [
2121
{text: "Trajectory Command Builder", link: "/extensions/roadrunner/command-builder"},
2222
{text: "Using With Other Commands", link: "/extensions/roadrunner/other-commands"}
2323
]
24+
},
25+
{
26+
text: "FateWeaver", items: [
27+
{text: "Installation", link: "/extensions/fateweaver/"},
28+
{text: "FateComponent", link: "/extensions/fateweaver/fatecomponent"},
29+
{text: "Publishers", link: "/extensions/fateweaver/publishers"},
30+
]
2431
}
2532
] satisfies SidebarItem[]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# `FateComponent`
2+
3+
The main feature added by this extension is the `FateComponent`,
4+
which can be added to your OpModes alongside other components:
5+
6+
:::tabs key:code
7+
8+
== Kotlin
9+
10+
```kotlin
11+
addComponents(
12+
/* existing components */
13+
FateComponent
14+
)
15+
```
16+
17+
== Java
18+
19+
```java
20+
addComponents(
21+
/* existing components */
22+
FateComponent.INSTANCE
23+
);
24+
```
25+
26+
:::
27+
28+
`FateComponent` will automatically log timestamps and the current
29+
Command snapshot at the end of every `OpMode` loop!
30+
31+
## Basic Logging Methods
32+
33+
To log a message, use the `write` method:
34+
35+
:::tabs key:code
36+
37+
== Kotlin
38+
39+
```kotlin
40+
// in `onUpdate` method
41+
FateComponent.write("ChannelName", object)
42+
```
43+
44+
== Java
45+
46+
```java
47+
//in `onUpdate` method
48+
FateComponent.write("ChannelName", object);
49+
```
50+
51+
:::
52+
53+
## Channels
54+
55+
You can also use `FateComponent` to create [channel](https://docs.fate.zharel.gay/ftc/gay.zharel.fateweaver.flight/-flight-log-channel/index.html) objects!
56+
57+
:::tabs key:code
58+
59+
== Kotlin
60+
61+
```kotlin
62+
val channel = FateComponent.createChannel("ChannelName", SomeClass::class)
63+
```
64+
65+
== Java
66+
67+
```java
68+
LogChannel<SomeClass> channel = FateComponent.createChannel("ChannelName", SomeClass.class);
69+
```
70+
71+
:::
72+
73+
> [!WARNING]
74+
> Channels must be created during an `OpMode`.
75+
> Creating a channel before an `OpMode` is initialized will result in an exception.

src/extensions/fateweaver/index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# FateWeaver Extension
2+
3+
This extension provides integration with the
4+
[FateWeaver Library](https://fate.zharel.gay/),
5+
a powerful logging library for FTC.
6+
7+
The [FateWeaver API docs](https://docs.fate.zharel.gau/) provide more information
8+
about the library.
9+
10+
## Installation
11+
12+
In the TeamCode `build.gradle`, go to the `dependencies` block.
13+
Add the following lines:
14+
15+
::: tabs key:gradle
16+
17+
== .gradle
18+
19+
```groovy
20+
implementation 'dev.nextftc.extensions:fateweaver:1.0.0'
21+
```
22+
23+
== .gradle.kts
24+
25+
```kotlin
26+
implementation("dev.nextftc.extensions:fateweaver:1.0.0")
27+
```
28+
29+
:::
30+
31+
Then, press the `Sync Now` button that appeared as a banner at the top of your
32+
Gradle file.
33+
34+
*You're good to go!*
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Publishers
2+
3+
The FateWeaver extension includes an additional feature called publishers,
4+
which allow you to register a channel that will be automatically logged to
5+
every loop.
6+
7+
Take our [lift subsystem](../../guide/subsystems/lift) from the guide.
8+
Let's add a public `state` getter:
9+
10+
:::tabs key:code
11+
12+
== Kotlin
13+
14+
```kotlin
15+
val state get() = motor.state
16+
```
17+
18+
== Java
19+
20+
```java
21+
public KineticState getState() {
22+
return motor.getState();
23+
}
24+
```
25+
26+
:::
27+
28+
Now, in the `onStartButtonPressed` method of our OpMode,
29+
we can register a publisher for the lift's state:
30+
31+
:::tabs key:code
32+
33+
== Kotlin
34+
35+
```kotlin
36+
val stateChannel = FateComponent.createChannel("Lift State", KineticState::class)
37+
FateComponent.registerPublisher(stateChannel, Lift::state)
38+
```
39+
40+
== Java
41+
42+
```java
43+
LogChannel<KineticState> stateChannel = FateComponent.createChannel("LiftState", KineticState.class);
44+
FateComponent.registerPublisher(stateChannel, Lift.INSTANCE::getState);
45+
```
46+
47+
:::
48+
49+
This will automatically publish the lift's state to the log file at the end of every loop.
50+
51+
There is an overload for `registerPublisher` that takes a
52+
channel name and schema (or class) instead of a channel object,
53+
which could be used as follows:
54+
55+
:::tabs key:code
56+
57+
== Kotlin
58+
59+
```kotlin
60+
FateComponent.registerPublisher("LiftState", KineticState::class, Lift::state)
61+
```
62+
63+
== Java
64+
65+
```java
66+
FateComponent.registerPublisher("LiftState", KineticState.class, Lift.INSTANCE::getState);
67+
```
68+
69+
:::
70+
71+
Publishers are automatically unregistered when the OpMode ends.
72+
73+
In this example, we use method and property references to simplify the code,
74+
but you can also use lambda expressions.
75+
WPILib has has an amazing explanation of method references and lambda expressions
76+
[here](https://docs.wpilib.org/en/stable/docs/software/basic-programming/functions-as-data.html).
77+
For information on Kotlin method references and lambda expressions,
78+
see [the Kotlin documentation](https://kotlinlang.org/docs/lambdas.html).

src/extensions/index.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ More information about the extension can be found [here](pedro/index).
1212

1313
This extension provides integration with the
1414
[RoadRunner Library](https://rr.brott.dev/).
15-
Docs are coming soon!
15+
More information about the extension can be found [here](roadrunner/index).
16+
17+
## FateWeaver
18+
19+
This extension provides integration with the
20+
[FateWeaver Library](https://fate.zharel.gay/).
21+
More information about the extension can be found [here](fateweaver/index).

0 commit comments

Comments
 (0)