Esempio n. 1
0
mesonhFiles = '/local/fseguin/nephelae_data/MesoNH02/bomex_hf.nc'

dtbase = NephelaeDataServer()
# dtbase.enable_periodic_save('output/database01.neph', timerTick=10.0)


def build_uav(uavId, navRef):
    uav = PprzMesonhUav(uavId, navRef, mesonhFiles, ['RCT', 'WT'])
    uav.add_sensor_observer(dtbase)
    uav.add_gps_observer(dtbase)
    return uav


interface = PprzSimulation(mesonhFiles, ['RCT', 'WT'],
                           build_uav_callback=build_uav)
interface.start()
# Has to be called after interface.start()
dtbase.set_navigation_frame(interface.navFrame)


def stop():
    if interface.running:
        print("Shutting down... ", end='')
        sys.stdout.flush()
        interface.stop()
        dtbase.disable_periodic_save()
        print("Complete.")


signal.signal(signal.SIGINT, lambda sig, fr: stop())
Esempio n. 2
0
    def configure_database(self):
        """TODO implement the replay"""

        database = None
        try:
            self.warmStart = self.config['allow_warm_start']
        except KeyError as e:
            warn("No warm start configuration specified. No warm start " +
                 "allowed byt default. Exception feedback : " + str(e))
            self.warmStart = False

        try:
            config = self.config['database']
        except KeyError:
            # No specific options were given to the database.
            # Leaving default behavior.
            if self.warmStart:
                raise RuntimeError("Warm start enable but no database " +
                                   "configuration was given. Aborting.")
            else:
                database = NephelaeDataServer()
                database.set_navigation_frame(self.localFrame)
                return database

        try:
            enableSave = config['enable_save']
        except KeyError:
            # No saving configuration
            enableSave = False
        try:
            filePath = config['filepath']
        except KeyError:
            filePath = None

        # This is safe (in python spec, x and y returns false if x is false
        # without trying to evaluate y)
        if self.warmStart and filePath is not None and os.path.exists(
                filePath):
            database = NephelaeDataServer.load(filePath)
            self.missionT0 = database.navFrame.position.t
            self.localFrame.position.t = self.missionT0
        else:
            database = NephelaeDataServer()
        database.set_navigation_frame(self.localFrame)

        if enableSave:
            if filePath is None:
                raise ValueError("Configuration file "+self.mainConfigPath+\
                    " asked for database saving but did not set a 'filepath' field.")
            try:
                timerTick = config['timer_tick']
            except KeyError:
                # Save database every 60.0 seconds if no tick given
                timerTick = 60.0
            try:
                force = config['overwrite_existing']
            except KeyError:
                # Don;t overwrite existing database by default
                force = False
            database.enable_periodic_save(filePath, timerTick, force)

        return database