Commit 01a3ca94 authored by Julian Zobel's avatar Julian Zobel
Browse files

UAVs can now return to base and recharge

parent 0cdce77f
...@@ -65,6 +65,13 @@ public interface Battery extends Cloneable { ...@@ -65,6 +65,13 @@ public interface Battery extends Cloneable {
default public void reset() { default public void reset() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/**
* Resets the Battery to the maximum (full) Energy-Level
*/
default public void setToMaximumLoad() {
throw new UnsupportedOperationException();
}
/** /**
* Sets the battery to a given percentage. * Sets the battery to a given percentage.
......
...@@ -56,5 +56,5 @@ public interface ControllableLocationActuator { ...@@ -56,5 +56,5 @@ public interface ControllableLocationActuator {
public void removeAllTargetLocations(); public void removeAllTargetLocations();
public void returnToBase(ReachedLocationCallback cb); public void returnToBase(ReachedLocationCallback cb);
} }
...@@ -52,8 +52,8 @@ public class RechargeableBattery extends SimpleBattery { ...@@ -52,8 +52,8 @@ public class RechargeableBattery extends SimpleBattery {
} }
@Override @Override
public void reset() { public void setToMaximumLoad() {
currentEnergy = initialEnergy; currentEnergy = capacity;
} }
@Override @Override
......
...@@ -20,38 +20,66 @@ ...@@ -20,38 +20,66 @@
package de.tud.kom.p2psim.impl.energy; package de.tud.kom.p2psim.impl.energy;
import java.util.LinkedList;
import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent; import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent; import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory; import de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback;
/** /**
* Ground-based charger for UAVs * Ground-based charger for UAVs. Replaces the battery completely, i.e.,
* sets battery capacity to full levels, but requires some time to do so.
* *
* *
* @author Julian Zobel * @author Julian Zobel
* @version 1.0, 21.09.2018 * @version 1.0, 21.09.2018
*/ */
public class UAVCharger implements HostComponent { public class UAVReplacementCharger implements HostComponent {
private Host host; private Host host;
private long replacementDuration; private long replacementDuration;
private int chargerSize;
private LinkedList<UAVTopologyComponent> uavs = new LinkedList<>(); public UAVReplacementCharger(Host host, long replacementDuration) {
public UAVCharger(Host host, long replacementDuration, int chargerSize) {
this.host = host; this.host = host;
this.replacementDuration = replacementDuration; this.replacementDuration = replacementDuration;
this.chargerSize = chargerSize; }
/**
* Charge a UAV by replacing the battery (i.e. reset to full battery levels). Replacement takes some time.
* The UAV is informed about the full replacement when it is finished by a callback.
*
* @param uav
* @param cb
*/
public void charge(UAVTopologyComponent uav, BatteryReplacementCallback cb) {
Event.scheduleWithDelay(replacementDuration, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
replacementComplete(uav, cb);
}
}, null, 0);
}
/**
* When this is called (after the replacement duration) the UAV's battery is set
* to full level/max capacity.
*
* @param uav
* @param cb
*/
protected void replacementComplete(UAVTopologyComponent uav, BatteryReplacementCallback cb) {
uav.getBattery().setToMaximumLoad();
cb.rechargeComplete();
} }
@Override @Override
public void initialize() { public void initialize() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
...@@ -68,22 +96,19 @@ public class UAVCharger implements HostComponent { ...@@ -68,22 +96,19 @@ public class UAVCharger implements HostComponent {
public static class Factory implements HostComponentFactory { public static class Factory implements HostComponentFactory {
private long replacementDuration; private long replacementDuration;
private int chargerSize;
/**
* Duration of the battery replacement in SECONDS
* @param replacementDuration
*/
public void setReplacementDuration(long replacementDuration) { public void setReplacementDuration(long replacementDuration) {
this.replacementDuration = replacementDuration; this.replacementDuration = replacementDuration;
}
public void setChargerSize(int chargerSize) {
this.chargerSize = chargerSize;
} }
@Override @Override
public HostComponent createComponent(Host host) { public HostComponent createComponent(Host host) {
return new UAVCharger(host, replacementDuration, chargerSize); return new UAVReplacementCharger(host, replacementDuration);
} }
} }
} }
...@@ -26,6 +26,8 @@ import de.tud.kom.p2psim.api.common.SimHost; ...@@ -26,6 +26,8 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
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.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.overlay.OverlayComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
...@@ -33,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction ...@@ -33,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public class BaseTopologyComponent extends AbstractTopologyComponent { public class BaseTopologyComponent extends AbstractTopologyComponent {
private OverlayComponent baseOverlayComponent; private OverlayComponent baseOverlayComponent;
private UAVReplacementCharger charger;
public BaseTopologyComponent(SimHost host, Topology topology, public BaseTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel, MovementModel movementModel, PlacementModel placementModel,
...@@ -41,6 +45,17 @@ public class BaseTopologyComponent extends AbstractTopologyComponent { ...@@ -41,6 +45,17 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
registerAsInformationProviderInSiS); registerAsInformationProviderInSiS);
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@Override
public void initialize() {
super.initialize();
try {
charger = getHost().getComponent(UAVReplacementCharger.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError("Unable to retrieve Replacement Charger for Base!");
}
}
@Override @Override
public double getMinMovementSpeed() { public double getMinMovementSpeed() {
...@@ -84,4 +99,9 @@ public class BaseTopologyComponent extends AbstractTopologyComponent { ...@@ -84,4 +99,9 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
public OverlayComponent getBaseComponent() { public OverlayComponent getBaseComponent() {
return baseOverlayComponent; return baseOverlayComponent;
} }
public UAVReplacementCharger getCharger() {
return charger;
}
} }
...@@ -41,6 +41,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableExcep ...@@ -41,6 +41,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableExcep
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.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.BatteryReplacementCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback; import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
/** /**
...@@ -176,6 +177,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -176,6 +177,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return battery.getCurrentPercentage(); return battery.getCurrentPercentage();
} }
public RechargeableBattery getBattery() {
return battery;
}
@Override @Override
public UAVMovementModel getUAVMovement() { public UAVMovementModel getUAVMovement() {
...@@ -257,9 +261,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -257,9 +261,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override @Override
public void reachedLocation() { public void reachedLocation() {
cb.reachedLocation();
deactivate(); deactivate();
connectToBaseCharger(); cb.reachedLocation();
} }
}; };
...@@ -267,10 +270,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -267,10 +270,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
} }
private void connectToBaseCharger() { protected void connectToBaseAndRecharge() {
BaseTopologyComponent base = UAVBasePlacement.base; BaseTopologyComponent base = UAVBasePlacement.base;
base.getCharger().charge(this, new BatteryReplacementCallback() {
@Override
public void rechargeComplete() {
System.out.println("Recharge completed!");
}
});
} }
......
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