├── gradle.properties ├── settings.gradle ├── settings.json ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ ├── resources │ ├── AppStyle.css │ └── GeneratorStyle.css │ └── kotlin │ └── org │ └── ghrobotics │ └── falcondashboard │ ├── Properties.kt │ ├── generator │ ├── fragments │ │ ├── InvalidTrajectoryFragment.kt │ │ ├── WaypointFragment.kt │ │ ├── CodeFragment.kt │ │ └── KtCodeFragment.kt │ ├── charts │ │ ├── VelocityChart.kt │ │ ├── RobotNode.kt │ │ ├── PositionChart.kt │ │ └── PositionNode.kt │ ├── tables │ │ └── WaypointsTable.kt │ └── GeneratorView.kt │ ├── MainView.kt │ ├── Main.kt │ ├── livevisualizer │ ├── charts │ │ ├── VisionTargetNode.kt │ │ └── FieldChart.kt │ └── LiveVisualizerView.kt │ ├── Util.kt │ ├── Network.kt │ └── Settings.kt ├── .gitignore ├── README.md ├── .github └── workflows │ └── main.yml ├── dependencies.gradle ├── gradlew.bat └── gradlew /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'falcondashboard' 2 | 3 | -------------------------------------------------------------------------------- /settings.json: -------------------------------------------------------------------------------- 1 | [false,true,false,0.0,0.0,10.0,4.0,4.0,"127.0.1.1"] -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FRC5190/FalconDashboard/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/resources/AppStyle.css: -------------------------------------------------------------------------------- 1 | /* Generic */ 2 | 3 | .root { 4 | -fx-background-color: white; 5 | } 6 | 7 | /* TAB PANE */ 8 | 9 | .jfx-tab-pane .tab-header-background { 10 | -fx-background-color: #690a0f; 11 | } 12 | 13 | .jfx-tab-pane .headers-region > .tab > .jfx-rippler { 14 | -jfx-rippler-fill: #bbb; 15 | } 16 | 17 | .jfx-tab-pane .tab-selected-line { 18 | -fx-background-color: #bbb; 19 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | .gradle/ 25 | build/ 26 | .idea/ 27 | *.iml 28 | out/ -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/Properties.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard 2 | 3 | import org.ghrobotics.lib.mathematics.units.inches 4 | 5 | /** 6 | * Stores general properties for robots and vision targets. 7 | */ 8 | object Properties { 9 | // Robot Sizes 10 | val kRobotLength = 31.inches 11 | val kRobotWidth = 29.inches 12 | 13 | // Target Sizes 14 | val kTargetWidth = 14.5.inches 15 | val kTargetThickness = kTargetWidth / 2 16 | } -------------------------------------------------------------------------------- /src/main/resources/GeneratorStyle.css: -------------------------------------------------------------------------------- 1 | /* Generic */ 2 | 3 | .root { 4 | -fx-background-color: white; 5 | } 6 | 7 | /* TAB PANE */ 8 | 9 | .jfx-tab-pane .tab-header-background { 10 | -fx-background-color: #222; 11 | } 12 | 13 | .jfx-tab-pane .headers-region > .tab > .jfx-rippler { 14 | -jfx-rippler-fill: #bbb; 15 | } 16 | 17 | .jfx-tab-pane .tab-selected-line { 18 | -fx-background-color: #bbb; 19 | } 20 | 21 | .series1 { 22 | -fx-background-color: transparent; 23 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/fragments/InvalidTrajectoryFragment.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.fragments 2 | 3 | import tornadofx.Fragment 4 | import tornadofx.hbox 5 | import tornadofx.paddingAll 6 | import tornadofx.text 7 | 8 | class InvalidTrajectoryFragment : Fragment() { 9 | override val root = hbox {} 10 | 11 | init { 12 | with(root) { 13 | title = "Invalid Trajectory Generated" 14 | paddingAll = 50 15 | 16 | text("You generated an invalid trajectory. Please ensure all your angles are correct.") 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/MainView.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard 2 | 3 | import javafx.scene.Parent 4 | import kfoenix.jfxtabpane 5 | import org.ghrobotics.falcondashboard.generator.GeneratorView 6 | import org.ghrobotics.falcondashboard.livevisualizer.LiveVisualizerView 7 | import tornadofx.View 8 | import tornadofx.plusAssign 9 | import tornadofx.tab 10 | 11 | class MainView : View("FRC 5190 Falcon Dashboard") { 12 | override val root: Parent = jfxtabpane { 13 | stylesheets += resources["/AppStyle.css"] 14 | 15 | prefHeight = 705.0 16 | prefWidth = 1550.0 17 | 18 | tab("Generator") { 19 | this += GeneratorView() 20 | isClosable = false 21 | } 22 | tab("Live Visualizer") { 23 | this += LiveVisualizerView() 24 | isClosable = false 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/Main.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard 2 | 3 | import edu.wpi.first.networktables.NetworkTablesJNI 4 | import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator 5 | import edu.wpi.first.wpiutil.CombinedRuntimeLoader 6 | import edu.wpi.first.wpiutil.WPIUtilJNI 7 | import javafx.stage.StageStyle 8 | import org.ghrobotics.falcondashboard.generator.fragments.InvalidTrajectoryFragment 9 | import tornadofx.App 10 | import tornadofx.find 11 | import tornadofx.launch 12 | 13 | class Main : App(MainView::class) { 14 | init { 15 | Settings 16 | Network 17 | 18 | TrajectoryGenerator.setErrorHandler { _, _ -> 19 | find().openModal(StageStyle.UTILITY) 20 | } 21 | } 22 | 23 | override fun stop() { 24 | Settings.save() 25 | } 26 | } 27 | 28 | fun main(args: Array) { 29 | WPIUtilJNI.Helper.setExtractOnStaticLoad(false); 30 | NetworkTablesJNI.Helper.setExtractOnStaticLoad(false); 31 | CombinedRuntimeLoader.loadLibraries(Main::class.java, "wpiutiljni", "ntcorejni") 32 | launch
(args) 33 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/livevisualizer/charts/VisionTargetNode.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.livevisualizer.charts 2 | 3 | import edu.wpi.first.wpilibj.geometry.Rotation2d 4 | import javafx.beans.property.ReadOnlyDoubleProperty 5 | import javafx.scene.layout.StackPane 6 | import javafx.scene.paint.Color 7 | import org.ghrobotics.falcondashboard.Properties 8 | import org.ghrobotics.lib.mathematics.units.inFeet 9 | import tornadofx.* 10 | 11 | class VisionTargetNode( 12 | rotation: Rotation2d, 13 | scaleProperty: ReadOnlyDoubleProperty 14 | ) : StackPane() { 15 | 16 | init { 17 | style { 18 | backgroundColor = multi(Color.TRANSPARENT) 19 | borderColor = multi(box(Color.GREEN)) 20 | borderWidth = multi(box(0.25.em)) 21 | } 22 | rotate = (-rotation).degrees 23 | 24 | usePrefHeight = true 25 | usePrefWidth = true 26 | prefHeightProperty() 27 | .bind(scaleProperty.multiply(Properties.kTargetWidth.inFeet())) 28 | prefWidthProperty() 29 | .bind(scaleProperty.multiply(Properties.kTargetThickness.inFeet())) 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Falcon Dashboard 2 | Dashboard used by FRC 5190 to generate trajectories and visualize live robot motion to debug trajectory tracking and computer vision code. 3 | 4 | ## Pre-Requisites 5 | JDK 11 or higher is required to build Falcon Dashboard. Older versions will cause compilation errors. 6 | 7 | ## Running 8 | Falcon Dashboard uses the Gradle build system. Run `./gradlew run` in the root project directory. 9 | 10 | ## Sending Data to Falcon Dashboard 11 | You can send data over NetworkTables to visualize the robot pose and trajectory data on the live visualizer. All entries are sent over the `Live_Dashboard` table. 12 | 13 | ### Robot Pose Data 14 | - `robotX`: The x position of the robot on the field in feet. 15 | - `robotY`: The y position of the robot on the field in feet. 16 | - `robotHeading` The heading of the robot in radians. 17 | 18 | ### Trajectory Data 19 | - `pathX`: The x position of the current reference point in feet. 20 | - `pathY`: The y position of the current reference point in feet. 21 | - `isFollowingPath`: Whether the robot is currently tracking a trajectory or not. 22 | 23 | ### Vision Targets 24 | - `visionTargets`: A list of `Pose2d` objects representing the vision targets in the field's coordinate system. 25 | 26 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/fragments/WaypointFragment.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.fragments 2 | 3 | import edu.wpi.first.wpilibj.geometry.Rotation2d 4 | import javafx.beans.property.SimpleDoubleProperty 5 | import org.ghrobotics.falcondashboard.createNumericalEntry 6 | import org.ghrobotics.falcondashboard.generator.GeneratorView 7 | import org.ghrobotics.lib.mathematics.twodim.geometry.Pose2d 8 | import org.ghrobotics.lib.mathematics.units.feet 9 | import tornadofx.* 10 | 11 | class WaypointFragment : Fragment() { 12 | override val root = vbox { } 13 | 14 | val x = SimpleDoubleProperty(0.0) 15 | val y = SimpleDoubleProperty(0.0) 16 | val a = SimpleDoubleProperty(0.0) 17 | 18 | init { 19 | with(root) { 20 | title = "Add Waypoint" 21 | 22 | paddingAll = 50 23 | 24 | createNumericalEntry("X", x) 25 | createNumericalEntry("Y", y) 26 | createNumericalEntry("Angle", a) 27 | 28 | button { 29 | text = "Add" 30 | prefWidth = 100.0 31 | action { 32 | GeneratorView.waypoints.add(Pose2d(x.value.feet, y.value.feet, Rotation2d.fromDegrees(a.value))) 33 | close() 34 | } 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/Util.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard 2 | 3 | import javafx.application.Platform 4 | import javafx.beans.property.DoublePropertyBase 5 | import javafx.beans.property.Property 6 | import javafx.beans.property.ReadOnlyObjectPropertyBase 7 | import javafx.beans.property.ReadOnlyProperty 8 | import javafx.collections.ObservableList 9 | import javafx.geometry.Pos 10 | import javafx.scene.Parent 11 | import javafx.util.converter.NumberStringConverter 12 | import kfoenix.jfxtextfield 13 | import tornadofx.* 14 | 15 | fun Parent.createNumericalEntry(name: String, property: DoublePropertyBase) = hbox { 16 | paddingAll = 5 17 | jfxtextfield { 18 | bind(property, converter = NumberStringConverter()) 19 | prefWidth = 40.0 20 | minWidth = 40.0 21 | } 22 | text(" $name") { alignment = Pos.CENTER_LEFT } 23 | } 24 | 25 | fun ui(block: () -> Unit) { 26 | Platform.runLater(block) 27 | } 28 | 29 | fun mapprop(receiver: ReadOnlyProperty, getter: ReadOnlyProperty.() -> T): ReadOnlyProperty = 30 | object : ReadOnlyObjectPropertyBase() { 31 | override fun getName() = receiver.name 32 | override fun getBean() = receiver.bean 33 | 34 | init { 35 | receiver.onChange { 36 | fireValueChangedEvent() 37 | } 38 | } 39 | 40 | override fun get() = getter.invoke(receiver) 41 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/fragments/CodeFragment.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.fragments 2 | 3 | import edu.wpi.first.wpilibj.trajectory.TrajectoryUtil 4 | import javafx.scene.layout.Priority 5 | import javafx.scene.text.Font 6 | import kfoenix.jfxtextarea 7 | import org.ghrobotics.falcondashboard.generator.GeneratorView 8 | import tornadofx.* 9 | import java.awt.Desktop 10 | import java.net.URI 11 | 12 | class CodeFragment : Fragment() { 13 | override val root = vbox { 14 | 15 | title = "Generated Code" 16 | 17 | style { 18 | padding = box(1.em) 19 | } 20 | 21 | prefWidth = 800.0 22 | prefHeight = 500.0 23 | 24 | jfxtextarea { 25 | font = Font.font("Monospaced") 26 | isEditable = false 27 | 28 | vgrow = Priority.ALWAYS 29 | 30 | text = TrajectoryUtil.serializeTrajectory(GeneratorView.trajectory.value) 31 | } 32 | vbox { 33 | style { 34 | padding = box(0.5.em, 0.em, 0.em, 0.em) 35 | } 36 | add(text(" This code is generated to be used with FalconLibrary")) 37 | add(hyperlink("https://github.com/5190GreenHopeRobotics/FalconLibrary") { 38 | setOnAction { 39 | Desktop.getDesktop() 40 | .browse(URI("https://github.com/5190GreenHopeRobotics/FalconLibrary")) 41 | } 42 | }) 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/charts/VelocityChart.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.charts 2 | 3 | import edu.wpi.first.wpilibj.trajectory.Trajectory 4 | import javafx.scene.chart.LineChart 5 | import javafx.scene.chart.NumberAxis 6 | import javafx.scene.paint.Color 7 | import javafx.scene.paint.Paint 8 | import org.ghrobotics.falcondashboard.generator.GeneratorView 9 | import tornadofx.MultiValue 10 | import tornadofx.data 11 | import tornadofx.style 12 | import kotlin.math.abs 13 | 14 | object VelocityChart : LineChart(NumberAxis(), NumberAxis()) { 15 | 16 | 17 | init { 18 | style { 19 | backgroundColor = MultiValue(arrayOf(Color.LIGHTGRAY)) 20 | } 21 | 22 | setMinSize(54 * 25.0, 27 * 25.0) 23 | 24 | axisSortingPolicy = SortingPolicy.NONE 25 | isLegendVisible = false 26 | createSymbols = false 27 | animated = false 28 | 29 | update(GeneratorView.trajectory.value) 30 | GeneratorView.trajectory.addListener { _, _, newValue -> update(newValue) } 31 | } 32 | 33 | private fun update(trajectory: Trajectory) { 34 | data.clear() 35 | 36 | val seriesVelocity = Series() 37 | 38 | with(seriesVelocity) { 39 | val duration = trajectory.totalTimeSeconds 40 | var t = 0.0 41 | val dt = 0.02 42 | 43 | while (t <= duration) { 44 | val point = trajectory.sample(t) 45 | t += dt 46 | data(point.timeSeconds, abs(point.velocityMetersPerSecond) * 3.2808) 47 | } 48 | this@VelocityChart.data.add(this) 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/livevisualizer/LiveVisualizerView.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.livevisualizer 2 | 3 | import edu.wpi.first.networktables.NetworkTableInstance 4 | import javafx.geometry.Pos 5 | import javafx.scene.input.KeyCode 6 | import javafx.scene.layout.Priority 7 | import javafx.scene.paint.Color 8 | import javafx.stage.StageStyle 9 | import kfoenix.jfxtextfield 10 | import org.ghrobotics.falcondashboard.Settings 11 | import org.ghrobotics.falcondashboard.livevisualizer.charts.FieldChart 12 | import tornadofx.* 13 | 14 | class LiveVisualizerView : View() { 15 | override val root = vbox { 16 | hbox { 17 | paddingAll = 10 18 | 19 | text("Network Table IP: ") { 20 | alignment = Pos.CENTER_LEFT 21 | } 22 | 23 | jfxtextfield(Settings.ip.value) { 24 | prefWidth = 100.0 25 | setOnKeyPressed { 26 | if (it.code == KeyCode.ENTER) { 27 | Settings.ip.set(this@jfxtextfield.text) 28 | object : Fragment() { 29 | override val root = vbox { 30 | text("Please Restart Falcon Dashboard for changes to take effect.") 31 | } 32 | }.openModal(stageStyle = StageStyle.UTILITY) 33 | } 34 | } 35 | } 36 | } 37 | stackpane { 38 | style { 39 | backgroundColor = multi(Color.LIGHTGRAY) 40 | } 41 | alignment = Pos.CENTER 42 | vgrow = Priority.ALWAYS 43 | add(FieldChart) 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | # Controls when the action will run. Triggers the workflow on push or pull request 4 | # events but only for the master branch 5 | on: 6 | push: 7 | branches: [ main ] 8 | pull_request: 9 | branches: [ main ] 10 | 11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 12 | jobs: 13 | build-windows: 14 | name: Build - Windows 15 | runs-on: windows-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Install Java 11 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 11 23 | - run: ./gradlew build shadowJar 24 | name: Build and create JAR 25 | - uses: actions/upload-artifact@v2 26 | with: 27 | path: build/libs/ 28 | 29 | build-macos: 30 | name: Build - macOS 31 | runs-on: macos-latest 32 | 33 | steps: 34 | - uses: actions/checkout@v2 35 | - name: Install Java 11 36 | uses: actions/setup-java@v1 37 | with: 38 | java-version: 11 39 | - run: chmod +x gradlew 40 | name: Make gradlew executable 41 | - run: ./gradlew build shadowJar 42 | name: Build and create JAR 43 | - uses: actions/upload-artifact@v2 44 | with: 45 | path: build/libs/ 46 | 47 | build-linux: 48 | name: Build - Linux 49 | runs-on: ubuntu-latest 50 | 51 | steps: 52 | - uses: actions/checkout@v2 53 | - name: Install Java 11 54 | uses: actions/setup-java@v1 55 | with: 56 | java-version: 11 57 | - run: chmod +x gradlew 58 | name: Make gradlew executable 59 | - run: ./gradlew build shadowJar 60 | name: Build and create JAR 61 | - uses: actions/upload-artifact@v2 62 | with: 63 | path: build/libs/ 64 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/charts/RobotNode.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.charts 2 | 3 | import edu.wpi.first.wpilibj.geometry.Rotation2d 4 | import javafx.beans.property.ReadOnlyDoubleProperty 5 | import javafx.beans.property.ReadOnlyProperty 6 | import javafx.beans.property.SimpleDoubleProperty 7 | import javafx.scene.layout.StackPane 8 | import javafx.scene.paint.Color 9 | import org.ghrobotics.falcondashboard.Properties 10 | import org.ghrobotics.falcondashboard.mapprop 11 | import org.ghrobotics.lib.mathematics.units.inFeet 12 | import tornadofx.* 13 | 14 | open class RobotNode( 15 | private val robotRotationProperty: ReadOnlyProperty, 16 | scaleProperty: ReadOnlyDoubleProperty 17 | ) : StackPane() { 18 | 19 | val robotRotation = SimpleDoubleProperty() 20 | 21 | fun bindRobotRotation() { 22 | robotRotation 23 | .bind(mapprop( 24 | robotRotationProperty 25 | ) { (-value).degrees }) 26 | } 27 | 28 | val robotPane = object : StackPane() { 29 | init { 30 | style { 31 | backgroundColor = multi(Color.TRANSPARENT) 32 | borderColor = multi(box(Color.BLUE)) 33 | borderRadius = multi(box(0.5.em)) 34 | borderWidth = multi(box(0.25.em)) 35 | } 36 | rotateProperty().bind(robotRotation) 37 | bindRobotRotation() 38 | usePrefHeight = true 39 | usePrefWidth = true 40 | prefHeightProperty() 41 | .bind(scaleProperty.multiply(Properties.kRobotWidth.inFeet())) 42 | prefWidthProperty() 43 | .bind(scaleProperty.multiply(Properties.kRobotLength.inFeet())) 44 | } 45 | } 46 | 47 | init { 48 | children.add(robotPane) 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /dependencies.gradle: -------------------------------------------------------------------------------- 1 | def nativeConfigName = "wpilibNatives" 2 | def nativeConfig = configurations.create(nativeConfigName) 3 | 4 | def nativeTasks = wpilibTools.createExtractionTasks { 5 | configurationName = nativeConfigName 6 | } 7 | 8 | nativeTasks.addToSourceSetResources(sourceSets.main) 9 | 10 | wpilibTools.deps.wpilibVersion = "2021.+" 11 | 12 | nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore") 13 | nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil") 14 | 15 | dependencies { 16 | // We need to add the Kotlin stdlib in order to use most Kotlin language features. 17 | compile "org.jetbrains.kotlin:kotlin-stdlib" 18 | compile "org.jetbrains.kotlin:kotlin-reflect" 19 | 20 | // TornadoFX 21 | compile("no.tornado:tornadofx:1.7.19") { transitive = false } 22 | 23 | // Material Theme 24 | compile "com.jfoenix:jfoenix:9.0.8" 25 | compile "com.github.bkenn:kfoenix:0.1.3" 26 | 27 | // Kotlin Coroutines 28 | compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3" 29 | 30 | // Kotson for Serialization 31 | compile "com.github.salomonbrys.kotson:kotson:2.5.0" 32 | 33 | // Falcon Library 34 | compile "org.ghrobotics.FalconLibrary:core:bae099cf0c" 35 | compile "org.ghrobotics.FalconLibrary:wpi:bae099cf0c" 36 | 37 | // Add core wpilibj, wpiutil, and ntcore 38 | implementation wpilibTools.deps.wpilibJava("wpiutil") 39 | implementation wpilibTools.deps.wpilibJava("wpimath") 40 | implementation wpilibTools.deps.wpilibJava("ntcore") 41 | 42 | // Add Jackson serialization 43 | implementation "com.fasterxml.jackson.core:jackson-annotations:2.10.0" 44 | implementation "com.fasterxml.jackson.core:jackson-core:2.10.0" 45 | implementation "com.fasterxml.jackson.core:jackson-databind:2.10.0" 46 | 47 | // Add EJML 48 | implementation group: "org.ejml", name: "ejml-simple", version: "0.38" 49 | 50 | // Add JavaFX 51 | implementation wpilibTools.deps.javafx("base") 52 | implementation wpilibTools.deps.javafx("controls") 53 | implementation wpilibTools.deps.javafx("fxml") 54 | implementation wpilibTools.deps.javafx("graphics") 55 | } 56 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/Network.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard 2 | 3 | import edu.wpi.first.wpilibj.geometry.Pose2d 4 | import edu.wpi.first.wpilibj.geometry.Rotation2d 5 | import kotlinx.coroutines.GlobalScope 6 | import kotlinx.coroutines.delay 7 | import kotlinx.coroutines.isActive 8 | import kotlinx.coroutines.launch 9 | import org.ghrobotics.falcondashboard.livevisualizer.charts.FieldChart 10 | import org.ghrobotics.lib.debug.FalconDashboard 11 | import org.ghrobotics.lib.mathematics.twodim.geometry.Pose2d 12 | import org.ghrobotics.lib.mathematics.units.feet 13 | import org.ghrobotics.lib.wrappers.networktables.FalconNetworkTable 14 | 15 | object Network { 16 | 17 | init { 18 | FalconNetworkTable.getTable("Live_Dashboard").instance.startClient(Settings.ip.value) 19 | 20 | var lastIsFollowingPath = false 21 | 22 | var lastRobotPose: Pose2d? = null 23 | var lastPathPose: Pose2d? = null 24 | 25 | GlobalScope.launch { 26 | while (isActive) { 27 | 28 | ui { 29 | FieldChart.updateVisionTargets(FalconDashboard.visionTargets) 30 | } 31 | 32 | val robotPose = Pose2d( 33 | FalconDashboard.robotX.feet, 34 | FalconDashboard.robotY.feet, 35 | Rotation2d(FalconDashboard.robotHeading) 36 | ) 37 | 38 | val pathPose = Pose2d( 39 | FalconDashboard.pathX.feet, 40 | FalconDashboard.pathY.feet, 41 | Rotation2d(FalconDashboard.pathHeading) 42 | ) 43 | 44 | val updateRobotPose = robotPose != lastRobotPose 45 | if (updateRobotPose) ui { FieldChart.updateRobotPose(robotPose) } 46 | lastRobotPose = robotPose 47 | 48 | if (FalconDashboard.isFollowingPath) { 49 | if (!lastIsFollowingPath) { 50 | // Only reset path cache when another path starts 51 | ui { FieldChart.clear() } 52 | lastRobotPose = null 53 | lastPathPose = null 54 | lastIsFollowingPath = true 55 | } else { 56 | val updatePathPose = pathPose != lastPathPose 57 | 58 | if (updatePathPose || updateRobotPose) { 59 | ui { 60 | if (updateRobotPose) FieldChart.addRobotPathPose(robotPose) 61 | if (updatePathPose) FieldChart.addPathPose(pathPose) 62 | } 63 | } 64 | 65 | lastPathPose = pathPose 66 | } 67 | } else { 68 | lastIsFollowingPath = false 69 | } 70 | delay(20) 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/Settings.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard 2 | 3 | import com.github.salomonbrys.kotson.fromJson 4 | import com.github.salomonbrys.kotson.registerTypeAdapter 5 | import com.google.gson.GsonBuilder 6 | import javafx.beans.property.SimpleBooleanProperty 7 | import javafx.beans.property.SimpleDoubleProperty 8 | import javafx.beans.property.SimpleStringProperty 9 | import java.io.File 10 | import java.io.FileReader 11 | import java.io.FileWriter 12 | 13 | 14 | object Settings { 15 | val name = SimpleStringProperty("Baseline") 16 | val reversed = SimpleBooleanProperty(false) 17 | val clampedCubic = SimpleBooleanProperty(true) 18 | val autoPathFinding = SimpleBooleanProperty(false) 19 | val startVelocity = SimpleDoubleProperty(0.0) 20 | val endVelocity = SimpleDoubleProperty(0.0) 21 | val maxVelocity = SimpleDoubleProperty(10.0) 22 | val maxAcceleration = SimpleDoubleProperty(4.0) 23 | val maxCentripetalAcceleration = SimpleDoubleProperty(4.0) 24 | val ip = SimpleStringProperty("127.0.1.1") 25 | 26 | private val gson = GsonBuilder().registerTypeAdapter { 27 | write { 28 | beginArray() 29 | value(it.reversed.value) 30 | value(it.clampedCubic.value) 31 | value(it.autoPathFinding.value) 32 | value(it.startVelocity.value) 33 | value(it.endVelocity.value) 34 | value(it.maxVelocity.value) 35 | value(it.maxAcceleration.value) 36 | value(it.maxCentripetalAcceleration.value) 37 | value(it.ip.value) 38 | endArray() 39 | } 40 | read { 41 | beginArray() 42 | reversed.set(nextBoolean()) 43 | clampedCubic.set(nextBoolean()) 44 | autoPathFinding.set(nextBoolean()) 45 | startVelocity.set(nextDouble()) 46 | endVelocity.set(nextDouble()) 47 | maxVelocity.set(nextDouble()) 48 | maxAcceleration.set(nextDouble()) 49 | maxCentripetalAcceleration.set(nextDouble()) 50 | ip.set(nextString()) 51 | endArray() 52 | return@read Settings 53 | } 54 | }.create()!! 55 | 56 | init { 57 | val file = File("settings.json") 58 | if (file.exists()) { 59 | try { 60 | gson.fromJson(FileReader(file)) 61 | } catch (e: Exception) { 62 | file.delete() 63 | val writer = FileWriter(file) 64 | writer.write(gson.toJson(Settings)) 65 | writer.close() 66 | } 67 | } else { 68 | val writer = FileWriter(file) 69 | writer.write(gson.toJson(Settings)) 70 | writer.close() 71 | } 72 | } 73 | 74 | fun save() { 75 | val writer = FileWriter(File("settings.json")) 76 | writer.write(gson.toJson(Settings)) 77 | writer.close() 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/fragments/KtCodeFragment.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.fragments 2 | 3 | import javafx.scene.layout.Priority 4 | import javafx.scene.text.Font 5 | import kfoenix.jfxtextarea 6 | import org.ghrobotics.falcondashboard.Settings 7 | import org.ghrobotics.falcondashboard.generator.GeneratorView 8 | import org.ghrobotics.lib.mathematics.twodim.geometry.x_u 9 | import org.ghrobotics.lib.mathematics.twodim.geometry.y_u 10 | import org.ghrobotics.lib.mathematics.units.feet 11 | import org.ghrobotics.lib.mathematics.units.inFeet 12 | import org.ghrobotics.lib.mathematics.units.meter 13 | import tornadofx.* 14 | import java.awt.Desktop 15 | import java.net.URI 16 | import java.text.DecimalFormat 17 | 18 | class KtCodeFragment : Fragment() { 19 | override val root = vbox { 20 | 21 | title = "Generated Code" 22 | 23 | style { 24 | padding = box(1.em) 25 | } 26 | 27 | prefWidth = 800.0 28 | prefHeight = 500.0 29 | 30 | jfxtextarea { 31 | font = Font.font("Monospaced") 32 | isEditable = false 33 | 34 | vgrow = Priority.ALWAYS 35 | 36 | text = buildString { 37 | 38 | // append( 39 | // "import org.ghrobotics.lib.mathematics.twodim.geometry.Pose2d\n" + 40 | // "import org.ghrobotics.lib.mathematics.twodim.trajectory.DefaultTrajectoryGenerator\n" + 41 | // "import org.ghrobotics.lib.mathematics.twodim.trajectory.constraints.CentripetalAccelerationConstraint\n" + 42 | // "import org.ghrobotics.lib.mathematics.units.degree\n" + 43 | // "import org.ghrobotics.lib.mathematics.units.derivedunits.acceleration\n" + 44 | // "import org.ghrobotics.lib.mathematics.units.derivedunits.velocity\n" + 45 | // "import org.ghrobotics.lib.mathematics.units.feet\n\n\n\n" 46 | // ) 47 | 48 | val name = Settings.name.value.decapitalize() 49 | .replace("\\s+".toRegex(), "") 50 | 51 | val dm = DecimalFormat("##.###") 52 | 53 | // append("val $name = DefaultTrajectoryGenerator.generateTrajectory(\n") 54 | append("wayPoints = listOf(\n") 55 | GeneratorView.waypoints.forEach { 56 | append( 57 | " Pose2d(${dm.format(it.translation.x_u.inFeet())}.feet, " + 58 | "${dm.format(it.translation.y_u.inFeet())}.feet, " + 59 | "${dm.format(it.rotation.degrees)}.degrees)" 60 | ) 61 | if (it != GeneratorView.waypoints.last()) append(",") 62 | append("\n") 63 | } 64 | append("),\n") 65 | // append( 66 | // " constraints = listOf(CentripetalAccelerationConstraint(${Settings.maxCentripetalAcceleration.value}.feet.acceleration),\n" + 67 | // " startVelocity = 0.0.feet.velocity,\n" + 68 | // " endVelocity = 0.0.feet.velocity,\n" + 69 | // " maxVelocity = ${Settings.maxVelocity.value}.feet.velocity,\n" + 70 | // " maxAcceleration = ${Settings.maxAcceleration.value}.feet.acceleration,\n" + 71 | // " reversed = ${Settings.reversed.value}\n)" 72 | // ) 73 | } 74 | } 75 | vbox { 76 | style { 77 | padding = box(0.5.em, 0.em, 0.em, 0.em) 78 | } 79 | add(text(" This code is generated to be used with FalconLibrary")) 80 | add(hyperlink("https://github.com/5190GreenHopeRobotics/FalconLibrary") { 81 | setOnAction { 82 | Desktop.getDesktop() 83 | .browse(URI("https://github.com/5190GreenHopeRobotics/FalconLibrary")) 84 | } 85 | }) 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/livevisualizer/charts/FieldChart.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.livevisualizer.charts 2 | 3 | import edu.wpi.first.wpilibj.geometry.Pose2d 4 | import edu.wpi.first.wpilibj.geometry.Rotation2d 5 | import javafx.scene.chart.LineChart 6 | import javafx.scene.chart.NumberAxis 7 | import javafx.scene.chart.XYChart 8 | import javafx.scene.paint.Color 9 | import org.ghrobotics.falcondashboard.Properties 10 | import org.ghrobotics.lib.mathematics.twodim.geometry.Transform2d 11 | import org.ghrobotics.lib.mathematics.twodim.geometry.x_u 12 | import org.ghrobotics.lib.mathematics.twodim.geometry.y_u 13 | import org.ghrobotics.lib.mathematics.units.inFeet 14 | import org.ghrobotics.lib.mathematics.units.inch 15 | import tornadofx.data 16 | import tornadofx.multi 17 | import tornadofx.style 18 | 19 | object FieldChart : LineChart( 20 | NumberAxis(0.0, 54.0, 1.0), 21 | NumberAxis(0.0, 27.0, 1.0) 22 | ) { 23 | 24 | private val robotSeries = XYChart.Series() 25 | private val pathSeries = XYChart.Series() 26 | private val robotBoundingBoxSeries = XYChart.Series() 27 | private val visionTargetSeries = XYChart.Series() 28 | 29 | init { 30 | style { 31 | backgroundColor = multi(Color.LIGHTGRAY) 32 | } 33 | lookup(".chart-plot-background").style += 34 | "-fx-background-image: url(\"chart-background.png\");" + 35 | "-fx-background-size: stretch;" + 36 | "-fx-background-position: top right;" + 37 | "-fx-background-repeat: no-repeat;" 38 | 39 | axisSortingPolicy = LineChart.SortingPolicy.NONE 40 | isLegendVisible = false 41 | animated = false 42 | createSymbols = false 43 | 44 | verticalGridLinesVisible = false 45 | isHorizontalGridLinesVisible = false 46 | 47 | data.add(robotSeries) 48 | data.add(pathSeries) 49 | data.add(robotBoundingBoxSeries) 50 | data.add(visionTargetSeries) 51 | } 52 | 53 | override fun resize(width: Double, height: Double) { 54 | val newWidth = height / 27 * 54 55 | if (newWidth > width) { 56 | super.resize(width, width / 54 * 27) 57 | } else { 58 | super.resize(newWidth, height) 59 | } 60 | } 61 | 62 | fun addRobotPathPose(pose2d: Pose2d) { 63 | @Suppress("UNCHECKED_CAST") 64 | robotSeries.data( 65 | pose2d.translation.x_u.inFeet(), 66 | pose2d.translation.y_u.inFeet() 67 | ) 68 | } 69 | 70 | fun addPathPose(pose2d: Pose2d) { 71 | @Suppress("UNCHECKED_CAST") 72 | pathSeries.data( 73 | pose2d.translation.x_u.inFeet(), 74 | pose2d.translation.y_u.inFeet() 75 | ) 76 | } 77 | 78 | fun updateRobotPose(pose2d: Pose2d) { 79 | robotBoundingBoxSeries.data.clear() 80 | getRobotBoundingBox(pose2d).forEach { 81 | robotBoundingBoxSeries.data( 82 | it.translation.x_u.inFeet(), 83 | it.translation.y_u.inFeet() 84 | ) 85 | } 86 | } 87 | 88 | fun updateVisionTargets(newVisionTargets: List) { 89 | visionTargetSeries.data.clear() 90 | newVisionTargets.forEach { 91 | val data = XYChart.Data( 92 | it.translation.x_u.inFeet(), 93 | it.translation.y_u.inFeet() 94 | ) 95 | data.node = VisionTargetNode( 96 | it.rotation, 97 | (xAxis as NumberAxis).scaleProperty() 98 | ) 99 | visionTargetSeries.data.add(data) 100 | } 101 | } 102 | 103 | private fun getRobotBoundingBox(center: Pose2d): Array { 104 | val tl = center.transformBy( 105 | Transform2d(-Properties.kRobotLength / 2, Properties.kRobotWidth / 2, Rotation2d()) 106 | ) 107 | 108 | val tr = center.transformBy( 109 | Transform2d(Properties.kRobotLength / 2, Properties.kRobotWidth / 2, Rotation2d()) 110 | ) 111 | 112 | val mid = center.transformBy( 113 | Transform2d(Properties.kRobotLength / 2.0 + 4.inch, 0.inch, Rotation2d()) 114 | ) 115 | 116 | val bl = center.transformBy( 117 | Transform2d(-Properties.kRobotLength / 2, -Properties.kRobotWidth / 2, Rotation2d()) 118 | ) 119 | 120 | val br = center.transformBy( 121 | Transform2d(Properties.kRobotLength / 2, -Properties.kRobotWidth / 2, Rotation2d()) 122 | ) 123 | 124 | return arrayOf(tl, tr, mid, br, bl, tl) 125 | } 126 | 127 | fun clear() { 128 | robotSeries.data.clear() 129 | pathSeries.data.clear() 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/charts/PositionChart.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.charts 2 | 3 | import edu.wpi.first.wpilibj.geometry.Rotation2d 4 | import javafx.beans.property.SimpleObjectProperty 5 | import javafx.scene.chart.LineChart 6 | import javafx.scene.chart.NumberAxis 7 | import javafx.scene.control.Tooltip 8 | import javafx.scene.input.MouseButton 9 | import javafx.scene.paint.Color 10 | import javafx.scene.paint.Paint 11 | import org.ghrobotics.falcondashboard.generator.GeneratorView 12 | import org.ghrobotics.falcondashboard.generator.charts.PositionChart.setOnMouseClicked 13 | import org.ghrobotics.lib.mathematics.twodim.geometry.Pose2d 14 | import org.ghrobotics.lib.mathematics.twodim.geometry.x_u 15 | import org.ghrobotics.lib.mathematics.twodim.geometry.y_u 16 | import org.ghrobotics.lib.mathematics.units.feet 17 | import org.ghrobotics.lib.mathematics.units.inFeet 18 | import tornadofx.MultiValue 19 | import tornadofx.bind 20 | import tornadofx.data 21 | import tornadofx.style 22 | 23 | /** 24 | * Chart that is used to display the field view for the trajectory 25 | * generator. 26 | */ 27 | object PositionChart : LineChart( 28 | NumberAxis(0.0, 54.0, 1.0), 29 | NumberAxis(0.0, 27.0, 1.0) 30 | ) { 31 | // Series 32 | private val seriesXY = Series() 33 | private val seriesWayPoints = Series() 34 | 35 | init { 36 | // Set styles 37 | style { 38 | backgroundColor = MultiValue(arrayOf(Color.LIGHTGRAY)) 39 | } 40 | lookup(".chart-plot-background").style += 41 | "-fx-background-image: url(\"chart-background.png\");" + 42 | "-fx-background-size: stretch;" + 43 | "-fx-background-position: top right;" + 44 | "-fx-background-repeat: no-repeat;" 45 | 46 | axisSortingPolicy = SortingPolicy.NONE 47 | isLegendVisible = false 48 | animated = false 49 | createSymbols = true 50 | verticalGridLinesVisible = false 51 | isHorizontalGridLinesVisible = false 52 | 53 | data.add(seriesXY) 54 | data.add(seriesWayPoints) 55 | 56 | // Add waypoint on double click 57 | setOnMouseClicked { 58 | if (it.button == MouseButton.PRIMARY) { 59 | if (it.clickCount == 2) { 60 | val plotX = xAxis.getValueForDisplay(xAxis.sceneToLocal(it.sceneX, it.sceneY).x) 61 | val plotY = yAxis.getValueForDisplay(yAxis.sceneToLocal(it.sceneX, it.sceneY).y) 62 | GeneratorView.waypoints.add(Pose2d(plotX.feet, plotY.feet, Rotation2d())) 63 | } 64 | } 65 | } 66 | 67 | // Bind data to waypoints table 68 | seriesWayPoints.data 69 | .bind(GeneratorView.waypoints) { 70 | val data = Data( 71 | it.translation.x_u.inFeet(), 72 | it.translation.y_u.inFeet() 73 | ) 74 | val currentPose2d = SimpleObjectProperty(it) 75 | currentPose2d.addListener { _, oldPose, newPose -> 76 | GeneratorView.waypoints[GeneratorView.waypoints.indexOf(oldPose)] = newPose 77 | } 78 | val node = PositionNode( 79 | data, 80 | (xAxis as NumberAxis), 81 | (yAxis as NumberAxis), 82 | currentPose2d 83 | ) 84 | data.node = node 85 | 86 | data 87 | } 88 | 89 | updateSeriesXY() 90 | GeneratorView.trajectory.addListener { _, _, _ -> 91 | updateSeriesXY() 92 | } 93 | } 94 | 95 | /** 96 | * Updates the trajectory on the field. 97 | */ 98 | private fun updateSeriesXY() { 99 | seriesXY.data.clear() 100 | 101 | val duration = GeneratorView.trajectory.value.totalTimeSeconds 102 | var t = 0.0 103 | val dt = 0.02 104 | 105 | while (t <= duration) { 106 | val point = GeneratorView.trajectory.value.sample(t) 107 | t += dt 108 | 109 | val data = seriesXY.data( 110 | point.poseMeters.translation.x_u.inFeet(), 111 | point.poseMeters.translation.y_u.inFeet(), 112 | point.poseMeters.rotation.degrees 113 | ) 114 | Tooltip.install( 115 | data.node, 116 | Tooltip( 117 | "%2.2f feet, %2.2f feet, %2.2f degrees".format( 118 | data.xValue, 119 | data.yValue, 120 | data.extraValue 121 | ) 122 | ) 123 | ) 124 | data.node.toBack() 125 | } 126 | } 127 | 128 | override fun resize(width: Double, height: Double) = super.resize(height / 27 * 54, height) 129 | } -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/charts/PositionNode.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.charts 2 | 3 | import edu.wpi.first.wpilibj.geometry.Pose2d 4 | import edu.wpi.first.wpilibj.geometry.Rotation2d 5 | import javafx.beans.property.SimpleObjectProperty 6 | import javafx.scene.Cursor 7 | import javafx.scene.chart.NumberAxis 8 | import javafx.scene.chart.XYChart 9 | import javafx.scene.input.MouseEvent 10 | import javafx.scene.layout.StackPane 11 | import javafx.scene.paint.Color 12 | import org.ghrobotics.falcondashboard.mapprop 13 | import org.ghrobotics.lib.mathematics.twodim.geometry.Translation2d 14 | import org.ghrobotics.lib.mathematics.units.feet 15 | import tornadofx.box 16 | import tornadofx.em 17 | import tornadofx.multi 18 | import tornadofx.style 19 | 20 | class PositionNode( 21 | private val data: XYChart.Data, 22 | private val xAxis: NumberAxis, 23 | private val yAxis: NumberAxis, 24 | simpleObjectProperty: SimpleObjectProperty 25 | ) : StackPane() { 26 | 27 | private val robotNode = RobotNode( 28 | mapprop( 29 | simpleObjectProperty 30 | ) { value.rotation }, 31 | xAxis.scaleProperty() 32 | ) 33 | 34 | init { 35 | var dragging = false 36 | 37 | style { 38 | backgroundColor = multi(Color.TRANSPARENT) 39 | padding = box(1.5.em) 40 | } 41 | children.add(robotNode) 42 | 43 | robotNode.robotPane.apply { 44 | var mouseXOffset = 0.0 45 | var mouseYOffset = 0.0 46 | 47 | setOnMousePressed { event -> 48 | if (!dragging) { 49 | dragging = true 50 | val location = event.locationRelativeToNode() 51 | mouseXOffset = location.first 52 | mouseYOffset = location.second 53 | } 54 | } 55 | 56 | setOnMouseDragged { event -> 57 | val (plotX, plotY) = event.locationRelativeToPlot() 58 | 59 | data.xValue = xAxis.getValueForDisplay(plotX - mouseXOffset) 60 | data.yValue = yAxis.getValueForDisplay(plotY - mouseYOffset) 61 | } 62 | 63 | setOnMouseReleased { 64 | dragging = false 65 | simpleObjectProperty.value = Pose2d( 66 | Translation2d( 67 | data.xValue.feet, 68 | data.yValue.feet 69 | ), 70 | simpleObjectProperty.value.rotation 71 | ) 72 | } 73 | 74 | setOnMouseEntered { 75 | scene.cursor = Cursor.MOVE 76 | } 77 | setOnMouseExited { 78 | scene.cursor = Cursor.CROSSHAIR 79 | } 80 | } 81 | 82 | var rotating = false 83 | var rotationOffset = Rotation2d() 84 | 85 | setOnMousePressed { event -> 86 | if (!rotating && !dragging) { 87 | rotating = true 88 | robotNode.robotRotation.unbind() 89 | rotationOffset = 90 | Rotation2d.fromDegrees(robotNode.robotRotation.get()) - event.angleRelativeToNode() 91 | } 92 | } 93 | 94 | setOnMouseDragged { event -> 95 | if (rotating) { 96 | val angle = event.angleRelativeToNode() 97 | 98 | robotNode.robotRotation.set((angle + rotationOffset).degrees) 99 | } 100 | } 101 | 102 | setOnMouseReleased { 103 | if (rotating) { 104 | rotating = false 105 | simpleObjectProperty.value = Pose2d( 106 | simpleObjectProperty.value.translation, 107 | Rotation2d.fromDegrees(-robotNode.robotRotation.value) 108 | ) 109 | robotNode.bindRobotRotation() 110 | } 111 | } 112 | 113 | setOnMouseEntered { 114 | scene.cursor = Cursor.CROSSHAIR 115 | } 116 | setOnMouseExited { 117 | scene.cursor = Cursor.DEFAULT 118 | } 119 | } 120 | 121 | private fun MouseEvent.angleRelativeToNode(): Rotation2d { 122 | val (localMouseX, localMouseY) = locationRelativeToNode() 123 | return Rotation2d(localMouseX, localMouseY) 124 | } 125 | 126 | private fun MouseEvent.locationRelativeToNode(): Pair { 127 | val (plotX, plotY) = locationRelativeToPlot() 128 | 129 | val localMouseX = plotX - xAxis.getDisplayPosition(data.xValue) 130 | val localMouseY = plotY - yAxis.getDisplayPosition(data.yValue) 131 | 132 | return localMouseX to localMouseY 133 | } 134 | 135 | private fun MouseEvent.locationRelativeToPlot(): Pair { 136 | val plotX = xAxis.sceneToLocal(sceneX, sceneY).x 137 | val plotY = yAxis.sceneToLocal(sceneX, sceneY).y 138 | return plotX to plotY 139 | } 140 | 141 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/tables/WaypointsTable.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator.tables 2 | 3 | import edu.wpi.first.wpilibj.geometry.Pose2d 4 | import edu.wpi.first.wpilibj.geometry.Rotation2d 5 | import javafx.beans.property.SimpleObjectProperty 6 | import javafx.scene.control.TableRow 7 | import javafx.scene.control.TableView 8 | import javafx.scene.control.cell.TextFieldTableCell 9 | import javafx.scene.input.ClipboardContent 10 | import javafx.scene.input.DataFormat 11 | import javafx.scene.input.TransferMode 12 | import javafx.util.converter.DoubleStringConverter 13 | import org.ghrobotics.falcondashboard.generator.GeneratorView 14 | import org.ghrobotics.falcondashboard.generator.tables.WaypointsTable.setRowFactory 15 | import org.ghrobotics.lib.mathematics.twodim.geometry.Pose2d 16 | import org.ghrobotics.lib.mathematics.twodim.geometry.Translation2d 17 | import org.ghrobotics.lib.mathematics.twodim.geometry.x_u 18 | import org.ghrobotics.lib.mathematics.twodim.geometry.y_u 19 | import org.ghrobotics.lib.mathematics.units.derived.degrees 20 | import org.ghrobotics.lib.mathematics.units.feet 21 | import org.ghrobotics.lib.mathematics.units.inFeet 22 | import tornadofx.column 23 | import kotlin.math.round 24 | 25 | object WaypointsTable : TableView(GeneratorView.waypoints) { 26 | 27 | private val columnX = column("X") { 28 | SimpleObjectProperty(round(it.value.translation.x_u.inFeet() * 1E3) / 1E3) 29 | } 30 | 31 | private val columnY = column("Y") { 32 | SimpleObjectProperty(round(it.value.translation.y_u.inFeet() * 1E3) / 1E3) 33 | } 34 | 35 | private val columnAngle = column("Angle") { 36 | SimpleObjectProperty(round(it.value.rotation.degrees)) 37 | } 38 | 39 | private val cellFactory = { 40 | val cell = TextFieldTableCell() 41 | cell.converter = DoubleStringConverter() 42 | cell 43 | } 44 | 45 | init { 46 | isEditable = true 47 | 48 | columnResizePolicy = CONSTRAINED_RESIZE_POLICY 49 | 50 | columns.forEach { 51 | it.isSortable = false 52 | it.isReorderable = false 53 | } 54 | 55 | with(columnX) { 56 | setCellFactory { cellFactory() } 57 | setOnEditCommit { 58 | val history = it.rowValue 59 | this@WaypointsTable.items[it.tablePosition.row] = Pose2d( 60 | Translation2d(it.newValue.feet, history.translation.y_u), 61 | history.rotation 62 | ) 63 | this@WaypointsTable.refresh() 64 | } 65 | } 66 | with(columnY) { 67 | setCellFactory { cellFactory() } 68 | setOnEditCommit { 69 | val history = it.rowValue 70 | this@WaypointsTable.items[it.tablePosition.row] = Pose2d( 71 | Translation2d(history.translation.x_u, it.newValue.feet), 72 | history.rotation 73 | ) 74 | this@WaypointsTable.refresh() 75 | } 76 | } 77 | with(columnAngle) { 78 | setCellFactory { cellFactory() } 79 | setOnEditCommit { 80 | val history = it.rowValue 81 | this@WaypointsTable.items[it.tablePosition.row] = Pose2d( 82 | history.translation, 83 | Rotation2d.fromDegrees(it.newValue) 84 | ) 85 | this@WaypointsTable.refresh() 86 | } 87 | } 88 | 89 | setRowFactory { _ -> 90 | val row = TableRow() 91 | 92 | row.setOnDragDetected { 93 | if (!row.isEmpty) { 94 | val index = row.index 95 | val db = startDragAndDrop(TransferMode.MOVE) 96 | db.dragView = row.snapshot(null, null) 97 | 98 | val cc = ClipboardContent() 99 | cc.putString(index.toString()) 100 | db.setContent(cc) 101 | it.consume() 102 | } 103 | } 104 | 105 | row.setOnDragOver { 106 | if (it.dragboard.hasString()) { 107 | if (row.index != it.dragboard.getContent(DataFormat.PLAIN_TEXT).toString().toInt()) { 108 | it.acceptTransferModes(*TransferMode.COPY_OR_MOVE) 109 | it.consume() 110 | } 111 | } 112 | it.consume() 113 | } 114 | 115 | row.setOnDragDropped { 116 | val db = it.dragboard 117 | if (db.hasString()) { 118 | val dragIndex = db.getContent(DataFormat.PLAIN_TEXT).toString().toInt() 119 | val dropIndex = if (row.isEmpty) { 120 | this@WaypointsTable.items.size 121 | } else row.index 122 | 123 | if (this@WaypointsTable.items.size > 2) { 124 | this@WaypointsTable.items.add(dropIndex, this@WaypointsTable.items.removeAt(dragIndex)) 125 | } else { 126 | this@WaypointsTable.items.reverse() 127 | } 128 | it.isDropCompleted = true 129 | it.consume() 130 | } 131 | } 132 | return@setRowFactory row 133 | } 134 | } 135 | 136 | fun loadFromText(text: String) { 137 | val lines = text.lines() 138 | 139 | val poses: List = lines.map { 140 | if(it.isEmpty()) return@map null 141 | var trim = it 142 | .replace(" ", "") 143 | .let { it2 -> if(it2.last() == ',') it2.substring(0, it2.length - 1) else it2 } 144 | .let { it2 -> if(!it2.startsWith("Pose2d", true)) null else it2 } ?: return@map null 145 | 146 | // so at this point all of our text starts with Pose2d and ends with a closing paren. 147 | // start by removing the starting and closing parenthesis 148 | 149 | trim = trim.substring(7, trim.length- 1) 150 | val x = trim.substring(0, trim.indexOf(".feet")) 151 | .let { it2 -> 152 | if(it2.startsWith("(") || it2.endsWith(")")) { 153 | return@let it2.substring(1, it2.length - 1) 154 | } else it2 155 | } 156 | .toDouble() 157 | val trimNoX = trim.substring(trim.indexOf(".feet") + 6, trim.length) 158 | val y = trimNoX.substring(0, trimNoX.indexOf(".feet")) 159 | .let { it2 -> 160 | if(it2.startsWith("(") || it2.endsWith(")")) { 161 | return@let it2.substring(1, it2.length - 1) 162 | } else it2 163 | } 164 | .toDouble() 165 | val trimNoY = trimNoX.substring(trimNoX.indexOf(".feet") + 6, trimNoX.length) 166 | val theta: Double = trimNoY.let { noY -> 167 | val index: Int = noY.indexOf(".degrees").let { ret -> 168 | if(ret < 0) noY.indexOf(".degree") else ret 169 | } 170 | val numberWithMaybeParens = noY.substring(0, index) 171 | if(numberWithMaybeParens.startsWith("(") || numberWithMaybeParens.endsWith(")")) { 172 | return@let numberWithMaybeParens.substring(1, numberWithMaybeParens.length - 1).toDouble() 173 | } 174 | return@let numberWithMaybeParens.toDouble() 175 | } 176 | val pose = Pose2d(x.feet, y.feet, theta.degrees) 177 | pose 178 | } 179 | GeneratorView.waypoints.setAll(poses.filterNotNull()) 180 | } 181 | 182 | fun removeSelectedItemIfPossible() { 183 | val item = selectionModel.selectedItem 184 | if (item != null && items.size > 2) GeneratorView.waypoints.remove(item) 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/main/kotlin/org/ghrobotics/falcondashboard/generator/GeneratorView.kt: -------------------------------------------------------------------------------- 1 | package org.ghrobotics.falcondashboard.generator 2 | 3 | import edu.wpi.first.wpilibj.geometry.Rotation2d 4 | import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig 5 | import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator 6 | import edu.wpi.first.wpilibj.trajectory.constraint.CentripetalAccelerationConstraint 7 | import edu.wpi.first.wpilibj.util.Units 8 | import javafx.beans.property.SimpleObjectProperty 9 | import javafx.geometry.Pos 10 | import javafx.scene.layout.Priority 11 | import javafx.scene.paint.Color 12 | import javafx.stage.StageStyle 13 | import kfoenix.jfxbutton 14 | import kfoenix.jfxcheckbox 15 | import kfoenix.jfxtabpane 16 | import kfoenix.jfxtextfield 17 | import org.ghrobotics.falcondashboard.Settings.autoPathFinding 18 | import org.ghrobotics.falcondashboard.Settings.clampedCubic 19 | import org.ghrobotics.falcondashboard.Settings.endVelocity 20 | import org.ghrobotics.falcondashboard.Settings.maxAcceleration 21 | import org.ghrobotics.falcondashboard.Settings.maxCentripetalAcceleration 22 | import org.ghrobotics.falcondashboard.Settings.maxVelocity 23 | import org.ghrobotics.falcondashboard.Settings.name 24 | import org.ghrobotics.falcondashboard.Settings.reversed 25 | import org.ghrobotics.falcondashboard.Settings.startVelocity 26 | import org.ghrobotics.falcondashboard.createNumericalEntry 27 | import org.ghrobotics.falcondashboard.generator.charts.PositionChart 28 | import org.ghrobotics.falcondashboard.generator.charts.VelocityChart 29 | import org.ghrobotics.falcondashboard.generator.fragments.CodeFragment 30 | import org.ghrobotics.falcondashboard.generator.fragments.KtCodeFragment 31 | import org.ghrobotics.falcondashboard.generator.fragments.WaypointFragment 32 | import org.ghrobotics.falcondashboard.generator.tables.WaypointsTable 33 | import org.ghrobotics.lib.mathematics.epsilonEquals 34 | import org.ghrobotics.lib.mathematics.twodim.geometry.Pose2d 35 | import org.ghrobotics.lib.mathematics.twodim.trajectory.FalconTrajectoryConfig 36 | import org.ghrobotics.lib.mathematics.twodim.trajectory.optimization.PathFinder 37 | import org.ghrobotics.lib.mathematics.units.derived.acceleration 38 | import org.ghrobotics.lib.mathematics.units.derived.velocity 39 | import org.ghrobotics.lib.mathematics.units.feet 40 | import tornadofx.* 41 | 42 | class GeneratorView : View() { 43 | 44 | override val root = hbox { 45 | stylesheets += resources["/GeneratorStyle.css"] 46 | vbox { 47 | style { 48 | paddingAll = 20.0 49 | maxWidth = 300.px 50 | spacing = 5.px 51 | } 52 | 53 | hbox { 54 | paddingAll = 5 55 | jfxtextfield { 56 | bind(name) 57 | prefWidth = 290.0 58 | } 59 | } 60 | 61 | jfxcheckbox { 62 | paddingAll = 5 63 | text = "Reversed" 64 | bind(reversed) 65 | } 66 | jfxcheckbox { 67 | paddingAll = 5 68 | text = "Clamped Cubic" 69 | bind(clampedCubic) 70 | } 71 | jfxcheckbox { 72 | paddingAll = 5 73 | text = "Auto Path Finding (Experimental)" 74 | bind(autoPathFinding) 75 | } 76 | 77 | createNumericalEntry("Start Velocity (f/s)", startVelocity) 78 | createNumericalEntry("End Velocity (f/s)", endVelocity) 79 | createNumericalEntry("Max Velocity (f/s)", maxVelocity) 80 | createNumericalEntry("Max Acceleration (f/s/s)", maxAcceleration) 81 | createNumericalEntry("Max Centripetal Acceleration (f/s/s)", maxCentripetalAcceleration) 82 | 83 | this += WaypointsTable 84 | 85 | vbox { 86 | spacing = 5.0 87 | jfxbutton { 88 | prefWidth = 290.0 89 | text = "Add Waypoint" 90 | action { 91 | find().openModal(stageStyle = StageStyle.UTILITY) 92 | } 93 | } 94 | jfxbutton { 95 | prefWidth = 290.0 96 | text = "Remove Waypoint" 97 | action { 98 | WaypointsTable.removeSelectedItemIfPossible() 99 | } 100 | } 101 | jfxbutton { 102 | prefWidth = 290.0 103 | text = "Load from text" 104 | action { 105 | object : Fragment() { 106 | override val root = vbox { 107 | 108 | prefWidth = 600.0 109 | prefHeight = 200.0 110 | 111 | val textEntryArea = textarea { 112 | prefWidth = 290.0 113 | 114 | isWrapText = true 115 | 116 | text = " Pose2d(11.75.feet, 25.689.feet, 0.0.degrees),\n" + 117 | " Pose2d(20.383.feet, 18.592.feet, (-68).degrees)" 118 | } 119 | jfxbutton { 120 | prefWidth = 290.0 121 | text = "Load from text" 122 | action { 123 | WaypointsTable.loadFromText(textEntryArea.text) 124 | } 125 | } 126 | } 127 | }.openModal(stageStyle = StageStyle.UTILITY) 128 | } 129 | } 130 | jfxbutton { 131 | prefWidth = 290.0 132 | text = "Generate JSON" 133 | action { 134 | find().openModal(stageStyle = StageStyle.UTILITY) 135 | } 136 | } 137 | jfxbutton { 138 | prefWidth = 290.0 139 | text = "Generate Code" 140 | action { 141 | find().openModal(stageStyle = StageStyle.UTILITY) 142 | } 143 | } 144 | } 145 | } 146 | jfxtabpane { 147 | maxWidth = Double.MAX_VALUE 148 | hgrow = Priority.ALWAYS 149 | style { 150 | backgroundColor = multi(Color.LIGHTGRAY) 151 | } 152 | tab("Position") { 153 | hbox { 154 | alignment = Pos.CENTER_LEFT 155 | add(PositionChart) 156 | } 157 | isClosable = false 158 | } 159 | tab("Velocity") { 160 | add(VelocityChart) 161 | isClosable = false 162 | } 163 | } 164 | } 165 | 166 | companion object { 167 | val waypoints = observableListOf( 168 | Pose2d(1.5.feet, 23.feet, Rotation2d()), 169 | Pose2d(11.5.feet, 23.feet, Rotation2d()) 170 | ) 171 | 172 | private val config: TrajectoryConfig = 173 | FalconTrajectoryConfig(maxVelocity.value.feet.velocity, maxAcceleration.value.feet.acceleration) 174 | .setStartVelocity(startVelocity.value.feet.velocity) 175 | .setEndVelocity(endVelocity.value.feet.velocity) 176 | .addConstraint(CentripetalAccelerationConstraint(Units.feetToMeters(maxCentripetalAcceleration.value))) 177 | .setReversed(reversed.value) 178 | 179 | val trajectory = SimpleObjectProperty(TrajectoryGenerator.generateTrajectory(waypoints, config)) 180 | 181 | init { 182 | update() 183 | waypoints.onChange { update() } 184 | reversed.onChange { update() } 185 | clampedCubic.onChange { update() } 186 | autoPathFinding.onChange { update() } 187 | 188 | startVelocity.onChange { update() } 189 | endVelocity.onChange { update() } 190 | maxVelocity.onChange { update() } 191 | maxAcceleration.onChange { update() } 192 | maxCentripetalAcceleration.onChange { update() } 193 | } 194 | 195 | @Synchronized 196 | private fun update() { 197 | if (startVelocity.value.isNaN() || 198 | endVelocity.value.isNaN() || 199 | maxVelocity.value epsilonEquals 0.0 || 200 | maxAcceleration.value epsilonEquals 0.0 || 201 | maxCentripetalAcceleration.value epsilonEquals 0.0 202 | ) return 203 | 204 | val wayPoints = if (autoPathFinding.value) { 205 | val pathFinder = PathFinder( 206 | 3.5.feet, 207 | PathFinder.k2018CubesSwitch, 208 | PathFinder.k2018LeftSwitch, 209 | PathFinder.k2018Platform 210 | ) 211 | waypoints.zipWithNext { start, end -> 212 | kotlin.runCatching { 213 | pathFinder.findPath(start, end)!! 214 | }.recover { listOf(start, end) } 215 | .getOrThrow() 216 | }.flatten().toSet().toList() 217 | } else waypoints.toList() 218 | 219 | val config = FalconTrajectoryConfig(maxVelocity.value.feet.velocity, maxAcceleration.value.feet.acceleration) 220 | .setStartVelocity(startVelocity.value.feet.velocity) 221 | .setEndVelocity(endVelocity.value.feet.velocity) 222 | .addConstraint(CentripetalAccelerationConstraint(Units.feetToMeters(maxCentripetalAcceleration.value))) 223 | .setReversed(reversed.value) 224 | 225 | if(clampedCubic.value) { 226 | val startPose = wayPoints.first() 227 | val endPose = waypoints.last() 228 | val interiorWaypoints = wayPoints.subList(1, waypoints.size - 1).map { it.translation } 229 | 230 | this.trajectory.set(TrajectoryGenerator.generateTrajectory(startPose, interiorWaypoints, endPose, config)) 231 | } else { 232 | this.trajectory.set(TrajectoryGenerator.generateTrajectory(wayPoints, config)) 233 | } 234 | } 235 | } 236 | } --------------------------------------------------------------------------------