Change coordinates for orbiting AI object to JSBSim inertial definition for consistency
This commit is contained in:
parent
8ec442d96a
commit
ec89cde472
1 changed files with 41 additions and 11 deletions
|
@ -10,6 +10,7 @@ var orbitalTarget = {
|
||||||
t.altitude = altitude;
|
t.altitude = altitude;
|
||||||
t.radius = 20908323.0 * 0.3048 + t.altitude;
|
t.radius = 20908323.0 * 0.3048 + t.altitude;
|
||||||
t.GM = 398759391386476.0;
|
t.GM = 398759391386476.0;
|
||||||
|
#t.GM = 398600441800000.0;
|
||||||
t.period = 2.0 * math.pi * math.sqrt(math.pow(t.radius, 3.0)/ t.GM);
|
t.period = 2.0 * math.pi * math.sqrt(math.pow(t.radius, 3.0)/ t.GM);
|
||||||
t.inclination = inclination;
|
t.inclination = inclination;
|
||||||
t.inc_rad = t.inclination * math.pi/180.0;
|
t.inc_rad = t.inclination * math.pi/180.0;
|
||||||
|
@ -17,12 +18,12 @@ var orbitalTarget = {
|
||||||
t.node_longitude = node_longitude;
|
t.node_longitude = node_longitude;
|
||||||
t.nl_rad = t.node_longitude * math.pi/180.0;
|
t.nl_rad = t.node_longitude * math.pi/180.0;
|
||||||
var l_tmp = t.l_vec[0];
|
var l_tmp = t.l_vec[0];
|
||||||
t.l_vec[0] = math.cos(t.nl_rad) * l_tmp;
|
t.l_vec[0] = -math.sin(t.nl_rad) * l_tmp;
|
||||||
t.l_vec[1] = -math.sin(t.nl_rad) * l_tmp;
|
t.l_vec[1] = math.cos(t.nl_rad) * l_tmp;
|
||||||
t.anomaly = anomaly;
|
t.anomaly = anomaly;
|
||||||
t.anomaly_rad = t.anomaly * math.pi/180.0;
|
t.anomaly_rad = t.anomaly * math.pi/180.0;
|
||||||
t.delta_lon = 0.0;
|
t.delta_lon = 0.0;
|
||||||
t.update_time = 1.0;
|
t.update_time = 0.1;
|
||||||
t.running_flag = 0;
|
t.running_flag = 0;
|
||||||
return t;
|
return t;
|
||||||
},
|
},
|
||||||
|
@ -50,28 +51,56 @@ var orbitalTarget = {
|
||||||
print("Lat: ", lla[0], " lon: ", lla[1], " alt: ", lla[2]);
|
print("Lat: ", lla[0], " lon: ", lla[1], " alt: ", lla[2]);
|
||||||
},
|
},
|
||||||
|
|
||||||
evolve: func (dt) {
|
evolve: func {
|
||||||
|
var dt = getprop("/sim/time/delta-sec");
|
||||||
|
#var speedup = getprop("/sim/speed-up");
|
||||||
|
#dt = dt * speedup;
|
||||||
me.anomaly_rad = me.anomaly_rad + dt/me.period * 2.0 * math.pi;
|
me.anomaly_rad = me.anomaly_rad + dt/me.period * 2.0 * math.pi;
|
||||||
if (me.anomaly_rad > 2.0 * math.pi)
|
if (me.anomaly_rad > 2.0 * math.pi)
|
||||||
{
|
{
|
||||||
me.anomaly_rad = me.anomaly_rad - 2.0 * math.pi;
|
me.anomaly_rad = me.anomaly_rad - 2.0 * math.pi;
|
||||||
}
|
}
|
||||||
me.anomaly = me.anomaly_rad * 180/math.pi;
|
me.anomaly = me.anomaly_rad * 180.0/math.pi;
|
||||||
me.delta_lon = me.delta_lon + dt * 0.00418333333333327;
|
me.delta_lon = me.delta_lon + dt * 0.00418333333333327;
|
||||||
},
|
},
|
||||||
get_inertial_pos: func {
|
get_inertial_pos: func {
|
||||||
|
|
||||||
# movement around equatorial orbit
|
# movement around equatorial orbit
|
||||||
var x = me.radius * -math.sin(me.anomaly_rad);
|
var x = me.radius * math.cos(me.anomaly_rad);
|
||||||
var y = me.radius * math.cos(me.anomaly_rad);
|
var y = me.radius * math.sin(me.anomaly_rad);
|
||||||
var z = 0;
|
var z = 0;
|
||||||
|
|
||||||
# tilt with inclination
|
# tilt with inclination
|
||||||
z = x * -math.sin(me.inc_rad);
|
z = y * math.sin(me.inc_rad);
|
||||||
x = x * math.cos(me.inc_rad);
|
y = y * math.cos(me.inc_rad);
|
||||||
|
|
||||||
|
|
||||||
# rotate with node longitude
|
# rotate with node longitude
|
||||||
|
|
||||||
|
var xp = x * math.cos(me.nl_rad) - y * math.sin(me.nl_rad);
|
||||||
|
var yp = x * math.sin(me.nl_rad) + y * math.cos(me.nl_rad);
|
||||||
|
|
||||||
|
return [xp, yp, z];
|
||||||
|
},
|
||||||
|
get_future_inertial_pos: func (time) {
|
||||||
|
|
||||||
|
var anomaly_rad = me.anomaly_rad + time/me.period * 2.0 * math.pi;
|
||||||
|
while (anomaly_rad > 2.0 * math.pi)
|
||||||
|
{
|
||||||
|
anomaly_rad = anomaly_rad - 2.0 * math.pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
# movement around equatorial orbit
|
||||||
|
var x = me.radius * math.cos(anomaly_rad);
|
||||||
|
var y = me.radius * math.sin(anomaly_rad);
|
||||||
|
var z = 0;
|
||||||
|
|
||||||
|
# tilt with inclination
|
||||||
|
z = y * math.sin(me.inc_rad);
|
||||||
|
y = y * math.cos(me.inc_rad);
|
||||||
|
|
||||||
|
# rotate with node longitude
|
||||||
|
|
||||||
var xp = x * math.cos(me.nl_rad) - y * math.sin(me.nl_rad);
|
var xp = x * math.cos(me.nl_rad) - y * math.sin(me.nl_rad);
|
||||||
var yp = x * math.sin(me.nl_rad) + y * math.cos(me.nl_rad);
|
var yp = x * math.sin(me.nl_rad) + y * math.cos(me.nl_rad);
|
||||||
|
|
||||||
|
@ -86,6 +115,7 @@ var orbitalTarget = {
|
||||||
|
|
||||||
return [coordinates.lat(), coordinates.lon(), coordinates.alt()];
|
return [coordinates.lat(), coordinates.lon(), coordinates.alt()];
|
||||||
},
|
},
|
||||||
|
|
||||||
start: func {
|
start: func {
|
||||||
if (me.running_flag == 1) {return;}
|
if (me.running_flag == 1) {return;}
|
||||||
me.running_flag = 1;
|
me.running_flag = 1;
|
||||||
|
@ -98,7 +128,7 @@ var orbitalTarget = {
|
||||||
run: func {
|
run: func {
|
||||||
me.evolve (me.update_time);
|
me.evolve (me.update_time);
|
||||||
if (me.running_flag == 1)
|
if (me.running_flag == 1)
|
||||||
{settimer(func me.run(), me.update_time);}
|
{settimer(func me.run(), 0);}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue