Commit 746b4c18 authored by Jean Meurice's avatar Jean Meurice
Browse files

JavaAutopilot, Documentation Structure

parent 94269565
Pipeline #290743 canceled with stage
in 2 seconds
......@@ -6,46 +6,44 @@ stages:
- linux
- integration-test
#masterJobLinux:
# stage: linux
# image: maven:3.6-jdk-8
# before_script:
# - apt-get update
# - apt-get install -y openjfx
# script:
# - mv lib/fmu_for_linux/*.fmu lib/
# - mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy sonar:sonar --settings settings.xml
## - cat report/target/coverage-report/html/index.html
# only:
# - master
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_OS
only:
- master
branchJobWindows:
stage: windows
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
tags:
- Windows10_OS
except:
MasterJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- mvn -B clean deploy sonar:sonar -s settings.xml
#- cat report/target/coverage-report/html/index.html
only:
- master
# BranchJobLinux:
# stage: linux
# image: hwzzz/openjdk-openjfx:latest
BranchJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- mvn -B clean install -s settings.xml
#- cat report/target/coverage-report/html/index.html
except:
- master
# masterJobWindows:
# stage: windows
# script:
# - mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
# - cat report/target/coverage-report/html/index.html
# except:
# - mvn clean deploy -s settings.xml
# - mvn package sonar:sonar -s settings.xml
# tags:
# - Windows10_OS
# only:
# - master
# branchJobWindows:
# stage: windows
# script:
# - mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
# tags:
# - Windows10_OS
# except:
# - master
#IntegrateionTest:
# tags:
......
# Simulation
![pipeline](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/simulation/badges/master/build.svg)
![coverage](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/simulation/badges/master/coverage.svg)
This repository includes the classes for the management of the simulation, the physics computations, the environment, the sensors and the vehicles.
## [Documentation for this project](docs/documentation/readme.md)
Discrete time steps are used to advance the simulation.
To use the different sub-project as maven dependency, add the following to your pom's `<dependencies>`:
The environment is created by parsing OpenStreetMap data.
# Vehicle Dynamics Model
A vehicle dynamics model is used to calculate the physical behaviour for a car in the simulation. This vehicle dynamics model is modeled in Modelica and then compiled into functional mock-up units. These units are then accessed and used in the `VehicleDynamicsModel` class.
To compile updated Modelica models into functional mock-up units, the _.mo_ files (the models) have to be exported via FMI into a _.fmu_ file using the OpenModelica Connection Editor v.1.12.0 (64-bit).
__NOTE:__ When new fmu's are added to the simulation, the _deployment.bat_ that copies the fmu's into the SmartFoxServer has to be updated as well.
The settings are:
* Version: 2.0
* Type: Co-Simulation
* Platform: Static
# Simulation Debugging and Debug Plotter
To quickly debug the simulator, a simulation can be configured and executed without starting up the server. An example is given in the `firstTest()` jUnit test in the `SimulatieVehicleTest` test class.
The debug plotter can be used to visualize a simulation that contains only __one__ physical vehicle. A use case for the debug plotter is also given in `firstTest()`. The plotter is registered to the simulation as an observer and is then generating one visualisation chart for each loop iteration.
# Height data
Height data is read from SRTM files, which are documented [here](https://dds.cr.usgs.gov/srtm/version2_1/Documentation/SRTM_Topo.pdf). Additional height data files can be downloaded from [this source](https://dds.cr.usgs.gov/srtm/version2_1/SRTM3/), where you need to select the continent and then search for the file you need. The file name format is dependent on latitude/longitude and defined as `[N/S][<LAT>][O/W][<LONG>].hgt`.
Each file contains data until the next higher latitude/longitude. For example file N50E006.hgt will cover all pairs of (latitude,longitude) from (50,6) to (51,7) (with resolution 3/3600=0.000833).
To determine min/max latitude/longitude, the file names of all loaded height data files need to be parsed according to the described format and then compared to find the lowest/highest values. Let's say N50E006.hgt and N51E006.hgt are loaded, then you would get minLat=50, minLong=6, maxLat=52, maxLong=7.
```xml
<dependency>
<groupId>montisim</groupId>
<artifactId>"sub-project name"</artifactId>
<version>${revision}</version>
</dependency>
```
# README
- Link to documentation
- How to include in other projects
# Documentation
- Introduction
- How to build
- Structure Overview
- Link to commons documentation
## Environment
- World
- Osm
- Pathfinding
## EESimulator
- EESimulator/Structure
- Components/Component Manager
- Discrete Events system/Events
- Messages/Types
- EE Setup / Validation
- Creating new components
- Buses, Bridges
- Sensors, Actuators
## Vehicle
- Structure
- DynamicObject/PhysicalValues
- Physics Model
- PowerTrain
- Builder/Config/Properties
## eecomponents
- Navigation
- Autopilots
## Simulator
- Simulator/Loop
- Vehicle Configs
## Debug Visualization
- Viewer, SimulationRunner/Control
- Renderers
\ No newline at end of file
[Documentation Root](readme.md) | [Previous (Simulator)](simulator.md)
# Debug Visualization
## Viewer, SimulationRunner/Control
## Renderers
\ No newline at end of file
[Documentation Root](readme.md) | [Previous (Vehicle)](vehicle.md) | [Next (Simulator)](simulator.md)
# EEComponents
## Navigation
## Autopilots
\ No newline at end of file
[//]: # (These documents are best viewed in their formatted form, e.g. in the online gitlab file viewer.)
[Documentation Root](readme.md) | [Previous (Environment)](environment.md) | [Next (Vehicle)](vehicle.md)
TODO
- EESimulator/Structure
- Components/Component Manager
- Discrete Events system/Events
- Messages/Types
- EE Setup / Validation
- Creating new components
- Buses, Bridges
- Sensors, Actuators
# EESimulator
> *__EE__ comes from "Electrical & Electronic Systems"*
The `EESimulator` sub-project handles the transmission and processing of **discrete events** inside a vehicle. These discrete events mainly have the form of **messages** between **ee-components** across communication **buses**.
> *__EE__ comes from "Electrical & Electronic Systems"*
## Usage
Users of this sub-project can either instance the `EESimulator` as part of their vehicle or inherit the `EEComponent` class to create new components that work inside the ee-vehicle.
......
[Documentation Root](readme.md) | [Previous (EESimulator)](eesimulator.md) | [Next (Vehicle)](vehicle.md)
# Environment
## World
## Osm
## Pathfinding
\ No newline at end of file
[//]: # (These documents are best viewed in their formatted form, e.g. in the online gitlab file viewer.)
# Simulation Documentation
## Sub-Projects
- [Environment](environment.md)
- [EESimulator](eesimulator.md)
- [Vehicle](vehicle.md)
- [EEComponents](eecomponents.md)
- [Simulator](simulator.md)
- [Debug Visualization](debugvis.md)
[Documentation]() of the `Commons` project TODO LINK
## Introduction
## How to build
## Structure Overview
\ No newline at end of file
[Documentation Root](readme.md) | [Previous (Vehicle)](vehicle.md) | [Next (Debug Visualization)](debugvis.md)
# Simulator
## Simulator/Loop
## Vehicle Configs
\ No newline at end of file
[Documentation Root](readme.md) | [Previous (EESimulator)](eesimulator.md) | [Next (EEComponents)](eecomponents.md)
# Vehicle
## Structure
## DynamicObject/PhysicalValues
## Physics Model
## PowerTrain
## Builder/Config/Properties
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="125" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="anybadge_1">
<rect width="98" height="20" rx="3" fill="#fff"/>
</mask>
<g mask="url(#anybadge_1)">
<path fill="#b0dbfc" d="M0 0h98v20H0z"/>
<!-- <path fill="#4c1" d="M97 0h28v20H97z"/> -->
<path fill="url(#b)" d="M0 0h125v20H0z"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="49.5" y="15" fill="#010101" fill-opacity=".3">Documentation</text>
<text x="48.5" y="14">Documentation</text>
</g>
</svg>
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.simulator.autopilots;
package de.rwth.montisim.simulation.eecomponents.autopilots;
import java.time.Duration;
import java.time.Instant;
......@@ -17,7 +17,6 @@ import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
import de.rwth.montisim.simulation.eesimulator.exceptions.EEMessageTypeException;
import de.rwth.montisim.simulation.eesimulator.message.Message;
import de.rwth.montisim.simulation.eesimulator.message.MessageInformation;
import de.rwth.montisim.simulation.vehicle.autopilots.PID;
import de.rwth.montisim.simulation.vehicle.physicalvalues.TrueCompass;
import de.rwth.montisim.simulation.vehicle.physicalvalues.TruePosition;
import de.rwth.montisim.simulation.vehicle.physicalvalues.TrueVelocity;
......@@ -26,7 +25,7 @@ import de.rwth.montisim.simulation.vehicle.powertrain.PowerTrainProperties;
public class JavaAutopilot extends EEComponent {
final JavaAutopilotProperties properties;
public static final double MAX_DEVIATION = 5; // max allowed deviation from the trajectory "corners" (in meters)
public static final double MAX_DEVIATION = 3; // max allowed deviation from the trajectory "corners" (in meters)
public static final double ORTHO_DIST = MAX_DEVIATION/(Math.sqrt(2)-1); // max allowed deviation from the trajectory "corners" (in meters)
MessageInformation velocityMsg;
......@@ -141,6 +140,10 @@ public class JavaAutopilot extends EEComponent {
final Vec2 targetDir = new Vec2();
final Vec2 carDir = new Vec2();
// TEMP
int mode = 0;
int target = 0;
void compute(Instant startTime) {
if (currentPosition == null || Double.isNaN(currentCompass)) return;
double carAngle = currentCompass * Geometry.DEG_TO_RAD;
......@@ -163,77 +166,107 @@ public class JavaAutopilot extends EEComponent {
return;
}
// Get current segment & next
currSeg.initFromTraj(index);
// Set Default Target
targetSeg = currSeg;
boolean hasNext = index + 2 < trajX.length;
if (hasNext){
nextSeg.initFromTraj(index+1);
// Eval junction turn
double junctionAngle = Math.acos(IPM.dot(currSeg.dir, nextSeg.dir));
double junctionSign = Math.signum(IPM.dot(normal, nextSeg.dir));
double maxRadius = junctionAngle == 0 ? Double.POSITIVE_INFINITY : MAX_DEVIATION / ((1/Math.cos(junctionAngle*0.5)) - 1);
double maxDistToCorner = Math.sqrt(MAX_DEVIATION * (MAX_DEVIATION + maxRadius*2));
double dt = getDeltaTime(startTime);
// Check if "in turn"
if (currSeg.projDistToEnd <= maxDistToCorner){
targetSeg = nextSeg;
}
}
SegmentPos targetSeg = findTargetSegment(index);
// Now that we have a target segment, we follow it
double turnOutput = 0;
double speedOutput = 0;
// Wether the car is pointing towards the segment
boolean towardsSeg = targetSeg.orthoPos * IPM.dot(targetSeg.normal, carDir) < 0;
// Wether the car is pointing in the direction of the trajectory
boolean towardsEnd = IPM.dot(targetSeg.dir, carDir) > 0;
boolean carTowardsSeg = targetSeg.orthoPos * IPM.dot(targetSeg.normal, carDir) < 0;
boolean carTowardsEnd = IPM.dot(targetSeg.dir, carDir) > 0;
double segmentAngle = Math.acos(targetSeg.dir.x) * Math.signum(targetSeg.dir.y);
// Define TURNING to align with target (depending on distance, orientation & speed)
double targetAngle = segmentAngle;
// Target angle (relative to segment)
double targetAngleRel = targetSeg.dist < ORTHO_DIST ? Math.acos(1-targetSeg.dist/ORTHO_DIST) : Math.PI*0.5;
targetAngle += targetAngleRel * Math.signum(-targetSeg.orthoPos);
targetDir.set(Math.cos(targetAngleRel), Math.sin(targetAngleRel));
double margin = 0.2;
double targetAngleRel = targetSeg.dist < margin ?
0 :
targetSeg.dist < ORTHO_DIST ?
Math.acos(1+(margin-targetSeg.dist)/ORTHO_DIST) :
Math.PI*0.5;
// If targetDir attained: check if "tangent turn" is possible
// targetDir attained = car pointing between orthogonal to segment & targetDir (CHECK symmetric +/- versions)
if (true) {
if (carTowardsSeg && carTowardsEnd && Math.abs(carAngle - segmentAngle) < targetAngleRel) {
if (mode == 0) {
//System.out.println("Tangent turn");
mode = 1;
}
// Find the radius of a circle tangent to the segment and the car position
double junctionAngle = Math.acos(IPM.dot(targetSeg.dir, carDir));
double radius = Math.tan( (Math.PI - junctionAngle)*0.5) * targetSeg.dist / IPM.dot(carDir, targetSeg.normal);
turnOutput = 452/radius * Math.signum(-targetSeg.orthoPos);
} else {
if (mode == 1) {
//System.out.println("Follow angle");
mode = 0;
}
double targetAngle = segmentAngle;
targetAngle += targetAngleRel * Math.signum(-targetSeg.orthoPos);
targetDir.set(Math.cos(targetAngleRel), Math.sin(targetAngleRel));
while (targetAngle > carAngle+Math.PI) targetAngle -= 2*Math.PI;
while (targetAngle < carAngle-Math.PI) targetAngle += 2*Math.PI;
turnOutput = turnPid.compute(dt, carAngle, targetAngle);
turnOutput *= Geometry.RAD_TO_DEG;
}
// Eval required speed -> in order to arrive at next turn with desired max speed or arrive at speed 0 at end
// Respect max speed
while (targetAngle > carAngle+Math.PI) targetAngle -= 2*Math.PI;
while (targetAngle < carAngle-Math.PI) targetAngle += 2*Math.PI;
double finalTargetSpeed = 30;
speedOutput = speedPid.compute(dt, currentVelocity, finalTargetSpeed);
speedOutput /= 3.6; // Convert to m/s related space
speedOutput /= properties.maxVehicleAccel; // Convert to [0:1] actuator range
double dt = 0;
sendMessage(sendTime, steeringMsg, turnOutput);
sendMessage(sendTime, accelMsg, speedOutput);
}
private double getDeltaTime(Instant time) {
if (lastTime == null) {
lastTime = startTime;
lastTime = time;
return 0;
} else {
dt = Time.secondsFromDuration(Duration.between(lastTime, startTime));
return Time.secondsFromDuration(Duration.between(lastTime, time));
}
}
double speedOutput = speedPid.compute(dt, currentVelocity, finalTargetSpeed);
speedOutput /= 3.6; // Convert to m/s related space
double accel = speedOutput / properties.maxVehicleAccel; // Convert to [0:1] actuator range
SegmentPos findTargetSegment(int index) {
currSeg.initFromTraj(index);
double turnOutput = turnPid.compute(dt, carAngle, targetAngle);
turnOutput *= Geometry.RAD_TO_DEG;
sendMessage(sendTime, steeringMsg, turnOutput);
sendMessage(sendTime, accelMsg, accel);
boolean hasNext = index + 2 < trajX.length;
if (hasNext){
nextSeg.initFromTraj(index+1);
// Eval junction turn
double junctionAngle = Math.acos(IPM.dot(currSeg.dir, nextSeg.dir));
double junctionSign = Math.signum(IPM.dot(normal, nextSeg.dir));
double maxRadius = junctionAngle == 0 ? Double.POSITIVE_INFINITY : MAX_DEVIATION / ((1/Math.cos(junctionAngle*0.5)) - 1);
double maxDistToCorner = Math.sqrt(MAX_DEVIATION * (MAX_DEVIATION + maxRadius*2));
// Check if "in turn"
if (currSeg.projDistToEnd <= maxDistToCorner){
if (target == 0){
target = 1;
//System.out.println("Following NEXT segment");
}
return nextSeg;
}
}
target = 0;
return currSeg;
}
final Vec2 normal = new Vec2();
......
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.simulator.autopilots;
package de.rwth.montisim.simulation.eecomponents.autopilots;
import java.time.Duration;
......
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.vehicle.autopilots;
package de.rwth.montisim.simulation.eecomponents.autopilots;
public class PID {
final double P;
......
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.vehicle.autopilots;
package de.rwth.montisim.simulation.eecomponents.autopilots;
import java.time.*;
......@@ -10,7 +10,7 @@ import de.rwth.montisim.simulation.eesimulator.components.*;
import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
import de.rwth.montisim.simulation.eesimulator.exceptions.EEMessageTypeException;
import de.rwth.montisim.simulation.eesimulator.message.*;
import de.rwth.montisim.simulation.vehicle.autopilots.TestAutopilotProperties.Mode;
import de.rwth.montisim.simulation.eecomponents.autopilots.TestAutopilotProperties.Mode;
import de.rwth.montisim.simulation.vehicle.physicalvalues.TrueVelocity;
import de.rwth.montisim.simulation.vehicle.powertrain.PowerTrainProperties;
......
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.vehicle.autopilots;
package de.rwth.montisim.simulation.eecomponents.autopilots;
import java.time.Duration;
......
# Simulator Sub-Project
## [Documentation for this sub-project](../docs/documentation/simulator.md)
To use this sub-project as maven dependency:
```xml
<dependency>
<groupId>montisim</groupId>
<artifactId>simulator</artifactId>
<version>${revision}</version>
</dependency>
```
......@@ -10,11 +10,11 @@ import de.rwth.montisim.commons.simulation.TimeUpdate;
import de.rwth.montisim.commons.utils.*;
import de.rwth.montisim.simulation.eesimulator.exceptions.*;
import de.rwth.montisim.simulation.eesimulator.message.MessageTypeManager;
import de.rwth.montisim.simulation.eecomponents.autopilots.TestAutopilotProperties;
import de.rwth.montisim.simulation.simulator.visualization.car.CarRenderer;
import de.rwth.montisim.simulation.simulator.visualization.plotter.TimePlotter;
import de.rwth.montisim.simulation.simulator.visualization.ui.*;
import de.rwth.montisim.simulation.vehicle.*;
import de.rwth.montisim.simulation.vehicle.autopilots.TestAutopilotProperties;
import de.rwth.montisim.simulation.vehicle.config.*;
import de.rwth.montisim.simulation.vehicle.physicsmodel.rigidbody.RigidbodyPhysics;
......
......@@ -15,14 +15,14 @@ import de.rwth.montisim.simulation.environment.osmmap.*;
import de.rwth.montisim.simulation.environment.world.World;
import de.rwth.montisim.simulation.environment.pathfinding.*;
import de.rwth.montisim.simulation.simulator.*;
import de.rwth.montisim.simulation.simulator.autopilots.JavaAutopilotProperties;
import de.rwth.montisim.simulation.eecomponents.autopilots.JavaAutopilotProperties;
import de.rwth.montisim.simulation.eecomponents.autopilots.TestAutopilotProperties;
import de.rwth.montisim.simulation.simulator.vehicleconfigs.DefaultVehicleConfig;
import de.rwth.montisim.simulation.simulator.visualization.car.CarRenderer;
import de.rwth.montisim.simulation.simulator.visualization.map.*;
import de.rwth.montisim.simulation.simulator.visualization.plotter.TimePlotter;
import de.rwth.montisim.simulation.simulator.visualization.ui.*;
import de.rwth.montisim.simulation.vehicle.Vehicle;
import de.rwth.montisim.simulation.vehicle.autopilots.TestAutopilotProperties;
import de.rwth.montisim.simulation.vehicle.config.VehicleConfig;
import de.rwth.montisim.simulation.vehicle.physicsmodel.rigidbody.RigidbodyPhysics;
......
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