Commit de67ae35 authored by Jean Meurice's avatar Jean Meurice

Added Geometry Types, Simulation Rework Changes

parent 3cd40277
......@@ -5,9 +5,9 @@ This repository includes the interfaces and general functionality for the other
It should be noted that this repository should not have any dependencies on the other repositories - instead all other repositories are allowed to have this repository as dependency.
## JavaFX replacement
## Geometric Types
[Point2D](src/main/java/de/rwth/monticore/EmbeddedMontiArc/simulators/commons/utils/Point2D.java), [Point3D](src/main/java/de/rwth/monticore/EmbeddedMontiArc/simulators/commons/utils/Point3D.java) and [Pair](src/main/java/de/rwth/monticore/EmbeddedMontiArc/simulators/commons/utils/Pair.java) replace the classes of the same name from the JavaFX library.
TODO
## LibraryService
......
......@@ -12,7 +12,7 @@
<groupId>montisim</groupId>
<artifactId>commons</artifactId>
<version>1.0.11</version>
<version>1.1.0</version>
<properties>
......
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.controller.commons;
import org.apache.commons.math3.linear.RealVector;
/**
* this class provides all information for a vertex data structur for a general graph.
* It is widely used in this function block setting.
*
* Created by Christoph Grüne on 22.12.2016.
* @author Christoph Grüne.
*/
public class Vertex {
private Long id;
private Long osmId;
private Double maximumSteeringAngle;
private RealVector position;
private boolean intersectionNode = false;
public Vertex(Long id, Long osmID, RealVector position, Double maximumSteeringAngle) {
this.id = id;
this.osmId = osmID;
this.position = position;
this.maximumSteeringAngle = maximumSteeringAngle;
}
/**
* copy constructor for Vertex
*/
public Vertex copy() {
return new Vertex(this.id.longValue(), this.osmId.longValue(), this.position.copy(), this.maximumSteeringAngle.doubleValue());
}
/**
* Setter for maximumVelocity
*
* @param maximumSteeringAngle the new maximumVelocity
*/
public void setMaximumSteeringAngle(double maximumSteeringAngle) {
this.maximumSteeringAngle = maximumSteeringAngle;
}
/**
* Function that sets intersectionNode
*
* @param intersectionNode New value for intersectionNode
*/
public void setIntersectionNode(boolean intersectionNode) {
this.intersectionNode = intersectionNode;
}
/**
* Function that returns intersectionNode
*
* @return Value for intersectionNode
*/
public boolean isIntersectionNode() {
return intersectionNode;
}
/**
* Getter for the ID of this vertex
*
* @return the ID
*/
public Long getId() {
return new Long(id.longValue());
}
/**
* Setter for vertex ID
*
* @param id
*/
public void setId(long id) {
this.id = id;
}
/**
* Getter for the OSM ID of this vertex
*
* @return the OSM ID
*/
public Long getOsmId() {
return new Long(osmId.longValue());
}
/**
* Getter for the maximal velocity one can drive at this vertex
*
* @return the maximal velocity
*/
public Double getMaximumSteeringAngle() {
return new Double(maximumSteeringAngle.doubleValue());
}
/**
* Getter for the position of this vertex
*
* @return the position
*/
public RealVector getPosition() {
return position.copy();
}
/**
* Test for the equality of two vertices. If all attributes are the same the vertices are considered to be equal.
*
* @param obj the object to test
* @return if the objects are equal
*/
@Override
public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) {
return false;
}
Vertex otherVertex = (Vertex) obj;
if(!otherVertex.getMaximumSteeringAngle().equals(this.getMaximumSteeringAngle())) {
return false;
} else if(!otherVertex.getOsmId().equals(this.getOsmId())) {
return false;
} else if(!otherVertex.getId().equals(this.getId())) {
return false;
} else if (!otherVertex.getPosition().equals(this.getPosition())) {
return false;
}
return true;
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.map;
/**
* Created by lukas on 31.01.17.
*/
public class Adjacency implements IAdjacency{
private IControllerNode node1;
private IControllerNode node2;
private long streetId;
private double distance;
public Adjacency(IControllerNode node1, IControllerNode node2) {
this.node1 = node1;
this.node2 = node2;
this.distance = node1.getPoint().distance(node2.getPoint());
}
@Override
public IControllerNode getNode1() {
return this.node1;
}
@Override
public IControllerNode getNode2() {
return this.node2;
}
@Override
public double getDistance() {
return this.distance;
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.map;
import de.rwth.monticore.EmbeddedMontiArc.simulators.commons.utils.Point3D;
/**
* Created by lukas on 31.01.17.
*/
public interface IControllerNode {
public final long INTERPOLATED_NODE = -1;
public final double INTERPOLATION_DISTANCE = 2;
public abstract Point3D getPoint();
public abstract long getId();
public abstract long getOsmId();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation;
import org.apache.commons.math3.linear.RealVector;
/**
* Interface that represents a physical vehicle in 3D space.
* Any positions and vectors are, if not stated otherwise, expressed in the global coordinate system.
* All values are expressed in SI units.
*/
public interface IPhysicalVehicle extends PhysicalObject {
/**
* Function that returns the wheel radius of the physical vehicle
* @return Wheel radius of the physical vehicle
*/
double getWheelRadius();
/**
* Function that returns the steering angle of the physical vehicle
* @return Steering angle of the physical vehicle
*/
double getSteeringAngle();
/**
* Function that returns a copy of the position vector of the center of the front right wheel
* @return Position vector of the center of the front right wheel
*/
RealVector getFrontRightWheelGeometryPosition();
/**
* Function that returns a copy of the position vector of the center of the front left wheel
* @return Position vector of the center of the front left wheel
*/
RealVector getFrontLeftWheelGeometryPosition();
/**
* Function that returns a copy of the position vector of the center of the back right wheel
* @return Position vector of the center of the back right wheel
*/
RealVector getBackRightWheelGeometryPosition();
/**
* Function that returns a copy of the position vector of the center of the back left wheel
* @return Position vector of the center of the back left wheel
*/
RealVector getBackLeftWheelGeometryPosition();
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
import java.time.Duration;
import java.util.List;
import java.util.Map;
/**
* Interface that represents a box shaped physical object in a 3D space, that can be rotated.
* Any positions and vectors are, if not stated otherwise, expressed in the global coordinate system.
* All values are, if not stated otherwise, expressed in SI units.
*/
public interface PhysicalObject {
/**
* Function that returns a copy of the center of mass position vector
* @return Position vector of the center of mass
*/
RealVector getPosition();
/**
* Function that sets the center of mass position vector
* @param position New position vector of the center of mass
*/
void setPosition(RealVector position);
/**
* Function that returns a copy of the rotation matrix around the center of mass
* @return Rotation matrix around the center of mass
*/
RealMatrix getRotation();
/**
* Function that sets the rotation matrix around the center of mass
* @param rotation New rotation matrix around the center of mass
*/
void setRotation(RealMatrix rotation);
/**
* Function that returns a copy of the velocity vector of the center of mass
* @return Velocity vector of the center of mass
*/
RealVector getVelocity();
/**
* Function that sets the velocity vector of the center of mass
* @param velocity New velocity vector of the center of mass
*/
void setVelocity(RealVector velocity);
/**
* Function that returns a copy of the angular velocity vector around the center of mass
* @return Angular velocity vector around the center of mass
*/
RealVector getAngularVelocity();
/**
* Function that sets the angular velocity vector around the center of mass
* @param angularVelocity New angular velocity around of the center of mass
*/
void setAngularVelocity(RealVector angularVelocity);
/**
* Function that adds an external force acting on the center of mass
* @param force Force vector that acts on the center of mass
*/
void addForce(RealVector force);
/**
* Function that add an external torque acting around the center of mass
* @param torque Torque vector that acts around the center of mass
*/
void addTorque(RealVector torque);
/**
* Function that returns the mass of the object
* @return Mass of the physical object
*/
double getMass();
/**
* Function that sets the mass of the object
* @param mass New mass of the physical object
*/
void setMass(double mass);
/**
* Function that returns the width of the object
* @return Width of the object
*/
double getWidth();
/**
* Function that sets the width of the object
* @param width New width of the object
*/
void setWidth(double width);
/**
* Function that returns the length of the object
* @return Length of the object
*/
double getLength();
/**
* Function that sets the length of the object
* @param length New length of the object
*/
void setLength(double length);
/**
* Function that returns the height of the object
* @return Height of the object
*/
double getHeight();
/**
* Function that sets the height of the object
* @param height New height of the object
*/
void setHeight(double height);
/**
* Function that returns a copy of center of geometry position vector
* @return Position vector of the center of geometry
*/
RealVector getGeometryPosition();
/**
* Function that sets the center of geometry position vector.
* @param geometryPosition New position vector of the center of geometry
*/
void setGeometryPosition(RealVector geometryPosition);
/**
* Function that returns a copy of the vector pointing from the center of mass position to the center of geometry position
* @return Offset vector of the center of mass position to the center of geometry position
*/
RealVector getGeometryPositionOffset();
/**
* Function that sets the vector pointing from the center of mass position to the center of geometry position
* @param geometryPositionOffset New offset vector of the center of mass position to the center of geometry position
*/
void setGeometryPositionOffset(RealVector geometryPositionOffset);
/**
* Function that returns the type of the physical object
* @return Type of the physical object
*/
PhysicalObjectType getPhysicalObjectType();
/**
* Function that returns the error flag
* @return Error flag of the physical object
*/
boolean getError();
/**
* Function that sets the error flag
* @param error New Error flag of the physical object
*/
void setError(boolean error);
/**
* Function that returns the collision flag
* @return Collision flag of the physical object
*/
boolean getCollision();
/**
* Function that sets the collision flag
* @param collision New collision flag of the physical object
*/
void setCollision(boolean collision);
/**
* Function that returns the id of the physical object
* @return Id of the physical object
*/
long getId();
/**
* Function that returns a list of pairs of 3D coordinates, indicating a vector on the edges of the physical object
* @return List of pairs of 3D points, indicating a vector on the edges of the physical object
*/
List<Map.Entry<RealVector, RealVector>> getBoundaryVectors();
// ToDo is unnecessary with three dimensional collision detection
/**
* Function that computes one step of the physical behaviour of the object
* @param deltaTime Duration of the current simulation step
*/
void computePhysics(Duration deltaTime);
/**
* Function that sets the position of the center of mass and the rotation of the object, in order to place the object on the surface of the world.
* given a x, y coordinate and a z rotation
* @param posX X component of the position of the physical object
* @param posY Y component of the position of the physical object
* @param rotZ Z component of the rotation of the physical object
*/
void putOnSurface(double posX, double posY, double rotZ);
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.monticore.EmbeddedMontiArc.simulators.commons.simulation;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
/**
* Informs objects about state changes in the simulation. To be informed about
* the simulation loop, you first need to register the object to the shared
* instance of the simulator using registerLoopObserver().
* Override the required functions to get notified for a given simulation event.
*/
public abstract class SimulationLoopNotifiable {
/**
* Is called just before the simulation objects update their states.
*
* @param simulationObjects List of all simulation objects
* @param totalTime Total simulation time
* @param deltaTime Delta simulation time
*/
public void willExecuteLoop(List<SimulationLoopExecutable> simulationObjects, Instant totalTime, Duration deltaTime) {}
/**
* Is called after the simulation objects updated their states.
*
* @param simulationObjects List of all simulation objects
* @param totalTime Total simulation time
* @param deltaTime Delta simulation time
*/
public void didExecuteLoop(List<SimulationLoopExecutable> simulationObjects, Instant totalTime, Duration deltaTime) {}
/**
* Is called for each object just before the simulation objects update their states.
*
* @param simulationObject Object for which the loop will be executed
* @param totalTime Total simulation time
* @param deltaTime Delta simulation time
*/
public void willExecuteLoopForObject(SimulationLoopExecutable simulationObject, Instant totalTime, Duration deltaTime) {}
/**
* Is called for each object after the simulation objects updated their states.
*
* @param simulationObject Object for which the loop iteration has been completed
* @param totalTime Total simulation time
* @param deltaTime Delta simulation time
*/
public void didExecuteLoopForObject(SimulationLoopExecutable simulationObject, Instant totalTime, Duration deltaTime) {}
/**
* Is called just before the simulation starts
*
* @param simulationObjects List of all simulation objects
*/