diff --git a/drone.lua b/drone.lua index 7312dd4..d745bd7 100644 --- a/drone.lua +++ b/drone.lua @@ -449,26 +449,47 @@ end -------------------------------------------------------------------- -- CALIBRATIONS -------------------------------------------------------------------- +local rafraichirCalib = nil -- affecte apres contexteIhm + local ui = { inviter = function(texte) ihm.message(texte, 3600) calibTexte = texte pcall(ihm.rafraichirConduite, { mode = mode, consigneY = consigneY }) + if rafraichirCalib then rafraichirCalib() end journal.info("[calib] " .. texte) end, progres = function(pct, texte) calibProgres, calibTexte = pct, texte + if rafraichirCalib then rafraichirCalib() end end, rscViolet = function(role) rscViolet = role end, attendreToucher = ihm.attendreToucher, choisirRole = ihm.choisirRole, } +-- vide la file d'evenements (touchers accumules pendant la calib, +-- qui seraient sinon rejoues sur d'anciennes zones) +local function purgerEvenements() + os.queueEvent("purge_evenements") + while true do + local ev = os.pullEvent() + if ev == "purge_evenements" then return end + end +end + local function lancerCalibration(quoi) enCalibration = true calibEnCours = quoi calibProgres, calibTexte = 0, quoi + ihm.reglerPage("calib") + local solAvecMoteur = { rsc = true, rscman = true, moteur = true } + if solAvecMoteur[quoi] and mode == "calibrage" then + -- tacheMoteur est suspendue pendant la calibration: on assure + -- la pleine puissance nous-memes + materiel.reglerMoteur(15) + end local ok, err = pcall(function() if quoi == "gimbal" or quoi == "joystick" or quoi == "typew" or quoi == "rsc" or quoi == "rscman" or quoi == "moteur" then @@ -531,6 +552,7 @@ local function lancerCalibration(quoi) ihm.message("", 0) calibEnCours, rscViolet = nil, nil enCalibration = false + purgerEvenements() end -- statuts des calibrations pour la page CALIB @@ -615,7 +637,9 @@ end local function tacheMoteur() local enSurcharge = false while true do - if mode == "off" then + if enCalibration then + -- les calibrations pilotent le moteur elles-memes + elseif mode == "off" then materiel.reglerMoteur(0) elseif os.clock() < boostMoteurFin then niveauMoteur = 15 @@ -841,6 +865,10 @@ local function lancerCible(texte) end end +rafraichirCalib = function() + pcall(ihm.rafraichirMoniteur, contexteIhm()) +end + local function tacheIhm() local prochainDessin = 0 local redessiner = false diff --git a/lib/calibration.lua b/lib/calibration.lua index b8165c7..ce2edd3 100644 --- a/lib/calibration.lua +++ b/lib/calibration.lua @@ -452,29 +452,37 @@ function Calibration.moteur(conf, etat, materiel, journal, Etat, ui) return false end - -- Phase 2: coefficients de consommation (moteur au maximum) + -- Phase 2: coefficients de consommation, mesures RSC PAR RSC + -- (un seul en rotation a la fois: pas d'overstress possible + -- pendant la calibration) materiel.reglerMoteur(15) sleep(C.ATTENTE_NIVEAU) local stressBase = materiel.lireStressBrut() or 0 - ui.progres(0.7, "coefficient helices") - for _, role in ipairs({ "lb", "rb", "lf", "rf" }) do - materiel.reglerRsc(role, C.RPM_STRESS) + local function coefficient(roles, base01, libelle) + local somme, n = 0, 0 + for idx, role in ipairs(roles) do + ui.progres(base01 + (idx - 1) / #roles * 0.14, + libelle .. " " .. role) + materiel.reglerRsc(role, C.RPM_STRESS) + sleep(C.ATTENTE_NIVEAU) + local s = materiel.lireStressBrut() or 0 + materiel.reglerRsc(role, 0) + sleep(0.5) + local delta = s - stressBase + if delta > 0 then + somme, n = somme + delta / C.RPM_STRESS, n + 1 + end + end + if n == 0 then return 0 end + return somme / n end - sleep(C.ATTENTE_NIVEAU) - local stressHelices = materiel.lireStressBrut() or 0 - materiel.toutArreter() - sleep(1) - ui.progres(0.85, "coefficient propulseurs") - materiel.reglerRsc("prop_l", C.RPM_STRESS) - materiel.reglerRsc("prop_r", C.RPM_STRESS) - sleep(C.ATTENTE_NIVEAU) - local stressProps = materiel.lireStressBrut() or 0 + local kh = coefficient({ "lb", "rb", "lf", "rf" }, 0.65, + "coeff helice") + local kp = coefficient({ "prop_l", "prop_r" }, 0.82, + "coeff propulseur") materiel.toutArreter() - - local kh = math.max(0, stressHelices - stressBase) / (4 * C.RPM_STRESS) - local kp = math.max(0, stressProps - stressBase) / (2 * C.RPM_STRESS) if kh <= 0 then journal.erreur("calib moteur: coefficient helices nul") ui.progres(0, "ECHEC: coeff nul")