Exemplo n.º 1
0
PredicThirteen::geodetic_t PredicThirteen::calc(PredicThirteen::tle_t t){
    printTle(&t);
    DEBUG_PRINTLN("----------------------------------------");
    PredicThirteen::vector_t zero_vector={0,0,0,0};
    PredicThirteen::vector_t pos = zero_vector;
    PredicThirteen::vector_t vel = zero_vector;
    PredicThirteen::geodetic_t geo = {0,0,0,0};

    jul_utc = daynum +723244000000LL;
    jul_epoch=Julian_Date_of_Epoch(t.epoch_year, t.epoch_day);
    printUint64("TestNum", (uint64_t) 11118562939LL);
    printUint64("daynum", daynum);
    printUint64("jul_utc",jul_utc);
    printUint64("jul_epoch",jul_epoch);
    tsince =   ((jul_utc - jul_epoch)/1000000.0) * minday;


    select_ephemeris(&t);

    SGP4(tsince, &t, &pos, &vel);
    Convert_Sat_State(&pos, &vel);   
    Magnitude(&vel);        
    printVar("jul_utc", jul_utc);
    Calculate_LatLonAlt(jul_utc, &pos, &geo);
    printVector(&pos);
    printVector(&vel);
    printGeo(&geo);
    LAT = geo.lat;
    LON = geo.lon;
    Serial.print("LAT: ");
    Serial.println(LAT);
    Serial.print("LON: ");
    Serial.println(LON);
    return geo;
}
Exemplo n.º 2
0
void TLE_Handler_Update(TM * time)
{
	double epoch;
	
	int year = time->tm_year;
	while (year > 100) { year -= 100; }
	
	epoch = (double)year * 100.0;
	epoch += time->tm_yday;
	epoch += (double)time->tm_hour / (double)HOURS_PER_DAY;
	epoch += (double)time->tm_min / (double)MINS_PER_DAY;
	epoch += (double)time->tm_sec / (double)S_PER_DAY;
	
	sgp4call(Julian_Date_of_Epoch(epoch), &pos, NULL, &s_data);
	Convert_Sat_State(&pos, NULL);
}
Exemplo n.º 3
0
void SatGL::RenderTrail(Satellite *sat, QMatrix4x4 projection, float distance, QQuaternion quat, bool trackon) // QMatrix4x4 modelview, bool trackon)
{
    QVector<GLfloat> postrail;

    double
            tsince,            // Time since epoch (in minutes)
            jul_epoch,         // Julian date of epoch
            jul_utc;           // Julian UTC date


    QSgp4Date nowutc = QSgp4Date::NowUTC();
    jul_utc = nowutc.Julian();
    jul_epoch = Julian_Date_of_Epoch(sat->GetEpoch());

    QMatrix4x4 model;
    model.translate(0.0, 0.0, distance);
    model.rotate(quat);

    QMatrix4x4 modelview;
    modelview = model;
    QMatrix4x4 modelocta;
    QColor col(0,255,255);

    QEci qeci;
    QVector3D pos;
    double id;
    int nbrVertices = 0;

    tsince = (jul_utc - jul_epoch) * MIN_PER_DAY; // in minutes

    for( id = tsince - 5; id < tsince; id++ )
    {
        (*sat).qsgp4->getPosition(id, qeci);
        QGeodetic qgeo = qeci.ToGeo();
        LonLat2PointRad(qgeo.latitude, qgeo.longitude, &pos, 1.001f);
        if(id < tsince && id >= tsince - 5 )
        {
            modelocta = model;
            modelocta.translate(pos.x(), pos.y(), pos.z());
            modelocta.scale(0.004f);
            octa->render(projection, modelocta, col);
        }
    }


    if(trackon)
    {
        for( id = tsince - opts.realminutesshown + 1; id <= tsince + opts.realminutesshown; id++ )  // nbr of id's = 2 * opts.realminutesshown
        {
            (*sat).qsgp4->getPosition(id, qeci);
            QGeodetic qgeo = qeci.ToGeo();
            LonLat2PointRad(qgeo.latitude, qgeo.longitude, &pos, 1.001f);
            postrail.append(pos.x());
            postrail.append(pos.y());
            postrail.append(pos.z());
        }

        positionsTrail.bind();

        if(tdiff != opts.realminutesshown)
        {
            tdiff = opts.realminutesshown;
            positionsTrail.allocate(postrail.data(), postrail.size() * sizeof(GLfloat));

        }
        else
        {
            positionsTrail.write(0, postrail.data(), postrail.size() * sizeof(GLfloat));
        }

        nbrVertices = positionsTrail.size() / (3 * sizeof(GLfloat));

        positionsTrail.release();

        QOpenGLVertexArrayObject::Binder vaoBinder(&vaotrail);

        program->bind();

        program->setUniformValue("MVP", projection * modelview);
        QMatrix3x3 norm = modelview.normalMatrix();
        program->setUniformValue("NormalMatrix", norm);

        QColor rendercolor(opts.sattrackcolor);
        program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

        glDrawArrays(GL_LINE_STRIP, 0, nbrVertices);

    }
}
Exemplo n.º 4
0
/** \brief Initialise satellite data.
 *  \param sat The satellite to initialise.
 *  \param qth Optional QTH info, use (0,0) if NULL.
 *
 * This function calculates the satellite data at t = 0, ie. epoch time
 * The function is called automatically by gtk_sat_data_read_sat.
 */
void
gtk_sat_data_init_sat (sat_t *sat, qth_t *qth)
{
    geodetic_t obs_geodetic;
    obs_set_t obs_set;
    geodetic_t sat_geodetic;
    double jul_utc, age;

    g_return_if_fail (sat != NULL);

    jul_utc = Julian_Date_of_Epoch (sat->tle.epoch); // => tsince = 0.0
    sat->jul_epoch = jul_utc;

    /* initialise observer location */
    if (qth != NULL) {
        obs_geodetic.lon = qth->lon * de2ra;
        obs_geodetic.lat = qth->lat * de2ra;
        obs_geodetic.alt = qth->alt / 1000.0;
        obs_geodetic.theta = 0;
    }
    else {
        obs_geodetic.lon = 0.0;
        obs_geodetic.lat = 0.0;
        obs_geodetic.alt = 0.0;
        obs_geodetic.theta = 0;
    }

    /* execute computations */
    if (sat->flags & DEEP_SPACE_EPHEM_FLAG)
        SDP4 (sat, 0.0);
    else
        SGP4 (sat, 0.0);

    /* scale position and velocity to km and km/sec */
    Convert_Sat_State (&sat->pos, &sat->vel);

    /* get the velocity of the satellite */
    Magnitude (&sat->vel);
    sat->velo = sat->vel.w;
    Calculate_Obs (jul_utc, &sat->pos, &sat->vel, &obs_geodetic, &obs_set);
    Calculate_LatLonAlt (jul_utc, &sat->pos, &sat_geodetic);

    while (sat_geodetic.lon < -pi)
        sat_geodetic.lon += twopi;
    
    while (sat_geodetic.lon > (pi))
        sat_geodetic.lon -= twopi;

    sat->az = Degrees (obs_set.az);
    sat->el = Degrees (obs_set.el);
    sat->range = obs_set.range;
    sat->range_rate = obs_set.range_rate;
    sat->ssplat = Degrees (sat_geodetic.lat);
    sat->ssplon = Degrees (sat_geodetic.lon);
    sat->alt = sat_geodetic.alt;
    sat->ma = Degrees (sat->phase);
    sat->ma *= 256.0/360.0;
    sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
    age = 0.0;
    sat->orbit = (long) floor((sat->tle.xno * xmnpda/twopi +
                               age * sat->tle.bstar * ae) * age +
                              sat->tle.xmo/twopi) + sat->tle.revnum - 1;

    /* orbit type */
    sat->otype = get_orbit_type (sat);
}
Exemplo n.º 5
0
/* Main program */
  int
main(void)
{
  /* TLE source file */
  char tle_file[] = "./rax.txt";

  /* Observer's geodetic co-ordinates.      */
  /* Lat North, Lon East in rads, Alt in km */
  geodetic_t obs_geodetic = {0.7368, -1.4615, 0.251, 0.0};

  /* Two-line Orbital Elements for the satellite */
  tle_t tle ;

  /* Zero vector for initializations */
  vector_t zero_vector = {0,0,0,0};

  /* Satellite position and velocity vectors */
  vector_t vel = zero_vector;
  vector_t pos = zero_vector;
  /* Satellite Az, El, Range, Range rate */
  vector_t obs_set;

  /* Solar ECI position vector  */
  vector_t solar_vector = zero_vector;
  /* Solar observed azi and ele vector  */
  vector_t solar_set;

  /* Calendar date and time (UTC) */
  struct tm utc;

  /* Satellite's predicted geodetic position */
  geodetic_t sat_geodetic;

  double
	tsince,            /* Time since epoch (in minutes) */
	jul_epoch,         /* Julian date of epoch          */
	jul_utc,           /* Julian UTC date               */
	eclipse_depth = 0, /* Depth of satellite eclipse    */
	/* Satellite's observed position, range, range rate */
	sat_azi, sat_ele, sat_range, sat_range_rate,
	/* Satellites geodetic position and velocity */
	sat_lat, sat_lon, sat_alt, sat_vel,
	/* Solar azimuth and elevation */
	sun_azi, sun_ele;

  /* Used for storing function return codes */
  int flg;

  char
	ephem[5],       /* Ephemeris in use string  */
	sat_status[12]; /* Satellite eclipse status */


  /* Input one (first!) TLE set from file */
  flg = Input_Tle_Set(tle_file, &tle);

  /* Abort if file open fails */
  if( flg == -1 )
  {
	printf(" File open failed - Exiting!\n");
	exit(-1);
  }

  /* Print satellite name and TLE read status */
  printf(" %s: ", tle.sat_name);
  if( flg == -2 )
  {
	printf("TLE set bad - Exiting!\n");
	exit(-2);
  }
  else
	printf("TLE set good - Happy Tracking!\n");

  /* Printout of tle set data for tests if needed */
  /*  printf("\n %s %s %i  %i  %i\n"
	  " %14f %10f %8f %8f\n"
	  " %8f %8f %9f %8f %8f %12f\n",
	  tle.sat_name, tle.idesg, tle.catnr, tle.elset, tle.revnum,
	  tle.epoch, tle.xndt2o, tle.xndd6o, tle.bstar,
	  tle.xincl, tle.xnodeo, tle.eo, tle.omegao, tle.xmo, tle.xno);
   */

  /** !Clear all flags! **/
  /* Before calling a different ephemeris  */
  /* or changing the TLE set, flow control */
  /* flags must be cleared in main().      */
  ClearFlag(ALL_FLAGS);

  /** Select ephemeris type **/
  /* Will set or clear the DEEP_SPACE_EPHEM_FLAG       */
  /* depending on the TLE parameters of the satellite. */
  /* It will also pre-process tle members for the      */
  /* ephemeris functions SGP4 or SDP4 so this function */
  /* must be called each time a new tle set is used    */
  select_ephemeris(&tle);

  do  /* Loop */
  {
	/* Get UTC calendar and convert to Julian */
	UTC_Calendar_Now(&utc);
	jul_utc = Julian_Date(&utc);

	/* Convert satellite's epoch time to Julian  */
	/* and calculate time since epoch in minutes */
	jul_epoch = Julian_Date_of_Epoch(tle.epoch);
	tsince = (jul_utc - jul_epoch) * xmnpda;

	/* Copy the ephemeris type in use to ephem string */
	if( isFlagSet(DEEP_SPACE_EPHEM_FLAG) )
	  strcpy(ephem,"SDP4");
	else
	  strcpy(ephem,"SGP4");

	/* Call NORAD routines according to deep-space flag */
	if( isFlagSet(DEEP_SPACE_EPHEM_FLAG) )
	  SDP4(tsince, &tle, &pos, &vel);
	else
	  SGP4(tsince, &tle, &pos, &vel);

	/* Scale position and velocity vectors to km and km/sec */
	Convert_Sat_State( &pos, &vel );

	/* Calculate velocity of satellite */
	Magnitude( &vel );
	sat_vel = vel.w;

	/** All angles in rads. Distance in km. Velocity in km/s **/
	/* Calculate satellite Azi, Ele, Range and Range-rate */
	Calculate_Obs(jul_utc, &pos, &vel, &obs_geodetic, &obs_set);

	/* Calculate satellite Lat North, Lon East and Alt. */
	Calculate_LatLonAlt(jul_utc, &pos, &sat_geodetic);

	/* Calculate solar position and satellite eclipse depth */
	/* Also set or clear the satellite eclipsed flag accordingly */
	Calculate_Solar_Position(jul_utc, &solar_vector);
	Calculate_Obs(jul_utc,&solar_vector,&zero_vector,&obs_geodetic,&solar_set);

	if( Sat_Eclipsed(&pos, &solar_vector, &eclipse_depth) )
	  SetFlag( SAT_ECLIPSED_FLAG );
	else
	  ClearFlag( SAT_ECLIPSED_FLAG );

	/* Copy a satellite eclipse status string in sat_status */
	if( isFlagSet( SAT_ECLIPSED_FLAG ) )
	  strcpy( sat_status, "Eclipsed" );
	else
	  strcpy( sat_status, "In Sunlight" );

	/* Convert and print satellite and solar data */
	sat_azi = Degrees(obs_set.x);
	sat_ele = Degrees(obs_set.y);
	sat_range = obs_set.z;
	sat_range_rate = obs_set.w;
	sat_lat = Degrees(sat_geodetic.lat);
	sat_lon = Degrees(sat_geodetic.lon);
	sat_alt = sat_geodetic.alt;

	sun_azi = Degrees(solar_set.x);
	sun_ele = Degrees(solar_set.y);

	printf("\n Date: %02d/%02d/%04d UTC: %02d:%02d:%02d  Ephemeris: %s"
		"\n Azi=%6.1f Ele=%6.1f Range=%8.1f Range Rate=%6.2f"
		"\n Lat=%6.1f Lon=%6.1f  Alt=%8.1f  Vel=%8.3f"
		"\n Stellite Status: %s - Depth: %2.3f"
		"\n Sun Azi=%6.1f Sun Ele=%6.1f\n",
		utc.tm_mday, utc.tm_mon, utc.tm_year,
		utc.tm_hour, utc.tm_min, utc.tm_sec, ephem,
		sat_azi, sat_ele, sat_range, sat_range_rate,
		sat_lat, sat_lon, sat_alt, sat_vel,
		sat_status, eclipse_depth,
		sun_azi, sun_ele);

	sleep(1);
  }  /* End of do */
  while( 1 ); /* This stops Compaq ccc 'unreachcode' warning! */

  return(0);
} /* End of main() */
Exemplo n.º 6
0
/* This is the old Calc() function. */
int predict_orbit(const predict_orbital_elements_t *orbital_elements, struct predict_orbit *m, double utc)
{
	/* Set time to now if now time is provided: */
	if (utc == 0) utc = predict_to_julian(time(NULL));
	
	/* Satellite position and velocity vectors */
	vec3_set(m->position, 0, 0, 0);
	vec3_set(m->velocity, 0, 0, 0);

	m->time = utc;
	double julTime = utc + 2444238.5;

	/* Convert satellite's epoch time to Julian  */
	/* and calculate time since epoch in minutes */
	double epoch = 1000.0*orbital_elements->epoch_year + orbital_elements->epoch_day;
	double jul_epoch = Julian_Date_of_Epoch(epoch);
	double tsince = (julTime - jul_epoch)*xmnpda;

	/* Call NORAD routines according to deep-space flag. */
	struct model_output output;
	switch (orbital_elements->ephemeris) {
		case EPHEMERIS_SDP4:
			sdp4_predict((struct _sdp4*)orbital_elements->ephemeris_data, tsince, &output);
			break;
		case EPHEMERIS_SGP4:
			sgp4_predict((struct _sgp4*)orbital_elements->ephemeris_data, tsince, &output);
			break;
		default:
			//Panic!
			return -1;
	}
	m->position[0] = output.pos[0];
	m->position[1] = output.pos[1];
	m->position[2] = output.pos[2];
	m->velocity[0] = output.vel[0];
	m->velocity[1] = output.vel[1];
	m->velocity[2] = output.vel[2];
	m->phase = output.phase;
	m->argument_of_perigee = output.omgadf;
	m->inclination = output.xinck;
	m->right_ascension = output.xnodek;

	/* TODO: Remove? Scale position and velocity vectors to km and km/sec */
	Convert_Sat_State(m->position, m->velocity);

	/* Calculate satellite Lat North, Lon East and Alt. */
	geodetic_t sat_geodetic;
	Calculate_LatLonAlt(utc, m->position, &sat_geodetic);

	m->latitude = sat_geodetic.lat;
	m->longitude = sat_geodetic.lon;
	m->altitude = sat_geodetic.alt;

	// Calculate solar position
	double solar_vector[3];
	sun_predict(m->time, solar_vector);

	// Find eclipse depth and if sat is eclipsed
	m->eclipsed = is_eclipsed(m->position, solar_vector, &m->eclipse_depth);

	// Calculate footprint
	m->footprint = 2.0*xkmper*acos(xkmper/(xkmper + m->altitude));
	
	// Calculate current number of revolutions around Earth
	double temp = twopi/xmnpda/xmnpda;
	double age = julTime - jul_epoch;
	double xno = orbital_elements->mean_motion*temp*xmnpda;
	double xmo = orbital_elements->mean_anomaly * M_PI / 180.0;
	m->revolutions = (long)floor((xno*xmnpda/(M_PI*2.0) + age*orbital_elements->bstar_drag_term)*age + xmo/(2.0*M_PI)) + orbital_elements->revolutions_at_epoch;

	//calculate whether orbit is decayed
	m->decayed = predict_decayed(orbital_elements, utc);

	return 0;
}