Added Intersection example + test

parent e08be6ec
......@@ -117,6 +117,39 @@ public class GenerationTest extends AbstractSymtabTest {
distributedTargetGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
public void testIntersectionGeneration() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
RosToEmamTagSchema.registerTagTypes(taggingResolver);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("ba.intersection.intersectionController", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
//Map<PortSymbol, RosConnectionSymbol> tags = TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
componentInstanceSymbol.getConnectors().stream()
.filter(c -> c.getSourcePort().equals(c.getTargetPort()))
.forEach(c -> System.out.println("Source = Target:"+c.getSource() + " -> " + c.getTargetPort()));
componentInstanceSymbol.getSubComponents().stream()
.flatMap(subc -> subc.getConnectors().stream())
.filter(c -> c.getSourcePort().equals(c.getTargetPort()))
.forEach(c -> System.out.println("Source = Target in comp "+c.getComponentInstance().get().getName()+":"+c.getSource() + " -> " + c.getTargetPort()));
componentInstanceSymbol.getPorts().forEach(p -> p.setMiddlewareSymbol(new RosConnectionSymbol()));
componentInstanceSymbol.getSubComponents().stream()
.flatMap(subc -> subc.getPorts().stream())
.forEach(p -> p.setMiddlewareSymbol(new RosConnectionSymbol()));
DistributedTargetGenerator distributedTargetGenerator = new DistributedTargetGenerator();
distributedTargetGenerator.setGenerationTargetPath("./target/generated-sources-cmake/intersection/src/");
distributedTargetGenerator.add(new CPPGenImpl(), "cpp");
distributedTargetGenerator.add(new RosCppGenImpl(), "roscpp");
distributedTargetGenerator.generate(componentInstanceSymbol, taggingResolver);
}
@Test
public void testMutliMwGenerateAll() throws IOException {
testMutliMw("allMw", true, true);
......
package ba.intersection;
//TODO: x = (n-1)n/2
//TODO: units
component ConflictComputer<N1 n = 4,N1 x = 6,N1 m = 5>{
port in Q^{3,m} trajectory[n];
port in Q cutoffPosIn,in Q cutoffTimeIn;
port out B conflictOut[x];
//TODO: horrible runtime O(n²m²)
//TODO: split into mutliple components?
//TODO: rename loop variables, comments
implementation Math{
Z xi = 1;
for ni = 1:n
Z minNj = ni + 1;
for nj = minNj:n
B conflictFlag = False;
Q^{3,m} tmpTrajA = trajectory(ni);
Q^{3,m} tmpTrajB = trajectory(nj);
for mi = 1:m
Z minMj = mi + 1;
for mj = minMj:m
Q deltaXSquared = (tmpTrajA(1,mi) - tmpTrajB(1,mj)) * (tmpTrajA(1,mi) - tmpTrajB(1,mj));
Q deltaYSquared = (tmpTrajA(2,mi) - tmpTrajB(2,mj)) * (tmpTrajA(2,mi) - tmpTrajB(2,mj));
Q deltaTSquared = (tmpTrajA(3,mi) - tmpTrajB(3,mj)) * (tmpTrajA(3,mi) - tmpTrajB(3,mj));
B condPos = deltaXSquared + deltaYSquared <= cutoffPosIn * cutoffPosIn;
B condTime = deltaTSquared <= cutoffTimeIn * cutoffTimeIn;
if condPos && condTime
conflictFlag = True;
//TODO: break
end
end
end
conflictOut(xi) = conflictFlag;
xi = xi + 1;
end
end
}
}
package ba.intersection;
//TODO: x = (n-1)n/2
component ConflictToStopConverter<N1 n = 2,N1 x = 3,N1 m = 5>{
port in Z(1:n) indexLookupIn[x];
port in B conflictIn[x];
port out B stopOut[n];
implementation Math{
for i = 1:n
stopOut(i) = False;
end
for i = 1:x
if conflictIn(i)
Z curIndex = indexLookupIn(i);
stopOut(curIndex) = True;
end
end
}
}
\ No newline at end of file
package ba.intersection;
//TODO: rename
//TODO: automatically calculate x: x = (n-1)n/2
component ConflictToStopLookup<N1 n = 2,N1 x = 3>{
port out Z(1:n) indexLookup[x];
implementation Math{
Z^{n,1} counter;
for i = 1:n
counter(i,1) = 0;
end
Z k = 1;
//TODO: remove once generator can handle i = n-1:n
Z maxI = n - 1;
for i = 1:maxI
Z minJ = i + 1;
for j = minJ:n
counter(i,1) = counter(i,1) + 1;
counter(j,1) = counter(j,1) + 1;
if counter(i,1) <= counter(j,1)
indexLookup(k) = i;
else
indexLookup(k) = j;
end
k = k + 1;
end
end
}
}
\ No newline at end of file
package ba.intersection;
//TODO: x = (n-1)n/2
//n: number of Trajectories, m = number of (x,y,dt) per trajectory
component DeltaTrajectoryComputer<N1 n = 2, N1 x = 3,N1 m = 5>{
port in Q(-oo:oo)^{3,m} trajectoryIn[n];
port in Q(-oo:oo)^{3,m} deltaTrajectoryOut[x];
implementation Math{
Z k = 1;
//TODO: remove once generator can handle i = n-1:n
Z maxI = n - 1;
for i = 1:maxI
Z minJ = i + 1;
for j = minJ:n
deltaTrajectoryOut(k) = trajectoryIn(i) - trajectoryIn(j);
k = k + 1;
end
end
}
}
\ No newline at end of file
package ba.intersection;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags Intersection{
//tag intersectionController.objectIdIn[1] with RosConnectionSymbol;
//tag intersectionController.relTrajectoryIn with RosConnectionSymbol;
//tag intersectionController.absPositionIn with RosConnectionSymbol;
tag intersectionController.cutoffPos with RosConnectionSymbol;
//tag intersectionController.cutoffTime with RosConnectionSymbol;
//tag intersectionController.objectIdOut with RosConnectionSymbol;
//tag intersectionController.stopOut with RosConnectionSymbol;
}
\ No newline at end of file
package ba.intersection;
import ba.util.RelToAbsTrajectory;
component IntersectionController{
port in Z objectIdIn[4];
port in Q^{3,5} relTrajIn[4];
port in Q^{2,1} absPosIn[4];
port in Q cutoffPosIn;
port in Q cutoffTimeIn;
port out Z objectIdOut[4];
port out B stopOut[4];
instance RelToAbsTrajectory<4,5> relToAbsTrajectory;
instance TrajectoryToStop<4,6,5> trajectoryToStop;
connect objectIdIn[:] -> objectIdOut[:];
connect cutoffPosIn -> trajectoryToStop.cutoffPos;
connect cutoffTimeIn -> trajectoryToStop.cutoffTime;
connect relTrajIn[:] -> relToAbsTrajectory.relTrajectoryIn[:];
connect absPosIn[:] -> relToAbsTrajectory.absPositionIn[:];
connect relToAbsTrajectory.absTrajectoryOut[:] -> trajectoryToStop.trajectoryIn[:];
connect trajectoryToStop.stop[:] -> stopOut[:];
}
\ No newline at end of file
package ba.intersection;
//TODO: x = (n-1)n/2
component TrajectoryToStop<N1 n = 4,N1 x = 6,N1 m = 5>{
port in Q^{3,m} trajectoryIn[n];
port in Q cutoffPos;
port in Q cutoffTime;
port out B stop[n];
instance ConflictToStopLookup<n,x> conflictToStopLookup;
instance ConflictComputer<n,x,m> conflictComputer;
instance ConflictToStopConverter<n,x,m> conflictToStopConverter;
connect trajectoryIn[:] -> conflictComputer.trajectory[:];
connect cutoffPos -> conflictComputer.cutoffPosIn;
connect cutoffTime -> conflictComputer.cutoffTimeIn;
connect conflictComputer.conflictOut[:] -> conflictToStopConverter.conflictIn[:];
connect conflictToStopLookup.indexLookup[:] -> conflictToStopConverter.indexLookupIn[:];
connect conflictToStopConverter.stopOut[:] -> stop[:];
}
\ No newline at end of file
package ba.util;
component RelToAbsTrajectory<N1 n = 4, N1 m = 5>{
port in Q^{3,m} relTrajectoryIn[n];
port in Q^{2,1} absPositionIn[n];
port out Q^{3,m} absTrajectoryOut[n];
implementation Math{
for i = 1:n
Q^{3,m} tmpRelTraj = relTrajectoryIn(i);
Q^{2,1} tmpAbsPos = absPositionIn(i);
Q^{3,m} tmpAbsTraj;
for j = 1:m
//x
tmpAbsTraj(1,j) = tmpRelTraj(1,j) + tmpAbsPos(1,1);
//y
tmpAbsTraj(2,j) = tmpRelTraj(2,j) + tmpAbsPos(2,1);
//dt
tmpAbsTraj(3,j) = tmpRelTraj(3,j);
end
absTrajectoryOut(i) = tmpAbsTraj;
end
}
}
\ 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