Commit 720d4119 authored by Jean Meurice's avatar Jean Meurice
Browse files

Tweaks & Bugfixes

parent e2cc6637
Pipeline #381059 failed with stage
in 1 minute and 1 second
......@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set;
import de.rwth.montisim.commons.dynamicinterface.PortInformation;
import de.rwth.montisim.commons.dynamicinterface.SimplePacketType;
import de.rwth.montisim.commons.dynamicinterface.PortInformation.PortType;
import de.rwth.montisim.commons.eventsimulation.DiscreteEvent;
import de.rwth.montisim.commons.eventsimulation.exceptions.UnexpectedEventException;
......@@ -38,21 +39,6 @@ public class SimpleCommunicationGateway extends EEComponent implements PortTagUs
this.address = network.registerNode(vehicle.properties.vehicleName + "_COMM_GATEWAY", vehicle.physicalObject, this);
}
// Receiving a message from a vehicle component -> Send to the Network
@Override
protected void receive(MessageReceiveEvent msgRecvEvent) {
Message msg = msgRecvEvent.getMessage();
SimpleNetworkMessage netMsg;
if (!(msg instanceof SimpleNetworkMessage)) {
// Standard message -> broadcast
// TODO Policy
netMsg = new SimpleNetworkMessage(IPV6Address.BROADCAST_ADDR, msg.msgInfo, msg.message, msg.msgLen);
} else {
netMsg = (SimpleNetworkMessage) msg;
}
netMsg.sender = address;
eesystem.simulator.addEvent(new SimpleNetworkRecvEvent(network, msgRecvEvent.getEventTime().plus(properties.processing_time), netMsg));
}
@Override
......@@ -67,13 +53,26 @@ public class SimpleCommunicationGateway extends EEComponent implements PortTagUs
} else throw new UnexpectedEventException(this.toString(), event);
}
// Receiving a message from a vehicle component -> Send to the Network
@Override
protected void receive(MessageReceiveEvent msgRecvEvent) {
Message msg = msgRecvEvent.getMessage();
Object packet[] = (Object[]) msg.message;
SimpleNetworkMessage netMsg = new SimpleNetworkMessage(new IPV6Address((String) packet[0]), msg.msgInfo, packet[1], msg.msgLen);
netMsg.sender = address;
eesystem.simulator.addEvent(new SimpleNetworkRecvEvent(network, msgRecvEvent.getEventTime().plus(properties.processing_time), netMsg));
}
// Receiving a message from the Network
private void receive(SimpleNetworkRecvEvent event) {
MessageInformation msgInfo = getMsgInfo(event.msg.msgInfo.name);
if (msgInfo == null) return; // The vehicle does not use this message
// Resolve local MessageInformation
SimpleNetworkMessage newMsg = new SimpleNetworkMessage(event.msg.target, msgInfo, event.msg.message, event.msg.msgLen);
newMsg.sender = event.msg.sender;
Object newData[] = new Object[2];
newData[0] = event.msg.sender.addr;
newData[1] = event.msg.message;
Message newMsg = new Message(msgInfo, newData, event.msg.msgLen);
eesystem.simulator.addEvent(new MessageSendEvent(this, event.getEventTime().plus(properties.processing_time), newMsg));
}
......@@ -86,7 +85,8 @@ public class SimpleCommunicationGateway extends EEComponent implements PortTagUs
public void processTag(String tag, PortInformation portInfo) {
// TODO handle multiple components with same port
// Add the found ports as own ports
if (portInfo.port_type != PortType.SOCKET) throw new IllegalArgumentException("Port "+portInfo.name + " has 'network' tag but is not of type 'SOCKET'.");
if (portInfo.port_type != PortType.SOCKET) throw new IllegalArgumentException("Port " + portInfo.name + " has 'network' tag but is not of type 'SOCKET'.");
if (!(portInfo.data_type instanceof SimplePacketType)) throw new IllegalArgumentException("Port "+portInfo.name + " has 'network' tag but its DataType is not 'SimplePacketType'.");
addPort(PortInformation.newSocketPort(portInfo.name, portInfo.data_type, portInfo.isOutput(), portInfo.isInput()));
// Register msg types at the Network for type checking
network.registerMessage(address, portInfo.name, portInfo.data_type);
......
......@@ -70,7 +70,7 @@ public class SimpleNetwork implements EventTarget, SimulatorModule {
private void dispatch(SimpleNetworkSendEvent event) {
SimpleNetworkNodeInfo sender = ipToNode.get(event.msg.sender.addr);
SimpleNetworkRecvEvent recvEvent = new SimpleNetworkRecvEvent(null, event.getEventTime(), event.msg);
if (event.msg.target.equals(IPV6Address.BROADCAST_ADDR)) {
if (event.msg.target.addr.equals(IPV6Address.BROADCAST_ADDR.addr)) {
nodesInRange(sender).forEach(v -> {
if (v != sender)
v.component.process(recvEvent);
......
......@@ -19,4 +19,8 @@ public class SimpleNetworkMessage extends Message {
protected SimpleNetworkMessage() {
}
public static Object newMessage(IPV6Address target, Object payload) {
return new Object[]{target.addr, payload};
}
}
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.eecomponents.vehicleconfigs;
import java.time.Duration;
import de.rwth.montisim.simulation.eecomponents.autopilots.JavaAutopilotProperties;
import de.rwth.montisim.simulation.eesimulator.bus.constant.ConstantBusProperties;
import de.rwth.montisim.simulation.eesimulator.sensor.SensorProperties;
......@@ -35,33 +33,21 @@ public class DefaultVehicleConfig {
this.properties.physics = rbPhysicsProperties;
properties.addComponent(
new SensorProperties(
Duration.ofMillis(100), // Update rate
Duration.ofMillis(10), // Read time
false
)
new SensorProperties()
.setPhysicalValueName(TrueVelocity.VALUE_NAME)
.setName("TrueVelocitySensor")
.connectTo("DefaultBus")
);
properties.addComponent(
new SensorProperties(
Duration.ofMillis(100), // Update rate
Duration.ofMillis(10), // Read time
false
)
new SensorProperties()
.setPhysicalValueName(TruePosition.VALUE_NAME)
.setName("TruePositionSensor")
.connectTo("DefaultBus")
);
properties.addComponent(
new SensorProperties(
Duration.ofMillis(100), // Update rate
Duration.ofMillis(10), // Read time
false
)
new SensorProperties()
.setPhysicalValueName(TrueCompass.VALUE_NAME)
.setName("TrueCompassSensor")
.connectTo("DefaultBus")
......
......@@ -8,7 +8,9 @@ import org.junit.Assert;
import org.junit.Test;
import de.rwth.montisim.commons.dynamicinterface.BasicType;
import de.rwth.montisim.commons.dynamicinterface.DataType;
import de.rwth.montisim.commons.dynamicinterface.PortInformation;
import de.rwth.montisim.commons.dynamicinterface.SimplePacketType;
import de.rwth.montisim.commons.eventsimulation.DiscreteEventSimulator;
import de.rwth.montisim.commons.simulation.TimeUpdate;
import de.rwth.montisim.commons.utils.BuildContext;
......@@ -17,6 +19,7 @@ import de.rwth.montisim.simulation.eesimulator.bus.constant.ConstantBusPropertie
import de.rwth.montisim.simulation.eesimulator.exceptions.EEMessageTypeException;
import de.rwth.montisim.simulation.eesimulator.exceptions.EEMissingComponentException;
import de.rwth.montisim.simulation.eesimulator.exceptions.EESetupException;
import de.rwth.montisim.simulation.eesimulator.message.Message;
import de.rwth.montisim.simulation.eesimulator.testcomponents.TestCompProperties;
import de.rwth.montisim.simulation.eesimulator.testcomponents.TestEEComponent;
import de.rwth.montisim.simulation.vehicle.Vehicle;
......@@ -25,7 +28,7 @@ import de.rwth.montisim.simulation.vehicle.VehicleProperties;
public class CommunicationTest {
@Test
public void broadcastTest() throws EEMessageTypeException, EESetupException, EEMissingComponentException {
public void commTest() throws EEMessageTypeException, EESetupException, EEMissingComponentException {
Instant start_time = Instant.ofEpochSecond(10);
DiscreteEventSimulator simulator = new DiscreteEventSimulator(start_time);
......@@ -46,6 +49,8 @@ public class CommunicationTest {
prop3.start_pos = Optional.of(new Vec2(7,1));
prop4.start_pos = Optional.of(new Vec2(20,7));
DataType intPacket = new SimplePacketType(BasicType.INT);
prop1.addComponent(
ConstantBusProperties.instantBus().setName("DefaultBus")
);
......@@ -54,9 +59,9 @@ public class CommunicationTest {
);
prop1.addComponent(
new TestCompProperties("TestComp1")
.addPort(PortInformation.newSocketPort("m1", BasicType.INT, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", BasicType.INT, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m3", BasicType.INT, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m1", intPacket, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", intPacket, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m3", intPacket, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.connectTo("DefaultBus")
);
prop2.addComponent(
......@@ -67,8 +72,8 @@ public class CommunicationTest {
);
prop2.addComponent(
new TestCompProperties("TestComp2")
.addPort(PortInformation.newSocketPort("m1", BasicType.INT, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", BasicType.INT, true, false).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m1", intPacket, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", intPacket, true, false).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.connectTo("DefaultBus")
);
prop3.addComponent(
......@@ -79,8 +84,8 @@ public class CommunicationTest {
);
prop3.addComponent(
new TestCompProperties("TestComp3")
.addPort(PortInformation.newSocketPort("m1", BasicType.INT, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", BasicType.INT, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m1", intPacket, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", intPacket, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.connectTo("DefaultBus")
);
prop4.addComponent(
......@@ -91,8 +96,8 @@ public class CommunicationTest {
);
prop4.addComponent(
new TestCompProperties("TestComp4")
.addPort(PortInformation.newSocketPort("m1", BasicType.INT, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", BasicType.INT, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m1", intPacket, true, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.addPort(PortInformation.newSocketPort("m2", intPacket, false, true).addTag(SimpleCommunicationGateway.NETWORK_TAG))
.connectTo("DefaultBus")
);
......@@ -112,31 +117,31 @@ public class CommunicationTest {
// Send messages
testComp1.sendMessage(
start_time.plus(Duration.ofMillis(5)),
new SimpleNetworkMessage(IPV6Address.BROADCAST_ADDR, testComp1.getMsgInfo("m1"), Integer.valueOf(1))
new Message(testComp1.getMsgInfo("m1"), SimpleNetworkMessage.newMessage(IPV6Address.BROADCAST_ADDR, Integer.valueOf(1)))
);
testComp2.sendMessage(
start_time.plus(Duration.ofMillis(25)),
new SimpleNetworkMessage(v1addr, testComp2.getMsgInfo("m1"), Integer.valueOf(2))
new Message(testComp2.getMsgInfo("m1"), SimpleNetworkMessage.newMessage(v1addr, Integer.valueOf(2)))
);
testComp3.sendMessage(
start_time.plus(Duration.ofMillis(35)),
new SimpleNetworkMessage(v1addr, testComp3.getMsgInfo("m1"), Integer.valueOf(3))
start_time.plus(Duration.ofMillis(35)),
new Message(testComp3.getMsgInfo("m1"), SimpleNetworkMessage.newMessage(v1addr, Integer.valueOf(3)))
);
testComp4.sendMessage(
start_time.plus(Duration.ofMillis(45)),
new SimpleNetworkMessage(v1addr, testComp4.getMsgInfo("m1"), Integer.valueOf(4))
start_time.plus(Duration.ofMillis(45)),
new Message(testComp4.getMsgInfo("m1"), SimpleNetworkMessage.newMessage(v1addr, Integer.valueOf(4)))
);
testComp1.sendMessage(
start_time.plus(Duration.ofMillis(70)),
new SimpleNetworkMessage(IPV6Address.BROADCAST_ADDR, testComp1.getMsgInfo("m2"), Integer.valueOf(5))
new Message(testComp1.getMsgInfo("m2"), SimpleNetworkMessage.newMessage(IPV6Address.BROADCAST_ADDR, Integer.valueOf(5)))
);
testComp1.sendMessage(
start_time.plus(Duration.ofMillis(100)),
new SimpleNetworkMessage(IPV6Address.BROADCAST_ADDR, testComp1.getMsgInfo("m3"), Integer.valueOf(6))
start_time.plus(Duration.ofMillis(100)),
new Message(testComp1.getMsgInfo("m3"), SimpleNetworkMessage.newMessage(IPV6Address.BROADCAST_ADDR, Integer.valueOf(6)))
);
simulator.update(new TimeUpdate(start_time, Duration.ofSeconds(1)));
......@@ -146,12 +151,12 @@ public class CommunicationTest {
Assert.assertEquals(1, testComp3.events.size());
Assert.assertEquals(0, testComp4.events.size());
Assert.assertEquals(2, (long)(Integer)testComp1.events.get(0).getMessage().message);
Assert.assertEquals(3, (long)(Integer)testComp1.events.get(1).getMessage().message);
Assert.assertEquals(2, (long)(Integer)((Object[])testComp1.events.get(0).getMessage().message)[1]);
Assert.assertEquals(3, (long)(Integer)((Object[])testComp1.events.get(1).getMessage().message)[1]);
Assert.assertEquals(1, (long)(Integer)testComp2.events.get(0).getMessage().message);
Assert.assertEquals(5, (long)(Integer)testComp2.events.get(1).getMessage().message);
Assert.assertEquals(1, (long)(Integer)((Object[])testComp2.events.get(0).getMessage().message)[1]);
Assert.assertEquals(5, (long)(Integer)((Object[])testComp2.events.get(1).getMessage().message)[1]);
Assert.assertEquals(1, (long)(Integer)testComp3.events.get(0).getMessage().message);
Assert.assertEquals(1, (long)(Integer)((Object[])testComp3.events.get(0).getMessage().message)[1]);
}
}
......@@ -30,7 +30,7 @@ public class SensorProperties extends EEComponentProperties {
this.send_only_changed = sendOnlyChanged;
}
protected SensorProperties() {
public SensorProperties() {
this.update_interval = Duration.ofMillis(100);
this.read_time = Duration.ofMillis(10);
this.send_only_changed = false;
......
......@@ -202,6 +202,8 @@
0.0,
0.0
],
"start_coords": {},
"start_osm_node": {},
"start_orientation": 0.0,
"task": {
"goals": [
......@@ -225,17 +227,17 @@
"SteeringActuator": {
"sensor": {
"nextUpdate": [
0,
990000000
4,
70000000
]
},
"targetValue": -137.69912470771388
"targetValue": 2.138957759123023
},
"BrakingActuator": {
"sensor": {
"nextUpdate": [
0,
990000000
4,
70000000
]
},
"targetValue": 0.0
......@@ -243,38 +245,42 @@
"GasActuator": {
"sensor": {
"nextUpdate": [
0,
990000000
4,
70000000
]
},
"targetValue": 0.5553088028485318
"targetValue": 0.025600579481880503
},
"TrueVelocitySensor": {
"logic": {
"nextUpdate": [
0,
990000000
4,
70000000
]
}
},
"TruePositionSensor": {
"logic": {
"nextUpdate": [
0,
990000000
4,
70000000
]
}
},
"TrueCompassSensor": {
"logic": {
"nextUpdate": [
0,
990000000
4,
70000000
]
}
},
"Navigation": {
"targets": [
[
-63.83,
-171.96
],
[
-63.83,
-171.96
......@@ -282,11 +288,9 @@
],
"currentPath": {
"trajectoryX": [
18,
0.0,
-2.3721876315154202,
-2.1798136749816006,
4.211962552465172,
16,
5.7813108846301935,
4.270347736560122,
4.289310779669538,
3.1923722851743537,
-9.68962336796794,
......@@ -303,11 +307,9 @@
-63.83
],
"trajectoryY": [
18,
0.0,
-0.12404716846665131,
-3.8028664914396786,
-3.4692817115581356,
16,
-6.164792883105725,
-6.197132576848973,
-7.083116827073201,
-8.372977976211862,
-11.419718966323348,
......@@ -325,61 +327,61 @@
]
},
"currentPos": [
1.6170090724482489,
-0.5128244385869507
-3.9864173310372286,
-14.116218391617224
]
},
"DefaultBus": {},
"TestAutopilot": {
"currentVelocity": 14.646501381369834,
"currentVelocity": 29.793168576702126,
"currentPosition": [
1.6170090724482489,
-0.5128244385869507
-3.9864173310372286,
-14.116218391617224
],
"currentCompass": -10.65766304240394,
"currentCompass": 176.48927739643344,
"newTrajX": [
10,
0.0,
-2.3721876315154202,
-2.1798136749816006,
4.211962552465172,
4.289310779669538,
3.1923722851743537,
-9.68962336796794,
-18.338561497475773,
-23.091961640246605,
-42.70325305754577
-42.70325305754577,
-45.76905551645384,
-49.706783445404504,
-76.86304284074316,
-92.37487821783468,
-107.28902274852298
],
"newTrajLength": 10,
"trajLength": 10,
"trajX": [
10,
0.0,
-2.3721876315154202,
-2.1798136749816006,
4.211962552465172,
4.289310779669538,
3.1923722851743537,
-9.68962336796794,
-18.338561497475773,
-23.091961640246605,
-42.70325305754577
-42.70325305754577,
-45.76905551645384,
-49.706783445404504,
-76.86304284074316,
-92.37487821783468,
-107.28902274852298
],
"trajY": [
10,
0.0,
-0.12404716846665131,
-3.8028664914396786,
-3.4692817115581356,
-7.083116827073201,
-8.372977976211862,
-11.419718966323348,
-13.64361749913033,
-15.689604149597187,
-30.64532178345498
-30.64532178345498,
-33.9255721190885,
-38.32889121431496,
-75.87941794250301,
-97.71810153550507,
-114.73092531183404
],
"currentGas": 0.5553088028485318,
"currentSteering": -137.69912470771388,
"currentGas": 0.025600579481880503,
"currentSteering": 2.138957759123023,
"currentBrakes": 0.0,
"lastTime": [
0,
......@@ -387,80 +389,80 @@
],
"currSeg": {
"posStart": [
0.0,
0.0
3.1923722851743537,
-8.372977976211862
],
"posEnd": [
-2.3721876315154202,
-0.12404716846665131
-9.68962336796794,
-11.419718966323348
],
"dir": [
-0.9986355548682545,
-0.05222095894345149
-0.9731523767464246,
-0.23016179446811966
],
"normal": [
0.05222095894345149,
-0.9986355548682545
0.23016179446811966,
-0.9731523767464246
],
"relPos": [
1.6170090724482489,
-0.5128244385869507
-7.178789616211582,
-5.743240415405362
],
"length": 2.37542877374156,
"projPos": -1.5880225683387108,
"orthoPos": 0.5965664821617892,
"dist": 0.5965664821617892,
"projDistToEnd": 3.963451342080271
"length": 13.237388060656167,
"projPos": 8.307930697250383,
"orthoPos": 3.936764960301489,
"dist": 3.936764960301489,
"projDistToEnd": 4.929457363405785
},
"nextSeg": {
"posStart": [
-2.3721876315154202,
-0.12404716846665131
-9.68962336796794,
-11.419718966323348
],
"posEnd": [
-2.1798136749816006,
-3.8028664914396786
-18.338561497475773,
-13.64361749913033
],
"dir": [
0.052220958943452016,
-0.9986355548682544
-0.9684960149914635,
-0.24902905241287568
],
"normal": [
0.9986355548682544,
0.052220958943452016
0.24902905241287568,
-0.9684960149914635
],
"relPos": [
3.9891967039636693,
-0.3887772701202994
5.703206036930711,
-2.696499425293876
],
"length": 3.683845728343167,
"projPos": 0.5965664821617913,
"orthoPos": 3.963451342080271,
"dist": 3.963451342080271,
"projDistToEnd": 3.0872792461813754
"length": 8.930277456623367,
"projPos": -4.852025622729854,
"orthoPos": 4.031812942916138,
"dist": 4.031812942916138,
"projDistToEnd": 13.78230307935322
},
"relPos": [
0.0,
0.0
],
"targetDir": [