Skip to content

Instantly share code, notes, and snippets.

@goooseman
Created October 12, 2023 09:44
Show Gist options
  • Save goooseman/2e948e1387f0022c1334b042cf644cc0 to your computer and use it in GitHub Desktop.
Save goooseman/2e948e1387f0022c1334b042cf644cc0 to your computer and use it in GitHub Desktop.
Script to convert OpenTX logs to "Telemetry Overlay" format
#!/usr/bin/env python
import sys
import pandas as pd
def convert_csv(input_csv):
# Read the original CSV file
df = pd.read_csv(input_csv)
# Rename columns
column_mapping = {
'Ptch(dB)': 'pitch angle (rad)',
'Roll(dB)': 'roll angle (rad)',
'Yaw(dB)': 'yaw angle (rad)',
'Dist(s k)': 'home distance (m)',
'Sats': 'sats',
'RFMD': 'RFMD',
'TRSS()': 'TRSS',
'TQly( f)': 'TQly',
'RxBt( V)': 'RxBt (v)',
'Curr( A)': 'Curr (a)',
'Capa(t)': 'Capa (t)',
'Alt(s k)': 'alt (m)',
'GSpd(cm/)': 'speed (km/h)',
'Thr': 'rc throttle',
'Rud': 'rc rudder',
'Ele': 'rc elevator',
'Ail': 'rc aileron'
}
df.rename(columns=column_mapping, inplace=True)
# Extract and format lat and lon
df[['lat (deg)', 'lon (deg)']] = df['GPS'].str.split(' ', expand=True)
df['lat (deg)'] = df['lat (deg)'].apply(lambda x: float(x))
df['lon (deg)'] = df['lon (deg)'].apply(lambda x: float(x))
# Format date
# Old time difference: 08:37:00 - 08:57:34 = 0:20:34 = -1234 seconds
df['date'] = pd.to_datetime(df['Date'] + ' ' + df['Time']) - pd.to_timedelta(1234, unit='s') + pd.to_timedelta(2, unit='h') + pd.to_timedelta(18077, unit='s')
# Format date to string
df['date'] = df['date'].dt.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
# Keep only the desired columns
columns_to_keep = ['date', 'lat (deg)', 'lon (deg)', 'alt (m)', 'speed (km/h)', 'pitch angle (rad)',
'roll angle (rad)', 'yaw angle (rad)', 'rc throttle', 'rc rudder', 'rc elevator', 'rc aileron',
'home distance (m)', 'sats', 'RFMD', 'TRSS', 'TQly', 'RxBt (v)', 'Curr (a)', 'Capa (t)']
df = df[columns_to_keep]
# Write the modified DataFrame to a new CSV file
output_csv = input_csv.replace('.csv', '-toverlay.csv')
df.to_csv(output_csv, index=False, sep=',', decimal='.')
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py input.csv")
sys.exit(1)
input_csv = sys.argv[1]
convert_csv(input_csv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment