Exemplo n.º 1
0
/** Assemble an NMEA GPVTG message and send it out NMEA USARTs.
 * NMEA VTG contains course and speed
 *
 * \param soln Pointer to gnss_solution struct
 */
void nmea_gpvtg(const gnss_solution *soln)
{
  /* NMEA Parameters for GPVTG
   * Ex.
   * $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K
   *    |     |   |    |  |   |   |   |   |
   * Command  |  'T'   | 'M'  |  'N'  |  'K'
   *     True Course   |  Speed (K)   |
   *               Mag. course     Speed (km/hr)
   */

  float vknots, vkmhr;
  float x,y,z;
  x = soln->vel_ned[0];
  y = soln->vel_ned[1];
  z = soln->vel_ned[2];
  float course = atan2(y,x);

  /* Conversion to magnitue knots */
  vknots = MS2KNOTTS(x,y,z);
  /* Conversion to magnitue km/hr */
  vkmhr = MS2KMHR(x,y,z);

  NMEA_SENTENCE_START(120);
  NMEA_SENTENCE_PRINTF(
                  "$GPVTG,%05.1f,T," /* Command, course, */
                  ",M," /* Magnetic Course (omitted) */
                  "%06.2f,N,%06.2f,K", /* Speed (knots, km/hr) */
                  course* R2D,
                  vknots, vkmhr);
  NMEA_SENTENCE_DONE();
}
Exemplo n.º 2
0
/** Assemble an NMEA GPRMC message and send it out NMEA USARTs.
 * NMEA RMC contains minimum GPS data 
 *
 * \param nav_meas Pointer to navigation_measurement struct.
 * \param soln Pointer to gnss_solution struct
 * \param gps_t Pointer to the current GPS Time
 */
void nmea_gprmc(const navigation_measurement_t *nav_meas,
                const gnss_solution *soln, const gps_time_t *gps_t)
{
  
  /* NMEA Parameters
   * Ex.
   * $GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
   *   |      |    |    |    |    |     |   |      |      |     |  |  |
   * Command  |    |   Lat  N/S   |     |   |      | Date Stamp | W/E |
   *    Time (UTC) |            Long   W/E  |  True Course      |   Cksum
   *            Validity (A-OK)           Speed            Variation 
   * Variation is ignored as we have no way to maintain that information
   * currently
   */
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);
  double frac_s = fmod(gps_t->tow, 1.0);

  s16 lat_deg = R2D * (soln->pos_llh[0]);
  double lat_min = MINUTES(soln->pos_llh[0]);
  s16 lon_deg = R2D * (soln->pos_llh[1]);
  double lon_min = MINUTES(soln->pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = soln->pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = soln->pos_llh[1] < 0 ? 'W' : 'E';

  float velocity;
  float x,y,z;
  x = soln->vel_ned[0];
  y = soln->vel_ned[1];
  z = soln->vel_ned[2];
  float course = atan2(y,x);

  /* Conversion to magnitue knots */
  velocity = MS2KNOTTS(x,y,z);

  double az, el;
  wgsecef2azel(nav_meas[0].sat_pos, soln->pos_ecef, &az, &el);

  char buf[100];
  u8 n = sprintf(buf,
                "$GPRMC,%02d%02d%06.3f,A," /* Command, Time (UTC), Valid */
                "%02d%010.7f,%c,%03d%010.7f,%c," /* Lat/Lon */
                "%06.2f,%05.1f," /* Speed, Course */
                "%02d%02d%02d," /* Date Stamp */
                ",", /* Variation */
                t.tm_hour, t.tm_min, t.tm_sec + frac_s,
                lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                velocity, course * R2D, 
                t.tm_mday, t.tm_mon, t.tm_year-100);

  u8 sum = nmea_checksum(buf);
  sprintf(buf + n, "*%02X\r\n", sum);
  nmea_output(buf);
}
Exemplo n.º 3
0
/** Assemble an NMEA GPRMC message and send it out NMEA USARTs.
 * NMEA RMC contains minimum GPS data 
 *
 * \param soln Pointer to gnss_solution struct
 * \param gps_t Pointer to the current GPS Time
 */
void nmea_gprmc(const gnss_solution *soln, const gps_time_t *gps_t)
{
  
  /* NMEA Parameters
   * Ex.
   * $GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
   *   |      |    |    |    |    |     |   |      |      |     |  |  |
   * Command  |    |   Lat  N/S   |     |   |      | Date Stamp | W/E |
   *    Time (UTC) |            Long   W/E  |  True Course      |   Cksum
   *            Validity (A-OK)           Speed            Variation 
   * Variation is ignored as we have no way to maintain that information
   * currently
   */
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);
  double frac_s = fmod(gps_t->tow, 1.0);

  s16 lat_deg = R2D * (soln->pos_llh[0]);
  double lat_min = MINUTES(soln->pos_llh[0]);
  s16 lon_deg = R2D * (soln->pos_llh[1]);
  double lon_min = MINUTES(soln->pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = soln->pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = soln->pos_llh[1] < 0 ? 'W' : 'E';

  float velocity;
  float x,y,z;
  x = soln->vel_ned[0];
  y = soln->vel_ned[1];
  z = soln->vel_ned[2];
  float course = atan2(y,x);

  /* Conversion to magnitue knots */
  velocity = MS2KNOTTS(x,y,z);

  NMEA_SENTENCE_START(140);
  NMEA_SENTENCE_PRINTF(
                "$GPRMC,%02d%02d%06.3f,A," /* Command, Time (UTC), Valid */
                "%02d%010.7f,%c,%03d%010.7f,%c," /* Lat/Lon */
                "%06.2f,%05.1f," /* Speed, Course */
                "%02d%02d%02d," /* Date Stamp */
                ",", /* Variation */
                t.tm_hour, t.tm_min, t.tm_sec + frac_s,
                lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                velocity, course * R2D, 
                t.tm_mday, t.tm_mon + 1, t.tm_year % 100);
  NMEA_SENTENCE_DONE();
}
Exemplo n.º 4
0
/** Assemble an NMEA GPVTG message and send it out NMEA USARTs.
 * NMEA VTG contains course and speed
 *
 * \param nav_meas Pointer to navigation_measurement struct.
 * \param soln Pointer to gnss_solution struct
 */
void nmea_gpvtg(const navigation_measurement_t *nav_meas,
                const gnss_solution *soln)
{
  /* NMEA Parameters for GPVTG
   * Ex.
   * $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K
   *    |     |   |    |  |   |   |   |   |
   * Command  |  'T'   | 'M'  |  'N'  |  'K'
   *     True Course   |  Speed (K)   |
   *               Mag. course     Speed (km/hr)
   */

  double az, el;
  wgsecef2azel(nav_meas[0].sat_pos, soln->pos_ecef, &az, &el);

  float vknots, vkmhr;
  float x,y,z;
  x = soln->vel_ned[0];
  y = soln->vel_ned[1];
  z = soln->vel_ned[2];
  float course = atan2(y,x);

  /* Conversion to magnitue knots */
  vknots = MS2KNOTTS(x,y,z);
  /* Conversion to magnitue km/hr */
  vkmhr = MS2KMHR(x,y,z);

  char buf[80];
  u8 n = sprintf(buf, 
                  "$GPVTG,%05.1f,T," /* Command, course, */
                  ",M," /* Magnetic Course (omitted) */
                  "%06.2f,N,%06.2f,K", /* Speed (knots, km/hr) */
                  course* R2D,
                  vknots, vkmhr);
  
  u8 sum = nmea_checksum(buf);
  sprintf(buf + n, "*%02X\r\n", sum);
  nmea_output(buf);
}