求助,模拟电梯系统

萌萌★洗衣机甩蘑菇

来自: 萌萌★洗衣机甩蘑菇
2008-11-28 22:04:12

×
加入小组后即可参加投票
  • 小马哥

    小马哥 2008-12-05 09:55:33

    电梯系统主要就是一个算法问题,这是核心部分 void CLiftCar::CarWork(void) { if(--this->m_iCarTime>0){ return; } if(this->m_iCarFor==NONE){ if(theLevel[this->m_iCurrentLevel].m_bUpButtonPressed==TRUE){ this->m_iCarFor=UP; this->Told("上开"); } else if(theLevel[this->m_iCurrentLevel].m_bDownButtonPressed==TRUE){ this->m_iCarFor=DOWN; this->Told("下开"); } else {//智能移动 this->Told("智能"); this->m_iCarFor=CarJudge(); this->Told((this->m_iCarFor==UP)?("上"):((this->m_iCarFor==DOWN)?"下":"停")); } this->m_bCarGateOpen=TRUE; this->m_bCarAtLevel=TRUE; this->m_iCarTime=WAITSECOND; this->CarOut(); // return; } else if(this->m_bCarAtLevel){ // STOP At Level if(this->m_bCarGateOpen==TRUE){ if(this->m_iCarFor==DOWN){ if(this->m_iCurrentLevel==this->m_iCarBottom){ this->m_iCarFor=UP; this->Told("底关"); } else { this->DownCarIn(); this->Told("下关"); } } else {//(this->m_iCarFor==UP){ if(this->m_iCurrentLevel==this->m_iCarTop){ this->m_iCarFor=DOWN; this->Told("顶关"); } else { this->UpCarIn(); this->Told("上关"); } } this->m_bCarAtLevel=FALSE; this->m_bCarGateOpen=FALSE; this->m_iCarTime=RUNNINGSECOND; // return; } else {//(this->m_bCarGateOpen==GATECLOSEED){ // Start to go if(this->m_iCarFor==DOWN){ // Internal Same Button, Go! if (this->CarBelowButton()) { this->m_bCarAtLevel=FALSE; this->m_iCarTime=RUNNINGSECOND; this->Told("下行"); } else { // No SameDIR REQ, Stop Wait this->m_iCarFor=NONE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; this->Told("停止"); } // return; } else {//(this->m_iCarFor==UP){ // Internal Same Button, Go! if(this->CarAboveButton()){ this->m_bCarAtLevel=FALSE; this->m_iCarTime=RUNNINGSECOND; this->Told("上行"); } else { // No SameDIR REQ, Stop Wait this->m_iCarFor=NONE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; this->Told("停止"); } // return; } // return; } // return; } else {// if(!this->m_bCarAtLevel){ // Car is Moving to a new Level if(this->m_iCarFor==UP){ if(this->m_iCurrentLevel<this->m_iCarTop) this->m_iCurrentLevel++; if(this->m_cButton[this->m_iCurrentLevel].m_bNonStop) { // NonStop Level this->m_iCarTime=RUNNINGSECOND; this->Told("禁停"); } else if(this->m_cButton[this->m_iCurrentLevel].m_bPushed) { if(this->m_iCurrentLevel==this->m_iCarTop){ this->m_iCarFor=DOWN; this->Told("顶开"); } else { this->m_iCarFor=UP; this->Told("上开"); } this->m_bCarAtLevel=TRUE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; // Internal Person want to go Out this->CarOut(); } else if (this->m_iCarCapacity>MAXCARPERSON-1) { //Car Full, NonStop this->m_iCarTime=RUNNINGSECOND; this->Told("满员"); } else if (theLevel[this->m_iCurrentLevel].m_bUpButtonPressed==TRUE){ // Level Same Request, Open Door this->m_bCarAtLevel=TRUE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; this->m_iCarFor=UP; this->Told("开上"); } // Internal Up Request, Keep Going else if(this->CarAboveButton()){ this->m_iCarTime=RUNNINGSECOND; this->Told("不停"); } // Upper Up, Keep Going else if(LevelAboveUp(this->m_iCurrentLevel)){ this->m_iCarTime=RUNNINGSECOND; this->Told("聚集"); } // Upper Down, Keep Going else if(LevelAboveDown(this->m_iCurrentLevel)){ this->m_iCarTime=RUNNINGSECOND; this->Told("聚集"); } else { // No Upper Request, Sleep ? this->m_bCarAtLevel=TRUE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; this->m_iCarFor=NONE; this->Told("停"); } // return; } else {//(this->m_iCarFor==DOWN){ if(this->m_iCurrentLevel>this->m_iCarBottom) this->m_iCurrentLevel--; if(this->m_cButton[this->m_iCurrentLevel].m_bNonStop) { // NonStop Level this->m_iCarTime=RUNNINGSECOND; this->Told("禁停"); } else if (this->m_cButton[this->m_iCurrentLevel].m_bPushed){ if(this->m_iCurrentLevel==0){ this->m_iCarFor=UP; this->Told("底开"); } else { this->m_iCarFor=DOWN; this->Told("下开"); } this->m_bCarAtLevel=TRUE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; // Internal Person want to go Out this->CarOut(); } else if (this->m_iCarCapacity>MAXCARPERSON-1) { //Car Full, NonStop this->m_iCarTime=RUNNINGSECOND; this->Told("满员"); } else if (theLevel[this->m_iCurrentLevel].m_bDownButtonPressed==TRUE){ // Level Same Request, Open Door this->m_bCarAtLevel=TRUE; this->m_bCarGateOpen=TRUE; this->m_iCarFor=DOWN; this->m_iCarTime=WAITSECOND; this->Told("开下"); } else if (this->CarBelowButton()) { // Internal Down Request, Keep Going this->m_iCarTime=RUNNINGSECOND; this->Told("不停"); } // Lower Down, Keep Going else if(LevelBelowDown(this->m_iCurrentLevel)){ this->m_iCarTime=RUNNINGSECOND; this->Told("聚集"); } // Lower Down, Keep Going else if(LevelBelowUp(this->m_iCurrentLevel)){ this->m_iCarTime=RUNNINGSECOND; this->Told("聚集"); } else { // No Lower Request, Sleep ? this->m_bCarAtLevel=TRUE; this->m_bCarGateOpen=TRUE; this->m_iCarTime=WAITSECOND; this->m_iCarFor=NONE; this->Told("睡眠"); } // return; } // return; } return; }

  • JohnYe

    JohnYe 2008-12-05 13:31:35

    偶当年做过这一题,弄了个定时器。 每隔500ms更新一次状态,就糊弄过去了。 呵呵呵。。。。

  • ngn999

    ngn999 (ngnis.me) 2008-12-05 23:26:18

    mark一下!我也要做这个题目了!

  • 子正-含光左卫

    子正-含光左卫 (修辞立其诚) 2008-12-12 19:50:14

    也许可以借助一下smc

  • 青菜肉丝

    青菜肉丝 2008-12-16 11:38:07

    电梯算法,elevator algorithm,自己google去

你的回应

回应请先 , 或 注册

7881 人聚集在这个小组
↑回顶部