Ejemplo n.º 1
0
def test2():
    """ Example of use of the Fox Sink dongle
    """

    # instanciate dongle
    foxdongle = fox_dongle.FoxDongle()

    print 'Enter acquisition loop (type ^C to stop and save tmp_imu.csv).'

    init = False
    while True:
        try:
            # handle dongle initialization
            if not init and foxdongle.init_dongle(test_acq_callback):
                init = True
                print 'Device is connected to %s.' % (foxdongle.line())

            time.sleep(5)
        except KeyboardInterrupt:
            print "\nStopped and Record in tmp_imu.csv."

            resp = fox.save_foxsignals_csvfile(foxdongle.data[:, 1],
                                               foxdongle.data[:, 2:5],\
                                               foxdongle.data[:, 5:8],\
                                               foxdongle.data[:, 8:11],
                                               "tmp_imu.csv")
            break
        except Exception as e:
            logging.error('exception reached:' + str(e))

    # must close to kill read thread (fox_sink)
    foxdongle.close_dongle()

    print 'Done'
Ejemplo n.º 2
0
def close(fdongle):
    from sensbiotk.io import iofox as fox
    print "\nStopped and Record in tmp_imu.csv."
    if fdongle.data != [] :
        resp = fox.save_foxsignals_csvfile(fdongle.data[:, 1], 
                                           fdongle.data[:, 2:5],
                                           fdongle.data[:, 5:8],
                                           fdongle.data[:, 8:11],
                                           "tmp_imu.csv")
    fdongle.close_dongle()
    return
Ejemplo n.º 3
0
def test_save():
    """ Test saving functions
    """

    # save imutest_acc with load_foxacc_csvfile
    [time, acc] = fox.load_foxacc_csvfile("data/imutest_acc.csv")
    resp = fox.save_foxacc_csvfile("tmpdata/imutest_acc_save.csv", time, acc)
    yield assert_equal, resp, "OK"

    [time1, acc1] = fox.load_foxacc_csvfile("tmpdata/imutest_acc_save.csv")
    yield assert_array_almost_equal, time, time1
    yield assert_array_almost_equal, acc, acc1

    # save imutest_mag with load_foxmag_csvfile
    [time, mag] = fox.load_foxmag_csvfile("data/imutest_mag.csv")
    resp = fox.save_foxmag_csvfile("tmpdata/imutest_mag_save.csv", time, mag)
    yield assert_equal, resp, "OK"

    [time1, mag1] = fox.load_foxmag_csvfile("tmpdata/imutest_mag_save.csv")
    yield assert_array_almost_equal, time, time1
    yield assert_array_almost_equal, mag, mag1

    # save imutest_gyr with load_foxgyr_csvfile
    [time, gyr] = fox.load_foxgyr_csvfile("data/imutest_gyr.csv")
    resp = fox.save_foxgyr_csvfile("tmpdata/imutest_gyr_save.csv", time, gyr)
    yield assert_equal, resp, "OK"

    [time1, gyr1] = fox.load_foxgyr_csvfile("tmpdata/imutest_gyr_save.csv")
    yield assert_array_almost_equal, time, time1
    yield assert_array_almost_equal, gyr, gyr1

    #  save_foxsignals_csvfile
    [time, acc, mag,
     gyr] = fox.load_foximu_csvfile("data/imutest_acc.csv",
                                    "data/imutest_mag.csv",
                                    "data/imutest_gyr.csv", 0.06, 1)

    resp = fox.save_foxsignals_csvfile(time, acc, mag, gyr,
                                       "tmpdata/imutest.csv")
    yield assert_equal, resp, "OK"
Ejemplo n.º 4
0
def main(argv):
    """ Main command
    """
    options = []
    filename = ""
    try:
        opts, _ = getopt.getopt(argv, "i:d:b:vt:f:pamgh", [
            "input=", "dir=", "basename", "verif", "time=", "frequency=",
            "plot", "acc", "mag", "gyr", "help"
        ])

    except getopt.GetoptError:
        usage()
        sys.exit(2)

    period = 0.005
    diroutput = "."
    newbasename = ""
    filenames = ""

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-i", "--input"):
            fnames = arg
            if not os.path.isfile(fnames):
                if not os.path.isdir(fnames):
                    print "error: input file/dir does not exist"
                    usage()
                    sys.exit(2)
                else:
                    # directory input specified
                    filenames = os.listdir(fnames)
                    idx = 0
                    for onefile in filenames:
                        filenames[idx] = fnames + "/" + onefile
                        #filenames[idx] = fnames + "/" + filenames[idx]
                        idx = idx + 1
            else:
                # filename input specified
                filenames = [fnames]
        elif opt in ("-d", "--dir"):
            diroutput = arg
        elif opt in ("-b", "--basename"):
            newbasename = arg
        elif opt in ("-v", "--verif"):
            options.append("-v")
        elif opt in ("-t", "--time"):
            try:
                period = float(arg)
            except ValueError:
                usage()
                sys.exit(2)
            if period <= 0:
                usage()
                sys.exit(2)
        elif opt in ("-f", "--frequency"):
            try:
                period = float(arg)
            except ValueError:
                usage()
                sys.exit(2)
            if period <= 0:
                usage()
                sys.exit(2)
            else:
                period = 1 / period
        elif opt in ("-p", "--plot"):
            options.append("-p")
        elif opt in ("-a", "--acc"):
            options.append("-a")
        elif opt in ("-m", "--mag"):
            options.append("-m")
        elif opt in ("-g", "--gyr"):
            options.append("-g")

    if len(filenames) == 0:
        usage()
        sys.exit(2)

    for filename in filenames:
        print "Conversion:", filename
        # Get names file
        basefile, fileacc, filemag, filegyr, fileimu =\
            getnamefiles(filename, newbasename, diroutput)
        # Read and convert file
        answer = iofox.convert_sensors_rawfile(filename, fileacc, filemag,
                                               filegyr)
        if answer != "OK":
            usage()
            sys.exit(2)
        # Load ascii files converted
        [myt, acc, mag, gyr] = \
            iofox.load_foximu_csvfile(fileacc, filemag, filegyr, period, 1)
        iofox.save_foxsignals_csvfile(myt, acc, mag, gyr, *fileimu)
        # Plot if necessary
        if "-p" in options:
            label = basefile + " IMU"
            viz.plot_imu(-1, label, myt, acc, mag, gyr)
        if "-a" in options:
            label = basefile + " Acc"
            plotsig(myt, acc, label, "ACC (m/s^2")
        if "-m" in options:
            label = basefile + " Mag"
            plotsig(myt, mag, label, "MAG (gauss)")
        if "-g" in options:
            label = basefile + " Gyr"
            plotsig(myt, gyr, label, "GYR (rad/s)")
        if "-v" in options:
            [myt, acc] = iofox.load_foxacc_csvfile(fileacc)
            label = basefile + " time verif."
            veriftime(label, myt[:, 0])
        # Clean temp files
        os.remove(fileacc)
        os.remove(filemag)
        os.remove(filegyr)

    plt.show()
            if not os.path.exists(DATA):
                os.makedirs(DATA)
            if not os.path.exists(DATAExpe):
                os.makedirs(DATAExpe)
            FILEACC = DATA + "/" + BASEFILE + "_acc.csv"
            FILEMAG = DATA + "/" + BASEFILE + "_mag.csv"
            FILEGYR = DATA + "/" + BASEFILE + "_gyr.csv"
            FILEPRESST = DATA + "/" + BASEFILE + "_presst.csv"
            FILEGPIO = DATA + "/" + BASEFILE + "_gpio.csv"
            ANS = iofox.convert_sensors_rawfile(str(onefile), FILEACC, FILEMAG,
                                                FILEGYR, FILEPRESST, FILEGPIO)
            if ANS == "OK":
                [TIME, ACC, MAG, GYR] = \
                    iofox.load_foximu_csvfile(
                    FILEACC, FILEMAG, FILEGYR, 1 / float(fs), 1)
                iofox.save_foxsignals_csvfile(TIME, ACC, MAG, GYR,
                                              DATA + "/" + BASEFILE + '.csv')
                if os.path.isfile(DATA + "/" + BASEFILE + '_gpio.csv'):
                    shutil.copy(DATA + "/" + BASEFILE + '_gpio.csv', DATAExpe)
                else:
                    shutil.copy(DATA + "/" + BASEFILE + '.csv', DATAExpe)
                os.remove(FILEACC)
                os.remove(FILEMAG)
                os.remove(FILEGYR)
                print "\n=>>> Successfully converted RAW file at Fs = " +\
                    str(fs) + "Hz to : " + HOME + "/ImuConvertedData/" + "\n"
                print str(file) + ' => ' + BASEFILE
                fileNumber = fileNumber + 1
            else:
                print "       Conversion failed"