├── settings.gradle ├── images ├── FRC2018.jpg ├── FRC2019.jpg └── ProgramWindow.PNG ├── src ├── resources │ └── images │ │ ├── FRC2018.jpg │ │ └── FRC2019.jpg └── java │ └── com │ └── mammen │ ├── generator │ ├── generator_vars │ │ ├── GeneratorVars.java │ │ ├── DriveBase.java │ │ ├── Units.java │ │ ├── SharedGeneratorVars.java │ │ └── PfV1GeneratorVars.java │ ├── Generator.java │ └── PfV1Generator.java │ ├── main │ ├── Main.java │ ├── MainApp.java │ └── MainUIModel.java │ ├── settings │ ├── SourcePathDisplayType.java │ └── SettingsModel.java │ ├── util │ ├── OSValidator.java │ ├── SerializeHelpers │ │ ├── ObjectSerializer.java │ │ ├── ReadObjectsHelper.java │ │ └── WriteObjectsHelper.java │ ├── ResourceLoader.java │ └── Mathf.java │ ├── ui │ └── javafx │ │ ├── dialog │ │ ├── add_waypoint │ │ │ ├── AddWaypointDialogController.java │ │ │ └── AddWaypointDialog.fxml │ │ ├── about │ │ │ ├── AboutDialogController.java │ │ │ └── AboutDialog.fxml │ │ ├── factory │ │ │ ├── AlertFactory.java │ │ │ └── DialogFactory.java │ │ └── settings │ │ │ ├── generator_vars │ │ │ ├── PathfinderV1VarsController.java │ │ │ └── PathfinderV1VarsUI.fxml │ │ │ ├── SettingsDialog.fxml │ │ │ └── SettingsDialogController.java │ │ └── main │ │ ├── graphs │ │ ├── VelGraphUI.fxml │ │ ├── PosGraphUI.fxml │ │ ├── VelGraphController.java │ │ └── PosGraphController.java │ │ ├── MainUI.fxml │ │ └── MainUIController.java │ ├── path │ ├── Waypoint.java │ └── Path.java │ └── file_io │ └── FileIO.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── LICENSE ├── azure-pipelines.yml ├── README.md ├── gradlew.bat ├── CHANGELOG.md └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Motion_Profile_Generator' -------------------------------------------------------------------------------- /images/FRC2018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/HEAD/images/FRC2018.jpg -------------------------------------------------------------------------------- /images/FRC2019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/HEAD/images/FRC2019.jpg -------------------------------------------------------------------------------- /images/ProgramWindow.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/HEAD/images/ProgramWindow.PNG -------------------------------------------------------------------------------- /src/resources/images/FRC2018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/HEAD/src/resources/images/FRC2018.jpg -------------------------------------------------------------------------------- /src/resources/images/FRC2019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/HEAD/src/resources/images/FRC2019.jpg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vannaka/Motion_Profile_Generator/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/util/OSValidator.java: -------------------------------------------------------------------------------- 1 | package com.mammen.util; 2 | 3 | public class OSValidator { 4 | 5 | private static String OS = System.getProperty("os.name").toLowerCase(); 6 | 7 | public static boolean isWindows() { 8 | 9 | return (OS.indexOf("win") >= 0); 10 | 11 | } 12 | 13 | public static boolean isMac() { 14 | 15 | return (OS.indexOf("mac") >= 0); 16 | 17 | } 18 | 19 | public static boolean isUnix() { 20 | 21 | return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); 22 | 23 | } 24 | 25 | public static boolean isSolaris() { 26 | 27 | return (OS.indexOf("sunos") >= 0); 28 | 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/java/com/mammen/util/SerializeHelpers/ObjectSerializer.java: -------------------------------------------------------------------------------- 1 | package com.mammen.util.SerializeHelpers; 2 | 3 | import java.io.*; 4 | 5 | public class ObjectSerializer 6 | { 7 | public static void saveObject( Object obj, String filePath ) throws IOException 8 | { 9 | ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( filePath ) ); 10 | out.writeObject( obj ); 11 | out.close(); 12 | } 13 | 14 | public static Object loadObject( String filePath ) 15 | { 16 | Object obj; 17 | 18 | try 19 | { 20 | ObjectInputStream in = new ObjectInputStream( new FileInputStream( filePath ) ); 21 | obj = in.readObject(); 22 | in.close(); 23 | } 24 | catch( IOException | ClassNotFoundException i ) 25 | { 26 | return null; 27 | } 28 | 29 | return obj; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /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/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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/main/graphs/VelGraphUI.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/java/com/mammen/util/ResourceLoader.java: -------------------------------------------------------------------------------- 1 | package com.mammen.util; 2 | 3 | import java.io.*; 4 | import java.net.URL; 5 | import java.nio.file.StandardCopyOption; 6 | import java.util.jar.Manifest; 7 | 8 | public class ResourceLoader 9 | { 10 | private ResourceLoader() 11 | { 12 | } 13 | 14 | public static URL getResource(String path) 15 | { 16 | return ResourceLoader.class.getResource( path ); 17 | } 18 | 19 | public static InputStream getResourceAsStream( String path ) 20 | { 21 | return ResourceLoader.class.getResourceAsStream(path); 22 | } 23 | 24 | public static void resourceToFile( String rsPath, File file ) throws IOException 25 | { 26 | InputStream is = getResourceAsStream( rsPath ); 27 | 28 | java.nio.file.Files.copy( is, file.toPath(), StandardCopyOption.REPLACE_EXISTING ); 29 | 30 | is.close(); 31 | } 32 | 33 | // TODO: Figure out what manifest this method is actually getting 34 | public static Manifest getManifest() 35 | { 36 | Manifest mf = new Manifest(); 37 | 38 | try 39 | { 40 | mf.read(getResourceAsStream("/META-INF/MANIFEST.MF")); 41 | } 42 | catch (IOException e) 43 | { 44 | e.printStackTrace(); 45 | } 46 | 47 | return mf; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/java/com/mammen/ui/javafx/main/graphs/PosGraphUI.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/util/Mathf.java: -------------------------------------------------------------------------------- 1 | package com.mammen.util; 2 | 3 | public class Mathf 4 | { 5 | private Mathf() {} 6 | 7 | /** 8 | * Rounds the specified value to the specified number of decimal places 9 | * 10 | * @param val the number to round 11 | * @param places the amonut of decimal places to round to 12 | * @return number rounded to places 13 | */ 14 | public static double round(double val, int places) { 15 | double tens = Math.pow(10.0, places); 16 | 17 | return Math.round(val * tens) / tens; 18 | } 19 | 20 | /** 21 | * Rounds the specified value to the closest specified multiple 22 | * 23 | * @param val the number to round 24 | * @param multi the multiple (<1) to round to 25 | * @return the rounded number 26 | */ 27 | public static double round( double val, double multi ) 28 | { 29 | return Math.round( val / multi ) * multi; 30 | } 31 | 32 | public static double meterToFeet( double meters ) 33 | { 34 | return meters / 0.3048; 35 | } 36 | 37 | public static double inchesToFeet( double inches ) 38 | { 39 | return inches / 12; 40 | } 41 | 42 | public static double feetToMeter( double feet ) 43 | { 44 | return feet * 0.3048; 45 | } 46 | 47 | public static double feetToInches( double feet ) 48 | { 49 | return feet * 12; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/java/com/mammen/util/SerializeHelpers/ReadObjectsHelper.java: -------------------------------------------------------------------------------- 1 | package com.mammen.util.SerializeHelpers; 2 | 3 | import com.mammen.path.Path; 4 | import com.mammen.settings.SourcePathDisplayType; 5 | import javafx.beans.property.*; 6 | 7 | import java.io.IOException; 8 | import java.io.ObjectInputStream; 9 | 10 | public class ReadObjectsHelper 11 | { 12 | public static void readStringProp( ObjectInputStream s, StringProperty prop ) throws IOException 13 | { 14 | prop.set( s.readUTF() ); 15 | } 16 | 17 | public static void readBoolProp( ObjectInputStream s, BooleanProperty prop ) throws IOException 18 | { 19 | prop.set( s.readBoolean() ); 20 | } 21 | 22 | public static void readDoubleProp( ObjectInputStream s, DoubleProperty prop ) throws IOException 23 | { 24 | prop.set( s.readDouble() ); 25 | } 26 | 27 | public static void readObjectProp( ObjectInputStream s, Property prop, Class type ) throws IOException, ClassNotFoundException 28 | { 29 | prop.setValue( type.cast( s.readObject() ) ); 30 | } 31 | 32 | // Read a ListProperty from ObjectInputStream (and return it) 33 | public static void readListPropPathElem( ObjectInputStream s, ListProperty lst ) throws IOException, ClassNotFoundException 34 | { 35 | int loop = s.readInt(); 36 | for( int i = 0; i < loop; i++ ) 37 | { 38 | lst.add( (Path.Elements)s.readObject() ); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/java/com/mammen/util/SerializeHelpers/WriteObjectsHelper.java: -------------------------------------------------------------------------------- 1 | package com.mammen.util.SerializeHelpers; 2 | 3 | import com.mammen.path.Path; 4 | import com.mammen.settings.SourcePathDisplayType; 5 | import javafx.beans.property.*; 6 | 7 | import java.io.IOException; 8 | import java.io.ObjectOutputStream; 9 | 10 | public class WriteObjectsHelper 11 | { 12 | 13 | // write a StringProperty to ObjectOutputStream 14 | public static void writeStringProp( ObjectOutputStream s, StringProperty strProp) throws IOException 15 | { 16 | s.writeUTF( strProp.getValueSafe() ); 17 | } 18 | 19 | // write a ListProperty to ObjectOutputStream 20 | public static void writeListPropPathElem( ObjectOutputStream s, ListProperty lstProp) throws IOException 21 | { 22 | if( lstProp == null || lstProp.getValue() == null ) 23 | { 24 | s.writeInt(0 ); 25 | return; 26 | } 27 | s.writeInt( lstProp.size() ); 28 | for( Path.Elements elt : lstProp.getValue() ) 29 | s.writeObject( elt ); 30 | } 31 | 32 | public static void writeBoolProp( ObjectOutputStream s, BooleanProperty boolProp ) throws IOException 33 | { 34 | s.writeBoolean( boolProp.get() ); 35 | } 36 | 37 | public static void writeDoubleProp( ObjectOutputStream s, DoubleProperty doubleProp ) throws IOException 38 | { 39 | s.writeDouble( doubleProp.get() ); 40 | } 41 | 42 | public static void writeObjectProp( ObjectOutputStream s, Property prop ) throws IOException 43 | { 44 | s.writeObject( prop.getValue() ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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/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/main/graphs/VelGraphController.java: -------------------------------------------------------------------------------- 1 | package com.mammen.ui.javafx.main.graphs; 2 | 3 | import com.mammen.generator.generator_vars.SharedGeneratorVars; 4 | import com.mammen.generator.generator_vars.DriveBase; 5 | import com.mammen.main.MainUIModel; 6 | import com.mammen.path.Path; 7 | import com.mammen.generator.generator_vars.Units; 8 | import javafx.fxml.FXML; 9 | import javafx.scene.chart.LineChart; 10 | import javafx.scene.chart.NumberAxis; 11 | import javafx.scene.chart.XYChart; 12 | 13 | public class VelGraphController 14 | { 15 | @FXML 16 | private LineChart velGraph; 17 | 18 | @FXML 19 | private NumberAxis axisTime, axisVel; 20 | 21 | private MainUIModel backend; 22 | private SharedGeneratorVars sharedVars; 23 | 24 | 25 | /************************************************************************** 26 | * initialize 27 | * Setup gui stuff here. 28 | *************************************************************************/ 29 | @FXML public void initialize() 30 | { 31 | backend = MainUIModel.getInstance(); 32 | sharedVars = SharedGeneratorVars.getInstance(); 33 | 34 | // Watch this to know when a new path has been generated 35 | backend.pathProperty().addListener( ( o, oldValue, newValue ) -> 36 | { 37 | // Update graph when the path changes 38 | refresh(); 39 | }); 40 | 41 | // Update axis to reflect the new unit 42 | sharedVars.unitProperty().addListener( ( o, oldValue, newValue ) -> 43 | { 44 | updateAxis( newValue ); 45 | }); 46 | } 47 | 48 | 49 | private void updateAxis( Units units ) 50 | { 51 | switch( units ) 52 | { 53 | case FEET: 54 | axisVel.setLabel("Velocity (ft/s)"); 55 | break; 56 | 57 | case METERS: 58 | axisVel.setLabel("Velocity (m/s)"); 59 | break; 60 | 61 | case INCHES: 62 | axisVel.setLabel("Velocity (in/s)"); 63 | break; 64 | } 65 | } 66 | 67 | 68 | /** 69 | * Populates the graph with the newest path data. 70 | */ 71 | private void refresh() 72 | { 73 | XYChart.Series flSeries, frSeries, blSeries, brSeries; 74 | 75 | // Clear data from velocity graph 76 | velGraph.getData().clear(); 77 | 78 | if( backend.getNumWaypoints() > 1 ) 79 | { 80 | flSeries = buildSeries( backend.getPath().getFrontLeft() ); 81 | frSeries = buildSeries( backend.getPath().getFrontRight() ); 82 | 83 | velGraph.getData().addAll( flSeries, frSeries ); 84 | 85 | if( sharedVars.getDriveBase() == DriveBase.SWERVE ) 86 | { 87 | blSeries = buildSeries( backend.getPath().getBackLeft() ); 88 | brSeries = buildSeries( backend.getPath().getBackRight() ); 89 | 90 | velGraph.getData().addAll( blSeries, brSeries ); 91 | 92 | flSeries.setName("Front Left Trajectory"); 93 | frSeries.setName("Front Right Trajectory"); 94 | blSeries.setName("Back Left Trajectory"); 95 | brSeries.setName("Back Right Trajectory"); 96 | } 97 | else 98 | { 99 | flSeries.setName("Left Trajectory"); 100 | frSeries.setName("Right Trajectory"); 101 | } 102 | } 103 | } 104 | 105 | /** 106 | * Builds a series from the given trajectory that is ready to display on a LineChart. 107 | * @param segments Partial path to build a series for. 108 | * @return The created series to display. 109 | */ 110 | private static XYChart.Series buildSeries( Path.Segment[] segments ) 111 | { 112 | XYChart.Series series = new XYChart.Series<>(); 113 | 114 | if( segments != null ) 115 | { 116 | int i = 0; 117 | for( Path.Segment seg : segments ) 118 | { 119 | // Holds x, y data for a single entry in the series. 120 | XYChart.Data data = new XYChart.Data<>(); 121 | 122 | // Set the x, y data. 123 | data.setXValue( seg.dt * i ); 124 | data.setYValue( seg.velocity ); 125 | 126 | // Add the data to the series. 127 | series.getData().add( data ); 128 | 129 | i++; 130 | } 131 | } 132 | 133 | return series; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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_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/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 |