- ajouté le module astro et la fonction cat, mais tout deux ne fonctionnent pas encore
This commit is contained in:
0
astro/Icon
Normal file
0
astro/Icon
Normal file
39
astro/equa2azim.js
Normal file
39
astro/equa2azim.js
Normal file
@@ -0,0 +1,39 @@
|
||||
// script en JS pour calculer les coordonnées longitude/azimut depuis une coordonnée équatoriale
|
||||
// le but du jeu c'est de convertir ce script JS en Lua pour le NodeMCU avec asservissement d'un
|
||||
// télescope à monture azimutale
|
||||
// zf180807.2217
|
||||
// source https://astronomy.stackexchange.com/questions/15013/calculating-azimuth-from-equatorial-coordinates
|
||||
|
||||
// a=arctan2(sin(θ−α),sinφ∗cos(θ−α)−cosφ∗tanδ)
|
||||
// Where
|
||||
// φ = geographic latitude of the observer (here: 0°)
|
||||
// θ = sidereal time (here: 0°)
|
||||
// δ = declination
|
||||
// α = right ascension
|
||||
|
||||
obliq = deg2rad(23.44); // obliquity of ecliptic
|
||||
lat2 = deg2rad(0); // observer's latitude
|
||||
lmst = deg2rad(0); // siderial time
|
||||
|
||||
function equatorial(lat, lon) {
|
||||
// returns equatorial from ecliptic coordinates
|
||||
dec = Math.asin( Math.cos(obliq) * Math.sin(lat) + Math.sin(obliq) *
|
||||
Math.cos(lat) * Math.sin(lon));
|
||||
ra = Math.atan2(Math.cos(obliq) * Math.sin(lon) - Math.sin(obliq) * Math.tan(lat),
|
||||
Math.cos(lon));
|
||||
ra += 2 * Math.PI * (ra < 0);
|
||||
return [dec, ra];
|
||||
}
|
||||
|
||||
function horizontal(lat, lon) {
|
||||
// returns horizontal from ecliptic coordinates
|
||||
coords = equatorial(lat, lon);
|
||||
dec = coords[0]; // δ
|
||||
ra = coords[1]; // α
|
||||
alt = Math.asin(Math.sin(lat2) * Math.sin(dec) + Math.cos(lat2) *
|
||||
Math.cos(dec) * Math.cos(lmst - ra));
|
||||
azm = Math.atan2(Math.sin(lmst - ra), Math.sin(lat2) * Math.cos(lmst - ra) -
|
||||
Math.cos(lat2) * Math.tan(dec));
|
||||
azm += 2 * Math.PI * (azm < 0);
|
||||
return [alt, azm];
|
||||
}
|
||||
48
astro/equa2azim.lua
Normal file
48
astro/equa2azim.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
-- script en LUA pour calculer les coordonnées longitude/azimut depuis une coordonnée équatoriale
|
||||
-- le but du jeu c'était de convertir script JS en LUA pour le NodeMCU avec asservissement d'un
|
||||
-- télescope à monture azimutale.
|
||||
-- le problème avec le LUA embarqué sur NodeMCU c'est qu'il n'y a pas de fonctions trigo :-(
|
||||
-- zf180807.2300
|
||||
-- source https:--astronomy.stackexchange.com/questions/15013/calculating-azimuth-from-equatorial-coordinates
|
||||
|
||||
|
||||
-- ce n'est pas terminé !
|
||||
|
||||
|
||||
-- a=arctan2(sin(θ−α),sinφ∗cos(θ−α)−cosφ∗tanδ)
|
||||
-- Where
|
||||
-- φ = geographic latitude of the observer (here: 0°)
|
||||
-- θ = sidereal time (here: 0°)
|
||||
-- δ = declination
|
||||
-- α = right ascension
|
||||
|
||||
obliq = math.rad(23.44) -- obliquity of ecliptic
|
||||
lat2 = math.rad(0) -- observer's latitude
|
||||
lmst = math.rad(0) -- siderial time
|
||||
|
||||
bool_to_number={ [true]=1, [false]=0 }
|
||||
|
||||
function equatorial(lat, lon)
|
||||
-- returns equatorial from ecliptic coordinates
|
||||
dec = math.asin( math.cos(obliq) * math.sin(lat) + math.sin(obliq) * math.cos(lat) * math.sin(lon))
|
||||
ra = math.atan2(math.cos(obliq) * math.sin(lon) - math.sin(obliq) * math.tan(lat) , math.cos(lon))
|
||||
ra = ra + 2 * math.pi * bool_to_number[ra < 0]
|
||||
return dec, ra
|
||||
end
|
||||
|
||||
function horizontal(lat, lon)
|
||||
-- returns horizontal from ecliptic coordinates
|
||||
coords = equatorial(lat, lon)
|
||||
dec = coords[0] -- δ
|
||||
ra = coords[1] -- α
|
||||
alt = math.asin(math.sin(lat2) * math.sin(dec) + math.cos(lat2) * math.cos(dec) * math.cos(lmst - ra))
|
||||
azm = math.atan2(math.sin(lmst - ra), math.sin(lat2) * math.cos(lmst - ra) - math.cos(lat2) * math.tan(dec))
|
||||
azm = azm + 2 * math.pi * bool_to_number[azm < 0]
|
||||
return alt, azm
|
||||
end
|
||||
|
||||
|
||||
|
||||
print "toto"
|
||||
|
||||
horizontal(13,6)
|
||||
20
cat.lua
Normal file
20
cat.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
|
||||
print("\n cat.lua zf180730.1259")
|
||||
|
||||
function cat(zfile)
|
||||
print("\n-------------------------------")
|
||||
|
||||
|
||||
zfilei = io.open(zfile, "r")
|
||||
io.input(zfilei)
|
||||
|
||||
i=1
|
||||
zline=io.read()
|
||||
repeat
|
||||
print(i..": "..zline)
|
||||
i=i+1 zline=io.read()
|
||||
until zline== nil
|
||||
io.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
49
trigo1.lua
Normal file
49
trigo1.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
-- Essais de fire des fonctions trigos qui manque dans NodeMCU
|
||||
-- ATTENTION: arcsin ne fonctionne pas pour les valeur proche de 1 !
|
||||
-- source: https://www.esp8266.com/viewtopic.php?p=64415#
|
||||
print("\ntrigo1.lua zf180726.1136 \n")
|
||||
|
||||
function sin(x)
|
||||
local p=-x*x*x
|
||||
local f=6
|
||||
local r=x+p/f
|
||||
for j=1,60 do
|
||||
p=-p*x*x
|
||||
f=f*2*(j+1)*(j+j+3)
|
||||
r=r+p/f
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
function cos(x)
|
||||
return sin(math.pi/2-x)
|
||||
end
|
||||
|
||||
function tan(x)
|
||||
return sin(x)/cos(x)
|
||||
end
|
||||
|
||||
function arcsin(x)
|
||||
local suma=x
|
||||
for i=1,60 do
|
||||
suma = suma + (dfi(2*i-1)/dfp(2*i))*(math.pow(x,2*i+1)/(2*i+1))
|
||||
print("Suma: "..suma)
|
||||
end
|
||||
return suma
|
||||
end
|
||||
|
||||
function dfp(x)
|
||||
local par=1
|
||||
for i=2,x,2 do
|
||||
par = par * i
|
||||
end
|
||||
return par
|
||||
end
|
||||
|
||||
function dfi(x)
|
||||
local impar=1
|
||||
for i=1,x,2 do
|
||||
impar = impar * i
|
||||
end
|
||||
return impar
|
||||
end
|
||||
90
trigo2.lua
Normal file
90
trigo2.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
-- 2e Essais de faire des fonctions trigos qui manque dans NodeMCU
|
||||
-- source pour sin&cos: https://www.esp8266.com/viewtopic.php?p=64415#
|
||||
-- source pour arcsin&arctan: http://www.electronicwings.com/nodemcu/magnetometer-hmc5883l-interfacing-with-nodemcu
|
||||
print("\ntrigo2.lua zf180726.1149 \n")
|
||||
|
||||
|
||||
|
||||
function sin(x)
|
||||
local p=-x*x*x
|
||||
local f=6
|
||||
local r=x+p/f
|
||||
for j=1,60 do
|
||||
p=-p*x*x
|
||||
f=f*2*(j+1)*(j+j+3)
|
||||
r=r+p/f
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
function cos(x)
|
||||
return sin(math.pi/2-x)
|
||||
end
|
||||
|
||||
function tan(x)
|
||||
return sin(x)/cos(x)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
pi = 3.14159265358979323846
|
||||
|
||||
|
||||
function arcsin(value)
|
||||
local val = value
|
||||
local sum = value
|
||||
if(value == nil) then
|
||||
return 0
|
||||
end
|
||||
-- as per equation it needs infinite iterations to reach upto 100% accuracy
|
||||
-- but due to technical limitations we are using
|
||||
-- only 10000 iterations to acquire reliable accuracy
|
||||
for i = 1,10000, 2 do
|
||||
val = (val*(value*value)*(i*i)) / ((i+1)*(i+2))
|
||||
sum = sum + val;
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
function arctan(value)
|
||||
if(value == nil) then
|
||||
return 0
|
||||
end
|
||||
local _value = value/math.sqrt((value*value)+1)
|
||||
return arcsin(_value)
|
||||
end
|
||||
|
||||
function atan2(y, x)
|
||||
if(x == nil or y == nil) then
|
||||
return 0
|
||||
end
|
||||
|
||||
if(x > 0) then
|
||||
return arctan(y/x)
|
||||
end
|
||||
if(x < 0 and 0 <= y) then
|
||||
return arctan(y/x) + pi
|
||||
end
|
||||
if(x < 0 and y < 0) then
|
||||
return arctan(y/x) - pi
|
||||
end
|
||||
if(x == 0 and y > 0) then
|
||||
return pi/2
|
||||
end
|
||||
if(x == 0 and y < 0) then
|
||||
return -pi/2
|
||||
end
|
||||
if(x == 0 and y == 0) then
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
print("On voit que l'arc sinus est précis au 1/2% prêt !")
|
||||
print("sin(3.14/2): "..sin(3.14/2))
|
||||
print("pi/(arcsin(1)*2): "..pi/(arcsin(1)*2))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user