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 {
default public void reset() {
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.
......
......@@ -56,5 +56,5 @@ public interface ControllableLocationActuator {
public void removeAllTargetLocations();
public void returnToBase(ReachedLocationCallback cb);
}
......@@ -52,8 +52,8 @@ public class RechargeableBattery extends SimpleBattery {
}
@Override
public void reset() {
currentEnergy = initialEnergy;
public void setToMaximumLoad() {
currentEnergy = capacity;
}
@Override
......
......@@ -20,38 +20,66 @@
package de.tud.kom.p2psim.impl.energy;
import java.util.LinkedList;
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.component.HostComponent;
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
* @version 1.0, 21.09.2018
*/
public class UAVCharger implements HostComponent {
public class UAVReplacementCharger implements HostComponent {
private Host host;
private long replacementDuration;
private int chargerSize;
private LinkedList<UAVTopologyComponent> uavs = new LinkedList<>();
public UAVCharger(Host host, long replacementDuration, int chargerSize) {
public UAVReplacementCharger(Host host, long replacementDuration) {
this.host = host;
this.replacementDuration = replacementDuration;
this.chargerSize = chargerSize;
this.replacementDuration = replacementDuration;
}
/**
* 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
public void initialize() {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
@Override
......@@ -68,22 +96,19 @@ public class UAVCharger implements HostComponent {
public static class Factory implements HostComponentFactory {
private long replacementDuration;
private int chargerSize;
/**
* Duration of the battery replacement in SECONDS
* @param replacementDuration
*/
public void setReplacementDuration(long replacementDuration) {
this.replacementDuration = replacementDuration;
}
public void setChargerSize(int chargerSize) {
this.chargerSize = chargerSize;
}
@Override
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;
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.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;
......@@ -33,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public class BaseTopologyComponent extends AbstractTopologyComponent {
private OverlayComponent baseOverlayComponent;
private UAVReplacementCharger charger;
public BaseTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel,
......@@ -41,6 +45,17 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
registerAsInformationProviderInSiS);
// 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
public double getMinMovementSpeed() {
......@@ -84,4 +99,9 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
public OverlayComponent getBaseComponent() {
return baseOverlayComponent;
}
public UAVReplacementCharger getCharger() {
return charger;
}
}
......@@ -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.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.callbacks.ReachedLocationCallback;
/**
......@@ -176,6 +177,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return battery.getCurrentPercentage();
}
public RechargeableBattery getBattery() {
return battery;
}
@Override
public UAVMovementModel getUAVMovement() {
......@@ -257,9 +261,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public void reachedLocation() {
cb.reachedLocation();
deactivate();
connectToBaseCharger();
cb.reachedLocation();
}
};
......@@ -267,10 +270,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
private void connectToBaseCharger() {
protected void connectToBaseAndRecharge() {
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