According to the classroom content, the state machine System state diagram can be described as follows:
The state machine system is designed according to the state diagram, the C language code is as follows:
1#include <iostream.h>2 using namespacestd;3 4 BOOL inch=false;//Vehicle Entry Brake sensor value5 BOOL out=false;//Vehicle Exit brake sensor value6 BOOLpos =false;//Landing lever position sensor, false for drop, true for lift7 intENG =0;//motor control signal, 0 for stop, 1 for positive turn lift, 2 for inverted drop8 BOOLLig =false;//traffic light control signal, false for red light, true for green9 intn =0;//represents the current state of the systemTen One voidStatus_1 () { AENG =0; -Lig =false; -cout <<"The landing lever has fallen. The traffic light is a red light and is forbidden. "; the } - - voidstatus_2{ -ENG =1; +cout <<"The vehicle is being detected, and the drop lever is being lifted, please later ..."; - } + A voidstatus_3{ atENG =0; -Lig =true; -cout <<"The landing bar has been lifted, the traffic light is green, please pass! "; - } - - voidstatus_4{ inENG =2; -Lig =false; tocout <<"the vehicle has passed and the landing lever is being lowered. "; + } - the intTest_status () { * if(inch==true){ $ if( out==false){Panax Notoginseng if(pos = =false){ - return 2; the } + } A if(pos = =true){ the if( out==false){ + return 3; - } $ } $}Else{ - if( out==true){ - if(pos = =true){ the return 4; - }Wuyi}Else{ the if(pos = =false){ - if( out==false){ Wu return 1; - } About } $ } - } - - voidMain () { A while(1){ +n =test_status (); the Switch(n) { - Case 1 : $ status_1 (); the Break; the Case 2 : the status_2 (); the Break; - Case 3 : in Status_3 (); the Break; the Case 4 : About status_4 (); the Break; the Case 0 : thecout <<"exception status, please troubleshoot system status"; + Break; - } the }Bayi } the
Real-time control software design job _02_ parking Access System State machine