Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoLog Annotation Kotlin Support #64

Open
doinkythederp opened this issue Jan 17, 2024 · 2 comments · May be fixed by #112
Open

AutoLog Annotation Kotlin Support #64

doinkythederp opened this issue Jan 17, 2024 · 2 comments · May be fixed by #112
Labels
enhancement New feature or request kotlin

Comments

@doinkythederp
Copy link

When using the AutoLog decorator I'm not seeing the classes it's supposed to generate. I have this in my build.gradle, which looks like it's supposed to set up autolog:

dependencies {
    ....

    def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
    annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$akitJson.version"
}

Here's the AutoLog code:

@AutoLog
class IntakeInputs {
    var feedVelocityHz = Rotation2d()
    var rollersVelocityHz = Rotation2d()
}

I've checked the build/ folder for the classes, but I don't see anything. Building also fails because IntakeInputsAutoLogged doesn't exist.

Here's the setup I'm using:

  • Kotlin 1.9.22
  • AdvantageKit 3.0.0
  • Intellij IDEA
@jwbonner
Copy link
Member

While I don't have a lot of experience with Kotlin, my understanding is that Java annotation processors aren't compatible with Kotlin code. Kotlin has alternative annotation processing systems (Kapt and KSP), which have different APIs. Unfortunately, that means you'll need to write the toLog and fromLog methods on the inputs class manually. As far as I know, all of the other standard features of AdvantageKit are compatible with Kotlin.

@camearle20 camearle20 changed the title How do I set up AutoLog class generation? AutoLog Annotation Kotlin Support Jan 17, 2024
@Daniel1464
Copy link

Daniel1464 commented Apr 3, 2024

In addition, while browsing code online, I found this really cool kotlin AutoLog implementation from 9432. We personally use a custom implementation that's slightly different than the loggable inputs model of advantagekit, but for most teams, this probably does the job.

https://github.com/Team-8-bit/2024-Sonic/blob/develop/annotation/src/main/kotlin/org/team9432/lib/annotation/Logged.kt

https://github.com/Team-8-bit/2024-Sonic/blob/develop/annotation/src/main/kotlin/org/team9432/lib/annotation/LoggedProcessor.kt

Note: this implementation doesn't include implementations for Pose2d and the Translation/Transform classes, as well as wpilib's unit system. You also need to mark the class as open in order for it to be extendable.

@jwbonner jwbonner added enhancement New feature or request kotlin labels Nov 1, 2024
@Daniel1464 Daniel1464 linked a pull request Nov 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kotlin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants