Commit 75a053f5 authored by Julian Zobel's avatar Julian Zobel
Browse files

Example scenario for ML

parent 125d6756
......@@ -23,10 +23,11 @@ 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.component.UAVTopologyComponent.UAVstate;
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.BaseConnectionCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
......@@ -46,6 +47,8 @@ public interface ControllableLocationActuator extends Actuator {
public boolean activate();
public boolean deactivate();
public UAVstate getState();
public PositionVector getCurrentLocation();
......@@ -70,16 +73,14 @@ public interface ControllableLocationActuator extends Actuator {
public void setTargetLocationRoute(LinkedList<PositionVector> route, ReachedLocationCallback cb);
public void removeAllTargetLocations();
public void batteryReplacement(BatteryReplacementCallback cb);
public void returnToBase(ReachedLocationCallback cb);
public void returnToBase(double velocity, ReachedLocationCallback cb);
public void connectToBase(BaseConnectedCallback cb);
public void disconnectFromBase(BaseDisconnectedCallback cb);
public boolean landAtBase(BaseConnectionCallback cb);
public boolean startFromBase(ReachedLocationCallback cb);
public void setMovementSpeed(double speed);
public void setMovementSpeed(double velocity);
public double getMinMovementSpeed();
......
......@@ -58,7 +58,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.N
* Abstract implementation of the topology component interface, to support basic
* functionalities to all topology components.
*
* @author Julian Zobel
* @author Julian Zobel, others before
* @version 1.0, 6 Sep 2018
*/
public abstract class AbstractTopologyComponent implements TopologyComponent {
......
......@@ -43,21 +43,20 @@ 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.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
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.BaseConnectionCallback;
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.communication.UAVToBaseInterface;
/**
* Topology component extension prividing a broader topology functionality for UAVs
* Topology component extension providing a broader topology functionality for UAVs
*
* @author Julian Zobel
* @version 1.0, 06.09.2018
*/
public class UAVTopologyComponent extends AbstractTopologyComponent implements SimUAVLocationActuator {
public enum UAVstate {OFFLINE, BASE_CONNECTION, ACTION, RETURN, CRASHED}
public enum UAVstate {OFFLINE, BASE_CONNECTION, BASE_CONNECTION_READY, ACTION, RETURN, CRASHED}
private UAVMovementModel movement;
......@@ -83,7 +82,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
public UAVTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
super(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
direction = new PositionVector(0,-1,0);
direction = new PositionVector(0,-1,0);
}
@Override
......@@ -106,10 +105,11 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
// retrieve base location
baseLocation = UAVBasePlacement.base.position.clone();
baseLocation = UAVBasePlacement.base.position.clone();
}
public void setState(UAVstate newState) {
private void setState(UAVstate newState) {
this.state = newState;
// TODO analyzer
......@@ -228,12 +228,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public void setTargetLocation(PositionVector targetLocation,
ReachedLocationCallback cb) {
if(!isActive()) return;
movement.setTargetLocation(new PositionVector(targetLocation), cb);
}
@Override
public void addTargetLocation(PositionVector targetLocation,
ReachedLocationCallback cb) {
if(!isActive()) return;
movement.addTargetLocation(new PositionVector(targetLocation), cb);
}
......@@ -271,59 +275,127 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return state;
}
private PositionVector getOverBaseLocation() {
PositionVector locationOverBase = baseLocation.clone();
locationOverBase.setAltitude(10);
return locationOverBase;
}
@Override
public void returnToBase(double velocity, ReachedLocationCallback cb) {
movement.setTargetVelocity(velocity);
movement.setTargetLocation(getOverBaseLocation(), cb);
}
@Override
public void returnToBase(ReachedLocationCallback cb) {
this.setState(UAVstate.RETURN);
public boolean landAtBase(BaseConnectionCallback cb) {
if(overBaseLocation()) {
this.setState(UAVstate.RETURN);
ReachedLocationCallback landedCallback = new ReachedLocationCallback() {
@Override
public void reachedLocation() {
deactivate();
connectToBase(cb);
}
};
movement.setTargetVelocity(5);
movement.setTargetLocation(baseLocation, landedCallback);
return true;
}
else return false;
}
ReachedLocationCallback returnCallback = new ReachedLocationCallback() {
@Override
public boolean startFromBase(ReachedLocationCallback cb) {
if(this.getCurrentLocation().equals(this.getBaseLocation())
&& state == UAVstate.BASE_CONNECTION_READY
&& activate()) {
disconnectFromBase();
movement.setTargetVelocity(movement.getVerticalAscentMaxVelocity());
movement.setTargetLocation(getOverBaseLocation(), cb);
@Override
public void reachedLocation() {
deactivate();
cb.reachedLocation();
}
};
return true;
}
else return false;
movement.setTargetVelocity(movement.getHorizontalMaxVelocity());
movement.setTargetLocation(baseLocation, returnCallback);
}
private boolean overBaseLocation() {
if(this.getCurrentLocation().getX() == this.getBaseLocation().getX()
&& this.getCurrentLocation().getY() == this.getBaseLocation().getY()) {
return true;
}
else return false;
}
public void batteryReplacement(BatteryReplacementCallback cb) {
private void batteryReplacement(BatteryReplacementCallback cb) {
if(state != UAVstate.BASE_CONNECTION) {
throw new UnsupportedOperationException("Cannot recharge if not connected to base!");
}
this.setState(UAVstate.OFFLINE);
BaseTopologyComponent base = UAVBasePlacement.base;
base.getCharger().charge(this, cb);
}
public void setControllerInterface(UAVToBaseInterface controllerInterface) {
this.controllerInterface = controllerInterface;
this.controllerInterface = controllerInterface;
this.controllerInterface.setDeploymentArea(topology.getWorldDimensions());
connectToBase(null);
}
@Override
public void connectToBase(BaseConnectedCallback cb) {
/**
* Connect to the base and initiate a recharge
*
* @param cb
*/
private void connectToBase(BaseConnectionCallback cb) {
BaseTopologyComponent base = UAVBasePlacement.base;
base.connectUAVToBase(controllerInterface);
if(cb != null)
cb.successfulConnection();
if(cb != null) {
cb.successfulConnection();
}
this.setState(UAVstate.BASE_CONNECTION);
shutdownCommunication();
// recharge
if(battery.getCurrentPercentage() <= 75) {
batteryReplacement(new BatteryReplacementCallback() {
@Override
public void rechargeComplete() {
setState(UAVstate.BASE_CONNECTION_READY);
if(cb != null) {
cb.readyForTakeoff();
}
}
});
}
else {
this.setState(UAVstate.BASE_CONNECTION_READY);
if(cb != null) {
cb.readyForTakeoff();
}
}
}
@Override
public void disconnectFromBase(BaseDisconnectedCallback cb) {
private void disconnectFromBase() {
startCommunication();
BaseTopologyComponent base = UAVBasePlacement.base;
base.disconnectUAVFromBase(controllerInterface);
if(cb != null)
cb.successfulDisconnection();
base.disconnectUAVFromBase(controllerInterface);
}
private void shutdownCommunication() {
......@@ -382,5 +454,21 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
}
@Override
public UAVstate getState() {
return state;
}
@Override
public void updateCurrentLocation(Location location) {
super.updateCurrentLocation(location);
if(!actuator.isOn() && (state == UAVstate.ACTION || state == UAVstate.RETURN)) {
this.deactivate();
}
}
}
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