I want to use TLE data to calculate the azimuth and elevation of every GPS satellites at user's location.
In order to verify the correctness of TLE calculation, I wrote an Android app that can be positioned using GPS and get the data of each satellite when positioning using Android API.
At the same time, the azimuth and elevation of the satellite are calculated using pyephem and user position, positioning time and TLE data when the app is in run.
Strangely, the results of my TLE data calculation are different from those obtained by app on phones.
The following is the specific process:
First,I write a simple Android program, use getPrn() , getAzimuth() , getElevation() to get prn, azimuth and elevation of each satellite. And get gps location. The core code is as follows:
private final GpsStatus.Listener gpsStatusListener = new GpsStatus.Listener() {
public void onGpsStatusChanged(int event) {
GpsStatus status = mLocationManager.getGpsStatus(null);
getGPSStatus(event, status);
}
};
private void getGPSStatus(int event, GpsStatus status) {
if (status == null) {
} else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
String detail = "";
int maxSatellites = status.getMaxSatellites();
Iterator<GpsSatellite> it = status.getSatellites().iterator();
// numSatelliteList.clear();
int count = 0;
int goodcount = 0;
mPrnStr = "";
while (it.hasNext() && count <= maxSatellites) {
GpsSatellite gpsSatellite = it.next();
float elevation = gpsSatellite.getElevation();
float azimuth = gpsSatellite.getAzimuth();
int prn = gpsSatellite.getPrn();
float snr = gpsSatellite.getSnr();
int hasAlmanac = gpsSatellite.hasAlmanac() ? 1 : 0;
int hasEphemeris = gpsSatellite.hasEphemeris() ? 1 : 0;
int usedInFix = gpsSatellite.usedInFix() ? 1 : 0;
if (usedInFix == 1) {
goodcount++;
mPrnStr += (prn + "|");
}
count++;
detail = detail + String.format("%.5f:%.5f:%d:%.5f:%d:%d:%d|", elevation, azimuth, prn, snr, hasAlmanac,
hasEphemeris, usedInFix);
}
mGpsStar = String.format("%d-%d", goodcount, count);
mGpsStarDetail = detail;
}
}
I ran the APP on my phone and got the following results:
49.00000:185.00000:10:29.20000:1:1:1|33.00000:52.00000:12:42.30000:1:1:1|54.00000:312.00000:14:38.80000:1:0:1
From the data, we can see that the azimuth of the satellite with PRN equal to 10 is 185° and elevation is 49°.
Second, when I run the app, the result of GPS positioning is 116.295953,40.050029,42.00(longitude,latitude,altitude)
I use pyephem and TLE compute azimuth and elevation of each satellite When my position is 116.295953,40.050029,42.00
and time is 2018-11-9 18:30:30
(This is the time I used to run Android app).
The code is as follows:
import ephem
me = ephem.Observer()
me.lon, me.lat, me.elevation = 116.295953,40.050029,42.00
line1 = 'GPS BIIF-11 (PRN 10)'
line2 = '1 41019U 15062A 18315.18162228 .00000031 00000-0 00000-0 0 9991'
line3 = '2 41019 55.1130 139.9366 0040562 201.4871 158.3788 2.00564661 22171'
sat = ephem.readtle(line1, line2, line3)
me.date = ephem.date((2018, 11, 9, 18, 30, 30))
sat.compute(me)
print sat.az * 180.0 / 3.1416
print sat.alt * 180.0 / 3.1416
The output of this code is:
24.5045833546
-19.6957760088
Because I set the same location and time, the results calculated from TLE should be similar to the results I got from running android app. But in the app result, the azimuth and elevation of prn10 is:185° and 49°.In the TLE result, the azimuth and elevation of prn10 is:24.5045833546°,-19.6957760088°. They're very different. It's strange.
Please tell me where the problem is. Thanks a lot.