Browse Source

changed dsl according to what's discussed
update-in and out rules indeed do not change the state

Bart Meyers 8 years ago
parent
commit
a658b30857

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow.sa

@@ -4,7 +4,7 @@ semantic adaptation controller_sa
 for fmu controller
 input ports armature_current -> obj_detected, passenger_up, passenger_down, driver_up, driver_down, next
 output ports up, down
-control rules { triggered by signal == true or t >= get_next_time_step(controller) }
+triggered by signal == true or t >= get_next_time_step(controller)
 in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
 	armature_current >! 5 -> obj_detected := true;
 	otherwise(armature_current) -> obj_detected := false;

+ 3 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_iteration_BASE.sa

@@ -17,7 +17,7 @@ output ports armature_current
 param MAXITER = 100;
 param REL_TOL = 1e-8;
 param ABS_TOL = 1e-8;
-control rules {
+control {
 	// do_step will always use the last values, do_step does not advance time so will replace the last signal values! 
 	// therefore, we must set the signal at time t+h of reaction_torque and height
 	// this is done by a very weird statement:
@@ -58,7 +58,7 @@ output ports reaction_torque
 param MAXITER = 100;
 param REL_TOL = 1e-8;
 param ABS_TOL = 1e-8;
-control rules {
+control {
 	var prev_height; // to compare new value with previous value
 	var window_state;
 	var obstacle_state;
@@ -83,7 +83,7 @@ output ports reaction_torque
 param MAXITER = 100;
 param REL_TOL = 1e-8;
 param ABS_TOL = 1e-8;
-control rules {
+control {
 	var prev_height; // to compare new value with previous value
 	var window_state;
 	var obstacle_state;

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay.sa

@@ -4,7 +4,7 @@ module Controller_SA
 
 semantic adaptation armature_current_sa
 for fmu controller
-control rules { triggered by signal == true }
+triggered by signal == true
 in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
 	armature_current >! 5 -> obj_detected := true;
 	otherwise(armature_current) -> obj_detected := false;

+ 8 - 13
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay_BASE.sa

@@ -12,24 +12,17 @@ param CROSSING = 5;
 param init_armature_current = CROSSING;
 param init_up = 0;
 param init_down = 0;
-control var internal_transition;
-control rules { // overwriting master! What to do in case of roll back? How to reuse generic algorithm
-	if (not is_set(internal_transition)) { // only at start of simulation
-		var state := get_state(controller);
-		internal_transition := do_step(controller, MAX) + t; // may return internal transition time or MAX
-		set_state(controller, state);
-	}
+control { // overwriting master! What to do in case of roll back? How to reuse generic algorithm
 	var step_size; // may be used to determine roll-back
 	if (signal == true or t >= internal_transition) {
-		step_size := do_step(controller, H); // do a step, then decide next internal transition
-		var state := get_state(controller);
-		internal_transition := do_step(controller, MAX) + t;
-		set_state(controller, state);
+		step_size := do_step(controller, e+H); // do a step, then decide next internal transition
 	}
 	return step_size;
 }
 in var stored_armature_current := init_armature_current;
+in var internal_transition;
 in rules {
+	not is_set(internal_transition) -> { internal_transition := get_next_time_step(controller) + t; } --> { };
 	true -> {
 		obj_detected := false;
 		if (not (not is_close(stored_armature_current, CROSSING, REL_TOL, ABS_TOL) and stored_armature_current > CROSSING)
@@ -46,10 +39,12 @@ in rules {
 		}
 		stored_armature_current := armature_current;
 	} --> { };
+	
 }
 out var stored_up := init_up;
 out var stored_down := init_down;
 out rules {
+	true -> { internal_transition := get_next_time_step(controller) + t; } --> {};
 	up == true -> { up := 1; } --> { };
 	otherwise up -> { } --> { };
 	down == true -> { down := 1; } --> { };
@@ -62,10 +57,10 @@ out rules {
 
 
 // other suggestion for implementing get_next_time_step, making it easier to generate baseDSL code
-/*control rules { // overwriting master! What to do in case of roll back? How to reuse generic algorithm
+/*control { // overwriting master! What to do in case of roll back? How to reuse generic algorithm
        var step_size; // may be used to determine roll-back
        if (signal == true or t >= internal_transition) {
-             step_size := do_step(controller, H); // do a step, then decide next internal transition
+             step_size := do_step(controller, e+H); // do a step, then decide next internal transition
        }
        return step_size;
 }

+ 1 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_multi_rate_BASE.sa

@@ -15,7 +15,7 @@ for fmu window_obstacle_sa_loop
 input ports motor_speed
 output ports reaction_torque
 param init_motor_speed = 0;
-control rules {
+control {
 	var h := H/10;
 	var proposed_h := H;
 	for (var iter in 0 .. 10) {

+ 12 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext

@@ -46,7 +46,9 @@ Adaptation:
 	// note that the order of semantic adaptations is prefixed in case of a algebraic loop:
 	// adaptations on internal signals of the loop are inner most, then the algebraic loop iteration, then adaptations on external signals
 	(generalrules+=GeneraleRule)*
-	((in=InRulesBlock)? & (out=OutRulesBlock)? & (control=ControlRuleBlock)?)
+	(control=ControlRuleBlock)?
+	(in=InRulesBlock)?
+	(out=OutRulesBlock)?
 //	('contains' '{' adaptations+=Adaptation+ '}')? // I prefer no structural information here, this belongs to a graphical model
 	;
 	
@@ -88,7 +90,7 @@ OutRulesBlock:
 	{OutRulesBlock} ('out' globalvars+=Declaration)* 'out' 'rules' ('with' setting+=GeneralSetting (',' setting+=GeneralSetting)*)? '{' iterationvars+=Declaration* rules+=DataRule* '}';
 
 ControlRuleBlock:
-	{ControlRuleBlock} ('control' globalvars+=Declaration)*  'control' 'rules' '{' controlrule=ControlRule '}'; // TODO: multiple rules or just one?
+	/*('control' globalvars+=Declaration)**/ ControlRule; // TODO: multiple rules or just one?
 
 DataRule: // condition -> state transition --> output function
 	(((condition=RuleCondition "->" statetransitionfunction=StateTransitionFunction) | ConditionStateTransition | ConditionLessRule) ("-->" outputfunction=OutputFunction)? | AlgebraicLoopSolution) ';';
@@ -138,11 +140,11 @@ OutputFunction:
 	{CompositeOutputFunction} '{' statements+=Statement* (returnstatement=ReturnStatement)? '}';
 	
 ControlRule:
-	{TriggeredControlRule} 'triggered' 'by' condition=Expression |
 	{ImpliedControlRule} 'implied' | // the default
+	{TriggeredControlRule} 'triggered' 'by' condition=Expression |
 	{PeriodicControlRule} 'periodic' ('at' init_time=REALTYPE)? 'every' period=REALTYPE | 
 	{MultipliedControlRule} 'multiplied' multiplication=INT 'times' | 
-	{CustomControlRule} statements+=Statement* returnstatement=ReturnStatement;
+	{CustomControlRule} 'control' '{' ControlRulestatements+=Statement* returnstatement=ReturnStatement '}'; // TODO: how do we know if control is given?
 
 AnonymousFunction: // has access to ports
 	{FunctionExpression} '{=' code=Expression '}'| 
@@ -160,6 +162,7 @@ Port:
 	// TODO: add internal destination/source of port
 	// Unity conversions: https://pint.readthedocs.io/en/0.7.2/
 	name=ID (':=' initval=LiteralOrArray)? ( multiplicity=Multiplicity )? ( '(' unity=Unity ')' )? ('->' target=[SpecifiedPort] | '-->' dependency+=[SpecifiedPort] (dependency+=[SpecifiedPort])*)?;
+	// TODO: -> output port of wrapped FMU to output port of SA FMU (only used in SA!)
 
 Multiplicity:
 	'[' (lower=INT '..')? upper=INT ']';
@@ -214,7 +217,7 @@ AbstractDeclaration: // can contain overlapping elements as long as it is only u
 	Port | ParamDeclaration | Declaration | DeclaredParameter | FunctionDeclaration;
 
 LValueDeclaration: // can contain overlapping elements as long as it is only used as reference
-	Port | ParamDeclaration | Declaration | DeclaredParameter;
+	Port | ParamDeclaration | Declaration | DeclaredParameter; // TODO: fmu.port
 
 Assignment:
 	lvalue=Variable ':=' expr=Expression; // TODO: to what can be assigned? only local vars?
@@ -318,8 +321,8 @@ BuiltinFunction:
 	{IsSet} name='is_set' '(' args=Variable ')' | 
 	{DoStepFun} name='do_step' '(' fmu=[FMU] ',' H=ArithmeticExpression ')' |
 	{GetState} name='get_state' '(' fmu=[FMU] ')' |
-	{GetNextInternalTimeStep} name='get_next_time_step' '(' fmu=[FMU] ')' // is actually the time step returned by do_step(fmu), preceded by get_state and succeeded by set_state
-	;
+	{GetNextInternalTimeStep} name='get_next_time_step' '(' fmu=[FMU] ')' | // is actually the time step returned by do_step(fmu), preceded by get_state and succeeded by set_state
+	{Elapsed} name='elapsed' '(' fmu=[FMU] ')';
 	
 Procedure:
 	{Reject} name='reject' |
@@ -330,7 +333,8 @@ Procedure:
 	
 Var:
 	{StepSize} name='H' | 
-	{CurrentTime} name='t' | 
+	{CurrentTime} name='t' |
+	{ElapsedTime} name='e' | // min (elapsed(fmu1), elapsed(fmu2), ...)
 	{Max} name='MAX' |
 	{GenericSignal} name='signal' ('[' (
 		index=NOW |