mshh
Full Member level 6
- Joined
- May 30, 2010
- Messages
- 349
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- usa
- 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.
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: