home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
habib
/
kodak
/
Drive_S4_10.txt
< prev
next >
Wrap
Text File
|
2000-04-18
|
6KB
|
99 lines
1000 ! DRIVE_S4_10 (JVJ 1999SEP21 MOD JVJ 1999SEP21)
1010 ! Program to simulate Nveh vehicles in line with random accels and collision avoidance
1020 ! Change force on trailing vehicles to be damped, anharmonic oscillator
1030 ! Trailing cars look at car ahead for relative position, two cars ahead for relative velocity
1040 ! Change def of Yacc_max, and greatly reduced Ydec_max (earlier value would now be written 5*Rand_max)
1050 ! Made Ydec_max a fixed value of 8 (not a multiple of Yacc_max)
1060 OPTION BASE 1
1070 INTEGER I,J,K,Nveh
1080 REAL Damp,Fprint,Freq,Lrand,Max_ypos_b,Rand_max,Tau_rand,Tdlt,Tmax,Tspace,Tyme
1090 REAL Veh_sep,Veh_length,Yacc_max,Ydamp,Ydec_max,Ypos_b,Yspring
1100 DIM Ans$[80],File$[32],Ht$[1]
1110 !
1120 File$="D4_9"
1130 Nveh=5 ! Number of vehicles in lane
1140 ALLOCATE REAL Ypos(Nveh),Yvel(Nveh),Yacc(Nveh),Yacc_rand(Nveh),Rand(Nveh)
1150 !
1160 Ht$=CHR$(9) ! Horizontal tab
1170 Tdlt=.05 ! Time interval step size [sec]
1180 Tyme=0 ! Starting time of simulation [sec]
1190 Tmax=1000 ! Maximum time of simulation
1200 Damp=1 ! Friction coefficient [1/sec]
1210 Freq=.2 ! Ocsillation freq from "spring" [1/sec]
1220 Tspace=1 ! Time between vehicles used to calc desired Veh_sep [sec]
1230 Veh_length=10 ! Length of vehicle [m]
1240 Tau_rand=1 ! Time constant used for EWMA filter in Yacc_rand [sec]
1260 Yacc_max=2 ! Ymax will be approx one sigma of EWMA distrib [m/sec^2]
1280 Ydec_max=8 ! Maximum braking decel
1290 !
1300 MAT Yvel=(20) ! Set every element in array to value 20 m/s
1310 MAT Yacc=(0) ! Set every accel to 0
1320 MAT Yacc_rand=(0)
1330 Veh_sep=Tspace*ABS(Yvel(1)) ! Calc Vehicle separtion based on speed and time separation
1340 FOR K=1 TO Nveh
1350 Ypos(K)=-K*(Veh_sep+Veh_length) ! Place vehicles at equal intervals to begin
1360 NEXT K
1370 Max_ypos_b=-Veh_sep
1380 !
1390 RANDOMIZE 100000000 ! Sets the random number generator seed
1400 !
1410 BEEP
1420 INPUT "Do you want to create a file? [Y/N]",Ans$ ! File or screen output only
1430 Fprint=(UPC$(Ans$[1])="Y")
1440 IF Fprint THEN
1450 I=52*Nveh*Tmax/Tdlt/256+1 ! Calculate approx. number of 256 byte records needed
1460 CREATE File$,I
1470 ASSIGN @File TO File$
1480 OUTPUT @File USING "K,5(A,K)";"K",Ht$,"Tyme",Ht$,"Rand",Ht$,"Ypos",Ht$,"Yvel",Ht$,"Yacc" ! Data column headers
1490 ELSE
1500 PRINT USING "6A,5(10A)";"K","Tyme","Rand","Ypos","Yvel","Yacc" ! Data column headers
1510 END IF
1520 !
1530 REPEAT
1540 Tyme=Tyme+Tdlt ! Increment time value by fixed amount
1550 Veh_sep=Tspace*MAX(ABS(MAX(Yvel(*))),ABS(MIN(Yvel(*)))) ! Veh sep based on largest abs(Yvel) of all vehicles
1552 Lrand=Tdlt/(Tdlt+Tau_rand) ! EWMA coefficient based on Tau_rand
1554 Rand_max=Yacc_max/(.58*SQR(Lrand/(2-Lrand))) ! Unif dist scaled to compensate EWMA narrowing of dist
1560 FOR K=1 TO Nveh
1570 Rand(K)=RND
1580 Yacc_rand(K)=(1-Lrand)*Yacc_rand(K)+Lrand*Rand_max*(2*Rand(K)-1) ! EWMA of random accels
1590 IF K=1 THEN
1600 Yacc(K)=Yacc_rand(K)
1610 ELSE
1620 Ypos_b=Ypos(K)-Ypos(K-1)+Veh_length ! Ypos_b is bumper-to-bumper rel position; should be neg
1630 Max_ypos_b=MAX(Ypos_b,Max_ypos_b) ! See how close (or above) zero Ypos_b ever gets
1640 IF Ypos_b>0 THEN ! This is collsion (if Vlength is actual vehicle length)
1650 BEEP 880,.02
1660 DISP "WARNING: COLLISION";K;Tyme;Ypos_b
1670 Yspring=Ydec_max ! Assign to max spring force allowed
1680 ELSE
1690 Yspring=Freq*Freq*(Ypos_b-Veh_sep*Veh_sep/Ypos_b) ! Anharmonic spring force
1700 Yspring=MIN(Yspring,Ydec_max) ! Clip to max spring force allowed
1710 END IF
1720 Ydamp=0 ! Calc damping from rel vel to each of 2 vehicles ahead
1730 FOR J=MAX(1,K-2) TO K-1
1740 Ydamp=Ydamp+Damp*(Yvel(K)-Yvel(J))
1750 NEXT J
1760 Yacc(K)=Yacc_rand(K)-Ydamp-Yspring ! Total accel is rand minus damping minus spring
1770 END IF
1780 NEXT K
1790 FOR K=1 TO Nveh
1800 Yvel(K)=Yvel(K)+Yacc(K)*Tdlt ! Calc new velocity based on new accel
1810 Ypos(K)=Ypos(K)+Yvel(K)*Tdlt ! Calc new position based on new velocity
1820 IF Fprint THEN ! Print data to file or screen
1830 OUTPUT @File USING "D,A,4D.3D,4(A,5D.3D)";K,Ht$,Tyme,Ht$,Rand(K),Ht$,Ypos(K),Ht$,Yvel(K),Ht$,Yacc(K)
1840 ELSE
1850 ! PRINT USING "D,X,4D.3D,4(X,5D.3D)";K,Tyme,Rand(K),Ypos(K),Yvel(K),Yacc(K)
1860 END IF
1870 NEXT K
1880 UNTIL Tyme>Tmax
1890 E: IF Fprint THEN ASSIGN @File TO * ! Close data path to file
1900 PRINT "Max_ypos_b=";Max_ypos_b ! Report closest approach for entire run
1910 BEEP
1920 END