Fait une moyenne tournante pour la mesure de la hauteur

This commit is contained in:
Christian Zufferey
2020-06-27 18:48:31 +02:00
parent 4af112c41f
commit 9e3d6d75c8
2 changed files with 14 additions and 7 deletions

View File

@@ -1,8 +1,8 @@
-- Petit script pour faire office de crontab pour les mesures
print("\n 0_cron.lua zf200625.1352 \n")
print("\n 0_cron.lua zf200627.1824 \n")
cron1=tmr.create()
cron1:alarm(5*1000, tmr.ALARM_AUTO, function()
cron1:alarm(20*1000, tmr.ALARM_AUTO, function()
-- if verbose then print("cron1........................") end
-- if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end

View File

@@ -1,10 +1,14 @@
-- Mesure la distance avec le module ultra-son de 15cm à 2m
-- Attention le module à ultra-son doit être alimenté en 5V !
print("\n 0_ultra_son.lua zf200624.1551 \n")
print("\n 0_ultra_son.lua zf200627.1846 \n")
speed_air=382
zlength=0
speed_air = 382
zlength_min = 0.15
zlength_max = 0.62
zlength = (zlength_min+zlength_max)/2
zlength_1, zlength_2, zlength_3 = zlength,zlength,zlength
--Paramètres pour le module ultra son
local ztrig=5
@@ -32,8 +36,11 @@ function zmesure()
-- print("Delta: "..ultra_son_stop-ultra_son_start)
zlength=math.floor(speed_air*(ultra_son_stop-ultra_son_start)/2/10000)/100
--zlength=speed_air*(ultra_son_stop-ultra_son_start)/2/10000
if zlength>2 then zlength=2 end
if zlength<0.15 then zlength=0.15 end
if zlength>zlength_max then zlength=zlength_max end
if zlength<zlength_min then zlength=zlength_min end
zlength_3= zlength_2 zlength_2= zlength_1 zlength_1= zlength
zlength = (zlength_1+zlength_2+zlength_3)/3
disp_mesure()
end