Real-time control software design job _02_ parking Access System State machine

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.