Commit 09fc2c8e authored by Jean Meurice's avatar Jean Meurice
Browse files

New Map and result Vis

parent d0fa2c09
......@@ -11,4 +11,5 @@
*.DS_Store
install/*
dependency-reduced-pom.xml
.vscode/
\ No newline at end of file
.vscode/
.factorypath
\ No newline at end of file
......@@ -13,6 +13,7 @@ Prev: [Maven Project tutorial](docs/maven.md) | Next: [MontiSim overview](
> - Use cases: building, inter-project copy, testing.
> chmod +x filename.sh
> msbuild -verbosity:quiet build\hardware-emulator.sln /m /p:Configuration=Release /p:Platform=x64
---
Prev: [Maven Project tutorial](docs/maven.md) | Next: [MontiSim overview](docs/montisim.md)
......@@ -51,8 +51,8 @@ located alongside the `basic-simulator.jar` file inside folders with the same na
By selecting a **scenario**, you can press the "Start Simulation" button to run this scenario in the simulator.
> ![Scenario select.](images/usage.png "Select a scenario and press the button.")
>
![Scenario select.](images/usage.png "Select a scenario and press the button.")
> **NOTE**: *Currently the output of the simulation is only shown in the console.*
You can start a simulation directly without interacting with the GUI by passing a scenario name as command line argument
......
......@@ -10,11 +10,17 @@
{
"name": "car1",
"physics_model": "masspoint",
"start_coords": [5.88133850,50.8354390,0],
"target_coords": [5.8813333,50.8355156,0],
"start_coords": [50.8354390, 5.88133850],
"target_coords": [50.8355156, 5.8813333],
"autopilot": {
"autopilot": "AutopilotAdapter",
"os": "windows",
"cpu_frequency": "4000000000",
"memory_frequency": "2500000000",
"cache_DL1": "262144,4,4",
"cache_IL1": "262144,4,4",
"cache_L2": "2097152,6,6",
"cache_L3": "12582912,40,40",
"no_time": true
}
}
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!--
......@@ -22,47 +22,44 @@
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>de.topobyte</pluginGroup>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>se-nexus</id>
<username>cibuild</username>
<password>${env.cibuild}</password>
</server>
<server>
<id>github</id>
<username>travisbuilduser</username>
<password>${env.travisbuilduserpassword}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>se-nexus</id>
<mirrorOf>external:*</mirrorOf>
<url>https://nexus.se.rwth-aachen.de/content/groups/public</url>
</mirror>
<mirror>
<id>topobyte-repository</id>
<mirrorOf>topobyte</mirrorOf>
<url>http://mvn.topobyte.de/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>de.topobyte</pluginGroup>
</pluginGroups>
<proxies></proxies>
<servers>
<server>
<id>se-nexus</id>
<username>cibuild</username>
<password>${env.cibuild}</password>
</server>
<server>
<id>github</id>
<username>travisbuilduser</username>
<password>${env.travisbuilduserpassword}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>se-nexus</id>
<mirrorOf>external:*</mirrorOf>
<url>https://nexus.se.rwth-aachen.de/content/groups/public</url>
</mirror>
<mirror>
<id>topobyte-repository</id>
<mirrorOf>topobyte</mirrorOf>
<url>http://mvn.topobyte.de/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
......@@ -72,25 +69,24 @@
<sonar.host.url>
https://metric.se.rwth-aachen.de
</sonar.host.url>
<sonar.login>
<sonar.login>
jenkins
</sonar.login>
<sonar.password>
<sonar.password>
${env.sonar}
</sonar.password>
</properties>
</profile>
<profile>
<id>se-nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
</repository>
<repository>
<profile>
<id>se-nexus</id>
<repositories>
<repository>
<id>mvnrepository</id>
<name>MVNRepository</name>
<url>https://maven.imagej.net/content/repositories/public</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
......@@ -120,8 +116,8 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<repository>
<id>topobyte</id>
<url>http://mvn.topobyte.de/</url>
<releases>
......@@ -131,63 +127,12 @@
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled /></releases>
<snapshots><enabled /></snapshots>
</pluginRepository>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>eclipse</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>topobyte</id>
<url>http://mvn.topobyte.de/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>se-nexus</activeProfile>
</activeProfiles>
</settings>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>se-nexus</activeProfile>
</activeProfiles>
</settings>
\ No newline at end of file
......@@ -18,15 +18,14 @@
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.rwth_aachen.se.montisim.simulators;
package de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator;
import commons.utils.LibraryService;
import de.rwth_aachen.se.montisim.simulators.basic_simulator.controller.BasicController;
import de.rwth_aachen.se.montisim.simulators.basic_simulator.filesystem.FileSystem;
import de.rwth_aachen.se.montisim.simulators.basic_simulator.gui.Browser;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.controller.BasicController;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.filesystem.FileSystem;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.filesystem.MapData;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.gui.Browser;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
/**
......@@ -46,12 +45,15 @@ public class App
public static void main( String[] args )
{
//new HelloTriangleSimple().setup();
//new Main().run(args);
load_icons();
System.out.println("Looks and Feels:");
/* System.out.println("Looks and Feels:");
UIManager.LookAndFeelInfo[] looks = UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo look : looks) {
System.out.println(look.getClassName());
}
} */
try {
/*
javax.swing.plaf.metal.MetalLookAndFeel
......@@ -77,10 +79,15 @@ public class App
FileSystem fileSystem = new FileSystem(System.getProperty("user.dir") + "/");
BasicController sim_controller = new BasicController(fileSystem);
/* MapData map = new MapData(fileSystem.getPath("maps", "Aachen2.osm"));
System.out.println("Map bounds: lat:["+map.minlat+" to "+map.maxlat+"] lon:["+map.minlon+" to "+map.maxlon+"]");
System.out.println("Loaded " + map.nodes.size() +" nodes.");
System.out.println("Loaded " + map.ways.size() +" ways."); */
if (args.length > 0){
String scenario_name = args[0];
System.out.println("Starting simulation with scenario: " + scenario_name);
sim_controller.initFromJsonScenario(FileSystem.getJson(fileSystem.getPath("scenarios", scenario_name + ".json")));
sim_controller.initFromJsonScenario(FileSystem.getJson(fileSystem.getPath("scenarios", scenario_name + ".json")), scenario_name);
sim_controller.startSimulation();
return;
}
......
......@@ -18,33 +18,28 @@
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.rwth_aachen.se.montisim.simulators.basic_simulator.controller;
import commons.simulation.SimulationLoopExecutable;
import commons.simulation.SimulationLoopNotifiable;
import de.rwth_aachen.se.montisim.simulators.basic_simulator.filesystem.FileSystem;
import de.rwth_aachen.se.montisim.simulators.basic_simulator.gui.Category;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
package de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.controller;
import javax.json.JsonObject;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.filesystem.FileSystem;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.filesystem.MapData;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation.SimulationLoopExecutable;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation.SimulationLoopNotifiable;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.HardwareEmulatorInterface;
import de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.gui.Category;
import simulation.simulator.Simulator;
import simulation.vehicle.PhysicalVehicle;
import simulation.environment.WorldModel;
import simulation.environment.osm.ParserSettings;
import simulation.environment.weather.WeatherSettings;
import simulation.simulator.SimulationType;
import simulation.simulator.Simulator;
import simulation.vehicle.PhysicalVehicle;
import simulator.integration.HardwareEmulatorInterface;
import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonValue;
import java.io.File;
import java.io.FileInputStream;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
public class BasicController implements SimulationLoopNotifiable, Runnable {
public class BasicController extends SimulationLoopNotifiable implements Runnable {
@Override
......@@ -52,142 +47,82 @@ public class BasicController implements SimulationLoopNotifiable, Runnable {
startSimulation();
}
public enum ScenarioSettings {
NAME("name"),
MAX_SIM_DURATION("max_sim_duration"),
SIMULATION_FREQUENCY("simulation_frequency"),
TIME("time"),
PEDESTRIAN_DENSITY("pedestrian_density"),
CARS("cars"),
MAP_NAME("map_name");
private String key_name;
ScenarioSettings(String key_name){
this.key_name = key_name;
}
public String get_key_name(){
return this.key_name;
}
}
Simulator simulator;
SimulationResult result;
HardwareEmulatorInterface model_server;
VehicleBuilder vehicle_builder;
FileSystem file_system;
HashMap<Long, VehicleBuilder.VehicleTrajectory> vehicleTrajectories = new HashMap<>();
public BasicController(FileSystem file_system) throws Exception {
String[] args = new String[2];
model_server = new HardwareEmulatorInterface("autopilots_folder=autopilots", "");
vehicle_builder = new VehicleBuilder(model_server);
result = new SimulationResult(file_system);
vehicle_builder = new VehicleBuilder(model_server, result);
simulator = null;
this.file_system = file_system;
}
public void initFromJsonScenario(JsonObject config) throws Exception {
JsonNumber p_d = config.getJsonNumber(ScenarioSettings.PEDESTRIAN_DENSITY.get_key_name());
double pedestrian_density = p_d != null ? p_d.doubleValue() : 0;
int max_sim_duration = config.getInt(ScenarioSettings.MAX_SIM_DURATION.get_key_name(), 60);
String scenario_name = config.getString(ScenarioSettings.NAME.get_key_name(), "default");
JsonNumber s_f = config.getJsonNumber(ScenarioSettings.SIMULATION_FREQUENCY.get_key_name());
double sim_frequ = s_f != null ? s_f.doubleValue() : 30;
String time = config.getString(ScenarioSettings.TIME.get_key_name(), "12:00");
String map_name = config.getString(ScenarioSettings.MAP_NAME.get_key_name());
//Check cars
JsonArray cars = config.getJsonArray(ScenarioSettings.CARS.get_key_name());
if (cars == null || cars.size() == 0){
throw new Exception("No cars specified in scenario " + scenario_name);
}
public void initFromJsonScenario(JsonObject scenario, String simulation_name) throws Exception {
ScenarioConfig config = new ScenarioConfig(scenario);
//Setup map
File mapPath = file_system.getPath(Category.CategoryType.MAPS.id, map_name + ".osm");
File mapPath = file_system.getPath(Category.CategoryType.MAPS.id, config.map_name + ".osm");
if (!mapPath.exists())
throw new Exception("Could not find map: " + map_name + " for scenario " + scenario_name);
throw new Exception("Could not find map: " + config.map_name + " for scenario " + config.scenario_name);
MapData map = new MapData(config.map_name, file_system);
//TODO free input stream when parsed
WorldModel.init(
new ParserSettings(new FileInputStream(mapPath), ParserSettings.ZCoordinates.ALLZERO),
new WeatherSettings()
);
//Setup simulator
Simulator.resetSimulator();
simulator = Simulator.getSharedInstance();
simulator.registerLoopObserver(this);
simulator.setSimulationDuration(max_sim_duration*1000);
simulator.setSimulationLoopFrequency((int) sim_frequ);
simulator.setSimulationDuration(config.max_sim_duration*1000);
simulator.setSimulationLoopFrequency((int) config.sim_frequ);
simulator.setSimulationType(SimulationType.SIMULATION_TYPE_FIXED_TIME);
org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
DateTime dt = formatter.parseDateTime(time);
simulator.setStartDaytime(dt.toDate());
simulator.setStartDaytime(config.time.toDate());
simulator.registerLoopObserver(this);
result.init_for_simulation(simulation_name, config.map_name, false, simulator.getSimulationLoopFrequency());
//Setup Vehicles
vehicleTrajectories.clear();
for (JsonValue car : cars){
if (car.getValueType() != JsonValue.ValueType.OBJECT)
throw new Exception("Expected Json object as car in scenario " + scenario_name);
JsonObject car_config = (JsonObject) car;
vehicle_builder.createVehicle(car_config, vehicleTrajectories);
for (VehicleConfig car : config.vehicles){
vehicle_builder.createVehicle(car, map);
}
}
public void startSimulation(){
simulator.startSimulation();
//Export simulation data when done:
result.export();
}
@Override
public void willExecuteLoop(List<SimulationLoopExecutable> simulationObjects, long totalTime, long deltaTime) {
}
@Override
public void didExecuteLoop(List<SimulationLoopExecutable> simulationObjects, long totalTime, long deltaTime) {
}
@Override
public void willExecuteLoopForObject(SimulationLoopExecutable simulationObject, long totalTime, long deltaTime) {
this.result.setup_next_frame(totalTime);
System.out.print("T: "+totalTime);
}
@Override
public void didExecuteLoopForObject(SimulationLoopExecutable simulationObject, long totalTime, long deltaTime) {
PhysicalVehicle vehicle = ((PhysicalVehicle) simulationObject);
double[] position = vehicle.getPosition().toArray();
double longitude = position[0];
double latitude = position[1];
VehicleBuilder.VehicleTrajectory traj = vehicleTrajectories.get(vehicle.getId());
double dist = traj.target.getDistance(vehicle.getPosition());
System.out.println("\tPosition of car: [" +latitude + ", " + longitude + "] (Dist to target: " + dist + ")");
//Temporary hack to stop simulation when vehicle attained its target
if (!traj.notified){
if (dist < 1){
System.out.println("\tCar at target");
if (simulationObject instanceof PhysicalVehicle){
PhysicalVehicle vehicle = ((PhysicalVehicle) simulationObject);
if (this.result.add_car_frame(vehicle)){
simulator.setSimulationDuration(1000+simulator.getSimulationTime());
traj.notified = true;
}
}
}
@Override
public void simulationStarted(List<SimulationLoopExecutable> simulationObjects) {
result.simulation_start();
}
@Override
public void simulationStopped(List<SimulationLoopExecutable> simulationObjects, long totalTime) {
}
}
......@@ -18,13 +18,13 @@
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.rwth_aachen.se.montisim.simulators.basic_simulator.controller;
package de.rwth.monticore.EmbeddedMontiArc.simulators.basic_simulator.controller;
import commons.controller.commons.BusEntry;
import commons.controller.interfaces.FunctionBlockInterface;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.controller.commons.BusEntry;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.controller.interfaces.FunctionBlockInterface;
import org.apache.commons.math3.linear.RealVector;
import simulation.vehicle.PhysicalVehicle;
import simulator.integration.HardwareEmulatorInterface;
import de.rwth.monticore.EmbeddedMontiArc.simulators.hardware_emulator.HardwareEmulatorInterface;
import simulation.vehicle.VehicleActuatorType;
import java.io.Serializable;
......@@ -140,7 +140,8 @@ public class DirectModelAsFunctionBlock implements FunctionBlockInterface {
Map<String, Object> result = new HashMap<>();
Object engine = outputs.get("engine");
if (engine != null)
result.put(BusEntry.ACTUATOR_ENGINE.toString(), ((double)engine) / 2.5); //TODO REMOVE SUPER JANKY TEMP TEST
//result.put(BusEntry.ACTUATOR_ENGINE.toString(), ((double)engine) / 2.5); //TODO REMOVE SUPER JANKY TEMP TEST
result.put(BusEntry.ACTUATOR_ENGINE.toString(), ((double)engine)); //TODO REMOVE SUPER JANKY TEMP TEST
Object brakes = outputs.get("brakes");
if (brakes != null)
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************