|
@@ -23,9 +23,15 @@ acc_x_history = deque(maxlen=graph_length)
|
|
|
acc_y_history = deque(maxlen=graph_length)
|
|
acc_y_history = deque(maxlen=graph_length)
|
|
|
acc_z_history = deque(maxlen=graph_length)
|
|
acc_z_history = deque(maxlen=graph_length)
|
|
|
|
|
|
|
|
|
|
+# New values
|
|
|
|
|
+gyro_mag_history = deque(maxlen=graph_length)
|
|
|
|
|
+accel_mag_history = deque(maxlen=graph_length)
|
|
|
|
|
+pitch_history = deque(maxlen=graph_length)
|
|
|
|
|
+roll_history = deque(maxlen=graph_length)
|
|
|
|
|
+temp_history = deque(maxlen=graph_length)
|
|
|
|
|
|
|
|
# Set up the display
|
|
# Set up the display
|
|
|
-width, height = 1000, 550
|
|
|
|
|
|
|
+width, height = 1000, 750
|
|
|
screen = pygame.display.set_mode((width, height))
|
|
screen = pygame.display.set_mode((width, height))
|
|
|
pygame.display.set_caption("MPU BLE Visualizer")
|
|
pygame.display.set_caption("MPU BLE Visualizer")
|
|
|
|
|
|
|
@@ -89,31 +95,39 @@ while running:
|
|
|
data = dobluetooth.getDataArr()
|
|
data = dobluetooth.getDataArr()
|
|
|
high_force : bool = False
|
|
high_force : bool = False
|
|
|
|
|
|
|
|
- if len(data) >= 6:
|
|
|
|
|
- # Accelerometer values
|
|
|
|
|
|
|
+ if len(data) >= 11:
|
|
|
|
|
+ rotX, rotY, rotZ = data[0:3]
|
|
|
accX, accY, accZ = data[3:6]
|
|
accX, accY, accZ = data[3:6]
|
|
|
|
|
+ gyroMag, accelMag = data[6:8]
|
|
|
|
|
+ pitch, roll, temp = data[8:11]
|
|
|
|
|
+
|
|
|
|
|
+ # Add to history
|
|
|
|
|
+ gyro_x_history.append(rotX)
|
|
|
|
|
+ gyro_y_history.append(rotY)
|
|
|
|
|
+ gyro_z_history.append(rotZ)
|
|
|
acc_x_history.append(accX)
|
|
acc_x_history.append(accX)
|
|
|
acc_y_history.append(accY)
|
|
acc_y_history.append(accY)
|
|
|
acc_z_history.append(accZ)
|
|
acc_z_history.append(accZ)
|
|
|
|
|
+ gyro_mag_history.append(gyroMag)
|
|
|
|
|
+ accel_mag_history.append(accelMag)
|
|
|
|
|
+ pitch_history.append(pitch)
|
|
|
|
|
+ roll_history.append(roll)
|
|
|
|
|
+ temp_history.append(temp)
|
|
|
|
|
|
|
|
- acc_magnitude = math.sqrt(accX**2 + accY**2 + accZ**2)
|
|
|
|
|
-
|
|
|
|
|
- if acc_magnitude > HIGH_FORCE_THRESHOLD:
|
|
|
|
|
|
|
+ if accelMag> HIGH_FORCE_THRESHOLD:
|
|
|
high_force = True
|
|
high_force = True
|
|
|
|
|
|
|
|
- rotX, rotY, rotZ = data[0:3]
|
|
|
|
|
- gyro_magnitude = math.sqrt(rotX**2 + rotY**2 + rotZ**2)
|
|
|
|
|
-
|
|
|
|
|
- if gyro_magnitude < 10:
|
|
|
|
|
|
|
+ if gyroMag < 10:
|
|
|
gyro_condition = "🟢 Stable"
|
|
gyro_condition = "🟢 Stable"
|
|
|
gyro_color = (0, 200, 0)
|
|
gyro_color = (0, 200, 0)
|
|
|
- elif gyro_magnitude < 75:
|
|
|
|
|
|
|
+ elif gyroMag < 75:
|
|
|
gyro_condition = "🟡 Moving"
|
|
gyro_condition = "🟡 Moving"
|
|
|
gyro_color = (255, 200, 0)
|
|
gyro_color = (255, 200, 0)
|
|
|
else:
|
|
else:
|
|
|
gyro_condition = "🔴 High Rotation"
|
|
gyro_condition = "🔴 High Rotation"
|
|
|
gyro_color = (255, 50, 50)
|
|
gyro_color = (255, 50, 50)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
# Create the font surface
|
|
# Create the font surface
|
|
|
gyro_status_surface = warning_font.render(f"Gyro Status: {gyro_condition}", True, gyro_color)
|
|
gyro_status_surface = warning_font.render(f"Gyro Status: {gyro_condition}", True, gyro_color)
|
|
|
|
|
|
|
@@ -123,12 +137,6 @@ while running:
|
|
|
# Blit it to the screen
|
|
# Blit it to the screen
|
|
|
screen.blit(gyro_status_surface, gyro_status_rect)
|
|
screen.blit(gyro_status_surface, gyro_status_rect)
|
|
|
|
|
|
|
|
- # Add to history
|
|
|
|
|
- gyro_mag_history.append(gyro_magnitude)
|
|
|
|
|
- gyro_x_history.append(rotX)
|
|
|
|
|
- gyro_y_history.append(rotY)
|
|
|
|
|
- gyro_z_history.append(rotZ)
|
|
|
|
|
-
|
|
|
|
|
for i in range(6):
|
|
for i in range(6):
|
|
|
val = abs(data[i])
|
|
val = abs(data[i])
|
|
|
|
|
|
|
@@ -184,15 +192,32 @@ while running:
|
|
|
screen.blit(font.render("Gyro X/Y/Z (°/s)", True, (0, 0, 0)), (10, gyro_top - 15))
|
|
screen.blit(font.render("Gyro X/Y/Z (°/s)", True, (0, 0, 0)), (10, gyro_top - 15))
|
|
|
screen.blit(font.render("Accel X/Y/Z (g)", True, (0, 0, 0)), (10, accel_top - 15))
|
|
screen.blit(font.render("Accel X/Y/Z (g)", True, (0, 0, 0)), (10, accel_top - 15))
|
|
|
|
|
|
|
|
- # Gyroscope graph
|
|
|
|
|
- draw_graph(screen, gyro_x_history, (255, 0, 0), gyro_top, graph_height, height_scale=10)
|
|
|
|
|
- draw_graph(screen, gyro_y_history, (0, 255, 0), gyro_top, graph_height, height_scale=10)
|
|
|
|
|
- draw_graph(screen, gyro_z_history, (0, 0, 255), gyro_top, graph_height, height_scale=10)
|
|
|
|
|
|
|
+ # Pitch and Roll
|
|
|
|
|
+ pitch_top = accel_top + graph_spacing
|
|
|
|
|
+ screen.blit(font.render("Pitch / Roll (°)", True, (0, 0, 0)), (10, pitch_top - 15))
|
|
|
|
|
+
|
|
|
|
|
+ # Temp + Mags
|
|
|
|
|
+ mags_top = pitch_top + graph_spacing
|
|
|
|
|
+ screen.blit(font.render("Temp (°C), AccelMag (g), GyroMag (°/s)", True, (0, 0, 0)), (10, mags_top - 15))
|
|
|
|
|
+
|
|
|
|
|
+ # Gyroscope graph (°/s)
|
|
|
|
|
+ draw_graph(screen, gyro_x_history, (255, 0, 0), gyro_top, graph_height, height_scale=5)
|
|
|
|
|
+ draw_graph(screen, gyro_y_history, (0, 255, 0), gyro_top, graph_height, height_scale=5)
|
|
|
|
|
+ draw_graph(screen, gyro_z_history, (0, 0, 255), gyro_top, graph_height, height_scale=5)
|
|
|
|
|
+
|
|
|
|
|
+ # Accelerometer graph (g)
|
|
|
|
|
+ draw_graph(screen, acc_x_history, (255, 128, 0), accel_top, graph_height, height_scale=30)
|
|
|
|
|
+ draw_graph(screen, acc_y_history, (0, 200, 200), accel_top, graph_height, height_scale=30)
|
|
|
|
|
+ draw_graph(screen, acc_z_history, (128, 0, 255), accel_top, graph_height, height_scale=30)
|
|
|
|
|
+
|
|
|
|
|
+ # Pitch and Roll (°)
|
|
|
|
|
+ draw_graph(screen, pitch_history, (100, 100, 255), pitch_top, graph_height, height_scale=1.5)
|
|
|
|
|
+ draw_graph(screen, roll_history, (255, 100, 100), pitch_top, graph_height, height_scale=1.5)
|
|
|
|
|
|
|
|
- # Accelerometer graph
|
|
|
|
|
- draw_graph(screen, acc_x_history, (255, 128, 0), accel_top, graph_height, height_scale=25)
|
|
|
|
|
- draw_graph(screen, acc_y_history, (0, 200, 200), accel_top, graph_height, height_scale=25)
|
|
|
|
|
- draw_graph(screen, acc_z_history, (128, 0, 255), accel_top, graph_height, height_scale=25)
|
|
|
|
|
|
|
+ # Temp + Mags
|
|
|
|
|
+ draw_graph(screen, temp_history, (200, 0, 0), mags_top, graph_height, height_scale=3)
|
|
|
|
|
+ draw_graph(screen, accel_mag_history, (0, 150, 255), mags_top, graph_height, height_scale=30)
|
|
|
|
|
+ draw_graph(screen, gyro_mag_history, (100, 255, 100), mags_top, graph_height, height_scale=5)
|
|
|
|
|
|
|
|
pygame.display.flip()
|
|
pygame.display.flip()
|
|
|
clock.tick(60)
|
|
clock.tick(60)
|