├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── azure-pipelines.yml ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── FRC2018.jpg ├── FRC2019.jpg └── ProgramWindow.PNG ├── settings.gradle └── src ├── java └── com │ └── mammen │ ├── file_io │ └── FileIO.java │ ├── generator │ ├── Generator.java │ ├── PfV1Generator.java │ └── generator_vars │ │ ├── DriveBase.java │ │ ├── GeneratorVars.java │ │ ├── PfV1GeneratorVars.java │ │ ├── SharedGeneratorVars.java │ │ └── Units.java │ ├── main │ ├── Main.java │ ├── MainApp.java │ └── MainUIModel.java │ ├── path │ ├── Path.java │ └── Waypoint.java │ ├── settings │ ├── SettingsModel.java │ └── SourcePathDisplayType.java │ ├── ui │ └── javafx │ │ ├── dialog │ │ ├── about │ │ │ ├── AboutDialog.fxml │ │ │ └── AboutDialogController.java │ │ ├── add_waypoint │ │ │ ├── AddWaypointDialog.fxml │ │ │ └── AddWaypointDialogController.java │ │ ├── factory │ │ │ ├── AlertFactory.java │ │ │ └── DialogFactory.java │ │ └── settings │ │ │ ├── SettingsDialog.fxml │ │ │ ├── SettingsDialogController.java │ │ │ └── generator_vars │ │ │ ├── PathfinderV1VarsController.java │ │ │ └── PathfinderV1VarsUI.fxml │ │ └── main │ │ ├── MainUI.fxml │ │ ├── MainUIController.java │ │ └── graphs │ │ ├── PosGraphController.java │ │ ├── PosGraphUI.fxml │ │ ├── VelGraphController.java │ │ └── VelGraphUI.fxml │ └── util │ ├── Mathf.java │ ├── OSValidator.java │ ├── ResourceLoader.java │ └── SerializeHelpers │ ├── ObjectSerializer.java │ ├── ReadObjectsHelper.java │ └── WriteObjectsHelper.java └── resources └── images ├── FRC2018.jpg └── FRC2019.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /mp_left.csv 3 | /*.ini 4 | *.ini 5 | /mp_right.csv 6 | /mp_right_detailed.csv 7 | /mp_left_detailed.csv 8 | /build 9 | .idea/**/* 10 | *.iml 11 | .gradle 12 | *.ipr 13 | 14 | *.iws 15 | out 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## [4.0.1] - 2019-1-22 8 | ### Changed 9 | - Fix bug where the x-axis was labeled incorrectly on the position graph when the units were changed. 10 | 11 | ## [4.0.0] - 2019-1-2 12 | ### Added 13 | - Waypoints can now be repositioned by clicking and dragging. 14 | - Now select what data you want exported in the csv and in what order. 15 | - Select which generator you want to use ( Only Pathfinder V1 for now ). 16 | - Graph maintains aspect ratio when resized. 17 | - Field image loaded from jar. 18 | - Now supports Windows, Mac and Linux. 19 | 20 | ### Changed 21 | - MOVED TO JAVA 11 22 | - Moved generator (Pathfinder) variables into the settings window. 23 | - Added a slight transparency to the grid lines on the position graph. 24 | - Misc. UI changes. 25 | 26 | ### Removed 27 | - "CSV Type" setting. 28 | - Support for .bot files (project settings). 29 | - Support for .traj export file type (binary path file). 30 | 31 | ## [3.0.0] - 2018-4-29 32 | ### Added 33 | - Completely rewritten using JavaFX for the GUI 34 | - Added a settings menu with settings that will persist across runs 35 | - Settings now saved in xml in home directory 36 | - Added new unit (Inches) 37 | - Changeable background image for position graph. 38 | - Export CSV type; Talon SRX or Jaci 39 | - Show waypoints on position graph. 40 | - Auto regenerate trajectory when any value is changed. 41 | - Other misc changes. Easter eggs? 42 | 43 | 44 | ## [2.3.0] - 2018-2-22 45 | ### Added 46 | - Added ability to choose between different units (Feet and Meters) 47 | 48 | ### Fixed 49 | - Bug where a user could get stuck in point update mode 50 | 51 | ## [2.2.0] - 2018-2-1 52 | ### Added 53 | - Added ability to choose the Fit method of the points. Hermite Cubic or Hermite Quintic 54 | - Added ability to choose between the Tank and Swerve modifiers 55 | - Added Tool tip text 56 | 57 | ### Fixed 58 | - Bug where app would crash when you double clicked in white space to update a point 59 | 60 | ## [2.1.0] - 2018-1-27 61 | ### Added 62 | - Added button to delete last point in the list (Thanks Team 1414) 63 | 64 | ## [2.0.0] - 2018-1-10 65 | ### Added 66 | - Added graphs for this years game!!! 67 | 68 | ## [1.2.0] - 2017-12-29 69 | ### Added 70 | - Added a preference system to reload old profile settings 71 | 72 | ### Fixed 73 | - The menu saving option now checks if file exists before saving 74 | 75 | ## [1.1.0] - 2017-12-20 76 | ### Added 77 | - Ability to edit existing waypoints without clearing entire list 78 | 79 | ## [1.0.2] - 2017-12-16 80 | ### Added 81 | - Ability to replace existing file when saving 82 | 83 | ### Changed 84 | - Moved Velocity Graph to the tabbed pane 85 | - Reworked Saving UX to make it more user friendly 86 | - Motion Profile displays on both red and blue tab 87 | 88 | ### Fixed 89 | - Resized menu bar to extend across entire window 90 | - Negative variables are now checked for 91 | - Fixed bug that allowed multiple graphs to be displayed on one graph 92 | 93 | ## [1.0.1] - 2017-11-11 94 | ### Added 95 | - Originally only had the blue alliance graph. Added red alliance graph 96 | - Tabbed view to switch between red and blue graphs 97 | - Motion Profile displays based on chosen tab 98 | - Menu bar with various items 99 | 100 | ### Removed 101 | - Save Button (moved action to menu bar) 102 | 103 | ## [1.0.0] - 2017-11-05 104 | ### Added 105 | - Initial Release 106 | - Graphs to display the motion profile and the velocity 107 | - Text boxes to enter the variables: Time Step, Velocity, Acceleration, Jerk, Wheel Base 108 | - Ability to enter waypoints through a separate text box for each: X, Y, and Angle 109 | - Validation for waypoints 110 | - Display points in a list box each time the "Add Point" button is pressed 111 | - Clear button clears the graphs and the list box 112 | - Text box to name the output file 113 | - Save button to choose directory and save motion profile 114 | - Generate button to calculate profile and velocity and display them -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Luke Mammen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Motion Profile Generator 2 | 3 | [![Build Status](https://dev.azure.com/Mammen-Robotics/Motion%20Profile%20Generator/_apis/build/status/vannaka.Motion_Profile_Generator?branchName=develop)](https://dev.azure.com/Mammen-Robotics/Motion%20Profile%20Generator/_build/latest?definitionId=1?branchName=develop) 4 | 5 | Generate paths to follow with a robot. 6 | 7 | ![alt text][logo] 8 | 9 | [logo]: https://github.com/vannaka/Motion_Profile_Generator/blob/master/images/ProgramWindow.PNG 10 | 11 | ## Get the App 12 | - [Here](https://github.com/vannaka/Motion_Profile_Generator/releases) 13 | 14 | ## Running the App 15 | - You will need java 11 to run this app. Download it [here](https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html). 16 | - Make sure the java 11 executable is in your path. 17 | - Double click `Motion_Profile_Generator_4.x.x.jar` to run. 18 | 19 | ## Usage Info 20 | - Checkout the wiki [Here](https://github.com/vannaka/Motion_Profile_Generator/wiki). 21 | 22 | ## Build Information 23 | - You will need Java 11; download it [here](https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html). 24 | - In the project folder run `gradlew build` 25 | - The JAR artifact will be created in `build/libs` 26 | 27 | ## Changelog 28 | - [Here](https://github.com/vannaka/Motion_Profile_Generator/blob/develop/CHANGELOG.md) 29 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | ## Gradle 2 | # Build your Java project and run tests with Gradle using a Gradle wrapper script. 3 | # Add steps that analyze code, save build artifacts, deploy, and more: 4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/java 5 | 6 | trigger: 7 | - master 8 | - develop 9 | 10 | pool: 11 | vmImage: 'vs2017-win2016' 12 | 13 | steps: 14 | - powershell: | 15 | mkdir build 16 | $ProgressPreference = 'SilentlyContinue' 17 | wget "https://download.java.net/java/ga/jdk11/openjdk-11_windows-x64_bin.zip" -O "build\jdk.zip" 18 | displayName: 'Download JDK 11' 19 | 20 | - task: JavaToolInstaller@0 21 | inputs: 22 | jdkSourceOption: localDirectory 23 | jdkFile: 'build/jdk.zip' 24 | jdkDestinationDirectory: 'build/jdkinst' 25 | jdkArchitectureOption: x64 26 | 27 | - task: Gradle@2 28 | inputs: 29 | workingDirectory: '' 30 | gradleWrapperFile: 'gradlew' 31 | gradleOptions: '-Xmx3072m' 32 | publishJUnitResults: false 33 | testResultsFiles: '**/TEST-*.xml' 34 | tasks: 'build' 35 | 36 | - task: CopyFiles@2 37 | inputs: 38 | sourceFolder: 'build/libs/' 39 | contents: '*.jar' 40 | targetFolder: $(Build.ArtifactStagingDirectory) 41 | 42 | - task: PublishBuildArtifacts@1 43 | inputs: 44 | artifactName: 'Motion Profile Generator' 45 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'application' 3 | id 'java' 4 | id 'idea' 5 | id 'eclipse' 6 | 7 | id 'org.openjfx.javafxplugin' version '0.0.5' 8 | id "com.github.johnrengelman.shadow" version "4.0.3" 9 | } 10 | 11 | 12 | mainClassName = 'com.mammen.main.Main' 13 | version = "4.0.1" 14 | 15 | project.sourceCompatibility = 11.0 16 | project.targetCompatibility = 11.0 17 | 18 | 19 | repositories { 20 | mavenCentral() 21 | jcenter() 22 | maven { 23 | url = uri( "https://dev.imjac.in/maven/" ) 24 | } 25 | } 26 | 27 | 28 | dependencies { 29 | // JavaFX cross platform packages 30 | compile( "org.openjfx:javafx-graphics:11:win" ) 31 | compile( "org.openjfx:javafx-graphics:11:linux" ) 32 | compile( "org.openjfx:javafx-graphics:11:mac" ) 33 | 34 | // FontAwesome Icons 35 | compile( 'de.jensd:fontawesomefx-commons:9.1.2' ) 36 | compile( 'de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2' ) 37 | 38 | // For loading native libs 39 | compile( "jaci.jniloader:JNILoader:1.0.1" ) 40 | 41 | // Pathfinder V1 42 | compile( "jaci.pathfinder:Pathfinder-Java:2019.1.10" ) 43 | 44 | compile( "jaci.pathfinder:Pathfinder-JNI:2019.1.10:windowsx86" ) 45 | compile( "jaci.pathfinder:Pathfinder-JNI:2019.1.10:windowsx86-64" ) 46 | compile( "jaci.pathfinder:Pathfinder-JNI:2019.1.10:osxx86-64" ) 47 | compile( "jaci.pathfinder:Pathfinder-JNI:2019.1.10:linuxx86" ) 48 | compile( "jaci.pathfinder:Pathfinder-JNI:2019.1.10:linuxx86-64" ) 49 | 50 | compile( "jaci.pathfinder:Pathfinder-CoreJNI:2019.1.10:windowsx86" ) 51 | compile( "jaci.pathfinder:Pathfinder-CoreJNI:2019.1.10:windowsx86-64" ) 52 | compile( "jaci.pathfinder:Pathfinder-CoreJNI:2019.1.10:osxx86-64" ) 53 | compile( "jaci.pathfinder:Pathfinder-CoreJNI:2019.1.10:linuxx86" ) 54 | compile( "jaci.pathfinder:Pathfinder-CoreJNI:2019.1.10:linuxx86-64" ) 55 | 56 | // Pathfinder V2 57 | // compile( "grpl.pathfinder:Pathfinder-Java:2.0.0-prealpha" ) 58 | // 59 | // compile( "grpl.pathfinder:Pathfinder-JNI:2.0.0-prealpha:windowsx86" ) 60 | // compile( "grpl.pathfinder:Pathfinder-JNI:2.0.0-prealpha:windowsx86-64" ) 61 | // compile( "grpl.pathfinder:Pathfinder-JNI:2.0.0-prealpha:osxx86-64" ) 62 | // compile( "grpl.pathfinder:Pathfinder-JNI:2.0.0-prealpha:linuxx86" ) 63 | // compile( "grpl.pathfinder:Pathfinder-JNI:2.0.0-prealpha:linuxx86-64" ) 64 | } 65 | 66 | 67 | javafx { 68 | modules = [ 'javafx.base', 'javafx.controls', 'javafx.fxml', 'javafx.graphics' ] 69 | } 70 | 71 | 72 | sourceSets { 73 | // Set top level dir of the java code 74 | main.java { 75 | srcDirs = ['src/java'] 76 | include '**/*.java' 77 | } 78 | 79 | // Set the top level dir of our resources 80 | main.resources { 81 | srcDirs = ['src/java', 'src/resources'] 82 | exclude '**/*.java', 'lib' 83 | } 84 | } 85 | 86 | 87 | jar { 88 | manifest { 89 | attributes( "Main-Class": mainClassName, 90 | "Version": version ) 91 | } 92 | } 93 | 94 | 95 | wrapper { 96 | // Set the version of our gradle wrapper 97 | gradleVersion = '5.0' 98 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/1df3a9970857f32ae419f3823d557a7f27a753ca/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 22 09:50:00 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip 7 | -------------------------------------------------------------------------------- /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="" 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 | -------------------------------------------------------------------------------- /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= 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 | -------------------------------------------------------------------------------- /images/FRC2018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/1df3a9970857f32ae419f3823d557a7f27a753ca/images/FRC2018.jpg -------------------------------------------------------------------------------- /images/FRC2019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/1df3a9970857f32ae419f3823d557a7f27a753ca/images/FRC2019.jpg -------------------------------------------------------------------------------- /images/ProgramWindow.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/1df3a9970857f32ae419f3823d557a7f27a753ca/images/ProgramWindow.PNG -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Motion_Profile_Generator' -------------------------------------------------------------------------------- /src/java/com/mammen/file_io/FileIO.java: -------------------------------------------------------------------------------- 1 | package com.mammen.file_io; 2 | 3 | import com.mammen.generator.generator_vars.DriveBase; 4 | import com.mammen.path.Path; 5 | 6 | import java.io.File; 7 | import java.io.FileNotFoundException; 8 | import java.io.PrintWriter; 9 | import java.util.List; 10 | 11 | public final class FileIO 12 | { 13 | 14 | public static void savePath( Path path, File savePathName, List elements ) throws FileNotFoundException 15 | { 16 | File dir = savePathName.getParentFile(); 17 | 18 | // Create dir if it does not exist yet 19 | if( dir != null && !dir.exists() && dir.isDirectory() ) 20 | { 21 | if( !dir.mkdirs() ) 22 | return; 23 | } 24 | 25 | DriveBase driveBase = path.getDriveBase(); 26 | 27 | PrintWriter flPw; 28 | PrintWriter frPw; 29 | PrintWriter blPw = null; 30 | PrintWriter brPw = null; 31 | 32 | if( driveBase == DriveBase.TANK ) 33 | { 34 | flPw = new PrintWriter( new File(savePathName + "_left.csv" ) ); 35 | frPw = new PrintWriter( new File(savePathName + "_right.csv" ) ); 36 | } 37 | else // driveBase == DriveBase.SWERVE 38 | { 39 | flPw = new PrintWriter( new File(savePathName + "_frontLeft.csv" ) ); 40 | frPw = new PrintWriter( new File(savePathName + "_frontRight.csv" ) ); 41 | blPw = new PrintWriter( new File(savePathName + "_backLeft.csv" ) ); 42 | brPw = new PrintWriter( new File(savePathName + "_backRight.csv" ) ); 43 | } 44 | 45 | // Label each column in the csv 46 | for( Path.Elements e : elements ) 47 | { 48 | flPw.print( e.toString() + ", " ); 49 | frPw.print( e.toString() + ", " ); 50 | if( blPw != null ) 51 | { 52 | blPw.print( e.toString() + ", " ); 53 | brPw.print( e.toString() + ", " ); 54 | } 55 | } 56 | flPw.println(); 57 | frPw.println(); 58 | if( blPw != null ) 59 | { 60 | blPw.println(); 61 | brPw.println(); 62 | } 63 | 64 | 65 | // Loop over every segment in the path. 66 | for( int i = 0; i < path.getLength(); i++ ) 67 | { 68 | // Write each element to the current line. 69 | for( Path.Elements e : elements ) 70 | { 71 | switch( e ) 72 | { 73 | case POSITION: 74 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).position ) ); 75 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).position ) ); 76 | if( blPw == null ) break; 77 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).position ) ); 78 | brPw.print( String.format( "%f, ", path.getBackRightSegment( i ).position ) ); 79 | break; 80 | 81 | case X_POINT: 82 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).x ) ); 83 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).x ) ); 84 | if( blPw == null ) break; 85 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).x ) ); 86 | brPw.print( String.format( "%f, ", path.getBackRightSegment( i ).x ) ); 87 | break; 88 | 89 | case Y_POINT: 90 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).y ) ); 91 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).y ) ); 92 | if( blPw == null ) break; 93 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).y ) ); 94 | brPw.print( String.format( "%f, ", path.getBackRightSegment( i ).y ) ); 95 | break; 96 | 97 | case HEADING: 98 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).heading ) ); 99 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).heading ) ); 100 | if( blPw == null ) break; 101 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).heading ) ); 102 | flPw.print( String.format( "%f, ", path.getBackRightSegment( i ).heading ) ); 103 | break; 104 | 105 | case VELOCITY: 106 | 107 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).velocity ) ); 108 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).velocity ) ); 109 | if( blPw == null ) break; 110 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).velocity ) ); 111 | brPw.print( String.format( "%f, ", path.getBackRightSegment( i ).velocity ) ); 112 | break; 113 | 114 | case ACCELERATION: 115 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).acceleration ) ); 116 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).acceleration ) ); 117 | if( blPw == null ) break; 118 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).acceleration ) ); 119 | brPw.print( String.format( "%f, ", path.getBackRightSegment( i ).acceleration ) ); 120 | break; 121 | 122 | case JERK: 123 | flPw.print( String.format( "%f, ", path.getFrontLeftSegment( i ).jerk ) ); 124 | frPw.print( String.format( "%f, ", path.getFrontRightSegment( i ).jerk ) ); 125 | if( blPw == null ) break; 126 | blPw.print( String.format( "%f, ", path.getBackLeftSegment( i ).jerk ) ); 127 | brPw.print( String.format( "%f, ", path.getBackRightSegment( i ).jerk ) ); 128 | break; 129 | 130 | case DELTA_TIME: 131 | flPw.print( String.format( "%d, ", (int)( path.getFrontLeftSegment( i ).dt * 1000 ) ) ); 132 | frPw.print( String.format( "%d, ", (int)( path.getFrontRightSegment( i ).dt * 1000 ) ) ); 133 | if( blPw == null ) break; 134 | blPw.print( String.format( "%d, ", (int)( path.getBackLeftSegment( i ).dt * 1000 ) ) ); 135 | brPw.print( String.format( "%d, ", (int)( path.getBackRightSegment( i ).dt * 1000 ) ) ); 136 | break; 137 | 138 | default: 139 | // Do nothing 140 | break; 141 | } 142 | } 143 | 144 | // End of line 145 | flPw.println(); 146 | frPw.println(); 147 | if( blPw != null ) 148 | { 149 | blPw.println(); 150 | brPw.println(); 151 | } 152 | } 153 | 154 | // Close the files 155 | flPw.close(); 156 | frPw.close(); 157 | if( blPw != null ) 158 | { 159 | blPw.close(); 160 | brPw.close(); 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/java/com/mammen/generator/Generator.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator; 2 | 3 | import com.mammen.path.Path; 4 | import com.mammen.path.Waypoint; 5 | 6 | import java.util.List; 7 | 8 | @FunctionalInterface 9 | public interface Generator 10 | { 11 | enum Type 12 | { 13 | PATHFINDER_V1( "Pathfinder Version 1" ); 14 | 15 | private String label; 16 | 17 | Type(String label ) 18 | { 19 | this.label = label; 20 | } 21 | 22 | @Override 23 | public String toString() 24 | { 25 | return label; 26 | } 27 | } 28 | 29 | class PathGenerationException extends Exception 30 | { 31 | PathGenerationException( String message ) 32 | { 33 | super( message ); 34 | } 35 | } 36 | 37 | class NotEnoughPointsException extends Exception 38 | { 39 | NotEnoughPointsException( String message ) 40 | { 41 | super( message ); 42 | } 43 | } 44 | 45 | Path generate( List waypointList ) throws PathGenerationException, NotEnoughPointsException; 46 | 47 | } -------------------------------------------------------------------------------- /src/java/com/mammen/generator/PfV1Generator.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator; 2 | 3 | import com.mammen.generator.generator_vars.SharedGeneratorVars; 4 | import com.mammen.generator.generator_vars.DriveBase; 5 | import com.mammen.generator.generator_vars.PfV1GeneratorVars; 6 | import com.mammen.path.Path; 7 | import com.mammen.path.Waypoint; 8 | import jaci.pathfinder.Pathfinder; 9 | import jaci.pathfinder.Trajectory; 10 | import jaci.pathfinder.modifiers.SwerveModifier; 11 | import jaci.pathfinder.modifiers.TankModifier; 12 | //import org.scijava.nativelib.NativeLoader; 13 | 14 | import java.util.List; 15 | 16 | public class PfV1Generator implements Generator 17 | { 18 | public PfV1Generator() 19 | { 20 | } 21 | 22 | public Path generate( List waypointList ) throws PathGenerationException, NotEnoughPointsException 23 | { 24 | PfV1GeneratorVars vars = PfV1GeneratorVars.getInstance(); 25 | SharedGeneratorVars sharedVars = SharedGeneratorVars.getInstance(); 26 | Trajectory source, fr, fl, br, bl; 27 | 28 | // We need at least 2 points to generate a trajectory. 29 | if( waypointList.size() > 1 ) 30 | { 31 | Trajectory.Config config = new Trajectory.Config( vars.getFitMethod().pfFitMethod(), Trajectory.Config.SAMPLES_HIGH, sharedVars.getTimeStep(), vars.getVelocity(), vars.getAccel(), vars.getJerk() ); 32 | 33 | try 34 | { 35 | source = Pathfinder.generate( wp2pf( waypointList ), config ); 36 | } 37 | catch( Exception e ) 38 | { 39 | throw new PathGenerationException( "Pathfinder V1 failed to generate the path." ); 40 | } 41 | 42 | if( sharedVars.getDriveBase() == DriveBase.SWERVE ) 43 | { 44 | SwerveModifier swerve = new SwerveModifier( source ); 45 | swerve.modify( sharedVars.getWheelBaseW(), sharedVars.getWheelBaseD(), SwerveModifier.Mode.SWERVE_DEFAULT ); 46 | 47 | fr = swerve.getFrontRightTrajectory(); 48 | fl = swerve.getFrontLeftTrajectory(); 49 | br = swerve.getBackRightTrajectory(); 50 | bl = swerve.getBackLeftTrajectory(); 51 | } 52 | else // DriveBase.Tank 53 | { 54 | TankModifier tank = new TankModifier( source ); 55 | tank.modify( sharedVars.getWheelBaseW() ); 56 | 57 | fr = tank.getRightTrajectory(); 58 | fl = tank.getLeftTrajectory(); 59 | br = null; 60 | bl = null; 61 | } 62 | 63 | return new Path( sharedVars.getDriveBase(), traj2Path( fl ), traj2Path( fr ), traj2Path( bl ), traj2Path( br ), traj2Path( source ) ); 64 | } 65 | 66 | throw new NotEnoughPointsException( "There are not enough points to generate a Path." ); 67 | } 68 | 69 | private static jaci.pathfinder.Waypoint[] wp2pf( List wpList ) 70 | { 71 | jaci.pathfinder.Waypoint[] wpArray = new jaci.pathfinder.Waypoint[ wpList.size() ]; 72 | 73 | for( int i = 0; i < wpList.size(); i++ ) 74 | { 75 | double x = wpList.get( i ).getX(); 76 | double y = wpList.get( i ).getY(); 77 | double angle = Pathfinder.d2r( wpList.get( i ).getAngle() ); 78 | 79 | wpArray[ i ] = new jaci.pathfinder.Waypoint( x, y, angle ); 80 | } 81 | 82 | return wpArray; 83 | } 84 | 85 | private static Path.Segment[] traj2Path(Trajectory traj ) 86 | { 87 | if( traj == null ) 88 | return null; 89 | 90 | Path.Segment[] segments = new Path.Segment[ traj.length() ]; 91 | 92 | for( int i = 0; i < traj.length(); i++ ) 93 | { 94 | segments[ i ] = new Path.Segment( 95 | traj.segments[ i ].dt, 96 | traj.segments[ i ].x, 97 | traj.segments[ i ].y, 98 | traj.segments[ i ].position, 99 | traj.segments[ i ].velocity, 100 | traj.segments[ i ].acceleration, 101 | traj.segments[ i ].jerk, 102 | traj.segments[ i ].heading 103 | ); 104 | } 105 | 106 | return segments; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/java/com/mammen/generator/generator_vars/DriveBase.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator.generator_vars; 2 | 3 | // Types of drive bases 4 | public enum DriveBase 5 | { 6 | TANK( "Tank" ), 7 | SWERVE( "Swerve" ); 8 | 9 | private String label; 10 | 11 | DriveBase( String label ) 12 | { 13 | this.label = label; 14 | } 15 | 16 | @Override 17 | public String toString() 18 | { 19 | return label; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/java/com/mammen/generator/generator_vars/GeneratorVars.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator.generator_vars; 2 | 3 | import org.w3c.dom.Element; 4 | 5 | public interface GeneratorVars 6 | { 7 | void writeXMLAttributes( Element element ); 8 | void readXMLAttributes( Element element ); 9 | void setDefaultValues(); 10 | void changeUnit( Units oldUnit, Units newUnit ); 11 | } 12 | -------------------------------------------------------------------------------- /src/java/com/mammen/generator/generator_vars/PfV1GeneratorVars.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator.generator_vars; 2 | 3 | import com.mammen.util.Mathf; 4 | import jaci.pathfinder.Trajectory; 5 | import javafx.beans.property.*; 6 | import org.w3c.dom.Element; 7 | 8 | public class PfV1GeneratorVars implements GeneratorVars 9 | { 10 | public enum FitMethod 11 | { 12 | HERMITE_CUBIC( "Cubic", Trajectory.FitMethod.HERMITE_CUBIC ), 13 | HERMITE_QUINTIC( "Quintic", Trajectory.FitMethod.HERMITE_QUINTIC ); 14 | 15 | private String label; 16 | private jaci.pathfinder.Trajectory.FitMethod pf_fitMethod; 17 | 18 | FitMethod( String label, Trajectory.FitMethod fitMethod ) 19 | { 20 | this.label = label; 21 | this.pf_fitMethod = fitMethod; 22 | } 23 | 24 | @Override 25 | public String toString() 26 | { 27 | return label; 28 | } 29 | 30 | public Trajectory.FitMethod pfFitMethod() 31 | { 32 | return pf_fitMethod; 33 | } 34 | } 35 | 36 | // Singleton Instance 37 | private static PfV1GeneratorVars vars = null; 38 | 39 | // Pathfinder V1 vars 40 | private DoubleProperty velocity = new SimpleDoubleProperty( 4.0 ); 41 | private DoubleProperty accel = new SimpleDoubleProperty( 3.0 ); 42 | private DoubleProperty jerk = new SimpleDoubleProperty( 5.0 ); 43 | private Property fitMethod = new SimpleObjectProperty<>( FitMethod.HERMITE_CUBIC ); 44 | private BooleanProperty isReversed = new SimpleBooleanProperty( false ); 45 | 46 | 47 | /************************************************************************** 48 | * Constructor 49 | *************************************************************************/ 50 | private PfV1GeneratorVars() 51 | { 52 | } 53 | 54 | /************************************************************************** 55 | *

Returns the PfV1GeneratorVars model.

56 | * 57 | * @return The one and only instance of the PfV1GeneratorVars model. 58 | *************************************************************************/ 59 | public static PfV1GeneratorVars getInstance() 60 | { 61 | if( vars == null ) 62 | { 63 | vars = new PfV1GeneratorVars(); 64 | } 65 | 66 | return vars; 67 | } 68 | 69 | @Override 70 | public void writeXMLAttributes( Element element ) 71 | { 72 | element.setAttribute("fitMethod", "" + fitMethod.getValue().name() ); 73 | element.setAttribute("velocity", "" + velocity.getValue() ); 74 | element.setAttribute("acceleration","" + accel.getValue() ); 75 | element.setAttribute("jerk", "" + jerk.getValue() ); 76 | element.setAttribute("reversed", "" + isReversed.getValue().toString() ); 77 | } 78 | 79 | @Override 80 | public void readXMLAttributes( Element element ) 81 | { 82 | fitMethod .setValue( FitMethod.valueOf( element.getAttribute("fitMethod" ) ) ); 83 | velocity .set( Double.parseDouble( element.getAttribute("velocity" ) ) ); 84 | accel .set( Double.parseDouble( element.getAttribute("acceleration" ) ) ); 85 | jerk .set( Double.parseDouble( element.getAttribute("jerk" ) ) ); 86 | isReversed .set( Boolean.parseBoolean( element.getAttribute("reversed" ) ) ); 87 | } 88 | 89 | /** 90 | * Resets configuration to default values for the given unit. 91 | */ 92 | @Override 93 | public void setDefaultValues() 94 | { 95 | fitMethod.setValue( FitMethod.HERMITE_CUBIC ); 96 | 97 | switch( SharedGeneratorVars.getInstance().getUnit() ) 98 | { 99 | case FEET: 100 | velocity.set( 4.0 ); 101 | accel.set( 3.0 ); 102 | jerk.set( 5.0 ); 103 | break; 104 | 105 | case METERS: 106 | accel.set( 0.9144 ); 107 | jerk.set( 18.288 ); 108 | break; 109 | 110 | case INCHES: 111 | velocity.set( 48 ); 112 | accel.set( 36 ); 113 | jerk .set( 720 ); 114 | break; 115 | } 116 | } 117 | 118 | @Override 119 | public void changeUnit( Units oldUnit, Units newUnit ) 120 | { 121 | // Convert each MP variable to the new unit 122 | double tmp_WBW = 0, tmp_WBD = 0, tmp_vel = 0, tmp_acc = 0, tmp_jer = 0; 123 | 124 | // convert to intermediate unit of feet 125 | switch( oldUnit ) 126 | { 127 | case FEET: 128 | tmp_vel = velocity.get(); 129 | tmp_acc = accel.get(); 130 | tmp_jer = jerk.get(); 131 | break; 132 | 133 | case INCHES: 134 | tmp_vel = Mathf.inchesToFeet( velocity.get() ); 135 | tmp_acc = Mathf.inchesToFeet( accel.get() ); 136 | tmp_jer = Mathf.inchesToFeet( jerk.get() ); 137 | break; 138 | 139 | case METERS: 140 | tmp_vel = Mathf.meterToFeet( velocity.get() ); 141 | tmp_acc = Mathf.meterToFeet( accel.get() ); 142 | tmp_jer = Mathf.meterToFeet( jerk.get() ); 143 | break; 144 | } 145 | 146 | // convert from intermediate unit of feet 147 | switch( newUnit ) 148 | { 149 | case FEET: 150 | velocity .set( tmp_vel ); 151 | accel .set( tmp_acc ); 152 | jerk .set( tmp_jer ); 153 | break; 154 | 155 | case INCHES: 156 | velocity .set( Mathf.round( Mathf.feetToInches( tmp_vel ),4 ) ); 157 | accel .set( Mathf.round( Mathf.feetToInches( tmp_acc ),4 ) ); 158 | jerk .set( Mathf.round( Mathf.feetToInches( tmp_jer ),4 ) ); 159 | 160 | break; 161 | 162 | case METERS: 163 | velocity .set( Mathf.round( Mathf.feetToMeter( tmp_vel ),4 ) ); 164 | accel .set( Mathf.round( Mathf.feetToMeter( tmp_acc ),4 ) ); 165 | jerk .set( Mathf.round( Mathf.feetToMeter( tmp_jer ),4 ) ); 166 | break; 167 | } 168 | } 169 | 170 | 171 | // Getters and Setters 172 | public double getVelocity() 173 | { 174 | return velocity.get(); 175 | } 176 | 177 | public DoubleProperty velocityProperty() 178 | { 179 | return velocity; 180 | } 181 | 182 | public void setVelocity( double velocity ) 183 | { 184 | this.velocity.set( velocity ); 185 | } 186 | 187 | public double getAccel() 188 | { 189 | return accel.get(); 190 | } 191 | 192 | public DoubleProperty accelProperty() 193 | { 194 | return accel; 195 | } 196 | 197 | public void setAccel( double accel ) 198 | { 199 | this.accel.set( accel ); 200 | } 201 | 202 | public double getJerk() 203 | { 204 | return jerk.get(); 205 | } 206 | 207 | public DoubleProperty jerkProperty() 208 | { 209 | return jerk; 210 | } 211 | 212 | public void setJerk( double jerk ) 213 | { 214 | this.jerk.set( jerk ); 215 | } 216 | 217 | public FitMethod getFitMethod() 218 | { 219 | return fitMethod.getValue(); 220 | } 221 | 222 | public Property fitMethodProperty() 223 | { 224 | return fitMethod; 225 | } 226 | 227 | public void setFitMethod( FitMethod fitMethod ) 228 | { 229 | this.fitMethod.setValue( fitMethod ); 230 | } 231 | 232 | public boolean isIsReversed() 233 | { 234 | return isReversed.get(); 235 | } 236 | 237 | public BooleanProperty isReversedProperty() 238 | { 239 | return isReversed; 240 | } 241 | 242 | public void setIsReversed( boolean isReversed ) 243 | { 244 | this.isReversed.set( isReversed ); 245 | } 246 | 247 | } -------------------------------------------------------------------------------- /src/java/com/mammen/generator/generator_vars/SharedGeneratorVars.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator.generator_vars; 2 | 3 | import com.mammen.util.Mathf; 4 | import javafx.beans.property.DoubleProperty; 5 | import javafx.beans.property.Property; 6 | import javafx.beans.property.SimpleDoubleProperty; 7 | import javafx.beans.property.SimpleObjectProperty; 8 | import org.w3c.dom.Element; 9 | 10 | public class SharedGeneratorVars implements GeneratorVars 11 | { 12 | private static SharedGeneratorVars sharedGeneratorVars = null; 13 | 14 | // Shared vars 15 | private DoubleProperty timeStep = new SimpleDoubleProperty( 0.05 ); 16 | private Property driveBase = new SimpleObjectProperty<>( DriveBase.TANK ); 17 | private Property unit = new SimpleObjectProperty<>( Units.FEET ); 18 | private DoubleProperty wheelBaseW = new SimpleDoubleProperty( 1.5 ); 19 | private DoubleProperty wheelBaseD = new SimpleDoubleProperty( 2.0 ); 20 | 21 | 22 | /************************************************************************** 23 | * Constructor 24 | *************************************************************************/ 25 | private SharedGeneratorVars() 26 | { 27 | unit.addListener( (o, oldValue, newValue) -> 28 | { 29 | changeUnit( oldValue, newValue ); 30 | }); 31 | } 32 | 33 | 34 | /************************************************************************** 35 | *

Returns the SharedGeneratorVars model.

36 | * 37 | * @return The one and only instance of the SharedGeneratorVars model. 38 | *************************************************************************/ 39 | public static SharedGeneratorVars getInstance() 40 | { 41 | if( sharedGeneratorVars == null ) 42 | { 43 | sharedGeneratorVars = new SharedGeneratorVars(); 44 | } 45 | 46 | return sharedGeneratorVars; 47 | } 48 | 49 | // getters and setters 50 | public double getTimeStep() 51 | { 52 | return timeStep.get(); 53 | } 54 | 55 | public DoubleProperty timeStepProperty() 56 | { 57 | return timeStep; 58 | } 59 | 60 | public void setTimeStep( double timeStep ) 61 | { 62 | this.timeStep.set( timeStep ); 63 | } 64 | 65 | public DriveBase getDriveBase() 66 | { 67 | return driveBase.getValue(); 68 | } 69 | 70 | public Property driveBaseProperty() 71 | { 72 | return driveBase; 73 | } 74 | 75 | public void setDriveBase( DriveBase driveBase ) 76 | { 77 | this.driveBase.setValue( driveBase ); 78 | } 79 | 80 | public Units getUnit() 81 | { 82 | return unit.getValue(); 83 | } 84 | 85 | public Property unitProperty() 86 | { 87 | return unit; 88 | } 89 | 90 | public void setUnit( Units unit ) 91 | { 92 | this.unit.setValue( unit ); 93 | } 94 | 95 | public double getWheelBaseW() 96 | { 97 | return wheelBaseW.get(); 98 | } 99 | 100 | public DoubleProperty wheelBaseWProperty() 101 | { 102 | return wheelBaseW; 103 | } 104 | 105 | public void setWheelBaseW( double wheelBaseW ) 106 | { 107 | this.wheelBaseW.set( wheelBaseW ); 108 | } 109 | 110 | public double getWheelBaseD() 111 | { 112 | return wheelBaseD.get(); 113 | } 114 | 115 | public DoubleProperty wheelBaseDProperty() 116 | { 117 | return wheelBaseD; 118 | } 119 | 120 | public void setWheelBaseD( double wheelBaseD ) 121 | { 122 | this.wheelBaseD.set( wheelBaseD ); 123 | } 124 | 125 | @Override 126 | public void writeXMLAttributes( Element element ) 127 | { 128 | element.setAttribute("unit", "" + unit.getValue().name() ); 129 | element.setAttribute("driveBase", "" + driveBase.getValue().name() ); 130 | element.setAttribute("dt", "" + timeStep.getValue() ); 131 | element.setAttribute("wheelBaseW", "" + wheelBaseW.getValue() ); 132 | element.setAttribute("wheelBaseD", "" + wheelBaseD.getValue() ); 133 | } 134 | 135 | @Override 136 | public void readXMLAttributes( Element element ) 137 | { 138 | unit .setValue( Units .valueOf( element.getAttribute("unit" ) ) ); 139 | driveBase .setValue( DriveBase.valueOf( element.getAttribute("driveBase" ) ) ); 140 | timeStep .set( Double.parseDouble( element.getAttribute("dt" ) ) ); 141 | wheelBaseW .set( Double.parseDouble( element.getAttribute("wheelBaseW" ) ) ); 142 | wheelBaseD .set( Double.parseDouble( element.getAttribute("wheelBaseD" ) ) ); 143 | } 144 | 145 | @Override 146 | public void setDefaultValues() 147 | { 148 | driveBase.setValue( DriveBase.TANK ); 149 | 150 | switch( unit.getValue() ) 151 | { 152 | case FEET: 153 | timeStep.set( 0.05 ); 154 | wheelBaseW.set( 1.5 ); 155 | wheelBaseD.set( 2.0 ); 156 | break; 157 | 158 | case METERS: 159 | timeStep.set( 0.05 ); 160 | wheelBaseW.set( 0.4462272 ); 161 | wheelBaseD.set( 0.4462272 ); 162 | break; 163 | 164 | case INCHES: 165 | timeStep.set( 0.05 ); 166 | wheelBaseW.set( 17.568 ); 167 | wheelBaseD.set( 17.568 ); 168 | break; 169 | } 170 | } 171 | 172 | @Override 173 | public void changeUnit( Units oldUnit, Units newUnit ) 174 | { 175 | // Convert each MP variable to the new unit 176 | double tmp_WBW = 0, tmp_WBD = 0, tmp_vel = 0, tmp_acc = 0, tmp_jer = 0; 177 | 178 | // convert to intermediate unit of feet 179 | switch( oldUnit ) 180 | { 181 | case FEET: 182 | tmp_WBW = wheelBaseW.get(); 183 | tmp_WBD = wheelBaseD.get(); 184 | break; 185 | 186 | case INCHES: 187 | tmp_WBW = Mathf.inchesToFeet( wheelBaseW.get() ); 188 | tmp_WBD = Mathf.inchesToFeet( wheelBaseD.get() ); 189 | break; 190 | 191 | case METERS: 192 | tmp_WBW = Mathf.meterToFeet( wheelBaseW.get() ); 193 | tmp_WBD = Mathf.meterToFeet( wheelBaseD.get() ); 194 | break; 195 | } 196 | 197 | // convert from intermediate unit of feet 198 | switch( newUnit ) 199 | { 200 | case FEET: 201 | wheelBaseW .set( tmp_WBW ); 202 | wheelBaseD .set( tmp_WBD ); 203 | break; 204 | 205 | case INCHES: 206 | wheelBaseW .set( Mathf.round( Mathf.feetToInches( tmp_WBW ),4 ) ); 207 | wheelBaseD .set( Mathf.round( Mathf.feetToInches( tmp_WBD ),4 ) ); 208 | 209 | break; 210 | 211 | case METERS: 212 | wheelBaseW .set( Mathf.round( Mathf.feetToMeter( tmp_WBW ),4 ) ); 213 | wheelBaseD .set( Mathf.round( Mathf.feetToMeter( tmp_WBD ),4 ) ); 214 | break; 215 | } 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/java/com/mammen/generator/generator_vars/Units.java: -------------------------------------------------------------------------------- 1 | package com.mammen.generator.generator_vars; 2 | 3 | // Units of every value 4 | public enum Units 5 | { 6 | FEET( "Feet" ), 7 | INCHES( "Inches" ), 8 | METERS( "Meter" ); 9 | 10 | private String label; 11 | 12 | Units( String label ) 13 | { 14 | this.label = label; 15 | } 16 | 17 | @Override 18 | public String toString() 19 | { 20 | return label; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/java/com/mammen/main/Main.java: -------------------------------------------------------------------------------- 1 | package com.mammen.main; 2 | 3 | public class Main 4 | { 5 | public static void main( String[] args ) 6 | { 7 | MainApp.main( args ); 8 | 9 | /* 10 | An explanation for why main() is called like this can be found here: 11 | https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle/52571719#52571719 12 | */ 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/java/com/mammen/main/MainApp.java: -------------------------------------------------------------------------------- 1 | package com.mammen.main; 2 | 3 | import javafx.application.Application; 4 | import javafx.fxml.FXMLLoader; 5 | import javafx.scene.Scene; 6 | import javafx.scene.layout.Pane; 7 | import javafx.stage.Stage; 8 | 9 | public class MainApp extends Application 10 | { 11 | @Override 12 | public void start( Stage primaryStage ) 13 | { 14 | try 15 | { 16 | Pane root = FXMLLoader.load( getClass().getResource("/com/mammen/ui/javafx/main/MainUI.fxml") ); 17 | root.autosize(); 18 | 19 | primaryStage.setScene( new Scene( root ) ); 20 | primaryStage.sizeToScene(); 21 | primaryStage.setTitle("Motion Profile Generator"); 22 | primaryStage.setMinWidth( 1280 ); //1170 23 | primaryStage.setMinHeight( 720 ); //790 24 | primaryStage.setResizable( true ); 25 | 26 | primaryStage.show(); 27 | } 28 | catch( Exception e ) 29 | { 30 | e.printStackTrace(); 31 | } 32 | } 33 | 34 | public static void main(String[] args) 35 | { 36 | // JavaFX 11+ uses GTK3 by default, and has problems on some display servers 37 | // This flag forces JavaFX to use GTK2 38 | System.setProperty( "jdk.gtk.version", "2" ); 39 | 40 | launch( args ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/java/com/mammen/main/MainUIModel.java: -------------------------------------------------------------------------------- 1 | package com.mammen.main; 2 | 3 | import com.mammen.file_io.FileIO; 4 | import com.mammen.generator.*; 5 | import com.mammen.generator.generator_vars.Units; 6 | import com.mammen.path.Path; 7 | import com.mammen.path.Waypoint; 8 | import com.mammen.settings.SettingsModel; 9 | import com.mammen.util.Mathf; 10 | 11 | import javafx.beans.Observable; 12 | import javafx.beans.property.*; 13 | import javafx.collections.FXCollections; 14 | 15 | import org.w3c.dom.Document; 16 | import org.w3c.dom.Element; 17 | import org.w3c.dom.NodeList; 18 | import org.w3c.dom.Text; 19 | import org.w3c.dom.ls.DOMImplementationLS; 20 | import org.w3c.dom.ls.LSOutput; 21 | import org.w3c.dom.ls.LSSerializer; 22 | import org.w3c.dom.bootstrap.DOMImplementationRegistry; 23 | 24 | import org.xml.sax.SAXException; 25 | 26 | import javax.xml.parsers.DocumentBuilder; 27 | import javax.xml.parsers.DocumentBuilderFactory; 28 | import javax.xml.parsers.ParserConfigurationException; 29 | 30 | import java.io.*; 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | 34 | 35 | /****************************************************************************** 36 | * MainUIModel 37 | * This is the model for the program. It contains all the data needed to 38 | * generate a path as well as the path itself. We use the JavaBeans model 39 | * of properties. The trajectories are setup so that 40 | * they are recalculated whenever any of their dependencies changes value. 41 | * These dependencies (velocity, accel, jerk, ect. ) are bound to gui 42 | * elements in their respective fxml controllers. 43 | ******************************************************************************/ 44 | public class MainUIModel 45 | { 46 | private static final String PROJECT_EXTENSION = "xml"; 47 | 48 | /****************************************************** 49 | * Waypoints 50 | ******************************************************/ 51 | private ListProperty waypointList = new SimpleListProperty<>( 52 | FXCollections.observableArrayList( 53 | p -> new Observable[]{ p.xProperty(), p.yProperty(), p.angleProperty() } ) ); 54 | 55 | /****************************************************** 56 | * Generated path. 57 | ******************************************************/ 58 | private Property path = new SimpleObjectProperty<>(); 59 | 60 | // File stuff 61 | private DocumentBuilderFactory dbFactory; 62 | private File workingProject; 63 | 64 | /****************************************************** 65 | * Program settings. 66 | ******************************************************/ 67 | private SettingsModel settings; 68 | 69 | /****************************************************** 70 | * The one and only instance of this class. 71 | ******************************************************/ 72 | private static MainUIModel backend = null; 73 | 74 | /************************************************************************** 75 | * Constructor 76 | *************************************************************************/ 77 | private MainUIModel() 78 | { 79 | settings = SettingsModel.getInstance(); 80 | 81 | dbFactory = DocumentBuilderFactory.newInstance(); 82 | 83 | settings.getSharedGeneratorVars().unitProperty().addListener( (o, oldValue, newValue) -> 84 | updateVarUnits( oldValue, newValue ) 85 | ); 86 | 87 | } /* MainUIModel() */ 88 | 89 | 90 | /************************************************************************** 91 | *

Returns the backend model.

92 | * 93 | * @return The one and only instance of the backend model. 94 | *************************************************************************/ 95 | public static MainUIModel getInstance() 96 | { 97 | if( backend == null ) 98 | { 99 | backend = new MainUIModel(); 100 | } 101 | 102 | return backend; 103 | } 104 | 105 | 106 | /************************************************************************** 107 | *

Generates a Path that fits the given waypoints.

108 | * 109 | * @throws com.mammen.generator.Generator.PathGenerationException 110 | * The path failed to generate. 111 | * @throws com.mammen.generator.Generator.NotEnoughPointsException 112 | * There were not enough points to generate a path. 113 | *************************************************************************/ 114 | public void generatePath() throws Generator.PathGenerationException, Generator.NotEnoughPointsException 115 | { 116 | Path newPath = settings.getGenerator().generate( waypointList ); 117 | 118 | if( newPath != null ) 119 | { 120 | path.setValue( newPath ); 121 | } 122 | } /* generatePath() */ 123 | 124 | 125 | /************************************************************************** 126 | * updateVarUnits 127 | * Converts the waypoints list from one Unit to another. 128 | * 129 | * @param old_unit The current Unit. 130 | * @param new_unit The Unit to convert to. 131 | **************************************************************************/ 132 | private void updateVarUnits( Units old_unit, Units new_unit ) 133 | { 134 | // TODO: Find a better way of doing this!!! 135 | // Maybe storing the values in the backend in feet 136 | // and only convert it for display. 137 | 138 | List tmpList = new ArrayList<>(); 139 | 140 | // Convert each point in the waypoints list 141 | for( Waypoint wp : waypointList ) 142 | { 143 | double tmp_x = 0, tmp_y = 0; 144 | 145 | // convert to intermediate unit of feet 146 | switch( old_unit ) 147 | { 148 | case FEET: 149 | tmp_x = wp.getX(); 150 | tmp_y = wp.getY(); 151 | break; 152 | 153 | case INCHES: 154 | tmp_x = Mathf.inchesToFeet( wp.getX() ); 155 | tmp_y = Mathf.inchesToFeet( wp.getY() ); 156 | break; 157 | 158 | case METERS: 159 | tmp_x = Mathf.meterToFeet( wp.getX() ); 160 | tmp_y = Mathf.meterToFeet( wp.getY() ); 161 | break; 162 | } 163 | 164 | // convert from intermediate unit of feet 165 | switch( new_unit ) 166 | { 167 | case FEET: 168 | tmpList.add( new Waypoint( tmp_x, tmp_y, wp.getAngle() ) ); 169 | break; 170 | 171 | case INCHES: 172 | tmpList.add( new Waypoint( Mathf.feetToInches( tmp_x ), 173 | Mathf.feetToInches( tmp_y ), 174 | wp.getAngle() ) ); 175 | 176 | break; 177 | 178 | case METERS: 179 | tmpList.add( new Waypoint( Mathf.feetToMeter( tmp_x ), 180 | Mathf.feetToMeter( tmp_y ), 181 | wp.getAngle() ) ); 182 | break; 183 | } 184 | } 185 | 186 | waypointList.clear(); 187 | waypointList.addAll( tmpList ); 188 | 189 | } /* updateVarUnits() */ 190 | 191 | 192 | /************************************************************************** 193 | *

Exports the Path to the parent folder, with the given root 194 | * name and file extension.

195 | * 196 | * @param parentPath The .csv file to save to. This method will write to 197 | * multiple files depending on the drivebase of the Path. 198 | * Each filename will be an appended version of the .csv 199 | * that parentPath references. 200 | *************************************************************************/ 201 | public void exportPath( File parentPath ) throws FileNotFoundException 202 | { 203 | FileIO.savePath( path.getValue(), parentPath, settings.getChosenCSVElements() ); 204 | } /* exportPath() */ 205 | 206 | 207 | /** 208 | * Saves the project in XML format. 209 | */ 210 | public void saveProjectAs( File path ) throws ParserConfigurationException 211 | { 212 | if( !path.getAbsolutePath().endsWith("." + PROJECT_EXTENSION ) ) 213 | path = new File(path + "." + PROJECT_EXTENSION ); 214 | 215 | File dir = path.getParentFile(); 216 | 217 | if( dir != null && !dir.exists() && dir.isDirectory() ) 218 | { 219 | if (!dir.mkdirs()) 220 | return; 221 | } 222 | 223 | if( path.exists() && !path.delete() ) 224 | return; 225 | 226 | workingProject = path; 227 | 228 | saveWorkingProject(); 229 | } 230 | 231 | /** 232 | * Saves the working project. 233 | */ 234 | public void saveWorkingProject() throws ParserConfigurationException 235 | { 236 | if( workingProject != null ) 237 | { 238 | // Create document 239 | DocumentBuilder db = dbFactory.newDocumentBuilder(); 240 | Document dom = db.newDocument(); 241 | 242 | // XML entry for the path waypoints and vars 243 | Element pathElement = dom.createElement("Path" ); 244 | 245 | // Save generator type 246 | pathElement.setAttribute( "GeneratorType", settings.getGeneratorType().name() ); 247 | 248 | // Save shared vars 249 | settings.getSharedGeneratorVars().writeXMLAttributes( pathElement ); 250 | 251 | // Write generator vars to xml file 252 | settings.getGeneratorVars().writeXMLAttributes( pathElement ); 253 | dom.appendChild( pathElement ); 254 | 255 | // Write waypoints to xml file 256 | for( Waypoint wp : waypointList ) 257 | { 258 | Element waypointEle = dom.createElement("Waypoint" ); 259 | Element xEle = dom.createElement("X" ); 260 | Element yEle = dom.createElement("Y" ); 261 | Element angleEle = dom.createElement("Angle" ); 262 | Text xText = dom.createTextNode("" + wp.getX() ); 263 | Text yText = dom.createTextNode("" + wp.getY() ); 264 | Text angleText = dom.createTextNode("" + wp.getAngle() ); 265 | 266 | xEle.appendChild( xText ); 267 | yEle.appendChild( yText ); 268 | angleEle.appendChild( angleText ); 269 | 270 | waypointEle.appendChild( xEle ); 271 | waypointEle.appendChild( yEle ); 272 | waypointEle.appendChild( angleEle ); 273 | 274 | pathElement.appendChild( waypointEle ); 275 | } 276 | 277 | FileOutputStream fos; 278 | try 279 | { 280 | fos = new FileOutputStream( workingProject ); 281 | DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance(); 282 | DOMImplementationLS impl = (DOMImplementationLS) reg.getDOMImplementation("LS" ); 283 | LSSerializer serializer = impl.createLSSerializer(); 284 | 285 | serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE ); 286 | 287 | LSOutput lso = impl.createLSOutput(); 288 | lso.setByteStream( fos ); 289 | serializer.write( dom, lso ); 290 | 291 | } 292 | catch( Exception e ) 293 | { 294 | throw new RuntimeException( e ); 295 | } 296 | } 297 | } 298 | 299 | /** 300 | * Loads a project from file. 301 | */ 302 | public void loadProject( File path ) throws IOException, ParserConfigurationException, SAXException 303 | { 304 | if( !path.exists() || path.isDirectory() ) 305 | return; 306 | 307 | if( path.getAbsolutePath().toLowerCase().endsWith( "." + PROJECT_EXTENSION ) ) 308 | { 309 | DocumentBuilder db = dbFactory.newDocumentBuilder(); 310 | Document dom = db.parse( path ); 311 | 312 | Element docEle = dom.getDocumentElement(); 313 | 314 | // Get generator type 315 | settings.setGeneratorType( Generator.Type.valueOf( docEle.getAttribute( "GeneratorType" ) )); 316 | 317 | // Get shared vars from xml file 318 | settings.getSharedGeneratorVars().readXMLAttributes( docEle ); 319 | 320 | // TODO: Does the settings.generatorType change listener get called before the next line? 321 | // If not, the settings.generatorVars variable will potentially be the wrong one. 322 | // I suspect that it does. 323 | 324 | // Get generator vars from xml file. 325 | settings.getGeneratorVars().readXMLAttributes( docEle ); 326 | 327 | // Get waypoints from xml file. 328 | NodeList waypointEleList = docEle.getElementsByTagName( "Waypoint" ); 329 | 330 | waypointList.clear(); 331 | if( waypointEleList != null && waypointEleList.getLength() > 0 ) 332 | { 333 | for( int i = 0; i < waypointEleList.getLength(); i++ ) 334 | { 335 | Element waypointEle = (Element) waypointEleList.item( i ); 336 | 337 | String xText = waypointEle.getElementsByTagName("X").item(0).getTextContent(); 338 | String yText = waypointEle.getElementsByTagName("Y").item(0).getTextContent(); 339 | String angleText = waypointEle.getElementsByTagName("Angle").item(0).getTextContent(); 340 | 341 | waypointList.add( new Waypoint( 342 | Double.parseDouble( xText ), 343 | Double.parseDouble( yText ), 344 | Double.parseDouble( angleText ) 345 | ) ); 346 | } 347 | } 348 | 349 | workingProject = path; 350 | } 351 | } 352 | 353 | /** 354 | * Clears the working project files 355 | */ 356 | public void clearWorkingFiles() 357 | { 358 | workingProject = null; 359 | } 360 | 361 | /** 362 | * Adds a waypoint to the list of waypoints 363 | */ 364 | public void addPoint( double x, double y, double angle ) 365 | { 366 | waypointList.add( new Waypoint( x, y, angle ) ); 367 | } 368 | 369 | /** 370 | * Adds a waypoint to the list of waypoints 371 | */ 372 | public void addPoint( Waypoint wp ) 373 | { 374 | waypointList.add( wp ); 375 | } 376 | 377 | private void removePoint( int index ) 378 | { 379 | waypointList.remove( index ); 380 | } 381 | 382 | public void removeLastPoint() 383 | { 384 | removePoint( waypointList.get().size() - 1 ); 385 | } 386 | 387 | public void removePoints( int first, int last ) 388 | { 389 | waypointList.remove( first, last + 1 ); 390 | } 391 | 392 | public int getNumWaypoints() 393 | { 394 | return waypointList.size(); 395 | } 396 | 397 | public Waypoint getWaypoint(int index ) 398 | { 399 | return waypointList.get( index ); 400 | } 401 | 402 | /** 403 | * Clears all the existing waypoints in the list. 404 | * This also clears all trajectories generated by the waypoints. 405 | */ 406 | public void clearPoints() 407 | { 408 | waypointList.clear(); 409 | path.setValue( null ); 410 | } 411 | 412 | public ListProperty waypointListProperty() 413 | { 414 | return waypointList; 415 | } 416 | 417 | public List getWaypointList() 418 | { 419 | return waypointList; 420 | } 421 | 422 | public boolean isWaypointListEmpty() 423 | { 424 | return waypointList.isEmpty(); 425 | } 426 | 427 | public Path getPath() 428 | { 429 | return path.getValue(); 430 | } 431 | 432 | public Property pathProperty() 433 | { 434 | return path; 435 | } 436 | } 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | -------------------------------------------------------------------------------- /src/java/com/mammen/path/Path.java: -------------------------------------------------------------------------------- 1 | package com.mammen.path; 2 | 3 | import com.mammen.generator.generator_vars.DriveBase; 4 | 5 | public class Path 6 | { 7 | /** 8 | * Reresents Each var in a Segment 9 | */ 10 | public enum Elements 11 | { 12 | DELTA_TIME( "Delta Time" ), 13 | X_POINT( "X Point" ), 14 | Y_POINT( "Y Point" ), 15 | POSITION( "Position" ), 16 | VELOCITY( "Velocity" ), 17 | ACCELERATION( "Acceleration" ), 18 | JERK( "Jerk" ), 19 | HEADING( "Heading" ); 20 | 21 | private String label; 22 | 23 | Elements( String label ) 24 | { 25 | this.label = label; 26 | } 27 | 28 | @Override 29 | public String toString() 30 | { 31 | return label; 32 | } 33 | 34 | } 35 | 36 | public static class Segment 37 | { 38 | public double dt; 39 | public double x; 40 | public double y; 41 | public double position; 42 | public double velocity; 43 | public double acceleration; 44 | public double jerk; 45 | public double heading; 46 | 47 | public Segment( double dt, double x, double y, double position, double velocity, double acceleration, double jerk, double heading ) 48 | { 49 | this.dt = dt; 50 | this.x = x; 51 | this.y = y; 52 | this.position = position; 53 | this.velocity = velocity; 54 | this.acceleration = acceleration; 55 | this.jerk = jerk; 56 | this.heading = heading; 57 | } 58 | } 59 | 60 | // Generated paths 61 | private Segment[] center; 62 | private Segment[] frontLeft; 63 | private Segment[] frontRight; 64 | private Segment[] backLeft; 65 | private Segment[] backRight; 66 | 67 | private DriveBase driveBase; 68 | 69 | public Path( DriveBase driveBase, Segment[] left, Segment[] right ) 70 | { 71 | this.driveBase = driveBase; 72 | this.frontLeft = left; 73 | this.frontRight = right; 74 | } 75 | 76 | public Path( DriveBase driveBase, Segment[] frontLeft, Segment[] frontRight, Segment[] backLeft, Segment[] backRight ) 77 | { 78 | this( driveBase, frontLeft, frontRight ); 79 | 80 | this.backLeft = backLeft; 81 | this.backRight = backRight; 82 | } 83 | 84 | public Path( DriveBase driveBase, Segment[] frontLeft, Segment[] frontRight, Segment[] backLeft, Segment[] backRight, Segment[] center ) 85 | { 86 | this( driveBase, frontLeft, frontRight, backLeft, backRight ); 87 | this.center = center; 88 | } 89 | 90 | // Getters and Setters 91 | public DriveBase getDriveBase() 92 | { 93 | return driveBase; 94 | } 95 | 96 | public Segment[] getCenter() 97 | { 98 | return center; 99 | } 100 | 101 | public Segment[] getFrontLeft() 102 | { 103 | return frontLeft; 104 | } 105 | 106 | public Segment[] getFrontRight() 107 | { 108 | return frontRight; 109 | } 110 | 111 | public Segment[] getBackLeft() 112 | { 113 | return backLeft; 114 | } 115 | 116 | public Segment[] getBackRight() 117 | { 118 | return backRight; 119 | } 120 | 121 | public int getLength() 122 | { 123 | return center.length; 124 | } 125 | 126 | public Segment getCenterSegment( int i ) 127 | { 128 | return center[ i ]; 129 | } 130 | 131 | public Segment getFrontLeftSegment( int i ) 132 | { 133 | return frontLeft[ i ]; 134 | } 135 | 136 | public Segment getFrontRightSegment( int i ) 137 | { 138 | return frontRight[ i ]; 139 | } 140 | 141 | public Segment getBackLeftSegment( int i ) 142 | { 143 | return backLeft[ i ]; 144 | } 145 | 146 | public Segment getBackRightSegment( int i ) 147 | { 148 | return backRight[ i ]; 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/java/com/mammen/path/Waypoint.java: -------------------------------------------------------------------------------- 1 | package com.mammen.path; 2 | 3 | import javafx.beans.property.DoubleProperty; 4 | import javafx.beans.property.SimpleDoubleProperty; 5 | 6 | public class Waypoint 7 | { 8 | private DoubleProperty x; 9 | private DoubleProperty y; 10 | private DoubleProperty angle; 11 | 12 | public Waypoint(double x, double y, double angle ) 13 | { 14 | this.x = new SimpleDoubleProperty( x ); 15 | this.y = new SimpleDoubleProperty( y ); 16 | this.angle = new SimpleDoubleProperty( angle ); 17 | } 18 | 19 | public double getX() 20 | { 21 | return x.get(); 22 | } 23 | 24 | public void setX( double x ) 25 | { 26 | this.x.set( x ); 27 | } 28 | 29 | public DoubleProperty xProperty() 30 | { 31 | return x; 32 | } 33 | 34 | public double getY() 35 | { 36 | return y.get(); 37 | } 38 | 39 | public void setY( double y ) 40 | { 41 | this.y.set( y ); 42 | } 43 | 44 | public DoubleProperty yProperty() 45 | { 46 | return y; 47 | } 48 | 49 | public double getAngle() 50 | { 51 | return angle.get(); 52 | } 53 | 54 | public void setAngle( double angle ) 55 | { 56 | this.angle.set( angle ); 57 | } 58 | 59 | public DoubleProperty angleProperty() 60 | { 61 | return angle; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/java/com/mammen/settings/SettingsModel.java: -------------------------------------------------------------------------------- 1 | package com.mammen.settings; 2 | 3 | import com.mammen.generator.Generator; 4 | import com.mammen.generator.PfV1Generator; 5 | import com.mammen.generator.generator_vars.GeneratorVars; 6 | import com.mammen.generator.generator_vars.PfV1GeneratorVars; 7 | import com.mammen.generator.generator_vars.SharedGeneratorVars; 8 | import com.mammen.path.Path; 9 | import com.mammen.util.SerializeHelpers.ObjectSerializer; 10 | import com.mammen.util.SerializeHelpers.ReadObjectsHelper; 11 | import com.mammen.util.SerializeHelpers.WriteObjectsHelper; 12 | import javafx.beans.property.*; 13 | import javafx.collections.FXCollections; 14 | import javafx.collections.ObservableList; 15 | 16 | import java.io.*; 17 | 18 | public class SettingsModel implements Serializable 19 | { 20 | /****************************************************** 21 | * File stuff 22 | ******************************************************/ 23 | private static final String FILE_NAME = "settings.set"; 24 | private static final String DIR_NAME = ".motion-profile-generator"; 25 | private static final String SETTINGS_DIR = System.getProperty("user.home") + File.separator + DIR_NAME; 26 | private static final String SETTINGS_FILE_PATH = SETTINGS_DIR + File.separator + FILE_NAME; 27 | private Boolean settingsDirExist; 28 | 29 | 30 | /****************************************************** 31 | * The one and only instance of this class. 32 | ******************************************************/ 33 | private static SettingsModel settings = null; 34 | 35 | 36 | /****************************************************** 37 | * Settings 38 | ******************************************************/ 39 | private transient StringProperty graphBGImagePath; 40 | private transient BooleanProperty addPointOnClick; 41 | private transient Property sourcePathDisplayType; 42 | private transient ListProperty chosenCSVElements; 43 | private transient ListProperty availableCSVElements; 44 | private transient StringProperty workingDirectory; 45 | private transient Property generatorType; 46 | private transient Property generatorVars; 47 | private transient Property generator; 48 | 49 | 50 | /****************************************************** 51 | * Instance of each generator and vars type. 52 | ******************************************************/ 53 | private transient SharedGeneratorVars sharedVars; 54 | private transient PfV1GeneratorVars pfV1Vars; 55 | private transient PfV1Generator pfV1Generator; 56 | 57 | 58 | /****************************************************** 59 | * Constructors 60 | ******************************************************/ 61 | // Prevent instantiation of this class 62 | private SettingsModel() 63 | { 64 | // Create settings dir if it does not exist yet 65 | File settingsDir = new File( SettingsModel.getSettingsDir() ); 66 | if( !settingsDir.exists() ) 67 | { 68 | settingsDirExist = settingsDir.mkdirs(); 69 | } 70 | else 71 | { 72 | settingsDirExist = true; 73 | } 74 | 75 | initialize(); 76 | 77 | chosenCSVElements.add( Path.Elements.DELTA_TIME ); 78 | chosenCSVElements.add( Path.Elements.POSITION ); 79 | chosenCSVElements.add( Path.Elements.VELOCITY ); 80 | 81 | availableCSVElements.add( Path.Elements.X_POINT ); 82 | availableCSVElements.add( Path.Elements.Y_POINT ); 83 | availableCSVElements.add( Path.Elements.ACCELERATION ); 84 | availableCSVElements.add( Path.Elements.JERK ); 85 | availableCSVElements.add( Path.Elements.HEADING ); 86 | 87 | // Update model references when the uses selects a new generator 88 | generatorType.addListener( (O, oldValue, newValue) -> 89 | { 90 | switch( newValue ) 91 | { 92 | case PATHFINDER_V1: 93 | generatorVars.setValue( pfV1Vars ); 94 | generator.setValue( pfV1Generator ); 95 | break; 96 | 97 | default: 98 | throw new RuntimeException( "The programmer forgot to add a case for the following generator: " + newValue ); 99 | } 100 | }); 101 | } 102 | 103 | private void initialize() 104 | { 105 | sharedVars = SharedGeneratorVars.getInstance(); 106 | pfV1Vars = PfV1GeneratorVars.getInstance(); 107 | pfV1Generator = new PfV1Generator(); 108 | 109 | graphBGImagePath = new SimpleStringProperty(); 110 | addPointOnClick = new SimpleBooleanProperty( true ); 111 | sourcePathDisplayType = new SimpleObjectProperty<>( SourcePathDisplayType.WP_ONLY ); 112 | chosenCSVElements = new SimpleListProperty<>( FXCollections.observableArrayList() ); 113 | availableCSVElements = new SimpleListProperty<>( FXCollections.observableArrayList() ); 114 | workingDirectory = new SimpleStringProperty( System.getProperty( "user.dir" ) ); 115 | generatorType = new SimpleObjectProperty<>( Generator.Type.PATHFINDER_V1 ); 116 | generatorVars = new SimpleObjectProperty<>( pfV1Vars ); 117 | generator = new SimpleObjectProperty<>( pfV1Generator ); 118 | } 119 | 120 | 121 | /************************************************************************** 122 | * getInstance 123 | * Use this method to retrieve the settings for this program. 124 | * @return If the settings file is found it will return previous settings. 125 | * If not then default settings will be returned. 126 | *************************************************************************/ 127 | public static SettingsModel getInstance() 128 | { 129 | if( settings == null ) 130 | { 131 | settings = (SettingsModel)ObjectSerializer.loadObject( SETTINGS_FILE_PATH ); 132 | 133 | if( settings == null ) 134 | { 135 | settings = new SettingsModel(); 136 | } 137 | } 138 | 139 | return settings; 140 | } 141 | 142 | 143 | /************************************************************************** 144 | * saveSettings 145 | * Save the settings to a file. 146 | *************************************************************************/ 147 | public void saveSettings() throws IOException 148 | { 149 | if( settingsDirExist ) 150 | ObjectSerializer.saveObject( this, SETTINGS_FILE_PATH ); 151 | } 152 | 153 | 154 | /************************************************************************** 155 | * getSettingsDir 156 | * Get the path to the settings directory 157 | * @return The path to the settings directory. 158 | *************************************************************************/ 159 | public static String getSettingsDir() 160 | { 161 | return SETTINGS_DIR; 162 | } 163 | 164 | 165 | /****************************************************** 166 | * Getters and Setters 167 | ******************************************************/ 168 | public String getGraphBGImagePath() 169 | { 170 | return graphBGImagePath.get(); 171 | } 172 | 173 | public StringProperty graphBGImagePathProperty() 174 | { 175 | return graphBGImagePath; 176 | } 177 | 178 | public void setGraphBGImagePath(String graphBGImagePath) 179 | { 180 | this.graphBGImagePath.set(graphBGImagePath); 181 | } 182 | 183 | public boolean isAddPointOnClick() 184 | { 185 | return addPointOnClick.get(); 186 | } 187 | 188 | public BooleanProperty addPointOnClickProperty() 189 | { 190 | return addPointOnClick; 191 | } 192 | 193 | public void setAddPointOnClick( boolean addPointOnClick ) 194 | { 195 | this.addPointOnClick.set( addPointOnClick ); 196 | 197 | } 198 | 199 | public SourcePathDisplayType getSourcePathDisplayType() 200 | { 201 | return sourcePathDisplayType.getValue(); 202 | } 203 | 204 | public Property sourcePathDisplayTypeProperty() 205 | { 206 | return sourcePathDisplayType; 207 | } 208 | 209 | public void setSourcePathDisplayType( SourcePathDisplayType sourcePathDisplayType ) 210 | { 211 | this.sourcePathDisplayType.setValue( sourcePathDisplayType ); 212 | } 213 | 214 | public ObservableList getChosenCSVElements() 215 | { 216 | return chosenCSVElements.get(); 217 | } 218 | 219 | public ListProperty chosenCSVElementsProperty() 220 | { 221 | return chosenCSVElements; 222 | } 223 | 224 | public void setChosenCSVElements( ObservableList chosenCSVElements ) 225 | { 226 | this.chosenCSVElements.set( chosenCSVElements ); 227 | } 228 | 229 | public ObservableList getAvailableCSVElements() 230 | { 231 | return availableCSVElements.get(); 232 | } 233 | 234 | public ListProperty availableCSVElementsProperty() 235 | { 236 | return availableCSVElements; 237 | } 238 | 239 | public void setAvailableCSVElements( ObservableList availableCSVElements ) 240 | { 241 | this.availableCSVElements.set( availableCSVElements ); 242 | } 243 | 244 | public String getWorkingDirectory() 245 | { 246 | return workingDirectory.get(); 247 | } 248 | 249 | public StringProperty workingDirectoryProperty() 250 | { 251 | return workingDirectory; 252 | } 253 | 254 | public void setWorkingDirectory( String workingDirectory ) 255 | { 256 | this.workingDirectory.set( workingDirectory ); 257 | } 258 | 259 | public Generator.Type getGeneratorType() 260 | { 261 | return generatorType.getValue(); 262 | } 263 | 264 | public Property generatorTypeProperty() 265 | { 266 | return generatorType; 267 | } 268 | 269 | public void setGeneratorType( Generator.Type generatorType ) 270 | { 271 | this.generatorType.setValue(generatorType); 272 | } 273 | 274 | public GeneratorVars getGeneratorVars() 275 | { 276 | return generatorVars.getValue(); 277 | } 278 | 279 | public Property generatorVarsProperty() 280 | { 281 | return generatorVars; 282 | } 283 | 284 | public void setGeneratorVars( GeneratorVars generatorVars ) 285 | { 286 | this.generatorVars.setValue(generatorVars); 287 | } 288 | 289 | public Generator getGenerator() 290 | { 291 | return generator.getValue(); 292 | } 293 | 294 | public Property generatorProperty() 295 | { 296 | return generator; 297 | } 298 | 299 | public SharedGeneratorVars getSharedGeneratorVars() 300 | { 301 | return sharedVars; 302 | } 303 | 304 | public void setSharedGeneratorVars( SharedGeneratorVars sharedVars ) 305 | { 306 | this.sharedVars = sharedVars; 307 | } 308 | 309 | /************************************************************************** 310 | * THESE TWO METHODS ARE NEEDED TO SERIALIZE THIS CLASS 311 | *************************************************************************/ 312 | private void writeObject( ObjectOutputStream s ) throws IOException 313 | { 314 | WriteObjectsHelper.writeStringProp( s, graphBGImagePath ); 315 | WriteObjectsHelper.writeBoolProp( s, addPointOnClick ); 316 | WriteObjectsHelper.writeObjectProp( s, sourcePathDisplayType ); 317 | WriteObjectsHelper.writeListPropPathElem( s, chosenCSVElements ); 318 | WriteObjectsHelper.writeListPropPathElem( s, availableCSVElements ); 319 | WriteObjectsHelper.writeStringProp( s, workingDirectory ); 320 | WriteObjectsHelper.writeObjectProp( s, generatorType ); 321 | } 322 | 323 | private void readObject( ObjectInputStream s ) throws IOException, ClassNotFoundException 324 | { 325 | settingsDirExist = true; 326 | 327 | initialize(); 328 | 329 | ReadObjectsHelper.readStringProp( s, graphBGImagePath ); 330 | ReadObjectsHelper.readBoolProp( s, addPointOnClick ); 331 | ReadObjectsHelper.readObjectProp( s, sourcePathDisplayType, SourcePathDisplayType.class ); 332 | ReadObjectsHelper.readListPropPathElem( s, chosenCSVElements ); 333 | ReadObjectsHelper.readListPropPathElem( s, availableCSVElements ); 334 | ReadObjectsHelper.readStringProp( s, workingDirectory ); 335 | ReadObjectsHelper.readObjectProp( s, generatorType, Generator.Type.class ); 336 | 337 | switch( generatorType.getValue() ) 338 | { 339 | case PATHFINDER_V1: 340 | generatorVars.setValue( pfV1Vars ); 341 | generator.setValue( pfV1Generator ); 342 | break; 343 | 344 | default: 345 | throw new RuntimeException( "The programmer forgot to add a case for the following generator: " + generatorType.getValue() ); 346 | } 347 | } 348 | } 349 | -------------------------------------------------------------------------------- /src/java/com/mammen/settings/SourcePathDisplayType.java: -------------------------------------------------------------------------------- 1 | package com.mammen.settings; 2 | 3 | public enum SourcePathDisplayType 4 | { 5 | NONE( "None" ), 6 | WP_ONLY( "Waypoints only" ), 7 | WP_PLUS_PATH( "Waypoints + Source" ); 8 | 9 | private String label; 10 | 11 | SourcePathDisplayType( String label ) 12 | { 13 | this.label = label; 14 | } 15 | 16 | @Override 17 | public String toString() 18 | { 19 | return label; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/about/AboutDialog.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 24 | 26 | 27 | 28 | 29 | 30 |
31 | 32 | 33 | 34 | 35 | 36 | 37 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
73 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/about/AboutDialogController.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.dialog.about; 2 | 3 | import com.mammen.util.ResourceLoader; 4 | import javafx.event.ActionEvent; 5 | import javafx.fxml.FXML; 6 | import javafx.scene.control.Button; 7 | import javafx.scene.control.Hyperlink; 8 | import javafx.scene.control.Label; 9 | 10 | import java.awt.*; 11 | import java.net.URI; 12 | import java.util.jar.Attributes; 13 | import java.util.jar.Manifest; 14 | 15 | /** 16 | * Controller for the About dialog 17 | * Mainly just to initialize the links and version number 18 | */ 19 | public class AboutDialogController { 20 | @FXML 21 | private Label lblVersion; 22 | 23 | @FXML 24 | private Hyperlink 25 | hlLukeGithub, 26 | hlBlakeGithub, 27 | hlPathfinder, 28 | hlMITLicense; 29 | 30 | @FXML 31 | private Button btnViewRepo; 32 | 33 | @FXML 34 | private void initialize() { 35 | Manifest manifest = ResourceLoader.getManifest(); 36 | String versionNum = "4.0.1"; 37 | 38 | if (manifest != null) { 39 | Attributes mfAttr = manifest.getMainAttributes(); 40 | String mfVersion = mfAttr.getValue("Version"); 41 | 42 | if (mfVersion != null) 43 | versionNum = mfVersion; 44 | } 45 | 46 | lblVersion.setText("v" + versionNum); 47 | 48 | hlLukeGithub.setOnAction((ActionEvent e) -> openLink("https://github.com/vannaka")); 49 | hlBlakeGithub.setOnAction((ActionEvent e) -> openLink("https://github.com/blake1029384756")); 50 | hlPathfinder.setOnAction((ActionEvent e) -> openLink("https://github.com/JacisNonsense/Pathfinder")); 51 | hlMITLicense.setOnAction((ActionEvent e) -> openLink("https://opensource.org/licenses/MIT")); 52 | 53 | btnViewRepo.setOnAction((ActionEvent e) -> openLink("https://github.com/vannaka/Motion_Profile_Generator")); 54 | } 55 | 56 | private void openLink(String url) { 57 | try { 58 | Desktop.getDesktop().browse(new URI(url)); 59 | } catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/add_waypoint/AddWaypointDialog.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/add_waypoint/AddWaypointDialogController.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.dialog.add_waypoint; 2 | 3 | import javafx.fxml.FXML; 4 | import javafx.scene.control.TextField; 5 | import javafx.scene.control.TextFormatter; 6 | import javafx.util.converter.DoubleStringConverter; 7 | 8 | public class AddWaypointDialogController 9 | { 10 | @FXML 11 | private TextField 12 | txtWX, // X-Coord 13 | txtWY, // Y-Coord 14 | txtWA; // Angle 15 | 16 | @FXML 17 | private void initialize() { 18 | txtWX.setTextFormatter( new TextFormatter<>( new DoubleStringConverter() ) ); 19 | txtWY.setTextFormatter( new TextFormatter<>( new DoubleStringConverter() ) ); 20 | txtWA.setTextFormatter( new TextFormatter<>( new DoubleStringConverter() ) ); 21 | } 22 | 23 | public TextField getTxtWX() 24 | { 25 | return txtWX; 26 | } 27 | 28 | public TextField getTxtWY() 29 | { 30 | return txtWY; 31 | } 32 | 33 | public TextField getTxtWA() 34 | { 35 | return txtWA; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/factory/AlertFactory.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.dialog.factory; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | 6 | import javafx.scene.control.Alert; 7 | import javafx.scene.control.Label; 8 | import javafx.scene.control.TextArea; 9 | import javafx.scene.layout.GridPane; 10 | import javafx.scene.layout.Priority; 11 | 12 | public class AlertFactory 13 | { 14 | public static Alert createExceptionAlert( Exception e ) 15 | { 16 | return createExceptionAlert( e, e.getMessage() ); 17 | } 18 | 19 | public static Alert createExceptionAlert( Exception e, String msg ) 20 | { 21 | Alert alert = new Alert(Alert.AlertType.ERROR); 22 | alert.setTitle("Exception Dialog"); 23 | alert.setHeaderText("Whoops!"); 24 | alert.setContentText(msg); 25 | 26 | // Create expandable Exception. 27 | StringWriter sw = new StringWriter(); 28 | PrintWriter pw = new PrintWriter(sw); 29 | e.printStackTrace(pw); 30 | String exceptionText = sw.toString(); 31 | 32 | Label label = new Label("The exception stacktrace was:"); 33 | 34 | TextArea textArea = new TextArea(exceptionText); 35 | textArea.setEditable(false); 36 | textArea.setWrapText(true); 37 | 38 | textArea.setMaxWidth(Double.MAX_VALUE); 39 | textArea.setMaxHeight(Double.MAX_VALUE); 40 | GridPane.setVgrow(textArea, Priority.ALWAYS); 41 | GridPane.setHgrow(textArea, Priority.ALWAYS); 42 | 43 | GridPane expContent = new GridPane(); 44 | expContent.setMaxWidth(Double.MAX_VALUE); 45 | expContent.add(label, 0, 0); 46 | expContent.add(textArea, 0, 1); 47 | 48 | // Set expandable Exception into the dialog pane. 49 | alert.getDialogPane().setExpandableContent(expContent); 50 | 51 | return alert; 52 | } 53 | 54 | public static Alert createInvalidOSAlert( String msg ) 55 | { 56 | Alert alert = new Alert(Alert.AlertType.ERROR); 57 | alert.setTitle("Invalid OS"); 58 | alert.setHeaderText("Whoops!"); 59 | alert.setContentText(msg); 60 | 61 | return alert; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/factory/DialogFactory.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.dialog.factory; 2 | 3 | import java.awt.Toolkit; 4 | 5 | import com.mammen.path.Waypoint; 6 | import com.mammen.util.ResourceLoader; 7 | import com.mammen.ui.javafx.dialog.add_waypoint.AddWaypointDialogController; 8 | 9 | import javafx.event.ActionEvent; 10 | import javafx.fxml.FXMLLoader; 11 | import javafx.scene.control.Alert; 12 | import javafx.scene.control.Button; 13 | import javafx.scene.control.ButtonBar; 14 | import javafx.scene.control.ButtonType; 15 | import javafx.scene.control.Dialog; 16 | import javafx.scene.control.DialogPane; 17 | import javafx.scene.control.TextField; 18 | 19 | public class DialogFactory 20 | { 21 | private DialogFactory() { } 22 | 23 | public static Dialog createAboutDialog() 24 | { 25 | Dialog dialog = new Dialog<>(); 26 | 27 | try 28 | { 29 | FXMLLoader loader = new FXMLLoader( ResourceLoader.getResource("/com/mammen/ui/javafx/dialog/about/AboutDialog.fxml") ); 30 | 31 | dialog.setDialogPane( loader.load() ); 32 | 33 | dialog.setResultConverter( (ButtonType buttonType) -> buttonType.getButtonData() == ButtonBar.ButtonData.CANCEL_CLOSE ); 34 | } 35 | catch( Exception e ) 36 | { 37 | e.printStackTrace(); 38 | dialog.getDialogPane().getButtonTypes().add( ButtonType.CLOSE ); 39 | } 40 | 41 | dialog.setTitle( "About" ); 42 | 43 | return dialog; 44 | } 45 | 46 | public static Dialog createSettingsDialog() 47 | { 48 | Dialog dialog = new Dialog<>(); 49 | 50 | try 51 | { 52 | FXMLLoader loader = new FXMLLoader( ResourceLoader.getResource("/com/mammen/ui/javafx/dialog/settings/SettingsDialog.fxml") ); 53 | 54 | dialog.setDialogPane( loader.load() ); 55 | 56 | ((Button) dialog.getDialogPane().lookupButton(ButtonType.APPLY)).setDefaultButton(true); 57 | ((Button) dialog.getDialogPane().lookupButton(ButtonType.CANCEL)).setDefaultButton(false); 58 | 59 | // Some header stuff 60 | dialog.setTitle("Settings"); 61 | dialog.setHeaderText("Manage settings"); 62 | 63 | dialog.setResultConverter( (ButtonType buttonType) -> buttonType.getButtonData() == ButtonBar.ButtonData.APPLY ); 64 | } 65 | catch( Exception e ) 66 | { 67 | e.printStackTrace(); 68 | } 69 | 70 | return dialog; 71 | } 72 | 73 | public static Dialog createWaypointDialog( String xPos, String yPos ) 74 | { 75 | Dialog dialog = new Dialog<>(); 76 | 77 | try 78 | { 79 | FXMLLoader loader = new FXMLLoader( ResourceLoader.getResource("/com/mammen/ui/javafx/dialog/add_waypoint/AddWaypointDialog.fxml") ); 80 | ButtonType add = new ButtonType("Add", ButtonBar.ButtonData.OK_DONE ); 81 | DialogPane root = loader.load(); 82 | 83 | AddWaypointDialogController controller = null; 84 | TextField txtWX, txtWY, txtWA; 85 | 86 | dialog.setDialogPane(root); 87 | 88 | controller = loader.getController(); 89 | 90 | txtWX = controller.getTxtWX(); 91 | txtWY = controller.getTxtWY(); 92 | txtWA = controller.getTxtWA(); 93 | 94 | txtWX.setText( xPos ); 95 | txtWY.setText( yPos ); 96 | 97 | // Some header stuff 98 | dialog.setTitle( "Add Waypoint" ); 99 | dialog.setHeaderText( "Add a new waypoint" ); 100 | 101 | dialog.getDialogPane().getButtonTypes().add( add ); 102 | 103 | dialog.setResultConverter( (ButtonType buttonType) -> 104 | { 105 | if( buttonType.getButtonData() == ButtonBar.ButtonData.OK_DONE ) 106 | { 107 | double x = Double.parseDouble( txtWX.getText().trim() ); 108 | double y = Double.parseDouble( txtWY.getText().trim() ); 109 | double angle = Double.parseDouble( txtWA.getText().trim() ); 110 | 111 | return new Waypoint( x, y, angle ); 112 | } 113 | 114 | return null; 115 | }); 116 | 117 | root.lookupButton( add ).addEventFilter( ActionEvent.ACTION, ae -> 118 | { 119 | try 120 | { 121 | Double.parseDouble( txtWX.getText().trim() ); 122 | Double.parseDouble( txtWY.getText().trim() ); 123 | Double.parseDouble( txtWA.getText().trim() ); 124 | } 125 | catch( Exception e ) 126 | { 127 | Alert alert = new Alert(Alert.AlertType.WARNING); 128 | 129 | alert.setTitle( "Invalid Point!" ); 130 | alert.setHeaderText( "Invalid point input!" ); 131 | alert.setContentText( "Please check your fields and try again." ); 132 | 133 | Toolkit.getDefaultToolkit().beep(); 134 | alert.showAndWait(); 135 | ae.consume(); 136 | } 137 | }); 138 | } 139 | catch( Exception e ) 140 | { 141 | e.printStackTrace(); 142 | } 143 | finally 144 | { 145 | dialog.getDialogPane().getButtonTypes().add( ButtonType.CANCEL ); 146 | } 147 | 148 | return dialog; 149 | } 150 | 151 | public static Dialog createWaypointDialog() 152 | { 153 | return createWaypointDialog("", ""); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/settings/SettingsDialog.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | 32 |
142 |
143 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/settings/SettingsDialogController.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.dialog.settings; 2 | 3 | import com.mammen.generator.Generator; 4 | import com.mammen.path.Path; 5 | import com.mammen.settings.SettingsModel; 6 | import com.mammen.settings.SourcePathDisplayType; 7 | import javafx.fxml.FXML; 8 | import javafx.scene.control.*; 9 | import javafx.scene.input.*; 10 | import javafx.scene.layout.Pane; 11 | import javafx.stage.FileChooser; 12 | 13 | import java.io.File; 14 | import java.util.*; 15 | 16 | public class SettingsDialogController 17 | { 18 | @FXML 19 | private Pane root, pnl_general, pnl_csv, pnl_generator, pnl_pfV1Vars; 20 | 21 | @FXML 22 | private TextField txtOverlayDir; 23 | 24 | @FXML 25 | private Button btnChooseOverlay, btn_general, btn_csv, btn_generator; 26 | 27 | @FXML 28 | private ChoiceBox choSourceDisplayType; 29 | 30 | @FXML 31 | private ChoiceBox cho_generatorType; 32 | 33 | @FXML 34 | private CheckBox chkAddWaypointOnClick; 35 | 36 | @FXML 37 | private ListView lst_availableElements, lst_chosenElements; 38 | 39 | private SettingsModel settings; 40 | 41 | private static DataFormat profileElementFormat = new DataFormat("com.mammen.path.Path.Elements" ); 42 | 43 | @FXML 44 | private void initialize() 45 | { 46 | settings = SettingsModel.getInstance(); 47 | 48 | btn_gen_styles(); 49 | 50 | /****************************************************** 51 | * Setup ui elements 52 | ******************************************************/ 53 | choSourceDisplayType.getItems().setAll( SourcePathDisplayType.values() ); 54 | cho_generatorType .getItems().setAll( Generator.Type.values() ); 55 | 56 | 57 | /****************************************************** 58 | * Setup bindings to the SettingsModel object 59 | ******************************************************/ 60 | txtOverlayDir .textProperty() .bindBidirectional( settings.graphBGImagePathProperty() ); 61 | choSourceDisplayType .valueProperty() .bindBidirectional( settings.sourcePathDisplayTypeProperty() ); 62 | chkAddWaypointOnClick .selectedProperty() .bindBidirectional( settings.addPointOnClickProperty() ); 63 | lst_chosenElements .itemsProperty() .bindBidirectional( settings.chosenCSVElementsProperty() ); 64 | lst_availableElements .itemsProperty() .bindBidirectional( settings.availableCSVElementsProperty() ); 65 | cho_generatorType .valueProperty() .bindBidirectional( settings.generatorTypeProperty() ); 66 | 67 | // Set visibility of settings panels 68 | pnl_general.setVisible( true ); 69 | pnl_csv.setVisible( false ); 70 | pnl_generator.setVisible( false ); 71 | 72 | settings.generatorTypeProperty().addListener( (O, oldValue, newValue) -> 73 | { 74 | switch( newValue ) 75 | { 76 | case PATHFINDER_V1: 77 | pnl_pfV1Vars.setVisible( true ); 78 | break; 79 | 80 | default: 81 | throw new RuntimeException( "The programmer forgot to add a case for the following generator: " + newValue ); 82 | } 83 | }); 84 | 85 | 86 | lst_chosenElements.setCellFactory( lv -> 87 | { 88 | ListCell cell = new ListCell() 89 | { 90 | @Override 91 | protected void updateItem( Path.Elements item, boolean empty ) 92 | { 93 | super.updateItem( item, empty ); 94 | if( empty || item == null ) 95 | { 96 | setText( null ); 97 | } 98 | else 99 | { 100 | setText( item.toString() ); 101 | } 102 | } 103 | }; 104 | 105 | cell.setOnDragOver( event -> 106 | { 107 | if( ( ( event.getGestureSource() == lst_chosenElements ) || ( event.getGestureSource() == lst_availableElements) ) 108 | && ( event.getDragboard().hasContent( profileElementFormat ) ) ) 109 | { 110 | event.acceptTransferModes( TransferMode.MOVE ); 111 | } 112 | 113 | event.consume(); 114 | }); 115 | 116 | cell.setOnDragDropped( event -> 117 | { 118 | Dragboard db = event.getDragboard(); 119 | boolean success = false; 120 | if( db.hasContent( profileElementFormat ) ) 121 | { 122 | if( cell.isEmpty() ) 123 | { 124 | lst_chosenElements.getItems().add( (Path.Elements)db.getContent( profileElementFormat ) ); 125 | success = true; 126 | } 127 | else 128 | { 129 | int index = cell.getIndex(); 130 | lst_chosenElements.getItems().add( index, (Path.Elements)db.getContent( profileElementFormat ) ); 131 | success = true; 132 | } 133 | } 134 | 135 | event.setDropCompleted( success ); 136 | 137 | event.consume(); 138 | }); 139 | 140 | // highlight cells when drag target 141 | cell.setOnDragEntered( event -> cell.setStyle("-fx-border-color: DodgerBlue") ); 142 | cell.setOnDragExited( event -> cell.setStyle("") ); 143 | return cell ; 144 | }); 145 | } 146 | 147 | @FXML 148 | private void showChooseOverlayDialog() 149 | { 150 | FileChooser fileChooser = new FileChooser(); 151 | 152 | fileChooser.setInitialDirectory(new File(System.getProperty("user.dir"))); 153 | fileChooser.setTitle("Find Position Map Overlay"); 154 | fileChooser.getExtensionFilters().add( 155 | new FileChooser.ExtensionFilter( 156 | "Image Files", 157 | "*.jpg", 158 | "*.jpeg", 159 | "*.png" 160 | ) 161 | ); 162 | 163 | File result = fileChooser.showOpenDialog(root.getScene().getWindow()); 164 | 165 | if (result != null && result.exists() && !result.isDirectory()) { 166 | txtOverlayDir.setText(result.getAbsolutePath()); 167 | } 168 | } 169 | 170 | @FXML 171 | private void showGeneralSettings() 172 | { 173 | pnl_general.toFront(); 174 | pnl_csv.setVisible( false ); 175 | pnl_general.setVisible( true ); 176 | pnl_generator.setVisible( false ); 177 | } 178 | 179 | @FXML 180 | private void showCSVSettings() 181 | { 182 | pnl_csv.toFront(); 183 | pnl_csv.setVisible( true ); 184 | pnl_general.setVisible( false ); 185 | pnl_generator.setVisible( false ); 186 | } 187 | 188 | @FXML 189 | private void showGeneratorSettings() 190 | { 191 | pnl_generator.toFront(); 192 | pnl_generator.setVisible( true ); 193 | pnl_csv.setVisible( false ); 194 | pnl_general.setVisible( false ); 195 | } 196 | 197 | //Drag from available to chosen 198 | @FXML 199 | private void lst_aval_onDragDetected() 200 | { 201 | Dragboard db = lst_availableElements.startDragAndDrop( TransferMode.MOVE ); 202 | ClipboardContent content = new ClipboardContent(); 203 | content.put( profileElementFormat, lst_availableElements.getSelectionModel().getSelectedItem() ); 204 | db.setContent( content ); 205 | } 206 | 207 | 208 | @FXML 209 | private void lst_avail_onDragOver( DragEvent event ) 210 | { 211 | if( ( event.getGestureSource() != lst_availableElements ) 212 | && ( event.getDragboard().hasContent( profileElementFormat ) ) ) 213 | { 214 | event.acceptTransferModes( TransferMode.MOVE ); 215 | } 216 | } 217 | 218 | 219 | @FXML 220 | private void lst_avail_onDragDrop( DragEvent event ) 221 | { 222 | /* data dropped */ 223 | /* if there is a string data on dragboard, read it and use it */ 224 | Dragboard db = event.getDragboard(); 225 | boolean success = false; 226 | if( db.hasContent( profileElementFormat ) ) 227 | { 228 | lst_availableElements.getItems().add( (Path.Elements)db.getContent( profileElementFormat ) ); 229 | lst_availableElements.getItems().sort( Comparator.comparing( Path.Elements::ordinal ) ); 230 | success = true; 231 | } 232 | /* let the source know whether the string was successfully 233 | * transferred and used */ 234 | event.setDropCompleted( success ); 235 | } 236 | 237 | 238 | @FXML 239 | private void lst_aval_onDragDone( DragEvent event ) 240 | { 241 | if (event.getTransferMode() == TransferMode.MOVE) 242 | { 243 | if( lst_availableElements.getItems().size() == 1 ) 244 | { 245 | lst_availableElements.getItems().remove(lst_availableElements.getSelectionModel().getSelectedIndex()); 246 | return; 247 | } 248 | lst_availableElements.getItems().remove(lst_availableElements.getSelectionModel().getSelectedIndex()); 249 | } 250 | } 251 | 252 | 253 | /* Drag from chosen to available*/ 254 | @FXML 255 | private void lst_chos_onDragDetected() 256 | { 257 | Dragboard db = lst_chosenElements.startDragAndDrop( TransferMode.MOVE ); 258 | ClipboardContent content = new ClipboardContent(); 259 | content.put( profileElementFormat, lst_chosenElements.getSelectionModel().getSelectedItem() ); 260 | db.setContent( content ); 261 | } 262 | 263 | 264 | @FXML 265 | private void lst_chos_onDragOver( DragEvent event ) 266 | { 267 | if( ( event.getGestureSource() != lst_chosenElements ) 268 | && ( event.getDragboard().hasContent( profileElementFormat ) ) ) 269 | { 270 | event.acceptTransferModes( TransferMode.MOVE ); 271 | } 272 | } 273 | 274 | 275 | @FXML 276 | private void lst_chos_onDragDrop( DragEvent event ) 277 | { 278 | /* data dropped */ 279 | /* if there is a string data on dragboard, read it and use it */ 280 | Dragboard db = event.getDragboard(); 281 | boolean success = false; 282 | if( db.hasContent( profileElementFormat ) ) 283 | { 284 | lst_chosenElements.getItems().add( (Path.Elements)db.getContent( profileElementFormat ) ); 285 | success = true; 286 | } 287 | /* let the source know whether the string was successfully 288 | * transferred and used */ 289 | event.setDropCompleted( success ); 290 | } 291 | 292 | 293 | @FXML 294 | private void lst_chos_onDragDone( DragEvent event ) 295 | { 296 | if( event.getTransferMode() == TransferMode.MOVE ) 297 | { 298 | if( lst_chosenElements.getItems().size() == 1 ) 299 | { 300 | lst_chosenElements.getItems().remove( lst_chosenElements.getSelectionModel().getSelectedIndex() ); 301 | return; 302 | } 303 | lst_chosenElements.getItems().remove( lst_chosenElements.getSelectionModel().getSelectedIndex() ); 304 | } 305 | } 306 | 307 | 308 | /* Button Effects */ 309 | @FXML 310 | private void btn_gen_styles() 311 | { 312 | btn_general .setStyle( "-fx-background-color: DodgerBlue; " + 313 | "-fx-text-fill: #FFFFFF"); 314 | 315 | btn_csv .setStyle( "-fx-border-color: transparent; " + 316 | "-fx-border-width: 0; " + 317 | "-fx-background-radius: 0; " + 318 | "-fx-background-color: transparent;" + 319 | "-fx-text-fill: #000000"); 320 | 321 | btn_generator.setStyle( "-fx-border-color: transparent; " + 322 | "-fx-border-width: 0; " + 323 | "-fx-background-radius: 0; " + 324 | "-fx-background-color: transparent;" + 325 | "-fx-text-fill: #000000"); 326 | } 327 | 328 | @FXML 329 | private void btn_csv_styles() 330 | { 331 | btn_csv .setStyle( "-fx-background-color: DodgerBlue; " + 332 | "-fx-text-fill: #FFFFFF"); 333 | 334 | btn_general .setStyle( "-fx-border-color: transparent; " + 335 | "-fx-border-width: 0; " + 336 | "-fx-background-radius: 0; " + 337 | "-fx-background-color: transparent;" + 338 | "-fx-text-fill: #000000"); 339 | 340 | btn_generator.setStyle( "-fx-border-color: transparent; " + 341 | "-fx-border-width: 0; " + 342 | "-fx-background-radius: 0; " + 343 | "-fx-background-color: transparent;" + 344 | "-fx-text-fill: #000000"); 345 | } 346 | 347 | @FXML 348 | private void btn_generatorStyles() 349 | { 350 | btn_general .setStyle( "-fx-border-color: transparent; " + 351 | "-fx-border-width: 0; " + 352 | "-fx-background-radius: 0; " + 353 | "-fx-background-color: transparent;" + 354 | "-fx-text-fill: #000000"); 355 | 356 | btn_csv .setStyle( "-fx-border-color: transparent; " + 357 | "-fx-border-width: 0; " + 358 | "-fx-background-radius: 0; " + 359 | "-fx-background-color: transparent;" + 360 | "-fx-text-fill: #000000"); 361 | 362 | btn_generator.setStyle( "-fx-background-color: DodgerBlue; " + 363 | "-fx-text-fill: #FFFFFF"); 364 | } 365 | 366 | } 367 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/settings/generator_vars/PathfinderV1VarsController.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.dialog.settings.generator_vars; 2 | 3 | import com.mammen.generator.generator_vars.SharedGeneratorVars; 4 | import com.mammen.generator.generator_vars.DriveBase; 5 | import com.mammen.generator.generator_vars.Units; 6 | import com.mammen.generator.generator_vars.PfV1GeneratorVars; 7 | import javafx.fxml.FXML; 8 | import javafx.scene.control.*; 9 | import javafx.scene.control.Label; 10 | import javafx.scene.control.TextField; 11 | import javafx.util.StringConverter; 12 | import javafx.util.converter.NumberStringConverter; 13 | 14 | import java.util.function.UnaryOperator; 15 | 16 | public class PathfinderV1VarsController 17 | { 18 | @FXML 19 | private Label 20 | lblWheelBaseD; 21 | 22 | @FXML 23 | private TextField 24 | txtTimeStep, 25 | txtVelocity, 26 | txtAcceleration, 27 | txtJerk, 28 | txtWheelBaseW, 29 | txtWheelBaseD; 30 | 31 | @FXML 32 | private ChoiceBox choFitMethod; 33 | 34 | @FXML 35 | private ChoiceBox choDriveBase; 36 | 37 | @FXML 38 | private ChoiceBox choUnits; 39 | 40 | private PfV1GeneratorVars vars; 41 | private SharedGeneratorVars sharedVars; 42 | 43 | 44 | /************************************************************************** 45 | * initialize 46 | * Setup gui stuff here. 47 | *************************************************************************/ 48 | @FXML private void initialize() 49 | { 50 | sharedVars = SharedGeneratorVars.getInstance(); 51 | vars = PfV1GeneratorVars.getInstance(); 52 | 53 | // Populate ChoiceBox's 54 | choDriveBase.getItems().setAll( DriveBase.values() ); 55 | choFitMethod.getItems().setAll( PfV1GeneratorVars.FitMethod.values() ); 56 | choUnits.getItems().setAll( Units.values() ); 57 | 58 | // Formats number typed into TextFields 59 | UnaryOperator filter = t -> 60 | { 61 | if( t.isReplaced() ) 62 | // If new text isn't a digit 63 | if( t.getText().matches("[^0-9]") ) 64 | { 65 | // Keep original text 66 | t.setText( t.getControlText().substring( t.getRangeStart(), t.getRangeEnd() ) ); 67 | } 68 | 69 | if( t.isAdded() ) 70 | { 71 | // If a period is already present. 72 | if ( t.getControlText().contains(".") ) 73 | { 74 | // If new text isn't a digit 75 | if( t.getText().matches("[^0-9]") ) 76 | { 77 | t.setText(""); 78 | } 79 | } 80 | // If we are adding a period to an empty field, prepend it with a zero. 81 | else if( ( t.getControlNewText().length() == 1 ) 82 | && ( t.getControlNewText().matches( "\\.") ) ) 83 | { 84 | t.setText("0."); 85 | //t.setCaretPosition( 2 ); 86 | } 87 | // If new text isn't a digit or a period 88 | else if ( t.getText().matches("[^0-9\\.]") ) 89 | { 90 | t.setText(""); 91 | } 92 | } 93 | 94 | return t; 95 | }; 96 | 97 | // Setup formatter to only allow doubles to be typed into these TextFields 98 | txtTimeStep .setTextFormatter( new TextFormatter<>( filter ) ); 99 | txtVelocity .setTextFormatter( new TextFormatter<>( filter ) ); 100 | txtAcceleration .setTextFormatter( new TextFormatter<>( filter ) ); 101 | txtJerk .setTextFormatter( new TextFormatter<>( filter ) ); 102 | txtWheelBaseW .setTextFormatter( new TextFormatter<>( filter ) ); 103 | txtWheelBaseD .setTextFormatter( new TextFormatter<>( filter ) ); 104 | 105 | 106 | // Converts formatted string in TextField to format of bounded property. 107 | StringConverter converter = new NumberStringConverter(); 108 | 109 | // Setup Bindings 110 | choFitMethod .valueProperty().bindBidirectional( vars.fitMethodProperty() ); 111 | choDriveBase .valueProperty().bindBidirectional( sharedVars.driveBaseProperty() ); 112 | choUnits .valueProperty().bindBidirectional( sharedVars.unitProperty() ); 113 | 114 | txtTimeStep .textProperty().bindBidirectional( sharedVars.timeStepProperty(), converter ); 115 | txtWheelBaseW .textProperty().bindBidirectional( sharedVars.wheelBaseWProperty(), converter ); 116 | txtWheelBaseD .textProperty().bindBidirectional( sharedVars.wheelBaseDProperty(), converter ); 117 | txtVelocity .textProperty().bindBidirectional( vars.velocityProperty(), converter ); 118 | txtAcceleration .textProperty().bindBidirectional( vars.accelProperty(), converter ); 119 | txtJerk .textProperty().bindBidirectional( vars.jerkProperty(), converter ); 120 | 121 | 122 | // Disable WheelBaseD for Tank DriveBase 123 | sharedVars.driveBaseProperty().addListener( ( o, oldValue, newValue ) -> 124 | { 125 | boolean dis = newValue == DriveBase.TANK; 126 | lblWheelBaseD.disableProperty().setValue( dis ); 127 | txtWheelBaseD.disableProperty().setValue( dis ); 128 | }); 129 | 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/dialog/settings/generator_vars/PathfinderV1VarsUI.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/main/MainUI.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |