Commit 34cb9024 authored by Julian Zobel's avatar Julian Zobel
Browse files

Bugfix for empty battery UAV failure (crash!)

parent af397019
...@@ -131,7 +131,7 @@ public class ActuatorEnergyComponent implements EnergyComponent { ...@@ -131,7 +131,7 @@ public class ActuatorEnergyComponent implements EnergyComponent {
@Override @Override
public boolean isOn() { public boolean isOn() {
if(!currentState.equals(OFF)) if(!currentState.equals(OFF) && isAvailable())
{ {
doStateChange(FLY); doStateChange(FLY);
return true; return true;
......
...@@ -25,6 +25,7 @@ import de.tud.kom.p2psim.api.energy.Battery; ...@@ -25,6 +25,7 @@ import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.EnergyComponent; import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener; import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.network.SimNetInterface; import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.impl.energy.components.ActuatorEnergyComponent;
/** /**
* Energy Model based on multiple exchangeable components. Each component states the amount of consumed energy, * Energy Model based on multiple exchangeable components. Each component states the amount of consumed energy,
...@@ -59,6 +60,10 @@ public class ComponentBasedEnergyModel extends AbstractEnergyModel implements En ...@@ -59,6 +60,10 @@ public class ComponentBasedEnergyModel extends AbstractEnergyModel implements En
monitorEmptyBattery(); monitorEmptyBattery();
if(component instanceof ActuatorEnergyComponent) {
((ActuatorEnergyComponent) component).turnOff();
}
/* /*
* Battery is now empty. Go offline. * Battery is now empty. Go offline.
*/ */
......
...@@ -137,7 +137,14 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -137,7 +137,14 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override @Override
public boolean isActive() { public boolean isActive() {
return actuator.isOn(); if(actuator.isOn())
return true;
else {
if(state == UAVstate.ACTION || state == UAVstate.RETURN) {
this.deactivate();
}
return false;
}
} }
@Override @Override
...@@ -279,9 +286,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S ...@@ -279,9 +286,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
} }
public void setControllerInterface(UAVToBaseInterface controllerInterface) { public void setControllerInterface(UAVToBaseInterface controllerInterface) {
this.controllerInterface = controllerInterface; this.controllerInterface = controllerInterface;
this.connectToBase(null);
} }
@Override @Override
......
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