Commit a0e56c74 authored by Jean Meurice's avatar Jean Meurice
Browse files

Upgrade to SoftwareSimulator, using CarLang controller configuration

parent 405ec2a5
Pipeline #206601 failed with stages
in 1 minute and 44 seconds
**/target/*
.settings/*
.settings/
.project
.classpath
.directory
.idea
.idea/*
.vscode/
/target
*.pyc
*.DS_Store
......@@ -12,3 +13,4 @@
/restful/src/main/resources/resources
*.jar
/bin/
HardwareEmulator.*
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- (c) https://github.com/MontiCore/monticore -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>server</artifactId>
<groupId>montisim-server</groupId>
<version>${revision}</version>
<packaging>pom</packaging>
<artifactId>server</artifactId>
<groupId>montisim-server</groupId>
<version>${revision}</version>
<packaging>pom</packaging>
<modules>
<module>rpc</module>
......@@ -16,40 +15,31 @@
</modules>
<properties>
<revision>2.2.5</revision>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<properties>
<revision>2.2.6</revision>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<smartfox.version>2.13</smartfox.version>
<montisim.version>1.0.1</montisim.version>
<!-- .. Plugins ....................................................... -->
<!-- .. Plugins ....................................................... -->
<assembly.plugin>2.5.4</assembly.plugin>
<compiler.plugin>3.3</compiler.plugin>
<source.plugin>2.4</source.plugin>
<shade.plugin>2.4.3</shade.plugin>
<jacoco.plugin>0.8.1</jacoco.plugin>
<wagon.provider.version>2.6</wagon.provider.version>
<!-- Deployment properties -->
<project.name>ServerExtension</project.name>
<config.file>config.properties</config.file>
<config.dir>main/resources</config.dir>
<wagon.provider.version>2.6</wagon.provider.version>
<java.version>1.8</java.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</properties>
<!-- ================================================================================ -->
<!-- External additional maven repositories -->
<!-- ================================================================================ -->
<!-- ================================================================================ -->
<!-- External additional maven repositories -->
<!-- ================================================================================ -->
<repositories>
<repository>
<repository>
<id>jboss-public-repository</id>
<name>JBoss Public Maven Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
......@@ -62,16 +52,16 @@
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repository>
<!-- In Project (temporal) -->
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
<dependencies>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
......@@ -93,11 +83,11 @@
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!--Unit test-->
......@@ -118,7 +108,7 @@
</dependency>
</dependencies>
<!-- == PROJECT BUILD SETTINGS =========================================== -->
<!-- == PROJECT BUILD SETTINGS =========================================== -->
<build>
<plugins>
......@@ -162,17 +152,17 @@
</plugins>
</build>
<!-- == DISTRIBUTION ==================================================== -->
<distributionManagement>
<repository>
<id>se-nexus</id>
<url>https://nexus.se.rwth-aachen.de/content/repositories/embeddedmontiarc-releases/</url>
</repository>
<snapshotRepository>
<id>se-nexus</id>
<url>https://nexus.se.rwth-aachen.de/content/repositories/embeddedmontiarc-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<!-- == DISTRIBUTION ==================================================== -->
<distributionManagement>
<repository>
<id>se-nexus</id>
<url>https://nexus.se.rwth-aachen.de/content/repositories/embeddedmontiarc-releases/</url>
</repository>
<snapshotRepository>
<id>se-nexus</id>
<url>https://nexus.se.rwth-aachen.de/content/repositories/embeddedmontiarc-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
......@@ -7,9 +7,8 @@
can be found under https://github.com/MontiCore/monticore.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>montisim-server</groupId>
......@@ -21,13 +20,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<revision>2.2.5</revision>
<revision>2.2.6</revision>
<montisim.commons.version>1.0.11</montisim.commons.version>
<montisim.simulation.version>2.0.4</montisim.simulation.version>
<montisim.simulation.version>2.0.5</montisim.simulation.version>
<montisim.controller.version>1.0.4</montisim.controller.version>
<montisim.simulationlanguage.version>1.1.0-SNAPSHOT</montisim.simulationlanguage.version>
......@@ -72,7 +72,7 @@
<groupId>montisim</groupId>
<artifactId>commons</artifactId>
<version>${montisim.commons.version}</version>
<!-- <version>2.1.0-SNAPSHOT</version>-->
<!-- <version>2.1.0-SNAPSHOT</version>-->
<scope>provided</scope>
<!--<exclusions>
<exclusion>
......@@ -247,10 +247,10 @@
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -86,7 +86,6 @@ public class Util {
public static CarContainer getDefaultCarContainer() {
if (defaultCarContainer == null) {
defaultCarContainer = CarLangTool.parse(Paths.get("src/main/resources/default"), "default").get().getCarContainer();
defaultCarContainer.setController(getProperties().getProperty("v_model", "AutopilotAdapter"));
}
return defaultCarContainer;
}
......
......@@ -48,11 +48,37 @@ car default {
SENSOR_OBSTACLE;
}
controller = AutopilotAdapter;
controller {
software = Autopilot;
software_simulator = emu {
test_real;
}
time_model = models {
cpu_frequency = 3GHz;
memory_frequency = 2500MHz;
cache_IL1 {
size = 262144;
read = 4;
write = 4;
}
cache_DL1 {
size = 262144;
read = 4;
write = 4;
}
cache_L2 {
size = 2097152;
read = 6;
write = 6;
}
cache_L3 {
size = 12582912;
read = 40;
write = 40;
}
}
}
physics_model = mass_point;
cpu {
frequency = 3GHz;
memory_frequency = 2GHz;
}
}
\ No newline at end of file
......@@ -7,9 +7,8 @@
can be found under https://github.com/MontiCore/monticore.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>montisim-server</groupId>
......@@ -17,12 +16,12 @@
<version>${revision}</version>
<properties>
<revision>2.2.5</revision>
<revision>2.2.6</revision>
<montisim.commons.version>1.0.11</montisim.commons.version>
<montisim.simulation.version>2.0.4</montisim.simulation.version>
<montisim.simulation.version>2.0.5</montisim.simulation.version>
<montisim.controller.version>1.0.4</montisim.controller.version>
<montisim.carlang.version>1.0.2</montisim.carlang.version>
<montisim.rmimodelserver.version>1.1.4</montisim.rmimodelserver.version>
<montisim.carlang.version>1.0.3</montisim.carlang.version>
<montisim.rmimodelserver.version>1.1.6</montisim.rmimodelserver.version>
</properties>
<dependencies>
......@@ -200,14 +199,14 @@
<build>
<!--auto-protobuf java code generation-->
<!-- uncomment to generate protobuf code using maven-->
<!-- <extensions>-->
<!-- <extension>-->
<!-- <groupId>kr.motd.maven</groupId>-->
<!-- <artifactId>os-maven-plugin</artifactId>-->
<!-- <version>1.5.0.Final</version>-->
<!-- </extension>-->
<!-- </extensions>-->
<!-- uncomment to generate protobuf code using maven-->
<!-- <extensions>-->
<!-- <extension>-->
<!-- <groupId>kr.motd.maven</groupId>-->
<!-- <artifactId>os-maven-plugin</artifactId>-->
<!-- <version>1.5.0.Final</version>-->
<!-- </extension>-->
<!-- </extensions>-->
<plugins>
<plugin>
......@@ -220,25 +219,25 @@
</configuration>
</plugin>
<!-- uncomment to generate protobuf code using maven -->
<!-- <plugin>-->
<!-- <groupId>org.xolstice.maven.plugins</groupId>-->
<!-- <artifactId>protobuf-maven-plugin</artifactId>-->
<!-- <version>0.5.1</version>-->
<!-- <configuration>-->
<!-- <protocArtifact>com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier}</protocArtifact>-->
<!-- <pluginId>grpc-java</pluginId>-->
<!-- <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.16.1:exe:${os.detected.classifier}</pluginArtifact>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>compile</goal>-->
<!-- <goal>compile-custom</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- uncomment to generate protobuf code using maven -->
<!-- <plugin>-->
<!-- <groupId>org.xolstice.maven.plugins</groupId>-->
<!-- <artifactId>protobuf-maven-plugin</artifactId>-->
<!-- <version>0.5.1</version>-->
<!-- <configuration>-->
<!-- <protocArtifact>com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier}</protocArtifact>-->
<!-- <pluginId>grpc-java</pluginId>-->
<!-- <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.16.1:exe:${os.detected.classifier}</pluginArtifact>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>compile</goal>-->
<!-- <goal>compile-custom</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
......@@ -265,7 +264,7 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
......@@ -289,8 +288,8 @@
</plugins>
<finalName>rpc</finalName>
</build>
<distributionManagement>
<distributionManagement>
<repository>
<id>se-nexus</id>
<url>https://nexus.se.rwth-aachen.de/content/repositories/embeddedmontiarc-releases/</url>
......
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package server.adapters.AutoPilot;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.controller.commons.BusEntry;
import org.apache.commons.math3.linear.RealVector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.adapters.util.RMIClient;
import simulation.EESimulator.*;
import simulation.bus.Bus;
import simulation.bus.BusMessage;
import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
/**
* Wrapper for controller that calculates speed and path of the vehicle.
*/
public class AutopilotAdapterAsEEComponent extends ImmutableEEComponent {
private static final Logger LOG = LoggerFactory.getLogger(AutopilotAdapterAsFunctionBlock.class);
private static final int MAX_TRAJECTORY_LENGTH = 100;
private final RMIClient client;
private final double[] serializableTrajectoryX = new double[MAX_TRAJECTORY_LENGTH];
private final double[] serializableTrajectoryY = new double[MAX_TRAJECTORY_LENGTH];
private double maxTemporaryAllowedVelocity;
private Map<Object, BusEntry> lastValueByMessageId = new HashMap<>();
/**
* Necessary messages that the controller needs
*/
private static final ArrayList<BusEntry> STANDARD_SUBSCRIBED_MESSAGES = new ArrayList<BusEntry>() {{
add(BusEntry.SENSOR_VELOCITY);
add(BusEntry.SENSOR_GPS_COORDINATES);
add(BusEntry.SENSOR_COMPASS);
add(BusEntry.SENSOR_STREETTYPE);
add(BusEntry.ACTUATOR_ENGINE_CURRENT);
add(BusEntry.ACTUATOR_BRAKE_CURRENT);
add(BusEntry.ACTUATOR_STEERING_CURRENT);
add(BusEntry.PLANNED_TRAJECTORY_X);
add(BusEntry.PLANNED_TRAJECTORY_Y);
}};
/**
* Outputs for a MassPointPhysicalVehicle
*/
public static final ArrayList<BusEntry> MASSPOINT_OUTPUT_MESSAGES = new ArrayList<BusEntry>() {{
add(BusEntry.ACTUATOR_STEERING);
add(BusEntry.ACTUATOR_BRAKE);
add(BusEntry.ACTUATOR_ENGINE);
}};
boolean newInputs = false;
/**
* Determines if a controller execute event is currently scheduled
*/
boolean wakeUpNeeded = false;
/**
* The minimum time between two updates of the controller
*/
Duration cycleTime;
HashMap<String, Serializable> inputs = new HashMap<String, Serializable>();
HashMap<String, Serializable> outputs = new HashMap<String, Serializable>();
Optional<Object> trajectoryX = Optional.empty();
Optional<Object> trajectoryY = Optional.empty();
/**
* Time when the controller was executed last.
*/
Instant lastFinishTime;
/**
* Create a default AutopilotAdapterAsEEComponent.
* @param client RMIClient of the created AutopilotAdapterAsEEComponent
* @param duration Cycle time of the created AutopilotAdapterAsEEComponent
* @param buses Buses that the created AutopilotAdapterAsEEComponent is connected to
* @return The created AutopilotAdapterAsEEComponent.
*/
public static AutopilotAdapterAsEEComponent createAutopilotAdapterAsEEComponent(RMIClient client, Duration duration, List<Bus> buses) {
if(buses == null || buses.isEmpty()){
throw new IllegalArgumentException("At least one bus is needed to initialize the AutopilotAdapter");
}
HashMap<BusEntry, List<EEComponent>> targetsByMessageId = new HashMap<BusEntry, List<EEComponent>>();
List<EEComponent> eeComponents = new ArrayList<EEComponent>(buses);
targetsByMessageId.put(BusEntry.ACTUATOR_ENGINE, eeComponents);
targetsByMessageId.put(BusEntry.ACTUATOR_BRAKE, eeComponents);
targetsByMessageId.put(BusEntry.ACTUATOR_STEERING, eeComponents);
targetsByMessageId.put(BusEntry.VEHICLE_MAX_TEMPORARY_ALLOWED_VELOCITY, eeComponents);
return new AutopilotAdapterAsEEComponent(client, buses.get(0).getSimulator(), STANDARD_SUBSCRIBED_MESSAGES, targetsByMessageId, duration);
}
/**
* Create a default AutopilotAdapterAsEEComponent.
* @param client RMIClient of the created AutopilotAdapterAsEEComponent
* @param bus Bus that the created AutopilotAdapterAsEEComponent is connected to
* @return The created AutopilotAdapterAsEEComponent.
*/
public static AutopilotAdapterAsEEComponent createAutopilotAdapterAsEEComponent(RMIClient client, Bus bus) {
return createAutopilotAdapterAsEEComponent(client, Duration.ofMillis(33), Collections.singletonList(bus));
}
/**
* Create a default AutopilotAdapterAsEEComponent.
* @param client RMIClient of the created AutopilotAdapterAsEEComponent
* @param buses Buses that the created AutopilotAdapterAsEEComponent is connected to
* @return The created AutopilotAdapterAsEEComponent.
*/
public static AutopilotAdapterAsEEComponent createAutopilotAdapterAsEEComponent(RMIClient client, List<Bus> buses) {
return createAutopilotAdapterAsEEComponent(client, Duration.ofMillis(33), buses);
}
/**
* Create a default AutopilotAdapterAsEEComponent.
* @param client RMIClient of the created AutopilotAdapterAsEEComponent
* @param duration Cycle time of the created AutopilotAdapterAsEEComponent
* @param bus Bus that the created AutopilotAdapterAsEEComponent is connected to
* @return The created AutopilotAdapterAsEEComponent.
*/
public static AutopilotAdapterAsEEComponent createAutopilotAdapterAsEEComponent(RMIClient client, Duration duration, Bus bus) {
return createAutopilotAdapterAsEEComponent(client, duration, Collections.singletonList(bus));
}
public AutopilotAdapterAsEEComponent(RMIClient client, EESimulator simulator, List<BusEntry> subscribedMessages, HashMap<BusEntry, List<EEComponent>> targetsByMessageId, Duration cycleTime) {
super(simulator, EEComponentType.AUTOPILOT, subscribedMessages, targetsByMessageId);
// When created, maximum temporary allowed velocity is not limited
this.maxTemporaryAllowedVelocity = Double.MAX_VALUE;
this.client = client;
lastFinishTime = simulator.getSimulationTime();
this.cycleTime = cycleTime;
this.getSimulator().addEvent(new ControllerExecuteEvent(getSimulator().getSimulationTime().plus(cycleTime), this));
}
public AutopilotAdapterAsEEComponent(RMIClient client, EESimulator simulator, List<BusEntry> subscribedMessages, HashMap<BusEntry, List<EEComponent>> targetsByMessageId) {
this(client,simulator,subscribedMessages,targetsByMessageId, Duration.ofMillis(33));
}
public void setCycleTime(Duration cycleTime) {
this.cycleTime = cycleTime;
}
public Duration getCycleTime() {
return cycleTime;
}
@Override
public void processEvent(EEDiscreteEvent event){
//buffer new values arrived by busMessage
if (event.getEventType() == EEDiscreteEventTypeEnum.BUSMESSAGE) {
BusMessage currentMessage = (BusMessage) event;
newInputs = true;
switch (currentMessage.getMessageID()) {
case SENSOR_VELOCITY:
double currentVelocity = (double) currentMessage.getMessage();
this.inputs.put("currentVelocity", currentVelocity);
break;
case SENSOR_GPS_COORDINATES:
double x = ((RealVector) currentMessage.getMessage()).getEntry(0);
double y = ((RealVector) currentMessage.getMessage()).getEntry(1);
this.inputs.put("x", x);
this.inputs.put("y", y);
break;
case SENSOR_COMPASS:
double compass = (double) currentMessage.getMessage();
this.inputs.put("compass", compass);
break;
case ACTUATOR_ENGINE_CURRENT:
double engine = (double) currentMessage.getMessage();
this.inputs.put("currentEngine", engine);
break;
case ACTUATOR_BRAKE_CURRENT:
double brakes = (double) currentMessage.getMessage();
this.inputs.put("currentBrakes", brakes);
break;
case ACTUATOR_STEERING_CURRENT:
double steering = (double) currentMessage.getMessage();
this.inputs.put("currentSteering", steering);
break;
case PLANNED_TRAJECTORY_X:
this.trajectoryX = Optional.of(currentMessage.getMessage());
break;
case PLANNED_TRAJECTORY_Y:
this.trajectoryY = Optional.of(currentMessage.getMessage());
break;
case SENSOR_STREETTYPE:
this.maxTemporaryAllowedVelocity = this.calculateAllowedVelocityByStreetType((String) currentMessage.getMessage());
this.sendMessage(this.maxTemporaryAllowedVelocity, 8, BusEntry.VEHICLE_MAX_TEMPORARY_ALLOWED_VELOCITY, event.getEventTime());
break;
default:
throw new IllegalArgumentException("Received unsubscribed Message. Message type was: " + currentMessage.getMessageID().toString());
}
if (trajectoryX.isPresent() && trajectoryY.isPresent()) {
if (trajectoryX.get() instanceof List<?> && trajectoryY.get() instanceof List<?>) {
int trajectoryLength = processTrajectory((List<Double>) trajectoryX.get(), (List<Double>) trajectoryY.get());
this.inputs.put("trajectory_length", trajectoryLength);
}
}
if(wakeUpNeeded) {
executeController(event);
}
} else if (event.getEventType() == EEDiscreteEventTypeEnum.CONTROLLER_EXECUTE_EVENT) {
if(newInputs) {
executeController(event);