Skip to content

Commit

Permalink
Big GUI update! GUI is now distributed using jlink and can be importe…
Browse files Browse the repository at this point in the history
…d via platform-specific classifiers
  • Loading branch information
amarcolini committed Apr 23, 2022
1 parent 1a43169 commit 7f1fc7a
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 57 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@ A comprehensive kotlin library designed for FTC. Based on [Road Runner](https://

## Installation

For the `command` and `navigation` modules, installation is as follows:

### Gradle

```gradle
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation "com.github.amarcolini.joos:$module:0.4.3-alpha"
}
```

Note that since the `command` module implicitly imports the `navigation` module,
only one implementation statement is needed.

To use the GUI, you can either download the image specific to your platform from the releases page,
or import it like so:

###Gradle

````groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation "com.github.amarcolini.joos:$module:0.4.2-alpha"
// Change 'win' to 'linux' or 'mac' depending on your operating system
implementation "com.github.amarcolini.joos:gui:0.4.3-alpha:win"
}
```
````
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
ext {
kotlin_version = "1.6.10"
lib_version = "0.4.2-alpha"
lib_version = "0.4.3-alpha"
}

repositories {
jcenter()
gradlePluginPortal()
google()
}

Expand All @@ -17,7 +17,6 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
}

Expand Down
32 changes: 19 additions & 13 deletions command/src/main/kotlin/com/amarcolini/joos/hardware/MotorGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.amarcolini.joos.command.Command
import com.amarcolini.joos.command.Component
import com.amarcolini.joos.control.FeedforwardCoefficients
import com.amarcolini.joos.control.PIDCoefficients
import com.amarcolini.joos.geometry.Angle
import com.amarcolini.joos.hardware.Motor.RunMode
import com.qualcomm.robotcore.hardware.HardwareMap

Expand Down Expand Up @@ -55,30 +56,35 @@ class MotorGroup(vararg val motors: Motor) : Component {
* The maximum revolutions per minute that all motors in the group can achieve.
*/
@JvmField
val maxRPM = motors.minOf { it.maxRPM }
val maxRPM: Double = motors.minOf { it.maxRPM }

/**
* The maximum distance velocity that all motors in the group can achieve.
*/
@JvmField
val maxDistanceVelocity = motors.minOf { it.maxDistanceVelocity }
val maxDistanceVelocity: Double = motors.minOf { it.maxDistanceVelocity }

/**
* The maximum ticks per second velocity that all motors in the group can achieve.
*/
@JvmField
val maxTPS: Double = motors.minOf { it.maxTPS }

/**
* A list of the individual rotations of each motor.
*/
val rotation: List<Angle> get() = motors.map { it.rotation }

/**
* The maximum distance that all motors in the group have travelled.
* @see distanceVelocity
*/
val distance get() = motors.minOf { it.distance }
val distance: Double get() = motors.minOf { it.distance }

/**
* The minimum distance velocity out of all motors in the group.
*/
val distanceVelocity get() = motors.minOf { it.distanceVelocity }
val distanceVelocity: Double get() = motors.minOf { it.distanceVelocity }

/**
* Whether the motor group is reversed.
Expand Down Expand Up @@ -119,14 +125,14 @@ class MotorGroup(vararg val motors: Motor) : Component {
velocity: Double,
acceleration: Double = 0.0,
unit: Motor.RotationUnit = Motor.RotationUnit.RPM
) = motors.forEach { it.setSpeed(velocity, acceleration, unit) }
): Unit = motors.forEach { it.setSpeed(velocity, acceleration, unit) }

/**
* Sets the percentage of power/velocity of the motor group in the range `[-1.0, 1.0]`.
*
* *Note*: Since power is expressed as a percentage, motors may move at different speeds.
*/
fun setPower(power: Double) = motors.forEach { it.power = power }
fun setPower(power: Double): Unit = motors.forEach { it.power = power }

var zeroPowerBehavior: Motor.ZeroPowerBehavior = Motor.ZeroPowerBehavior.FLOAT
set(value) {
Expand All @@ -143,7 +149,7 @@ class MotorGroup(vararg val motors: Motor) : Component {
/**
* PID coefficients used in [RunMode.RUN_USING_ENCODER].
*/
var veloCoefficients = PIDCoefficients(1.0)
var veloCoefficients: PIDCoefficients = PIDCoefficients(1.0)
set(value) {
motors.forEach { it.veloCoefficients = value }
field = value
Expand All @@ -152,7 +158,7 @@ class MotorGroup(vararg val motors: Motor) : Component {
/**
* PID coefficients used in [RunMode.RUN_TO_POSITION].
*/
var positionCoefficients = PIDCoefficients(1.0)
var positionCoefficients: PIDCoefficients = PIDCoefficients(1.0)
set(value) {
motors.forEach { it.positionCoefficients = value }
field = value
Expand All @@ -161,7 +167,7 @@ class MotorGroup(vararg val motors: Motor) : Component {
/**
* Feedforward coefficients used in both [RunMode.RUN_USING_ENCODER] and [RunMode.RUN_WITHOUT_ENCODER].
*/
var feedforwardCoefficients = FeedforwardCoefficients(1 / maxDistanceVelocity)
var feedforwardCoefficients: FeedforwardCoefficients = FeedforwardCoefficients(1 / maxDistanceVelocity)
set(value) {
motors.forEach { it.feedforwardCoefficients = value }
field = value
Expand All @@ -188,7 +194,7 @@ class MotorGroup(vararg val motors: Motor) : Component {
/**
* Returns a command that runs all the motors in the group until all of them have reached the desired position.
*/
fun goToPosition(position: Int) = Command.of {
fun goToPosition(position: Int): Command = Command.of {
runMode = RunMode.RUN_TO_POSITION
targetPosition = position
}
Expand All @@ -203,7 +209,7 @@ class MotorGroup(vararg val motors: Motor) : Component {
/**
* Returns a command that runs all the motors in the group until all of them have reached the desired distance.
*/
fun goToDistance(distance: Double) = Command.of {
fun goToDistance(distance: Double): Command = Command.of {
runMode = RunMode.RUN_TO_POSITION
motors.forEach {
it.targetPosition = (distance / it.distancePerRev * it.TPR).toInt()
Expand All @@ -222,12 +228,12 @@ class MotorGroup(vararg val motors: Motor) : Component {
/**
* Resets the encoders of all the motors in the group.
*/
fun resetEncoder() = motors.forEach { it.resetEncoder() }
fun resetEncoder(): Unit = motors.forEach { it.resetEncoder() }

/**
* Returns whether any of the motors in the group are currently moving towards the desired setpoint using [RunMode.RUN_TO_POSITION].
*/
fun isBusy() = motors.any { it.isBusy() }
fun isBusy(): Boolean = motors.any { it.isBusy() }

/**
* Updates both [RunMode.RUN_USING_ENCODER] and [RunMode.RUN_TO_POSITION]. Running this method is
Expand Down
117 changes: 98 additions & 19 deletions gui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'kotlin'
id 'maven-publish'
id "com.github.johnrengelman.shadow" version "7.1.0"
// id "com.github.johnrengelman.shadow" version "7.1.0"
id 'org.beryx.jlink' version '2.25.0'
}

repositories {
Expand All @@ -12,47 +13,88 @@ repositories {

application {
mainClass = "${rootProject.group}.gui.ApplicationKt"
mainModule = 'joos.gui'
applicationDefaultJvmArgs = ['--add-opens=javafx.graphics/javafx.scene=tornadofx']
}

javafx {
version = "11.0.2"
modules = ['javafx.controls', 'javafx.graphics', 'javafx.swing']
version = "15.0.1"
modules = ['javafx.controls']
}

shadowJar {
destinationDirectory.set(buildDir)
archiveBaseName.set("$rootProject.name-gui")
archiveClassifier.set("all")
archiveVersion.set(lib_version)
//shadowJar {
// destinationDirectory.set(buildDir)
// archiveBaseName.set("$rootProject.name-gui")
// archiveClassifier.set("all")
// archiveVersion.set(lib_version)
//}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
withSourcesJar()
}

configurations {
imageDependency {
extendsFrom implementation
canBeResolved(true)
}
}

dependencies {
api project(':navigation')
implementation 'no.tornado:tornadofx:1.7.20'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:win"
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:linux"
runtimeOnly "org.openjfx:javafx-graphics:$javafx.version:mac"
runtimeOnly "org.openjfx:javafx-controls:$javafx.version"
implementation 'io.github.classgraph:classgraph:4.8.146'

imageDependency "org.openjfx:javafx-controls:$javafx.version:win"
imageDependency "org.openjfx:javafx-controls:$javafx.version:mac"
imageDependency "org.openjfx:javafx-controls:$javafx.version:linux"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileKotlin {
kotlinOptions {
jvmTarget = "11"
apiVersion = "1.5"
}
destinationDirectory.set(compileJava.destinationDirectory.get())
}

task sourcesJar(type: Jar) {
task windowsJar(type: Jar) {
from sourceSets.main.allSource
classifier('sources')
dependencies {
implementation "org.openjfx:javafx-controls:$javafx.version:win"
}
classifier('win')
}

task linuxJar(type: Jar) {
from sourceSets.main.allSource
dependencies {
implementation "org.openjfx:javafx-controls:$javafx.version:linux"
}
classifier('linux')
}

task macJar(type: Jar) {
from sourceSets.main.allSource
dependencies {
implementation "org.openjfx:javafx-controls:$javafx.version:mac"
}
classifier('mac')
}

publishing {
publications {
release(MavenPublication) {
from components.java
artifact sourcesJar
artifactId = "gui"
artifact windowsJar
artifact linuxJar
artifact macJar
pom {
name = "Joos"
description = "A comprehensive kotlin library designed for FTC."
Expand All @@ -73,4 +115,41 @@ publishing {
url = '../testRepo'
}
}
}

jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
configuration = 'imageDependency'
addExtraDependencies("javafx")
forceMerge('javafx')

mergedModule {
excludeProvides servicePattern: 'com.fasterxml.jackson.*'
uses 'kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader'
uses 'kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition'
uses 'kotlin.reflect.jvm.internal.impl.util.ModuleVisibilityHelper'
}

launcher {
jvmArgs = ['--add-opens=javafx.graphics/javafx.scene=tornadofx']
noConsole = true
}

targetPlatform("linux") {
jdkHome = jdkDownload("https://api.adoptium.net/v3/binary/latest/11/ga/linux/x64/jdk/hotspot/normal/eclipse") {
archiveExtension = 'tar.gz'
}
}

targetPlatform("win") {
jdkHome = jdkDownload("https://api.adoptium.net/v3/binary/latest/11/ga/windows/x64/jdk/hotspot/normal/eclipse") {
archiveExtension = 'zip'
}
}

targetPlatform("mac") {
jdkHome = jdkDownload("https://api.adoptium.net/v3/binary/latest/11/ga/mac/x64/jdk/hotspot/normal/eclipse") {
archiveExtension = 'tar.gz'
}
}
}
15 changes: 15 additions & 0 deletions gui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module joos.gui {
requires javafx.controls;
requires javafx.graphics;
requires tornadofx;
requires transitive kotlin.stdlib;
requires kotlin.reflect;
uses kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoader;
uses kotlin.reflect.jvm.internal.impl.resolve.ExternalOverridabilityCondition;
uses kotlin.reflect.jvm.internal.impl.util.ModuleVisibilityHelper;
requires io.github.classgraph;
exports com.amarcolini.joos.gui;
exports com.amarcolini.joos.gui.rendering;
exports com.amarcolini.joos.gui.style;
exports com.amarcolini.joos.gui.trajectory;
}
Loading

0 comments on commit 7f1fc7a

Please sign in to comment.