Commit 9ffd41f2 authored by Julian Zobel's avatar Julian Zobel
Browse files

SImple topology component fpr the base station

adapted multicopter movement and UAV topology component
parent 9fa50bfd
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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<AttractionPoint> getAllAttractionPoints() {
throw new UnsupportedOperationException();
}
@Override
public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) {
throw new UnsupportedOperationException();
}
@Override
public AttractionPoint getCurrentTargetAttractionPoint() {
throw new UnsupportedOperationException();
}
}
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
package de.tud.kom.p2psim.impl.topology.component; package de.tud.kom.p2psim.impl.topology.component;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set; import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
...@@ -32,11 +34,13 @@ import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator; ...@@ -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.movement.UAVMovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.energy.components.ActuatorEnergyComponent; 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.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent; 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.battery.BatterySensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; 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.Location;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
/** /**
* Topology component used for UAVs. * Topology component used for UAVs.
...@@ -85,26 +89,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -85,26 +89,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
System.err.println("No Battery Component was found!"); System.err.println("No Battery Component was found!");
} }
} }
@Override
public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint)
throws UnsupportedOperationException {
// TODO Auto-generated method stub
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
// TODO Auto-generated method stub
return null;
}
@Override
public AttractionPoint getCurrentTargetAttractionPoint() {
// TODO Auto-generated method stub
return null;
}
public void setUAVComponent(OverlayComponent uavOverlayComponent) { public void setUAVComponent(OverlayComponent uavOverlayComponent) {
this.uavOverlayComponent = uavOverlayComponent; this.uavOverlayComponent = uavOverlayComponent;
} }
...@@ -150,23 +135,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -150,23 +135,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
} }
@Override @Override
public Location getCurrentLocation() { public PositionVector getCurrentLocation() {
// TODO Auto-generated method stub return position.clone();
return null;
} }
@Override @Override
public double getCurrentBatteryLevel() { public double getCurrentBatteryLevel() {
// TODO Auto-generated method stub return battery.getCurrentPercentage();
return 0;
}
@Override
public void moveToLocation(Location targetLocation) {
// TODO Auto-generated method stub
} }
@Override @Override
public UAVMovementModel getUAVMovement() { public UAVMovementModel getUAVMovement() {
return movement; return movement;
...@@ -188,6 +166,55 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -188,6 +166,55 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
actuator.useActuator(actuatorLoad); actuator.useActuator(actuatorLoad);
} }
@Override
public Set<AttractionPoint> 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<PositionVector> route,
ReachedLocationCallback cb) {
LinkedList<PositionVector> 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<PositionVector> getTargetLocations() {
return movement.getTargetLocations();
}
......
...@@ -24,13 +24,10 @@ import java.util.HashMap; ...@@ -24,13 +24,10 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel; 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.component.UAVTopologyComponent;
import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* Local movement logic specifically designs the movement for multicopter UAVs. * Local movement logic specifically designs the movement for multicopter UAVs.
...@@ -48,8 +45,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { ...@@ -48,8 +45,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
private double preferredCruiseSpeed; private double preferredCruiseSpeed;
private double currentSpeed; private double currentSpeed;
private LinkedList<Location> waypoints = new LinkedList<>(); private LinkedList<PositionVector> route = new LinkedList<>();
private Map<Location, ?> locationCallbacks = new HashMap<>(); // TODO callback interface private Map<PositionVector, ReachedLocationCallback> locationCallbacks = new HashMap<>(); // TODO callback interface
public SimpleMutlicopterMovement(UAVTopologyComponent topologyComponent, double maxCruiseSpeed, double minCruiseSpeed) { public SimpleMutlicopterMovement(UAVTopologyComponent topologyComponent, double maxCruiseSpeed, double minCruiseSpeed) {
...@@ -57,10 +54,7 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { ...@@ -57,10 +54,7 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
this.maxCruiseSpeed = maxCruiseSpeed; this.maxCruiseSpeed = maxCruiseSpeed;
this.minCruiseSpeed = minCruiseSpeed; this.minCruiseSpeed = minCruiseSpeed;
this.preferredCruiseSpeed = this.maxCruiseSpeed; 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 @Override
...@@ -82,21 +76,23 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { ...@@ -82,21 +76,23 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
public double getCurrentSpeed() { public double getCurrentSpeed() {
return currentSpeed; return currentSpeed;
} }
@Override @Override
public void move(long timeBetweenMovementOperations) { public void move(long timeBetweenMovementOperations) {
if(!waypoints.isEmpty() && topologyComponent.isActive() ) { if(!route.isEmpty() && topologyComponent.isActive() ) {
PositionVector currentPosition= topologyComponent.getRealPosition(); PositionVector currentPosition= topologyComponent.getRealPosition();
Location targetLocation = waypoints.getFirst(); PositionVector targetPosition = route.getFirst();
PositionVector targetPosition = new PositionVector(targetLocation);
Double distanceToTargetPosition = targetPosition.distanceTo(currentPosition); Double distanceToTargetPosition = targetPosition.distanceTo(currentPosition);
// If target point is reached within a 1 meter margin, we remove that point from the list // 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); topologyComponent.updateCurrentLocation(targetPosition, 0);
currentSpeed = 0; currentSpeed = 0;
return; return;
...@@ -117,10 +113,65 @@ public class SimpleMutlicopterMovement implements UAVMovementModel { ...@@ -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<PositionVector> 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<PositionVector> getTargetLocations() {
LinkedList<PositionVector> copy = new LinkedList<>();
for (PositionVector pv : route) {
copy.add(pv.clone());
}
return copy;
}
@Override
public void removeTargetLocations() {
route.clear();
locationCallbacks.clear();
}
} }
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