Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Display robot outline #99

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class CreateProjectController {
@FXML
private TextField wheelBase;
@FXML
private TextField robotWidth;
@FXML
private TextField robotLength;
@FXML
private ChoiceBox<Game> game;

@FXML
Expand Down Expand Up @@ -90,8 +94,10 @@ private void createProject() {
double accelerationMax = Double.parseDouble(maxAcceleration.getText());
double jerkMax = Double.parseDouble(maxJerk.getText());
double wheelBaseDistance = Double.parseDouble(wheelBase.getText());
double robotWidthValue = Double.parseDouble(robotWidth.getText());
double robotLengthValue = Double.parseDouble(robotLength.getText());
ProjectPreferences.Values values = new ProjectPreferences.Values(timeDelta, velocityMax, accelerationMax,
jerkMax, wheelBaseDistance, game.getValue());
jerkMax, wheelBaseDistance, robotWidthValue, robotLengthValue, game.getValue());
ProjectPreferences prefs = ProjectPreferences.getInstance(directory.getAbsolutePath());
prefs.setValues(values);
FxUtils.loadMainScreen(vBox.getScene(), getClass());
Expand Down Expand Up @@ -124,5 +130,7 @@ private void setupEditProject() {
maxAcceleration.setText(String.valueOf(values.getMaxAcceleration()));
maxJerk.setText(String.valueOf(values.getMaxJerk()));
wheelBase.setText(String.valueOf(values.getWheelBase()));
robotWidth.setText(String.valueOf(values.getRobotWidth()));
robotLength.setText(String.valueOf(values.getRobotLength()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PathDisplayController {

private final double circleScale = .75; //NOPMD should be static, will be modified later
private final double splineScale = 6; //NOPMD should be static, will be modified later
private final double lineScale = 4; //NOPMD should be static, will be modified later
private final double lineScale = 2; //NOPMD should be static, will be modified later

@FXML
private Group splineGroup;
Expand Down Expand Up @@ -142,21 +142,25 @@ private void addPathToPane(Path newPath) {
*/
public void addWaypointToPane(Waypoint current) {
waypointGroup.getChildren().add(current.getIcon());
waypointGroup.getChildren().add(current.getRobotOutline());
vectorGroup.getChildren().add(current.getTangentLine());
current.getIcon().setScaleX(circleScale / field.getScale());
current.getIcon().setScaleY(circleScale / field.getScale());
current.getIcon().toFront();
current.getRobotOutline().getStyleClass().add("robotOutline");
current.getRobotOutline().setStrokeWidth(lineScale / field.getScale());
current.getTangentLine().setStrokeWidth(lineScale / field.getScale());
current.getTangentLine().toBack();
current.getTangentLine().toFront();
current.getSpline().addToGroup(splineGroup, splineScale / field.getScale());
}


private void removePathFromPane(Path newPath) {
for (Waypoint wp : newPath.getWaypoints()) {
wp.getSpline().removeFromGroup(splineGroup);
}
for (Waypoint wp : newPath.getWaypoints()) {
waypointGroup.getChildren().remove(wp.getIcon());
waypointGroup.getChildren().remove(wp.getRobotOutline());
vectorGroup.getChildren().remove(wp.getTangentLine());
}
}
Expand Down Expand Up @@ -225,6 +229,7 @@ private void delete(Waypoint waypoint) {
Path path = waypoint.getPath();
Waypoint previous = path.getWaypoints().get(path.getWaypoints().indexOf(waypoint) - 1);
waypointGroup.getChildren().remove(waypoint.getIcon());
waypointGroup.getChildren().remove(waypoint.getRobotOutline());
vectorGroup.getChildren().remove(waypoint.getTangentLine());
waypoint.getSpline().removeFromGroup(splineGroup);
path.remove(waypoint);
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/edu/wpi/first/pathweaver/ProjectPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private ProjectPreferences(String directory) {
}

private void setDefaults() {
values = new Values(0.2, 10.0, 60.0, 60.0, 2.0, Game.POWER_UP_2018);
values = new Values(0.2, 10.0, 60.0, 60.0, 2.0, 28.0, 38.0, Game.POWER_UP_2018);
updateValues();
}

Expand All @@ -62,6 +62,14 @@ public void setValues(Values values) {
updateValues();
}

/**
* Gets the preferences for the current project.
* @return the preference values for this project.
*/
public Values getValues() {
return values;
}

public String getDirectory() {
return directory;
}
Expand Down Expand Up @@ -115,16 +123,14 @@ public Field getField() {
}
}

public Values getValues() {
return values;
}

public static class Values {
private final double timeStep;
private final double maxVelocity;
private final double maxAcceleration;
private final double maxJerk;
private final double wheelBase;
private final double robotWidth;
private final double robotLength;
private Game game;

/**
Expand All @@ -134,15 +140,19 @@ public static class Values {
* @param maxAcceleration The maximum acceleration to use
* @param maxJerk The maximum jerk (acceleration per second) to use
* @param wheelBase The width between the individual sides of the drivebase
* @param robotWidth The width of the robot (in inches)
* @param robotLength The length of the robot (in inches)
* @param game The year/FRC game
*/
public Values(double timeStep, double maxVelocity, double maxAcceleration, double maxJerk,
double wheelBase, Game game) {
double wheelBase, double robotWidth, double robotLength, Game game) {
this.timeStep = timeStep;
this.maxVelocity = maxVelocity;
this.maxAcceleration = maxAcceleration;
this.maxJerk = maxJerk;
this.wheelBase = wheelBase;
this.robotWidth = robotWidth;
this.robotLength = robotLength;
this.game = game;
}

Expand All @@ -166,6 +176,14 @@ public double getWheelBase() {
return wheelBase;
}

public double getRobotWidth() {
return robotWidth;
}

public double getRobotLength() {
return robotLength;
}

public Game getGame() {
return game;
}
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/edu/wpi/first/pathweaver/Waypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javafx.scene.input.TransferMode;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;

@SuppressWarnings("PMD.TooManyMethods")
public class Waypoint {
Expand All @@ -30,7 +31,7 @@ public class Waypoint {
private Path path;
public static Waypoint currentWaypoint = null;


private final Rectangle robotOutline;
private final Line tangentLine;
private Polygon icon;

Expand All @@ -52,6 +53,7 @@ public void setPath(Path path) {
* @param fixedAngle If the angle the of the waypoint should be fixed. Used for first and last waypoint
* @param myPath the path this waypoint belongs to
*/
@SuppressWarnings("PMD.NcssCount")
public Waypoint(Point2D position, Point2D tangentVector, boolean fixedAngle, Path myPath) {
path = myPath;
lockTangent.set(fixedAngle);
Expand All @@ -62,6 +64,8 @@ public Waypoint(Point2D position, Point2D tangentVector, boolean fixedAngle, Pat
x.addListener(listener -> update());
y.addListener(listener -> update());

ProjectPreferences.Values values = ProjectPreferences.getInstance().getValues();

tangentLine = new Line();
tangentLine.getStyleClass().add("tangent");
tangentLine.startXProperty().bind(x);
Expand All @@ -70,6 +74,19 @@ public Waypoint(Point2D position, Point2D tangentVector, boolean fixedAngle, Pat
tangentLine.endXProperty().bind(Bindings.createObjectBinding(() -> getTangent().getX() + getX(), tangentX, x));
tangentLine.endYProperty().bind(Bindings.createObjectBinding(() -> getTangent().getY() + getY(), tangentY, y));

double robotWidth = values.getRobotWidth();
double robotLength = values.getRobotLength();

robotOutline = new Rectangle();
robotOutline.setHeight(robotWidth);
robotOutline.setWidth(robotLength);
robotOutline.xProperty().bind(x.subtract(robotLength / 2));
robotOutline.yProperty().bind(y.subtract(robotWidth / 2));
robotOutline.rotateProperty().bind(
Bindings.createObjectBinding(() ->
getTangent() == null ? 0.0 : Math.toDegrees(Math.atan2(getTangent().getY(), getTangent().getX())),
tangentX, tangentY));

this.spline = new NullSpline();

setupDnd();
Expand Down Expand Up @@ -182,6 +199,10 @@ public void setTangent(Point2D tangent) {
this.tangentY.set(tangent.getY());
}

public Rectangle getRobotOutline() {
return robotOutline;
}

public Polygon getIcon() {
return icon;
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/edu/wpi/first/pathweaver/createProject.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox fx:id="vBox" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="360.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.wpi.first.pathweaver.CreateProjectController">
<VBox fx:id="vBox" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.wpi.first.pathweaver.CreateProjectController">
<children>
<Label fx:id="title" text="Create Project...">
<font>
Expand All @@ -34,6 +34,8 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="20.0" left="40.0" right="40.0" top="10.0" />
Expand All @@ -45,6 +47,8 @@
<Label text="Max Acceleration" GridPane.rowIndex="4" />
<Label text="Max Jerk" GridPane.rowIndex="5" />
<Label text="Wheel Base" GridPane.rowIndex="6" />
<Label text="Robot Width" GridPane.rowIndex="7" />
<Label text="Robot Length" GridPane.rowIndex="8" />
<TextField fx:id="directory" editable="false" GridPane.columnIndex="1" />
<Button fx:id="browse" mnemonicParsing="false" onAction="#browseDirectory" text="Browse" GridPane.columnIndex="2" />
<ChoiceBox fx:id="game" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
Expand All @@ -53,12 +57,16 @@
<TextField fx:id="maxAcceleration" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField fx:id="maxJerk" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<TextField fx:id="wheelBase" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<TextField fx:id="robotWidth" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<TextField fx:id="robotLength" GridPane.columnIndex="1" GridPane.rowIndex="8" />
<Label text="Time delta between points (seconds)" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label text="Maximum capable velocity of robot (ft/s)" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<Label text="Maximum acceleration (ft/s/s)" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<Label text="Maximum jerk (acceleration per second) (ft/s/s/s)" GridPane.columnIndex="2" GridPane.rowIndex="5" />
<Label text="Distance between left and right of wheel base (ft)" GridPane.columnIndex="2" GridPane.rowIndex="6" />
<ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="7">
<Label text="Width of the robot (ft)" GridPane.columnIndex="2" GridPane.rowIndex="7" />
<Label text="Length of the robot (ft)" GridPane.columnIndex="2" GridPane.rowIndex="8" />
<ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="9">
<buttons>
<Button mnemonicParsing="false" onAction="#cancel" text="Cancel" />
<Button fx:id="create" mnemonicParsing="false" onAction="#createProject" text="Create Project" />
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/edu/wpi/first/pathweaver/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@
}

.path {
-fx-stroke-line-cap: round;
-fx-stroke-line-cap: butt;
-fx-fill: null;
-fx-cursor: hand;
-fx-stroke: derive(my-color, -25%);
}

.robotOutline {
-fx-fill: null;
-fx-stroke: "lightgray";
}

.tank {
-fx-opacity: 0.7;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="360.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.wpi.first.pathweaver.WelcomeController">
<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.wpi.first.pathweaver.WelcomeController">
<opaqueInsets>
<Insets />
</opaqueInsets>
Expand Down