Dependencies: PinDetect mbed Servo
main.cpp@0:81f78497df4e, 2012-06-18 (annotated)
- Committer:
- Rufaida
- Date:
- Mon Jun 18 17:47:17 2012 +0000
- Revision:
- 0:81f78497df4e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rufaida | 0:81f78497df4e | 1 | /***********************************************************************/ |
Rufaida | 0:81f78497df4e | 2 | |
Rufaida | 0:81f78497df4e | 3 | /* STATE MACHINE ASSIGMENT_ENB5050 */ |
Rufaida | 0:81f78497df4e | 4 | |
Rufaida | 0:81f78497df4e | 5 | /* Written by Rufaida A.Rhim ,Noora A.Aziz */ |
Rufaida | 0:81f78497df4e | 6 | |
Rufaida | 0:81f78497df4e | 7 | /* Date 13-May-2012 */ |
Rufaida | 0:81f78497df4e | 8 | |
Rufaida | 0:81f78497df4e | 9 | /* This program is written for ELEVATOR */ |
Rufaida | 0:81f78497df4e | 10 | |
Rufaida | 0:81f78497df4e | 11 | /***********************************************************************/ |
Rufaida | 0:81f78497df4e | 12 | |
Rufaida | 0:81f78497df4e | 13 | #include "mbed.h" |
Rufaida | 0:81f78497df4e | 14 | #include "definitions.h" |
Rufaida | 0:81f78497df4e | 15 | #include "actions.h" |
Rufaida | 0:81f78497df4e | 16 | #include "events.h" |
Rufaida | 0:81f78497df4e | 17 | #include "ding.h" |
Rufaida | 0:81f78497df4e | 18 | #include "door_leds.h" |
Rufaida | 0:81f78497df4e | 19 | #include "Motor.h" |
Rufaida | 0:81f78497df4e | 20 | |
Rufaida | 0:81f78497df4e | 21 | events event; |
Rufaida | 0:81f78497df4e | 22 | states state; |
Rufaida | 0:81f78497df4e | 23 | |
Rufaida | 0:81f78497df4e | 24 | /*check the program on PuTTY */ |
Rufaida | 0:81f78497df4e | 25 | const char event_lookup[MAX_EVENTS][25] ={"ev_Go_To_Bottom_Button", "ev_Go_To_Top_Button", "ev_Bottom_Call_Button", "ev_Top_Call_Button", "ev_Near_Top_Button", "ev_Near_Bottom_Button", "ev_Top_Button", "ev_Bottom_Button", "ev_Timeout", "ev_Safety","ev_loading_event"}; |
Rufaida | 0:81f78497df4e | 26 | const char state_lookup[MAX_STATES][25] ={"st_At_Top_Closed", "st_Going_Bottom", "st_Wait_For_Bottom", "st_Wait_For_Ding_Bottom", "st_Wait_For_door_Bottom","st_At_Bottom_Closed", "st_Going_Up","st_Wait_For_Top,", "st_Wait_For_Ding_Top", "st_Wait_For_door_Top", "st_Wait_For_Safety", "st_Wait_For_Bottom_Floor"}; |
Rufaida | 0:81f78497df4e | 27 | |
Rufaida | 0:81f78497df4e | 28 | /* This is the state table with actions, states, and events */ |
Rufaida | 0:81f78497df4e | 29 | void (*const state_table [MAX_STATES][MAX_EVENTS]) (void)={ |
Rufaida | 0:81f78497df4e | 30 | // ev_Go_To_Bottom_Button ev_Go_To_Top_Button ev_Bottom_Call_Button ev_Top_Call_Button ev_Near_Top_Button ev_Near_Bottom_Button ev_Top_Button ev_Bottom_Button ev_Timeout ev_Safety ev_loading_event |
Rufaida | 0:81f78497df4e | 31 | { act_ramp_motor_down, act_open_close_Top_door, act_ramp_motor_down, act_open_close_Top_door, do_nothing, do_nothing, act_stop_motor_ding_top, do_nothing, do_nothing, act_slow_to_dowm, do_nothing }, //function for state st_At_Top_Closed |
Rufaida | 0:81f78497df4e | 32 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_slow_speed_down, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing }, //function for state st_Going_Bottom |
Rufaida | 0:81f78497df4e | 33 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_slow_speed_down, do_nothing, act_stop_motor_ding_bottom, do_nothing, do_nothing, do_nothing }, //function for state st_Wait_For_Bottom |
Rufaida | 0:81f78497df4e | 34 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_open_close_Bottom_door, do_nothing, do_nothing }, //function for state st_Wait_For_Ding_Bottom |
Rufaida | 0:81f78497df4e | 35 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_bottom_close, do_nothing, do_nothing }, //function for state st_Wait_For_door_Bottom |
Rufaida | 0:81f78497df4e | 36 | { act_open_close_Bottom_door, act_ramp_motor_up, act_open_close_Bottom_door, act_ramp_motor_up, do_nothing, do_nothing, do_nothing, act_stop_motor_ding_bottom, do_nothing, do_nothing, do_nothing }, //function for state st_At_Bottom_Closed |
Rufaida | 0:81f78497df4e | 37 | { do_nothing, do_nothing, do_nothing, do_nothing, act_slow_speed_up, do_nothing, do_nothing, do_nothing, do_nothing, act_slow_to_dowm, do_nothing }, //function for state st_Going_Up |
Rufaida | 0:81f78497df4e | 38 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_stop_motor_ding_top, do_nothing, do_nothing, act_slow_to_dowm, do_nothing }, //function for state st_Wait_For_Top |
Rufaida | 0:81f78497df4e | 39 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_open_close_Top_door, do_nothing, do_nothing }, //function for state st_wait_For_Ding_Top |
Rufaida | 0:81f78497df4e | 40 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_top_close, do_nothing, do_nothing }, //function for state st_Wait_For_door_Top |
Rufaida | 0:81f78497df4e | 41 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_slow_to_dowm, do_nothing }, //function for state st_Wait_For_Safety |
Rufaida | 0:81f78497df4e | 42 | { do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, do_nothing, act_stop_motor_ding_bottom, do_nothing, do_nothing, do_nothing }, //function for state st_Wait_For_Bottom_Floor |
Rufaida | 0:81f78497df4e | 43 | |
Rufaida | 0:81f78497df4e | 44 | }; |
Rufaida | 0:81f78497df4e | 45 | /*the main function which starts the doors,motor and ding*/ |
Rufaida | 0:81f78497df4e | 46 | int main (void) { |
Rufaida | 0:81f78497df4e | 47 | Starting_Motor(); |
Rufaida | 0:81f78497df4e | 48 | initialise_events(); |
Rufaida | 0:81f78497df4e | 49 | Start_up_sound(); |
Rufaida | 0:81f78497df4e | 50 | Starting_LEDS(); |
Rufaida | 0:81f78497df4e | 51 | motor(up_slow,0); |
Rufaida | 0:81f78497df4e | 52 | |
Rufaida | 0:81f78497df4e | 53 | state = st_Wait_For_Safety; |
Rufaida | 0:81f78497df4e | 54 | printf("Statrting State: %s\n",state_lookup[state]); |
Rufaida | 0:81f78497df4e | 55 | |
Rufaida | 0:81f78497df4e | 56 | |
Rufaida | 0:81f78497df4e | 57 | while (1) { |
Rufaida | 0:81f78497df4e | 58 | event=get_event(); |
Rufaida | 0:81f78497df4e | 59 | printf("Event: %s ",event_lookup[event]); |
Rufaida | 0:81f78497df4e | 60 | state_table[state][event](); |
Rufaida | 0:81f78497df4e | 61 | printf("State: %s\n",state_lookup[state]); |
Rufaida | 0:81f78497df4e | 62 | } |
Rufaida | 0:81f78497df4e | 63 | } |