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

Removed the doubled state machine of UAVCOntroller and UAVTopologyComponent

parent e42f2c0f
......@@ -22,13 +22,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.component.sensor.location.LocationSensor;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.Actuator;
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;
......@@ -40,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocation
* @author Julian Zobel
*
*/
public interface ControllableLocationActuator extends Actuator {
public interface ControllableLocationActuator extends Actuator, LocationSensor {
public boolean isActive();
......@@ -74,6 +72,8 @@ public interface ControllableLocationActuator extends Actuator {
public void removeAllTargetLocations();
public void batteryReplacement(BatteryReplacementCallback cb);
public void returnToBase(double velocity, ReachedLocationCallback cb);
public boolean landAtBase(BaseConnectionCallback cb);
......@@ -91,4 +91,6 @@ public interface ControllableLocationActuator extends Actuator {
public double estimatePowerConsumptionWatt(double velocity);
public double estimateFlightDistance(double velocity, double batterylevel, double batterythreshold);
public double getOptimalMovementSpeed();
}
......@@ -57,7 +57,7 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.UAVToBaseIn
*/
public class UAVTopologyComponent extends AbstractTopologyComponent implements SimUAVLocationActuator {
public enum UAVstate {OFFLINE, BASE_CONNECTION, BASE_CONNECTION_READY, ACTION, RETURN, CRASHED}
public enum UAVstate {OFFLINE, BASE_CONNECTION, BASE_CONNECTION_READY, ACTION, RETURN, LANDING, CRASHED}
private UAVMovementModel movement;
......@@ -290,7 +290,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public void returnToBase(double velocity, ReachedLocationCallback cb) {
if(!isActive()) return;
if(!isActive())
return;
this.setState(UAVstate.RETURN);
movement.setTargetVelocity(velocity);
movement.setTargetLocation(getBaseReturnLocation(), cb);
}
......@@ -300,7 +302,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
if(!isActive()) return false;
if(isOverBaseLocation()) {
this.setState(UAVstate.RETURN);
this.setState(UAVstate.LANDING);
ReachedLocationCallback landedCallback = new ReachedLocationCallback() {
......@@ -344,7 +346,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
private void batteryReplacement(BatteryReplacementCallback cb) {
public void batteryReplacement(BatteryReplacementCallback cb) {
if(state != UAVstate.BASE_CONNECTION) {
throw new UnsupportedOperationException("Cannot recharge if not connected to base!");
......@@ -358,7 +360,6 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
public void setControllerInterface(UAVToBaseInterface controllerInterface) {
this.controllerInterface = controllerInterface;
this.controllerInterface.setDeploymentArea(topology.getWorldDimensions());
connectToBase(null);
}
......@@ -446,6 +447,10 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return distance;
}
public double getOptimalMovementSpeed() {
return movement.estimateOptimalSpeed();
}
@Override
public PositionVector getBaseLocation() {
return getBaseReturnLocation();
......
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