Fix for wakes on internal data

#bug
This commit is contained in:
Calum
2017-05-04 13:20:50 +12:00
parent c7b6261602
commit fd8ed92f88
4 changed files with 69 additions and 10 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ public class App extends Application
} }
//Change the StreamReceiver in this else block to change the default data source. //Change the StreamReceiver in this else block to change the default data source.
else{ else{
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); sr = new StreamReceiver("localhost", 8085, "RaceStream");
} }
sr.start(); sr.start();
+3 -2
View File
@@ -214,18 +214,19 @@ public class BoatGroup extends RaceObject{
pixelVelocityY = dy / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval;
rotationalGoal = rotation; rotationalGoal = rotation;
calculateRotationalVelocity(); calculateRotationalVelocity();
if (wakeGenerationDelay > 0) { if (wakeGenerationDelay > 0) {
wake.rotate(rotationalGoal); wake.rotate(rotationalGoal);
rotateTo(rotationalGoal); //Need to test with this removed. rotateTo(rotationalGoal); //Need to test with this removed.
rotationalVelocity = 0; rotationalVelocity = 0;
wakeGenerationDelay--; wakeGenerationDelay--;
} else { } else {
wake.setRotationalVelocity(rotationalVelocity, currentRotation, boat.getVelocity()); wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity());
} }
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
} else { } else {
setToInitialLocation = true; setToInitialLocation = true;
rotationalGoal = rotation;; rotationalGoal = rotation;
moveTo(newXValue, newYValue, rotation); moveTo(newXValue, newYValue, rotation);
} }
} }
+4 -3
View File
@@ -54,14 +54,15 @@ class Wake extends Group {
void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocity) { void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocity) {
sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]); sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]);
sum += Math.abs(rotationalVelocity); sum += Math.abs(rotationalVelocity);
// System.out.println("sum = " + sum);
max = Math.max(max, rotationalVelocity); max = Math.max(max, rotationalVelocity);
// System.out.println("max = " + max);
if (sum < (max / 3)) if (sum < (max / 3))
rotate (rotationGoal); //In relatively straight segments the wake snaps to match the boats current position. rotate (rotationGoal); //In relatively straight segments the wake snaps to match the boats current position.
//This stops the wake from eventually becoming out of sync with the boat. //This stops the wake from eventually becoming out of sync with the boat.
if (Math.abs(rotationalVelocity) > 0.5) { //This accounts for rogue rotations that are greater than what would be realistic. Value is kinda rough.
//Basically just for our internal mock.
if (Math.abs(rotationalVelocity) > 0.05) {
rotationalVelocity = 0; rotationalVelocity = 0;
rotate(rotationGoal);
} }
//Update the index of the array of recent velocities that each wake uses. Each wake is 3 velocities behind the //Update the index of the array of recent velocities that each wake uses. Each wake is 3 velocities behind the
//next smallest wake. //next smallest wake.
@@ -51,14 +51,71 @@ public class MarkGroupTest {
} }
@Test @Test
public void correctMovementCorrectId () { public void correctMovementCorrectIdSingle () {
double originalX = singleMG.getChildren().get(0).getLayoutX(); double originalX = singleMG.getChildren().get(0).getLayoutX();
double originalY = singleMG.getChildren().get(0).getLayoutY(); double originalY = singleMG.getChildren().get(0).getLayoutY();
long timeinterval = 100/60; long timeinterval = 1000/60;
double expectedChange = 10 / 200 * timeinterval; double expectedChange = 10 / 200 * timeinterval;
singleMG.setDestination(originalX + 10, originalY + 10, 0, 0); singleMG.setDestination(originalX + 10, originalY + 10, 0, 0);
singleMG.updatePosition(timeinterval); singleMG.updatePosition(timeinterval);
Assert.assertTrue(originalX == singleMG.getChildren().get(0).getLayoutX()); Assert.assertTrue(originalX + expectedChange == singleMG.getChildren().get(0).getLayoutX());
Assert.assertTrue(originalY == singleMG.getChildren().get(0).getLayoutY()); Assert.assertTrue(originalY + expectedChange == singleMG.getChildren().get(0).getLayoutY());
}
@Test
public void correctMovementCorrectIDGate () {
double originalX1 = gateMG.getChildren().get(0).getLayoutX();
double originalY1 = gateMG.getChildren().get(0).getLayoutY();
double originalX2 = gateMG.getChildren().get(1).getLayoutX();
double originalY2 = gateMG.getChildren().get(1).getLayoutY();
long timeinterval = 1000/60;
double expectedChange = 10 / 200 * timeinterval;
gateMG.setDestination(originalX1 + 10, originalY1 + 10, 0, 1);
gateMG.setDestination(originalX2 + 10, originalY2 + 10, 0, 2);
gateMG.updatePosition(timeinterval);
Assert.assertTrue(originalX1 + expectedChange == gateMG.getChildren().get(0).getLayoutX());
Assert.assertTrue(originalY1 + expectedChange == gateMG.getChildren().get(0).getLayoutY());
Assert.assertTrue(originalX2 + expectedChange == gateMG.getChildren().get(1).getLayoutX());
Assert.assertTrue(originalY2 + expectedChange == gateMG.getChildren().get(1).getLayoutY());
}
@Test
public void correctMovementCorrectIDGateBothIDS () {
double originalX1 = gateMG.getChildren().get(0).getLayoutX();
double originalY1 = gateMG.getChildren().get(0).getLayoutY();
double originalX2 = gateMG.getChildren().get(1).getLayoutX();
double originalY2 = gateMG.getChildren().get(1).getLayoutY();
long timeinterval = 1000/60;
double expectedChange = 10 / 200 * timeinterval;
gateMG.setDestination(originalX1 + 10, originalY1 + 10, 0, 1, 2);
gateMG.updatePosition(timeinterval);
Assert.assertTrue(originalX1 + expectedChange == gateMG.getChildren().get(0).getLayoutX());
Assert.assertTrue(originalY1 + expectedChange == gateMG.getChildren().get(0).getLayoutY());
Assert.assertTrue(originalX2 + expectedChange == gateMG.getChildren().get(1).getLayoutX());
Assert.assertTrue(originalY2 + expectedChange == gateMG.getChildren().get(1).getLayoutY());
}
// @Test
// public void correctMovementOneCorrectIDGateBothIDS () {
// double originalX1 = gateMG.getChildren().get(0).getLayoutX();
// double originalY1 = gateMG.getChildren().get(0).getLayoutY();
// double originalX2 = gateMG.getChildren().get(1).getLayoutX();
// double originalY2 = gateMG.getChildren().get(1).getLayoutY();
// long timeinterval = 1000/60;
// double expectedChange = 10 / 200 * timeinterval;
// gateMG.setDestination(originalX1 + 10, originalY1 + 10, 0, 1, 3);
// gateMG.updatePosition(timeinterval);
// System.out.println("gateMG.getChildren().get(1).getLayoutX() = " + gateMG.getChildren().get(1).getLayoutX());
// System.out.println("gateMG.getChildren().get(0).getLayoutX() = " + gateMG.getChildren().get(0).getLayoutX());
// Assert.assertTrue(originalX1 + expectedChange == gateMG.getChildren().get(0).getLayoutX());
// Assert.assertTrue(originalY1 + expectedChange == gateMG.getChildren().get(0).getLayoutY());
// Assert.assertTrue(originalX2 + expectedChange != gateMG.getChildren().get(1).getLayoutX());
// Assert.assertTrue(originalY2 + expectedChange != gateMG.getChildren().get(1).getLayoutY());
// }
@Test
public void lineUpdatesCorrectly () {
} }
} }