Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.6 kB
3
Indexable
Never
timer(on:=timer.on, reset:=timer.reset);

// Closed = 0
IF closedFeedback AND NOT openFeedback AND NOT (state = 0) THEN
	state := 0;
	slowTurning := FALSE;
	changingState := FALSE;
	timer.on := FALSE;
	timer.reset := TRUE;
END_IF

// Open = 1
IF openFeedback AND NOT closedFeedback AND NOT (state = 1) THEN
	state := 1;
	slowTurning := FALSE;
	changingState := FALSE;
	timer.on := FALSE;
	timer.reset := TRUE;
END_IF

// Transition
IF NOT openFeedback AND NOT closedFeedback THEN
	
	// If we did not request to make a change but the valve
	// changed state then someone is turning it manually.
	manual := NOT changingState;
	
	// Open -> Close = 2
	IF state = 0 OR state = 1 THEN
		state := 2;
		timer.reset := TRUE;
		timer.on := TRUE;
	END_IF
END_IF

CASE state OF
	-1: // Error
		error := TRUE;
		
	0: // Closed
		IF openCommand AND NOT changingState THEN
			changingState := TRUE;
			timer.reset := TRUE;
			timer.on := TRUE;
		END_IF
		
		IF changingState AND timer.elapsedTime > T1 THEN
			inactive := TRUE;
		END_IF
		
	1: // Open
		IF closeCommand AND NOT changingState THEN
			changingState := TRUE;
			timer.reset := TRUE;
			timer.on := TRUE;
		END_IF
		
		IF changingState AND timer.elapsedTime > T1 THEN
			inactive := TRUE;
		END_IF
			
	2: // Neither Open or Closed (Transition)
		IF timer.elapsedTime > maxT2 THEN
			slowTurning := TRUE;
		END_IF
		
	ELSE
		error := openFeedback AND closedFeedback;
	
END_CASE

lastOpenFeedback := openFeedback;
lastClosedFeedback := closedFeedback;
openCommand := FALSE;
closeCommand := FALSE;