Modeling: Before SetCompare

parent e142e7bc
......@@ -131,6 +131,7 @@ public class GenerationTest extends AbstractSymtabTest {
DistributedTargetGenerator distributedTargetGenerator = new DistributedTargetGenerator();
String generationTargetPath = "./target/generated-sources-cmake/system/src/";
distributedTargetGenerator.setGenerationTargetPath(generationTargetPath);
distributedTargetGenerator.setGenDebug(true);
distributedTargetGenerator.add(new CPPGenImpl(),"cpp");
distributedTargetGenerator.add(new RosCppGenImpl(),"roscpp");
......@@ -138,6 +139,22 @@ public class GenerationTest extends AbstractSymtabTest {
fixKnownErrors(files);
}
@Test
public void testSetCompareInstance() throws IOException{
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("ba.tests.setCompareInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
MiddlewareGenerator middlewareGenerator = new MiddlewareGenerator();
String generationTargetPath = "./target/generated-sources-cmake/setCompareInstance/src/";
middlewareGenerator.setGenerationTargetPath(generationTargetPath);
middlewareGenerator.add(new CPPGenImpl(),"cpp");
//middlewareGenerator.add(new RosCppGenImpl(),"roscpp");
List<File> files = middlewareGenerator.generate(componentInstanceSymbol, taggingResolver);
fixKnownErrors(files);
}
@Test
public void testLaneIntersection() throws IOException{
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
......@@ -192,6 +209,7 @@ public class GenerationTest extends AbstractSymtabTest {
content = content.replace("Fcos","std::cos");
content = content.replace("Fabs","std::abs");
content = content.replace("Col<int> counter=Col<int>(1);" , "Col<int> counter=Col<int>(n);");
content = content.replace("colvec tmpLine;","colvec tmpLine = colvec(4);");
// content = content.replace("sqrt","std::sqrt");
Files.write(path, content.getBytes(charset));
......
......@@ -17,9 +17,9 @@ for d in */ ; do
mkdir "$d"/build
quitOnError
echo CMake
cmake -B"$d"/build/ -H"$d"/src/
cmake -B"$d"/build/ -H"$d"/src/ -DCMAKE_BUILD_TYPE=DEBUG
quitOnError
echo make
echo make -j4
make -C "$d"/build/
quitOnError
done
......
package ba;
import ba.intersection.IntersectionController;
import ba.util.RelToAbsTrajectory;
import ba.vehicle.VelocityController;
component System{
//Intersection
instance IntersectionController intersectionController;
ports in Q cutoffPosIn,
in Q cutoffTimeIn,
ports in Q cutoffTimeIn,
in B isActiveIn,
in Q^{3,20} trajectory[2],
out B stopOut[2];
in Q^{3,20} absTrajectory[2];
connect cutoffPosIn -> intersectionController.cutoffPos;
connect cutoffTimeIn -> intersectionController.cutoffTime;
connect isActiveIn -> intersectionController.isActive;
connect trajectory[:] -> intersectionController.trajectoryIn[:];
//TODO: into speed controller
connect intersectionController.stop[:] -> stopOut[:];
connect absTrajectory[:] -> intersectionController.trajectoryIn[:];
//Collision detection
instance CollisionDetection collisionDetection;
......@@ -27,4 +22,24 @@ component System{
connect hullsIn[:] -> collisionDetection.hulls[:];
connect collisionDetection.collision -> collisionOut;
//Vehicles
instance VelocityController velocityController[2];
ports in Q maxAccel[2],
in Q maxVel[2],
in Q deltaTime[2],
in B resetVel[2],
in B slowDown[2],
out Q curVel[2];
connect maxAccel[:] -> velocityController[:].maxAccelIn;
connect maxVel[:] -> velocityController[:].maxVelIn;
connect deltaTime[:] -> velocityController[:].deltaTimeIn;
connect resetVel[:] -> velocityController[:].resetVelIn;
connect velocityController[:].curVelOut -> curVel[:];
connect intersectionController.stop[:] -> velocityController[:].slowDownIn;
}
\ No newline at end of file
package ba.intersection;
component CollisionToConflict{
ports in B collisionIn,
in Z indexIn1,
in Z indexIn2,
in Q^{2,1} colPosIn,
in Q^{3,5} trajectoryIn1,
in Q^{3,5} trajectoryIn2,
in Q timeCutoff,
out B conflict;
implementation Math{
if collisionIn
//TODO: with norm()?
Q dx1 = trajectoryIn1(1,indexIn1) - trajectoryIn1(1,indexIn1 + 1);
Q dy1 = trajectoryIn1(2,indexIn1) - trajectoryIn1(2,indexIn1 + 1);
Q dist1 = sqrt(dx1*dx1 + dy1*dy1);
Q dx2 = trajectoryIn2(1,indexIn2) - trajectoryIn2(1,indexIn2 + 1);
Q dy2 = trajectoryIn2(2,indexIn2) - trajectoryIn2(2,indexIn2 + 1);
Q dist2 = sqrt(dx2*dx2 + dy2*dy2);
Q dxp1 = trajectoryIn1(1,indexIn1) - colPosIn(1,1);
Q dyp1 = trajectoryIn1(2,indexIn1) - colPosIn(2,1);
Q distp1 = sqrt(dxp1*dxp1 + dyp1*dyp1);
Q dxp2 = trajectoryIn2(1,indexIn2) - colPosIn(1,1);
Q dyp2 = trajectoryIn2(2,indexIn2) - colPosIn(2,1);
Q distp2 = sqrt(dxp2*dxp2 + dyp2*dyp2);
Q time1 = distp1/dist1 * (trajectoryIn1(3,indexIn1 + 1) - trajectoryIn1(3,indexIn1));
Q time2 = distp2/dist2 * (trajectoryIn2(3,indexIn2 + 1) - trajectoryIn2(3,indexIn2));
conflict = abs(time1 - time2) < timeCutoff;
else
conflict = False;
end
}
}
\ No newline at end of file
package ba.intersection;
import ba.util.LineIntersection;
import ba.util.TrajectoryToLine;
//TODO: x = (n-1)n/2
//TODO: units
component ConflictComputer<N1 n = 2,N1 x = 1,N1 m = 5>{
port in Q^{3,m} trajectory[n];
port in Q cutoffPosIn,in Q cutoffTimeIn;
port 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;
instance TrajectoryCompare trajectoryCompare;
instance CollisionToConflict collisionToConflict;
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
}
connect trajectory[1] -> trajectoryCompare.trajectory[1];
connect trajectory[2] -> trajectoryCompare.trajectory[2];
connect trajectory[1] -> collisionToConflict.trajectoryIn1;
connect trajectory[2] -> collisionToConflict.trajectoryIn2;
connect cutoffTimeIn -> collisionToConflict.timeCutoff;
connect trajectoryCompare.collision -> collisionToConflict.collisionIn;
connect trajectoryCompare.index1 -> collisionToConflict.indexIn1;
connect trajectoryCompare.index2 -> collisionToConflict.indexIn2;
connect trajectoryCompare.colPos -> collisionToConflict.colPosIn;
connect collisionToConflict.conflict -> conflictOut[1];
}
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 = 1,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;
//component IntersectionController<N1 n = 2,N1 x = 1,N1 m = 20>{
//component IntersectionController<N1 n = 2,N1 x = 1,N1 m = 5>{
component IntersectionController{
port in Q^{3,20} trajectoryIn[2];
port in Q cutoffPos;
port in Q^{3,5} trajectoryIn[2];
port in Q cutoffTime;
port in B isActive;
port out B stop[2];
instance ConflictToStopLookup<2,1> conflictToStopLookup;
instance ConflictComputer<2,1,20> conflictComputer;
instance ConflictToStopConverter<2,1,20> conflictToStopConverter;
instance ConflictComputer<2,1,5> conflictComputer;
instance ConflictToStopConverter<2,1,5> conflictToStopConverter;
connect trajectoryIn[:] -> conflictComputer.trajectory[:];
connect cutoffPos -> conflictComputer.cutoffPosIn;
connect cutoffTime -> conflictComputer.cutoffTimeIn;
connect conflictComputer.conflictOut[:] -> conflictToStopConverter.conflictIn[:];
connect conflictToStopLookup.indexLookup[:] -> conflictToStopConverter.indexLookupIn[:];
......
package ba.intersection;
component LineInterToIndex{
ports in B collisionIn[10],
in Q^{2,1} pointsIn[10],
out B collisionOut,
out Z index1,
out Z index2,
out Q^{2,1} pos;
implementation Math{
Z k = 1;
B found = False;
for i = 1:4
for j = i:4
if found == False
if collisionIn(k)
index1 = i;
index2 = j;
pos = pointsIn(k);
found = True;
end
k = k + 1;
end
end
end
collisionOut = found;
}
}
\ No newline at end of file
package ba.intersection;
import ba.util.TrajectoryToLine;
import ba.util.LineIntersection;
component TrajectoryCompare{
ports in Q^{3,5} trajectory[2],
out B collision,
out Z index1,
out Z index2,
out Q^{2,1} colPos;
instance TrajectoryToLine trajectoryToLine1;
instance TrajectoryToLine trajectoryToLine2;
instance LineIntersection lineIntersection[10];
instance LineInterToIndex lineInterToIndex;
connect trajectory[1] -> trajectoryToLine1.trajectoryIn;
connect trajectory[2] -> trajectoryToLine2.trajectoryIn;
connect lineIntersection[:].intersects -> lineInterToIndex.collisionIn[:];
connect lineIntersection[:].point -> lineInterToIndex.pointsIn[:];
connect lineInterToIndex.collisionOut -> collision;
connect lineInterToIndex.index1 -> index1;
connect lineInterToIndex.index2 -> index2;
connect lineInterToIndex.pos -> colPos;
//compare 4 lines to 4 other lines without permutations with same index
//4*5/2 = 10
connect trajectoryToLine1.lineOut[1] -> lineIntersection[1].line1;
connect trajectoryToLine2.lineOut[1] -> lineIntersection[1].line2;
connect trajectoryToLine1.lineOut[1] -> lineIntersection[2].line1;
connect trajectoryToLine2.lineOut[2] -> lineIntersection[2].line2;
connect trajectoryToLine1.lineOut[1] -> lineIntersection[3].line1;
connect trajectoryToLine2.lineOut[3] -> lineIntersection[3].line2;
connect trajectoryToLine1.lineOut[1] -> lineIntersection[4].line1;
connect trajectoryToLine2.lineOut[4] -> lineIntersection[4].line2;
connect trajectoryToLine1.lineOut[2] -> lineIntersection[5].line1;
connect trajectoryToLine2.lineOut[2] -> lineIntersection[5].line2;
connect trajectoryToLine1.lineOut[2] -> lineIntersection[6].line1;
connect trajectoryToLine2.lineOut[3] -> lineIntersection[6].line2;
connect trajectoryToLine1.lineOut[2] -> lineIntersection[7].line1;
connect trajectoryToLine2.lineOut[4] -> lineIntersection[7].line2;
connect trajectoryToLine1.lineOut[3] -> lineIntersection[8].line1;
connect trajectoryToLine2.lineOut[3] -> lineIntersection[8].line2;
connect trajectoryToLine1.lineOut[3] -> lineIntersection[9].line1;
connect trajectoryToLine2.lineOut[4] -> lineIntersection[9].line2;
connect trajectoryToLine1.lineOut[4] -> lineIntersection[10].line1;
connect trajectoryToLine2.lineOut[4] -> lineIntersection[10].line2;
//end line compare
}
\ No newline at end of file
package ba.tests;
import ba.util.*;
component SetCompareInstance{
instance SingleSetCompare<3,3,Q> singleSetCompareQ;
//instance SingleSetCompare<Q^{3,5},2,1> singleSetCompareMatGen;
instance MatrixSingleSetCompare<3,5,2,1> singleSetCompareMat;
instance DualSetCompare<3,6,Q> dualSetCompareQ;
//instance DualSetCompare<Q^{3,5},2,3> dualSetCompareMatGen;
instance MatrixDualSetCompare<4,1,2,3> dualSetCompareMat;
}
\ No newline at end of file
package ba.util;
//TODO: n2 = n(n+1)/2
//TODO: EMAM2Cpp does not work with matrix generics
//TODO: EMAM2Cpp does not work when T is first generic, n and n2 are not present in generated code
component DualSetCompare<N1 n = 5, N2 n2 = 15,T>{
ports in T setIn1[n],
in T setIn2[n],
out T listOut1[n2],
out T listOut2[n2];
implementation Math{
Z counter = 1;
for i = 1:n
for j = i:n
listOut1(counter) = setIn1(i);
listOut2(counter) = setIn2(j);
counter = counter + 1;
end
end
}
}
\ No newline at end of file
package ba.util;
//TODO: n2 = n(n+1)/2
//TODO: EMAM2CPP
component MatrixDualSetCompare<N1 rows = 3,N1 cols = 3,N1 n = 5, N2 n2 = 15>{
ports in Q^{rows,cols} setIn1[n],
in Q^{rows,cols} setIn2[n],
out Q^{rows,cols} listOut1[n2],
out Q^{rows,cols} listOut2[n2];
implementation Math{
Z counter = 1;
for i = 1:n
for j = i:n
listOut1(counter) = setIn1(i);
listOut2(counter) = setIn2(j);
counter = counter + 1;
end
end
}
}
\ No newline at end of file
package ba.util;
//TODO: x has to be (n-1)n/2
//TODO: remove once EMAM2Cpp works with matrix generics
component MatrixSingleSetCompare<N1 rows = 3,N1 cols = 3, N1 n =2,N1 x = 1>{
ports in Q^{rows,cols} setIn[n],
out Q^{rows,cols} listOut1[x],
out Q^{rows,cols} listOut2[x];
implementation Math{
Z counter = 1;
for i = 1:n
for j = (i+1):n
listOut1(counter) = setIn(i);
listOut2(counter) = setIn(j);
counter = counter + 1;
end
end
}
}
\ No newline at end of file
package ba.util;
//TODO: x has to be (n-1)n/2
//TODO: EMAM2Cpp does not work with matrix generics
component SingleSetCompare<N1 n = 2,N1 x = 1,T>{
ports in T setIn[n],
out T listOut1[x],
out T listOut2[x];
implementation Math{
Z counter = 1;
for i = 1:n
for j = (i+1):n
listOut1(counter) = setIn(i);
listOut2(counter) = setIn(j);
counter = counter + 1;
end
end
}
}
\ No newline at end of file
package ba.util;
component TrajectoryToLine{
ports in Q^{3,5} trajectoryIn,
//m-1 lineOuts
out Q^{4,1} lineOut[4];
implementation Math{
for i = 1:4
Q^{4,1} tmpLine;
tmpLine(1,1) = trajectoryIn(1,i);
tmpLine(2,1) = trajectoryIn(2,i);
tmpLine(3,1) = trajectoryIn(1,i+1);
tmpLine(4,1) = trajectoryIn(2,i+1);
lineOut(i) = tmpLine;
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