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

Adaptions to the energy model and actuator energy components.

Configuration class for actuator energy coimponents.
parent 9263d452
......@@ -20,8 +20,9 @@
package de.tud.kom.p2psim.api.topology.movement;
public interface UAVMovementModel {
public void setPreferredCruiseSpeed(double v_pref);
public double getMaxCruiseSpeed();
......
......@@ -25,6 +25,7 @@ import java.util.Random;
import java.util.Vector;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
......@@ -141,7 +142,7 @@ public class EnergyModelFactory implements HostComponentFactory {
energyConfigurations.add(energyConfig);
}
private void setMinimumStartEnergyLevel(double level) {
public void setMinimumStartEnergyLevel(double level) {
if(level > 1.0) {
this.minimumStartEnergyLevel = 1.0;
}
......@@ -152,7 +153,8 @@ public class EnergyModelFactory implements HostComponentFactory {
this.minimumStartEnergyLevel = level;
}
}
private void setUseRandomBatteryStartConfiguration(boolean randomStart) {
public void setUseRandomBatteryStartConfiguration(boolean randomStart) {
this.useRandomBatteryStartConfiguration = randomStart;
}
......
......@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.impl.energy;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -112,4 +113,12 @@ public class SimpleBattery implements Battery {
return initialEnergy;
}
@Override
public boolean isFullyCharged() {
if(currentEnergy == initialEnergy) {
return true;
}
return false;
}
}
......@@ -20,17 +20,22 @@
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.analyzer.EnergyAnalyzer;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
/**
* Energy component for actuaors, representing the electrical consumers of actuators.
* This models several states, where energy is consumed differently.
*
* @author Julian Zobel
* @version 1.0, 11.09.2018
*/
public class ActuatorEnergyComponent implements EnergyComponent {
/**
......@@ -38,34 +43,59 @@ public class ActuatorEnergyComponent implements EnergyComponent {
*
* TODO More states reflecting a more accurate energy consumption?
*/
public final EnergyState OFF, HOVER, FLY;
public final EnergyState OFF, FLY, MAX;
private EnergyState currentState;
private EnergyEventListener energyModel;
private long lastStateChange;
private long lastEnergyConsumationEvent;
private double actuatorLoad;
public ActuatorEnergyComponent(int numberOfActuators, double volt, double hoverAmp, double flyAmp) {
OFF = new DefaultEnergyState("OFF", 0);
HOVER = new DefaultEnergyState("HOVER", numberOfActuators * (hoverAmp * volt) * 1000000);
FLY = new DefaultEnergyState("FLY", numberOfActuators * (flyAmp * volt) * 1000000);
public ActuatorEnergyComponent(int numberOfActuators, double volt, double hoverAmp, double maxAmp) {
OFF = new DefaultEnergyState("OFF", 0);
FLY = new DefaultEnergyState("FLY", numberOfActuators * (hoverAmp * volt) * 1000000);
MAX = new DefaultEnergyState("MAX", numberOfActuators * (maxAmp * volt) * 1000000);
this.currentState = OFF;
this.lastStateChange = Time.getCurrentTime();
this.lastEnergyConsumationEvent = Time.getCurrentTime();
this.actuatorLoad = 0;
}
public void doStateChange(EnergyState newState) {
long timeSpentInState = Time.getCurrentTime() - lastStateChange;
long timeSpentInState = Time.getCurrentTime() - lastEnergyConsumationEvent;
energyModel.componentConsumedEnergy(this, calculateEnergyConsumation(currentState, timeSpentInState));
currentState = newState;
lastStateChange = Time.getCurrentTime();
lastEnergyConsumationEvent = Time.getCurrentTime();
}
@Override
public double calculateEnergyConsumation(EnergyState state, long timeInState) {
if(state.equals(FLY)) {
double consumationDelta = MAX.getEnergyConsumption() - FLY.getEnergyConsumption();
double consumation = FLY.getEnergyConsumption() + consumationDelta * actuatorLoad;
return consumation * ( (double) timeInState / (double) Time.SECOND);
}
else
return state.getEnergyConsumption() * ( (double) timeInState / (double) Time.SECOND);
}
public void useActuator(double load) {
if(load < 0 || load > 1.0) {
throw new AssertionError("Actuator load must be between 0 and 1!");
}
else {
this.actuatorLoad = load;
doStateChange(FLY);
}
}
@Override
public void eventOccurred(Object content, int type) {
// TODO Auto-generated method stub
......@@ -79,28 +109,33 @@ public class ActuatorEnergyComponent implements EnergyComponent {
@Override
public void turnOff() {
if(!currentState.equals(OFF)) {
doStateChange(OFF);
}
return;
}
@Override
public boolean turnOn() {
// TODO
if (isAvailable()) {
if (currentState.equals(OFF)) {
currentState = FLY;
}
return true;
}
return false;
}
public boolean isAvailable() {
// TODO
if (energyModel.componentCanBeActivated(this))
return true;
return false;
}
@Override
public boolean isOn() {
// TODO
return false;
if(!currentState.equals(OFF))
return true;
return false;
}
@Override
public void setEnergyEventListener(EnergyEventListener listener) {
energyModel = listener;
......
/*
* Copyright (c) 2005-2010 KOM � Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.impl.energy.components.ActuatorEnergyComponent;
/**
* Energy Configuration for {@link ActuatorEnergyComponent}s.
*
* @author Julian Zobel
* @version 1.0, 11.09.2018
*/
public class ActuatorEnergyConsumptionConfig implements EnergyConfiguration<ActuatorEnergyComponent> {
private int numberOfActuators;
private double volt;
private double hoverAmp; // in ampere
private double flyAmp; // in ampere
@Override
public ActuatorEnergyComponent getConfiguredEnergyComponent(SimHost host) {
return new ActuatorEnergyComponent(numberOfActuators, volt, hoverAmp, flyAmp);
}
@Override
public String getHelp() {
return "Fix actuator energy consumption config";
}
@Override
public boolean isWellConfigured() {
if(numberOfActuators >= 1 && volt > 0
&& hoverAmp > 0 && flyAmp > 0)
return true;
return false;
}
public void setNumberOfActuators(int num) {
numberOfActuators = num;
}
public void setHoverAmp(double ampereHovering) {
this.hoverAmp = ampereHovering;
}
public void setFlyAmp(double ampereFlying) {
this.flyAmp = ampereFlying;
}
public void setVolt(double voltage) {
this.volt = voltage;
}
}
......@@ -26,11 +26,11 @@ import java.util.Vector;
import de.tud.kom.p2psim.api.analyzer.EnergyAnalyzer;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyInfo;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.impl.energy.Battery;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
......
......@@ -21,12 +21,18 @@
package de.tud.kom.p2psim.impl.energy.models;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.impl.energy.Battery;
/**
* Energy Model based on multiple exchangeable components. Each component states the amount of consumed energy,
* which the energy model than will remove from the battery.
*
* @author Julian Zobel
* @version 1.0, 11.09.2018
*/
public class ComponentBasedEnergyModel extends AbstractEnergyModel implements EnergyEventListener {
public ComponentBasedEnergyModel(SimHost host, Battery bat) {
......@@ -46,10 +52,13 @@ public class ComponentBasedEnergyModel extends AbstractEnergyModel implements En
if (!bat.isEmpty()) {
bat.consumeEnergy(consumedEnergy);
monitorEnergyConsumation(component, consumedEnergy);
if (bat.isEmpty()) {
monitorEmptyBattery();
/*
* Battery is now empty. Go offline.
*/
......
......@@ -25,7 +25,7 @@ import java.util.List;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.UAVLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
......@@ -38,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.Time;
*/
public class UAVMovement implements MovementModel, EventHandler {
private List<UAVLocationActuator> actuators = new LinkedList<>();
private List<SimUAVLocationActuator> actuators = new LinkedList<>();
protected long timeBetweenMoveOperation = Time.SECOND;
public UAVMovement() {
......@@ -47,8 +47,8 @@ public class UAVMovement implements MovementModel, EventHandler {
@Override
public void addComponent(SimLocationActuator actuator) {
if(!actuators.contains(actuator) && actuator instanceof UAVLocationActuator)
actuators.add((UAVLocationActuator) actuator);
if(!actuators.contains(actuator) && actuator instanceof SimUAVLocationActuator)
actuators.add((SimUAVLocationActuator) actuator);
}
@Override
......@@ -67,7 +67,7 @@ public class UAVMovement implements MovementModel, EventHandler {
}
private void triggerComponentMovement() {
for (UAVLocationActuator actuator : actuators) {
for (SimUAVLocationActuator actuator : actuators) {
actuator.getUAVMovement().move(timeBetweenMoveOperation);
}
......
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