"""SMA muscle: validate the thermal model, then size drive current, PWM and battery.""" import json, os import numpy as np import matplotlib; matplotlib.use("Agg") import matplotlib.pyplot as plt import sma FIG = os.path.join(os.path.dirname(__file__), "..", "..", "docs", "figures") W = sma.fitted() V_BATT, V_MIN = 3.7, 3.3 # LiPo nominal / near-empty under load L_WIRE = 0.100 # m of wire per muscle CAP_MAH = 500 res = {} fig, ax = plt.subplots(1, 3, figsize=(15, 4.2)) cols = {"0.10 mm": "#1f77b4", "0.13 mm": "#2ca02c", "0.15 mm": "#d62728"} for name, p in W.items(): d, Rm, h = p["d"], p["Rm"], p["h"] t_heat = sma.heating_time(p["I_rec"], d, Rm, h) # steady-state temperature at recommended current, and minimum current to reach Af T_ss = sma.T_AMB + p["I_rec"]**2 * Rm / (h * np.pi * d) I_min = np.sqrt((sma.AF - sma.T_AMB) * h * np.pi * d / Rm) R = Rm * L_WIRE I_full = V_BATT / R duty = min(1.0, (p["I_rec"] / I_full) ** 2) # RMS-equivalent PWM duty duty_low = min(1.0, (p["I_rec"] / (V_MIN / R)) ** 2) # energy per stroke and one gait cycle (heat, then cool) E = p["I_rec"]**2 * R * t_heat t_cool_m = sma.cooling_time(h, d, Rm) cycle = t_heat + t_cool_m P_avg = E / cycle + 0.25 # + ~0.25 W ESP32-C3 with Wi-Fi life_min = CAP_MAH / 1000 * 3.7 * 3600 / P_avg / 60 * 0.8 res[name] = dict(h=round(h, 1), t_heat_model=round(t_heat, 2), t_cool_model=round(t_cool_m, 2), t_cool_datasheet=p["t_cool"], T_ss=round(T_ss), I_min_mA=round(I_min * 1e3), R_100mm=round(R, 2), I_full_mA=round(I_full * 1e3), duty_pct=round(duty * 100), duty_lowbatt_pct=round(duty_low * 100), E_stroke_J=round(E, 2), cycle_s=round(cycle, 2), stroke_mm=round(0.04 * L_WIRE * 1e3, 1), battery_min=round(life_min)) # (a) one heat/cool cycle t, T, s = sma.simulate(lambda tt: p["I_rec"] if tt < t_heat else 0.0, d, Rm, h, 5.0) ax[0].plot(t, s * 4.0, color=cols[name], label=f"{name} @ {p['I_rec']*1e3:.0f} mA") ax[0].plot(t, T / 100 * 4.0, color=cols[name], ls=":", lw=1) # (b) heating time vs current I = np.linspace(I_min * 1.03, p["I_rec"] * 2.2, 40) ax[1].plot(I * 1e3, [sma.heating_time(i, d, Rm, h) for i in I], color=cols[name], label=name) ax[1].plot(p["I_rec"] * 1e3, t_heat, "o", color=cols[name]) # (c) wire temperature if left on (burn safety) ax[2].plot(I * 1e3, sma.T_AMB + I**2 * Rm / (h * np.pi * d), color=cols[name], label=name) ax[0].set(xlabel="time (s)", ylabel="contraction (% of length) | dotted: T/25 (°C)", title="(a) One pulse: heat at rated current, then cool") ax[1].set(xlabel="drive current (mA)", ylabel="time to full contraction (s)", ylim=(0, 4), title="(b) Contraction time vs current (dot = data-sheet current)") ax[2].axhline(230, color="k", ls="--"); ax[2].text(150, 236, "paper ignition ≈ 230 °C", fontsize=8) ax[2].axhline(sma.AF, color="grey", ls=":"); ax[2].text(150, sma.AF + 5, "Af = 78 °C", fontsize=8) ax[2].set(xlabel="continuous current (mA)", ylabel="steady-state wire temperature (°C)", title="(c) Temperature if a pulse is never switched off", ylim=(0, 450)) for a in ax: a.grid(alpha=.3); a.legend(fontsize=8) fig.tight_layout(); fig.savefig(os.path.join(FIG, "sim_sma_thermal.png"), dpi=160) print(json.dumps(res, indent=1)) json.dump(res, open(os.path.join(os.path.dirname(__file__), "results_sma.json"), "w"), indent=1)