Commit d3e62a60 authored by Julian Zobel's avatar Julian Zobel
Browse files

Basiuc Strategy with Callbacks

parent 01a3ca94
......@@ -22,7 +22,12 @@ 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.uavsupport.Actuator;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
/**
......@@ -33,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocation
* @author Julian Zobel
*
*/
public interface ControllableLocationActuator {
public interface ControllableLocationActuator extends Actuator {
public boolean isActive();
......@@ -56,5 +61,8 @@ public interface ControllableLocationActuator {
public void removeAllTargetLocations();
public void returnToBase(ReachedLocationCallback cb);
public void connectToBase(BaseConnectedCallback cb);
public void disconnectFromBase(BaseDisconnectedCallback cb);
}
......@@ -77,8 +77,7 @@ public class ActuatorEnergyComponent implements EnergyComponent {
@Override
public double calculateEnergyConsumation(EnergyState state, long timeInState) {
if(state.equals(FLY)) {
double consumationDelta = MAX.getEnergyConsumption() - FLY.getEnergyConsumption();
double consumationDelta = MAX.getEnergyConsumption() - FLY.getEnergyConsumption();
double consumation = FLY.getEnergyConsumption() + consumationDelta * actuatorLoad;
return consumation * ( (double) timeInState / (double) Time.SECOND);
}
......
......@@ -30,13 +30,15 @@ import de.tud.kom.p2psim.impl.energy.UAVReplacementCharger;
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.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.BaseToUAVInterface;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.UAVToBaseInterface;
public class BaseTopologyComponent extends AbstractTopologyComponent {
private OverlayComponent baseOverlayComponent;
private UAVReplacementCharger charger;
private BaseToUAVInterface controllerInterface;
public BaseTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel,
......@@ -104,4 +106,15 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
return charger;
}
public void setControllerInterface(BaseToUAVInterface controllerInterface) {
this.controllerInterface = controllerInterface;
}
public void connectUAVToBase(UAVToBaseInterface uav) {
this.controllerInterface.connectUAVtoBase(uav);
}
public void disconnectUAVFromBase(UAVToBaseInterface uav) {
this.controllerInterface.disconnectUAV(uav);
}
}
......@@ -41,7 +41,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableExcep
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent;
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.BatteryReplacementCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.UAVToBaseInterface;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
/**
......@@ -61,9 +63,11 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
private ActuatorEnergyComponent actuator;
private RechargeableBattery battery;
private UAVstate state = UAVstate.OFFLINE;
private UAVstate state;
private PositionVector baseLocation;
private UAVToBaseInterface controllerInterface;
/**
* Create a TopologyComponent for the current host.
*
......@@ -94,7 +98,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
System.err.println("No Battery Component was found!");
}
baseLocation = position.clone();
// retrieve base location
baseLocation = UAVBasePlacement.base.position.clone();
}
public void setState(UAVstate newState) {
......@@ -196,12 +201,6 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return actuator;
}
public void updateCurrentLocation(Location location, double actuatorLoad) {
super.updateCurrentLocation(location);
actuator.useActuator(actuatorLoad);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
throw new UnsupportedOperationException();
......@@ -261,7 +260,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public void reachedLocation() {
deactivate();
deactivate();
cb.reachedLocation();
}
};
......@@ -269,18 +268,36 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
movement.setTargetLocation(baseLocation, returnCallback);
}
protected void connectToBaseAndRecharge() {
protected void batteryReplacement() {
BaseTopologyComponent base = UAVBasePlacement.base;
base.getCharger().charge(this, new BatteryReplacementCallback() {
@Override
public void rechargeComplete() {
System.out.println("Recharge completed!");
}
});
base.getCharger().charge(this, null);
}
public void setControllerInterface(UAVToBaseInterface controllerInterface) {
this.controllerInterface = controllerInterface;
UAVBasePlacement.base.connectUAVToBase(this.controllerInterface);
state = UAVstate.OFFLINE;
}
@Override
public void connectToBase(BaseConnectedCallback cb) {
BaseTopologyComponent base = UAVBasePlacement.base;
base.connectUAVToBase(controllerInterface);
if(cb != null)
cb.successfulConnection();
}
@Override
public void disconnectFromBase(BaseDisconnectedCallback cb) {
BaseTopologyComponent base = UAVBasePlacement.base;
base.disconnectUAVFromBase(controllerInterface);
if(cb != null)
cb.successfulDisconnection();
}
}
......@@ -23,6 +23,9 @@ package de.tud.kom.p2psim.impl.topology.movement.aerial;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.joda.time.tz.ZoneInfoProvider;
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel;
import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
......@@ -92,7 +95,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
if(distanceToTargetPosition < 0.1 || distanceToTargetPosition < currentSpeed)
{
route.removeFirst();
topologyComponent.updateCurrentLocation(targetPosition, 0.5); // triggers energy consumption for last distance
topologyComponent.getActuatorEnergyComponent().useActuator(0.5);
topologyComponent.updateCurrentLocation(targetPosition); // triggers energy consumption for last distance
currentSpeed = 0;
topologyComponent.getActuatorEnergyComponent().useActuator(0); // now hover
locationReached(targetPosition);
......@@ -111,7 +115,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
PositionVector newPosition = new PositionVector(currentPosition);
newPosition.add(direction);
topologyComponent.updateCurrentLocation(newPosition, 1);
topologyComponent.getActuatorEnergyComponent().useActuator(1);
topologyComponent.updateCurrentLocation(newPosition);
}
......
......@@ -25,15 +25,13 @@ import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/**
* This is the interface for the generator of the {@link AttractionPoint}s. It
* gets the set number of AttractionPoints back. This mean, it will be generate
* them and set the Position of them.
* Interface for {@link AttractionPoint} generators. Will generate a given amount of attraction points.
*
* @author Christoph Muenker
* @version 1.0, 02.07.2013
* @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018
*/
public interface IAttractionGenerator {
public List<AttractionPoint> getAttractionPoints();
}
......@@ -20,9 +20,9 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Vector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
......@@ -35,11 +35,11 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
* It generates the given number of {@link AttractionPoint}s and sets the
* Position randomly.
* Generates the given number of {@link AttractionPoint}s and sets the
* position randomly within the world dimensions.
*
* @author Christoph Muenker
* @version 1.0, 02.07.2013
* @author Christoph Muenker, Julian Zobel
* @version 1.1, 09 2018
*/
public class RandomAttractionGenerator implements IAttractionGenerator {
......@@ -50,6 +50,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private int numberOfAttractionPoints;
private boolean numberOfAPsSet = false;
private List<AttractionPoint> attractionPoints;
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public RandomAttractionGenerator(int numberOfAttractionPoints) {
......@@ -62,6 +64,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
}
this.numberOfAPsSet = true;
this.numberOfAttractionPoints = numberOfAttractionPoints;
this.attractionPoints = new LinkedList<AttractionPoint>();
createAttractionPoints();
}
@Override
......@@ -71,13 +75,22 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
"Number of Attraction Points is not set in RandomAttractionGenerator!");
}
List<AttractionPoint> result = new Vector<AttractionPoint>();
if(attractionPoints.isEmpty())
createAttractionPoints();
return attractionPoints;
}
private void createAttractionPoints() {
List<AttractionPoint> result = new LinkedList<AttractionPoint>();
for (int i = 0; i < numberOfAttractionPoints; i++) {
PositionVector posVec = createPosVec();
AttractionPoint aPoint = new AttractionPointImpl("AP"+i,posVec);
AttractionPoint aPoint = new AttractionPointImpl("AP"+i, posVec);
result.add(aPoint);
}
return result;
attractionPoints.clear();
attractionPoints.addAll(result);
}
private PositionVector createPosVec() {
......
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