Skip to content

Commit 2bee229

Browse files
committed
Vibration Example Added Again
1 parent 8bdb131 commit 2bee229

File tree

22 files changed

+1515
-0
lines changed

22 files changed

+1515
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Fan Vibration Monitoring
2+
3+
The **Fan Vibration Monitoring** example creates a smart vibration detector that monitors a fan (or any vibrating machinery) for anomalies. It visualizes raw accelerometer data in real-time and allows users to dynamically adjust the anomaly detection sensitivity through a web dashboard.
4+
5+
![Fan Vibration Monitoring](assets/docs_assets/vibration-anomaly.png)
6+
7+
## Description
8+
9+
Monitor the physical status of a fan in real-time. This example uses a Modulino Movement to capture acceleration data and a dedicated Brick to detect vibration anomalies.
10+
11+
Unlike simple threshold detectors, this app provides:
12+
* **Live Data Visualization:** A real-time scrolling plot of X, Y, and Z acceleration.
13+
* **Dynamic Sensitivity:** A slider to adjust the anomaly scoring threshold on the fly.
14+
* **History:** A log of the most recent detected anomalies with timestamps.
15+
16+
## Bricks Used
17+
18+
The example uses the following Bricks:
19+
20+
- `web_ui`: Brick to create a web interface to display the dashboard.
21+
- `vibration_anomaly_detection`: Brick that processes accelerometer data to detect irregular vibration patterns.
22+
23+
## Hardware and Software Requirements
24+
25+
### Hardware
26+
27+
- Arduino UNO Q (x1)
28+
- Modulino Movement (LSM6DSOX) (x1)
29+
- Qwiic Cable (x1)
30+
- USB-C® to USB-A Cable (x1)
31+
32+
### Software
33+
34+
- Arduino App Lab
35+
36+
**Note:** You can run this example using your Arduino UNO Q as a Single Board Computer (SBC) using a [USB-C hub](https://store.arduino.cc/products/usb-c-to-hdmi-multiport-adapter-with-ethernet-and-usb-hub) with a mouse, keyboard, and monitor attached.
37+
38+
## How to Use the Example
39+
40+
1. Connect the Modulino Movement sensor to the Arduino UNO Q via the Qwiic connector.
41+
2. Run the App.
42+
3. Open the App on your browser.
43+
4. Observe the **Accelerometer Data** chart to see the live vibration waveforms.
44+
5. Use the **Set anomaly score** slider to adjust how sensitive the detector is. Lower values make it more sensitive; higher values require stronger vibrations to trigger an alert.
45+
6. Shake the sensor or attach it to a fan to simulate an anomaly. The "Feedback" section will show a warning, and the event will be logged in "Recent Anomalies".
46+
47+
## How it Works
48+
49+
Here is a brief explanation of the full-stack application:
50+
51+
### 🔧 Backend (main.py)
52+
53+
- Initializes the `vibration_anomaly_detection` Brick.
54+
- Receives raw sensor data via `Bridge`, converts it from gravity units ($g$) to acceleration ($m/s^2$), and forwards it to the UI for plotting.
55+
- Accumulates samples in the detection Brick.
56+
- Listens for threshold overrides from the UI to update the detection sensitivity in real-time.
57+
- Broadcasts anomaly alerts containing the anomaly score and timestamp.
58+
59+
### 💻 Frontend (index.html + app.js)
60+
61+
- **Real-time Plotting:** Uses an HTML5 Canvas to draw the live X, Y, Z acceleration waveforms.
62+
- **Interactive Controls:** Sends slider values to the backend to tune the algorithm parameters.
63+
- **Alert System:** visualizes anomalies with status icons and maintains a chronological list of recent detections.
64+
65+
## Understanding the Code
66+
67+
Once the application is running, you can access it from your web browser. At that point, the device begins performing the following:
68+
69+
- **Reading sensor data on the MCU (Arduino sketch).**
70+
71+
The firmware reads the Modulino Movement sensor every 16ms. It sends the X, Y, and Z values to the Python backend using `Bridge.notify`.
72+
73+
```cpp
74+
void loop() {
75+
// ... timing logic (16ms interval) ...
76+
77+
// Read new movement data from the sensor
78+
has_movement = movement.update();
79+
80+
if(has_movement == 1) {
81+
// Get acceleration values
82+
x_accel = movement.getX();
83+
y_accel = movement.getY();
84+
z_accel = movement.getZ();
85+
86+
// Send data to Python
87+
Bridge.notify("record_sensor_movement", x_accel, y_accel, z_accel);
88+
}
89+
}
90+
```
91+
92+
- **Processing data and updating the UI (Python).**
93+
94+
The backend serves as the central hub. It receives the raw data, converts the units for the algorithm, feeds the detector, and simultaneously pushes the data to the frontend for the live plot.
95+
96+
```python
97+
def record_sensor_movement(x: float, y: float, z: float):
98+
try:
99+
# Convert g -> m/s^2 for the detector
100+
x_ms2 = x * 9.81
101+
y_ms2 = y * 9.81
102+
z_ms2 = z * 9.81
103+
104+
# Forward raw data to UI for plotting
105+
ui.send_message('sample', {'x': x_ms2, 'y': y_ms2, 'z': z_ms2})
106+
107+
# Forward samples to the vibration_detection Brick
108+
vibration_detection.accumulate_samples((x_ms2, y_ms2, z_ms2))
109+
110+
except Exception as e:
111+
logger.exception(f"record_sensor_movement: Error: {e}")
112+
```
113+
114+
- **Handling Dynamic Thresholds.**
115+
116+
When you move the slider in the browser, the frontend emits an event. The backend updates the detection brick's sensitivity immediately.
117+
118+
```python
119+
def on_override_th(value: float):
120+
logger.info(f"Setting new anomaly threshold: {value}")
121+
vibration_detection.anomaly_detection_threshold = value
122+
```
123+
124+
- **Visualizing the Data (JavaScript).**
125+
126+
The frontend receives the `sample` event and pushes it into an array. The `drawPlot` function clears the canvas and redraws the lines for X, Y, and Z to create the scrolling chart effect.
127+
128+
```javascript
129+
function drawPlot() {
130+
if (!hasDataFromBackend) return;
131+
132+
// Clear the canvas before drawing the new frame
133+
ctx.clearRect(0, 0, currentWidth, currentHeight);
134+
135+
// ... grid drawing code ...
136+
137+
// Draw series (X, Y, Z)
138+
drawSeries('x','#0068C9');
139+
drawSeries('y','#FF9900');
140+
drawSeries('z','#FF2B2B');
141+
}
142+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: Fan Vibration Monitoring
2+
icon: 🌀
3+
description: Monitor fan vibrations and detect anomalies
4+
5+
bricks:
6+
- arduino:web_ui
7+
- arduino:vibration_anomaly_detection

0 commit comments

Comments
 (0)