creata timeline con tempi in decimi
This commit is contained in:
284
timeline chiusura.py
Normal file
284
timeline chiusura.py
Normal file
@@ -0,0 +1,284 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
# =========================
|
||||
# CONFIGURAZIONE
|
||||
# =========================
|
||||
m1pwmap =40
|
||||
m1pwmch=60
|
||||
m2pwmap=70
|
||||
m2pwmch= 70
|
||||
m3pwmap= 35
|
||||
m3pwmch= 40
|
||||
m4pwmap= 40
|
||||
m4pwmch= 40
|
||||
m1rampstart= 20
|
||||
m2rampstart= 20
|
||||
m3rampstart= 20
|
||||
m4rampstart= 20
|
||||
t1ap= 280
|
||||
t2ap= 4
|
||||
t3ap= 10
|
||||
t4ap= 40
|
||||
twap= 1
|
||||
t1ch= 27
|
||||
t2ch= 10
|
||||
t3ch= 30
|
||||
t4ch= 1
|
||||
twch= 1
|
||||
# 0,
|
||||
# 0,
|
||||
# 0,
|
||||
tramp1= 100
|
||||
m1pwmMan= 60
|
||||
m2pwmMan= 70
|
||||
m3pwmMan= 40
|
||||
m4pwmMan= 40
|
||||
trampman= 50
|
||||
tramp= 10
|
||||
|
||||
apM1start= 310
|
||||
apM1stop= 450
|
||||
apM2start= 30
|
||||
apM2stop= 310
|
||||
apM3start= 350
|
||||
apM3stop= 450
|
||||
apM4start= 450
|
||||
apM4stop= 850
|
||||
|
||||
chM1start= 10
|
||||
chM1stop= 280
|
||||
chM2start= 280
|
||||
chM2stop= 580
|
||||
chM3start= 20
|
||||
chM3stop= 280
|
||||
chM4start= 280
|
||||
chM4stop= 680
|
||||
|
||||
# Ogni fase è:
|
||||
# (tempo_inizio, tempo_fine, velocita_iniziale, velocita_finale)
|
||||
|
||||
motori = {
|
||||
"Motore1": [
|
||||
(chM1start, chM1start+tramp, m1rampstart, m1pwmch),
|
||||
(chM1start+tramp, chM1stop, m1pwmch, m1pwmch),
|
||||
(chM1stop, chM1stop+tramp, m1pwmch, 0)
|
||||
],
|
||||
"Motore2": [
|
||||
(chM2start, chM2start+tramp, m2rampstart, m2pwmch),
|
||||
(chM2start+tramp, chM2stop, m2pwmch, m2pwmch),
|
||||
(chM2stop, chM2stop+tramp, m2pwmch, 0)
|
||||
],
|
||||
"Motore3": [
|
||||
(chM3start, chM3start+tramp, m3rampstart, m3pwmch),
|
||||
(chM3start+tramp, chM3stop, m3pwmch, m3pwmch),
|
||||
(chM3stop, chM3stop+tramp, m3pwmch, 0)
|
||||
],
|
||||
"Motore4": [
|
||||
(chM4start, chM4start+tramp, m4rampstart, m4pwmch),
|
||||
(chM4start+tramp, chM4stop, m4pwmch, m4pwmch),
|
||||
(chM4stop, chM4stop+tramp, m4pwmch, 0)
|
||||
]
|
||||
}
|
||||
|
||||
# Buzzer ON/OFF: (inizio, fine)
|
||||
buzzer = [
|
||||
(20, 21),
|
||||
(22, 23),
|
||||
(24, 25),
|
||||
(26, 27),
|
||||
(28, 29),
|
||||
(30, 31),
|
||||
(32, 33),
|
||||
(34, 35),
|
||||
(36, 37),
|
||||
(38, 39),
|
||||
(40, 41),
|
||||
(42, 43),
|
||||
(44, 45),
|
||||
(46, 47),
|
||||
(48, 49),
|
||||
(50, 55),
|
||||
(60, 65),
|
||||
(70, 75),
|
||||
(80, 85),
|
||||
(90, 95),
|
||||
(100, 105),
|
||||
(110, 115),
|
||||
(120, 125),
|
||||
(130, 135),
|
||||
(140, 145),
|
||||
(150, 155),
|
||||
(160, 165),
|
||||
(170, 175),
|
||||
(180, 185),
|
||||
(190, 195),
|
||||
(200, 205),
|
||||
(210, 215),
|
||||
(220, 225),
|
||||
(230, 235),
|
||||
(240, 245),
|
||||
(250, 255),
|
||||
(260, 265),
|
||||
(270, 275),
|
||||
(280, 285),
|
||||
(290, 295),
|
||||
(300, 305),
|
||||
(310, 315),
|
||||
(320, 325),
|
||||
(330, 335),
|
||||
(340, 345),
|
||||
(350, 355),
|
||||
(360, 365),
|
||||
(370, 375),
|
||||
(380, 385),
|
||||
(390, 395),
|
||||
(400, 405),
|
||||
(410, 415),
|
||||
(420, 425),
|
||||
(430, 435),
|
||||
(440, 445),
|
||||
(450, 455),
|
||||
(460, 465),
|
||||
(470, 475),
|
||||
(480, 485),
|
||||
(490, 495),
|
||||
(500, 505),
|
||||
(510, 515),
|
||||
(520, 525),
|
||||
(530, 535),
|
||||
(540, 545),
|
||||
(550, 555),
|
||||
(560, 565),
|
||||
(570, 575),
|
||||
(580, 585),
|
||||
(590, 595),
|
||||
(600, 605),
|
||||
(610, 615),
|
||||
(620, 625),
|
||||
(630, 635),
|
||||
(640, 645),
|
||||
(650, 655),
|
||||
(660, 665),
|
||||
(670, 675),
|
||||
(680, 685),
|
||||
(690, 695),
|
||||
(700, 705),
|
||||
(710, 715),
|
||||
(720, 725),
|
||||
(730, 735),
|
||||
(740, 745),
|
||||
(750, 755),
|
||||
(760, 765),
|
||||
(770, 775),
|
||||
(780, 785),
|
||||
(790, 795),
|
||||
(800, 805),
|
||||
(810, 815),
|
||||
(820, 825),
|
||||
(830, 835),
|
||||
(840, 845),
|
||||
(850, 855),
|
||||
(860, 865),
|
||||
(870, 875),
|
||||
(880, 885),
|
||||
(890, 895),
|
||||
(900, 905),
|
||||
(910, 915),
|
||||
(920, 925),
|
||||
(930, 935),
|
||||
(940, 945),
|
||||
(950, 955),
|
||||
(960, 965),
|
||||
(970, 975),
|
||||
(980, 985),
|
||||
(990, 995),
|
||||
]
|
||||
|
||||
tasto = [
|
||||
(0, 30),
|
||||
|
||||
]
|
||||
|
||||
# =========================
|
||||
# CREAZIONE GRAFICO
|
||||
# =========================
|
||||
|
||||
fig, ax = plt.subplots(figsize=(13, 6))
|
||||
|
||||
colori = {
|
||||
"Motore1": "blue",
|
||||
"Motore2": "lightgreen",
|
||||
"Motore3": "orange",
|
||||
"Motore4": "purple"
|
||||
}
|
||||
# Motori: linee di velocità
|
||||
for nome, fasi in motori.items():
|
||||
tempi = []
|
||||
velocita = []
|
||||
|
||||
for start, end, v0, v1 in fasi:
|
||||
t = np.linspace(start, end, 50)
|
||||
v = np.linspace(v0, v1, 50)
|
||||
|
||||
tempi.extend(t)
|
||||
velocita.extend(v)
|
||||
|
||||
ax.plot(tempi, velocita, marker="o", markersize=2, label=nome, color=colori[nome])
|
||||
|
||||
# Buzzer: riga separata in basso
|
||||
y_buzzer = -10
|
||||
|
||||
for start, end in buzzer:
|
||||
ax.broken_barh(
|
||||
[(start, end - start)],
|
||||
(y_buzzer, 8),
|
||||
facecolors="red",
|
||||
alpha=0.7
|
||||
)
|
||||
|
||||
# Scritta "Buzzer"
|
||||
ax.text(
|
||||
-120,
|
||||
y_buzzer + 4,
|
||||
"Buzzer",
|
||||
va="center",
|
||||
ha="right"
|
||||
)
|
||||
|
||||
# tasto: riga separata in basso
|
||||
y_tasto = -20
|
||||
|
||||
for start, end in tasto:
|
||||
ax.broken_barh(
|
||||
[(start, end - start)],
|
||||
(y_tasto, 8),
|
||||
facecolors="yellow",
|
||||
alpha=0.7
|
||||
)
|
||||
|
||||
# Scritta "tasto"
|
||||
ax.text(
|
||||
-120,
|
||||
y_tasto + 4,
|
||||
"Tasto",
|
||||
va="center",
|
||||
ha="right"
|
||||
)
|
||||
|
||||
# =========================
|
||||
# FORMATTAZIONE
|
||||
# =========================
|
||||
|
||||
ax.set_xlabel("Tempo (decimi di secondo)")
|
||||
ax.set_ylabel("Velocità motore (%)")
|
||||
ax.set_title("Timeline CHIUSURA motori con rampe + buzzer")
|
||||
|
||||
ax.set_ylim(-20, 110)
|
||||
ax.grid(True)
|
||||
ax.legend()
|
||||
|
||||
# Salva immagine
|
||||
plt.savefig("timeline_completa.png", dpi=300, bbox_inches="tight")
|
||||
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user