Compare commits

..

2 commits

Author SHA1 Message Date
Nicolas Rohrbeck
27cec19b80 Merge branch 'master' of ssh://forge.bexus.org/Seth/seth_tools 2025-09-23 14:08:46 +02:00
Nicolas Rohrbeck
9d2b5bd8d2 handles nan timestamps 2025-09-23 14:08:38 +02:00

View file

@ -163,16 +163,16 @@ def calculate_heading(mag, phi, theta):
mag_world = np.matmul(Rz(-phi), np.matmul(Ry(theta-np.pi), np.matmul(Rz(phi), mag))) mag_world = np.matmul(Rz(-phi), np.matmul(Ry(theta-np.pi), np.matmul(Rz(phi), mag)))
mag_world_psi = np.arctan2(mag_world[1], mag_world[0]) + declination # angle mag vector in wf, x axis in wf + delta because TN is delta left of the MN (=mag vector) mag_world_psi = np.arctan2(mag_world[1], mag_world[0]) + declination # angle mag vector in wf, x axis in wf + delta because TN is delta left of the MN (=mag vector)
if mag_world_psi <= 0: if mag_world_psi <= 0:
mag_world_psi = 2*np.pi + mag_world_psi # because compass counts clock-wise and atan2 counter CW mag_world_psi = abs(mag_world_psi) # because compass counts clock-wise and atan2 counter CW
else: else:
pass mag_world_psi = 2*np.pi - mag_world_psi
heading = mag_world_psi * 180/np.pi # heading in degrees (0deg = True North) heading = mag_world_psi * 180/np.pi # heading in degrees (0deg = True North)
return heading return heading
def calculate_ads(acc_raw, mag_raw): def calculate_ads(acc_raw, mag_raw):
acc, mag = calibrate_vectors(acc_raw, mag_raw) acc, mag = calibrate_vectors(acc_raw, mag_raw)
pitch = math.atan(acc[0]/acc[2]) pitch = math.atan(acc[0]/acc[2]) # math package returns in radians
roll = math.atan(acc[1]/acc[2]) roll = math.atan(acc[1]/acc[2])
phi = math.atan2(acc[1], acc[2]) phi = math.atan2(acc[1], acc[2])
g_length_xy = math.sqrt(acc[0]**2+acc[1]**2+acc[2]**2) g_length_xy = math.sqrt(acc[0]**2+acc[1]**2+acc[2]**2)
@ -254,12 +254,16 @@ def main(input):
pres.append(b[1]) # may only be two P lines in one interval pres.append(b[1]) # may only be two P lines in one interval
if l[:2] == 'H ': # One every 12s if l[:2] == 'H ': # One every 12s
ts = int(l.split()[1]) ts = l.split()[1]
if fp and fp.split('/')[-1] == "2025-08-14-longtime-23e.AHA" and ts > 1800000000: # timestamps wrong in this file if ts == 'nan':
time.append(ts)
else:
ts = int(ts)
if fp and fp.split('/')[-1] == "2025-08-14-longtime-23e.AHA" and ts != 'nan' and ts > 1800000000: # timestamps wrong in this file
ts -= 1963615744 ts -= 1963615744
if i < 2000 and ts >= 3718824668-1963615744: if i < 2000 and ts >= 3718824668-1963615744:
ts -= 12*3600 ts -= 12*3600
if fp and fp.split('/')[-1] == '2025-08-08-seth-17e.AHA' and ts > 1800000000: if fp and fp.split('/')[-1] == '2025-08-08-seth-17e.AHA' and ts != 'nan' and ts > 1800000000:
ts -= 2138848512 ts -= 2138848512
if i < 500 and ts > 3893525631-2138848512: if i < 500 and ts > 3893525631-2138848512:
ts -= 16404 ts -= 16404
@ -273,10 +277,10 @@ def main(input):
if sl == '0' or sl == '1': # only operate if slice numbers are correct if sl == '0' or sl == '1': # only operate if slice numbers are correct
dorn_temps.extend(hdorn(l)) dorn_temps.extend(hdorn(l))
if l[:8] == 'I2C-MAG ': if l[:8] == 'I2C-MAG ' and l.split()[1] == '19':
mag_raw = [float(num) for num in l.split()[2:]] mag_raw = [int(num) for num in l.split()[2:]]
if l[:8] == 'I2C-ACC ': if l[:8] == 'I2C-ACC ' and l.split()[1] == '19':
acc_raw = [float(num) for num in l.split()[2:]] acc_raw = [int(num) for num in l.split()[2:]]
if l[:4] == 'C64 ': if l[:4] == 'C64 ':
heading, roll, pitch = calculate_ads(acc_raw, mag_raw) heading, roll, pitch = calculate_ads(acc_raw, mag_raw)