Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need your help in elevator program

Status
Not open for further replies.

mshh

Full Member level 6
Full Member level 6
Joined
May 30, 2010
Messages
349
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
usa
Visit site
Activity points
3,871
this is the elevator algorithm that i want to do. i did it using state machine but i have a problem with storing requests while the elevator is moving

1-the elevator is at ground floor as a default then somebody calls it from nth floor during it's travel to up somebody in n-2 and n-3 called it so the elevator should go up to (n-3) floor then to (n-2) floor then to nth floor.

2- there will be seven segment and arrows to display its state and floor number ( i will hold this step now)

3- during going up somebody called the elevator to go down , but the elevator will complete it's first orders then stop and go down.

the same time that happens when going up will happen when going down if somebody in between top floor and bottom pressed a button it should stop and take him

4-if two buttons pressed at the same time go to the first one the elevator way (up or down)

5- when there are no requests the elevator is waiting at the last called floor and its door is opened .

6-when it is moving the doors should be closed and make sure it isn't opened . when the elevator stopped at the called floor don't move if the door is opened



i think that's all for now. the problem here is that i don't know how to store requests during its moving

inputs and outputs for 5 floors

inputs:

the inside buttons are connected in parallel with the outside call button just one button for up and down so i show just the inside buttons

1- BUTTON_0 //push button for first floor inside the elevator
2-BUTTON_1
3-BUTTON_2
4-BUTTON_3
5-BUTTON_4 //push button for 5th floor

6- SENSOR_0 // proximity sensor in the first floor that will sense the elevator existence
7-SENSOR_1
8-SENSOR_2
9-SENSOR_3
10-SENSOR_4

outputs:
1-go up( for the motor control)

2- go down
3- fast (for the motor working with up or down) when it is far from requested floor
4-slow (for the motor working with up or down) when reached
5-seven segment display floor number
6 - up and down arrow
7- lock for the door


the algorithm and input and outputs ,every thing is here except the code

this is the basic requirements for the elevator then i will update it if needed.


Code dot - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <mega16.h>
#include <delay.h>
 
#define BUTTON_0 PINC.0
#define BUTTON_1 PINC.1
#define BUTTON_2 PINC.2
#define BUTTON_3 PINC.3
#define BUTTON_4 PINC.4
 
#define SENSOR_0 PIND.0
#define SENSOR_1 PIND.1
#define SENSOR_2 PIND.2
#define SENSOR_3 PIND.3
#define SENSOR_4 PIND.4
//////////////////////////
#define MOVE_UP    PORTB.1
#define MOVE_DOWN PORTB.2
/////////////////////////////////
enum elevator_state {
PARKED_0,PARKED_1,PARKED_2 ,PARKED_3 , PARKED_4 ,
UP_TO_1   , UP_TO_2 , UP_TO_3   , UP_TO_4 ,DOWN_TO_3, DOWN_TO_2,
   DOWN_TO_1, DOWN_TO_0
};
////////////////////////
enum motor_direction {
STOP      = 0,   // send 0 to portb to stop the elevator
};
 
////////////////////////////
 
 
unsigned char state = PARKED_0;
unsigned char motor=STOP;
////////////////////////////
void error(void)
{
motor = STOP;
for(;;) {
     PORTB.5 = 1;
}     
}
////////////////////////////////
 
void main(void)
{
PORTB=0x00;DDRB=0xFF;
PORTC=0x00;DDRC=0x00;
PORTD=0x00;DDRD=0x00;
 
for( ;; ) {
     
     switch( state ) {
      case PARKED_0:
         if (BUTTON_1 | BUTTON_2 | BUTTON_3 | BUTTON_4) {
           state = UP_TO_1;
          PORTB.1=1;
         }
        else{
        PORTB=0;      //clear up
        }
         break;
         
      case PARKED_1:      
        if (BUTTON_2 | BUTTON_3 | BUTTON_4) {
          state = UP_TO_2;
          PORTB.1=1; // motor up
        }
       
        else if (BUTTON_0) {
          state = DOWN_TO_0;
           PORTB.2=1;     // /down
        }
        else{
                   PORTB=0;      //stop the motor
            }
      
                     
          break;
 
      case PARKED_2:      
        if (BUTTON_3 | BUTTON_4) {
          state = UP_TO_3;
           PORTB.1=1;
        }
       
        else if (BUTTON_0 | BUTTON_1) {
          state = DOWN_TO_1;
        PORTB.2=1;     // /down
          }
          
          else{
                   PORTB=0;      //stop the motor
            }
              
          break;
////////////////////////////////////////
      case PARKED_3:      
        if (BUTTON_4) {
          state = UP_TO_4;
        PORTB.1=1;
        }
        else if (BUTTON_0 | BUTTON_1 | BUTTON_2 ) {
          state = DOWN_TO_2;
           PORTB.2=1;     // /down
        }
                     
          break;
                 
      case PARKED_4:      
        if (BUTTON_0 | BUTTON_1 | BUTTON_2 | BUTTON_3) {
        PORTB.2=1;      // down
        }
                     
          break;
          
        case UP_TO_1:
       
          if (BUTTON_2 | BUTTON_3 | BUTTON_4) {
           state = UP_TO_2;
             PORTB.1=1;
         }
          
          if (SENSOR_1) {
          delay_us(10);
            state = PARKED_1;
        PORTB.1=0;
          }
          else {
             PORTB.1=1;
          }
          break;
 
        case UP_TO_2:
       
           if (BUTTON_3 | BUTTON_4) {
           state = UP_TO_3;
           PORTB.1=1;
         }
           if (SENSOR_2) {
            state = PARKED_2;
          PORTB.1=0;
          }
          else {
            motor = MOVE_UP;
          }
          break;
 
        case UP_TO_3:
                  
        if (BUTTON_4) {
           state = UP_TO_4;
           PORTB.1=1;
         }
       
        if (SENSOR_3) {
            state = PARKED_3;
       PORTB.1=0;      //clear up
          }
          else {
       PORTB.1=1;
          }
          break;
 
        case UP_TO_4:
          if (SENSOR_4) {
            state = PARKED_4;
PORTB.1=0;
          }
          else {
            motor = MOVE_UP;
          }
          break;
          
     case DOWN_TO_0:       
 
          if (SENSOR_0) {
            state = PARKED_0;
             PORTB.2=0;      //stop the motor
          }
          else {
             PORTB.2=1;     // /down
            }
            
      case DOWN_TO_1:
            
        if (BUTTON_0) {
           state = DOWN_TO_0;
           PORTB.2=1;     // /down
            }
        else if (SENSOR_1) {
            state = PARKED_1;
             PORTB.2=0;      //stop the motor
          }
          else {
             PORTB.2=1;     // /down
            }
     case DOWN_TO_2:       
           if (BUTTON_1 | BUTTON_0) {
           state = DOWN_TO_1;
           PORTB.2=1;     // /down
           } 
          if (SENSOR_2) {
            state = PARKED_2;
             PORTB.2=0;      //stop the motor
          }
          else {
             PORTB.2=1;     // /down
             PORTB.1=0;     // clear up
 
            }
            
     case DOWN_TO_3:       
           if (BUTTON_2 | BUTTON_1 | BUTTON_0) {
           state = DOWN_TO_2;
             PORTB.2=1;     // /down
            }
          else if (SENSOR_3) {
            state = PARKED_3;
             PORTB.2=0;      //stop the motor
          }
          else {
             PORTB.2=1;     // /down
             PORTB.1=0;     // clear up
 
            }
            break;
          
      default:
        error();
      }
    }
    }
      
 
 
     }

 
Last edited by a moderator:

Make an array in your program LILO(Last In Last Out). When ever a button is pressed the number is stored into your array. The elevator will ultimately go to the highest number. Using array technique you can solve the problem. If you need more help let us know.
 

yes please i don't know how to use array technique inside my code so if you write it i will be grateful and i will complete the code based on your help
 

5 step elevator program and circuit pic16f877 - picbasic
**broken link removed**
Code:
'****************************************************************

'*  Name    : UNTITLED.BAS                                      *

'*  Author  : [select VIEW...EDITOR OPTIONS]                    *

'*  Notice  : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *

'*          : All Rights Reserved                               *

'*  Date    : 2008/01/02                                        *

'*  Version : 1.0    b                                           *

'*  Notes   : mehdi rajabi 09125354921  [url]www.omidravanro.com[/url]                                                  *

'*          :                                                   *

'****************************************************************







trisa=%000000      ; port a khoruji                   1 v

trisb=%11000011      ; port b vorudi$khuruji            0 kh

trisc=%11111111      ; port c vorudi

trisd=%00000000     ;port d khoruji

trise=%111          ; port e vorudi




key0 var portc.4

key1 var portc.3 

key2 var portc.2 

key3 var portc.1 

key4 var portc.0




symbol SENs0=portb.1 

symbol SENs4=portb.0 




symbol usens=portb.6

symbol dsens=portb.7



symbol upled = portb.2

symbol hiled = portb.3

symbol loled = portb.4

symbol DOWNled = portb.5




b0 var byte

b1 var byte




test:

portb=%11000011

portd=%00000000

pause 100




main:          ;agar asansor dar paintarin tabaqe bud shenasai naravad.

if sens0=0 then

goto chek

else 

goto shenasai

endif 




shenasai:      ;asansor az har ja shasti begirad jahat shenasai be paiin beravad.

if key0=1 or key1=1 or key2=1 or key3=1 or key4=1 and sens0=1 then

downled=1

goto  jahatdn

else

goto shenasai

endif




  

jahatdn:

if sens0=0  then

pause 10

downled=0

pause 10

goto chek

else

downled=1

goto jahatdn

endif

              

chek:




low portd.7

pause 10

high portd.7

pause 10

if key0=1 or key1=1 or key2=1 or key3=1 or key4=1  then park 

goto chek




park:              




if key0=1 and sens0=1 then 

high key0

pause 10

endif

    

if key1=1 then 

high key1

pause 10

endif




if key2=1 then

high  key2

pause 10

endif




if key3=1 then 

high  key3

pause 10

endif




if key4=1 and sens4=1 then

high key4

pause 10

endif 

 

if b1=$3f and key1=1 or key2=1 or key3=1 or key4=1then runup

pause 10

if b1=$06 and key2=1 or key3=1 or key4=1 then runup

pause 10

if b1=$5b and key3=1 or key4=1 then runup 

pause 10

if b1=$4f and key4=1 then runup

pause 10

if b1=$66 and key0=1 or key1=1 or key2=1 or key3=1 then rundown

pause 10

if b1=$4f and key0=1 or key1=1 or key2=1 then rundown

pause 10

if b1=$5b and key0=1 or key1=1 then rundown

pause 10

if b1=$06 and key0=1 then rundown 

pause 10




     ; b0,[$3f,$06,$5b,$4f,$66,$6d,$7d,$07,$7f,$6f],b1  10 tabaqe (0 to 9)

stop1:

lookup b0,[$3f,$06,$5b,$4f,$66],b1         ; tarif 5 tabaqe

portd=b1

if usens=1  then 

b0=b0+1

write 1,b1

pause 10

endif

if dsens=1   then 

b0=b0-1

write 1,b1

pause 10

endif




if b1=$3f or sens0=0 and key0=1 then     ;0

hiled =0

downled=0

key0 =0

pause 10

endif




if b1=$06 and key1=1 then       ;1

 upled =0

 downled =0

 key1 =0

pause 10

endif




if b1=$5b and key2=1 then      ;2

low upled

low downled

low key2 

pause 10

endif




if b1=$4f and key3=1 then      ;3

upled=0

downled=0

low key3

pause 10

endif




if b1=$66 or sens4=0 and key4=1 then      ;4

upled=0

downled=0

low key4 

pause 10

endif

pause 50

;goto stop1

goto park



runup:

downled=0

pause 50

upled=1

pause 20

goto stop1

  



rundown:

upled=0

pause 50

downled=1

pause 20

goto stop1

  




;goto chek




         

         end
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top