Commit fd46ba14 authored by Danilo Lourenco Trotta's avatar Danilo Lourenco Trotta

Merge branch 'master' into danilo2

parents 82eb34dd a4b5a0bb
Pipeline #117079 passed with stage
in 2 minutes and 34 seconds
......@@ -27,14 +27,19 @@ or download the project as a [.zip file](https://github.com/MontiSim/server/arch
__NOTE:__ _MontiSim_ is the directory, in which MontiSim-belonging projects should be clonned. It has to be manually created.
Additionally [RMIModelServer](https://github.com/MontiSim/RMIModelServer) repository has to be cloned, in order to be used and to allow integration of external vehicle models. This can be done via the following commands:
Additionally [RMIModelServer](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/RMIModelServer) repository has to be cloned, in order to be used and to allow integration of external vehicle autopilot models. This can be done via the following commands:
cd MontiSim
git clone https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/RMIModelServer.git
cd ./RMIModelServer
mvn clean install
./scripts/compile_install.bat or ./scripts/compile_install.sh
To use an external vehicle model, one has to clone the corresponding repository. For the _Autopilot emam_ vehicle model, located in [Autopilot emam repository](https://github.com/MontiSim/EMAM-showcase), the following commands have to be executed:
The RMIModelServer uses the [HardwareEmulator](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/hardware_emulator) project to run the autopilots.
A pre-compiled version of the HardwareEmulator is contained in the `install` folder of the RMI server.
The install folder also contains a `run.bat` / `run.sh` script that starts the RMI server within the install folder and uses the `autopilots` folder it contains to load autopilots.
The install folder has to be updated if a new version of the _HardwareEmulator_ is used.
To use an external vehicle autopilot, one has to clone the corresponding repository. For the _Autopilot emam_ vehicle model, located in [Autopilot emam repository](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/EMAM-showcase), the following commands have to be executed:
cd MontiSim
git clone https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/simulators/EMAM-showcase.git
......@@ -43,10 +48,8 @@ To use an external vehicle model, one has to clone the corresponding repository.
main.bat
The last command `main.bat` will compile the model and run it in a server container to test it. One can close the server container right after its start, since the only reason the `main.bat` is used in current case is to generate the _Autopilot_ dll library.
__NOTE:__ Autopilot EMAM model works only in _Windows 64 bit_ environment.
To run the RMIModelServer, one has to run the `run.bat` or `run.sh` scripts located in `RMIModelServer/scripts/` directory. Pay attention to the version of the RMIModelServer. The filename of the form `rmi-model-server-*.jar` (where * stands for some version) in `run.bat` should match the generated jar-file in the `RMIModelServer/target/` directory.
This dll (os `.so` for linux) file can be renamed to a desired autopilot name and placed inside the `autopilots` folder used by the RMIModelServer.
This folder contains the last version of the _EMAM-showcase_ autopilot (_AutopilotAdapter_).
# Installation
......
sqlite3 world.db ".read sqlite-world.sql"
\ No newline at end of file
......@@ -175,7 +175,7 @@
<dependency>
<groupId>montisim</groupId>
<artifactId>rmi-model-server</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>
<!-- Autopilot -->
<dependency>
......
This diff is collapsed.
This diff is collapsed.
......@@ -14,6 +14,7 @@ import de.se_rwth.commons.logging.Log;
import rwth.server.bo.util.Logger;
import rwth.server.pojo.MapArea;
import rwth.server.pojo.MapSector;
import simulation.environment.object.House;
import simulation.environment.osm.Parser2D;
import simulation.environment.osm.ParserSettings;
import simulation.environment.visualisationadapter.implementation.Bounds2D;
......
......@@ -63,7 +63,7 @@ public class StreetDao {
return new Street2D(nodes, row.getDouble("speed_limit"), intersections, osmId,
DataConverter.getBool(row.getInt("isoneway")),
StreetTypes.valueOf(row.getUtfString("street_type")));
StreetTypes.valueOf(row.getUtfString("street_type")), EnvStreet.StreetPavements.QUALITY);
}catch (SQLException e){
console.trace(ExtensionLogLevel.ERROR, e);
}
......@@ -123,7 +123,7 @@ public class StreetDao {
//register street, when all the nodes and intersections for it, have been fetched
if(osmId == null || osmId.longValue() != row.getLong("osmid")) {
if(nodes != null && nodes.size() > 1) { //street can not be defined by only one node
result.add(new Street2D(nodes, speedLimit, intersections, osmId, isOneWay, stype, sPavement));
result.add(new Street2D(nodes, speedLimit, intersections, osmId, isOneWay, stype, EnvStreet.StreetPavements.QUALITY));
}
//prepare new street data
speedLimit = row.getInt("speed_limit");
......@@ -145,7 +145,7 @@ public class StreetDao {
}
//add last street
if(nodes != null && nodes.size() > 1 && osmId != null && intersections != null && stype != null)
result.add(new Street2D(nodes, speedLimit, intersections, osmId, isOneWay, stype, sPavement));
result.add(new Street2D(nodes, speedLimit, intersections, osmId, isOneWay, stype, EnvStreet.StreetPavements.QUALITY));
return result;
}catch (SQLException e){
......
......@@ -87,7 +87,6 @@ public class RoomExt extends SFSExtension {
addEventListener(SFSEventType.USER_JOIN_ROOM, this);
addEventListener(SFSEventType.USER_LEAVE_ROOM, this);
}
@Override
......
......@@ -322,7 +322,8 @@ public class SimulationController implements SimulationLoopNotifiable {
* @return PhysicalVehicle
*/
private PhysicalVehicle setupVehicle() {
RMIClient rmiClient = new RMIClient(this.RMIhost, this.RMIport, this.vehicleModel);
String autopilot_configuration = "autopilot="+ this.vehicleModel;
RMIClient rmiClient = new RMIClient(this.RMIhost, this.RMIport, autopilot_configuration);
AutopilotAdapterAsFunctionBlock mainBlockAdapter = new AutopilotAdapterAsFunctionBlock(rmiClient);
......
......@@ -42,8 +42,9 @@ public class AutopilotAdapterAsFunctionBlock implements FunctionBlockInterface {
}
@Override
public void execute() {
modelOutputs = client.execute(modelInputs);
public void execute(double timeDelta) {
//PutAll in because the execute now only returns UPDATES: keep the old values if no update.
modelOutputs.putAll(client.oldExecute(modelInputs, timeDelta));
}
@Override
......@@ -81,22 +82,19 @@ public class AutopilotAdapterAsFunctionBlock implements FunctionBlockInterface {
@Override
public Map<String, Object> getOutputs() {
double engine = (double) modelOutputs.get("engine");
double brakes = (double) modelOutputs.get("brakes");
double steering = (double) modelOutputs.get("steering");
Map<String, Object> result = new HashMap<>();
result.put(
BusEntry.ACTUATOR_ENGINE.toString(),
engine
);
result.put(
BusEntry.ACTUATOR_BRAKE.toString(),
brakes
);
result.put(
BusEntry.ACTUATOR_STEERING.toString(),
steering
);
Object engine = modelOutputs.get("engine");
if (engine != null)
result.put(BusEntry.ACTUATOR_ENGINE.toString(), engine);
Object brakes = modelOutputs.get("brakes");
if (brakes != null)
result.put(BusEntry.ACTUATOR_BRAKE.toString(), brakes);
Object steering = modelOutputs.get("steering");
if ( steering != null)
result.put(BusEntry.ACTUATOR_STEERING.toString(), steering );
LOG.debug("control commands " + brakes + " " + engine + " " + steering);
return result;
}
......
......@@ -30,39 +30,83 @@ public class RMIClient {
*
* @param host - RMI server address
* @param port - RMI server port
* @param requestedModel - the accessed remote object, implementing VehicleModel
* @param configuration - the configuration to setup an Autopilot (autopilot, os, cpu_frequency, ...)
*/
public RMIClient(String host, int port, String requestedModel) {
public RMIClient(String host, int port, String configuration) {
this.console = Logger.getInstance();
try {
Registry registry = LocateRegistry.getRegistry(host, port);
this.manager = (RMIManager) registry.lookup(RMIServer.MODEL_MANAGER);
//register model to be created by the RMIManager
this.modelId = this.manager.registerModel(requestedModel);
this.modelId = this.manager.alloc_autopilot(configuration);
if (this.modelId < 0){
this.console.trace(ExtensionLogLevel.ERROR, "Could not allocate autopilot and emulator: " + this.manager.query("get_error_msg"));
}
} catch (RemoteException e) {
this.console.trace(ExtensionLogLevel.ERROR, "RMI connection problem: " + e);
} catch (NotBoundException e) {
this.console.trace(ExtensionLogLevel.ERROR, "No RMI object associated with [" + RMIServer.MODEL_MANAGER + "]: " + e);
} catch (AlreadyBoundException e) {
this.console.trace(ExtensionLogLevel.ERROR, "ModelManager already registered: " + e);
}
}
/**
* @return the remotely accessed <b>VehicleModel</b>
* or <b>null</b> if no object have been associated with the requested model
* or RMI connection has failed.
/*
This function can eventually be replaced with the distributed start_tick()/end_tick() method for updating all
HardwareEmulators in parallel.
This method first calls updateBus() on all the emulators with the BUS updates.
Then the simulation starts all the emulators with start_tick() on all the RMIModelServers.
Then the simulation resyncronizes the emulators with end_tick() on all the RMI servers.
Finally the individual BUS updates can be pulled with getOutputs().
*/
public HashMap<String, Serializable> execute(HashMap<String, Serializable> inputs) {
try {
if(this.modelId.intValue() > 0) {
return this.manager.executeModel(this.modelId, inputs);
public HashMap<String, Serializable> oldExecute(HashMap<String, Serializable> inputs, double timeDelta){
if (this.modelId >= 0) {
try {
return this.manager.old_execute(this.modelId, (long)(timeDelta*1000000), inputs);
} catch(RemoteException e){
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
}
} catch (RemoteException e) {
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
} else {
this.console.trace(ExtensionLogLevel.ERROR, "No remote Autopilot to send a bus update to.");
}
return new HashMap<String, Serializable>();
}
public void updateBus(HashMap<String, Serializable> inputs) {
if (this.modelId >= 0) {
try {
this.manager.update_bus(this.modelId, inputs);
} catch(RemoteException e){
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
}
} else {
this.console.trace(ExtensionLogLevel.ERROR, "No remote Autopilot to send a bus update to.");
}
}
public HashMap<String, Serializable> getOutputs() {
if (this.modelId >= 0) {
try {
return this.manager.get_outputs(this.modelId);
} catch(RemoteException e){
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
}
} else {
this.console.trace(ExtensionLogLevel.ERROR, "No remote Autopilot to pull a bus update from.");
}
return null;
return new HashMap<String, Serializable>();
}
public String query(String query){
if (this.modelId >= 0) {
try {
return this.manager.query(query);
} catch(RemoteException e){
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
}
} else {
this.console.trace(ExtensionLogLevel.ERROR, "Query on unallocated Autopilot");
}
return new String();
}
/**
......@@ -85,10 +129,12 @@ public class RMIClient {
* Unregisters remote VehicleModel.
*/
public void removeModel() {
try {
this.manager.removeModel(this.modelId);
} catch (RemoteException e) {
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
}
if (this.modelId >= 0)
try {
this.manager.free_autopilot(this.modelId);
this.modelId = -1;
} catch (RemoteException e) {
this.console.trace(ExtensionLogLevel.ERROR, "RMI manager execution error: " + e);
}
}
}
package rwth.server.simulation.adapters.util;
import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import rwth.server.simulation.adapters.interfaces.VehicleModel;
public interface RMIManager extends Remote {
public int registerModel(String modelClass) throws RemoteException, AlreadyBoundException;
public VehicleModel getModel(int modelId) throws RemoteException;
public void removeModel(int modelId) throws RemoteException;
}
\ No newline at end of file
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