Skip to content

Commit

Permalink
Merge pull request #108 from thkruz/sgp4Validation
Browse files Browse the repository at this point in the history
Sgp4 validation
  • Loading branch information
ezze committed Jan 6, 2023
2 parents 3ca50b0 + 7691f3a commit 64f4e92
Show file tree
Hide file tree
Showing 67 changed files with 1,930,147 additions and 359 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lib
sgp4_verification/lib/sgp4
*.log
package-lock.json
test/propagation/sgp4prop
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"rollup": "^2.26.11",
"rollup-plugin-terser": "^7.0.2"
},
"jest": {
"testPathIgnorePatterns": [
"node_modules",
"test/propagation/sgp4prop"
]
},
"homepage": "https://github.com/shashwatak/satellite-js",
"directories": {
"lib": "lib",
Expand Down
10 changes: 5 additions & 5 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ export const twoPi = pi * 2;
export const deg2rad = pi / 180.0;
export const rad2deg = 180 / pi;
export const minutesPerDay = 1440.0;
export const mu = 398600.5; // in km3 / s2
export const earthRadius = 6378.137; // in km
export const mu = 398600.8; // in km3 / s2
export const earthRadius = 6378.135; // in km
export const xke = 60.0 / Math.sqrt((earthRadius * earthRadius * earthRadius) / mu);
export const vkmpersec = (earthRadius * xke) / 60.0;
export const tumin = 1.0 / xke;
export const j2 = 0.00108262998905;
export const j3 = -0.00000253215306;
export const j4 = -0.00000161098761;
export const j2 = 0.001082616;
export const j3 = -0.00000253881;
export const j4 = -0.00000165597;
export const j3oj2 = j3 / j2;
export const x2o3 = 2.0 / 3.0;
38 changes: 13 additions & 25 deletions src/io.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
pi,
tumin,
deg2rad,
} from './constants';
import { pi, deg2rad } from './constants';

import {
jday,
days2mdhms,
} from './ext';
import { jday, days2mdhms } from './ext';

import sgp4init from './propagation/sgp4init';

Expand Down Expand Up @@ -80,13 +73,16 @@ export default function twoline2satrec(longstr1, longstr2) {
satrec.epochdays = parseFloat(longstr1.substring(20, 32));
satrec.ndot = parseFloat(longstr1.substring(33, 43));
satrec.nddot = parseFloat(
`.${parseInt(longstr1.substring(44, 50), 10)
}E${longstr1.substring(50, 52)}`,
`.${parseInt(longstr1.substring(44, 50), 10)}E${longstr1.substring(
50,
52,
)}`,
);
satrec.bstar = parseFloat(
`${longstr1.substring(53, 54)
}.${parseInt(longstr1.substring(54, 59), 10)
}E${longstr1.substring(59, 61)}`,
`${longstr1.substring(53, 54)}.${parseInt(
longstr1.substring(54, 59),
10,
)}E${longstr1.substring(59, 61)}`,
);

// satrec.satnum = longstr2.substring(2, 7);
Expand All @@ -103,19 +99,15 @@ export default function twoline2satrec(longstr1, longstr2) {
// satrec.bstar= satrec.bstar * Math.pow(10.0, ibexp);

// ---- convert to sgp4 units ----
satrec.a = ((satrec.no * tumin) ** (-2.0 / 3.0));
satrec.ndot /= (xpdotp * 1440.0); // ? * minperday
satrec.nddot /= (xpdotp * 1440.0 * 1440);
// satrec.ndot /= (xpdotp * 1440.0); // ? * minperday
// satrec.nddot /= (xpdotp * 1440.0 * 1440);

// ---- find standard orbital elements ----
satrec.inclo *= deg2rad;
satrec.nodeo *= deg2rad;
satrec.argpo *= deg2rad;
satrec.mo *= deg2rad;

satrec.alta = (satrec.a * (1.0 + satrec.ecco)) - 1.0;
satrec.altp = (satrec.a * (1.0 - satrec.ecco)) - 1.0;

// ----------------------------------------------------------------
// find sgp4epoch time of element set
// remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
Expand All @@ -134,11 +126,7 @@ export default function twoline2satrec(longstr1, longstr2) {
const mdhmsResult = days2mdhms(year, satrec.epochdays);

const {
mon,
day,
hr,
minute,
sec,
mon, day, hr, minute, sec,
} = mdhmsResult;
satrec.jdsatepoch = jday(year, mon, day, hr, minute, sec);

Expand Down
4 changes: 2 additions & 2 deletions src/propagation/dspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ export default function dspace(options) {
+ (d3222 * Math.cos((-xomi + xli) - g32))
+ (d5220 * Math.cos((xomi + xli) - g52))
+ (d5232 * Math.cos((-xomi + xli) - g52))
+ (2.0 * d4410 * Math.cos((x2omi + x2li) - g44))
+ 2.0 * ((d4410 * Math.cos((x2omi + x2li) - g44))
+ (d4422 * Math.cos(x2li - g44))
+ (d5421 * Math.cos((xomi + x2li) - g54))
+ (d5433 * Math.cos((-xomi + x2li) - g54));
+ (d5433 * Math.cos((-xomi + x2li) - g54)));
xnddt *= xldot;
}

Expand Down
4 changes: 4 additions & 0 deletions src/propagation/sgp4init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
j4,
j3oj2,
x2o3,
tumin,
} from '../constants';

import dpper from './dpper';
Expand Down Expand Up @@ -262,6 +263,9 @@ export default function sgp4init(satrec, options) {
satrec.no = initlResult.no;
satrec.con41 = initlResult.con41;
satrec.gsto = initlResult.gsto;
satrec.a = (satrec.no * tumin) ** (-2.0 / 3.0);
satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0;
satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0;
satrec.error = 0;

// sgp4fix remove this check as it is unnecessary
Expand Down
40 changes: 20 additions & 20 deletions test/propagation/dsinit.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@
"results": {
"argpm": 0,
"atime": 0,
"d2201": -1.2099452515548102e-11,
"d2211": 1.0011506195793891e-11,
"d3210": -5.0866898135037016e-12,
"d3222": -3.987984720569471e-13,
"d4410": 4.109492519702797e-13,
"d4422": 9.349618846253649e-14,
"d5220": 2.4097891471717693e-13,
"d5232": 1.6478793629942387e-13,
"d5421": -2.138743302011661e-13,
"d5433": -9.311246040525512e-15,
"d2201": -1.2099438856510436e-11,
"d2211": 1.0011494893832913e-11,
"d3210": -5.086681199981555e-12,
"d3222": -3.9879779675343986e-13,
"d4410": 4.10948324131911e-13,
"d4422": 9.349597736749112e-14,
"d5220": 2.4097823461671757e-13,
"d5232": 1.6478747122823163e-13,
"d5421": -2.1387372659636362e-13,
"d5433": -9.311219761949575e-15,
"dedt": 6.387624124699951e-9,
"del1": 0,
"del2": 0,
Expand Down Expand Up @@ -188,16 +188,16 @@
"results": {
"argpm": 0,
"atime": 0,
"d2201": -2.077924583398718e-11,
"d2211": 8.354983905797916e-11,
"d3210": -7.971726821781479e-11,
"d3222": -1.5879590871766552e-11,
"d4410": 1.5757473446619235e-11,
"d4422": 7.56870174312408e-12,
"d5220": 3.642170086460131e-11,
"d5232": 6.090615241770774e-11,
"d5421": -4.636788210900563e-11,
"d5433": -5.740340181834411e-12,
"d2201": -2.077922237635543e-11,
"d2211": 8.354974473880257e-11,
"d3210": -7.971713322895552e-11,
"d3222": -1.5879563982136425e-11,
"d4410": 1.575743786950506e-11,
"d4422": 7.56868465456182e-12,
"d5220": 3.642159807380104e-11,
"d5232": 6.0905980525896e-11,
"d5421": -4.636775124768956e-11,
"d5433": -5.740323981213709e-12,
"dedt": 5.789849295568645e-9,
"del1": 0,
"del2": 0,
Expand Down
20 changes: 20 additions & 0 deletions test/propagation/full-catalog/BadTLE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
1 33589U 91003S 19156.28428763 -.00000001 +00000-0 +39291-2 0 9991
2 33589 007.5114 000.3168 6752729 232.4889 045.0370 02.63585777043792
1 40081U 14038C 22221.24935965 -.00000020 00000-0 00000-0 0 9994
2 40081 0.0544 0.3980 0002696 138.3497 221.2709 5.00115359147392

// Reentry
1 50643U 82092AMP 22107.08250619 .17935521 -11960-5 45096-2 0 9994
2 50643 82.5475 328.5319 0011741 236.4515 123.5658 16.28849345 21342

// Crazy Ecce
1 43846U 18103B 22079.42598936 -.00047618 00000-0 00000-0 0 9991
2 43846 55.1662 7.8333 7551453 59.2451 33.0956 0.02456857158065
1 48419U 91075Q 22221.28029576 .00000566 00000-0 14123-2 0 9996
2 48419 7.5076 0.1398 6425379 73.0041 344.7415 3.27664205103484

// Huge B*
1 44850U 19088A 22221.48313072 -.00000011 00000-0 16595+1 0 9993
2 44850 64.9641 120.9119 0012532 260.4965 279.9784 2.13102398 20705
1 89400U 22135.70173143 -.00029463 +00000+0 -45712+1 0 9994
2 89400 63.1733 251.3371 1951966 101.2335 281.1876 8.12027678 15
Loading

0 comments on commit 64f4e92

Please sign in to comment.