-
Notifications
You must be signed in to change notification settings - Fork 1
docs(mobile): add comprehensive beacon localization documentation #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,359 @@ | ||||||||||||||||||||||||||
| # Beacon-Based Localization Calibration Guide | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| This guide provides step-by-step instructions for calibrating the RSSI-based indoor positioning system in your specific environment. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Overview | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The localization algorithm uses two key parameters that affect accuracy: | ||||||||||||||||||||||||||
| 1. **TxPower**: Reference transmitted power at 1 meter (default: -59 dBm) | ||||||||||||||||||||||||||
| 2. **Path Loss Exponent (n)**: Environment-specific signal propagation factor (default: 2.0) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| For best results, these should be calibrated for your specific building and environment. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Quick Start: TxPower Calibration | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| TxPower calibration is the easiest and fastest way to improve accuracy. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Step 1: Prepare Equipment | ||||||||||||||||||||||||||
| - Navign mobile app (with localization enabled) | ||||||||||||||||||||||||||
| - Tape measure or laser rangefinder (accuracy to 0.5m) | ||||||||||||||||||||||||||
| - At least 3 calibration points per beacon | ||||||||||||||||||||||||||
| - Notebook to record measurements | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Step 2: Select Calibration Beacons | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Choose 2-3 beacons in different areas of your facility: | ||||||||||||||||||||||||||
| - One in an open area (hallway/corridor) | ||||||||||||||||||||||||||
| - One in a constrained area (office, stairwell) | ||||||||||||||||||||||||||
| - One with potential obstacles (near metal, water) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Step 3: Record RSSI at Known Distances | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| For each beacon: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. **Close distance (1-2 meters)** | ||||||||||||||||||||||||||
| - Stand 1 meter from beacon | ||||||||||||||||||||||||||
| - Record app RSSI reading (average of 5 readings) | ||||||||||||||||||||||||||
| - Stand 2 meters from beacon | ||||||||||||||||||||||||||
| - Record RSSI reading | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 2. **Medium distance (5-10 meters)** | ||||||||||||||||||||||||||
| - Stand 5 meters from beacon | ||||||||||||||||||||||||||
| - Record RSSI reading | ||||||||||||||||||||||||||
| - Stand 10 meters from beacon (if space allows) | ||||||||||||||||||||||||||
| - Record RSSI reading | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 3. **Far distance (20-30 meters)** | ||||||||||||||||||||||||||
| - Stand 20 meters from beacon | ||||||||||||||||||||||||||
| - Record RSSI reading | ||||||||||||||||||||||||||
| - Stand 30 meters if possible | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Example table: | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| Beacon A (Hallway): | ||||||||||||||||||||||||||
| Distance (m) | RSSI (dBm) | Notes | ||||||||||||||||||||||||||
| 1.0 | -58 | Clear line of sight | ||||||||||||||||||||||||||
| 2.0 | -62 | Clear line of sight | ||||||||||||||||||||||||||
| 5.0 | -72 | Clear line of sight | ||||||||||||||||||||||||||
| 10.0 | -82 | Clear line of sight | ||||||||||||||||||||||||||
| 20.0 | -92 | Clear line of sight | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Step 4: Calculate Reference TxPower | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| For each distance measurement: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| TxPower = RSSI + 20 * n * log10(distance) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Where: | ||||||||||||||||||||||||||
| - RSSI = measured signal strength (negative, e.g., -58) | ||||||||||||||||||||||||||
| - n = 2.0 (use default for now) | ||||||||||||||||||||||||||
| - distance = meters from beacon | ||||||||||||||||||||||||||
| - log10 = logarithm base 10 | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| **Example calculation:** | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| At 1 meter with RSSI -58: | ||||||||||||||||||||||||||
| TxPower = -58 + 20 * 2.0 * log10(1) | ||||||||||||||||||||||||||
| TxPower = -58 + 20 * 2.0 * 0 | ||||||||||||||||||||||||||
| TxPower = -58 dBm | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| At 10 meters with RSSI -82: | ||||||||||||||||||||||||||
| TxPower = -82 + 20 * 2.0 * log10(10) | ||||||||||||||||||||||||||
| TxPower = -82 + 20 * 2.0 * 1.0 | ||||||||||||||||||||||||||
| TxPower = -82 + 40 | ||||||||||||||||||||||||||
| TxPower = -42 dBm (this seems off - indicates environment effect) | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
Comment on lines
+83
to
+88
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Step 5: Update TxPower Value | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| If your calculated TxPower differs significantly from -59 dBm: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. Open `mobile/src-tauri/src/locate/locator.rs` | ||||||||||||||||||||||||||
| 2. Find the `rssi_to_distance()` function | ||||||||||||||||||||||||||
| 3. Update the TxPower value: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```rust | ||||||||||||||||||||||||||
| fn rssi_to_distance(mut rssi: f64) -> f64 { | ||||||||||||||||||||||||||
| let tx_power = -59.0; // ← Change this value | ||||||||||||||||||||||||||
| // ... rest of function | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| For example, if your calculations average to -55 dBm: | ||||||||||||||||||||||||||
| ```rust | ||||||||||||||||||||||||||
| let tx_power = -55.0; // Adjusted for your environment | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 4. Rebuild the mobile app: | ||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||
| cd mobile | ||||||||||||||||||||||||||
| pnpm run tauri build | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Step 6: Validate Improvements | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Repeat your measurements with the updated TxPower: | ||||||||||||||||||||||||||
| - Positions should now be more accurate | ||||||||||||||||||||||||||
| - Distance estimates should match your measurements better | ||||||||||||||||||||||||||
| - Document the improvement for your records | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Advanced: Path Loss Exponent Calibration | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| If TxPower calibration alone doesn't achieve desired accuracy, calibrate the path loss exponent `n`. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Theory | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The path loss exponent depends on environment: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Environment | n Value | Notes | | ||||||||||||||||||||||||||
| |-------------|---------|-------| | ||||||||||||||||||||||||||
| | Free space (outdoor) | 2.0 | Ideal, rarely occurs indoors | | ||||||||||||||||||||||||||
| | Open hallway | 2.0-2.3 | Clean line of sight, few obstacles | | ||||||||||||||||||||||||||
| | Typical office | 2.5-3.0 | Some walls, furniture | | ||||||||||||||||||||||||||
| | Dense environment | 3.0-3.5 | Many obstacles, people | | ||||||||||||||||||||||||||
| | Metal/water heavy | 3.5-4.5+ | Severe signal degradation | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Measurement Procedure | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. **Collect distance-RSSI pairs** (minimum 8-10 pairs across different distances) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Example data: | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| Distance (m) | RSSI (dBm) | ||||||||||||||||||||||||||
| 1.0 | -59 | ||||||||||||||||||||||||||
| 2.0 | -65 | ||||||||||||||||||||||||||
| 5.0 | -73 | ||||||||||||||||||||||||||
| 10.0 | -83 | ||||||||||||||||||||||||||
| 15.0 | -89 | ||||||||||||||||||||||||||
| 20.0 | -95 | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 2. **Use regression analysis** to find optimal `n`: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The path loss formula rearranges to: | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| RSSI = TxPower - 20*n*log10(distance) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Which is linear: `RSSI = a - b*log10(distance)` where `b = 20*n` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Using linear regression (or spreadsheet): | ||||||||||||||||||||||||||
| - Plot distance vs RSSI | ||||||||||||||||||||||||||
| - Fit a line | ||||||||||||||||||||||||||
| - Calculate: `n = b / 20` where `b` is the slope magnitude | ||||||||||||||||||||||||||
|
Comment on lines
+161
to
+166
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Using a Spreadsheet | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| In Excel/Google Sheets: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. Create columns: | ||||||||||||||||||||||||||
| - A: Distance (meters) | ||||||||||||||||||||||||||
| - B: RSSI (dBm) | ||||||||||||||||||||||||||
| - C: log10(Distance) = LOG10(A1) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 2. Use LINEST or SLOPE function: | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
| slope = SLOPE(B:B, C:C) | ||||||||||||||||||||||||||
| n = slope / 20 | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 3. Example with sample data: | ||||||||||||||||||||||||||
| - slope = -40.3 | ||||||||||||||||||||||||||
| - n = 40.3 / 20 = 2.015 ≈ 2.0 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+177
to
+186
|
||||||||||||||||||||||||||
| If your n value differs from 2.0: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```rust | ||||||||||||||||||||||||||
| fn rssi_to_distance(mut rssi: f64) -> f64 { | ||||||||||||||||||||||||||
| let tx_power = -59.0; | ||||||||||||||||||||||||||
| if rssi > 0f64 { | ||||||||||||||||||||||||||
| rssi = -rssi; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| let n = 2.0; // ← Update this value, e.g., 2.5, 3.0, etc. | ||||||||||||||||||||||||||
| 10f64.powf((tx_power - rssi) / (10.0 * n)) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Performance Validation | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| After calibration, measure accuracy in real-world conditions: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Test Method 1: Fixed Position Accuracy | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. Stand at 10 known locations across your facility | ||||||||||||||||||||||||||
| 2. Let the app localize for 10 seconds each (averaging multiple readings) | ||||||||||||||||||||||||||
| 3. Record calculated position and actual position | ||||||||||||||||||||||||||
| 4. Calculate error distance: `√((x_calc - x_actual)² + (y_calc - y_actual)²)` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| **Target metrics:** | ||||||||||||||||||||||||||
| - Open space: ±1.5m (90% of measurements) | ||||||||||||||||||||||||||
| - Typical office: ±2.5m (90% of measurements) | ||||||||||||||||||||||||||
| - Dense areas: ±4m (90% of measurements) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Test Method 2: Tracking Accuracy | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. Walk a known path (straight line, grid pattern) | ||||||||||||||||||||||||||
| 2. Record GPS-like position trace from app | ||||||||||||||||||||||||||
| 3. Compare against actual path | ||||||||||||||||||||||||||
| 4. Calculate deviation from expected route | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| **Target metric:** Path deviation < 2m from actual route in typical areas | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Troubleshooting | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Problem: Positions are consistently too far from beacon | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| **Cause:** TxPower value is too high (too positive) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| **Solution:** | ||||||||||||||||||||||||||
| - Decrease TxPower value (e.g., -59 → -62) | ||||||||||||||||||||||||||
| - This makes the algorithm think signals are weaker than they are | ||||||||||||||||||||||||||
| - Results in smaller distance estimates | ||||||||||||||||||||||||||
|
Comment on lines
+229
to
+234
|
||||||||||||||||||||||||||
| **Cause:** TxPower value is too high (too positive) | |
| **Solution:** | |
| - Decrease TxPower value (e.g., -59 → -62) | |
| - This makes the algorithm think signals are weaker than they are | |
| - Results in smaller distance estimates | |
| **Cause:** TxPower value is too high (less negative than it should be) | |
| **Solution:** | |
| - Decrease TxPower value (e.g., -59 → -62) | |
| - This makes the reference TxPower more negative (lower power in dBm) | |
| - For the same RSSI, this results in smaller distance estimates |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous troubleshooting entry, this explanation has contradictory language:
"Cause: TxPower value is too low (too negative)
Solution: Increase TxPower value (e.g., -59 → -56)"
The cause says "too low (too negative)" but in dBm terms, -59 is actually a HIGHER power level than -62, even though it's less negative numerically. The solution correctly shows -59 → -56 (making it less negative/higher power), but the phrasing "too low (too negative)" could confuse users.
Suggest rephrasing for clarity:
"Cause: TxPower value is too negative (lower power than actual)
Solution: Increase TxPower value (make it less negative, e.g., -59 → -56)"
| **Cause:** TxPower value is too low (too negative) | |
| **Solution:** | |
| - Increase TxPower value (e.g., -59 → -56) | |
| - This increases distance estimates | |
| **Cause:** TxPower value is too negative (lower power than actual) | |
| **Solution:** | |
| - Increase TxPower value (make it less negative, e.g., -59 → -56) | |
| - This makes the algorithm assume stronger signal at 1 m, increasing inferred distances so positions are less clustered near the beacon |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test example references an undefined distance function and TOLERANCE constant. While this is documentation code (not meant to compile), it could be improved for clarity by either:
- Showing the implementation of these helpers:
fn distance(p1: (f64, f64), p2: (f64, f64)) -> f64 {
((p1.0 - p2.0).powi(2) + (p1.1 - p2.1).powi(2)).sqrt()
}
const TOLERANCE: f64 = 2.0; // meters- Or using inline calculations instead of helper functions:
let error = ((expected.0 - actual.0).powi(2) +
(expected.1 - actual.1).powi(2)).sqrt();
assert!(error < 2.0); // within 2 metersThis would make the example more self-contained and educational.
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference link for "IEEE Wireless Propagation Model" points to the generic IEEE 802 homepage (https://www.ieee802.org/), which doesn't directly provide information about wireless propagation models.
Consider updating this to a more specific resource, such as:
- IEEE 802.11 TGn Channel Models document
- A specific IEEE paper on indoor propagation
- An alternative educational resource that explains path loss models
Alternatively, if the intent is just to reference IEEE as an organization, the text should be updated to reflect that this is a general reference rather than a specific propagation model document.
| - Multipath Fading: [IEEE Wireless Propagation Model](https://www.ieee802.org/) | |
| - Multipath Fading: [Multipath Propagation (Wikipedia)](https://en.wikipedia.org/wiki/Multipath_propagation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formula for calculating TxPower is incorrect. The documentation states:
TxPower = RSSI + 20 * n * log10(distance)However, this is inconsistent with the path loss model used in the code. The correct formula should be:
TxPower = RSSI + 10 * n * log10(distance)This can be verified by rearranging the distance formula in rssi_to_distance():
The factor should be 10n, not 20n. Using 20*n will result in incorrect calibration values.