7from test_ekf
import EKF
10def blend_angle(ekf, old_angle, new_angle, alpha):
11 diff = ekf.normalize_angle(new_angle - old_angle)
12 return ekf.normalize_angle(old_angle + alpha * diff)
15def latlon_toxy(lat, lon, lat0, lon0):
21 lat0 = np.radians(lat0)
22 lon0 = np.radians(lon0)
24 x = (lon - lon0) * R * np.cos(lat0)
30def tilt_compensated_yaw(accel, mag):
35 norm_a = np.sqrt(ax**2 + ay**2 + az**2)
36 norm_m = np.sqrt(mx**2 + my**2 + mz**2)
38 if norm_a < 1e-6
or norm_m < 1e-6:
46 pitch = np.arcsin(-ax)
47 roll = np.arctan2(ay, az)
50 mx_comp = mx * np.cos(pitch) + mz * np.sin(pitch)
51 my_comp = mx * np.sin(roll) * np.sin(pitch) + my * np.cos(roll) - mz * np.sin(roll) * np.cos(pitch)
54 yaw = np.arctan2(-my_comp, mx_comp)