Created
February 11, 2023 15:57
-
-
Save saas-coder/1c54b8cbaa931d5c6b408c520f1a067a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy.fftpack import fft | |
| def vehicle_condition_detection(acc_info, g, h, h_prime, h_1, h_2, T): | |
| time = 0 | |
| vehicle_condition = "Unknown" | |
| while True: | |
| for t in range(len(acc_info)): | |
| Ax, Ay, Az = acc_info[t] | |
| theta_x = np.arctan(Ax/Az) | |
| theta_y = np.arctan(Ay/Az) | |
| A_x = g * np.sin(theta_x) | |
| A_y = g * np.sin(theta_y) | |
| if A_x > h or A_y > h: | |
| time = 0 | |
| vehicle_condition = "Moving" | |
| break | |
| else: | |
| A_z = Az - g * np.cos(theta_x) * np.cos(theta_y) | |
| f_k = np.abs(fft(A_z)) | |
| mean, variance = np.mean(f_k), np.var(f_k) | |
| if variance > h_prime: | |
| time = 0 | |
| vehicle_condition = "Moving" | |
| break | |
| elif np.all(np.abs(f_k - mean) < variance + h_1): | |
| time = 0 | |
| vehicle_condition = "EngineOff" | |
| break | |
| elif np.any(np.abs(f_k - mean) < h_2 * variance): | |
| time = time + 1 | |
| vehicle_condition = "Idle" | |
| if time > T: | |
| alarm_trigger() | |
| break | |
| return vehicle_condition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment