Untitled

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

// Error = -1
IF openFeedback AND closedFeedback THEN
	state := -1;
	timerEnable := FALSE;
	timer.reset := TRUE;
END_IF

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

// Open = 1
IF openFeedback AND NOT closedFeedback AND NOT (state = 1) THEN
	state := 1;
	changingState := FALSE;
	timerEnable := 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.
	IF NOT changingState THEN
		manual := TRUE;
	END_IF
	
	// Open -> Close = 2
	IF state = 0 THEN
		state := 2;
		timer.reset := TRUE;
		timerEnable := TRUE;
	END_IF
	
	// Close -> Open = 3
	IF state = 1 THEN
		state := 3;
		timer.reset := TRUE;
		timerEnable := TRUE;
	END_IF
END_IF

CASE state OF 
	-1: // Error
		error := TRUE;
		RETURN;
		
	0: // Closed
		IF openCommand AND NOT changingState THEN
			changingState := TRUE;
			timer.reset := TRUE;
			timerEnable := 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;
			timerEnable := TRUE;
		END_IF
		
		IF changingState AND timer.elapsedTime > T1 THEN
			inactive := TRUE;
		END_IF
		
	2: // Open -> Close
		IF timer.elapsedTime > maxT2 THEN
			slowTurning := TRUE;
		END_IF
		
	3: // Close -> Open
		IF timer.elapsedTime > maxT2 THEN
			slowTurning := TRUE;
		END_IF
END_CASE

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