Commit 94d7be9a authored by Julian Zobel's avatar Julian Zobel
Browse files

Abstract Topology Component now informs location listeners only when a certain...

Abstract Topology Component now informs location listeners only when a certain location offset is reached
ControllableLocationActurator extends LocationSensor interface to provide location update requests
parent 742d2883
......@@ -22,9 +22,8 @@ package de.tud.kom.p2psim.api.topology.component;
import java.util.LinkedList;
import de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent;
import de.tud.kom.p2psim.impl.topology.placement.UAVBasePlacement;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationSensor;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.Actuator;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
......@@ -39,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocation
* @author Julian Zobel
*
*/
public interface ControllableLocationActuator extends Actuator {
public interface ControllableLocationActuator extends Actuator, LocationSensor {
public boolean isActive();
......
......@@ -65,6 +65,7 @@ public abstract class AbstractTopologyComponent implements TopologyComponent {
protected SimHost host;
protected final PositionVector position;
protected final Double POSITION_REQUEST_UPDATE_ACCURACY = 0.1; // accuracy for location request updates
protected Topology topology;
protected MovementModel movementModel;
......@@ -224,12 +225,21 @@ public abstract class AbstractTopologyComponent implements TopologyComponent {
}
@Override
public void updateCurrentLocation(Location location) {
position.set(location);
public void updateCurrentLocation(Location location) {
for (LocationListener locationListener : listeners) {
locationListener.onLocationChanged(getHost(), getLastLocation());
boolean informListeners = false;
// only inform listeners if the location has changed
if(location.distanceTo(position) >= POSITION_REQUEST_UPDATE_ACCURACY) {
informListeners = true;
}
position.set(location);
if(informListeners) {
for (LocationListener locationListener : listeners) {
locationListener.onLocationChanged(getHost(), getLastLocation());
}
}
}
@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