コード例 #1
0
ファイル: track_data.py プロジェクト: cpn18/track-chart
def json_to_dict_mileage(data_file, known_file):
    if os.path.exists(data_file + ".pickle"):
        return pickle_to_dict_mileage(data_file + ".pickle")

    gyroXangle = gyroYangle = gyroZangle = CFangleX = CFangleY = CFangleZ = 0
    last_time = None
    for line_no, obj in pirail.read(data_file):
        if obj['class'] != "ATT":
            continue
        if 'roll' in obj and 'yaw' in obj and 'pitch' in obj:
            mileage = obj['mileage']
            mileageToData[mileage] = acceleration_gyroscopic_data(
                obj['acc_x'], obj['acc_y'], obj['acc_z'], obj['roll'],
                obj['pitch'], obj['yaw'])
            continue

        if last_time is not None:
            DT = (pirail.parse_time(obj['time']) -
                  pirail.parse_time(last_time)).total_seconds()
            last_time = obj['time']
        else:
            DT = 0

        # Calculate Yaw/Pitch/Roll
        # Based on:
        # https://github.com/ozzmaker/BerryIMU/blob/master/python-BerryIMU-gryo-accel-compass/berryIMU-simple.py
        gyroXangle += obj['gyro_x'] * DT
        gyroYangle += obj['gyro_y'] * DT
        gyroZangle += obj['gyro_z'] * DT
        AccXangle = math.degrees(
            (float)(math.atan2(obj['acc_y'], obj['acc_z']) + math.pi))
        AccYangle = math.degrees(
            (float)(math.atan2(obj['acc_z'], obj['acc_x']) + math.pi))
        AccZangle = math.degrees(
            (float)(math.atan2(obj['acc_y'], obj['acc_x']) + math.pi))
        # Complementary Filter
        CFangleX = AA * (CFangleX + obj['gyro_x'] * DT) + (1 - AA) * AccXangle
        CFangleY = AA * (CFangleY + obj['gyro_y'] * DT) + (1 - AA) * AccYangle
        CFangleZ = AA * (CFangleZ + obj['gyro_z'] * DT) + (1 - AA) * AccZangle

        if 'mileage' not in obj:
            if 'lat' in obj and 'lon' in obj:
                obj['mileage'], obj['certainty'] = gps_to_mileage.Gps2Miles(
                    known_file).find_mileage(obj['lat'], obj['lon'])
        mileageToData[obj['mileage']] = acceleration_gyroscopic_data(
            AccXangle, AccYangle, AccZangle, CFangleY, CFangleX, CFangleZ)

    with open(data_file + ".pickle", "wb") as f:
        pickle.dump(mileageToData, f, pickle.HIGHEST_PROTOCOL)
    return mileageToData
コード例 #2
0
ファイル: track_data.py プロジェクト: cpn18/track-chart
def get_maxAll(track: dict):
    list_x = []
    list_y = []
    list_z = []
    list_roll = []
    list_pitch = []
    list_yaw = []

    for data_point in track.values():
        list_x.append(data_point.get_accX())
        list_y.append(data_point.get_accY())
        list_z.append(data_point.get_accZ())
        list_roll.append(data_point.get_roll())
        list_pitch.append(data_point.get_pitch())
        list_yaw.append(data_point.get_yaw())

    sd_x = max(list_x)
    sd_y = max(list_y)
    sd_z = max(list_z)
    sd_roll = max(list_roll)
    sd_pitch = max(list_pitch)
    sd_yaw = max(list_yaw)

    return acceleration_gyroscopic_data(sd_x, sd_y, sd_z, sd_roll, sd_pitch,
                                        sd_yaw)
コード例 #3
0
ファイル: track_data.py プロジェクト: cpn18/track-chart
def calc_standard_deviation_all(track: dict):
    list_x = []
    list_y = []
    list_z = []
    list_roll = []
    list_pitch = []
    list_yaw = []

    for data_point in track.values():
        list_x.append(data_point.get_accX())
        list_y.append(data_point.get_accY())
        list_z.append(data_point.get_accZ())
        list_roll.append(data_point.get_roll())
        list_pitch.append(data_point.get_pitch())
        list_yaw.append(data_point.get_yaw())

    sd_x = statistics.stdev(list_x)
    sd_y = statistics.stdev(list_y)
    sd_z = statistics.stdev(list_z)
    sd_roll = statistics.stdev(list_roll)
    sd_pitch = statistics.stdev(list_pitch)
    sd_yaw = statistics.stdev(list_yaw)

    return acceleration_gyroscopic_data(sd_x, sd_y, sd_z, sd_roll, sd_pitch,
                                        sd_yaw)
コード例 #4
0
ファイル: track_data.py プロジェクト: cpn18/track-chart
def calc_average_acceleration_gyro(track: dict):
    average_accX = average_accY = average_accZ = average_roll = average_pitch = average_yaw = 0
    n = len(track.values())

    for data_point in track.values():
        average_accX += data_point.get_accX()
        average_accY += data_point.get_accY()
        average_accZ += data_point.get_accZ()
        average_roll += data_point.get_roll()
        average_pitch += data_point.get_pitch()
        average_yaw += data_point.get_yaw()

    return acceleration_gyroscopic_data(average_accX / n, average_accY / n,
                                        average_accZ / n, average_roll / n,
                                        average_pitch / n, average_yaw / n)