Created
October 11, 2024 23:38
-
-
Save agrif/ed17595297cf54f40ade721618fbb09b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() -> anyhow::Result<()> { | |
let lines = vec![ | |
"ISS (ZARYA)", | |
"1 25544U 98067A 24285.74177330 .00036177 00000-0 64514-3 0 9990", | |
"2 25544 51.6390 98.0883 0008472 63.6655 27.1997 15.49693494476628", | |
]; | |
let home = satkit::ITRFCoord::from_geodetic_deg(0.0, 0.0, 268.9); | |
// parse TLE | |
let mut tle = | |
satkit::TLE::load_3line(lines[0], lines[1], lines[2]).map_err(|e| anyhow::anyhow!(e))?; | |
// prediction time | |
let tm = satkit::AstroTime::now().map_err(|e| anyhow::anyhow!(e))?; | |
// propogate orbit | |
let (teme_pos, teme_vel, errs) = satkit::sgp4::sgp4(&mut tle, &[tm]); | |
// move from True-Equinox Mean Equator (used in SGP4) | |
// to International Terrestrial Reference Frame (ITRF) used by people | |
let qteme2itrf = satkit::frametransform::qteme2itrf(&tm); | |
let itrf_pos = qteme2itrf * teme_pos.column(0); | |
let itrf_vel = qteme2itrf * teme_vel.column(0); | |
println!("pos {:?}", itrf_pos); | |
println!("vel {:?}", itrf_vel); | |
println!("velmag {:?}", itrf_vel.norm()); | |
println!("err {:?}", errs); | |
// wrap ITRF in a nicer wrapper to extract lat/long/alt | |
let itrf = satkit::ITRFCoord::from_slice(itrf_pos.column(0).as_slice()) | |
.map_err(|e| anyhow::anyhow!(e))?; | |
println!(); | |
println!("lat {:?}", itrf.latitude_deg()); | |
println!("lon {:?}", itrf.longitude_deg()); | |
println!("altitude {:?}", itrf.hae()); | |
// transform into a coordinate frame with home as origin | |
// choices: East / North / UP (enu) or North / East / Down (ned) | |
//let enu = itrf.to_enu(&home).normalize(); | |
let enu = home.q_enu2itrf().conjugate() * (itrf - home); | |
let enu = enu.normalize(); | |
//let ned = itrf.to_ned(&home).normalize(); | |
//let ned = home.q_ned2itrf().conjugate() * (itrf - home); | |
//let ned = ned.normalize(); | |
// ...why are these bugged | |
println!(); | |
println!("enu:"); | |
println!("east: {:?}", enu.x); | |
println!("north: {:?}", enu.y); | |
println!("up: {:?}", enu.z); | |
//println!("ned:"); | |
//println!("north: {:?}", ned.x); | |
//println!("east: {:?}", ned.y); | |
//println!("down: {:?}", ned.z); | |
// extract elevation and azimuth | |
let el = enu.z.asin() * 180.0 / std::f64::consts::PI; | |
let az = enu.x.atan2(enu.y) * 180.0 / std::f64::consts::PI; | |
println!(); | |
println!("el {:?} az {:?}", el, az); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment