Commit 179aa249 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Bugfixes and additions.

UAV Topology and UAV Movement.
parent c9ab26ed
......@@ -25,4 +25,5 @@ package de.tud.kom.p2psim.api.topology.movement;
public interface UAVLocationActuator extends SimLocationActuator {
public UAVMovementModel getUAVMovement();
public void setUAVMovement(UAVMovementModel uavMovement);
}
......@@ -37,7 +37,6 @@ import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest;
......@@ -53,6 +52,13 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.util.SiSTopologyProvid
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName;
/**
* Abstract implementation of the topology component interface, to support basic
* functionalities to all topology components.
*
* @author Julian Zobel
* @version 1.0, 6 Sep 2018
*/
public abstract class AbstractTopologyComponent implements TopologyComponent {
protected SimHost host;
......@@ -67,6 +73,7 @@ public abstract class AbstractTopologyComponent implements TopologyComponent {
private Map<LocationListener, LocationRequestImpl> openRequests = new LinkedHashMap<LocationListener, LocationRequestImpl>();
private List<LocationListener> listeners = new LinkedList<>();
//
public AbstractTopologyComponent(SimHost host, Topology topology, MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
this.topology = topology;
this.host = host;
......@@ -203,7 +210,7 @@ public abstract class AbstractTopologyComponent implements TopologyComponent {
}
@Override
public Location getLastLocation() {
public Location getLastLocation() {
/*
* As we want to mimic real world behavior, the current position
* snapshot is cloned to prevent information propagation due to Java.
......
......@@ -39,18 +39,18 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
*
* CHANGELOG
*
* - 14/08/08 Bjoern Richerzhagen: removed a number of unused, uncommented, and
* - 14.08.2008 Bjoern Richerzhagen: removed a number of unused, uncommented, and
* dubious methods from this class. Fixed the replace-bug (discovered by Nils)
* with little overhead. Implemented assertions with assertions - previous
* method introduces unwanted overhead outside of development settings. Removed
* the dubious equals-tolerance, which violates the hashCode contract. Seriously
* guys...
*
* - 05/09/18 Julian Zobel: Added location support for third dimension (altitude)
* - 05.09.2018 Julian Zobel: Added location support for third dimension (altitude)
* and removed a bug in the moveStep() function.
*
* @author Bjoern Richerzhagen
* @version 1.0, 04/25/2011
* @author Bjoern Richerzhagen, Julian Zobel
* @version 1.1, 06.09.2018
*/
public class PositionVector implements Location {
......@@ -61,7 +61,7 @@ public class PositionVector implements Location {
* transforms can be performed in the getter-methods.
*/
private double[] values;
private double accuracy = -1;
/**
......@@ -78,10 +78,11 @@ public class PositionVector implements Location {
}
/**
* Clone a PositionVector
* Constructors for position vectors, also usable for cloning.
*
* @param vec
*/
public PositionVector(PositionVector vec) {
this(vec.getDimensions());
for (int i = 0; i < vec.getDimensions(); i++) {
......@@ -115,7 +116,7 @@ public class PositionVector implements Location {
this.setLatitudeOrY(location.getLatitudeOrY());
this.setLongitudeOrX(location.getLongitudeOrX());
}
}
/**
* Convenience Constructor, initializes a Vector with values.length
......@@ -130,6 +131,19 @@ public class PositionVector implements Location {
}
}
@Override
public PositionVector clone() {
/*
* If you extend Position Vector, make sure to overwrite this method!
*/
return new PositionVector(this); // use clone constructor
}
/*
*
*
*/
@Override
public void setLatitudeOrY(double latitudeOrY)
throws UnsupportedOperationException {
......@@ -361,22 +375,10 @@ public class PositionVector implements Location {
}
@Override
public String toString() {
return "PV [" + Arrays.toString(values) + "]";
public String toString() {
return "PV " + Arrays.toString(values) + "";
}
@Override
public PositionVector clone() {
/*
* If you extend Position Vector, make sure to overwrite this method!
*/
return new PositionVector(this); // use clone constructor
}
@Override
public int hashCode() {
final int prime = 31;
......
......@@ -51,8 +51,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* This factory is configured with one or more {@link TopologyView}s if the
* {@link LinkLayer} is used.
*
* @author Bjoern Richerzhagen
* @version 1.0, 01.03.2012
* @author Bjoern Richerzhagen, Julian Zobel
* @version 1.1, 06.09.2018
*/
public class TopologyFactory implements HostComponentFactory {
......@@ -85,13 +85,15 @@ public class TopologyFactory implements HostComponentFactory {
private boolean alreadyCreatedInstances = false;
private boolean alreadyAddedMovement = false;
private boolean isUAVComponent = false;
/**
*
*/
@XMLConfigurableConstructor({ "worldX", "worldY" })
public TopologyFactory(double worldX, double worldY) {
topo = new DefaultTopology(new PositionVector(worldX, worldY));
topo = new DefaultTopology(new PositionVector(worldX, worldY));
// Make the topology component available globally
Binder.registerComponent(topo);
}
......@@ -126,9 +128,20 @@ public class TopologyFactory implements HostComponentFactory {
* Create a TopologyComponent and register it with the Topology and its
* movement model.
*/
TopologyComponent toCo = new DefaultTopologyComponent(host, topo,
movement, placement, registerAsInformationProviderInSiS);
TopologyComponent toCo;
/*
* Choose the UAV topology component, if this host is part of the UAV group!
*
*/
if(isUAVComponent) {
toCo = new UAVTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
else {
toCo = new DefaultTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
/*
* Need to register TopoViews as movement listeners, as they might need
* to update topologies after each movement.
......@@ -271,4 +284,8 @@ public class TopologyFactory implements HostComponentFactory {
public ObstacleModel getObstacleModel() {
return obstacleModel;
}
public void setIsUAVComponent(boolean uav) {
this.isUAVComponent = uav;
}
}
......@@ -28,13 +28,21 @@ import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.UAVLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.movement.aerial.MutlicopterMovement;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/**
* Topology component used for UAVs.
*
* @author Julian Zobel
* @version 1.0, 06.09.2018
*/
public class UAVTopologyComponent extends AbstractTopologyComponent implements UAVLocationActuator {
UAVMovementModel movement;
OverlayComponent uavOverlayComponent;
/**
* Create a TopologyComponent for the current host.
*
......@@ -50,26 +58,22 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements U
@Override
public double getMinMovementSpeed() {
// TODO Auto-generated method stub
return 0;
return movement.getMinCruiseSpeed();
}
@Override
public double getMaxMovementSpeed() {
// TODO Auto-generated method stub
return 0;
return movement.getMaxCruiseSpeed();
}
@Override
public double getMovementSpeed() {
// TODO Auto-generated method stub
return 0;
return movement.getCurrentSpeed();
}
@Override
public void setMovementSpeed(double speed) {
// TODO Auto-generated method stub
movement.setPreferredCruiseSpeed(speed);
}
@Override
......@@ -98,6 +102,23 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements U
}
@Override
public void setUAVMovement(UAVMovementModel uavMovement) {
this.movement = uavMovement;
}
public void setUAVComponent(OverlayComponent uavOverlayComponent) {
this.uavOverlayComponent = uavOverlayComponent;
}
public OverlayComponent getUAVComponent() {
return uavOverlayComponent;
}
......
......@@ -20,18 +20,12 @@
package de.tud.kom.p2psim.impl.topology.movement;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -41,8 +35,6 @@ import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/**
* Unified movement Models. Can be used inside an Application (virtual Position)
......@@ -98,7 +90,7 @@ public abstract class AbstractMovementModel implements MovementModel {
public void addComponent(SimLocationActuator component) {
if (worldDimensions == null) {
worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
.getWorldDimensions();
}
components.add(component);
}
......@@ -156,7 +148,9 @@ public abstract class AbstractMovementModel implements MovementModel {
* @return
*/
protected boolean isValidPosition(PositionVector vector) {
for (int i = 0; i < vector.getDimensions(); i++) {
if (vector.getEntry(i) > getWorldDimension(i)
|| vector.getEntry(i) < 0) {
return false;
......
......@@ -25,7 +25,6 @@ import java.util.Random;
import java.util.Set;
import java.util.WeakHashMap;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
......@@ -41,8 +40,6 @@ import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
......
......@@ -28,8 +28,11 @@ import de.tud.kom.p2psim.impl.topology.PositionVector;
/**
* Mainly for testing: random movement
*
* @author Bjoern Richerzhagen, adapted from ido.MoveModels
* @version 1.0, mm/dd/2011
* Update (JZ): Added position validation, such that the newly calculated positions do not
* exceed the simulation boundaries.
*
* @author Bjoern Richerzhagen, adapted from ido.MoveModels; Julian Zobel
* @version 1.1, 09.2018
*/
public class RandomMovement extends AbstractMovementModel {
......@@ -39,16 +42,22 @@ public class RandomMovement extends AbstractMovementModel {
@Override
public void move() {
Set<SimLocationActuator> comps = getComponents();
for (SimLocationActuator comp : comps) {
for (SimLocationActuator comp : comps) {
PositionVector pos = comp.getRealPosition();
updatePosition(comp, pos.plus(getRandomDeltaWithinSpeed(pos, comp.getMinMovementSpeed(),
comp.getMaxMovementSpeed())));
PositionVector newPos;
do {
newPos = pos.plus(getRandomDeltaWithinSpeed(pos, comp.getMinMovementSpeed(),
comp.getMaxMovementSpeed()));
}
while(!isValidPosition(newPos));
updatePosition(comp, newPos);
}
}
}
......@@ -25,12 +25,15 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.UAVTopologyComponent;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class MutlicopterMovement implements UAVMovementModel {
UAVTopologyComponent topologyComponent;
private UAVTopologyComponent topologyComponent;
private final double maxCruiseSpeed;
private final double minCruiseSpeed;
......@@ -41,7 +44,8 @@ public class MutlicopterMovement implements UAVMovementModel {
private Map<Location, ?> locationCallbacks = new HashMap<>(); // TODO callback interface
public MutlicopterMovement(double maxCruiseSpeed, double minCruiseSpeed) {
public MutlicopterMovement(UAVTopologyComponent topologyComponent, double maxCruiseSpeed, double minCruiseSpeed) {
this.topologyComponent = topologyComponent;
this.maxCruiseSpeed = maxCruiseSpeed;
this.minCruiseSpeed = minCruiseSpeed;
}
......@@ -69,7 +73,9 @@ public class MutlicopterMovement implements UAVMovementModel {
@Override
public void move(long timeBetweenMovementOperations) {
// TODO Auto-generated method stub
System.out.println(Simulator.getFormattedTime(Simulator.getCurrentTime()) + " | " + topologyComponent);
}
......
......@@ -26,14 +26,25 @@ import java.util.List;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.UAVLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
/**
* Movement model container for all UAVs. This primarily triggers the local movement models of the respective UAVs.
*
* @author Julian Zobel
* @version 1.0, 6 Sep 2018
*/
public class UAVMovement implements MovementModel, EventHandler {
private List<UAVLocationActuator> actuators = new LinkedList<>();
protected long timeBetweenMoveOperation = Time.SECOND;
public UAVMovement() {
Event.scheduleImmediately(this, null, 0);
}
@Override
public void addComponent(SimLocationActuator actuator) {
if(!actuators.contains(actuator) && actuator instanceof UAVLocationActuator)
......@@ -42,7 +53,7 @@ public class UAVMovement implements MovementModel, EventHandler {
@Override
public void placeComponent(SimLocationActuator actuator) {
throw new UnsupportedOperationException();
//
}
@Override
......@@ -59,6 +70,8 @@ public class UAVMovement implements MovementModel, EventHandler {
for (UAVLocationActuator actuator : actuators) {
actuator.getUAVMovement().move(timeBetweenMoveOperation);
}
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, 1);
}
......
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