Commit e68ebafa authored by Julian Zobel's avatar Julian Zobel
Browse files

Logging for crash. Provide the return location instead the base location

parent 75a053f5
......@@ -39,6 +39,7 @@ 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;
......@@ -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);
}
......@@ -244,6 +249,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@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));
......@@ -275,7 +281,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return state;
}
private PositionVector getOverBaseLocation() {
private PositionVector getBaseReturnLocation() {
PositionVector locationOverBase = baseLocation.clone();
locationOverBase.setAltitude(10);
......@@ -283,14 +289,17 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
@Override
public void returnToBase(double velocity, ReachedLocationCallback cb) {
public void returnToBase(double velocity, ReachedLocationCallback cb) {
if(!isActive()) return;
movement.setTargetVelocity(velocity);
movement.setTargetLocation(getOverBaseLocation(), cb);
movement.setTargetLocation(getBaseReturnLocation(), cb);
}
@Override
public boolean landAtBase(BaseConnectionCallback cb) {
if(overBaseLocation()) {
if(!isActive()) return false;
if(isOverBaseLocation()) {
this.setState(UAVstate.RETURN);
ReachedLocationCallback landedCallback = new ReachedLocationCallback() {
......@@ -312,13 +321,13 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public boolean startFromBase(ReachedLocationCallback cb) {
if(this.getCurrentLocation().equals(this.getBaseLocation())
if(this.getCurrentLocation().equals(baseLocation)
&& state == UAVstate.BASE_CONNECTION_READY
&& activate()) {
disconnectFromBase();
movement.setTargetVelocity(movement.getVerticalAscentMaxVelocity());
movement.setTargetLocation(getOverBaseLocation(), cb);
movement.setTargetLocation(getBaseReturnLocation(), cb);
return true;
}
......@@ -326,9 +335,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
private boolean overBaseLocation() {
if(this.getCurrentLocation().getX() == this.getBaseLocation().getX()
&& this.getCurrentLocation().getY() == this.getBaseLocation().getY()) {
private boolean isOverBaseLocation() {
if(this.getCurrentLocation().getX() == baseLocation.getX()
&& this.getCurrentLocation().getY() == baseLocation.getY()) {
return true;
}
else return false;
......@@ -439,7 +448,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public PositionVector getBaseLocation() {
return baseLocation.clone();
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