Commit e9c62f18 authored by Lukas Bram's avatar Lukas Bram
Browse files

Add simple battery_level sensor

parent d6a02e6a
......@@ -10,6 +10,7 @@ import de.rwth.montisim.simulation.eesimulator.EESystem;
import de.rwth.montisim.simulation.vehicle.physicalvalues.*;
import de.rwth.montisim.simulation.vehicle.physicsmodel.PhysicsModel;
import de.rwth.montisim.simulation.vehicle.powertrain.PowerTrain;
import de.rwth.montisim.simulation.vehicle.powertrain.electrical.ElectricalPowerTrain;
import de.rwth.montisim.simulation.vehicle.task.Task;
public class Vehicle extends SimulationObject implements Updatable, Destroyable, TaskRunner {
......@@ -62,6 +63,9 @@ public class Vehicle extends SimulationObject implements Updatable, Destroyable,
}
protected void addPhysicalValues() {
if ( powerTrain instanceof ElectricalPowerTrain ) {
physicalValues.addPhysicalValue(new BatteryLevel( ((ElectricalPowerTrain) powerTrain).battery));
}
physicalValues.addPhysicalValue(new TrueCompass(physicalObject));
physicalValues.addPhysicalValue(new TrueVelocity(physicalObject));
physicalValues.addPhysicalValue(new TruePosition(physicalObject));
......
package de.rwth.montisim.simulation.vehicle.physicalvalues;
import de.rwth.montisim.commons.physicalvalue.PhysicalValueDouble;
import de.rwth.montisim.simulation.vehicle.powertrain.electrical.battery.Battery;
public class BatteryLevel extends PhysicalValueDouble {
public static final String VALUE_NAME = "battery_level";
transient final Battery battery;
public BatteryLevel(Battery battery) {
super(VALUE_NAME);
this.battery = battery;
}
/**
* @return [x,y, upper_speed_limit] */
@Override
public Object get(){
return battery.percentage();
}
@Override
public void set(Object value){
// cannot change the battery level this way
}
}
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