Commit e42f2c0f authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge remote-tracking branch 'origin/lab/20-21-acs-6-2' into jz/int-dmaa

# Conflicts:
#	src/de/tud/kom/p2psim/api/topology/component/ControllableLocationActuator.java
#	src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java
parents 55c9d677 60311368
......@@ -22,10 +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.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.component.sensor.location.LocationSensor;
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;
......@@ -38,13 +40,15 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocation
* @author Julian Zobel
*
*/
public interface ControllableLocationActuator extends Actuator, LocationSensor {
public interface ControllableLocationActuator extends Actuator {
public boolean isActive();
public boolean activate();
public boolean deactivate();
public UAVstate getState();
public PositionVector getCurrentLocation();
......@@ -69,16 +73,14 @@ public interface ControllableLocationActuator extends Actuator, LocationSensor {
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();
......@@ -89,6 +91,4 @@ public interface ControllableLocationActuator extends Actuator, LocationSensor {
public double estimatePowerConsumptionWatt(double velocity);
public double estimateFlightDistance(double velocity, double batterylevel, double batterythreshold);
public double estimateOptimalSpeed();
}
......@@ -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 {
......
......@@ -39,25 +39,25 @@ import de.tud.kom.p2psim.impl.energy.models.AbstractEnergyModel;
import de.tud.kom.p2psim.impl.topology.placement.UAVBasePlacement;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
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.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 +83,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 +106,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
......@@ -174,11 +175,15 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
actuator.turnOff();
if(this.position.getAltitude() != 0) {
this.setState(UAVstate.CRASHED);
this.setState(UAVstate.CRASHED);
PositionVector l = getCurrentLocation();
l.setAltitude(0);
this.updateCurrentLocation(l);
uavOverlayComponent.shutdown();
shutdownCommunication();
Monitor.log(this.getClass(), Level.WARN, "[UAVTopologyComponent] UAV " + getUAVComponent().getHost().getId() + " crashed at " + getRealPosition(), "");
} else {
this.setState(UAVstate.OFFLINE);
}
......@@ -228,18 +233,23 @@ 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);
}
@Override
public void setTargetLocationRoute(LinkedList<PositionVector> route,
ReachedLocationCallback cb) {
if(!isActive()) return;
LinkedList<PositionVector> positionvectorlist = new LinkedList<>();
for (Location loc : route) {
positionvectorlist.add(new PositionVector(loc));
......@@ -271,59 +281,130 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return state;
}
private PositionVector getBaseReturnLocation() {
PositionVector locationOverBase = baseLocation.clone();
locationOverBase.setAltitude(10);
return locationOverBase;
}
@Override
public void returnToBase(ReachedLocationCallback cb) {
this.setState(UAVstate.RETURN);
public void returnToBase(double velocity, ReachedLocationCallback cb) {
if(!isActive()) return;
movement.setTargetVelocity(velocity);
movement.setTargetLocation(getBaseReturnLocation(), cb);
}
@Override
public boolean landAtBase(BaseConnectionCallback cb) {
if(!isActive()) return false;
ReachedLocationCallback returnCallback = new ReachedLocationCallback() {
if(isOverBaseLocation()) {
this.setState(UAVstate.RETURN);
@Override
public void reachedLocation() {
deactivate();
cb.reachedLocation();
}
};
ReachedLocationCallback landedCallback = new ReachedLocationCallback() {
@Override
public void reachedLocation() {
deactivate();
connectToBase(cb);
}
};
movement.setTargetVelocity(5);
movement.setTargetLocation(baseLocation, landedCallback);
return true;
}
else return false;
}
@Override
public boolean startFromBase(ReachedLocationCallback cb) {
if(this.getCurrentLocation().equals(baseLocation)
&& state == UAVstate.BASE_CONNECTION_READY
&& activate()) {
disconnectFromBase();
movement.setTargetVelocity(movement.getVerticalAscentMaxVelocity());
movement.setTargetLocation(getBaseReturnLocation(), cb);
return true;
}
else return false;
movement.setTargetVelocity(movement.getHorizontalMaxVelocity());
movement.setTargetLocation(baseLocation, returnCallback);
}
private boolean isOverBaseLocation() {
if(this.getCurrentLocation().getX() == baseLocation.getX()
&& this.getCurrentLocation().getY() == baseLocation.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() {
......@@ -365,13 +446,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return distance;
}
public double estimateOptimalSpeed() {
return movement.estimateOptimalSpeed();
}
@Override
public PositionVector getBaseLocation() {
return baseLocation.clone();
return getBaseReturnLocation();
}
......@@ -386,5 +463,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