/** * Initialise the gps module * \return -1 if initialisation failed * \return 0 on success */ int32_t GPSInitialize(void) { gpsPort = PIOS_COM_GPS; uint8_t gpsProtocol; #ifdef MODULE_GPS_BUILTIN module_enabled = true; #else uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM]; ModuleSettingsAdminStateGet(module_state); if (module_state[MODULESETTINGS_ADMINSTATE_GPS] == MODULESETTINGS_ADMINSTATE_ENABLED) { module_enabled = true; } else { module_enabled = false; } #endif // These things are only conditional on small F1 targets. // Expected to be always present otherwise. #ifdef SMALLF1 if (gpsPort && module_enabled) { #endif GPSPositionInitialize(); GPSVelocityInitialize(); #if !defined(PIOS_GPS_MINIMAL) GPSTimeInitialize(); GPSSatellitesInitialize(); HomeLocationInitialize(); UBloxInfoInitialize(); #endif #if defined(PIOS_GPS_PROVIDES_AIRSPEED) AirspeedActualInitialize(); #endif updateSettings(); #ifdef SMALLF1 } #endif if (gpsPort && module_enabled) { ModuleSettingsGPSDataProtocolGet(&gpsProtocol); switch (gpsProtocol) { case MODULESETTINGS_GPSDATAPROTOCOL_NMEA: gps_rx_buffer = PIOS_malloc(NMEA_MAX_PACKET_LENGTH); break; case MODULESETTINGS_GPSDATAPROTOCOL_UBX: gps_rx_buffer = PIOS_malloc(sizeof(struct UBXPacket)); break; default: gps_rx_buffer = NULL; } PIOS_Assert(gps_rx_buffer); return 0; } return -1; }
/** * Initialise the module. Called before the start function * \returns 0 on success or -1 if initialisation failed */ int32_t SensorsInitialize(void) { accel_bias[0] = rand_gauss() / 10; accel_bias[1] = rand_gauss() / 10; accel_bias[2] = rand_gauss() / 10; AccelsInitialize(); AttitudeSimulatedInitialize(); BaroAltitudeInitialize(); BaroAirspeedInitialize(); GyrosInitialize(); GyrosBiasInitialize(); GPSPositionInitialize(); GPSVelocityInitialize(); MagnetometerInitialize(); MagBiasInitialize(); return 0; }
/** * Initialise the gps module * \return -1 if initialisation failed * \return 0 on success */ int32_t GPSInitialize(void) { gpsPort = PIOS_COM_GPS; uint8_t gpsProtocol; #ifdef MODULE_GPS_BUILTIN module_enabled = true; #else uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM]; ModuleSettingsAdminStateGet(module_state); if (module_state[MODULESETTINGS_ADMINSTATE_GPS] == MODULESETTINGS_ADMINSTATE_ENABLED) { module_enabled = true; } else { module_enabled = false; } #endif #if defined(REVOLUTION) // These objects MUST be initialized for Revolution // because the rest of the system expects to just // attach to their queues GPSPositionInitialize(); GPSVelocityInitialize(); GPSTimeInitialize(); GPSSatellitesInitialize(); HomeLocationInitialize(); UBloxInfoInitialize(); updateSettings(); #else if (gpsPort && module_enabled) { GPSPositionInitialize(); GPSVelocityInitialize(); #if !defined(PIOS_GPS_MINIMAL) GPSTimeInitialize(); GPSSatellitesInitialize(); #endif #if defined(PIOS_GPS_PROVIDES_AIRSPEED) AirspeedActualInitialize(); #endif updateSettings(); } #endif if (gpsPort && module_enabled) { ModuleSettingsGPSDataProtocolGet(&gpsProtocol); switch (gpsProtocol) { case MODULESETTINGS_GPSDATAPROTOCOL_NMEA: gps_rx_buffer = pvPortMalloc(NMEA_MAX_PACKET_LENGTH); break; case MODULESETTINGS_GPSDATAPROTOCOL_UBX: gps_rx_buffer = pvPortMalloc(sizeof(struct UBXPacket)); break; default: gps_rx_buffer = NULL; } PIOS_Assert(gps_rx_buffer); return 0; } return -1; }