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 {
* speed. Does not alter the current position-vector instance. Does not
* 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
* only used in movement models, its functionality might be better implemented
* there...
* only used in movement models, its functionality might be better
* implemented there...
*
* @param destination
* @param speed
* @return
*/
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);
direction.subtract(this);
direction.normalize();
......
......@@ -60,9 +60,13 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
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() {
this.worldDimensions = Topology.getWorldDimension();
latLeft = GPSCalculation.getLatLower();
......@@ -124,7 +128,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
PositionVector nextPoint = transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon());
newPosition = comp.getRealPosition().moveStep(nextPoint, getMovementSpeed(comp));
if(nextPoint.distanceTo(comp.getRealPosition()) < maxDistanceNextPoint) actualIndex++;
if (nextPoint
.distanceTo(comp.getRealPosition()) < tolerance) {
actualIndex++;
}
}
i++;
}
......@@ -175,7 +182,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
this.navigationalType = navigationalType;
}
public void setMaxDistanceNextPoint(double maxDistanceNextPoint) {
this.maxDistanceNextPoint = maxDistanceNextPoint;
public void setWaypointTolerance(double tolerance) {
this.tolerance = tolerance;
}
}
......@@ -20,8 +20,14 @@
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;
/**
*
* @author Martin Hellwig
* @version 1.0, Nov 3, 2015
*/
public class GPSCalculation {
private static double latCenter;
......@@ -35,9 +41,9 @@ public class GPSCalculation {
private void setScaleFactor() {
//this.scaleFactor = Math.pow(2.0d, (13 - zoom));
/*
* BR: set scaleFactor to fixed zoom level 15 (as in this case, 1px ==
* 1m) - this way, the world-size specified in the configs is valid on
* all zoom levels.
* BR: set scaleFactor to fixed zoom level 15 ==> 0.125 (as in this
* case, 1px == 1m) - this way, the world-size specified in the configs
* is valid on all zoom levels.
*/
this.scaleFactor = 0.125;
// 17: 2, 16: 1, 15: 0.5, 14: 0.25
......@@ -57,19 +63,23 @@ public class GPSCalculation {
}
public static double getLatUpper() {
return latCenter + scaleFactor*0.027613;
return latCenter + scaleFactor * 0.027613
* Topology.getWorldDimension().getX() / 1000;
}
public static double getLatLower() {
return latCenter - scaleFactor*0.027613;
return latCenter - scaleFactor * 0.027613
* Topology.getWorldDimension().getX() / 1000;
}
public static double getLonLeft() {
return lonCenter - scaleFactor*0.0419232;
return lonCenter - scaleFactor * 0.0419232
* Topology.getWorldDimension().getY() / 1000;
}
public static double getLonRight() {
return lonCenter + scaleFactor*0.0419232;
return lonCenter + scaleFactor * 0.0419232
* Topology.getWorldDimension().getY() / 1000;
}
public void setLatCenter(double latCenter) {
......
......@@ -144,7 +144,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
@Override
public Map<MovementSupported, AttractionPoint> getAssignments() {
return new HashMap<MovementSupported, AttractionPoint>(assignments);
// FIXME why new? return new HashMap<MovementSupported,
// AttractionPoint>(assignments);
return assignments;
}
@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