Browse Source

finish storage emit behaviour debug

David Heck 4 years ago
parent
commit
8dda9330b1
3 changed files with 33 additions and 26 deletions
  1. 29 24
      src/algo/StorageElement.java
  2. 2 2
      src/algo/StorageProductionController.java
  3. 2 0
      src/algo/TestAlgo.java

+ 29 - 24
src/algo/StorageElement.java

@@ -2,7 +2,6 @@ package algo;
 
 import com.google.gson.annotations.Expose;
 
-import algo.StorageObject.Mode;
 import classes.HolonElement;
 import ui.model.Model;
 
@@ -57,39 +56,34 @@ public class StorageElement extends HolonElement {
 	/**
 	 * 
 	 * @param status Mode of currect operation
-	 * @param energy float how much energy is needed from storage/ can be collected
+	 * @param energyWanted float how much energy is needed from storage/ can be collected
 	 *               by the storage
 	 * @return float how much energy was collected/emited
 	 */
-	public float setStatusAndSetEnergy(Mode status, float energy) {
+	public float setStatusAndSetEnergy(Mode status, float energyWanted) {
 		this.status = status;
 		switch (status) {
 		case STANDBY:
 			this.setEnergyPerElement(0);
 			return 0;
 		case EMIT:
-			if (stateOfCharge >= energy) { // enough energy stored than wanted
-				if (energy >= maxInRatio) { // more energy wanted than can be given
+			if (energyWanted >= maxOutRatio) { // more energy wanted than can be giving
+				if (stateOfCharge >= maxOutRatio) { // more energy wanted than can be given
 					this.setEnergyPerElement(maxOutRatio);
-//					stateOfCharge = stateOfCharge - maxOutRatio;//TODO: not hear but in simulation manager
 					return maxOutRatio;
-				} else { // less energy wanted that can be given
-					this.setEnergyPerElement(energy);
-//					stateOfCharge = stateOfCharge - energy;
-					return energy;
+				} else { // less energy stored that can be given
+					return notEnoughChargedToEmitWantedEnergy();
 				}
-			} else {// not enough energy stored than wanted
-				if (stateOfCharge == 0) { // no energy stored at all
-					this.status = Mode.STANDBY;
-					return 0;
-				} else { // emit energy that is available even though is less that wanted
-					this.setEnergyPerElement(stateOfCharge);
-//					stateOfCharge = 0;
-					return stateOfCharge;
+			} else {// not enough energy stored than what can be given
+				if (stateOfCharge >= energyWanted) { // more energy stored than wanted
+					this.setEnergyPerElement(energyWanted);
+					return energyWanted;
+				} else { // less energy stored than wanted
+					return notEnoughChargedToEmitWantedEnergy();
 				}
 			}
 		case COLLECT:
-			if (energy >= maxInRatio) { // more engery given than can be collected
+			if (energyWanted >= maxInRatio) { // more engery given than can be collected
 				if (stateOfCharge + maxInRatio > capacity) { // Storage nearly full only load rest to get full
 					this.setEnergyPerElement(-(capacity - stateOfCharge));
 //					stateOfCharge = capacity;
@@ -104,14 +98,14 @@ public class StorageElement extends HolonElement {
 					this.status = Mode.STANDBY;
 					return 0;
 				} else {
-					if (stateOfCharge + energy > capacity) { // Storage nearly full only load rest to get full
+					if (stateOfCharge + energyWanted > capacity) { // Storage nearly full only load rest to get full
 						this.setEnergyPerElement(-(capacity - stateOfCharge));
 //						stateOfCharge = capacity;
 						return capacity - stateOfCharge;
 					} else { // take all engery that is available
-						this.setEnergyPerElement(-energy);
+						this.setEnergyPerElement(-energyWanted);
 //						stateOfCharge = stateOfCharge + energy;
-						return energy;
+						return energyWanted;
 					}
 				}
 			}
@@ -126,12 +120,13 @@ public class StorageElement extends HolonElement {
 	}
 
 	public void chargeCalc(){
+		System.out.println("stateofcharge" + getId()+ "before:" + stateOfCharge + " with incomming " + status + " " + getEnergyPerElement() );
 		switch (status){
 			case COLLECT:
 				stateOfCharge = stateOfCharge - getEnergyPerElement();
 				break;
 			case EMIT:
-				stateOfCharge = stateOfCharge + getEnergyPerElement();
+				stateOfCharge = stateOfCharge - getEnergyPerElement();
 				break;
 			default:
 		}
@@ -139,7 +134,7 @@ public class StorageElement extends HolonElement {
 			status = Mode.STANDBY;
 			setEnergyPerElement(0);
 		}
-
+		System.out.println("stateofcharge after:" + stateOfCharge + " now as " + status + " " + getEnergyPerElement() );
 	}
 
 	public void setStateOfCharge(float stateOfCharge){
@@ -148,7 +143,17 @@ public class StorageElement extends HolonElement {
 		}else{
 			this.stateOfCharge = capacity;
 		}
+	}
 
+	private float notEnoughChargedToEmitWantedEnergy(){
+		if(stateOfCharge <= 0){
+			this.status = Mode.STANDBY;
+			this.setEnergyPerElement(0);
+			return 0;
+		}else{
+			this.setEnergyPerElement(stateOfCharge);
+			return stateOfCharge;
+		}
 
 	}
 

+ 2 - 2
src/algo/StorageProductionController.java

@@ -43,11 +43,11 @@ public class StorageProductionController {
                 }
 
                 if(energyLeftToEnabled <= 0){
-                	System.out.println("enabled energy from storage" + energyLeftToEnabled);
+                	System.out.println("enabled energy from storage");
                     return;
                 }
             }
-        }else{
+        }else{//TODO:!!!!!! das ist nich fertig
             disableStorageProduction(energyNeeded - currentStorageProduction());
         }
 

+ 2 - 0
src/algo/TestAlgo.java

@@ -346,10 +346,12 @@ public class TestAlgo implements AddOn {
 				return true;
 			} else {
 				// blackstart has failed
+				SPC.disableStorageProduction(-1);//TODO:disable all
 				println("Not enough storage energy available");
 				return false;
 			}
 		} else {
+			//TODO: disable storage?
 			// renewable energy production is sufficient for the blackstart
 			rampUpPowerplant();
 			enableConsumers(