diff --git a/drone.lua b/drone.lua index 1c860d0..76e68fa 100644 --- a/drone.lua +++ b/drone.lua @@ -144,7 +144,7 @@ exigerInterface(materiel, "lib/materiel.lua", { }) exigerInterface(regulation, "lib/regulation.lua", { "reguler", "plaquer", "rpmHover", "reglerInjection", - "gainsModifies", "vitesseVerticale", + "gainsModifies", "vitesseVerticale", "gelerBoite", }) exigerInterface(ecran, "lib/ecran.lua", { "rafraichirMoniteur", "choisirRole", "message", @@ -435,6 +435,8 @@ local function lancerCalibration(quoi) calibEnCours = quoi calibProgres, calibTexte = 0, quoi ecran.reglerPage("calib") + -- la boite ne change JAMAIS de rapport pendant une calibration + regulation.gelerBoite(true) local ok, err = pcall(function() if quoi == "inclinaison" then if mode ~= "vol" then @@ -462,6 +464,7 @@ local function lancerCalibration(quoi) end end) if not ok then journal.erreur("calibration: " .. tostring(err)) end + regulation.gelerBoite(false) ecran.message("", 0) calibEnCours, rscViolet = nil, nil enCalibration = false diff --git a/lib/calib.lua b/lib/calib.lua index 26436d4..d9c5c8b 100644 --- a/lib/calib.lua +++ b/lib/calib.lua @@ -658,13 +658,23 @@ function Calib.altitude(conf, etat, materiel, regulation, journal, end sleep(dt) end - local meilleur, somme = nil, 0.5 + local meilleur, somme, second = nil, 0.5, 0 for nom, s in pairs(releves) do - if math.abs(s) > math.abs(somme) then meilleur, somme = nom, s end + if math.abs(s) > math.abs(somme) then + second = math.abs(somme) + meilleur, somme = nom, s + elseif math.abs(s) > second then + second = math.abs(s) + end end if meilleur then etat.veloVertical = { nom = meilleur, signe = (somme > 0) and 1 or -1 } journal.info("calib altitude: capteur vertical = " .. meilleur) + if second > 0.5 * math.abs(somme) then + journal.alerte("calib altitude: detection du capteur vertical " + .. "AMBIGUE (un autre capteur bouge presque autant): " + .. "refaire la calib drone bien immobile") + end else etat.veloVertical = nil journal.alerte("calib altitude: capteur vertical non detecte, " diff --git a/lib/conf.lua b/lib/conf.lua index a6e0649..ee38a23 100644 --- a/lib/conf.lua +++ b/lib/conf.lua @@ -71,6 +71,28 @@ local DEFAUT = [[ } ]] +-- fusion recursive: les valeurs de l'utilisateur PRIMENT, les cles +-- absentes (nouvelles versions) sont completees par les defauts +local function fusionner(defauts, utilisateur, manquantes, prefixe) + local resultat = {} + for cle, valeur in pairs(defauts) do + local sienne = utilisateur[cle] + if type(valeur) == "table" and type(sienne) == "table" then + resultat[cle] = fusionner(valeur, sienne, manquantes, + prefixe .. cle .. ".") + elseif sienne ~= nil then + resultat[cle] = sienne + else + resultat[cle] = valeur + table.insert(manquantes, prefixe .. tostring(cle)) + end + end + for cle, valeur in pairs(utilisateur) do + if resultat[cle] == nil then resultat[cle] = valeur end + end + return resultat +end + function Conf.charger(journal) if not fs.exists("drone.conf") then local f = fs.open("drone.conf", "w") @@ -86,6 +108,19 @@ function Conf.charger(journal) if not conf then error("drone.conf illisible: corriger ou supprimer le fichier", 0) end + + -- MIGRATION: un drone.conf d'une version anterieure peut manquer + -- de sections (ex: REGUL): elles sont completees par les defauts + local defauts = textutils.unserialize(DEFAUT) + local manquantes = {} + conf = fusionner(defauts, conf, manquantes, "") + if #manquantes > 0 then + journal.alerte(("drone.conf: %d parametre(s) absent(s) " + .. "complete(s) par defaut (%s%s)"):format(#manquantes, + table.concat(manquantes, ", ", 1, math.min(4, #manquantes)), + #manquantes > 4 and ", ..." or "")) + end + if not conf.verifie then journal.alerte("drone.conf non verifie: relire les parametres " .. "puis passer verifie a true") diff --git a/lib/regulation.lua b/lib/regulation.lua index d2b4318..b20c737 100644 --- a/lib/regulation.lua +++ b/lib/regulation.lua @@ -176,10 +176,19 @@ function Regulation.nouveau(conf, etat, materiel, Pid, journal) ------------------------------------------------------------------ local prochainChangement = 0 local boiteModifiee = false + local boiteGelee = false + + -- gel de la boite (calibrations: un changement de rapport en + -- pleine mesure la polluerait) + function r.gelerBoite(gel) + boiteGelee = gel and true or false + end local function gererBoite(cibles, calme) local b = etat.boite - if not b or not calme then return end + if not b or not calme or boiteGelee then return end + if injection.vitesse or injection.tangage + or injection.roulis then return end if os.clock() < prochainChangement then return end local base = (cibles.lb + cibles.rb + cibles.lf + cibles.rf) / 4 local rsc = base / b.rapport