mirror of
https://github.com/NohamR/Stage-2023.git
synced 2025-05-23 16:39:02 +00:00
gipps + pipes
This commit is contained in:
parent
edbd2c138b
commit
27527819fa
122
gipps/gipps.py
Normal file
122
gipps/gipps.py
Normal file
@ -0,0 +1,122 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
from colour import Color
|
||||
|
||||
# ===========
|
||||
t0 = 0
|
||||
tf = 30
|
||||
dt = 1
|
||||
t = t0
|
||||
# ===========
|
||||
nbv = 2
|
||||
|
||||
"""# =========== VARIABBLES
|
||||
Xn(t) # position au temps t
|
||||
Vn(t) # vitesse au temps t
|
||||
An(t+Tr) # accel au temps t + Tr
|
||||
ln # ?
|
||||
k # ?
|
||||
m # ?
|
||||
"""
|
||||
|
||||
# =========== CONSTANTES
|
||||
An = 1.7 # accel max sampled from a normal distribution. N(1.7,0.3²) m/s²
|
||||
Bn = -2 * An # frein max equated to - 2An
|
||||
Sn = 6.5 # taille de la voiture plus marge sampled from a normal distribution. N(6.5,0.3²) m
|
||||
Vd = 20.0 # vitesse désirée sampled from a normal distribution. N(20.0,3.2²) m/sec
|
||||
# X*n # position fin de freinage (calculable)
|
||||
Tr = 2/3 + (2/3)/2 # temps de réaction + sûreté (= tau + θ = 2/3 + tau/2)
|
||||
# B supposé égal à Bn-1 (si pas égal alors amplifications ??)
|
||||
|
||||
|
||||
def rainbow_gradient(num_colors):
|
||||
colors = []
|
||||
base_color = Color("violet")
|
||||
gradient = list(base_color.range_to(Color("red"), num_colors))
|
||||
for color in gradient:
|
||||
hex_code = color.hex_l
|
||||
colors.append(hex_code)
|
||||
return colors
|
||||
colors = rainbow_gradient(nbv)
|
||||
|
||||
def px(xx): # Avance au cours du temps
|
||||
xx += 1
|
||||
return xx
|
||||
|
||||
def vitesseatt(t, yy): # Vitesse qu'il peut réellement atteindre d'un point de vue dynamique
|
||||
|
||||
|
||||
|
||||
Vnt = yy[-1]
|
||||
|
||||
value = Vnt + 2.5 * An * Tr * ( 1 - (Vnt/Vd) ) * np.sqrt( ( 0.025 + (Vnt/Vd) ))
|
||||
print('value: ', value)
|
||||
|
||||
yy[0] = value
|
||||
newyy = yy
|
||||
print('newyy: ', newyy)
|
||||
return newyy
|
||||
|
||||
|
||||
def vitesseadop(t, yy): # Vitesse qu'il est possible d'adopter en connaissant les contraintes de sécurité liées à la présence du véhicule leader
|
||||
t = t + Tr
|
||||
pass
|
||||
|
||||
def vitessereelle(t, yyold): # Vitesse du véhicule
|
||||
print(len(yy))
|
||||
t = t + Tr
|
||||
if (t>= 0) and (t<=10):
|
||||
yy[-1] = 0 # Arrêt du leader
|
||||
elif (t>= 15) and (t<=20):
|
||||
|
||||
else:
|
||||
yy[-1] = Vd # Leader avance normalement
|
||||
|
||||
|
||||
# a = np.where(t <= 10, (Umax - Umin) / 10, - (Umax - Umin) / 10)
|
||||
# vt = np.where(t <= 10, Umin + a * t, Umax + 2 * a * (t - 10))
|
||||
|
||||
|
||||
|
||||
|
||||
vatt = vitesseatt(t, yyold)
|
||||
vadop = vitesseadop(t, yyold)
|
||||
# return min(vatt, vadop)
|
||||
return vatt
|
||||
|
||||
|
||||
xxbase = np.linspace(-nbv, -1, nbv)
|
||||
yybase = np.linspace(0, 0, nbv)
|
||||
|
||||
xxold = xxbase.copy()
|
||||
yyold = yybase.copy()
|
||||
|
||||
while(t<tf):
|
||||
plt.figure(1,figsize=[16,9])
|
||||
plt.clf()
|
||||
plt.xlim([-1,31])
|
||||
plt.ylim([-0.5, Vd+1])
|
||||
|
||||
|
||||
xx = px(xxold)
|
||||
print('xx: ', len(xx))
|
||||
|
||||
yy = vitessereelle(t, yyold)
|
||||
print('yyold: ', len(yyold))
|
||||
print('yy: ', len(yy))
|
||||
|
||||
|
||||
plt.scatter(xx, yy, c=colors)
|
||||
|
||||
|
||||
plt.plot([0,30],[Vd, Vd], color='k', linestyle='-', linewidth=1)
|
||||
plt.xlabel('temps en s')
|
||||
plt.ylabel('vitesse en m.s-¹')
|
||||
plt.title('Vitesse maximale désirée\nvitesse du leader : ' + str(Vd) + 'm.s-¹\ndistance minimale entre deux voitures : ' + str('') + 'm\n\nTemps : ' + str(t))
|
||||
plt.draw()
|
||||
# plt.savefig(str(t)+'.png')
|
||||
plt.pause(1)
|
||||
t += dt
|
||||
xxold = xx.copy()
|
||||
yyold = yy.copy()
|
BIN
gipps/graph.png
Normal file
BIN
gipps/graph.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
43
gipps/graph.py
Normal file
43
gipps/graph.py
Normal file
@ -0,0 +1,43 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# =========== CONSTANTES
|
||||
An = 1.7 # accel max sampled from a normal distribution. N(1.7,0.3²) m/s²
|
||||
Bn = -2 * An # frein max equated to - 2An
|
||||
Sn = 6.5 # taille de la voiture plus marge sampled from a normal distribution. N(6.5,0.3²) m
|
||||
Vd = 20.0 # vitesse désirée sampled from a normal distribution. N(20.0,3.2²) m/sec
|
||||
# X*n # position fin de freinage (calculable)
|
||||
Tr = 2/3 + (2/3)/2 # temps de réaction + sûreté (= tau + θ = 2/3 + tau/2)
|
||||
# B supposé égal à Bn-1 (si pas égal alors amplifications ??)
|
||||
|
||||
|
||||
vv = np.linspace(0, 100, 200)
|
||||
|
||||
def vitesseatt(vv): # Vitesse qu'il peut réellement atteindre d'un point de vue dynamique
|
||||
value = vv + 2.5 * An * Tr * ( 1 - (vv/Vd) ) * np.sqrt( ( 0.025 + (vv/Vd) ))
|
||||
return value
|
||||
|
||||
|
||||
def vitesseadop(vv): # Vitesse qu'il est possible d'adopter en connaissant les contraintes de sécurité liées à la présence du véhicule leader
|
||||
value = 1
|
||||
return value
|
||||
|
||||
def vitessereelle(vv): # Vitesse maximale désirée
|
||||
vatt = vitesseatt(vv)
|
||||
vadop = vitesseadop(vv)
|
||||
return min(vatt, vadop)
|
||||
|
||||
plt.figure(figsize=[16,9])
|
||||
|
||||
|
||||
plt.plot(vv, vitesseatt(vv), '-', color='red', label='No mask')
|
||||
# plt.plot(vv, vitesseadop(vv), '-', color='green', label='No mask')
|
||||
|
||||
|
||||
plt.legend()
|
||||
plt.title('Variation de la vitesse de la voiture suivant en fonction de la voiture leader')
|
||||
plt.xlabel('vitesse de la voiture leader en m.s-¹')
|
||||
plt.ylabel('vitesse de la voiture qui suit en m.s-¹')
|
||||
plt.savefig('gipps/graph.png')
|
||||
plt.draw()
|
||||
plt.pause(4)
|
16
modelv.py
16
modelv.py
@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
from colour import Color
|
||||
|
||||
t0 = 0
|
||||
tf = 20
|
||||
@ -13,6 +14,17 @@ U = 1.25 # vitesse m.s-¹
|
||||
Wm = 0.3 # distance minimale entre la voiture et celle qui la précède m
|
||||
Ws = 0.9 # m
|
||||
|
||||
def rainbow_gradient(num_colors):
|
||||
colors = []
|
||||
base_color = Color("violet")
|
||||
gradient = list(base_color.range_to(Color("red"), num_colors))
|
||||
for color in gradient:
|
||||
hex_code = color.hex_l
|
||||
colors.append(hex_code)
|
||||
return colors
|
||||
colors = rainbow_gradient(11)
|
||||
|
||||
|
||||
def phi(ww): # prend en entrée la distance entre les deux véhicules
|
||||
PHI = (U*(1 - np.exp(- (ww-Wm)/Ws)))
|
||||
return (ww >= Wm)* PHI # retourne la vitesse du véhicule
|
||||
@ -39,10 +51,10 @@ while(t<tf):
|
||||
plt.ylim([-0.5, 1.5])
|
||||
vt = vitesses(xxold)
|
||||
xx = position(xxold, vt)
|
||||
color = ['#ff0000', '#ff5300', '#ffa500', '#ffd200', '#ffff00', '#80c000', '#008000', '#004080', '#0000ff', '#2600c1', '#4b0082']
|
||||
# color = ['#ff0000', '#ff5300', '#ffa500', '#ffd200', '#ffff00', '#80c000', '#008000', '#004080', '#0000ff', '#2600c1', '#4b0082']
|
||||
plt.scatter(xx, vt)
|
||||
print(xx)
|
||||
plt.scatter(xx, y, c=color)
|
||||
plt.scatter(xx, y, c=colors)
|
||||
plt.plot([0,20],[1.25, 1.25], color='k', linestyle='-', linewidth=1)
|
||||
plt.xlabel('distance w en m')
|
||||
plt.ylabel('vitesse en m.s-¹')
|
||||
|
29
pipes/dist sécurité.py
Normal file
29
pipes/dist sécurité.py
Normal file
@ -0,0 +1,29 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
vt = 1.25 # 4,5 km/h
|
||||
Umin = 1 # vitesse m/s
|
||||
Umax = 36 # environ 130 km/h
|
||||
Wm = 4.23 # longueur du véhicule en m (moyenne française)
|
||||
t = np.linspace(0, 15, 400)
|
||||
|
||||
def vitesse(t):
|
||||
a = np.where(t <= 10, (Umax - Umin) / 10, - (Umax - Umin) / 10)
|
||||
vt = np.where(t <= 10, Umin + a * t, Umax + 2 * a * (t - 10))
|
||||
return vt
|
||||
|
||||
|
||||
def security(t):
|
||||
vt = vitesse(t)
|
||||
dist = Wm * (1 + (vt/(16.1/3.6)))
|
||||
# print(dist)
|
||||
return dist
|
||||
|
||||
plt.figure(figsize=[16, 9])
|
||||
plt.xlim([-1,16])
|
||||
plt.xlabel('temps (s)')
|
||||
plt.ylabel('distance de sécurité (m)')
|
||||
plt.plot(t, security(t))
|
||||
plt.savefig('pipes/dist sécurités.png')
|
||||
plt.draw()
|
||||
plt.pause(5)
|
BIN
pipes/dist sécurités.png
Normal file
BIN
pipes/dist sécurités.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
38
polairedc.py
38
polairedc.py
@ -2,13 +2,14 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
from colour import Color
|
||||
import random
|
||||
|
||||
t0 = 0
|
||||
tf = 200
|
||||
dt = 0.5
|
||||
t = t0
|
||||
|
||||
nbv = 20
|
||||
nbv = 30
|
||||
|
||||
def rainbow_gradient(num_colors):
|
||||
colors = []
|
||||
@ -20,26 +21,6 @@ def rainbow_gradient(num_colors):
|
||||
return colors
|
||||
colors = rainbow_gradient(nbv)
|
||||
|
||||
def status(distances):
|
||||
num_colors = len(distances)
|
||||
colors = []
|
||||
base_color = Color("green")
|
||||
target_color = Color("red")
|
||||
luminance_start = base_color.get_luminance()
|
||||
luminance_end = target_color.get_luminance()
|
||||
for i in range(num_colors):
|
||||
moydist = distances[i]
|
||||
t = i / (num_colors - 1)
|
||||
adjusted_luminance = luminance_start + (luminance_end - luminance_start) * (1 - t) * (moydist - 1) / 18
|
||||
color = Color(rgb=(base_color.rgb[0] * (1 - t) + target_color.rgb[0] * t,
|
||||
base_color.rgb[1] * (1 - t) + target_color.rgb[1] * t,
|
||||
base_color.rgb[2] * (1 - t) + target_color.rgb[2] * t))
|
||||
color.set_luminance(adjusted_luminance)
|
||||
hex_code = color.hex_l
|
||||
colors.append(hex_code)
|
||||
return colors
|
||||
|
||||
|
||||
U = 1.25 # vitesse m.s-¹
|
||||
Wm = 0.3 # distance minimale entre la voiture et celle qui la précède m
|
||||
Ws = 0.9 # m
|
||||
@ -51,10 +32,14 @@ def phi(ww): # prend en entrée la distance entre les deux véhicules
|
||||
y = np.linspace(1, 1, nbv)
|
||||
xxbase = np.linspace(0, 1, nbv)
|
||||
|
||||
arr = random.randint(0,nbv-1)
|
||||
|
||||
def distances(fposition):
|
||||
# print('fposition', fposition)
|
||||
dist = np.diff(fposition)
|
||||
inter = fposition[0]+20-fposition[-1]
|
||||
if (t>= 50) and (t<=60) :
|
||||
dist[arr] = 0
|
||||
newdist = np.insert(dist, len(dist), inter)
|
||||
return newdist
|
||||
|
||||
@ -75,20 +60,13 @@ while(t < tf):
|
||||
plt.polar(theta, r, alpha=0)
|
||||
|
||||
dst = distances(xxold)
|
||||
statusc = status(dst)
|
||||
print(dst)
|
||||
print(statusc)
|
||||
|
||||
vt = phi(dst)
|
||||
xx = position(xxold, vt)
|
||||
|
||||
plt.scatter(xx/10 * np.pi, y, c=colors)
|
||||
|
||||
# for i in range(len(xx)-1):
|
||||
# plt.plot([xx[i]/10 * np.pi, xx[i+1]/10 * np.pi], [y[i], y[i+1]], color=statusc[i])
|
||||
|
||||
plt.title('Vitesse maximale : ' + str(U) + ' m/s\ndistance minimale entre deux voitures : ' + str(Wm) + ' m\nnombre de voitures : ' + str(nbv))
|
||||
plt.title('Vitesse maximale : ' + str(U) + ' m/s\ndistance minimale entre deux voitures : ' + str(Wm) + ' m\nnombre de voitures : ' + str(nbv) + '\n temps : ' + str(t)+ '\n la voiture qui va freiner est la ' + str(arr) + ' ème (à 50s)')
|
||||
plt.draw()
|
||||
plt.pause(0.00001)
|
||||
t += dt
|
||||
xxold = xx.copy()
|
||||
xxold = xx.copy()
|
@ -14,5 +14,6 @@ plt.figure(figsize=[16,9])
|
||||
plt.xlabel('distance w en m')
|
||||
plt.ylabel('vitesse en m.s-¹')
|
||||
plt.plot(ww, phi(ww))
|
||||
plt.savefig('phi(ww).png', dpi=300)
|
||||
plt.show()
|
||||
plt.savefig('test/phi(www).png')
|
||||
plt.draw()
|
||||
plt.pause(4)
|
Loading…
x
Reference in New Issue
Block a user