shashwatak / satellite-js

Modular set of functions for SGP4 and SDP4 propagation of TLEs.
MIT License
917 stars 145 forks source link

Unable to get matching results. #3

Closed Axiverse closed 10 years ago

Axiverse commented 10 years ago

I'm comparing results with: http://www.satellite-calculations.com/TLETracker/SatTracker.htm

And I can't seem to get matching results. Besides the TLE, the only two inputs from me are the time for satellite.propagate, and satellite.gmstime_from_date

I'm using this code

    var iss = [
        '1 25544U 98067A   14074.90256052  .00016379  00000-0  28535-3 0  8761',
        '2 25544  51.6489 201.9469 0004294 307.0067 147.1768 15.50879666876859'];

    var satrec = satellite.twoline2satrec(iss[0], iss[1]);

        var now = new Date();

        var pv = satellite.propagate( satrec,
                        now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
                        now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()
                        );

        //pv = satellite.propagate( satrec,
        //              now.getFullYear(), now.getMonth(), now.getDate(),
        //              now.getHours(), now.getMinutes(), now.getSeconds()
        //              );

        var position_eci = pv.position;

        var gmst = satellite.gstime_from_date (now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
                        now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());

        var p_eci = satellite.eci_to_ecf( position_eci, gmst );
        var p_gf = satellite.eci_to_geodetic( p_eci, gmst );

The TLE is

ISS (ZARYA)             
1 25544U 98067A   14074.90256052  .00016379  00000-0  28535-3 0  8761
2 25544  51.6489 201.9469 0004294 307.0067 147.1768 15.50879666876859
shashwatak commented 10 years ago

Thanks for using this library!

I'm a bit busy right now, but I'll try to take a look at this on the weekend. If I don't have a response for you by monday, feel free to email/message me again, to remind me.

Axiverse commented 10 years ago

Alright, looking forward to it. Thanks for making the library too, all I can offer is a screenshot. =)

screen shot 2014-03-19 at 12 03 07 am

Axiverse commented 10 years ago

Ping

shashwatak commented 10 years ago

That looks amazing =)

Sorry for the lag. Still haven't had a chance to look at the issue >_< last couple of weekends have been gnarly.

shashwatak commented 10 years ago

Just wanted to pop in and say I've done nothing useful with regards to this yet =( Still quite busy with work and personal stuff. But I haven't forgotten!

Hopefully this weekend I find the time. Keeping fingers crossed.

davidcalhoun commented 10 years ago

The sgp4_verification Chrome App is failing for me too, giving results that are slightly off. I think there's a root cause

My guess is that it's JS fudging up the floating point math. For example, try this in your console:

> 1.1 + 1.3
2.4000000000000004

Obviously there's something funky going on with the math there - it's a defect built into the language. This is one of the worst parts of the language.

To do accurate floating point math you have to convert the floating point numbers to whole numbers by multiplying by some large number, doing your calculations with whole numbers, then dividing by that same large number at the end:

> ((1.1 * 10) + (1.3 * 10)) / 10
2.4

Unfortunately you have to pass all your add/subtract and multiply/divide stuff through passthrough functions to get accurate results. :(

davidcalhoun commented 10 years ago

Here's a library that should help with the floating point errors: http://mathjs.org/

bakercp commented 10 years ago

Hi there, I too am getting strange results that don't match up with my C++ code or other online resources -- I'm wondering if any additional progress has been made on this?

Here's where I'm working.

http://data.olab.io/sky-client https://github.com/olab-io/sky-client

bakercp commented 10 years ago

One thing I just figured out was that the month is expected to be in the range 1-12, not 0-11 (which is what javascript date functions give you with new Date.getUTCMonth()). This "fix" makes the calculations much closer to others. My altitude and latitude now match various references, but my longitude is still off. Anyway, making progress.

    var gmst = satellite.gstime_from_date (now.getUTCFullYear(),
                                            now.getUTCMonth() + 1,
                                            now.getUTCDate(),
                                            now.getUTCHours(),
                                            now.getUTCMinutes(),
                                            now.getUTCSeconds());
bakercp commented 10 years ago

OK. I cleaned up my code and now it appears that all of my problems stemmed from the + 1 error. I ended up figuring it out because the julian dates generated from my original code were a month behind and I also noticed this (https://github.com/koansys/isat/blob/master/js/jday.js#L14 in some related code). Thanks for the port!

bakercp commented 10 years ago

A PR with documentation updates: https://github.com/shashwatak/satellite-js/pull/4

shashwatak commented 10 years ago

Thanks Chris =)

Was that the only issue? Can this be closed?

shashwatak commented 10 years ago

Haha, i'm glad it wasn't the floating point thing, that would be embarrassing >_>

Although shitty documentation is not any better, i suppose.

bakercp commented 10 years ago

The month issue resolved it for me. Thanks! On May 28, 2014 1:19 PM, "Shashwat Kandadai" notifications@github.com wrote:

Haha, i'm glad it wasn't the floating point thing, that would be embarrassing >_>

Although shitty documentation is not any better, i suppose.

— Reply to this email directly or view it on GitHubhttps://github.com/shashwatak/satellite-js/issues/3#issuecomment-44445118 .

Axiverse commented 10 years ago

I looked over my code, and I do have +1 on month. I probably tried every variation thereof. Here's the actual code, perhaps I'm doing something stupid. I've updated the TLE, and am comparing to http://www.isstracker.com/. The good news is that latitude seems to stay within 0.1 degrees of the site, but longitude off by about 162 degrees (I've added this constant in the code below). Do you see anything obvious?

var simulateISS = function () {

    var iss = [
        '1 25544U 98067A   14149.54897135  .00004817  00000-0  90686-4 0  3820',
        '2 25544  51.6485 191.9904 0003760  50.7118  66.1661 15.50520394888433'];

    // create satellite 3d model
    var s = planet(1);

    // load tle for iss
    var satrec = satellite.twoline2satrec(iss[0], iss[1]);

    var is = 0;

    $(window).on( "orb:update", function( ) {

        // get date variables
        var now = new Date();
        var year = now.getUTCFullYear();
        var month = now.getUTCMonth() + 1;
        var date = now.getUTCDate();
        var hour = now.getUTCHours();
        var minute = now.getUTCMinutes();
        var second = now.getUTCSeconds();

        var pv = satellite.propagate( satrec, year, month, date, hour, minute, second );

        var position_eci = pv.position;

        var gmst = satellite.gstime_from_date ( year, month, date, hour, minute, second );

        var p_eci = satellite.eci_to_ecf( position_eci, gmst );
        var p_gf = satellite.eci_to_geodetic( p_eci, gmst );

        // radian to degree conversion
        var r2d = 180 / Math.PI;
        var p;

        // set p from xyz
        p = new THREE.Vector3(p_eci.x, p_eci.y, p_eci.z);
        p.multiplyScalar(100 / 6378.1);

        // set p from long/lat
        p = toVector(162 + p_gf.longitude * r2d, p_gf.latitude * r2d);

        s.position = p;

        // display debug text
        var infoa = $('#info-a');
        infoa.text((p_gf.longitude * r2d + 162).toFixed(2) + ', ' + (p_gf.latitude * r2d).toFixed(2));
    });

    Orb.scene.add(s);

};
Axiverse commented 10 years ago

Ah, I found the error - variable error/confusion of eci and ecf; Thanks for validating.

var p_eci = satellite.eci_to_ecf( position_eci, gmst );
var p_gf = satellite.eci_to_geodetic( p_eci, gmst );
shashwatak commented 10 years ago

Thanks again to everybody involved with this =D

akraj31 commented 7 years ago

This issue is closed that means you guys are getting correct result, so maybe there is some understanding issue because of which I am not able to generate correct results. Please help me regarding this.

I have compared the results with AGI STK Desktop application. AGI STK Help Page says

By default, STK utilizes the CSSI SGP4 routine, Version 2008-11-03.

Following is the full description of my usage:

TLE Data:

1 20959U 90103A   14044.72615235  .00000027  00000-0  00000+0 0  2724 
2 20959  54.3261 214.0472 0115346 348.3774  11.3322  2.00583365170051

ECI Data generated from AGI STK software:

Time (UTCG)                    x (km)            y (km)       z (km) 
28 Jul 2017 02:55:06.000    -6749.036399    -14064.485321    21282.805742
28 Jul 2017 02:55:07.000    -6745.397433    -14065.853241    21283.102965
28 Jul 2017 02:55:08.000    -6741.758320    -14067.220855    21283.399727
28 Jul 2017 02:55:09.000    -6738.119061    -14068.588164    21283.696028
28 Jul 2017 02:55:10.000    -6734.479656    -14069.955168    21283.991866
28 Jul 2017 02:55:11.000    -6730.840105    -14071.321867    21284.287243
28 Jul 2017 02:55:12.000    -6727.200408    -14072.688260    21284.582158
28 Jul 2017 02:55:13.000    -6723.560565    -14074.054349    21284.876612
28 Jul 2017 02:55:14.000    -6719.920576    -14075.420132    21285.170603
28 Jul 2017 02:55:15.000    -6716.280441    -14076.785610    21285.464134

My Code( using satellite.js):

updateEntityToCurrentSimTime: function (time) {
        var date = new Date( "07/28/2017 08:25:05");
        var tleLines = ["1 20959U 90103A   14044.72615235  .00000027  00000-0  00000+0 0  2724",
                        "2 20959  54.3261 214.0472 0115346 348.3774  11.3322  2.00583365170051"];

        var satrec = satellite.twoline2satrec(tleLines[0], tleLines[1]);         

        //update current date
        date.setSeconds(date.getSeconds() + time);            

        var gmst = satellite.gstimeFromDate(date);

        var posAndVelECI = satellite.propagate(satrec, date);
}

ECI data from my code:

28 Jul 2017 02:55:06 GMT    -6729.586681293093    -14090.192704493444    21271.96936623743
28 Jul 2017 02:55:07 GMT    -6725.942904316204    -14091.546319840401    21272.272757457347
28 Jul 2017 02:55:08 GMT    -6722.298834777501    -14092.899684035754    21272.57569941536
28 Jul 2017 02:55:09 GMT    -6718.654766124882    -14094.252688097995    21272.87816771835
28 Jul 2017 02:55:10 GMT    -6715.010551711341    -14095.605386498912    21273.18017456913
28 Jul 2017 02:55:11 GMT    -6711.366191662034    -14096.9577791936    21273.481719959364
28 Jul 2017 02:55:12 GMT    -6707.721686056604    -14098.309866154083    21273.782803884547
28 Jul 2017 02:55:13 GMT    -6704.077034974806    -14099.661647352345    21274.083426340152
28 Jul 2017 02:55:14 GMT    -6700.432238496194    -14101.013122760447    21274.383587321685
28 Jul 2017 02:55:15 GMT    -6696.787150063399    -14102.364346701132    21274.683298872136