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 >
Text File  |  2000-04-18  |  6KB  |  99 lines

  1. 1000   ! DRIVE_S4_10 (JVJ 1999SEP21 MOD JVJ 1999SEP21)
  2. 1010   ! Program to simulate Nveh vehicles in line with random accels and collision avoidance
  3. 1020   ! Change force on trailing vehicles to be damped, anharmonic oscillator
  4. 1030   ! Trailing cars look at car ahead for relative position, two cars ahead for relative velocity
  5. 1040   ! Change def of Yacc_max, and greatly reduced Ydec_max (earlier value would now be written 5*Rand_max)
  6. 1050   ! Made Ydec_max a fixed value of 8 (not a multiple of Yacc_max)
  7. 1060     OPTION BASE 1
  8. 1070     INTEGER I,J,K,Nveh
  9. 1080     REAL Damp,Fprint,Freq,Lrand,Max_ypos_b,Rand_max,Tau_rand,Tdlt,Tmax,Tspace,Tyme
  10. 1090     REAL Veh_sep,Veh_length,Yacc_max,Ydamp,Ydec_max,Ypos_b,Yspring
  11. 1100     DIM Ans$[80],File$[32],Ht$[1]
  12. 1110     !
  13. 1120     File$="D4_9"
  14. 1130     Nveh=5                                   ! Number of vehicles in lane
  15. 1140     ALLOCATE REAL Ypos(Nveh),Yvel(Nveh),Yacc(Nveh),Yacc_rand(Nveh),Rand(Nveh)
  16. 1150     !
  17. 1160     Ht$=CHR$(9)                              ! Horizontal tab
  18. 1170     Tdlt=.05                                 ! Time interval step size [sec]
  19. 1180     Tyme=0                                   ! Starting time of simulation [sec]
  20. 1190     Tmax=1000                                ! Maximum time of simulation
  21. 1200     Damp=1                                   ! Friction coefficient [1/sec]
  22. 1210     Freq=.2                                  ! Ocsillation freq from "spring" [1/sec]
  23. 1220     Tspace=1                                 ! Time between vehicles used to calc desired Veh_sep [sec]
  24. 1230     Veh_length=10                            ! Length of vehicle [m]
  25. 1240     Tau_rand=1                               ! Time constant used for EWMA filter in Yacc_rand [sec]
  26. 1260     Yacc_max=2                               ! Ymax will be approx one sigma of EWMA distrib [m/sec^2]
  27. 1280     Ydec_max=8                               ! Maximum braking decel                   
  28. 1290     !
  29. 1300     MAT Yvel=(20)                            ! Set every element in array to value 20 m/s
  30. 1310     MAT Yacc=(0)                             ! Set every accel to 0
  31. 1320     MAT Yacc_rand=(0)
  32. 1330     Veh_sep=Tspace*ABS(Yvel(1))              ! Calc Vehicle separtion based on speed and time separation
  33. 1340     FOR K=1 TO Nveh
  34. 1350       Ypos(K)=-K*(Veh_sep+Veh_length)        ! Place vehicles at equal intervals to begin
  35. 1360     NEXT K
  36. 1370     Max_ypos_b=-Veh_sep
  37. 1380     !
  38. 1390     RANDOMIZE 100000000                      ! Sets the random number generator seed
  39. 1400     !
  40. 1410     BEEP
  41. 1420     INPUT "Do you want to create a file? [Y/N]",Ans$  ! File or screen output only
  42. 1430     Fprint=(UPC$(Ans$[1])="Y")
  43. 1440     IF Fprint THEN
  44. 1450       I=52*Nveh*Tmax/Tdlt/256+1                   ! Calculate approx. number of 256 byte records needed
  45. 1460       CREATE File$,I
  46. 1470       ASSIGN @File TO File$
  47. 1480       OUTPUT @File USING "K,5(A,K)";"K",Ht$,"Tyme",Ht$,"Rand",Ht$,"Ypos",Ht$,"Yvel",Ht$,"Yacc" ! Data column headers
  48. 1490     ELSE
  49. 1500       PRINT USING "6A,5(10A)";"K","Tyme","Rand","Ypos","Yvel","Yacc"  ! Data column headers
  50. 1510     END IF
  51. 1520     !
  52. 1530     REPEAT
  53. 1540       Tyme=Tyme+Tdlt                         ! Increment time value by fixed amount
  54. 1550       Veh_sep=Tspace*MAX(ABS(MAX(Yvel(*))),ABS(MIN(Yvel(*)))) ! Veh sep based on largest abs(Yvel) of all vehicles
  55. 1552       Lrand=Tdlt/(Tdlt+Tau_rand)             ! EWMA coefficient based on Tau_rand
  56. 1554       Rand_max=Yacc_max/(.58*SQR(Lrand/(2-Lrand)))  ! Unif dist scaled to compensate EWMA narrowing of dist
  57.  
  58.  
  59.  
  60. 1560       FOR K=1 TO Nveh
  61. 1570         Rand(K)=RND
  62. 1580         Yacc_rand(K)=(1-Lrand)*Yacc_rand(K)+Lrand*Rand_max*(2*Rand(K)-1)  ! EWMA of random accels
  63. 1590         IF K=1 THEN
  64. 1600           Yacc(K)=Yacc_rand(K)
  65. 1610         ELSE
  66. 1620           Ypos_b=Ypos(K)-Ypos(K-1)+Veh_length     ! Ypos_b is bumper-to-bumper rel position; should be neg
  67. 1630           Max_ypos_b=MAX(Ypos_b,Max_ypos_b)       ! See how close (or above) zero Ypos_b ever gets
  68. 1640           IF Ypos_b>0 THEN                        ! This is collsion (if Vlength is actual vehicle length)
  69. 1650             BEEP 880,.02
  70. 1660             DISP "WARNING: COLLISION";K;Tyme;Ypos_b
  71. 1670             Yspring=Ydec_max                      ! Assign to max spring force allowed
  72. 1680           ELSE
  73. 1690             Yspring=Freq*Freq*(Ypos_b-Veh_sep*Veh_sep/Ypos_b)   ! Anharmonic spring force
  74. 1700             Yspring=MIN(Yspring,Ydec_max)         ! Clip to max spring force allowed
  75. 1710           END IF
  76. 1720           Ydamp=0                                 ! Calc damping from rel vel to each of 2 vehicles ahead
  77. 1730           FOR J=MAX(1,K-2) TO K-1
  78. 1740             Ydamp=Ydamp+Damp*(Yvel(K)-Yvel(J))
  79. 1750           NEXT J
  80. 1760           Yacc(K)=Yacc_rand(K)-Ydamp-Yspring      ! Total accel is rand minus damping minus spring
  81. 1770         END IF
  82. 1780       NEXT K
  83.  
  84.  
  85. 1790       FOR K=1 TO Nveh
  86. 1800         Yvel(K)=Yvel(K)+Yacc(K)*Tdlt              ! Calc new velocity based on new accel
  87. 1810         Ypos(K)=Ypos(K)+Yvel(K)*Tdlt              ! Calc new position based on new velocity
  88. 1820         IF Fprint THEN                            ! Print data to file or screen
  89. 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)
  90. 1840         ELSE
  91. 1850   !       PRINT USING "D,X,4D.3D,4(X,5D.3D)";K,Tyme,Rand(K),Ypos(K),Yvel(K),Yacc(K)
  92. 1860         END IF
  93. 1870       NEXT K
  94. 1880     UNTIL Tyme>Tmax
  95. 1890 E:  IF Fprint THEN ASSIGN @File TO *              ! Close data path to file
  96. 1900     PRINT "Max_ypos_b=";Max_ypos_b                ! Report closest approach for entire run
  97. 1910     BEEP
  98. 1920     END
  99.