Commit 1b66ba35 authored by Jean Meurice's avatar Jean Meurice
Browse files

Powertrain-EE merge + Version up

parents a4deb77d 959ce879
Pipeline #188236 failed with stage
in 16 seconds
......@@ -28,6 +28,7 @@ masterJobWindows:
stage: windows
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
- mvn package sonar:sonar -s settings.xml
tags:
- Windows10
only:
......
......@@ -41,11 +41,18 @@
<version>${revision}</version>
</dependency>
<!-- Dependency to commons -->
<!-- Dependency to control -->
<dependency>
<groupId>montisim</groupId>
<artifactId>commons</artifactId>
<version>${commons.version}</version>
<groupId>montisim-controller</groupId>
<artifactId>control</artifactId>
<version>${controller.version}</version>
</dependency>
<!-- Dependency on structures.Graph class -->
<dependency>
<groupId>montisim-controller</groupId>
<artifactId>library</artifactId>
<version>${controller.version}</version>
</dependency>
<dependency>
......@@ -119,6 +126,25 @@
<version>1.6.1</version>
</dependency>
<!-- testing -->
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
......
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package simulation.environment.object;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation.SimulationLoopExecutable;
import org.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.RealVector;
import simulation.environment.util.Chargeable;
import simulation.environment.util.ChargingProcess;
import simulation.environment.visualisationadapter.implementation.Node2D;
import simulation.environment.visualisationadapter.interfaces.EnvNode;
import simulation.environment.visualisationadapter.interfaces.EnvObject;
import simulation.environment.visualisationadapter.interfaces.EnvTag;
import java.time.Duration;
import java.util.*;
/**
* Charging Station Class
* <p>
*
* @version 1.0
* @since 2019-05-22
*/
public class ChargingStation implements SimulationLoopExecutable, EnvObject {
/**
* Name of the Charging Station
*/
private String name;
private long osmId;
/**
* Electrical consumption
*/
private double consumption = 0;
/**
* Voltage and Ampere of the ChargingStation
*/
private double voltage = 100;
private double ampere = 1;
/**
* Number of cars which can be charged at the same time, default = 1
*/
private int capacity = 1;
private ArrayList<Chargeable> carObjects = new ArrayList<>();
private HashMap<Chargeable, ChargingProcess> chargingProcessesMap = new HashMap<>();
/**
* Location of the Charging Station
*/
private RealVector location;
private ArrayList<EnvNode> nodes;
/**
* Car tracing Radius of the Charging Station
*/
private double stationRadius = 8;
// ===================
// Constructor
// ===================
/**
* Default Positon: 0,0,0
*/
public ChargingStation() {
this.nodes = new ArrayList<EnvNode>(){{add(new Node2D(0, 0, 0));}};
this.location = new ArrayRealVector(new double[] {0.0, 0.0, 0.0});
this.name = "Charging Station ";
}
/**
* Cunstructor
*
* @param osmId
* @param node
* @param capacity number of cars that can be placed in the Charging Station
* @param name
*/
public ChargingStation(long osmId, EnvNode node, int capacity, String name) {
this.osmId = osmId;
this.nodes = new ArrayList<EnvNode>(){{add(node);}};
this.location = new ArrayRealVector(new double[]{
node.getX().doubleValue(), node.getY().doubleValue(), node.getZ().doubleValue()});
this.capacity = capacity;
this.name = name;
}
// ===================
// Methods
// ===================
/**
* Method to start the charging process
*
* @param vehicle current vehicle
* @return false if it is already in use or not near by
*/
public boolean startCharging(Chargeable vehicle) {
if (!vehicle.isChargeable()){
return false;
}
if (carStandingAtTheCS(vehicle) && (!isOccupied())) {
carObjects.add(vehicle);
ChargingProcess cp = new ChargingProcess(vehicle, this);
// Start the Charging Process
cp.startProcess();
chargingProcessesMap.put(vehicle, cp);
return true;
}
return false;
}
/**
* Method to stop the charging process
*
* @return false if not in use or vehicle not found
*/
public boolean stopCharging(Chargeable vehicle) {
if (carObjects.remove(vehicle)) {
chargingProcessesMap.remove(vehicle);
return true;
}
return false;
}
public boolean isOccupied() {
if (this.carObjects.size() == this.capacity) {
return true;
}
return false;
}
public boolean carStandingAtTheCS(Chargeable vehicle) {
// Is the Car near the CS (consider only x,y coordinates)
RealVector location2D = new ArrayRealVector(new double[]{location.getEntry(0),location.getEntry(1)});
RealVector vehiclePos2D = new ArrayRealVector(new double[]{vehicle.getPosition().getEntry(0),vehicle.getPosition().getEntry(1)});
return location2D.getDistance(vehiclePos2D) < stationRadius;
}
// ===================
// Getter and Setter
// ===================
public String getName() {
return this.name;
}
public long getOsmId() {
return this.osmId;
}
public int getCapacity() {
return this.capacity;
}
public void setCapacity(int capacity) { this.capacity = capacity; }
public RealVector getLocation() {
return this.location.copy();
}
public void setLocation(RealVector point) {
this.location = point.copy();
}
public double getStationRadius() {
return this.stationRadius;
}
public void setStationRadius(double stationTrackingRadius) {
this.stationRadius = stationTrackingRadius;
}
public String toString() {
return getName() + ", Capacity: " + getCapacity() + ", OsmID: " + getOsmId() + "\n" + getLocation();
}
public ArrayList<Chargeable> getCarObjects() {
return this.carObjects;
}
public double getConsumption() {
return consumption;
}
public double getVoltage(){
return this.voltage;
}
public double getAmpere(){
return this.ampere;
}
public void setVoltage(double voltage){
this.voltage = voltage;
}
public void setAmpere(double ampere){
this.ampere = ampere;
}
public void setConsumption(double consumption) {
if (consumption < 0) {
simulation.util.Log.warning("Consumption < 0 is not possible! Fallback to zero.");
this.consumption = 0;
} else {
this.consumption = consumption;
}
}
/**
* Function that requests the called object to update its state for given time
* difference
*
* @param timeDiffMs Difference in time measured in milliseconds
*/
@Override
public void executeLoopIteration(Duration timeDiffMs) {
for(ChargingProcess cp : chargingProcessesMap.values()){
cp.executeLoopIteration(timeDiffMs);
}
}
@Override
public ArrayList<EnvNode> getNodes() {
return nodes;
}
@Override
public EnvTag getTag() {
return EnvTag.CHARGING_STATION;
}
}
......@@ -6,6 +6,7 @@
*/
package simulation.environment.osm;
import simulation.environment.object.ChargingStation;
import simulation.environment.visualisationadapter.implementation.*;
import simulation.environment.visualisationadapter.interfaces.*;
import simulation.environment.visualisationadapter.implementation.EnvironmentContainer2D;
......@@ -49,6 +50,8 @@ public class EnvironmentContainerConverter {
ArrayList<EnvStreet> meterStreets = new ArrayList<>();
ArrayList<Building> meterBuildings = new ArrayList<>();
ArrayList<Waterway> meterWaterway = new ArrayList<>();
ArrayList<ChargingStation> meterChargingStations = new ArrayList<>();
for(EnvStreet longLatStreet : containerLongLat.getStreets()) {
ArrayList<EnvNode> nodes = new ArrayList<>();
for(EnvNode node : longLatStreet.getNodes()) {
......@@ -115,15 +118,36 @@ public class EnvironmentContainerConverter {
meterWaterway.add(new Waterway2D(nodes, longLatWaterway.getOsmId()));
}
computeMinMax(meterStreets, meterBuildings, meterWaterway);
containerMeters = new EnvironmentContainer2D(bounds,meterStreets, meterBuildings, meterWaterway);
for(ChargingStation chargingStation: containerLongLat.getChargingStations()) {
EnvNode node = chargingStation.getNodes().get(0);
double nLong = node.getX().doubleValue();
double nLat = node.getY().doubleValue();
double mY = converter.convertLatToMeters(nLat);
double mX = converter.convertLongToMeters(nLong, nLat);
double mZ = node.getZ().doubleValue();
long osmId = node.getOsmId();
Node2D nodeInMeter = new Node2D(mX, mY, mZ, osmId);
meterChargingStations.add(new ChargingStation(
osmId, nodeInMeter, chargingStation.getCapacity(), chargingStation.getName()));
}
computeMinMax(meterStreets, meterBuildings, meterWaterway, meterChargingStations);
containerMeters = new EnvironmentContainer2D(
bounds,meterStreets, meterBuildings, meterWaterway, meterChargingStations);
}
/**
* computes the min and max values for x,y,z and thus the bounds of the environment
* @param streets
*/
private void computeMinMax(ArrayList<EnvStreet> streets,ArrayList<Building> buildings, ArrayList<Waterway> waterways) {
private void computeMinMax(
ArrayList<EnvStreet> streets,
ArrayList<Building> buildings,
ArrayList<Waterway> waterways,
ArrayList<ChargingStation> chargingStations) {
//assure that every street (including pavements lies in the bounds of the environment
double minX = 0 - Waterway.RIVER_WIDTH;
double minY = 0 - Waterway.RIVER_WIDTH;
......@@ -178,6 +202,21 @@ public class EnvironmentContainerConverter {
}
}
}
for(ChargingStation chargingStation: chargingStations) {
for(EnvNode nodes: chargingStation.getNodes()) {
if(nodes.getX().doubleValue() > maxX) {
maxX = nodes.getX().doubleValue();
}
if(nodes.getY().doubleValue() > maxY) {
maxY = nodes.getY().doubleValue();
}
if(nodes.getZ().doubleValue() > maxZ) {
maxZ = nodes.getZ().doubleValue();
}
}
}
this.bounds = new Bounds2D(minX, maxX, minY, maxY, minZ, maxZ);
}
......
......@@ -6,6 +6,7 @@
*/
package simulation.environment.osm;
import simulation.environment.object.ChargingStation;
import simulation.environment.visualisationadapter.interfaces.Building;
import simulation.environment.visualisationadapter.interfaces.EnvStreet;
import simulation.environment.visualisationadapter.interfaces.VisualisationEnvironmentContainer;
......@@ -41,6 +42,10 @@ public interface IParser {
*/
public abstract Collection<Waterway> getWaterways();
/**
* @return a collection of all Charging Stations parsed
*/
public abstract Collection<ChargingStation> getChargingStations();
/**
......
......@@ -18,7 +18,10 @@ import de.topobyte.osm4j.core.resolve.EntityNotFoundException;
import de.topobyte.osm4j.xml.dynsax.OsmXmlReader;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.RealVector;
import org.w3c.dom.Document;
import simulation.environment.object.ChargingStation;
import simulation.environment.osm.Dto.OSMNode;
import simulation.environment.visualisationadapter.implementation.*;
import simulation.environment.visualisationadapter.interfaces.*;
......@@ -48,8 +51,10 @@ public class Parser2D implements IParser {
private HashSet<EnvStreet> streets;
private HashSet<Building> buildings;
private HashSet<Waterway> waterway;
private HashSet<ChargingStation> chargingStations;
private String filePath;
private String mapName;
private InputStream in;
......@@ -66,6 +71,7 @@ public class Parser2D implements IParser {
public Parser2D(ParserSettings pSettings) {
this.in = pSettings.in;
this.z = pSettings.z;
this.mapName = pSettings.mapName;
init();
}
......@@ -73,6 +79,7 @@ public class Parser2D implements IParser {
this.streets = new HashSet<>();
this.buildings = new HashSet<>();
this.waterway = new HashSet<>();
this.chargingStations = new HashSet<>();
}
/**
......@@ -203,6 +210,8 @@ public class Parser2D implements IParser {
} catch (EntityNotFoundException e) {
e.printStackTrace();
}
parseChargingStations();
buildContainer();
addSomeRandomTrees();
generateZCoordinates();
......@@ -224,6 +233,33 @@ public class Parser2D implements IParser {
addStreetSigns();
}
private void parseChargingStations() {
// Each charging station in OSM are represented by a node with tag amenity=charging_station
// We iterate over all nodes in the map to find charging stations
for (OsmNode node: dataSet.getNodes().valueCollection()){
Map<String, String> tags = OsmModelUtil.getTagsAsMap(node);
String amenity = tags.get("amenity");
if (amenity != null && amenity.equals("charging_station")){
String capacity = tags.get("capacity");
if (capacity == null) {
capacity = "1";
}
String name = tags.get("name");
if (name == null) {
name = "chargingStation";
}
this.chargingStations.add(new ChargingStation(
node.getId(),
new Node2D(node.getLongitude(), node.getLatitude(), 0, node.getId()),
Integer.parseInt(capacity),
name)
);
}
}
}
private void addStreetSigns() {
// Disable street signs for now, they are not supported by computer vision / controller yet
// StreetSignGenerator.generateStreetSigns(containerM);
......@@ -246,7 +282,7 @@ public class Parser2D implements IParser {
this.container = new simulation.environment.visualisationadapter.implementation.EnvironmentContainer2D(
new Bounds2D(this.dataSet.getBounds().getLeft(), this.dataSet.getBounds().getRight(), this.dataSet.getBounds().getBottom(), this.dataSet.getBounds().getTop(), 0, 0),
this.streets, this.buildings, this.waterway);
this.streets, this.buildings, this.waterway, this.chargingStations);
}
......@@ -272,7 +308,6 @@ public class Parser2D implements IParser {
String surface = tags.get("surface");
// System.out.println("PARSE OBJECTS FUNCTION "+highway);
// System.out.println(waterway);
......@@ -292,9 +327,7 @@ public class Parser2D implements IParser {
if (waterway != null) {
constructWaterway( way, waterway);
}
}
}
......@@ -369,6 +402,10 @@ public class Parser2D implements IParser {
return this.waterway;
}
public Collection<ChargingStation> getChargingStations() {
return this.chargingStations;
}
public InMemoryMapDataSet getDataSet() {
return this.dataSet;
}
......@@ -425,4 +462,8 @@ public class Parser2D implements IParser {
return EnvStreet.StreetPavements.PAVED;
}
}
}
public String getMapName(){
return this.mapName;
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
package simulation.environment.osm;
import java.io.InputStream;
import java.util.Optional;
/**
* Created by lukas on 16.02.17.
......@@ -20,6 +21,7 @@ public class ParserSettings {
public InputStream in;
public ZCoordinates z;
public String mapName = "";
public ParserSettings(String in, ZCoordinates z) {
this.in = getClass().getResourceAsStream(in);
......@@ -31,4 +33,10 @@ public class ParserSettings {
this.in = in;
this.z = z;
}
public ParserSettings(InputStream in, ZCoordinates z, String mapName) {
this.in = in;
this.z = z;
this.mapName = mapName;
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package simulation.environment.util;
import org.apache.commons.math3.linear.RealVector;
import simulation.environment.object.ChargingStation;
import java.util.Optional;
public interface Chargeable {
boolean isCharging();
void setCharging(boolean isCharging);
boolean isChargeable();
VehicleType getVehicleType();
Optional<IBattery> getBattery();
// boolean isFullyCharged();
boolean isParkedChargingStation(ChargingStation station);
void onRechargeReady();
RealVector getPosition();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/