Exemplo n.º 1
0
def test1():
    """ Test1
    """
    from sensbiotk.io import iofox_deprec as fox
    from sensbiotk.io import viz

    print "Test Calibration"
    [time, acc, mag, gyr] = fox.load_foximu_csvfile(FILETEST)
    viz.plot_imu(0, "calib", time[:, 1], acc, mag, gyr)

    acc_motionless = acc[5500:7500]
    gyr_motionless = gyr[5500:7500]
    mag_motion = mag[8000:18000]

    scale, offset = calib_acc.compute_simple(acc_motionless)
    print "Acc"
    print "Scale=", scale
    print "Offset=", offset

    scale, offset = calib_mag.compute(mag_motion)
    print "Mag"
    print "Scale=", scale
    print "Offset=", offset

    scale, offset = calib_gyr.compute(gyr_motionless)
    print "Gyr"
    print "Scale=", scale
    print "Offset=", offset

    viz.plot_show()

    return
Exemplo n.º 2
0
def test0():
    """ Test 0
    """
    filein = DIR + "HIGPS00.RAW"
    fileout = DIR + "imu00.csv"
    fileoutp = DIR + "presst00.csv"

    fox.convert_fox_rawfile(filein, fileout, fileoutp)
    [time, acc_imu, mag_imu, gyr_imu] = fox.load_foximu_csvfile(fileout)
    time_imu = time[:, 1]
    viz.plot_imu(1, "FOX IMU sensors", time_imu, acc_imu, mag_imu, gyr_imu)
Exemplo n.º 3
0
def visu_running():
    """  plotting of a running
    """
    # Fichier ascii de donnees FOX
    filename = "./data/imu11.csv"

    # Read IMU data
    [time, acc_imu, mag_imu, gyr_imu] = fox.load_foximu_csvfile(filename)
    # Split data
    time_imu = time[:, 1]

    viz.plot_imu(1, "FOX IMU sensors", time_imu, acc_imu, mag_imu, gyr_imu)
    viz.plot_show()
    return
Exemplo n.º 4
0
def imu_door_norm(filename):
    """ Visualize the IMU signals, compute their norms,
    and give the extremun magnetometers norm

    Parameters
    ----------
    filename : filename IMU door to be analyzed
    time_i   : begin time of the extremun research
    time_f   : end time of the extremun research

    Returns
    -------
     [data
    """

    # Read IMU data
    [time, acc_imu, mag_imu, gyr_imu] = fox.load_foximu_csvfile(filename)
    time_imu = time[:, 1]
    # Sensors norm
    acc_norm = np.sqrt(np.sum(acc_imu[:, i]**2 for i in range(0, 3)))
    mag_norm = np.sqrt(np.sum(mag_imu[:, i]**2 for i in range(0, 3)))
    gyr_norm = np.sqrt(np.sum(gyr_imu[:, i]**2 for i in range(0, 3)))

    viz.plot_imu(1, "FOX IMU sensors", time_imu, acc_imu, mag_imu, gyr_imu)

    plt.figure(2)
    plt.subplot(311)
    plt.plot(time_imu, acc_norm)
    plt.title("FOX IMU norm signals sensors")
    plt.legend(('x', 'y', 'z'),
               bbox_to_anchor=(0, 1, 1, 0),
               ncol=2,
               loc=3,
               borderaxespad=0.)
    plt.ylabel('ACC (m/s^2)')
    plt.subplot(312)
    plt.plot(time_imu, mag_norm)
    plt.ylabel('MAG (gauss)')
    plt.subplot(313)
    plt.plot(time_imu, gyr_norm)
    plt.ylabel('GYR (rad/s)')
    plt.xlabel('time (s)')

    plt.figure(3)
    plt.title("FOX IMU samples verification")
    plt.plot(time_imu[1:], time[1:, 2])

    return [time_imu, acc_norm, mag_norm, gyr_norm]
Exemplo n.º 5
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()