Browse Source

Started work on lazy sa

Casper Thule 3 years ago
parent
commit
473337bafe

+ 4 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -44,6 +44,10 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Test def window_sa_canonical_new() {
 		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical_new.BASE.sa', 'generated', "powerwindow");
 	}
+	
+	@Test def lazy_sa_canonical() {
+		__parseNoErrors('test_input/single_folder_spec/lazy/lazy.sa', 'generated', "lazy");
+	}
 
 	def __parseNoErrorsWithValidation(String directory, String filename) {
 		val model = __parse(filename);

BIN
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/Controller.fmu


+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/lazy.sa

@@ -2,7 +2,7 @@ semantic adaptation reactive moore LazySA lazy_sa
 at "./path/to/LazySA.fmu"
 
 	for inner fmu Controller controller
-	at "./path/to/Controller.fmu"
+	at "test_input/single_folder_spec/lazy/Controller.fmu"
 	with input ports obj_detected, passenger_up, passenger_down, passenger_stop, driver_up, driver_down, driver_stop
 	with output ports up, down, stop
 

+ 71 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/test_input/single_folder_spec/lazy/lazy_canonical.sa

@@ -0,0 +1,71 @@
+semantic adaptation reactive moore LazySA lazy_sa
+at "./path/to/LazySA.fmu"
+
+	for inner fmu Controller controller
+	at "test_input/single_folder_spec/lazy/Controller.fmu"
+	with input ports obj_detected, passenger_up, passenger_down, passenger_stop, driver_up, driver_down, driver_stop
+	with output ports up, down, stop
+
+input ports obj_detected -> controller.obj_detected,
+			passenger_up -> controller.passenger_up,
+			passenger_down -> controller.passenger_down,
+			passenger_stop -> controller.passenger_stop,
+			driver_up -> controller.driver_up,
+			driver_down -> controller.driver_down,
+			driver_stop -> controller.driver_stop
+
+output ports up, down, stop
+
+param 	INIT_OBJ_DETECTED := false,
+		INIT_PASSENGER_UP := false,
+		INIT_PASSENGER_DOWN := false,
+		INIT_PASSENGER_STOP := false,
+		INIT_DRIVER_UP := false,
+		INIT_DRIVER_DOWN := false,
+		INIT_DRIVER_STOP := false;
+
+control var	tn := -1.0,
+			tl := -1.0,
+			prev_obj_detected := INIT_OBJ_DETECTED,
+			prev_passenger_up := INIT_PASSENGER_UP,
+			prev_passenger_down := INIT_PASSENGER_DOWN,
+			prev_passenger_stop := INIT_PASSENGER_STOP,
+			prev_driver_up := INIT_DRIVER_UP,
+			prev_driver_down := INIT_DRIVER_DOWN,
+			prev_driver_stop := INIT_DRIVER_STOP;
+
+control rules {
+	if (tl < 0.0){
+		tl := t;
+	}
+	
+	var step_size := min(H, tn - t); 
+	if (lazy_sa.obj_detected != prev_obj_detected or
+		lazy_sa.passenger_up != prev_passenger_up or
+		lazy_sa.passenger_down != prev_passenger_down or
+		lazy_sa.passenger_stop != prev_passenger_stop or
+		lazy_sa.driver_up != prev_driver_up or
+		lazy_sa.driver_down != prev_driver_down or
+		lazy_sa.driver_stop != prev_driver_stop or
+		(t+H) >= tn
+	){
+		var step_to_be_done := (t+H-tl);
+		var step_done := do_step(controller, t, step_to_be_done); 
+		tn := tl + step_done + get_next_time_step(controller); 
+		step_size := tl + step_done - t; 
+		tl := tl + step_done; 
+	}
+	
+	prev_obj_detected := lazy_sa.obj_detected;
+	prev_passenger_up := lazy_sa.passenger_up;
+	prev_passenger_down := lazy_sa.passenger_down;
+	prev_passenger_stop := lazy_sa.passenger_stop;
+	prev_driver_up := lazy_sa.driver_up;
+	prev_driver_down := lazy_sa.driver_down;
+	prev_driver_stop := lazy_sa.driver_stop;
+	
+	return step_size;
+}
+
+in var
+

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/data/SVVariability.java

@@ -3,6 +3,6 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data;
 public enum SVVariability {
 	continuous,
 	discrete,
-	fixed,
+	fixed
 
 }

+ 15 - 13
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -33,8 +33,8 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ParamDeclarati
 
 class CppGenerator extends SemanticAdaptationGenerator {
 	private var IFileSystemAccess2 fsa;
-
 	private List<File> resourcePaths = newArrayList();
+
 	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
 		this.fsa = fsa;
 		for (SemanticAdaptation type : resource.allContents.toIterable.filter(SemanticAdaptation)) {
@@ -43,27 +43,23 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		}
 	}
 
-	def List<File> getResourcePaths(){
-		return resourcePaths;		
-	}
-
 	// TODO: Verify adaptation.name is not a C++ keyword
 	def void compile(SemanticAdaptation adaptation) {
-		for (Adaptation type : adaptation.elements.filter(Adaptation)) {
+		for (Adaptation adap : adaptation.elements.filter(Adaptation)) {
 			// Value used for scoping variables in the .sa file
-			val adapInteralRefName = type.name;
+			val adapInteralRefName = adap.name;
 
 			// The CPP class name
-			val adapClassName = type.name.toFirstUpper;
+			val adapClassName = adap.name.toFirstUpper;
 
 			// This is the external name used in the model description file for the semantic adaptation FMU.
-			val adapExternalName = type.type.name;
+			val adapExternalName = adap.type.name;
 
 			// List of FMUs with a pairing between its name and its type.name.
 			var ArrayList<Pair<String, String>> fmus = newArrayList();
 
 			// TODO: Currently only 1 inner fmu is supported
-			val innerFmus = type.inner.eAllContents.toList.filter(InnerFMU);
+			val innerFmus = adap.inner.eAllContents.toList.filter(InnerFMU);
 			if (innerFmus.size > 1) {
 				throw new IncorrectAmountOfElementsException("Only one InnerFmu is supported.")
 			}
@@ -83,7 +79,7 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			 */
 			// TODO: Add support for multiple inner fmus
 			var ModelDescription md;
-			for (fmu : type.inner.eAllContents.toList.filter(InnerFMU)) {
+			for (fmu : adap.inner.eAllContents.toList.filter(InnerFMU)) {
 				val fmuFile = new File(fmu.path.replace('\"', ''));
 				this.resourcePaths.add(fmuFile);
 				md = new ModelDescription(fmu.name, fmu.type.name, fmuFile);
@@ -102,18 +98,20 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 			// Compile Params
 			var LinkedHashMap<String, GlobalInOutVariable> params = newLinkedHashMap;
-			val String paramsConstructorSource = compileParams(params, type.params);
+			val String paramsConstructorSource = compileParams(params, adap.params);
 
 			/*
 			 * This map contains all the ScalarVariables for the semantic adaptation. 
 			 * The are not populated yet, but they will be during the compilation of the in and out rule blocks. 
 			 */
 			var LinkedHashMap<String, SAScalarVariable> SASVs = calcSASVsFromInportsOutports(adapInteralRefName,
-				type.inports, type.outports)
+				adap.inports, adap.outports)
 
 			// C++ defines for accessing semantic adaptation scalar variables 
 			val String SADefines = calcSADefines(SASVs.values);
 
+			// Compile the transparent in mappings
+
 			// Compile the in rules
 			val inRuleResult = compileInOutRuleBlocks(InputOutputType.Input, adaptation.eAllContents.toIterable.filter(
 				InRulesBlock).map[x|x as InOutRules], adapClassName, adapInteralRefName, mappedScalarVariables, SASVs,
@@ -576,4 +574,8 @@ class CppGenerator extends SemanticAdaptationGenerator {
 
 		return saSVs;
 	}
+
+	def List<File> getResourcePaths() {
+		return resourcePaths;
+	}
 }

+ 12 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/GeneralConditionSwitch.xtend

@@ -1,12 +1,12 @@
 package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
 
 import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.util.SemanticAdaptationSwitch
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SingleParamDeclaration
+import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.BoolLiteral
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ParamDeclarations
-import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Expression
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.RealLiteral
-import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SVType
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.SingleParamDeclaration
+import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.util.SemanticAdaptationSwitch
 import org.eclipse.emf.ecore.EObject
 
 class GeneralConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation> {
@@ -24,6 +24,14 @@ class GeneralConditionSwitch extends SemanticAdaptationSwitch<ReturnInformation>
 		retInfo.code = '''«object.value»''';
 		return retInfo;
 	}
+	
+		override ReturnInformation caseBoolLiteral(BoolLiteral object) {
+		var retInfo = new ReturnInformation();
+		retInfo.type = SVType.Boolean;
+		retInfo.value = Conversions.convertTypeToObject(retInfo.type, object);
+		retInfo.code = '''«object.value»''';
+		return retInfo;
+	}
 
 	override ReturnInformation defaultCase(EObject object) {
 		var retVal = new ReturnInformation();