From 9ffd41f2a7fa0b487c4a7787754b072ad998ae46 Mon Sep 17 00:00:00 2001 From: Julian Zobel Date: Fri, 14 Sep 2018 14:54:25 +0200 Subject: [PATCH] SImple topology component fpr the base station adapted multicopter movement and UAV topology component --- .../component/BaseTopologyComponent.java | 79 ++++++++++++++++ .../component/UAVTopologyComponent.java | 89 ++++++++++++------- .../aerial/SimpleMutlicopterMovement.java | 83 +++++++++++++---- 3 files changed, 204 insertions(+), 47 deletions(-) create mode 100644 src/de/tud/kom/p2psim/impl/topology/component/BaseTopologyComponent.java diff --git a/src/de/tud/kom/p2psim/impl/topology/component/BaseTopologyComponent.java b/src/de/tud/kom/p2psim/impl/topology/component/BaseTopologyComponent.java new file mode 100644 index 00000000..442eb602 --- /dev/null +++ b/src/de/tud/kom/p2psim/impl/topology/component/BaseTopologyComponent.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab + * + * This file is part of PeerfactSim.KOM. + * + * PeerfactSim.KOM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * PeerfactSim.KOM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with PeerfactSim.KOM. If not, see . + * + */ + +package de.tud.kom.p2psim.impl.topology.component; + +import java.util.Set; + +import de.tud.kom.p2psim.api.common.SimHost; +import de.tud.kom.p2psim.api.topology.Topology; +import de.tud.kom.p2psim.api.topology.movement.MovementModel; +import de.tud.kom.p2psim.api.topology.placement.PlacementModel; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; +import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; + +public class BaseTopologyComponent extends AbstractTopologyComponent { + + public BaseTopologyComponent(SimHost host, Topology topology, + MovementModel movementModel, PlacementModel placementModel, + boolean registerAsInformationProviderInSiS) { + super(host, topology, movementModel, placementModel, + registerAsInformationProviderInSiS); + // TODO Auto-generated constructor stub + } + + @Override + public double getMinMovementSpeed() { + throw new UnsupportedOperationException(); + } + + @Override + public double getMaxMovementSpeed() { + throw new UnsupportedOperationException(); + } + + @Override + public double getMovementSpeed() { + throw new UnsupportedOperationException(); + } + + @Override + public void setMovementSpeed(double speed) { + throw new UnsupportedOperationException(); + } + + @Override + public Set getAllAttractionPoints() { + throw new UnsupportedOperationException(); + } + + @Override + public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) { + throw new UnsupportedOperationException(); + } + + @Override + public AttractionPoint getCurrentTargetAttractionPoint() { + throw new UnsupportedOperationException(); + } + + + +} diff --git a/src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java b/src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java index db285641..5a7f3566 100644 --- a/src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java +++ b/src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java @@ -20,6 +20,8 @@ package de.tud.kom.p2psim.impl.topology.component; +import java.util.HashSet; +import java.util.LinkedList; import java.util.Set; import de.tud.kom.p2psim.api.common.SimHost; @@ -32,11 +34,13 @@ import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator; import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.impl.energy.components.ActuatorEnergyComponent; +import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent; import de.tudarmstadt.maki.simonstrator.api.component.sensor.battery.BatterySensor; 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.uavsupport.callbacks.ReachedLocationCallback; /** * Topology component used for UAVs. @@ -85,26 +89,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S System.err.println("No Battery Component was found!"); } } - - @Override - public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) - throws UnsupportedOperationException { - // TODO Auto-generated method stub - - } - - @Override - public Set getAllAttractionPoints() { - // TODO Auto-generated method stub - return null; - } - - @Override - public AttractionPoint getCurrentTargetAttractionPoint() { - // TODO Auto-generated method stub - return null; - } - + public void setUAVComponent(OverlayComponent uavOverlayComponent) { this.uavOverlayComponent = uavOverlayComponent; } @@ -150,23 +135,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S } @Override - public Location getCurrentLocation() { - // TODO Auto-generated method stub - return null; + public PositionVector getCurrentLocation() { + return position.clone(); } @Override public double getCurrentBatteryLevel() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void moveToLocation(Location targetLocation) { - // TODO Auto-generated method stub - + return battery.getCurrentPercentage(); } + @Override public UAVMovementModel getUAVMovement() { return movement; @@ -188,6 +166,55 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S actuator.useActuator(actuatorLoad); } + @Override + public Set getAllAttractionPoints() { + throw new UnsupportedOperationException(); + } + + @Override + public void setTargetLocation(PositionVector targetLocation, + ReachedLocationCallback cb) { + movement.setTargetLocation(new PositionVector(targetLocation), cb); + } + + @Override + public void addTargetLocation(PositionVector targetLocation, + ReachedLocationCallback cb) { + movement.addTargetLocation(new PositionVector(targetLocation), cb); + } + + @Override + public void setTargetLocationRoute(LinkedList route, + ReachedLocationCallback cb) { + LinkedList positionvectorlist = new LinkedList<>(); + for (Location loc : route) { + positionvectorlist.add(new PositionVector(loc)); + } + movement.setTargetLocationRoute(positionvectorlist, cb); + } + + @Override + public void removeAllTargetLocations() { + movement.removeTargetLocations(); + } + + @Override + public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) { + throw new UnsupportedOperationException(); + } + + @Override + public AttractionPoint getCurrentTargetAttractionPoint() { + throw new UnsupportedOperationException(); + } + + @Override + public LinkedList getTargetLocations() { + return movement.getTargetLocations(); + } + + + diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/aerial/SimpleMutlicopterMovement.java b/src/de/tud/kom/p2psim/impl/topology/movement/aerial/SimpleMutlicopterMovement.java index 519e4543..5bf2fbd2 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/aerial/SimpleMutlicopterMovement.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/aerial/SimpleMutlicopterMovement.java @@ -24,13 +24,10 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel; -import de.tud.kom.p2psim.impl.energy.components.ActuatorEnergyComponent; -import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent; import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tudarmstadt.maki.simonstrator.api.Time; - -import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; +import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback; /** * Local movement logic specifically designs the movement for multicopter UAVs. @@ -48,8 +45,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { private double preferredCruiseSpeed; private double currentSpeed; - private LinkedList waypoints = new LinkedList<>(); - private Map locationCallbacks = new HashMap<>(); // TODO callback interface + private LinkedList route = new LinkedList<>(); + private Map locationCallbacks = new HashMap<>(); // TODO callback interface public SimpleMutlicopterMovement(UAVTopologyComponent topologyComponent, double maxCruiseSpeed, double minCruiseSpeed) { @@ -57,10 +54,7 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { this.maxCruiseSpeed = maxCruiseSpeed; this.minCruiseSpeed = minCruiseSpeed; this.preferredCruiseSpeed = this.maxCruiseSpeed; - - waypoints.add(new PositionVector(100,100,100)); - waypoints.add(new PositionVector(600,600,15)); - waypoints.add(new PositionVector(200,500,70)); + } @Override @@ -82,21 +76,23 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { public double getCurrentSpeed() { return currentSpeed; } + + @Override public void move(long timeBetweenMovementOperations) { - if(!waypoints.isEmpty() && topologyComponent.isActive() ) { + if(!route.isEmpty() && topologyComponent.isActive() ) { PositionVector currentPosition= topologyComponent.getRealPosition(); - Location targetLocation = waypoints.getFirst(); - PositionVector targetPosition = new PositionVector(targetLocation); + PositionVector targetPosition = route.getFirst(); Double distanceToTargetPosition = targetPosition.distanceTo(currentPosition); // If target point is reached within a 1 meter margin, we remove that point from the list - if(distanceToTargetPosition < 1 || distanceToTargetPosition < currentSpeed) + if(distanceToTargetPosition < 0.1 || distanceToTargetPosition < currentSpeed) { - waypoints.add(waypoints.removeFirst()); + locationReached(targetPosition); + route.add(route.removeFirst()); topologyComponent.updateCurrentLocation(targetPosition, 0); currentSpeed = 0; return; @@ -117,10 +113,65 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { } + //System.out.println(Simulator.getFormattedTime(Simulator.getCurrentTime()) + " | " + topologyComponent); + } + + /** + * Trigger the callback function, if there is a valid callback + * + * @param position + */ + private void locationReached(PositionVector position) { + if(locationCallbacks.containsKey(position)) { + locationCallbacks.get(position).reachedLocation(); + } + } + + @Override + public void setTargetLocation(PositionVector target, + ReachedLocationCallback reachedLocationCallback) { + route.clear(); + route.add(target); + if(reachedLocationCallback != null) + locationCallbacks.put(target, reachedLocationCallback); - // System.out.println(Simulator.getFormattedTime(Simulator.getCurrentTime()) + " | " + topologyComponent); } + @Override + public void setTargetLocationRoute(LinkedList route, + ReachedLocationCallback reachedLocationCallback) { + this.route.clear(); + this.route.addAll(route); + if(reachedLocationCallback != null) + locationCallbacks.put(route.getLast(), reachedLocationCallback); + } + @Override + public void addTargetLocation(PositionVector target, + ReachedLocationCallback reachedLocationCallback) { + route.add(target); + if(reachedLocationCallback != null) + locationCallbacks.put(target, reachedLocationCallback); + } + + @Override + public LinkedList getTargetLocations() { + + LinkedList copy = new LinkedList<>(); + for (PositionVector pv : route) { + copy.add(pv.clone()); + } + + return copy; + } + + @Override + public void removeTargetLocations() { + route.clear(); + locationCallbacks.clear(); + } + + + } -- GitLab