Beispiel #1
0
def load_file(ulog_file_path, reload=True):
    """ Main function to load a Ulg file and create a Flight Object
    return : Flight object ( and saved or not  in a pkl file) 
    """
    if reload_file:
        # print("Reading Ulog file : " + str(ulog_file_name))

        mflight = Flight()

        mflight.add_data_file(ulog_file_path, Device.PIXRACER, Position.PILOT)
        mflight.add_info("Tulipe Glider", "Razor4", None, "Paul", 94.2,
                         "Nice Place")
        mflight.add_general_section()

        logger.info("Writing : " + name_saved_file)
        with open(name_saved_file, "wb") as f:
            pickle.dump(mflight, f)

    else:
        logger.info("Reading : " + name_saved_file)
        with open(name_saved_file, "rb") as f:
            mflight = pickle.load(f)

    # Print Data for debug.
    logger.debug(mflight)
    df_data = mflight.data[0].list_available_data()
    logger.debug(df_data)
    # df_data.loc[df_data['parent']=='vehicle_local_position']

    mdf = mflight.get_df_by_position(Position.PILOT)[0]
    logger.debug(mdf)
Beispiel #2
0
class import_log_diaglog(QDialog):
    def __init__(self, parent=None):
        super(import_log_diaglog, self).__init__(parent)

        self.ui = Ui_Dialog_import_log()
        self.ui.setupUi(self)

        self.flight = None

        populate_combo_box(self.ui.positionComboBox, Position)
        populate_combo_box(self.ui.positionComboBox_2, Position)

        populate_combo_box(self.ui.deviceComboBox, Device)
        populate_combo_box(self.ui.deviceComboBox_2, Device)

        populate_combo_box(self.ui.deviceComboBox_video_device, VideoDevice)

        self.ui.positionComboBox.setCurrentIndex(
            self.ui.positionComboBox.findText(
                Position.PILOT.name))  # to have pilot as default position
        self.ui.deviceComboBox.setCurrentIndex(
            self.ui.deviceComboBox.findText(
                Device.PIXRACER.name))  # to have pixracer as default position

        #set up button
        self.ui.button_debug.clicked.connect(self.debug_)
        self.ui.button_import.clicked.connect(self.import_flight)
        self.ui.pushButton_import_file_log1.clicked.connect(self.browse_path)

        self.check_valid()

        #set up line edit:
        self.ui.gliderModelLineEdit.textChanged.connect(self.check_valid)

        self.imported_Flight = None

    def debug_(self):
        """Quickly populate all flied for rapid debug
        """
        logger.debug("Populate with dummy values")
        file_name = "/home/fred/Ozone/paralogger/paralogger/samples/log_6_2019-11-6-13-32-36_flight_1.ulg"

        self.ui.label_file_log_1.setText(file_name)
        self.ui.gliderModelLineEdit.setText("Macpi4")
        self.ui.manufacturerLineEdit.setText("Exemple_gliders_ltd")
        self.ui.locationLineEdit.setText("niceplace")
        self.ui.gliderSizeLineEdit.setText("24")
        self.ui.pilotLineEdit.setText("Arnold")
        self.ui.weightKgDoubleSpinBox.setValue(95)
        self.ui.laboratoryLineEdit.setText("GoodLab")

    def update_label_status(self, str_message):
        self.ui.label_status.setText(str_message)
        QGuiApplication.processEvents()  # would be better to use a progressbar

    def browse_path(self):
        filename = QFileDialog.getOpenFileName(self, 'Open pickler File', "",
                                               'Logs Files (*.*)')

        if isinstance(filename, tuple):
            filename = filename[0]
        if filename:
            self.ui.label_file_log_1.setText(filename)

    def import_flight(self):
        """Create a Flight object, read the raw log file and add meta data .
        TODO mange if device != Pixracer 
        """

        self.update_label_status("Loading in progress, please wait  ...")
        self.update()

        logger.debug('import flight .......')

        self.imported_Flight = Flight()

        ulog_file_path = self.ui.label_file_log_1.text()
        ulog_device = self.ui.deviceComboBox.currentData()
        ulog_position = self.ui.positionComboBox.currentData()

        glider_name = self.ui.gliderModelLineEdit.text()
        manufacturer_name = self.ui.manufacturerLineEdit.text()
        modif = self.ui.gliderModifLineEdit.text()
        location = self.ui.locationLineEdit.text()
        size = self.ui.gliderSizeLineEdit.text()
        pilot = self.ui.pilotLineEdit.text()
        weight = self.ui.weightKgDoubleSpinBox.value()
        lab = self.ui.laboratoryLineEdit.text()

        self.imported_Flight.add_data_file(ulog_file_path, ulog_device,
                                           ulog_position)
        self.imported_Flight.add_info(manufacturer_name, glider_name, size,
                                      modif, pilot, weight, location, lab)
        self.imported_Flight.add_general_section()

        logger.debug("close import dialog")

        self.close()

    def check_valid(self):
        """Check if the  required field and ok  to enble the import.
        """
        check_list = []
        item_to_check = [self.ui.gliderModelLineEdit, self.ui.label_file_log_1]

        for item in item_to_check:
            check_list.append(len(item.text()) < 1)

        if not any(check_list):
            self.ui.button_import.setEnabled(True)
            self.ui.label_status.setText("Field with * are mandatory (OK)")
        else:
            self.ui.button_import.setEnabled(False)
Beispiel #3
0
log_name = "log_23_2019-9-29-15-15-10_heli_slow.ulg"
ulog_file_path = os.path.join(cwd, "samples", log_name)
Reload_file = True
gravity = 9.80665  # m·s-2

name_saved_file = "mflight_plot.pkl"

#%%  Prepare file
logger.info(" --- Start ----")

if Reload_file:
    # print("Reading Ulog file : " + str(ulog_file_name))

    mflight = Flight()

    mflight.add_data_file(ulog_file_path, Device.PIXRACER, Position.PILOT)
    mflight.add_info("Tulipe Glider", "Razor4", None, "Paul", 94.2,
                     "Nice Place")

    logger.info("Writing : " + name_saved_file)

    with open(name_saved_file, "wb") as f:
        pickle.dump(mflight, f)

else:
    logger.info("Reading : " + name_saved_file)
    with open(name_saved_file, "rb") as f:
        mflight = pickle.load(f)

# Print the input Dataframe.
print(mflight)