浏览代码

power adaptation generated code

Cláudio Gomes 8 年之前
父节点
当前提交
9ac13886cb

+ 0 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/power_canonical.BASE.sa

@@ -26,13 +26,9 @@ in rules {
 	};
 }
 
-control var time_last_window := 0
-
 control rules {
-	var e := t - time_last_window;
 	invoke_update_in(t=t, h=H, dt=0);
 	power.doStep(t, H);
-	time_last_window := t;
 }
 
 out var stored_armature_current := init_armature_current;

+ 102 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/power_canonical_generated_algorithm.sa

@@ -0,0 +1,102 @@
+code power_sa:
+	
+	var in_condition_executed;
+	var out_condition_executed;
+	
+	var power; //FMU power ref
+	
+	var time_last_window;
+	
+	var stored_windowsa_u,
+		stored_windowsa_d;
+	
+	var stored_window_reaction_torque,
+		stored_window_height;
+	
+	var init_armature_current = 0,
+		init_displacement = 0,
+		init_speed = 0;
+	
+	var stored_armature_current,
+		stored_displacement,
+		stored_speed;
+	
+	function instantiate()
+		power.instantiate()
+		return
+	end function
+	
+	function setup_experiment(t, ...) 
+		time_last_window := t;
+	end function
+	
+	function enter_init() 
+		power.enter_init()
+		return
+	end function
+	
+	function exit_init() 
+		power.exit_init()
+		return
+	end function
+	
+	function setValues(ports, values) 		
+		in_condition_executed = empty map
+		if (true) then
+			in_condition_executed[cond1] = true
+			
+			stored_windowsa_u = values["u"]
+			stored_windowsa_d = values["d"]
+			
+			// power_sa is moore, so nothing else to do.
+			
+		end if
+		
+		out_condition_executed := empty map // force output computation.
+	end function
+	
+	function doStep(t, H)
+		
+		var e := t - time_last_window;
+		{ // new scope
+			var t := t
+			var h := H
+			var dt := 0
+			power.setValues("u", stored_windowsa_u)
+			power.setValues("d", stored_windowsa_d)
+		}
+		power.doStep(t, H);
+		time_last_window := t;
+		out_condition_executed := empty map
+	end function
+	
+	function getValues(ports)
+		var values = empty map
+		
+		if out_condition_executed == empty map then
+			if true then
+				stored_armature_current = power.getValues("armature_current")
+				out_condition_executed[cond1] := true
+			end if
+			if true then
+				stored_displacement = power.getValues("displacement")
+				out_condition_executed[cond2] := true
+			end if
+			if true then
+				stored_speed = power.getValues("speed")
+				out_condition_executed[cond3] := true
+			end if
+		end if
+		
+		if out_condition_executed[cond1] then
+			values["armature_current"] := stored_armature_current
+		end if
+		if out_condition_executed[cond2] then
+			values["displacement"] := stored_displacement
+		end if
+		if out_condition_executed[cond3] then
+			values["speed"] := stored_speed
+		end if
+		
+		return values
+	end function

+ 0 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/examples/window_sa_canonical.BASE.sa

@@ -29,13 +29,9 @@ in rules {
 	};
 }
 
-control var time_last_window := 0
-
 control rules {
-	var e := t - time_last_window;
 	invoke_update_in(t=t, h=H, dt=0);
 	window.doStep(t, H);
-	time_last_window := t;
 }
 
 out var stored_window_reaction_torque,