Commit 27cb8f2e authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Fixed overshooting in PositionVector

- Prior, moving at a certain speed towards a target position could lead
to overshooting and, thus, to oscillations.
parent 740ed390
...@@ -424,15 +424,28 @@ public class PositionVector implements Position, Location { ...@@ -424,15 +424,28 @@ public class PositionVector implements Position, Location {
* speed. Does not alter the current position-vector instance. Does not * speed. Does not alter the current position-vector instance. Does not
* alter the destination vector instance. * alter the destination vector instance.
* *
* IFF the speed would lead to us overshooting the destination, we will just
* move right onto the destination instead. This prevents oscillations in
* movement models.
*
* FIXME BR: this method signature and purpose is not well defined. As it is * FIXME BR: this method signature and purpose is not well defined. As it is
* only used in movement models, its functionality might be better implemented * only used in movement models, its functionality might be better
* there... * implemented there...
* *
* @param destination * @param destination
* @param speed * @param speed
* @return * @return
*/ */
public PositionVector moveStep(PositionVector destination, double speed) { public PositionVector moveStep(PositionVector destination, double speed) {
double distance = destination.distanceTo(this);
if (distance < speed) {
/*
* We would overshoot the target.
*/
return new PositionVector(destination);
}
PositionVector direction = new PositionVector(destination); PositionVector direction = new PositionVector(destination);
direction.subtract(this); direction.subtract(this);
direction.normalize(); direction.normalize();
......
...@@ -60,9 +60,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -60,9 +60,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private double latRight; //Values from -90 to 90 private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180 private double lonRight; //Values from -180 to 180
private double maxDistanceNextPoint; //This defines the maximum distance to the next point in line;
//if the distance is smaller than the given one, the node will choose the next point in the list
/**
* Tolerance in meters (if the node reached a waypoint up to "tolerance"
* meters, it will select the next waypoint in the path.
*/
private double tolerance = 1;
public RealWorldStreetsMovement() { public RealWorldStreetsMovement() {
this.worldDimensions = Topology.getWorldDimension(); this.worldDimensions = Topology.getWorldDimension();
latLeft = GPSCalculation.getLatLower(); latLeft = GPSCalculation.getLatLower();
...@@ -124,7 +128,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -124,7 +128,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
PositionVector nextPoint = transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon()); PositionVector nextPoint = transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon());
newPosition = comp.getRealPosition().moveStep(nextPoint, getMovementSpeed(comp)); newPosition = comp.getRealPosition().moveStep(nextPoint, getMovementSpeed(comp));
if(nextPoint.distanceTo(comp.getRealPosition()) < maxDistanceNextPoint) actualIndex++; if (nextPoint
.distanceTo(comp.getRealPosition()) < tolerance) {
actualIndex++;
}
} }
i++; i++;
} }
...@@ -175,7 +182,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -175,7 +182,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
this.navigationalType = navigationalType; this.navigationalType = navigationalType;
} }
public void setMaxDistanceNextPoint(double maxDistanceNextPoint) { public void setWaypointTolerance(double tolerance) {
this.maxDistanceNextPoint = maxDistanceNextPoint; this.tolerance = tolerance;
} }
} }
...@@ -20,8 +20,14 @@ ...@@ -20,8 +20,14 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm; package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import de.tud.kom.p2psim.impl.topology.Topology;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
/**
*
* @author Martin Hellwig
* @version 1.0, Nov 3, 2015
*/
public class GPSCalculation { public class GPSCalculation {
private static double latCenter; private static double latCenter;
...@@ -35,9 +41,9 @@ public class GPSCalculation { ...@@ -35,9 +41,9 @@ public class GPSCalculation {
private void setScaleFactor() { private void setScaleFactor() {
//this.scaleFactor = Math.pow(2.0d, (13 - zoom)); //this.scaleFactor = Math.pow(2.0d, (13 - zoom));
/* /*
* BR: set scaleFactor to fixed zoom level 15 (as in this case, 1px == * BR: set scaleFactor to fixed zoom level 15 ==> 0.125 (as in this
* 1m) - this way, the world-size specified in the configs is valid on * case, 1px == 1m) - this way, the world-size specified in the configs
* all zoom levels. * is valid on all zoom levels.
*/ */
this.scaleFactor = 0.125; this.scaleFactor = 0.125;
// 17: 2, 16: 1, 15: 0.5, 14: 0.25 // 17: 2, 16: 1, 15: 0.5, 14: 0.25
...@@ -57,19 +63,23 @@ public class GPSCalculation { ...@@ -57,19 +63,23 @@ public class GPSCalculation {
} }
public static double getLatUpper() { public static double getLatUpper() {
return latCenter + scaleFactor*0.027613; return latCenter + scaleFactor * 0.027613
* Topology.getWorldDimension().getX() / 1000;
} }
public static double getLatLower() { public static double getLatLower() {
return latCenter - scaleFactor*0.027613; return latCenter - scaleFactor * 0.027613
* Topology.getWorldDimension().getX() / 1000;
} }
public static double getLonLeft() { public static double getLonLeft() {
return lonCenter - scaleFactor*0.0419232; return lonCenter - scaleFactor * 0.0419232
* Topology.getWorldDimension().getY() / 1000;
} }
public static double getLonRight() { public static double getLonRight() {
return lonCenter + scaleFactor*0.0419232; return lonCenter + scaleFactor * 0.0419232
* Topology.getWorldDimension().getY() / 1000;
} }
public void setLatCenter(double latCenter) { public void setLatCenter(double latCenter) {
......
...@@ -144,7 +144,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -144,7 +144,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
@Override @Override
public Map<MovementSupported, AttractionPoint> getAssignments() { public Map<MovementSupported, AttractionPoint> getAssignments() {
return new HashMap<MovementSupported, AttractionPoint>(assignments); // FIXME why new? return new HashMap<MovementSupported,
// AttractionPoint>(assignments);
return assignments;
} }
@Override @Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment