Commit 9f587868 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Modeled Communication Quality

parent 4e0259a9
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ComponentSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath.cocos.EmbeddedMontiArcMathCoCos;
......@@ -26,6 +27,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
......@@ -84,6 +86,7 @@ public class GenerationTest extends AbstractSymtabTest {
}
@Ignore("Planner no longer used")
@Test
public void plannerTest() throws IOException{
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
......@@ -128,10 +131,29 @@ public class GenerationTest extends AbstractSymtabTest {
.flatMap(sc -> sc.getPorts().stream())
.forEach(p -> p.setMiddlewareSymbol(new RosConnectionSymbol()));
List<ConnectorSymbol> stopCommConnectors = componentInstanceSymbol.getConnectors()
.stream()
.filter(con -> con.getTarget().startsWith("stopCommQuality") || con.getSource().startsWith("stopCommQuality"))
.sorted(Comparator.comparing(ConnectorSymbol::getName))
.collect(Collectors.toList());
for(ConnectorSymbol con : stopCommConnectors){
String indexString = con.getName().replaceAll(".*\\[(\\d+)\\].*","$1");
if(con.getSource().startsWith("stopCommQuality")){
con.getSourcePort().setMiddlewareSymbol(new RosConnectionSymbol("/v"+ indexString + "/comm/in/slowDown"+ indexString,"std_msgs/Bool","data"));
con.getTargetPort().setMiddlewareSymbol(new RosConnectionSymbol("/v"+ indexString + "/comm/in/slowDown"+ indexString,"std_msgs/Bool","data"));
}else{
con.getSourcePort().setMiddlewareSymbol(new RosConnectionSymbol("/sim/comm/slowDown" + indexString,"std_msgs/Bool","data"));
con.getTargetPort().setMiddlewareSymbol(new RosConnectionSymbol("/sim/comm/slowDown" + indexString,"std_msgs/Bool","data"));
}
}
DistributedTargetGenerator distributedTargetGenerator = new DistributedTargetGenerator();
String generationTargetPath = "./target/generated-sources-cmake/system/src/";
distributedTargetGenerator.setGenerationTargetPath(generationTargetPath);
distributedTargetGenerator.setGenDebug(true);
// distributedTargetGenerator.setGenDebug(true);
distributedTargetGenerator.add(new CPPGenImpl(),"cpp");
distributedTargetGenerator.add(new RosCppGenImpl(),"roscpp");
......@@ -278,6 +300,7 @@ public class GenerationTest extends AbstractSymtabTest {
distributedTargetGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Ignore("Part of system now. See testBaSystem")
@Test
public void testIntersectionGeneration() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
......
package ba;
import ba.intersection.IntersectionController;
import ba.util.RelToAbsTrajectory;
import ba.util.CommQuality;
import ba.vehicle.VelocityController;
component System{
//Intersection
instance IntersectionController intersectionController;
......@@ -25,9 +27,11 @@ component System{
//Vehicles
instance VelocityController velocityController[2];
ports in Q maxAccel[2],
in Q maxVel[2],
in Q deltaTime[2],
in Q holdTime[2],
in B resetVel[2],
in B slowDown[2],
out Q curVel[2];
......@@ -35,11 +39,15 @@ component System{
connect maxAccel[:] -> velocityController[:].maxAccelIn;
connect maxVel[:] -> velocityController[:].maxVelIn;
connect deltaTime[:] -> velocityController[:].deltaTimeIn;
connect holdTime[:] -> velocityController[:].holdTimeIn;
connect resetVel[:] -> velocityController[:].resetVelIn;
connect velocityController[:].curVelOut -> curVel[:];
connect intersectionController.stop[:] -> velocityController[:].slowDownIn;
instance CommQuality<B> stopCommQuality[2];
connect intersectionController.stop[:] -> stopCommQuality[:].in1;
connect stopCommQuality[:].out1 -> velocityController[:].slowDownIn;
//connect intersectionController.stop[:] -> velocityController[:].slowDownIn;
}
\ No newline at end of file
package ba.util;
//Dummy component. Behaviour is implemented in ROS. The Ports are only used to define the incoming and outgoing topics
component CommQuality<T>{
port in T in1,
out T out1;
}
\ No newline at end of file
package ba.util;
//TODO: remove once EMAM2Cpp can handle matrix generics
//Dummy component. Behaviour is implemented in ROS. The Ports are only used to define the incoming and outgoing topics
component MatrixCommQuality<N1 rows = 3,N1 cols = 3>{
port in Q^{rows,cols} commIn,
out Q^{rows,cols} commOut;
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ component VelocityController{
ports in Q maxVelIn,
in Q maxAccelIn,
in Q deltaTimeIn,
in Q holdTimeIn,
in B slowDownIn,
in B resetVelIn;
......@@ -11,17 +12,25 @@ component VelocityController{
implementation Math{
static Q lastVel = 0;
static Q holdFor = 0;
Q resVel;
if resetVelIn
lastVel = maxVelIn;
resVel = maxVelIn;
holdFor = 0;
else
Q deltaVel = maxAccelIn * deltaTimeIn;
if slowDownIn
resVel = lastVel - deltaVel;
resVel = lastVel - maxAccelIn * deltaTimeIn;
holdFor = holdTimeIn;
else
resVel = lastVel + deltaVel;
holdFor = holdFor - deltaTimeIn;
if holdFor <= 0
//holdFor is either (-deltaTimeIn)
//or (- time since accel start)
resVel = lastVel + maxAccelIn * (-holdFor);
holdFor = 0;
end
end
end
......
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