Bladeren bron

Discussions with Claudio, Kenneth and Casper. Written comments and changed examples

Casper Thule 8 jaren geleden
bovenliggende
commit
95cee726af

+ 30 - 18
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/controller_sa.BASE.sa

@@ -16,11 +16,12 @@ param init_up = 0;
 param init_down = 0;
 
 in var previous_arm_current := init_armature_current;
+in var stored_arm_current := init_armature_current;
 in var stored_displacement := init_displacement;
 in var stored_speed := init_speed;
 in var next_time_step := -1;
 in var step_size;
-in var aux_obj_detected;
+in var aux_obj_detected := 0;
 
 in rules {
 	next_time_step < 0 -> { 
@@ -35,34 +36,36 @@ in rules {
 	} --> { };
 	
 	true -> {
-		aux_obj_detected := false;
-		step_size := H;
-		if ((not is_close(stored_armature_current, CROSSING, REL_TOL, ABS_TOL) and stored_armature_current < CROSSING)
-					and (not is_close(armature_current, CROSSING, REL_TOL, ABS_TOL) and armature_current > CROSSING)) { // crossing, but not within tolerance
-			var negative_value := stored_armature_current - CROSSING;
-			var positive_value := armature_current - CROSSING;
-			step_size := (H * (- negative_value)) / (positive_value - negative_value);
-		} else {
-			if (not (not is_close(stored_armature_current, CROSSING, REL_TOL, ABS_TOL) and stored_armature_current > CROSSING)
-						and is_close(armature_current, CROSSING, REL_TOL, ABS_TOL)) { // crossing within tolerance found
-				aux_obj_detected := true;
-			}
-		}
+		stored_arm_current := armature_current
 	} --> {
 		obj_detected := aux_obj_detected; // Sets this input to the FMU 
 	};
 }
 
 control rules {
+	aux_obj_detected := false;
+	step_size := H;
+	if ((not is_close(previous_arm_current, CROSSING, REL_TOL, ABS_TOL) and previous_arm_current < CROSSING)
+				and (not is_close(stored_arm_current, CROSSING, REL_TOL, ABS_TOL) and stored_arm_current > CROSSING)) { // crossing, but not within tolerance
+		var negative_value := previous_arm_current - CROSSING;
+		var positive_value := stored_arm_current - CROSSING;
+		step_size := (H * (- negative_value)) / (positive_value - negative_value);
+	} else {
+		if ((not is_close(previous_arm_current, CROSSING, REL_TOL, ABS_TOL) and previous_arm_current < CROSSING)
+					and is_close(stored_arm_current, CROSSING, REL_TOL, ABS_TOL )) { // crossing within tolerance found
+			aux_obj_detected := true;
+		}
+	}
+	
 	if (obj_detected == true or t >= next_time_step) {
 		var aux_h = do_step(controller, t-e, e); // do a step, then decide next internal transition
 		assert aux_h == e; // this must always be the case, otherwise it is better not to use the timed transition adaptation.
-		internal_transition := -1; // next time the setValues is called, the internal transition will be set again.
+		next_time_step := -1; // next time the setValues is called, the internal transition will be set again.
 	}
 	if is_close(step_size, H, REL_TOL, ABS_TOL) {
 		// Step accepted, so store the known input.
 		// We cannot store the armature current at the in rules because we may not accept the step and because they may be called multiple times. If that happens, we want to still have the old value of armature current, to compare it with the new one.
-		stored_armature_current := armature_current;
+		previous_arm_current := stored_arm_current;
 	}
 	return step_size; // the step size is calculated in the in_rules.
 }
@@ -85,8 +88,8 @@ out rules {
 	Suppose I have the following rules:
 		var1 == true and var2 == false -> ...
 		otherwise var1 -> ...
-	*/
-	up == true -> { up := 1; } --> { };
+	
+	controller.up == true -> { stored_up := 1; } --> { };
 	otherwise up -> { } --> { }; 
 	down == true -> { down := 1; } --> { };
 	otherwise down -> { } --> { };
@@ -94,4 +97,13 @@ out rules {
 	otherwise stop -> { } --> { };
 	true -> { up := stored_up; stored_up := up; } --> { };
 	true -> { down := stored_down; stored_down := down; } --> { }; 
+	*/
+	controller.up -> {stored_up := 1} --> {u := stored_up};
+	not controller.up -> {stored_up := 0} --> {u := stored_up};
+	
+	controller.down -> {stored_down := 1} --> {d := stored_down};
+	not controller.down -> {stored_down := 0} --> {d := stored_down};
+	
+	controller.stop -> {stored_down := 0; stored_up :=0 } --> {u := stored_up ; d := stored_down};
+	
 }

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/power.BASE.sa

@@ -28,7 +28,7 @@ out rules {
 	true -> {
 		stored_speed := speed;
 	} --> {
-		speed := stored_speed;
+		speed := stored_speed;   && adaptedFMU.getValues()
 	}; 
 }
 

+ 14 - 10
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/sketch.BASE.sa

@@ -1,14 +1,14 @@
 import ExternalModule
 module LocalModule
 semantic adaptation Adapted_FMU_Name
-for fmu fmu1, fmu2, ... ;
+for fmu fmu1, fmu2, fmu3, fmu4, ... ; \\ Kenneth> how does it know where the FMU fils are_):?
 
 input ports in_port_1, 
 			in_port_2,
 				...
 			;
 
-input ports out_port_1, 
+output ports out_port_1, 
 			out_port_2,
 			...
 			;
@@ -30,11 +30,15 @@ out var ov1 := init_ov1,
 
 in rules {
 	in_condition_1 -> {
-		sa_in_1
-	} --> { update_in_1 }; 
+		sa_in_1 //function with write access to invars with no read access to any vars except input.
+	} --> { 
+		update_in_1 //read all (except out vars) and write access to all invars
+	}; 
 	in_condition_2 -> {
 		sa_in_2
-	} --> { update_in_2 }; 
+	} --> { 
+		update_in_2 
+	}; 
 	...
 }
 
@@ -44,11 +48,11 @@ control rules {
 }
 
 out rules {
-	in_condition_1 -> {
-		sa_in_1
-	} --> { update_in_1 }; 
+	out_condition_1 -> {
+		update_out_1
+	} --> { sa_out_1 }; 
 	in_condition_2 -> {
-		sa_in_2
-	} --> { update_in_2 }; 
+		update_out_1
+	} --> { sa_out_2 }; 
 	...
 }

+ 9 - 5
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/window_obstacle_sa.BASE.sa

@@ -10,13 +10,14 @@ Notice that we're importing the Window_SA module... that's where the window_sa F
 */
 for fmu window_sa, obstacle
 
-input ports displacement -> displacement,
+input ports displacement -> displacement, // I should not need to say this.
 			speed;
 
-output ports tau -> tau;
+output ports tau -> tau; 
 
 in var previous_speed := 0;
 in var future_speed := 0;
+in var current_speed := 0;
 param RATE := 10;
 
 in rules {
@@ -29,6 +30,8 @@ in rules {
 		Upon execution, this block must call setValues of the original FMUs (window_sa and obstacle).
 		The correct thing then is to execute the next block and then do the setValues of the original FMUs.
 		*/
+		current_speed := adapted.speed
+		
 	} --> {
 		/*
 		This block will be called whenever any of the input ports that are unconnected in the original FMUs is read, in the control rules block.
@@ -41,8 +44,9 @@ in rules {
 		So the declaration would be equivalent to having this intruction in this block.
 		displacement := displacement;
 		*/
-		speed := previous_speed + (future_speed - previous_speed)*dt;
+		window_sa.speed := previous_speed + (future_speed - previous_speed)*dt;
 	}
+	// Feedback: everything should be prefixed, and the prefixes should be short.
 }
 
 control rules {
@@ -52,10 +56,10 @@ control rules {
 	The two instructions below need to be made, because previously they were made in the sa_in block, but multiple calls to the sa_in block would make them fail.
 	*/
 	previous_speed := future_speed;
-	future_speed := speed;
+	future_speed := current_speed; // you cannot access input ports of the adapted FMU here.
 	
 	for (var iter in 0 .. RATE) { // multi-rate loop
-		var prev_height := height
+		var prev_height := window_sa.height
 		var inner_time := t
 		for (var iter in 0 .. MAXITER) {
 			transaction(obstacle) // Inspired by transactions in databases.

+ 23 - 5
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/window_sa.BASE.sa

@@ -10,10 +10,12 @@ for fmu window
 No need to have input ports declared for this model.
 Every input port of the original FMU will be automatically assumed to be an input port of the adapted FMU.
 Having no input ports declaration is equivalent to having this:
-input ports reaction_force (N) --> reaction_force (N),
-			displacement (rad) --> displacement (rad),
-			speed (rad/s) --> speed (rad/s);
+input ports reaction_force (N) -> reaction_force (N),
+			displacement (rad) -> displacement (rad),
+			speed (rad/s) -> speed (rad/s);
 If the units are not declared, then they are assumed to be equal and brought from the scenario description.
+
+Remark: If there is an input port which is dangling, but is not declared here, then it will be assumed to be forwarded.
 */
 
 /*
@@ -26,10 +28,26 @@ output ports height (m) -> disp (cm), tau;
 There are alternatives ways that this can be interpreted:
 disp  := arbitrary_function(height) * 100 or arbitrary_function(height * 100) (they are not necessarily equal)
 We pick the first one, so what we have is this:
-disp := arbitrary_function(height);
-disp := disp*100; // This part never has to be coded.
+aux_var := arbitrary_function(height);
+disp := aux_var*100; // This part never has to be coded.
 */
 
+in rules {
+	true -> { } --> { 
+		/*
+			No declaration is equivalent to this:
+			window.reaction_force := window_sa.reaction_force; 
+			window.displacement := displacement; 
+			window.speed := speed; 		
+			
+			all input ports have to be prefix in this situation:
+				if (speed != speed) {
+					then world ends
+				}
+		*/
+	}; 
+}
+
 out rules {
 	true -> { } --> { 
 		tau := -reaction_torque;