SGP.NET icon indicating copy to clipboard operation
SGP.NET copied to clipboard

RangeRate seems to be incorrect

Open Magner18 opened this issue 3 years ago • 12 comments

I Implemented a very basic application using SGP.NET and I think I am getting incorrect range rate values. my little test app is tracking STARLINK-3962, and I can watch the range change by something like .2 km/s or 1km/s depending on the satellites current position relative to the ground station. anyway the reported range rate is sometime 0km/s or 0.00000000000000002079601643302110 km/s. anyway that value I think is incorrect.

Magner18 avatar Jun 24 '22 14:06 Magner18

Can you share the TLE and a timestamp where the issue occurs? I'll get it set up in a debugger and see where the issue is coming from. I'll also compare it to gpredict since the RR calculation is using the same formula.

parzivail avatar Jun 24 '22 14:06 parzivail

1 52708U 22053BE 22175.16667824 -.00063401 00000-0 -45001-3 0 9990 2 52708 53.2156 116.0059 0002599 15.3214 275.1441 15.73231754 6108

10:15 am 6/24/2022

Ground station location lat 31.577255 long -110.36208 alt 3052

Magner18 avatar Jun 24 '22 15:06 Magner18

Can you confirm that this snippet properly represents and reproduces the issue?

var tle = new []
{
	"1 52708U 22053BE  22175.16667824 -.00063401  00000-0 -45001-3 0  9990",
	"2 52708  53.2156 116.0059 0002599  15.3214 275.1441 15.73231754  6108"
};

var time = new DateTime(2022, 6, 24, 17, 15, 00, DateTimeKind.Utc);

var gs = new GroundStation(new GeodeticCoordinate(Angle.FromDegrees(31.577255), Angle.FromDegrees(-110.36208), 3052));

var sat = new Satellite(tle[0], tle[1]);
while (true)
{
	var o = gs.Observe(sat, time);
	Console.WriteLine(o.RangeRate);

	time += TimeSpan.FromSeconds(1);
	Thread.Sleep(100);
}

parzivail avatar Jun 24 '22 15:06 parzivail

strangely it does not, however if you use DateTime.Now instead of the time i provided it does produce the issue I am seeing.

Magner18 avatar Jun 24 '22 15:06 Magner18

Does it also break when using DateTime.UtcNow? All input times are in UTC.

parzivail avatar Jun 24 '22 15:06 parzivail

that also breaks. I think the issue may be that by setting time to DateTime.Now or DateTime.UtcNow the value changes while it is doing the calculations.

Magner18 avatar Jun 24 '22 15:06 Magner18

Nope, thats not it, I think it just something to do with a time generated using DateTime.Now

Magner18 avatar Jun 24 '22 16:06 Magner18

ok I created the time var like this var time = new DateTime(Datetime.Now.Year, Datetime.Now.Month, Datetime.Now.Day, Datetime.Now.Hour, Datetime.Now.Minute, Datetime.Now.Second, DateTimeKind.UTC);

and the problem went away.

Magner18 avatar Jun 24 '22 16:06 Magner18

Changing the inner loop to directly use DateTime.UtcNow seems to produce similar output to the first snippet:

while (true)
{
	var o = gs.Observe(sat, DateTime.UtcNow);
	Console.WriteLine(o.RangeRate);
	Thread.Sleep(1000);
}

It's strange that directly using DateTime.UtcNow in your case was creating an issue (and be warned that DateTime.Now uses your local time, which will be incorrect in the ground station's time zone by 7 hours). What runtime are you using?

parzivail avatar Jun 24 '22 16:06 parzivail

4.0.30319.42000

Magner18 avatar Jun 24 '22 16:06 Magner18

@parzivail so you are able to reproduce the issue I am seeing?

Magner18 avatar Jun 24 '22 16:06 Magner18

Apologies for the delay -- No, I haven't been able to reproduce this issue, on .NET 4 or .NET 6. Can you put together a minimal repo that can demonstrate the issue so I can reproduce your setup exactly? I doubt this is a runtime issue but it's very strange that using the dynamic DateTime fields break but using a constructed DateTime works.

parzivail avatar Jun 27 '22 15:06 parzivail