Exemple #1
0
void altitude_test(double altitude, uint32_t pressure) {
  double test_altitude = pressure_to_altitude(pressure);

  if (test_altitude > altitude - MAX_ERROR &&
      test_altitude < altitude + MAX_ERROR) { // Success
    printf("%dPa = %gm (Expected %gm)\n", pressure, test_altitude, altitude);
  } else { // Fail
    printf("\nERROR:\n");
    printf("%dPa = %gm (Expected %gm)\n", pressure, test_altitude, altitude);
    exit(1);
  }
}
void
QmlBarometerAltimeterReading::set_sea_level_pressure(qreal sea_level_pressure)
{
  qInfo() << "set_sea_level_pressure" << sea_level_pressure << m_sea_level_pressure;
  if (!qFuzzyCompare(sea_level_pressure, m_sea_level_pressure)) {
    qInfo() << "set_sea_level_pressure yes";
    m_sea_level_pressure = sea_level_pressure;
    Q_EMIT pressureSeaLevelChanged();
    m_altitude = pressure_to_altitude(m_pressure);
    Q_EMIT altitudeChanged(); // versus readingUpdate ?
  }
}
void
QmlBarometerAltimeterReading::readingUpdate()
{
  qreal pressure = m_sensor->reading()->pressure();
  if (m_pressure != pressure) {
    m_pressure = pressure;
    Q_EMIT pressureChanged();
    m_altitude = pressure_to_altitude(pressure);
    Q_EMIT altitudeChanged();
  }

  qreal temperature = m_sensor->reading()->temperature();
  if (m_temperature != temperature) {
    m_temperature = temperature;
    Q_EMIT temperatureChanged();
  }
}
Exemple #4
0
/**
 * Main system entry point
 */
int main (void) {
  SystemInit();

  /* Initialise Pins */
  CUTDOWN_OFF();
  HEATER_OFF();
  MBED_OFF();
  GREEN_OFF();

  /* Update the value of SystemCoreClock */
  SystemCoreClockUpdate();

  /* Initialise Interfaces */
  i2c_init();
  spi_init(process_imu_frame); // IMU
  sd_spi_init(); // SD
  uart_init(); // GPS
  pwrmon_init(); // ADC

  /* Initialise Sensors */
  init_barometer();

  /* SD Card */
  if (initialise_card()) { // Initialised to something
    if (disk_initialize() == 0) { // Disk initialisation was successful
      sd_good = 1;
    }
  }

  GREEN_ON();

  /* Configure the SysTick */
  NVIC_SetPriority(SysTick_IRQn, 0); // Highest Priority Interrupt
  SysTick_Config(SystemCoreClock / RTTY_BAUD);

  /* Watchdog - Disabled for debugging */
#ifndef WATCHDOG_DISABLED
  init_watchdog();
#endif

  struct barometer* b;
  struct imu_raw ir;
  struct gps_data gd;
  struct gps_time gt;
  double alt, ext_temp;
  int tx_length; // The length of the built tx string

  char tx_string[TX_STRING_LENGTH];

  while (1) {
    /* Grab Data */
    pwrmon_start(pwrmon_callback);
    b = get_barometer();
    get_imu_raw_data(&ir);
    get_gps_data(&gd);
    get_gps_time(&gt);
    ext_temp = get_temperature();

    /* Data Processing */
    if (b->valid) {
      alt = pressure_to_altitude(b->pressure);
    } else {
      alt = -1;
      b->temperature = -1;
    }

    /* Act on the data */
    control_gsm(alt);
    control_cutdown(ticks_until_cutdown, alt);
    control_heater(b->temperature);

    /* Create a protocol string */
    int cutstat;
    if (ticks_until_cutdown == 0) {
      cutstat = -1;
    } else {
      cutstat = ticks_until_cutdown / (RTTY_BAUD*60);
    }
    tx_length = build_communications_frame(tx_string, TX_STRING_LENGTH,
					   &gt, b, &gd, alt, ext_temp, &ir,
					   cutstat,  cutdown_voltage);

    /* Transmit - Quietly fails if another transmission is ongoing */
    rtty_set_string(tx_string, tx_length);

    /* Store */
    if (sd_good) {
      tx_length -= 2; // Remove \n\0
      tx_length += communications_frame_add_extra(tx_string + tx_length,
				     TX_STRING_LENGTH - tx_length, &ir);

      disk_write_next_block((uint8_t*)tx_string, tx_length+1); // Include null terminator
    }

    /* Housekeeping */
    GREEN_TOGGLE();
    feed_watchdog();
  }
}
Exemple #5
0
void pressure_sensor(unsigned pressure)
{
	double kPa = pressure_from_sensor(pressure);
	double altitude = pressure_to_altitude(kPa * 1000);
	printf("pressure\t%f\t%f\n", time, altitude);
}