M10 : consommation par mode, profil de courant en deep sleep. M11 : publish/subscribe, arborescence des topics. M12 : démarche de projet, structure multi-fichiers. Synthèse : carte du parcours. Figure du chenillard (M2) déplacée après son code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.7 KiB
Python
62 lines
2.7 KiB
Python
"""Module 10 — Gestion de l'énergie."""
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
from style import BLEU, CM, ENCRE, GRIS, ORANGE, ROUGE, VERT, Figure
|
|
|
|
|
|
def consommation_modes():
|
|
fig, ax = plt.subplots(figsize=(16 * CM, 6.4 * CM))
|
|
modes = [("Actif\n(Wi-Fi, calcul)", 80, 250, ROUGE, "moins d'1 jour"),
|
|
("Modem-sleep", 20, 30, ORANGE, "≈ 3 jours"),
|
|
("Light sleep", 0.7, 0.9, BLEU, "≈ 3 mois"),
|
|
("Deep sleep", 0.010, 0.150, VERT, "plus d'1 an (théorique)")]
|
|
for i, (nom, bas, haut, c, autonomie) in enumerate(modes):
|
|
ax.barh(i, haut - bas, left=bas, height=0.5, color=c, alpha=0.85)
|
|
ax.text(haut * 1.4, i, autonomie, va="center", fontsize=8.5, color=c, fontweight="bold")
|
|
ax.set_yticks(range(len(modes)), [m[0] for m in modes])
|
|
ax.invert_yaxis()
|
|
ax.set_xscale("log")
|
|
ax.set_xlim(0.005, 20000)
|
|
ax.set_xticks([0.01, 0.1, 1, 10, 100, 1000], ["10 µA", "100 µA", "1 mA", "10 mA", "100 mA", "1 A"])
|
|
ax.set_xlabel("courant consommé (échelle logarithmique)")
|
|
ax.text(20000, -0.75, "autonomie avec une batterie de 2000 mAh", ha="right", fontsize=7.5,
|
|
color=GRIS, style="italic")
|
|
ax.grid(axis="y", visible=False)
|
|
fig.tight_layout()
|
|
return fig
|
|
|
|
|
|
def cycle_deep_sleep():
|
|
fig, ax = plt.subplots(figsize=(16 * CM, 6.0 * CM))
|
|
t, i = [0], [0.05]
|
|
for debut in (0, 60, 120):
|
|
t += [debut, debut + 0.4, debut + 1.0, debut + 3.0]
|
|
i += [45, 40, 160, 0.05]
|
|
t += [150]
|
|
i += [0.05]
|
|
ax.step(t, i, where="post", color=BLEU, lw=1.6)
|
|
ax.fill_between(t, 0.01, i, step="post", color=BLEU, alpha=0.12)
|
|
ax.set_yscale("log")
|
|
ax.set_ylim(0.01, 600)
|
|
ax.set_yticks([0.01, 0.1, 1, 10, 100], ["10 µA", "100 µA", "1 mA", "10 mA", "100 mA"])
|
|
ax.set_xlim(-3, 150)
|
|
ax.set_xlabel("temps (s)")
|
|
ax.set_ylabel("courant")
|
|
ax.annotate("réveil : setup() repart du début\nmesure BME280, envoi Wi-Fi (≈ 3 s)", xy=(61.5, 160), xytext=(66, 260),
|
|
fontsize=7.8, color=ROUGE, arrowprops=dict(arrowstyle="-|>", color=ROUGE, lw=0.8))
|
|
ax.text(30, 0.5, "deep sleep (≈ 57 s)\nseule la RTC reste alimentée", ha="center", fontsize=7.8, color=VERT)
|
|
ax.text(31.5, 0.16, "esp_sleep_enable_timer_wakeup(60 s)", ha="center", fontsize=7.3, color=ENCRE,
|
|
family="monospace")
|
|
ax.text(91, 2.0, "compteurReveils (RTC_DATA_ATTR)\nconservé d'un cycle à l'autre", ha="center", fontsize=7.5,
|
|
color=GRIS, style="italic")
|
|
ax.grid(axis="x", visible=False)
|
|
fig.tight_layout()
|
|
return fig
|
|
|
|
|
|
FIGURES = [
|
|
Figure("m10-consommation-modes", consommation_modes),
|
|
Figure("m10-cycle-deep-sleep", cycle_deep_sleep),
|
|
]
|