MATLAB SIMULATION

profileKATONO
general_project.m

%Group x %Copyright 12/18/2013 %---------------------------------------------------------------------- %THE SIGNAL SIMULATOR PROGRAM %Generating A Rounder=rand; s=Rounder*10; A=round(s); %------------------------------------------------------------------- %THE SIGNAL PROGAM %loops through four directions in order from first to last, and invoke excution %of each %Exceting the different sub programs that build the project if A<=4; if A==1; disp('DIRECTION 1') elseif A==2; disp('DIRECTION 2') elseif A==3; disp('DIRECTION 3') else disp('EDIRECTION 1') end else disp('NO MATCHING EVENT') end %CASE_I %this sub-program displays the traffic light that is active at a %given time % Active State = Yorba Linda East and West Right changes to ON %Group x %copyright 12/12/2014 w= 1; x= 1; y= 0; z= 0; m= 0; n= 0; disp('State: Mirage West Right is ON') disp('State: Mirage East Right is ON') %CASE_II %this sub-program displays a traffic light that is ON at a %given time % Active State = Yorba Linda East and West Left changes to ON w= 0; x= 0; y= 1; z= 1; m= 0; n= 0; disp('State: Mirage West Left is ON') disp('State: Mirage East Left is ON') %CASE_III %this sub-program displays a traffic light that is ON at a %given time % Active State = Associated North,Left,Straight ON w= 0; x= 0; y= 0; z= 0; m= 1; n= 0; disp('State: Mirage North,Left,Straight ON') %CASE_IV %this sub-program displays a traffic light that is ON at a %given time % Active State = Associated South,Left,Straight ON w= 0; x= 0; y= 0; z= 0; m= 0; n= 1; disp('State:Mirage South,Left,Straight is ON') % THE LIGHT SEQUENCE GENERATOR % It displays the traffic lights GREEN,YELLOW,RED IN A SEQUENCE %The initial value is zero when there are no cars in a lane cars=0; %initialize loop control if cars>0; GREEN; YELLOW; RED; else disp('THE LANE DOES NOT CONSIST OF ANY CARS') end %CAR_GENERATOR_FUNCTION %the sub_program will help generate the number of cars in a lane %intersection random_cars=rand; %random number generator(car_generator) x=random_cars*.10; no_of_cars=round(x); if no_of_cars>=2 disp('NUMBER OF CARS',no_of_cars) else disp('No cars available') end %In this sub_program the traffic light displays light depending on the %number of cars in a given lane %We will take the minimum time to be 8secs %We will take the maximum time to be 24secs cars=0; if cars<=4; green_time_length=6; elseif cars<6; green_time_length=12; elseif cars<8; green_time_length=19; else green_time_length=23; end disp('THE TIME LENGTH OF GREEN LIGHT IS:') disp(green_time_length) disp('SECS') %DISPLAY OF GREEN LIGHT %this sub_program will add a delay to the required time in secs disp('THE TRAFFIC LIGHT IS GREEN') %DISPLAY OF YELLOW LIGHT %this sub_program will display a yellow light after the green light green_time_length=0; pause(green_time_length); display('THE TRAFFIC LIGHT IS YELLOW') pause(5); %DISPLAY OF RED LIGHT %this sub_program will display a red light after the yellow light yellow_time_length=0; pause(yellow_time_length); disp('THE TRAFFIC LIGHT IS RED') pause(5);