Compare commits
461 Commits
sl-control
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b353a2ba29 | |||
| 329797d43c | |||
| 1ae600ead4 | |||
| e73674f161 | |||
| 972db16635 | |||
| 5250ce67ad | |||
| d2175bf7d0 | |||
| 2a13c3e18b | |||
| 3f0508815d | |||
| d9e7acfa0d | |||
| c02faf3ac2 | |||
| 61f241ae1d | |||
| 26e71d7a14 | |||
| 2fa097e3d6 | |||
| b830420efc | |||
| 9d6c72bd24 | |||
| 9b460e34db | |||
| c297d24a48 | |||
| 885a66f24b | |||
| fbc88f5c2a | |||
| 0122957b6b | |||
| 759277a7e0 | |||
| b1e8da4403 | |||
| dd8afb480f | |||
| 43fb3f1147 | |||
| 416a393134 | |||
| 60f500c206 | |||
| b1cd15327f | |||
| b72e435bf3 | |||
| 9cf98830c6 | |||
| a1233dbd04 | |||
| fa75c442a7 | |||
| fe84ff6039 | |||
| fda6ab99ff | |||
| 308be74330 | |||
| 19be6bbe11 | |||
| 5ef1f7e365 | |||
| bfca6d1d92 | |||
| f71dad5344 | |||
| 5e97676703 | |||
| 30b0f245e1 | |||
| 7db6158ada | |||
| f0d9fead74 | |||
| 811a2ccc5c | |||
| bb354336c3 | |||
| 6d047ca50c | |||
| f384cc4810 | |||
| 2560718b39 | |||
| e220797c07 | |||
| b5354e1ac0 | |||
| f59bc9931e | |||
| de4d1bbe3a | |||
| d235c414e0 | |||
| 62d7525df7 | |||
| 2b3f3584a9 | |||
| 7a100b2d14 | |||
| 37b646780d | |||
| 2d60aab79c | |||
| af982bb575 | |||
| 6d59baa30e | |||
| 1ec4d3fc58 | |||
|
|
c6cf64217d | ||
| 5906af542b | |||
| 4318589496 | |||
| 441c56b1d9 | |||
| 334ab9249c | |||
| 4affd6d0cb | |||
| fe979fdd1f | |||
| 9e8ea3c411 | |||
| d57c0bd51d | |||
| fdda6fe5ee | |||
| 3457919c7a | |||
| cfdd74a9dc | |||
| 4f3a30d871 | |||
| 7eb3f187e2 | |||
|
|
a50dbe7e56 | ||
| 6561e35fd6 | |||
| 4dc75c8a70 | |||
| 4d0a377cee | |||
| 06101371ff | |||
| cf0ceb4641 | |||
| ee16bae9fb | |||
| 70fa404437 | |||
| c11cbaf3e6 | |||
| d132b74df0 | |||
| 8985934f29 | |||
| 9ed678ca35 | |||
| 06db56103f | |||
| 05ba557dca | |||
| 0a2f336eb8 | |||
| 5e82878083 | |||
| 92c0628c62 | |||
| 56c59f60fe | |||
| 7f67fc6abe | |||
| ea5203b67d | |||
| 14c80dc33c | |||
| 7d2d41ba9f | |||
| b74307c58a | |||
|
|
9d2b19104f | ||
| 89f892e5ef | |||
|
|
289185e6cf | ||
| 4f81571dd3 | |||
|
|
d9b4b10b90 | ||
|
|
a96fd91ed7 | ||
|
|
bf8df6af8f | ||
| d8b25bad77 | |||
| b2c9f368f6 | |||
| a506989af6 | |||
| 1d87899270 | |||
| 0fcad75cb4 | |||
| 5aadf4b5c8 | |||
| 5f0affcd79 | |||
| 779f9d00e2 | |||
| 4c7fa938a5 | |||
| 45332f1a8b | |||
| af46b15391 | |||
| e1d605dba7 | |||
| c8c8794daa | |||
| b5862ef529 | |||
|
|
343e53081a | ||
| 602fbc6ab3 | |||
| 1fd935b87e | |||
| b6c6dbd838 | |||
|
|
26bf4ab8d3 | ||
| cb802ee76f | |||
| 0e8758e9e1 | |||
| 7785a16bff | |||
| 68568b2b66 | |||
| 38df5b4ebb | |||
| fea550c851 | |||
| 13b17a11e1 | |||
| 96d13052b4 | |||
| a01fa091d4 | |||
| 62aab7164e | |||
| 7e12dab4ae | |||
| 1e69337ffd | |||
| 82ad626a94 | |||
| 921eaba8b3 | |||
|
|
65e0009118 | ||
|
|
9b1f3ddaf0 | ||
| 837c42a00d | |||
| c0bb4f6276 | |||
| 2996d18ace | |||
| bb5eff1382 | |||
| 8b1d6483cf | |||
| 6c00d6a321 | |||
| 2460ba27c7 | |||
| 2367e08140 | |||
| f188997192 | |||
| 7e5f673f7d | |||
| be4966b01d | |||
|
|
82cc223fb8 | ||
| 5f03e4cbef | |||
|
|
587ca8a98e | ||
| 40b0917c33 | |||
| c76d5b0dd7 | |||
|
|
c62444cc0e | ||
|
|
dd13569413 | ||
| 816d165db4 | |||
| cbcae34b79 | |||
| 061189670a | |||
| 8fbe7c0033 | |||
| 15ff5acca7 | |||
| f2743198e5 | |||
| 6512c805be | |||
| 1da1d50171 | |||
| 6a8b6a679e | |||
| ddf8332cd7 | |||
| e9429e6177 | |||
| 2b06161cb4 | |||
| c1b82608d5 | |||
|
|
08bc23f6df | ||
| 5dac6337e6 | |||
|
|
4b8d1b2ff7 | ||
| 5556c06153 | |||
| 5a1290a8f9 | |||
| 7b75cdad1a | |||
| b09017c949 | |||
| 1726558a7a | |||
| 5a3f4d1df6 | |||
| b2f01b42f3 | |||
| a7eb2ba3e5 | |||
| 4035b4cfc3 | |||
|
|
7708c63698 | ||
| 131d85a0d3 | |||
| 44691742c8 | |||
|
|
814624045a | ||
| 929c9ecd74 | |||
| 8592361095 | |||
| 35440b7463 | |||
| d36b79371d | |||
| 3b0b9d0f16 | |||
| 4116232b27 | |||
| c7dcce18c2 | |||
| 8e03a209be | |||
|
|
a4879b6b3f | ||
| 2180b61440 | |||
| c2d9adad25 | |||
| 76668d8346 | |||
| d8e5490a0e | |||
| 6409360428 | |||
| 6c5ecc9e00 | |||
| df6b79d676 | |||
| 0dbd64a6f4 | |||
| 8e21201dd4 | |||
| 80e3b23aec | |||
| 36643dd652 | |||
| da6a17cdcb | |||
| cc3a65f4a4 | |||
| c68b751590 | |||
| 0fd6ea92b0 | |||
|
|
c249b2d74e | ||
| 59d164944d | |||
| 6e09d13dfc | |||
|
|
02217443ea | ||
| 14164089dc | |||
| 6d316514da | |||
| 2d97033539 | |||
| 71ec357c93 | |||
| cc0ffd1999 | |||
| 19a30a1c4f | |||
| f71fdae747 | |||
| 916ad36ad5 | |||
| fc43135144 | |||
| e67783f313 | |||
| 68b6410b24 | |||
| 5b7ee63d1e | |||
| 4f33e4e88d | |||
| 54bc2509c1 | |||
| b0a5041261 | |||
| 7141e12320 | |||
|
|
d5246fe3a8 | ||
| 7ad8c82da6 | |||
| b128e164e7 | |||
| e28f1549cb | |||
| dd4eabf218 | |||
|
|
3bb4b71cea | ||
| f14ce5c3ba | |||
| 2e2ed2d0a7 | |||
| 5b9e9dd412 | |||
| 706a67c0b7 | |||
| 8d58d5e34c | |||
| d3eca7bebc | |||
| 8d67d06857 | |||
| e5329391bc | |||
| 5d17b6c501 | |||
| b5acb32ee6 | |||
| bbfcd2a9d1 | |||
| 5add2cab51 | |||
| 892d0a2089 | |||
| 678fd221f5 | |||
|
|
f49e84b8bb | ||
| 48e9af60a9 | |||
| e4116dffc0 | |||
| b0c2b5564d | |||
| 1f4929b68c | |||
| d97fa5fab0 | |||
| a3d3ea1471 | |||
| e1248f92b9 | |||
| 6f3dd46285 | |||
| 5cea0812d5 | |||
|
|
49628bcc61 | ||
| 062c05cac0 | |||
| 767f377120 | |||
| 80ee9ece87 | |||
|
|
868b453777 | ||
| 83e3033abe | |||
| 5f6a13ccca | |||
| 4dc18201aa | |||
| 2dd03a245d | |||
| 340248a0d2 | |||
| 7a4930e8d2 | |||
| b986702aed | |||
| a4285b5ecd | |||
| d770cb99a3 | |||
| fabfd5e974 | |||
| 6d6909d9d9 | |||
| d79e38eb5b | |||
| 7b22141142 | |||
| 285178b2f9 | |||
| 56a48b4e25 | |||
| 8f0215d461 | |||
| f5877756d5 | |||
| 33036e2967 | |||
| 50d1ebbdcc | |||
| 60e16dc6ca | |||
| e66bcc2ab0 | |||
| 7379aa459c | |||
| dd459c0df7 | |||
| fd742f6890 | |||
| d7051fe854 | |||
| 6293d2ec60 | |||
| b178614e6e | |||
| e26301c7ca | |||
| c96c68a7c4 | |||
|
|
2e9fd6fa4c | ||
| 0c03060016 | |||
| 00e632ecbf | |||
| d421d63c6f | |||
| 02e9b15e6f | |||
| c25d63772a | |||
| b38f948844 | |||
| 3ecf334642 | |||
| 5a4150a2d0 | |||
| 270507ad49 | |||
| f47b01eff6 | |||
| 2ba8df17fd | |||
| fb93acee0a | |||
| 9027fa9e12 | |||
| 5e62e81a97 | |||
|
|
f4e4f184ef | ||
| dc525d652c | |||
| 569ac3fb35 | |||
| 8538fa2f9d | |||
| 381549b33f | |||
| 5c05874ed3 | |||
| 35e35a2997 | |||
| 9d36e1007d | |||
| 3ea19fbb99 | |||
| b9a6eaa3fa | |||
| 3d008ddbb7 | |||
| fac873c261 | |||
| 27a95dce0a | |||
| 1530104e22 | |||
| ab5dd97fcb | |||
| 41dc80ea7d | |||
| 292c73fb60 | |||
| c1076b8230 | |||
| 2d144f5bcc | |||
| 3830db8225 | |||
| 7cad97d0db | |||
|
|
bd46aa5bc3 | ||
| b950528079 | |||
| d657696840 | |||
| 27bf0efd94 | |||
| 3b10d77208 | |||
| 7c287e6f37 | |||
| 2203773377 | |||
| df0329d4f1 | |||
|
|
eb37f160ce | ||
|
|
df49eec21f | ||
| 54d4bd97f5 | |||
| c00967f33d | |||
| 7000cbfbd3 | |||
| b8b29125d6 | |||
| d7b1366d6c | |||
| d10c385bdc | |||
| 1878b09eee | |||
| a9afcffc1d | |||
| 9683fd3685 | |||
| c1b3a4368d | |||
| 73263c1faa | |||
| 524d2545ed | |||
| eda5154650 | |||
| ca95489b1d | |||
| 16068aa3e4 | |||
| 33fcc9d935 | |||
| 31cfb9dcb9 | |||
| 9e3e586fca | |||
| a06821a8c8 | |||
| eff69b2037 | |||
| 4cb3ac7fe7 | |||
| 6aca138af1 | |||
| 8981b0b87a | |||
| 8070dcd4b1 | |||
| 2fad597976 | |||
| 3746a5b92d | |||
| fdc44f7025 | |||
| 4e6ecacd37 | |||
| 250c71d930 | |||
| c86abdd1b8 | |||
| f69c02880e | |||
| 88deacb337 | |||
| 9257f4c7de | |||
| 1222532971 | |||
| a9d66ddcc1 | |||
| 136ca1fb9c | |||
| 020adf1b94 | |||
| 86c60f48e6 | |||
| c85619b8da | |||
| b2c8f76114 | |||
| 65ec1151f8 | |||
| 7bc2b64c1d | |||
| 39258f465b | |||
| 82cb2bde79 | |||
| fc6151ae16 | |||
| 7a17b1bf16 | |||
| 858ae1e7b9 | |||
| a4351d0da3 | |||
| 19017eca37 | |||
| 55c8f387ab | |||
| e35bd949c0 | |||
| 9fc3e9894e | |||
| 170c64eec1 | |||
| 93756f5248 | |||
| 3c93a72d01 | |||
| 844504e92e | |||
| 985e03a26d | |||
| d52e7af554 | |||
| 7cfb98aec1 | |||
| ce1a5e5fee | |||
| a11722e872 | |||
| bc3ed1a0c7 | |||
| f4e71777ec | |||
| 6df453e8d0 | |||
| 5604670646 | |||
| b942bb549a | |||
| 3a639507c7 | |||
| 8aa4072a63 | |||
| cfa8ee111d | |||
| 34c7af38b2 | |||
| 410ace3540 | |||
| 5cec6779e5 | |||
| aeb90efa61 | |||
| b04fd916ff | |||
| a8a9771ec7 | |||
| 042c0529a1 | |||
| e2587b60fb | |||
| 82b8f40b39 | |||
| 46fc2db8e6 | |||
| 6592b58f65 | |||
| 45d456049a | |||
| 631282b95f | |||
| 0ecf341c57 | |||
| 94d12159b4 | |||
| eac203ecf4 | |||
| c620dc51a7 | |||
| bcf848109b | |||
| 672120bb50 | |||
| f7f89403d5 | |||
| ae76697a1c | |||
| 677e6eb75e | |||
| 0af4441120 | |||
| ddb93bec20 | |||
| 358c1ab6f9 | |||
| 7966eb5187 | |||
| 2a9b03dd76 | |||
| 93028dc847 | |||
| 3bee8f3cb4 | |||
| 813d6f2529 | |||
| 9b538395c0 | |||
| a0f3677732 | |||
| 3fce9bf577 | |||
| 1729e43964 | |||
| 347449ed95 | |||
| 5156100197 | |||
| a7d9531537 | |||
| bd9cb6da35 | |||
| c50899f000 | |||
| 79505579b1 | |||
| a310c8afc9 | |||
| 2f76d1d0d5 | |||
| eb61207532 | |||
| 1c8430e68a | |||
| ba39e9ba26 | |||
| 4fd7306d01 | |||
| 4dbb4c6f0d | |||
| f506c89960 | |||
| 00c94cfe0d | |||
| a3386e1694 | |||
| 23e05a634f |
308
.claude/plans/zany-hugging-oasis.md
Normal file
308
.claude/plans/zany-hugging-oasis.md
Normal file
@ -0,0 +1,308 @@
|
||||
# Issue #469: Terrain Classification Implementation Plan
|
||||
|
||||
## Context
|
||||
|
||||
SaltyBot currently has good sensor infrastructure (IMU, cameras, RealSense) and a robust velocity control system with the `VelocityRamp` class. However, it lacks terrain awareness for surface type detection and speed adaptation. This feature will enable:
|
||||
|
||||
1. **Surface detection** via IMU vibration analysis and camera texture analysis
|
||||
2. **Automatic speed adaptation** based on terrain type and roughness
|
||||
3. **Terrain logging** for mapping and future learning
|
||||
4. **Improved robot safety** by reducing speed on rough/unstable terrain
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
The implementation follows the existing ROS2 patterns:
|
||||
|
||||
```
|
||||
IMU/Camera Data
|
||||
↓
|
||||
[terrain_classifier_node] ← New node
|
||||
↓
|
||||
/saltybot/terrain_state (TerrainState.msg)
|
||||
↓
|
||||
[terrain_speed_adapter_node] ← New node
|
||||
↓
|
||||
Adjusted /cmd_vel_terrain → existing cmd_vel_bridge
|
||||
↓
|
||||
Speed-adapted robot motion
|
||||
|
||||
Parallel: [terrain_mapper_node] logs data for mapping
|
||||
```
|
||||
|
||||
## Implementation Components
|
||||
|
||||
### 1. **Message Definition: TerrainState.msg**
|
||||
**File to create:** `jetson/ros2_ws/src/saltybot_social_msgs/msg/TerrainState.msg`
|
||||
|
||||
Fields:
|
||||
- `std_msgs/Header header` — timestamp/frame_id
|
||||
- `uint8 terrain_type` — enum (0=unknown, 1=pavement, 2=grass, 3=gravel, 4=sand, 5=indoor)
|
||||
- `float32 roughness` — 0.0=smooth, 1.0=very rough
|
||||
- `float32 confidence` — 0.0-1.0 classification confidence
|
||||
- `float32 recommended_speed_ratio` — 0.1-1.0 (fraction of max speed)
|
||||
- `string source` — "imu_vibration" or "camera_texture" or "fused"
|
||||
|
||||
**Update files:**
|
||||
- `jetson/ros2_ws/src/saltybot_social_msgs/CMakeLists.txt` — add TerrainState.msg to rosidl_generate_interfaces()
|
||||
- `jetson/ros2_ws/src/saltybot_social_msgs/package.xml` — no changes needed (std_msgs already a dependency)
|
||||
|
||||
### 2. **Terrain Classifier Node**
|
||||
**File to create:** `jetson/ros2_ws/src/saltybot_bringup/saltybot_bringup/terrain_classifier_node.py`
|
||||
|
||||
**Purpose:** Analyze IMU and camera data to classify terrain type and estimate roughness.
|
||||
|
||||
**Subscribes to:**
|
||||
- `/camera/imu` (sensor_msgs/Imu) — RealSense IMU at 200 Hz
|
||||
- `/camera/color/image_raw` (sensor_msgs/Image) — camera RGB at 15 Hz
|
||||
|
||||
**Publishes:**
|
||||
- `/saltybot/terrain_state` (TerrainState.msg) — at 5 Hz
|
||||
|
||||
**Key functions:**
|
||||
- `_analyze_imu_vibration()` — FFT analysis on accel data (window: 200 samples = 1 sec)
|
||||
- Compute power spectral density in 0-50 Hz band
|
||||
- Extract features: peak frequency, energy distribution, RMS acceleration
|
||||
- Roughness = normalized RMS of high-freq components (>10 Hz)
|
||||
|
||||
- `_analyze_camera_texture()` — CNN-based texture analysis
|
||||
- Uses MobileNetV2 pre-trained on ImageNet as feature extractor
|
||||
- Extracts high-level texture/surface features from camera image
|
||||
- Lightweight model (~3.5M parameters, ~50-100ms inference on Jetson)
|
||||
- Outputs feature vector fed to classification layer
|
||||
|
||||
- `_classify_terrain()` — decision logic
|
||||
- Simple rule-based classifier (can be upgraded to CNN)
|
||||
- Input: [imu_roughness, camera_texture_variance, accel_magnitude]
|
||||
- Decision tree or thresholds to classify into 5 types
|
||||
- Output: terrain_type, roughness, confidence
|
||||
|
||||
**Node Parameters:**
|
||||
- `imu_window_size` (int, default 200) — samples for FFT window
|
||||
- `publish_rate_hz` (float, default 5.0)
|
||||
- `roughness_threshold` (float, default 0.3) — FFT roughness threshold
|
||||
- `terrain_timeout_s` (float, default 5.0) — how long to keep previous estimate if no new data
|
||||
|
||||
### 3. **Speed Adapter Node**
|
||||
**File to create:** `jetson/ros2_ws/src/saltybot_bringup/saltybot_bringup/terrain_speed_adapter_node.py`
|
||||
|
||||
**Purpose:** Adapt cmd_vel speed based on terrain state and integration with velocity ramp.
|
||||
|
||||
**Subscribes to:**
|
||||
- `/cmd_vel` (geometry_msgs/Twist) — raw velocity commands
|
||||
- `/saltybot/terrain_state` (TerrainState.msg) — terrain classification
|
||||
|
||||
**Publishes:**
|
||||
- `/cmd_vel_terrain` (geometry_msgs/Twist) — terrain-adapted velocity
|
||||
|
||||
**Logic:**
|
||||
- Extract target linear velocity from cmd_vel
|
||||
- Apply terrain speed ratio: `adapted_speed = target_speed × recommended_speed_ratio`
|
||||
- Preserve angular velocity (steering not affected by terrain)
|
||||
- Publish adapted command
|
||||
|
||||
**Node Parameters:**
|
||||
- `enable_terrain_adaptation` (bool, default true)
|
||||
- `min_speed_ratio` (float, default 0.1) — never go below 10% of requested speed
|
||||
- `debug_logging` (bool, default false)
|
||||
|
||||
**Note:** This is a lightweight adapter. The existing `velocity_ramp_node` handles acceleration/deceleration smoothing independently.
|
||||
|
||||
### 4. **Terrain Mapper Node** (Logging/Mapping)
|
||||
**File to create:** `jetson/ros2_ws/src/saltybot_bringup/saltybot_bringup/terrain_mapper_node.py`
|
||||
|
||||
**Purpose:** Log terrain detections with robot pose for future mapping.
|
||||
|
||||
**Subscribes to:**
|
||||
- `/saltybot/terrain_state` (TerrainState.msg)
|
||||
- `/odom` (nav_msgs/Odometry) — robot pose
|
||||
|
||||
**Publishes:**
|
||||
- `/saltybot/terrain_log` (std_msgs/String) — CSV formatted log messages (optional, mainly for logging)
|
||||
|
||||
**Logic:**
|
||||
- Store terrain observations: (timestamp, pose_x, pose_y, terrain_type, roughness, confidence)
|
||||
- Log to file: `~/.ros/terrain_map_<timestamp>.csv`
|
||||
- Resample to 1 Hz to avoid spam
|
||||
|
||||
**Node Parameters:**
|
||||
- `log_dir` (string, default "~/.ros/")
|
||||
- `resample_rate_hz` (float, default 1.0)
|
||||
|
||||
### 5. **Launch Configuration**
|
||||
**File to update:** `jetson/ros2_ws/src/saltybot_bringup/launch/full_stack.launch.py`
|
||||
|
||||
Add terrain nodes:
|
||||
```python
|
||||
terrain_classifier_node = Node(
|
||||
package='saltybot_bringup',
|
||||
executable='terrain_classifier',
|
||||
name='terrain_classifier',
|
||||
parameters=[{
|
||||
'imu_window_size': 200,
|
||||
'publish_rate_hz': 5.0,
|
||||
}],
|
||||
remappings=[
|
||||
('/imu_in', '/camera/imu'),
|
||||
('/camera_in', '/camera/color/image_raw'),
|
||||
],
|
||||
)
|
||||
|
||||
terrain_speed_adapter_node = Node(
|
||||
package='saltybot_bringup',
|
||||
executable='terrain_speed_adapter',
|
||||
name='terrain_speed_adapter',
|
||||
parameters=[{
|
||||
'enable_terrain_adaptation': True,
|
||||
'min_speed_ratio': 0.1,
|
||||
}],
|
||||
remappings=[
|
||||
('/cmd_vel_in', '/cmd_vel'),
|
||||
('/cmd_vel_out', '/cmd_vel_terrain'),
|
||||
],
|
||||
)
|
||||
|
||||
terrain_mapper_node = Node(
|
||||
package='saltybot_bringup',
|
||||
executable='terrain_mapper',
|
||||
name='terrain_mapper',
|
||||
)
|
||||
```
|
||||
|
||||
**Update setup.py entry points:**
|
||||
```python
|
||||
'terrain_classifier = saltybot_bringup.terrain_classifier_node:main'
|
||||
'terrain_speed_adapter = saltybot_bringup.terrain_speed_adapter_node:main'
|
||||
'terrain_mapper = saltybot_bringup.terrain_mapper_node:main'
|
||||
```
|
||||
|
||||
### 6. **Integration with Existing Stack**
|
||||
- The existing velocity ramp (`velocity_ramp_node.py`) processes `/cmd_vel_smooth` or `/cmd_vel`
|
||||
- Optionally, update cmd_vel_bridge to use `/cmd_vel_terrain` if available, else fall back to `/cmd_vel`
|
||||
- Terrain classification runs independently at 5 Hz (much slower than velocity ramping at 50 Hz)
|
||||
|
||||
### 7. **Future CNN Enhancement**
|
||||
The current implementation uses rule-based classification with IMU FFT and camera edge detection. A future enhancement could add a lightweight CNN for texture classification (e.g., MobileNet) by:
|
||||
1. Creating a `terrain_classifier_cnn.py` with TensorFlow/ONNX model
|
||||
2. Replacing decision logic in `terrain_classifier_node.py` with CNN inference
|
||||
3. Maintaining same message interface
|
||||
|
||||
## Implementation Tasks
|
||||
|
||||
1. ✅ **Phase 1: Message Definition**
|
||||
- Create `TerrainState.msg` in saltybot_social_msgs
|
||||
- Update `CMakeLists.txt`
|
||||
|
||||
2. ✅ **Phase 2: Terrain Classifier Node**
|
||||
- Implement `terrain_classifier_node.py` with IMU FFT analysis
|
||||
- Implement camera texture analysis
|
||||
- Decision logic for classification
|
||||
|
||||
3. ✅ **Phase 3: Speed Adapter Node**
|
||||
- Implement `terrain_speed_adapter_node.py`
|
||||
- Velocity command adaptation
|
||||
|
||||
4. ✅ **Phase 4: Terrain Mapper Node**
|
||||
- Implement `terrain_mapper_node.py` for logging
|
||||
|
||||
5. ✅ **Phase 5: Integration**
|
||||
- Update `full_stack.launch.py` with new nodes
|
||||
- Update `setup.py` with entry points
|
||||
- Test integration
|
||||
|
||||
## Testing & Verification
|
||||
|
||||
**Unit Tests:**
|
||||
- Test IMU FFT feature extraction with synthetic vibration data
|
||||
- Test terrain classification decision logic
|
||||
- Test speed ratio application
|
||||
- Test CSV logging format
|
||||
|
||||
**Integration Tests:**
|
||||
- Run full stack with simulated IMU/camera data
|
||||
- Verify terrain messages published at 5 Hz
|
||||
- Verify cmd_vel_terrain adapts speeds correctly
|
||||
- Check terrain log file is created and properly formatted
|
||||
|
||||
**Manual Testing:**
|
||||
- Drive robot on different surfaces
|
||||
- Verify terrain detection changes appropriately
|
||||
- Verify speed adaptation is smooth (no jerks from ramping)
|
||||
- Check terrain log CSV has correct format
|
||||
|
||||
## Critical Files Summary
|
||||
|
||||
**To Create:**
|
||||
- `jetson/ros2_ws/src/saltybot_social_msgs/msg/TerrainState.msg`
|
||||
- `jetson/ros2_ws/src/saltybot_bringup/saltybot_bringup/terrain_classifier_node.py`
|
||||
- `jetson/ros2_ws/src/saltybot_bringup/saltybot_bringup/terrain_speed_adapter_node.py`
|
||||
- `jetson/ros2_ws/src/saltybot_bringup/saltybot_bringup/terrain_mapper_node.py`
|
||||
|
||||
**To Modify:**
|
||||
- `jetson/ros2_ws/src/saltybot_social_msgs/CMakeLists.txt` (add TerrainState.msg)
|
||||
- `jetson/ros2_ws/src/saltybot_bringup/launch/full_stack.launch.py` (add nodes)
|
||||
- `jetson/ros2_ws/src/saltybot_bringup/setup.py` (add entry points)
|
||||
|
||||
**Key Dependencies:**
|
||||
- `numpy` — FFT analysis (already available in saltybot)
|
||||
- `scipy.signal` — Butterworth filter (optional, for smoothing)
|
||||
- `cv2` (OpenCV) — image processing (already available)
|
||||
- `tensorflow` or `tf-lite` — MobileNetV2 pre-trained model for texture CNN
|
||||
- `rclpy` — ROS2 Python client
|
||||
|
||||
**CNN Model Details:**
|
||||
- Model: MobileNetV2 pre-trained on ImageNet
|
||||
- Input: 224×224 RGB image (downsampled from camera)
|
||||
- Output: 1280-dim feature vector from last conv layer before classification
|
||||
- Strategy: Use pre-trained features directly (transfer learning) for quick MVP, no fine-tuning needed initially
|
||||
- Alternative: Pre-trained weights can be fine-tuned on terrain image dataset in future iterations
|
||||
- Inference: ~50-100ms on Jetson Xavier (acceptable at 5 Hz publish rate)
|
||||
|
||||
## Terrain Classification Logic (IMU + CNN Fusion)
|
||||
|
||||
**Features extracted:**
|
||||
1. `imu_roughness` = normalized RMS of high-freq (>10 Hz) accel components (0-1)
|
||||
- Computed from FFT power spectral density in 10-50 Hz band
|
||||
- Reflects mechanical vibration from surface contact
|
||||
|
||||
2. `cnn_texture_features` = 1280-dim feature vector from MobileNetV2
|
||||
- Pre-trained features capture texture, edge, and surface characteristics
|
||||
- Reduced to 2-3 principal components via PCA or simple aggregation
|
||||
|
||||
3. `accel_magnitude` = RMS of total acceleration (m/s²)
|
||||
- Helps distinguish stationary (9.81 m/s²) vs. moving
|
||||
|
||||
**Classification approach (Version 1):**
|
||||
- Simple decision tree with IMU-dominant logic + CNN support:
|
||||
```
|
||||
if imu_roughness < 0.2 and accel_magnitude < 9.8:
|
||||
terrain = PAVEMENT (confidence boosted if CNN agrees)
|
||||
elif imu_roughness < 0.35 and cnn_grainy_score < 0.4:
|
||||
terrain = GRASS
|
||||
elif imu_roughness > 0.45 and cnn_granular_score > 0.5:
|
||||
terrain = GRAVEL
|
||||
elif cnn_sand_texture_score > 0.6 and imu_roughness > 0.3:
|
||||
terrain = SAND
|
||||
else:
|
||||
terrain = INDOOR
|
||||
```
|
||||
|
||||
- Confidence: weighted combination of IMU and CNN agreement
|
||||
- Roughness metric: `0.0 = smooth, 1.0 = very rough` derived from IMU FFT energy ratio
|
||||
|
||||
**Speed recommendations:**
|
||||
- Pavement: 1.0 (full speed)
|
||||
- Grass: 0.8 (20% slower)
|
||||
- Gravel: 0.5 (50% slower)
|
||||
- Sand: 0.4 (60% slower)
|
||||
- Indoor: 0.7 (30% slower by default)
|
||||
|
||||
**Future improvement:** Replace decision tree with trained classifier (Random Forest, SVM, or small Dense net) on labeled terrain dataset once collected.
|
||||
|
||||
---
|
||||
|
||||
This plan follows SaltyBot's established patterns:
|
||||
- Pure Python libraries for core logic (_terrain_analysis.py)
|
||||
- ROS2 node wrappers for integration
|
||||
- Parameter-based configuration in YAML
|
||||
- Message-based pub/sub architecture
|
||||
- Integration with existing velocity control pipeline
|
||||
162
.gitea/workflows/ota-release.yml
Normal file
162
.gitea/workflows/ota-release.yml
Normal file
@ -0,0 +1,162 @@
|
||||
# .gitea/workflows/ota-release.yml
|
||||
# Gitea Actions — ESP32 OTA firmware build & release (bd-9kod)
|
||||
#
|
||||
# Triggers on signed release tags:
|
||||
# esp32-balance/vX.Y.Z → builds esp32s3/balance/ (ESP32-S3 Balance board)
|
||||
# esp32-io/vX.Y.Z → builds esp32s3-io/ (ESP32-S3 IO board)
|
||||
#
|
||||
# Uses the official espressif/idf Docker image for reproducible builds.
|
||||
# Attaches <app>_<version>.bin + <app>_<version>.sha256 to the Gitea release.
|
||||
# The ESP32 Balance OTA system fetches the .bin from the release asset URL.
|
||||
|
||||
name: OTA release — build & attach firmware
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "esp32-balance/v*"
|
||||
- "esp32-io/v*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
name: Build ${{ github.ref_name }}
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: espressif/idf:v5.2.2
|
||||
options: --user root
|
||||
|
||||
steps:
|
||||
# ── 1. Checkout ───────────────────────────────────────────────────────────
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# ── 2. Resolve build target from tag ─────────────────────────────────────
|
||||
# Tag format: esp32-balance/v1.2.3 or esp32-io/v1.2.3
|
||||
- name: Resolve project from tag
|
||||
id: proj
|
||||
shell: bash
|
||||
run: |
|
||||
TAG="${GITHUB_REF_NAME}"
|
||||
case "$TAG" in
|
||||
esp32-balance/*)
|
||||
DIR="esp32s3/balance"
|
||||
APP="esp32s3_balance"
|
||||
;;
|
||||
esp32-io/*)
|
||||
DIR="esp32s3-io"
|
||||
APP="esp32s3_io"
|
||||
;;
|
||||
*)
|
||||
echo "::error::Unrecognised tag prefix: ${TAG}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
VERSION="${TAG#*/}"
|
||||
echo "dir=${DIR}" >> "$GITHUB_OUTPUT"
|
||||
echo "app=${APP}" >> "$GITHUB_OUTPUT"
|
||||
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
echo "Build: ${APP} ${VERSION} from ${DIR}"
|
||||
|
||||
# ── 3. Build with ESP-IDF ─────────────────────────────────────────────────
|
||||
- name: Build firmware (idf.py build)
|
||||
shell: bash
|
||||
run: |
|
||||
. "${IDF_PATH}/export.sh"
|
||||
cd "${{ steps.proj.outputs.dir }}"
|
||||
idf.py build
|
||||
|
||||
# ── 4. Collect binary & generate checksum ────────────────────────────────
|
||||
- name: Collect artifacts
|
||||
id: art
|
||||
shell: bash
|
||||
run: |
|
||||
APP="${{ steps.proj.outputs.app }}"
|
||||
VER="${{ steps.proj.outputs.version }}"
|
||||
BIN_SRC="${{ steps.proj.outputs.dir }}/build/${APP}.bin"
|
||||
BIN_OUT="${APP}_${VER}.bin"
|
||||
SHA_OUT="${APP}_${VER}.sha256"
|
||||
|
||||
cp "$BIN_SRC" "$BIN_OUT"
|
||||
sha256sum "$BIN_OUT" > "$SHA_OUT"
|
||||
|
||||
echo "bin=${BIN_OUT}" >> "$GITHUB_OUTPUT"
|
||||
echo "sha=${SHA_OUT}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
echo "Binary: ${BIN_OUT} ($(wc -c < "$BIN_OUT") bytes)"
|
||||
echo "Checksum: $(cat "$SHA_OUT")"
|
||||
|
||||
# ── 5. Archive artifacts in CI workspace ─────────────────────────────────
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: firmware-${{ steps.proj.outputs.app }}-${{ steps.proj.outputs.version }}
|
||||
path: |
|
||||
${{ steps.art.outputs.bin }}
|
||||
${{ steps.art.outputs.sha }}
|
||||
|
||||
# ── 6. Create Gitea release (if needed) & upload assets ──────────────────
|
||||
# Uses GITHUB_TOKEN (auto-provided, contents:write from permissions block).
|
||||
# URL-encodes the tag to handle the slash in esp32-balance/vX.Y.Z.
|
||||
- name: Publish assets to Gitea release
|
||||
shell: bash
|
||||
env:
|
||||
GITEA_URL: https://gitea.vayrette.com
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
TAG: ${{ steps.proj.outputs.tag }}
|
||||
BIN: ${{ steps.art.outputs.bin }}
|
||||
SHA: ${{ steps.art.outputs.sha }}
|
||||
run: |
|
||||
API="${GITEA_URL}/api/v1/repos/${REPO}"
|
||||
|
||||
# URL-encode the tag (slash in esp32-balance/vX.Y.Z must be escaped)
|
||||
TAG_ENC=$(python3 -c "
|
||||
import urllib.parse, sys
|
||||
print(urllib.parse.quote(sys.argv[1], safe=''))
|
||||
" "$TAG")
|
||||
|
||||
# Try to fetch an existing release for this tag
|
||||
RELEASE=$(curl -sf \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${API}/releases/tags/${TAG_ENC}") || true
|
||||
|
||||
# If no release yet, create it
|
||||
if [ -z "$RELEASE" ]; then
|
||||
echo "Creating release for tag: ${TAG}"
|
||||
RELEASE=$(curl -sf \
|
||||
-X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(python3 -c "
|
||||
import json, sys
|
||||
print(json.dumps({
|
||||
'tag_name': sys.argv[1],
|
||||
'name': sys.argv[1],
|
||||
'draft': False,
|
||||
'prerelease': False,
|
||||
}))
|
||||
" "$TAG")" \
|
||||
"${API}/releases")
|
||||
fi
|
||||
|
||||
RELEASE_ID=$(echo "$RELEASE" | python3 -c "
|
||||
import sys, json; print(json.load(sys.stdin)['id'])
|
||||
")
|
||||
echo "Release ID: ${RELEASE_ID}"
|
||||
|
||||
# Upload binary and checksum
|
||||
for FILE in "$BIN" "$SHA"; do
|
||||
FNAME=$(basename "$FILE")
|
||||
echo "Uploading: ${FNAME}"
|
||||
curl -sf \
|
||||
-X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-F "attachment=@${FILE}" \
|
||||
"${API}/releases/${RELEASE_ID}/assets?name=${FNAME}"
|
||||
done
|
||||
|
||||
echo "Published: ${BIN} + ${SHA} → release ${TAG}"
|
||||
BIN
.pio/build/f722/.sconsign312.dblite
Normal file
BIN
.pio/build/f722/.sconsign312.dblite
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/lib143/Printer/usbd_printer.o
Normal file
BIN
.pio/build/f722/lib143/Printer/usbd_printer.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib143/libPrinter.a
Normal file
BIN
.pio/build/f722/lib143/libPrinter.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib14a/MTP/usbd_mtp.o
Normal file
BIN
.pio/build/f722/lib14a/MTP/usbd_mtp.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib14a/MTP/usbd_mtp_opt.o
Normal file
BIN
.pio/build/f722/lib14a/MTP/usbd_mtp_opt.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib14a/MTP/usbd_mtp_storage.o
Normal file
BIN
.pio/build/f722/lib14a/MTP/usbd_mtp_storage.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib14a/libMTP.a
Normal file
BIN
.pio/build/f722/lib14a/libMTP.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib274/CDC_RNDIS/usbd_cdc_rndis.o
Normal file
BIN
.pio/build/f722/lib274/CDC_RNDIS/usbd_cdc_rndis.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib274/libCDC_RNDIS.a
Normal file
BIN
.pio/build/f722/lib274/libCDC_RNDIS.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib30e/CustomHID/usbd_customhid.o
Normal file
BIN
.pio/build/f722/lib30e/CustomHID/usbd_customhid.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib30e/libCustomHID.a
Normal file
BIN
.pio/build/f722/lib30e/libCustomHID.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc.o
Normal file
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc_bot.o
Normal file
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc_bot.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc_data.o
Normal file
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc_data.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc_scsi.o
Normal file
BIN
.pio/build/f722/lib3fe/MSC/usbd_msc_scsi.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib3fe/libMSC.a
Normal file
BIN
.pio/build/f722/lib3fe/libMSC.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib455/CCID/usbd_ccid.o
Normal file
BIN
.pio/build/f722/lib455/CCID/usbd_ccid.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib455/CCID/usbd_ccid_cmd.o
Normal file
BIN
.pio/build/f722/lib455/CCID/usbd_ccid_cmd.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib455/libCCID.a
Normal file
BIN
.pio/build/f722/lib455/libCCID.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib732/VIDEO/usbd_video.o
Normal file
BIN
.pio/build/f722/lib732/VIDEO/usbd_video.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib732/libVIDEO.a
Normal file
BIN
.pio/build/f722/lib732/libVIDEO.a
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/lib7f1/HID/usbd_hid.o
Normal file
BIN
.pio/build/f722/lib7f1/HID/usbd_hid.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib7f1/libHID.a
Normal file
BIN
.pio/build/f722/lib7f1/libHID.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib82d/DFU/usbd_dfu.o
Normal file
BIN
.pio/build/f722/lib82d/DFU/usbd_dfu.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib82d/libDFU.a
Normal file
BIN
.pio/build/f722/lib82d/libDFU.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib93a/AUDIO/usbd_audio.o
Normal file
BIN
.pio/build/f722/lib93a/AUDIO/usbd_audio.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/lib93a/libAUDIO.a
Normal file
BIN
.pio/build/f722/lib93a/libAUDIO.a
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/libb65/USB_CDC/usbd_cdc_if.o
Normal file
BIN
.pio/build/f722/libb65/USB_CDC/usbd_cdc_if.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/libb65/USB_CDC/usbd_conf.o
Normal file
BIN
.pio/build/f722/libb65/USB_CDC/usbd_conf.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/libe6a/CDC_ECM/usbd_cdc_ecm.o
Normal file
BIN
.pio/build/f722/libe6a/CDC_ECM/usbd_cdc_ecm.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/libe6a/libCDC_ECM.a
Normal file
BIN
.pio/build/f722/libe6a/libCDC_ECM.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/libef9/CompositeBuilder/usbd_composite_builder.o
Normal file
BIN
.pio/build/f722/libef9/CompositeBuilder/usbd_composite_builder.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/libef9/libCompositeBuilder.a
Normal file
BIN
.pio/build/f722/libef9/libCompositeBuilder.a
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/audio.o
Normal file
BIN
.pio/build/f722/src/audio.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/battery.o
Normal file
BIN
.pio/build/f722/src/battery.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/bno055.o
Normal file
BIN
.pio/build/f722/src/bno055.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/buzzer.o
Normal file
BIN
.pio/build/f722/src/buzzer.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/coulomb_counter.o
Normal file
BIN
.pio/build/f722/src/coulomb_counter.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/esc_backend.o
Normal file
BIN
.pio/build/f722/src/esc_backend.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/esc_hoverboard.o
Normal file
BIN
.pio/build/f722/src/esc_hoverboard.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/esc_vesc.o
Normal file
BIN
.pio/build/f722/src/esc_vesc.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/face_animation.o
Normal file
BIN
.pio/build/f722/src/face_animation.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/face_lcd.o
Normal file
BIN
.pio/build/f722/src/face_lcd.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/face_uart.o
Normal file
BIN
.pio/build/f722/src/face_uart.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/fan.o
Normal file
BIN
.pio/build/f722/src/fan.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/ina219.o
Normal file
BIN
.pio/build/f722/src/ina219.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/jetson_uart.o
Normal file
BIN
.pio/build/f722/src/jetson_uart.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/jlink.o
Normal file
BIN
.pio/build/f722/src/jlink.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/led.o
Normal file
BIN
.pio/build/f722/src/led.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/ota.o
Normal file
BIN
.pio/build/f722/src/ota.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/power_mgmt.o
Normal file
BIN
.pio/build/f722/src/power_mgmt.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/rgb_fsm.o
Normal file
BIN
.pio/build/f722/src/rgb_fsm.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/servo.o
Normal file
BIN
.pio/build/f722/src/servo.o
Normal file
Binary file not shown.
Binary file not shown.
BIN
.pio/build/f722/src/ultrasonic.o
Normal file
BIN
.pio/build/f722/src/ultrasonic.o
Normal file
Binary file not shown.
BIN
.pio/build/f722/src/watchdog.o
Normal file
BIN
.pio/build/f722/src/watchdog.o
Normal file
Binary file not shown.
@ -1 +1 @@
|
||||
ee8efb31f6b185f16e4d385971f1a0e3291fe5fd
|
||||
ffc01fb580c81760bdda9a672fe1212be4578e3e
|
||||
148
AUTONOMOUS_ARMING.md
Normal file
148
AUTONOMOUS_ARMING.md
Normal file
@ -0,0 +1,148 @@
|
||||
# Autonomous Arming (Issue #512)
|
||||
|
||||
## Overview
|
||||
The robot can now be armed and operated autonomously from the Jetson without requiring an RC transmitter. The RC receiver (ELRS) is now optional and serves as an override/kill-switch rather than a requirement.
|
||||
|
||||
## Arming Sources
|
||||
|
||||
### Jetson Autonomous Arming
|
||||
- Command: `A\n` (single byte 'A' followed by newline)
|
||||
<<<<<<< HEAD
|
||||
- Sent via USB CDC to the ESP32 BALANCE firmware
|
||||
=======
|
||||
- Sent via USB Serial (CH343) to the ESP32-S3 firmware
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
- Robot arms after ARMING_HOLD_MS (~500ms) safety hold period
|
||||
- Works even when RC is not connected or not armed
|
||||
|
||||
### RC Arming (Optional Override)
|
||||
- Command: CH5 switch on ELRS transmitter
|
||||
- When RC is connected and armed, robot can be armed via RC
|
||||
- RC and Jetson can both request arming independently
|
||||
|
||||
## Safety Features
|
||||
|
||||
### Maintained from Original Design
|
||||
1. **Arming Hold Timer** — 500ms hold before motors enable (prevents accidental arming)
|
||||
2. **Tilt Safety** — Robot must be within ±10° level to arm
|
||||
3. **IMU Calibration** — Gyro must be calibrated before arming
|
||||
4. **Remote E-Stop Override** — `safety_remote_estop_active()` blocks all arming
|
||||
|
||||
### New for Autonomous Operation
|
||||
1. **RC Kill Switch** (CH5 OFF when RC connected)
|
||||
- Triggers emergency stop (motor cutoff) instead of disarm
|
||||
- Allows Jetson-armed robots to remain armed when RC disconnects
|
||||
- Maintains safety of kill switch for emergency situations
|
||||
|
||||
2. **RC Failsafe**
|
||||
- If RC signal is lost after being established, robot disarms (500ms timeout)
|
||||
- Prevents runaway if RC connection drops during flight
|
||||
- USB-only mode (no RC ever connected) is unaffected
|
||||
|
||||
3. **Jetson Timeout** (200ms heartbeat)
|
||||
- Jetson must send heartbeat (H command) every 500ms
|
||||
- Prevents autonomous runaway if Jetson crashes/loses connection
|
||||
- Handled by `jetson_cmd_is_active()` checks
|
||||
|
||||
## Command Protocol
|
||||
|
||||
<<<<<<< HEAD
|
||||
### From Jetson to ESP32 BALANCE (USB CDC)
|
||||
=======
|
||||
### From Jetson to ESP32-S3 (USB Serial (CH343))
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
```
|
||||
A — Request arm (triggers safety hold, then motors enable)
|
||||
D — Request disarm (immediate motor stop)
|
||||
E — Emergency stop (immediate motor cutoff, latched)
|
||||
Z — Clear emergency stop latch
|
||||
H — Heartbeat (refresh timeout timer, every 500ms)
|
||||
C<spd>,<str> — Drive command: speed, steer (also refreshes heartbeat)
|
||||
```
|
||||
|
||||
<<<<<<< HEAD
|
||||
### From ESP32 BALANCE to Jetson (USB CDC)
|
||||
=======
|
||||
### From ESP32-S3 to Jetson (USB Serial (CH343))
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
Motor commands are gated by `bal.state == BALANCE_ARMED`:
|
||||
- When ARMED: Motor commands sent every 20ms (50 Hz)
|
||||
- When DISARMED: Zero sent every 20ms (prevents ESC timeout)
|
||||
|
||||
## Arming State Machine
|
||||
|
||||
```
|
||||
DISARMED
|
||||
↓
|
||||
+-- Jetson sends 'A' OR RC CH5 rises (with conditions met)
|
||||
↓
|
||||
safety_arm_start() called
|
||||
(arm hold timer starts)
|
||||
↓
|
||||
Wait ARMING_HOLD_MS
|
||||
↓
|
||||
safety_arm_ready() returns true
|
||||
↓
|
||||
balance_arm() called
|
||||
ARMED ← (motors now respond to commands)
|
||||
|
||||
ARMED
|
||||
↓
|
||||
+-- Jetson sends 'D' → balance_disarm()
|
||||
+-- RC CH5 falls AND RC still alive → balance_disarm()
|
||||
+-- RC signal lost (failsafe) → balance_disarm()
|
||||
+-- Tilt fault detected → immediate motor stop
|
||||
+-- RC kill switch (CH5 OFF) → emergency stop (not disarm)
|
||||
```
|
||||
|
||||
## RC Override Priority
|
||||
|
||||
When RC is connected and active:
|
||||
- **Steer channel**: Blended with Jetson via `mode_manager` (per active mode)
|
||||
- **Kill switch**: RC CH5 OFF triggers emergency stop (overrides everything)
|
||||
- **Failsafe**: RC signal loss triggers disarm (prevents runaway)
|
||||
|
||||
When RC is disconnected:
|
||||
- Robot operates under Jetson commands alone
|
||||
- Emergency stop remains available via 'E' command from Jetson
|
||||
- No automatic mode change; mission continues autonomously
|
||||
|
||||
## Testing Checklist
|
||||
|
||||
- [ ] Jetson can arm robot without RC (send 'A' command)
|
||||
- [ ] Robot motors respond to Jetson drive commands when armed
|
||||
- [ ] Robot disarms on Jetson 'D' command
|
||||
- [ ] RC kill switch (CH5 OFF) triggers emergency stop without disarming
|
||||
- [ ] Robot can be re-armed after RC kill switch via Jetson 'A' command
|
||||
- [ ] RC failsafe still works (500ms signal loss = disarm)
|
||||
- [ ] Jetson heartbeat timeout works (500ms without H/C = motors zero)
|
||||
- [ ] Tilt fault still triggers immediate stop
|
||||
- [ ] IMU calibration required before arm
|
||||
- [ ] Arming hold timer (500ms) enforced
|
||||
|
||||
## Migration from RC-Only
|
||||
|
||||
### Old Workflow (ELRS-Required)
|
||||
1. Power on robot
|
||||
2. Arm via RC CH5
|
||||
3. Send speed/steer commands via RC
|
||||
4. Disarm via RC CH5
|
||||
|
||||
### New Workflow (Autonomous)
|
||||
1. Power on robot
|
||||
2. Send heartbeat 'H' every 500ms from Jetson
|
||||
3. When ready to move, send 'A' command (wait 500ms)
|
||||
4. Send drive commands 'C<spd>,<str>' every ≤200ms
|
||||
5. When done, send 'D' command to disarm
|
||||
|
||||
### New Workflow (RC + Autonomous Mixed)
|
||||
1. Power on robot, bring up RC
|
||||
2. Jetson sends heartbeat 'H'
|
||||
3. Arm via RC CH5 OR Jetson 'A' (both valid)
|
||||
4. Control via RC sticks OR Jetson drive commands (blended)
|
||||
5. Emergency kill: RC CH5 OFF (emergency stop) OR Jetson 'E'
|
||||
6. Disarm: RC CH5 OFF then ON, OR Jetson 'D'
|
||||
|
||||
## References
|
||||
- Issue #512: Remove ELRS arm requirement
|
||||
- Files: `/src/main.c` (arming logic), `/lib/USB_CDC/src/usbd_cdc_if.c` (CDC commands)
|
||||
31
CLAUDE.md
31
CLAUDE.md
@ -1,17 +1,36 @@
|
||||
# SaltyLab Firmware — Agent Playbook
|
||||
|
||||
## Project
|
||||
Self-balancing two-wheeled robot: STM32F722 flight controller, hoverboard hub motors, Jetson Nano for AI/SLAM.
|
||||
<<<<<<< HEAD
|
||||
**SAUL-TEE** — 4-wheel wagon (870×510×550 mm, 23 kg).
|
||||
Two ESP32-S3 boards + Jetson Orin via CAN. Full spec: `docs/SAUL-TEE-SYSTEM-REFERENCE.md`
|
||||
|
||||
| Board | Role |
|
||||
|-------|------|
|
||||
| **ESP32-S3 BALANCE** | QMI8658 IMU, PID balance, CAN→VESC (L:68 / R:56), GC9A01 LCD (Waveshare Touch LCD 1.28) |
|
||||
| **ESP32-S3 IO** | TBS Crossfire RC, ELRS failover, BTS7960 motors, NFC/baro/ToF, WS2812 |
|
||||
| **Jetson Orin** | AI/SLAM, CANable2 USB→CAN, cmds 0x300–0x303, telemetry 0x400–0x401 |
|
||||
|
||||
> **Legacy:** `src/` and `include/` = archived STM32 HAL — do not extend. New firmware in `esp32/`.
|
||||
=======
|
||||
Self-balancing two-wheeled robot: ESP32-S3 ESP32-S3 BALANCE, hoverboard hub motors, Jetson Orin Nano Super for AI/SLAM.
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
|
||||
## Team
|
||||
| Agent | Role | Focus |
|
||||
|-------|------|-------|
|
||||
| **sl-firmware** | Embedded Firmware Lead | STM32 HAL, USB CDC debugging, SPI/UART, PlatformIO, DFU bootloader |
|
||||
<<<<<<< HEAD
|
||||
| **sl-firmware** | Embedded Firmware Lead | ESP32-S3, ESP-IDF, QMI8658, CAN/UART protocol, BTS7960 |
|
||||
| **sl-controls** | Control Systems Engineer | PID tuning, IMU fusion, balance loop, safety |
|
||||
| **sl-perception** | Perception / SLAM Engineer | Jetson Orin, RealSense D435i, RPLIDAR, ROS2, Nav2 |
|
||||
=======
|
||||
| **sl-firmware** | Embedded Firmware Lead | ESP-IDF, USB Serial (CH343) debugging, SPI/UART, PlatformIO, DFU bootloader |
|
||||
| **sl-controls** | Control Systems Engineer | PID tuning, IMU sensor fusion, real-time control loops, safety systems |
|
||||
| **sl-perception** | Perception / SLAM Engineer | Jetson Nano, RealSense D435i, RPLIDAR, ROS2, Nav2 |
|
||||
| **sl-perception** | Perception / SLAM Engineer | Jetson Orin Nano Super, RealSense D435i, RPLIDAR, ROS2, Nav2 |
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
|
||||
## Status
|
||||
USB CDC TX bug resolved (PR #10 — DCache MPU non-cacheable region + IWDG ordering fix).
|
||||
USB Serial (CH343) TX bug resolved (PR #10 — DCache MPU non-cacheable region + IWDG ordering fix).
|
||||
|
||||
## Repo Structure
|
||||
- `projects/saltybot/SALTYLAB.md` — Design doc
|
||||
@ -29,11 +48,11 @@ USB CDC TX bug resolved (PR #10 — DCache MPU non-cacheable region + IWDG order
|
||||
| `saltyrover-dev` | Integration — rover variant |
|
||||
| `saltytank` | Stable — tracked tank variant |
|
||||
| `saltytank-dev` | Integration — tank variant |
|
||||
| `main` | Shared code only (IMU drivers, USB CDC, balance core, safety) |
|
||||
| `main` | Shared code only (IMU drivers, USB Serial (CH343), balance core, safety) |
|
||||
|
||||
### Rules
|
||||
- Agents branch FROM `<variant>-dev` and PR back TO `<variant>-dev`
|
||||
- Shared/infrastructure code (IMU drivers, USB CDC, balance core, safety) goes in `main`
|
||||
- Shared/infrastructure code (IMU drivers, USB Serial (CH343), balance core, safety) goes in `main`
|
||||
- Variant-specific code (motor topology, kinematics, config) goes in variant branches
|
||||
- Stable branches get promoted from `-dev` after review and hardware testing
|
||||
- **Current SaltyLab team** works against `saltylab-dev`
|
||||
|
||||
52
TEAM.md
52
TEAM.md
@ -1,12 +1,22 @@
|
||||
# SaltyLab — Ideal Team
|
||||
|
||||
## Project
|
||||
Self-balancing two-wheeled robot using a drone flight controller (STM32F722), hoverboard hub motors, and eventually a Jetson Nano for AI/SLAM.
|
||||
<<<<<<< HEAD
|
||||
**SAUL-TEE** — 4-wheel wagon (870×510×550 mm, 23 kg).
|
||||
Two ESP32-S3 boards (BALANCE + IO) + Jetson Orin. See `docs/SAUL-TEE-SYSTEM-REFERENCE.md`.
|
||||
|
||||
## Current Status
|
||||
- **Hardware:** ESP32-S3 BALANCE (Waveshare Touch LCD 1.28, CH343 USB) + ESP32-S3 IO (bare devkit, JTAG USB)
|
||||
- **Firmware:** ESP-IDF/PlatformIO target; legacy `src/` STM32 HAL archived
|
||||
- **Comms:** UART 460800 baud inter-board; CANable2 USB→CAN for Orin; CAN 500 kbps to VESCs (L:68 / R:56)
|
||||
=======
|
||||
Self-balancing two-wheeled robot using a drone ESP32-S3 BALANCE (ESP32-S3), hoverboard hub motors, and eventually a Jetson Orin Nano Super for AI/SLAM.
|
||||
|
||||
## Current Status
|
||||
- **Hardware:** Assembled — FC, motors, ESC, IMU, battery, RC all on hand
|
||||
- **Firmware:** Balance PID + hoverboard ESC protocol written, but blocked by USB CDC bug
|
||||
- **Blocker:** USB CDC TX stops working when peripheral inits (SPI/UART/GPIO) are added alongside USB OTG FS — see `USB_CDC_BUG.md`
|
||||
- **Firmware:** Balance PID + hoverboard ESC protocol written, but blocked by USB Serial (CH343) bug
|
||||
- **Blocker:** USB Serial (CH343) TX stops working when peripheral inits (SPI/UART/GPIO) are added alongside USB on ESP32-S3 — see `legacy/stm32/USB_CDC_BUG.md` for historical context
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
|
||||
---
|
||||
|
||||
@ -14,18 +24,30 @@ Self-balancing two-wheeled robot using a drone flight controller (STM32F722), ho
|
||||
|
||||
### 1. Embedded Firmware Engineer (Lead)
|
||||
**Must-have:**
|
||||
- Deep STM32 HAL experience (F7 series specifically)
|
||||
<<<<<<< HEAD
|
||||
- Deep ESP32 (Arduino/ESP-IDF) or STM32 HAL experience
|
||||
- USB OTG FS / CDC ACM debugging (TxState, endpoint management, DMA conflicts)
|
||||
- SPI + UART + USB coexistence on STM32
|
||||
- PlatformIO or bare-metal STM32 toolchain
|
||||
- SPI + UART + USB coexistence on ESP32
|
||||
- PlatformIO or bare-metal ESP32 toolchain
|
||||
- DFU bootloader implementation
|
||||
=======
|
||||
- Deep ESP-IDF experience (ESP32-S3 specifically)
|
||||
- USB Serial (CH343) / UART debugging on ESP32-S3
|
||||
- SPI + UART + USB coexistence on ESP32-S3
|
||||
- ESP-IDF / Arduino-ESP32 toolchain
|
||||
- OTA firmware update implementation
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
|
||||
**Nice-to-have:**
|
||||
- Betaflight/iNav/ArduPilot codebase familiarity
|
||||
- ESP32-S3 peripheral coexistence (SPI + UART + USB)
|
||||
- PID control loop tuning for balance robots
|
||||
- FOC motor control (hoverboard ESC protocol)
|
||||
|
||||
**Why:** The immediate blocker is a USB peripheral conflict. Need someone who's debugged STM32 USB issues before — this is not a software logic bug, it's a hardware peripheral interaction issue.
|
||||
<<<<<<< HEAD
|
||||
**Why:** The immediate blocker is a USB peripheral conflict. Need someone who's debugged STM32 USB issues before — ESP32 firmware for the balance loop and I/O needs to be written from scratch.
|
||||
=======
|
||||
**Why:** The immediate blocker is a USB peripheral conflict on ESP32-S3. Need someone who's debugged ESP32-S3 USB Serial (CH343) issues before — this is not a software logic bug, it's a hardware peripheral interaction issue.
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
|
||||
### 2. Control Systems / Robotics Engineer
|
||||
**Must-have:**
|
||||
@ -43,7 +65,7 @@ Self-balancing two-wheeled robot using a drone flight controller (STM32F722), ho
|
||||
|
||||
### 3. Perception / SLAM Engineer (Phase 2)
|
||||
**Must-have:**
|
||||
- Jetson Nano / NVIDIA Jetson platform
|
||||
- Jetson Orin Nano Super / NVIDIA Jetson platform
|
||||
- Intel RealSense D435i depth camera
|
||||
- RPLIDAR integration
|
||||
- SLAM (ORB-SLAM3, RTAB-Map, or similar)
|
||||
@ -54,19 +76,23 @@ Self-balancing two-wheeled robot using a drone flight controller (STM32F722), ho
|
||||
- Obstacle avoidance
|
||||
- Nav2 stack
|
||||
|
||||
**Why:** Phase 2 goal is autonomous navigation. Jetson Nano with RealSense + RPLIDAR for indoor mapping and person following.
|
||||
**Why:** Phase 2 goal is autonomous navigation. Jetson Orin Nano Super with RealSense + RPLIDAR for indoor mapping and person following.
|
||||
|
||||
---
|
||||
|
||||
## Hardware Reference
|
||||
| Component | Details |
|
||||
|-----------|---------|
|
||||
| FC | MAMBA F722S (STM32F722RET6, MPU6000) |
|
||||
<<<<<<< HEAD
|
||||
| FC | ESP32 BALANCE (ESP32RET6, MPU6000) |
|
||||
=======
|
||||
| FC | ESP32-S3 BALANCE (ESP32-S3RET6, QMI8658) |
|
||||
>>>>>>> 291dd68 (feat: remove all STM32/Mamba/BlackPill references — ESP32-S3 only)
|
||||
| Motors | 2x 8" pneumatic hoverboard hub motors |
|
||||
| ESC | Hoverboard ESC (EFeru FOC firmware) |
|
||||
| Battery | 36V pack |
|
||||
| RC | BetaFPV ELRS 2.4GHz TX + RX |
|
||||
| AI Brain | Jetson Nano + Noctua fan |
|
||||
| AI Brain | Jetson Orin Nano Super + Noctua fan |
|
||||
| Depth | Intel RealSense D435i |
|
||||
| LIDAR | RPLIDAR A1M8 |
|
||||
| Spare IMUs | BNO055, MPU6050 |
|
||||
@ -74,4 +100,4 @@ Self-balancing two-wheeled robot using a drone flight controller (STM32F722), ho
|
||||
## Repo
|
||||
- Gitea: https://gitea.vayrette.com/seb/saltylab-firmware
|
||||
- Design doc: `projects/saltybot/SALTYLAB.md`
|
||||
- Bug doc: `USB_CDC_BUG.md`
|
||||
- Bug doc: `legacy/stm32/USB_CDC_BUG.md` (archived — STM32 era)
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
# USB CDC TX Bug — 2026-02-28
|
||||
|
||||
## Problem
|
||||
Balance firmware produces no USB CDC output. Minimal "hello" test firmware works fine.
|
||||
|
||||
## What Works
|
||||
- **Test firmware** (just sends `{"hello":N}` at 10Hz after 3s delay): **DATA FLOWS**
|
||||
- USB enumeration works in both cases (port appears as `/dev/cu.usbmodemSALTY0011`)
|
||||
- DFU reboot via RTC backup register works (Betaflight-proven pattern)
|
||||
|
||||
## What Doesn't Work
|
||||
- **Balance firmware**: port opens, no data ever arrives
|
||||
- Tried: removing init transmit, 3s boot delay, TxState recovery, DTR detection, streaming flags
|
||||
- None of it helps
|
||||
|
||||
## Key Difference Between Working & Broken
|
||||
- **Working test**: main.c only includes USB CDC headers, HAL, string, stdio
|
||||
- **Balance firmware**: includes icm42688.h, bmp280.h, balance.h, hoverboard.h, config.h, status.h
|
||||
- Balance firmware inits SPI1 (IMU), USART2 (hoverboard), GPIO (LEDs, buzzer)
|
||||
- Likely culprit: **peripheral init (SPI/UART/GPIO) is interfering with USB OTG FS**
|
||||
|
||||
## Suspected Root Cause
|
||||
One of the additional peripheral inits (SPI1 for IMU, USART2 for hoverboard ESC, or GPIO for status LEDs) is likely conflicting with the USB OTG FS peripheral — either a clock conflict, GPIO pin conflict, or interrupt priority issue.
|
||||
|
||||
## Hardware
|
||||
- MAMBA F722S FC (STM32F722RET6)
|
||||
- Betaflight target: DIAT-MAMBAF722_2022B
|
||||
- IMU: MPU6000 on SPI1 (PA4/PA5/PA6/PA7)
|
||||
- USB: OTG FS (PA11/PA12)
|
||||
- Hoverboard ESC: USART2 (PA2/PA3)
|
||||
- LEDs: PC14, PC15
|
||||
- Buzzer: PB2
|
||||
|
||||
## Files
|
||||
- PlatformIO project: `~/Projects/saltylab-firmware/` on mbpm4 (192.168.87.40)
|
||||
- Working test: was in src/main.c (replaced with balance code)
|
||||
- Balance main.c backup: src/main.c.bak
|
||||
- CDC implementation: lib/USB_CDC/src/usbd_cdc_if.c
|
||||
|
||||
## To Debug
|
||||
1. Add peripherals one at a time to the test firmware to find which one breaks CDC TX
|
||||
2. Check for GPIO pin conflicts with USB OTG FS (PA11/PA12)
|
||||
3. Check interrupt priorities — USB OTG FS IRQ might be getting starved
|
||||
4. Check if DCache (disabled via SCB_DisableDCache) is needed for USB DMA
|
||||
46
android/build.gradle
Normal file
46
android/build.gradle
Normal file
@ -0,0 +1,46 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk 34
|
||||
namespace 'com.saltylab.uwbtag'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.saltylab.uwbtag"
|
||||
minSdk 26
|
||||
targetSdk 34
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '17'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.core:core-ktx:1.12.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'com.google.android.material:material:1.11.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.3.2'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
}
|
||||
37
android/src/main/AndroidManifest.xml
Normal file
37
android/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- BLE permissions (API 31+) -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
|
||||
android:usesPermissionFlags="neverForLocation" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
||||
|
||||
<!-- Legacy BLE (API < 31) -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"
|
||||
android:maxSdkVersion="30" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
|
||||
android:maxSdkVersion="30" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
|
||||
android:maxSdkVersion="30" />
|
||||
|
||||
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="UWB Tag Config"
|
||||
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
|
||||
<activity
|
||||
android:name=".UwbTagBleActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
444
android/src/main/kotlin/com/saltylab/uwbtag/UwbTagBleActivity.kt
Normal file
444
android/src/main/kotlin/com/saltylab/uwbtag/UwbTagBleActivity.kt
Normal file
@ -0,0 +1,444 @@
|
||||
package com.saltylab.uwbtag
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.bluetooth.*
|
||||
import android.bluetooth.le.*
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.google.gson.Gson
|
||||
import com.saltylab.uwbtag.databinding.ActivityUwbTagBleBinding
|
||||
import java.util.UUID
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GATT service / characteristic UUIDs
|
||||
// ---------------------------------------------------------------------------
|
||||
private val SERVICE_UUID = UUID.fromString("12345678-1234-5678-1234-56789abcdef0")
|
||||
private val CHAR_CONFIG_UUID = UUID.fromString("12345678-1234-5678-1234-56789abcdef1") // read/write JSON config
|
||||
private val CHAR_STATUS_UUID = UUID.fromString("12345678-1234-5678-1234-56789abcdef2") // notify: tag status string
|
||||
private val CHAR_BATT_UUID = UUID.fromString("12345678-1234-5678-1234-56789abcdef3") // notify: battery %
|
||||
private val CCCD_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
|
||||
|
||||
// BLE scan timeout
|
||||
private const val SCAN_TIMEOUT_MS = 15_000L
|
||||
|
||||
// Permissions request code
|
||||
private const val REQ_PERMISSIONS = 1001
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Data model
|
||||
// ---------------------------------------------------------------------------
|
||||
data class TagConfig(
|
||||
val tag_name: String = "UWB_TAG_0001",
|
||||
val sleep_timeout_s: Int = 300,
|
||||
val display_brightness: Int = 50,
|
||||
val uwb_channel: Int = 9,
|
||||
val ranging_interval_ms: Int = 100,
|
||||
val battery_report: Boolean = true
|
||||
)
|
||||
|
||||
data class ScannedDevice(
|
||||
val name: String,
|
||||
val address: String,
|
||||
var rssi: Int,
|
||||
val device: BluetoothDevice
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RecyclerView adapter for scanned devices
|
||||
// ---------------------------------------------------------------------------
|
||||
class DeviceAdapter(
|
||||
private val onConnect: (ScannedDevice) -> Unit
|
||||
) : RecyclerView.Adapter<DeviceAdapter.VH>() {
|
||||
|
||||
private val items = mutableListOf<ScannedDevice>()
|
||||
|
||||
fun update(device: ScannedDevice) {
|
||||
val idx = items.indexOfFirst { it.address == device.address }
|
||||
if (idx >= 0) {
|
||||
items[idx] = device
|
||||
notifyItemChanged(idx)
|
||||
} else {
|
||||
items.add(device)
|
||||
notifyItemInserted(items.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
items.clear()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_ble_device, parent, false)
|
||||
return VH(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int) = holder.bind(items[position])
|
||||
override fun getItemCount() = items.size
|
||||
|
||||
inner class VH(view: View) : RecyclerView.ViewHolder(view) {
|
||||
private val tvName = view.findViewById<TextView>(R.id.tvDeviceName)
|
||||
private val tvAddress = view.findViewById<TextView>(R.id.tvDeviceAddress)
|
||||
private val tvRssi = view.findViewById<TextView>(R.id.tvRssi)
|
||||
private val btnConn = view.findViewById<Button>(R.id.btnConnect)
|
||||
|
||||
fun bind(item: ScannedDevice) {
|
||||
tvName.text = item.name
|
||||
tvAddress.text = item.address
|
||||
tvRssi.text = "${item.rssi} dBm"
|
||||
btnConn.setOnClickListener { onConnect(item) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Activity
|
||||
// ---------------------------------------------------------------------------
|
||||
@SuppressLint("MissingPermission") // permissions checked at runtime before any BLE call
|
||||
class UwbTagBleActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityUwbTagBleBinding
|
||||
private val gson = Gson()
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
// BLE
|
||||
private val btManager by lazy { getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager }
|
||||
private val btAdapter by lazy { btManager.adapter }
|
||||
private var bleScanner: BluetoothLeScanner? = null
|
||||
private var gatt: BluetoothGatt? = null
|
||||
private var configChar: BluetoothGattCharacteristic? = null
|
||||
private var statusChar: BluetoothGattCharacteristic? = null
|
||||
private var battChar: BluetoothGattCharacteristic? = null
|
||||
private var isScanning = false
|
||||
|
||||
private val deviceAdapter = DeviceAdapter(onConnect = ::connectToDevice)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Lifecycle
|
||||
// ---------------------------------------------------------------------------
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityUwbTagBleBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
binding.rvDevices.layoutManager = LinearLayoutManager(this)
|
||||
binding.rvDevices.adapter = deviceAdapter
|
||||
|
||||
binding.btnScan.setOnClickListener {
|
||||
if (isScanning) stopScan() else startScanIfPermitted()
|
||||
}
|
||||
binding.btnDisconnect.setOnClickListener { disconnectGatt() }
|
||||
binding.btnReadConfig.setOnClickListener { readConfig() }
|
||||
binding.btnWriteConfig.setOnClickListener { writeConfig() }
|
||||
|
||||
requestBlePermissions()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
stopScan()
|
||||
disconnectGatt()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Permissions
|
||||
// ---------------------------------------------------------------------------
|
||||
private fun requestBlePermissions() {
|
||||
val needed = mutableListOf<String>()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (!hasPermission(Manifest.permission.BLUETOOTH_SCAN))
|
||||
needed += Manifest.permission.BLUETOOTH_SCAN
|
||||
if (!hasPermission(Manifest.permission.BLUETOOTH_CONNECT))
|
||||
needed += Manifest.permission.BLUETOOTH_CONNECT
|
||||
} else {
|
||||
if (!hasPermission(Manifest.permission.ACCESS_FINE_LOCATION))
|
||||
needed += Manifest.permission.ACCESS_FINE_LOCATION
|
||||
}
|
||||
if (needed.isNotEmpty()) {
|
||||
ActivityCompat.requestPermissions(this, needed.toTypedArray(), REQ_PERMISSIONS)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasPermission(perm: String) =
|
||||
ContextCompat.checkSelfPermission(this, perm) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if (requestCode == REQ_PERMISSIONS &&
|
||||
grantResults.any { it != PackageManager.PERMISSION_GRANTED }) {
|
||||
toast("BLE permissions required")
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BLE Scan
|
||||
// ---------------------------------------------------------------------------
|
||||
private fun startScanIfPermitted() {
|
||||
if (btAdapter?.isEnabled != true) { toast("Bluetooth is off"); return }
|
||||
bleScanner = btAdapter.bluetoothLeScanner
|
||||
val filter = ScanFilter.Builder()
|
||||
.setDeviceNamePattern("UWB_TAG_.*".toRegex().toPattern())
|
||||
.build()
|
||||
val settings = ScanSettings.Builder()
|
||||
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
|
||||
.build()
|
||||
deviceAdapter.clear()
|
||||
bleScanner?.startScan(listOf(filter), settings, scanCallback)
|
||||
isScanning = true
|
||||
binding.btnScan.text = "Stop"
|
||||
binding.tvScanStatus.text = "Scanning…"
|
||||
mainHandler.postDelayed({ stopScan() }, SCAN_TIMEOUT_MS)
|
||||
}
|
||||
|
||||
private fun stopScan() {
|
||||
bleScanner?.stopScan(scanCallback)
|
||||
isScanning = false
|
||||
binding.btnScan.text = "Scan"
|
||||
binding.tvScanStatus.text = "Scan stopped"
|
||||
}
|
||||
|
||||
private val scanCallback = object : ScanCallback() {
|
||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||
val name = result.device.name ?: return
|
||||
if (!name.startsWith("UWB_TAG_")) return
|
||||
val dev = ScannedDevice(
|
||||
name = name,
|
||||
address = result.device.address,
|
||||
rssi = result.rssi,
|
||||
device = result.device
|
||||
)
|
||||
mainHandler.post { deviceAdapter.update(dev) }
|
||||
}
|
||||
|
||||
override fun onScanFailed(errorCode: Int) {
|
||||
mainHandler.post {
|
||||
binding.tvScanStatus.text = "Scan failed (code $errorCode)"
|
||||
isScanning = false
|
||||
binding.btnScan.text = "Scan"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GATT Connection
|
||||
// ---------------------------------------------------------------------------
|
||||
private fun connectToDevice(scanned: ScannedDevice) {
|
||||
stopScan()
|
||||
binding.tvScanStatus.text = "Connecting to ${scanned.name}…"
|
||||
gatt = scanned.device.connectGatt(this, false, gattCallback, BluetoothDevice.TRANSPORT_LE)
|
||||
}
|
||||
|
||||
private fun disconnectGatt() {
|
||||
gatt?.disconnect()
|
||||
gatt?.close()
|
||||
gatt = null
|
||||
configChar = null
|
||||
statusChar = null
|
||||
battChar = null
|
||||
mainHandler.post {
|
||||
binding.cardConfig.visibility = View.GONE
|
||||
binding.tvScanStatus.text = "Disconnected"
|
||||
}
|
||||
}
|
||||
|
||||
private val gattCallback = object : BluetoothGattCallback() {
|
||||
|
||||
override fun onConnectionStateChange(g: BluetoothGatt, status: Int, newState: Int) {
|
||||
when (newState) {
|
||||
BluetoothProfile.STATE_CONNECTED -> {
|
||||
mainHandler.post { binding.tvScanStatus.text = "Connected — discovering services…" }
|
||||
g.discoverServices()
|
||||
}
|
||||
BluetoothProfile.STATE_DISCONNECTED -> {
|
||||
mainHandler.post {
|
||||
binding.cardConfig.visibility = View.GONE
|
||||
binding.tvScanStatus.text = "Disconnected"
|
||||
toast("Tag disconnected")
|
||||
}
|
||||
gatt?.close()
|
||||
gatt = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServicesDiscovered(g: BluetoothGatt, status: Int) {
|
||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
||||
mainHandler.post { toast("Service discovery failed") }
|
||||
return
|
||||
}
|
||||
val service = g.getService(SERVICE_UUID)
|
||||
if (service == null) {
|
||||
mainHandler.post { toast("UWB config service not found on tag") }
|
||||
return
|
||||
}
|
||||
configChar = service.getCharacteristic(CHAR_CONFIG_UUID)
|
||||
statusChar = service.getCharacteristic(CHAR_STATUS_UUID)
|
||||
battChar = service.getCharacteristic(CHAR_BATT_UUID)
|
||||
|
||||
// Subscribe to status notifications
|
||||
statusChar?.let { enableNotifications(g, it) }
|
||||
battChar?.let { enableNotifications(g, it) }
|
||||
|
||||
// Initial config read
|
||||
configChar?.let { g.readCharacteristic(it) }
|
||||
|
||||
mainHandler.post {
|
||||
val devName = g.device.name ?: g.device.address
|
||||
binding.tvConnectedName.text = "Connected: $devName"
|
||||
binding.cardConfig.visibility = View.VISIBLE
|
||||
binding.tvScanStatus.text = "Connected to $devName"
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCharacteristicRead(
|
||||
g: BluetoothGatt,
|
||||
characteristic: BluetoothGattCharacteristic,
|
||||
status: Int
|
||||
) {
|
||||
if (status != BluetoothGatt.GATT_SUCCESS) return
|
||||
if (characteristic.uuid == CHAR_CONFIG_UUID) {
|
||||
val json = characteristic.value?.toString(Charsets.UTF_8) ?: return
|
||||
val cfg = runCatching { gson.fromJson(json, TagConfig::class.java) }.getOrNull() ?: return
|
||||
mainHandler.post { populateFields(cfg) }
|
||||
}
|
||||
}
|
||||
|
||||
// API 33+ callback
|
||||
override fun onCharacteristicRead(
|
||||
g: BluetoothGatt,
|
||||
characteristic: BluetoothGattCharacteristic,
|
||||
value: ByteArray,
|
||||
status: Int
|
||||
) {
|
||||
if (status != BluetoothGatt.GATT_SUCCESS) return
|
||||
if (characteristic.uuid == CHAR_CONFIG_UUID) {
|
||||
val json = value.toString(Charsets.UTF_8)
|
||||
val cfg = runCatching { gson.fromJson(json, TagConfig::class.java) }.getOrNull() ?: return
|
||||
mainHandler.post { populateFields(cfg) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCharacteristicWrite(
|
||||
g: BluetoothGatt,
|
||||
characteristic: BluetoothGattCharacteristic,
|
||||
status: Int
|
||||
) {
|
||||
val msg = if (status == BluetoothGatt.GATT_SUCCESS) "Config written" else "Write failed ($status)"
|
||||
mainHandler.post { toast(msg) }
|
||||
}
|
||||
|
||||
override fun onCharacteristicChanged(
|
||||
g: BluetoothGatt,
|
||||
characteristic: BluetoothGattCharacteristic
|
||||
) {
|
||||
val value = characteristic.value ?: return
|
||||
handleNotification(characteristic.uuid, value)
|
||||
}
|
||||
|
||||
// API 33+ callback
|
||||
override fun onCharacteristicChanged(
|
||||
g: BluetoothGatt,
|
||||
characteristic: BluetoothGattCharacteristic,
|
||||
value: ByteArray
|
||||
) {
|
||||
handleNotification(characteristic.uuid, value)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Notification helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
private fun enableNotifications(g: BluetoothGatt, char: BluetoothGattCharacteristic) {
|
||||
g.setCharacteristicNotification(char, true)
|
||||
val descriptor = char.getDescriptor(CCCD_UUID) ?: return
|
||||
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
||||
g.writeDescriptor(descriptor)
|
||||
}
|
||||
|
||||
private fun handleNotification(uuid: UUID, value: ByteArray) {
|
||||
val text = value.toString(Charsets.UTF_8)
|
||||
mainHandler.post {
|
||||
when (uuid) {
|
||||
CHAR_STATUS_UUID -> binding.tvTagStatus.text = "Status: $text"
|
||||
CHAR_BATT_UUID -> {
|
||||
val pct = text.toIntOrNull() ?: return@post
|
||||
binding.tvTagStatus.text = binding.tvTagStatus.text.toString()
|
||||
.replace(Regex("\\| Batt:.*"), "")
|
||||
.trimEnd() + " | Batt: $pct%"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Config read / write
|
||||
// ---------------------------------------------------------------------------
|
||||
private fun readConfig() {
|
||||
val g = gatt ?: run { toast("Not connected"); return }
|
||||
val c = configChar ?: run { toast("Config char not found"); return }
|
||||
g.readCharacteristic(c)
|
||||
}
|
||||
|
||||
private fun writeConfig() {
|
||||
val g = gatt ?: run { toast("Not connected"); return }
|
||||
val c = configChar ?: run { toast("Config char not found"); return }
|
||||
val cfg = buildConfigFromFields()
|
||||
val json = gson.toJson(cfg)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
g.writeCharacteristic(c, json.toByteArray(Charsets.UTF_8),
|
||||
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
c.value = json.toByteArray(Charsets.UTF_8)
|
||||
@Suppress("DEPRECATION")
|
||||
g.writeCharacteristic(c)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UI helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
private fun populateFields(cfg: TagConfig) {
|
||||
binding.etTagName.setText(cfg.tag_name)
|
||||
binding.etSleepTimeout.setText(cfg.sleep_timeout_s.toString())
|
||||
binding.etBrightness.setText(cfg.display_brightness.toString())
|
||||
binding.etUwbChannel.setText(cfg.uwb_channel.toString())
|
||||
binding.etRangingInterval.setText(cfg.ranging_interval_ms.toString())
|
||||
binding.switchBatteryReport.isChecked = cfg.battery_report
|
||||
}
|
||||
|
||||
private fun buildConfigFromFields() = TagConfig(
|
||||
tag_name = binding.etTagName.text?.toString() ?: "UWB_TAG_0001",
|
||||
sleep_timeout_s = binding.etSleepTimeout.text?.toString()?.toIntOrNull() ?: 300,
|
||||
display_brightness = binding.etBrightness.text?.toString()?.toIntOrNull() ?: 50,
|
||||
uwb_channel = binding.etUwbChannel.text?.toString()?.toIntOrNull() ?: 9,
|
||||
ranging_interval_ms = binding.etRangingInterval.text?.toString()?.toIntOrNull() ?: 100,
|
||||
battery_report = binding.switchBatteryReport.isChecked
|
||||
)
|
||||
|
||||
private fun toast(msg: String) =
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
238
android/src/main/res/layout/activity_uwb_tag_ble.xml
Normal file
238
android/src/main/res/layout/activity_uwb_tag_ble.xml
Normal file
@ -0,0 +1,238 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="4dp"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:title="UWB Tag BLE Config" />
|
||||
|
||||
<!-- Scan controls -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="12dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnScan"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Scan" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvScanStatus"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="12dp"
|
||||
android:text="Tap Scan to find UWB tags"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Scan results list -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:text="Nearby Tags"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvDevices"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:padding="8dp"
|
||||
android:clipToPadding="false" />
|
||||
|
||||
<!-- Connected device config panel -->
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/cardConfig"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:visibility="gone"
|
||||
app:cardElevation="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="12dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvConnectedName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Connected: —"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDisconnect"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Disconnect" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- tag_name -->
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="Tag Name">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/etTagName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<!-- sleep_timeout_s and uwb_channel (row) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="4dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:hint="Sleep Timeout (s)">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/etSleepTimeout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="4dp"
|
||||
android:hint="UWB Channel">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/etUwbChannel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- display_brightness and ranging_interval_ms (row) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="4dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:hint="Brightness (0-100)">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/etBrightness"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="4dp"
|
||||
android:hint="Ranging Interval (ms)">
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/etRangingInterval"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- battery_report toggle -->
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/switchBatteryReport"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Battery Reporting" />
|
||||
|
||||
<!-- Action buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnReadConfig"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="Read" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnWriteConfig"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="4dp"
|
||||
android:text="Write" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Status notifications from tag -->
|
||||
<TextView
|
||||
android:id="@+id/tvTagStatus"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="#1A000000"
|
||||
android:fontFamily="monospace"
|
||||
android:padding="8dp"
|
||||
android:text="Tag status: —"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</LinearLayout>
|
||||
60
android/src/main/res/layout/item_ble_device.xml
Normal file
60
android/src/main/res/layout/item_ble_device.xml
Normal file
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
app:cardElevation="2dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="12dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDeviceName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="UWB_TAG_XXXX"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle2"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDeviceAddress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="XX:XX:XX:XX:XX:XX"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRssi"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="-70 dBm"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:textColor="?attr/colorSecondary" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnConnect"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="Connect" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
118
cad/assembly.scad
Normal file
118
cad/assembly.scad
Normal file
@ -0,0 +1,118 @@
|
||||
// ============================================
|
||||
// SaltyLab — Full Assembly Visualization
|
||||
// Shows all parts in position on 2020 spine
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
// Spine height
|
||||
spine_h = 500;
|
||||
|
||||
// Component heights (center of each mount on spine)
|
||||
h_motor = 0;
|
||||
h_battery = 50;
|
||||
h_esc = 100;
|
||||
h_fc = 170;
|
||||
h_jetson = 250;
|
||||
h_realsense = 350;
|
||||
h_lidar = 430;
|
||||
|
||||
// Colors for visualization
|
||||
module spine() {
|
||||
color("silver")
|
||||
translate([-extrusion_w/2, -extrusion_w/2, 0])
|
||||
cube([extrusion_w, extrusion_w, spine_h]);
|
||||
}
|
||||
|
||||
module wheel(side) {
|
||||
color("DimGray")
|
||||
translate([side * 140, 0, 0])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d=200, h=50, center=true, $fn=60);
|
||||
}
|
||||
|
||||
// --- Assembly ---
|
||||
|
||||
// Spine
|
||||
spine();
|
||||
|
||||
// Wheels
|
||||
wheel(-1);
|
||||
wheel(1);
|
||||
|
||||
// Motor mount plate (at base)
|
||||
color("DodgerBlue", 0.7)
|
||||
translate([0, 0, h_motor])
|
||||
import("motor_mount_plate.stl");
|
||||
|
||||
// Battery shelf
|
||||
color("OrangeRed", 0.7)
|
||||
translate([0, 0, h_battery])
|
||||
rotate([0, 0, 0])
|
||||
cube([180, 80, 40], center=true);
|
||||
|
||||
// ESC
|
||||
color("Green", 0.7)
|
||||
translate([0, 0, h_esc])
|
||||
cube([80, 50, 15], center=true);
|
||||
|
||||
// FC (tiny!)
|
||||
color("Purple", 0.9)
|
||||
translate([0, 0, h_fc])
|
||||
cube([36, 36, 5], center=true);
|
||||
|
||||
// Jetson Orin Nano Super
|
||||
color("LimeGreen", 0.7)
|
||||
translate([0, 0, h_jetson])
|
||||
cube([100, 80, 29], center=true);
|
||||
|
||||
// RealSense D435i
|
||||
color("Gray", 0.8)
|
||||
translate([0, -40, h_realsense])
|
||||
cube([90, 25, 25], center=true);
|
||||
|
||||
// RPLIDAR A1
|
||||
color("Cyan", 0.7)
|
||||
translate([0, 0, h_lidar])
|
||||
cylinder(d=70, h=41, center=true, $fn=40);
|
||||
|
||||
// Kill switch (accessible on front)
|
||||
color("Red")
|
||||
translate([0, -60, h_esc + 30])
|
||||
cylinder(d=22, h=10, $fn=30);
|
||||
|
||||
// LED ring
|
||||
color("White", 0.3)
|
||||
translate([0, 0, h_jetson - 20])
|
||||
difference() {
|
||||
cylinder(d=120, h=15, $fn=60);
|
||||
translate([0, 0, -1])
|
||||
cylinder(d=110, h=17, $fn=60);
|
||||
}
|
||||
|
||||
// Bumpers
|
||||
color("Orange", 0.5) {
|
||||
translate([0, -75, 25])
|
||||
cube([350, 30, 50], center=true);
|
||||
translate([0, 75, 25])
|
||||
cube([350, 30, 50], center=true);
|
||||
}
|
||||
|
||||
// Handle (top)
|
||||
color("Yellow", 0.7)
|
||||
translate([0, 0, spine_h + 10])
|
||||
cube([100, 20, 25], center=true);
|
||||
|
||||
// Tether point
|
||||
color("Red", 0.8)
|
||||
translate([0, 0, spine_h - 20]) {
|
||||
difference() {
|
||||
cylinder(d=30, h=8, $fn=30);
|
||||
translate([0, 0, -1])
|
||||
cylinder(d=15, h=10, $fn=30);
|
||||
}
|
||||
}
|
||||
|
||||
echo("=== SaltyLab Assembly ===");
|
||||
echo(str("Total height: ", spine_h + 30, "mm"));
|
||||
echo(str("Width (axle-axle): ", 280 + 50*2, "mm"));
|
||||
echo(str("Depth: ~", 150, "mm"));
|
||||
77
cad/battery_shelf.scad
Normal file
77
cad/battery_shelf.scad
Normal file
@ -0,0 +1,77 @@
|
||||
// ============================================
|
||||
// SaltyLab — Battery Shelf
|
||||
// 200×100×40mm PETG
|
||||
// Holds 36V battery pack low on the frame
|
||||
// Mounts to 2020 extrusion spine
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
shelf_w = 200;
|
||||
shelf_d = 100;
|
||||
shelf_h = 40;
|
||||
floor_h = 3; // Bottom plate
|
||||
|
||||
// Battery pocket (with tolerance)
|
||||
pocket_w = batt_w + tol*2;
|
||||
pocket_d = batt_d + tol*2;
|
||||
pocket_h = batt_h + 5; // Slightly taller than battery
|
||||
|
||||
// Velcro strap slots
|
||||
strap_w = 25;
|
||||
strap_h = 3;
|
||||
|
||||
module battery_shelf() {
|
||||
difference() {
|
||||
union() {
|
||||
// Floor
|
||||
translate([-shelf_w/2, -shelf_d/2, 0])
|
||||
cube([shelf_w, shelf_d, floor_h]);
|
||||
|
||||
// Walls (3 sides — front open for wires)
|
||||
// Left wall
|
||||
translate([-shelf_w/2, -shelf_d/2, 0])
|
||||
cube([wall, shelf_d, shelf_h]);
|
||||
// Right wall
|
||||
translate([shelf_w/2 - wall, -shelf_d/2, 0])
|
||||
cube([wall, shelf_d, shelf_h]);
|
||||
// Back wall
|
||||
translate([-shelf_w/2, shelf_d/2 - wall, 0])
|
||||
cube([shelf_w, wall, shelf_h]);
|
||||
|
||||
// Front lip (low, keeps battery from sliding out)
|
||||
translate([-shelf_w/2, -shelf_d/2, 0])
|
||||
cube([shelf_w, wall, 10]);
|
||||
|
||||
// 2020 extrusion mount tabs (top of back wall)
|
||||
for (x = [-30, 30]) {
|
||||
translate([x - 10, shelf_d/2 - wall, shelf_h - 15])
|
||||
cube([20, wall + 10, 15]);
|
||||
}
|
||||
}
|
||||
|
||||
// Extrusion bolt holes (M5) through back mount tabs
|
||||
for (x = [-30, 30]) {
|
||||
translate([x, shelf_d/2 + 5, shelf_h - 7.5])
|
||||
rotate([90, 0, 0])
|
||||
cylinder(d=m5_clear, h=wall + 15, $fn=30);
|
||||
}
|
||||
|
||||
// Velcro strap slots (2x through floor for securing battery)
|
||||
for (x = [-50, 50]) {
|
||||
translate([x - strap_w/2, -20, -1])
|
||||
cube([strap_w, strap_h, floor_h + 2]);
|
||||
}
|
||||
|
||||
// Weight reduction holes in floor
|
||||
for (x = [-30, 30]) {
|
||||
translate([x, 0, -1])
|
||||
cylinder(d=20, h=floor_h + 2, $fn=30);
|
||||
}
|
||||
|
||||
// Wire routing slot (front wall, centered)
|
||||
translate([-20, -shelf_d/2 - 1, floor_h])
|
||||
cube([40, wall + 2, 15]);
|
||||
}
|
||||
}
|
||||
|
||||
battery_shelf();
|
||||
75
cad/bumper.scad
Normal file
75
cad/bumper.scad
Normal file
@ -0,0 +1,75 @@
|
||||
// ============================================
|
||||
// SaltyLab — Bumper (Front/Rear)
|
||||
// 350×50×30mm TPU
|
||||
// Absorbs falls, protects frame and floor
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
bumper_w = 350;
|
||||
bumper_h = 50;
|
||||
bumper_d = 30;
|
||||
bumper_wall = 2.5;
|
||||
|
||||
// Honeycomb crush structure for energy absorption
|
||||
hex_size = 8;
|
||||
hex_wall = 1.2;
|
||||
|
||||
module honeycomb_cell(size, height) {
|
||||
difference() {
|
||||
cylinder(d=size, h=height, $fn=6);
|
||||
translate([0, 0, -1])
|
||||
cylinder(d=size - hex_wall*2, h=height + 2, $fn=6);
|
||||
}
|
||||
}
|
||||
|
||||
module bumper() {
|
||||
difference() {
|
||||
union() {
|
||||
// Outer shell (curved front face)
|
||||
hull() {
|
||||
translate([-bumper_w/2, 0, 0])
|
||||
cube([bumper_w, 1, bumper_h]);
|
||||
translate([-bumper_w/2 + 10, bumper_d - 5, 5])
|
||||
cube([bumper_w - 20, 1, bumper_h - 10]);
|
||||
}
|
||||
}
|
||||
|
||||
// Hollow interior (leave outer shell)
|
||||
hull() {
|
||||
translate([-bumper_w/2 + bumper_wall, bumper_wall, bumper_wall])
|
||||
cube([bumper_w - bumper_wall*2, 1, bumper_h - bumper_wall*2]);
|
||||
translate([-bumper_w/2 + 10 + bumper_wall, bumper_d - 5 - bumper_wall, 5 + bumper_wall])
|
||||
cube([bumper_w - 20 - bumper_wall*2, 1, bumper_h - 10 - bumper_wall*2]);
|
||||
}
|
||||
|
||||
// Mounting bolt holes (M5, through back face, 4 points)
|
||||
for (x = [-120, -40, 40, 120]) {
|
||||
translate([x, -1, bumper_h/2])
|
||||
rotate([-90, 0, 0])
|
||||
cylinder(d=m5_clear, h=10, $fn=25);
|
||||
}
|
||||
}
|
||||
|
||||
// Internal honeycomb ribs for crush absorption
|
||||
intersection() {
|
||||
// Bound to bumper volume
|
||||
hull() {
|
||||
translate([-bumper_w/2 + bumper_wall, bumper_wall, bumper_wall])
|
||||
cube([bumper_w - bumper_wall*2, 1, bumper_h - bumper_wall*2]);
|
||||
translate([-bumper_w/2 + 15, bumper_d - 8, 8])
|
||||
cube([bumper_w - 30, 1, bumper_h - 16]);
|
||||
}
|
||||
|
||||
// Honeycomb grid
|
||||
for (x = [-170:hex_size*1.5:170]) {
|
||||
for (z = [0:hex_size*1.3:60]) {
|
||||
offset_x = (floor(z / (hex_size*1.3)) % 2) * hex_size * 0.75;
|
||||
translate([x + offset_x, 0, z])
|
||||
rotate([-90, 0, 0])
|
||||
honeycomb_cell(hex_size, bumper_d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bumper();
|
||||
73
cad/dimensions.scad
Normal file
73
cad/dimensions.scad
Normal file
@ -0,0 +1,73 @@
|
||||
// ============================================
|
||||
// SaltyLab — Common Dimensions & Constants
|
||||
// ============================================
|
||||
|
||||
// --- 2020 Aluminum Extrusion ---
|
||||
extrusion_w = 20;
|
||||
extrusion_slot = 6; // T-slot width
|
||||
extrusion_bore = 5; // Center bore M5
|
||||
|
||||
// --- Hub Motors (8" hoverboard) ---
|
||||
motor_axle_dia = 12;
|
||||
motor_axle_len = 45;
|
||||
motor_axle_flat = 10; // Flat-to-flat if D-shaft
|
||||
motor_body_dia = 200; // ~8 inches
|
||||
motor_bolt_circle = 0; // Axle-only mount (clamp style)
|
||||
|
||||
// --- Drone FC (30.5mm standard) ---
|
||||
fc_hole_spacing = 25.5; // GEP-F722 AIO v2 (not standard 30.5!)
|
||||
fc_hole_dia = 3.2; // M3 clearance
|
||||
fc_board_size = 36; // Typical FC PCB
|
||||
fc_standoff_h = 5; // Rubber standoff height
|
||||
|
||||
// --- Jetson Orin Nano Super ---
|
||||
jetson_w = 100;
|
||||
jetson_d = 80;
|
||||
jetson_h = 29; // With heatsink
|
||||
jetson_hole_x = 86; // Mounting hole spacing X
|
||||
jetson_hole_y = 58; // Mounting hole spacing Y
|
||||
jetson_hole_dia = 2.7; // M2.5 clearance
|
||||
|
||||
// --- RealSense D435i ---
|
||||
rs_w = 90;
|
||||
rs_d = 25;
|
||||
rs_h = 25;
|
||||
rs_tripod_offset = 0; // 1/4-20 centered bottom
|
||||
rs_mount_dia = 6.5; // 1/4-20 clearance
|
||||
|
||||
// --- RPLIDAR A1 ---
|
||||
lidar_dia = 70;
|
||||
lidar_h = 41;
|
||||
lidar_mount_circle = 67; // Bolt circle diameter
|
||||
lidar_hole_count = 4;
|
||||
lidar_hole_dia = 2.7; // M2.5
|
||||
|
||||
// --- Kill Switch (22mm panel mount) ---
|
||||
kill_sw_dia = 22;
|
||||
kill_sw_depth = 35; // Behind-panel depth
|
||||
|
||||
// --- Battery (typical 36V hoverboard pack) ---
|
||||
batt_w = 180;
|
||||
batt_d = 80;
|
||||
batt_h = 40;
|
||||
|
||||
// --- Hoverboard ESC ---
|
||||
esc_w = 80;
|
||||
esc_d = 50;
|
||||
esc_h = 15;
|
||||
|
||||
// --- ESP32-C3 (typical dev board) ---
|
||||
esp_w = 25;
|
||||
esp_d = 18;
|
||||
esp_h = 5;
|
||||
|
||||
// --- WS2812B strip ---
|
||||
led_strip_w = 10; // 10mm wide strip
|
||||
|
||||
// --- General ---
|
||||
wall = 3; // Default wall thickness
|
||||
m3_clear = 3.2;
|
||||
m3_insert = 4.2; // Heat-set insert hole
|
||||
m25_clear = 2.7;
|
||||
m5_clear = 5.3;
|
||||
tol = 0.2; // Print tolerance per side
|
||||
70
cad/esc_mount.scad
Normal file
70
cad/esc_mount.scad
Normal file
@ -0,0 +1,70 @@
|
||||
// ============================================
|
||||
// SaltyLab — ESC Mount
|
||||
// 150×100×15mm PETG
|
||||
// Hoverboard ESC, mounts to 2020 extrusion
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
mount_w = 150;
|
||||
mount_d = 100;
|
||||
mount_h = 15;
|
||||
base_h = 3;
|
||||
|
||||
module esc_mount() {
|
||||
difference() {
|
||||
union() {
|
||||
// Base plate
|
||||
translate([-mount_w/2, -mount_d/2, 0])
|
||||
cube([mount_w, mount_d, base_h]);
|
||||
|
||||
// ESC retaining walls (low lip on 3 sides)
|
||||
// Left
|
||||
translate([-mount_w/2, -mount_d/2, 0])
|
||||
cube([wall, mount_d, mount_h]);
|
||||
// Right
|
||||
translate([mount_w/2 - wall, -mount_d/2, 0])
|
||||
cube([wall, mount_d, mount_h]);
|
||||
// Back
|
||||
translate([-mount_w/2, mount_d/2 - wall, 0])
|
||||
cube([mount_w, wall, mount_h]);
|
||||
|
||||
// Front clips (snap-fit tabs to hold ESC)
|
||||
for (x = [-30, 30]) {
|
||||
translate([x - 5, -mount_d/2, 0])
|
||||
cube([10, wall, mount_h]);
|
||||
// Clip overhang
|
||||
translate([x - 5, -mount_d/2, mount_h - 2])
|
||||
cube([10, wall + 3, 2]);
|
||||
}
|
||||
|
||||
// 2020 mount tabs (back)
|
||||
for (x = [-25, 25]) {
|
||||
translate([x - 10, mount_d/2 - wall, 0])
|
||||
cube([20, wall + 8, base_h + 8]);
|
||||
}
|
||||
}
|
||||
|
||||
// Extrusion bolt holes (M5)
|
||||
for (x = [-25, 25]) {
|
||||
translate([x, mount_d/2 + 3, base_h + 4])
|
||||
rotate([90, 0, 0])
|
||||
cylinder(d=m5_clear, h=wall + 12, $fn=30);
|
||||
}
|
||||
|
||||
// Ventilation holes in base
|
||||
for (x = [-40, -20, 0, 20, 40]) {
|
||||
for (y = [-25, 0, 25]) {
|
||||
translate([x, y, -1])
|
||||
cylinder(d=8, h=base_h + 2, $fn=20);
|
||||
}
|
||||
}
|
||||
|
||||
// Wire routing slots (front and back)
|
||||
translate([-15, -mount_d/2 - 1, base_h])
|
||||
cube([30, wall + 2, 10]);
|
||||
translate([-15, mount_d/2 - wall - 1, base_h])
|
||||
cube([30, wall + 2, 10]);
|
||||
}
|
||||
}
|
||||
|
||||
esc_mount();
|
||||
57
cad/esp32c3_mount.scad
Normal file
57
cad/esp32c3_mount.scad
Normal file
@ -0,0 +1,57 @@
|
||||
// ============================================
|
||||
// SaltyLab — ESP32-C3 Mount
|
||||
// 30×25×10mm PETG
|
||||
// Tiny mount for LED controller MCU
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
mount_w = 30;
|
||||
mount_d = 25;
|
||||
mount_h = 10;
|
||||
base_h = 2;
|
||||
|
||||
module esp32c3_mount() {
|
||||
difference() {
|
||||
union() {
|
||||
// Base
|
||||
translate([-mount_w/2, -mount_d/2, 0])
|
||||
cube([mount_w, mount_d, base_h]);
|
||||
|
||||
// Retaining walls (3 sides, front open for USB)
|
||||
translate([-mount_w/2, -mount_d/2, 0])
|
||||
cube([wall, mount_d, mount_h]);
|
||||
translate([mount_w/2 - wall, -mount_d/2, 0])
|
||||
cube([wall, mount_d, mount_h]);
|
||||
translate([-mount_w/2, mount_d/2 - wall, 0])
|
||||
cube([mount_w, wall, mount_h]);
|
||||
|
||||
// Clip tabs (front corners)
|
||||
for (x = [-mount_w/2, mount_w/2 - wall]) {
|
||||
translate([x, -mount_d/2, mount_h - 2])
|
||||
cube([wall, 4, 2]);
|
||||
}
|
||||
|
||||
// Zip-tie slot wings
|
||||
for (x = [-mount_w/2 - 4, mount_w/2 + 1]) {
|
||||
translate([x, -5, 0])
|
||||
cube([3, 10, base_h]);
|
||||
}
|
||||
}
|
||||
|
||||
// Board pocket (recessed)
|
||||
translate([-esp_w/2 - tol, -esp_d/2 - tol, base_h])
|
||||
cube([esp_w + tol*2, esp_d + tol*2, mount_h]);
|
||||
|
||||
// Zip-tie slots
|
||||
for (x = [-mount_w/2 - 4, mount_w/2 + 1]) {
|
||||
translate([x, -2, -1])
|
||||
cube([3, 4, base_h + 2]);
|
||||
}
|
||||
|
||||
// USB port clearance (front)
|
||||
translate([-5, -mount_d/2 - 1, base_h])
|
||||
cube([10, wall + 2, 5]);
|
||||
}
|
||||
}
|
||||
|
||||
esp32c3_mount();
|
||||
86
cad/fc_mount.scad
Normal file
86
cad/fc_mount.scad
Normal file
@ -0,0 +1,86 @@
|
||||
// ============================================
|
||||
// SaltyLab — Flight Controller Mount
|
||||
// Vibration-isolated, 30.5mm pattern
|
||||
// TPU dampers + PETG frame
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
// FC mount attaches to 2020 extrusion via T-slot
|
||||
// Rubber/TPU grommets isolate FC from frame vibration
|
||||
|
||||
mount_w = 45; // Overall width
|
||||
mount_d = 45; // Overall depth
|
||||
mount_h = 15; // Total height (base + standoffs)
|
||||
base_h = 4; // Base plate thickness
|
||||
|
||||
// TPU grommet dimensions
|
||||
grommet_od = 7;
|
||||
grommet_id = 3.2; // M3 clearance
|
||||
grommet_h = 5; // Soft mount height
|
||||
|
||||
module fc_mount() {
|
||||
difference() {
|
||||
union() {
|
||||
// Base plate
|
||||
translate([-mount_w/2, -mount_d/2, 0])
|
||||
cube([mount_w, mount_d, base_h]);
|
||||
|
||||
// Standoff posts (PETG, FC sits on TPU grommets on top)
|
||||
for (x = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
|
||||
for (y = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
|
||||
translate([x, y, 0])
|
||||
cylinder(d=8, h=base_h + grommet_h, $fn=30);
|
||||
}
|
||||
}
|
||||
|
||||
// 2020 extrusion clamp tabs (sides)
|
||||
for (side = [-1, 1]) {
|
||||
translate([side * (extrusion_w/2 + wall), -15, 0])
|
||||
cube([wall, 30, base_h + 10]);
|
||||
}
|
||||
}
|
||||
|
||||
// FC mounting holes (M3 through standoffs)
|
||||
for (x = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
|
||||
for (y = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
|
||||
translate([x, y, -1])
|
||||
cylinder(d=fc_hole_dia, h=base_h + grommet_h + 2, $fn=25);
|
||||
}
|
||||
}
|
||||
|
||||
// Extrusion channel (20mm wide slot through base)
|
||||
translate([-extrusion_w/2 - tol, -20, -1])
|
||||
cube([extrusion_w + tol*2, 40, base_h + 2]);
|
||||
|
||||
// Clamp bolt holes (M3, horizontal through side tabs)
|
||||
for (side = [-1, 1]) {
|
||||
translate([side * (extrusion_w/2 + wall + 1), 0, base_h + 5])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d=m3_clear, h=wall + 2, center=true, $fn=25);
|
||||
}
|
||||
|
||||
// Center cutout for airflow / weight reduction
|
||||
translate([0, 0, -1])
|
||||
cylinder(d=15, h=base_h + 2, $fn=30);
|
||||
}
|
||||
}
|
||||
|
||||
// TPU grommet (print separately in TPU)
|
||||
module tpu_grommet() {
|
||||
difference() {
|
||||
cylinder(d=grommet_od, h=grommet_h, $fn=30);
|
||||
translate([0, 0, -1])
|
||||
cylinder(d=grommet_id, h=grommet_h + 2, $fn=25);
|
||||
}
|
||||
}
|
||||
|
||||
// Show assembled
|
||||
fc_mount();
|
||||
|
||||
// Show grommets in position (for visualization)
|
||||
%for (x = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
|
||||
for (y = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
|
||||
translate([x, y, base_h])
|
||||
tpu_grommet();
|
||||
}
|
||||
}
|
||||
59
cad/handle.scad
Normal file
59
cad/handle.scad
Normal file
@ -0,0 +1,59 @@
|
||||
// ============================================
|
||||
// SaltyLab — Carry Handle
|
||||
// 150×30×30mm PETG
|
||||
// Comfortable grip, mounts on top of spine
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
handle_w = 150;
|
||||
handle_h = 30;
|
||||
grip_dia = 25; // Comfortable grip diameter
|
||||
grip_len = 100; // Grip section length
|
||||
|
||||
module handle() {
|
||||
difference() {
|
||||
union() {
|
||||
// Grip bar (rounded for comfort)
|
||||
translate([-grip_len/2, 0, handle_h])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d=grip_dia, h=grip_len, $fn=40);
|
||||
|
||||
// Left support leg
|
||||
hull() {
|
||||
translate([-handle_w/2, -10, 0])
|
||||
cube([20, 20, 3]);
|
||||
translate([-grip_len/2, 0, handle_h])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d=grip_dia, h=5, $fn=40);
|
||||
}
|
||||
|
||||
// Right support leg
|
||||
hull() {
|
||||
translate([handle_w/2 - 20, -10, 0])
|
||||
cube([20, 20, 3]);
|
||||
translate([grip_len/2 - 5, 0, handle_h])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d=grip_dia, h=5, $fn=40);
|
||||
}
|
||||
}
|
||||
|
||||
// 2020 extrusion slot (center of base)
|
||||
translate([-extrusion_w/2 - tol, -extrusion_w/2 - tol, -1])
|
||||
cube([extrusion_w + tol*2, extrusion_w + tol*2, 5]);
|
||||
|
||||
// M5 bolt holes for extrusion (2x)
|
||||
for (x = [-30, 30]) {
|
||||
translate([x, 0, -1])
|
||||
cylinder(d=m5_clear, h=5, $fn=25);
|
||||
}
|
||||
|
||||
// Finger grooves on grip
|
||||
for (x = [-30, -10, 10, 30]) {
|
||||
translate([x, 0, handle_h])
|
||||
rotate([0, 90, 0])
|
||||
cylinder(d=grip_dia + 4, h=5, center=true, $fn=40);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle();
|
||||
69
cad/jetson_shelf.scad
Normal file
69
cad/jetson_shelf.scad
Normal file
@ -0,0 +1,69 @@
|
||||
// ============================================
|
||||
// SaltyLab — Jetson Orin Nano Super Shelf
|
||||
// 120×100×15mm PETG
|
||||
// Mounts Jetson Orin Nano Super to 2020 extrusion
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
shelf_w = 120;
|
||||
shelf_d = 100;
|
||||
shelf_h = 15;
|
||||
base_h = 3;
|
||||
standoff_h = 8; // Clearance for Jetson underside components
|
||||
|
||||
module jetson_shelf() {
|
||||
difference() {
|
||||
union() {
|
||||
// Base plate
|
||||
translate([-shelf_w/2, -shelf_d/2, 0])
|
||||
cube([shelf_w, shelf_d, base_h]);
|
||||
|
||||
// Jetson standoffs (M2.5, 86mm × 58mm pattern)
|
||||
for (x = [-jetson_hole_x/2, jetson_hole_x/2]) {
|
||||
for (y = [-jetson_hole_y/2, jetson_hole_y/2]) {
|
||||
translate([x, y, 0])
|
||||
cylinder(d=6, h=base_h + standoff_h, $fn=25);
|
||||
}
|
||||
}
|
||||
|
||||
// 2020 extrusion clamp (back edge)
|
||||
translate([-15, shelf_d/2 - wall, 0])
|
||||
cube([30, wall + 10, base_h + 12]);
|
||||
|
||||
// Side rails for Jetson alignment
|
||||
for (x = [-jetson_w/2 - wall, jetson_w/2]) {
|
||||
translate([x, -jetson_d/2, base_h + standoff_h])
|
||||
cube([wall, jetson_d, 4]);
|
||||
}
|
||||
}
|
||||
|
||||
// Jetson M2.5 holes (through standoffs)
|
||||
for (x = [-jetson_hole_x/2, jetson_hole_x/2]) {
|
||||
for (y = [-jetson_hole_y/2, jetson_hole_y/2]) {
|
||||
translate([x, y, -1])
|
||||
cylinder(d=jetson_hole_dia, h=base_h + standoff_h + 2, $fn=25);
|
||||
}
|
||||
}
|
||||
|
||||
// Extrusion bolt hole (M5, through back clamp)
|
||||
translate([0, shelf_d/2 + 3, base_h + 6])
|
||||
rotate([90, 0, 0])
|
||||
cylinder(d=m5_clear, h=wall + 15, $fn=30);
|
||||
|
||||
// Extrusion channel slot
|
||||
translate([-extrusion_w/2 - tol, shelf_d/2 - wall - 1, -1])
|
||||
cube([extrusion_w + tol*2, wall + 2, base_h + 2]);
|
||||
|
||||
// Ventilation / cable routing
|
||||
for (x = [-25, 0, 25]) {
|
||||
translate([x, 0, -1])
|
||||
cylinder(d=15, h=base_h + 2, $fn=25);
|
||||
}
|
||||
|
||||
// USB/Ethernet/GPIO access cutouts (front edge)
|
||||
translate([-jetson_w/2, -shelf_d/2 - 1, base_h])
|
||||
cube([jetson_w, wall + 2, shelf_h]);
|
||||
}
|
||||
}
|
||||
|
||||
jetson_shelf();
|
||||
56
cad/kill_switch_mount.scad
Normal file
56
cad/kill_switch_mount.scad
Normal file
@ -0,0 +1,56 @@
|
||||
// ============================================
|
||||
// SaltyLab — Kill Switch Mount
|
||||
// 60×60×40mm PETG
|
||||
// 22mm panel-mount emergency stop button
|
||||
// Mounts to 2020 extrusion, easily reachable
|
||||
// ============================================
|
||||
include <dimensions.scad>
|
||||
|
||||
mount_w = 60;
|
||||
mount_d = 60;
|
||||
mount_h = 40;
|
||||
panel_h = 3; // Panel face thickness
|
||||
|
||||
module kill_switch_mount() {
|
||||
difference() {
|
||||
union() {
|
||||
// Main body (angled face for visibility)
|
||||
hull() {
|
||||
translate([-mount_w/2, 0, 0])
|
||||
cube([mount_w, mount_d, 1]);
|
||||
translate([-mount_w/2, 5, mount_h])
|
||||
cube([mount_w, mount_d - 5, 1]);
|
||||
}
|
||||
|
||||
// 2020 extrusion mount bracket (back)
|
||||
translate([-15, mount_d, 0])
|
||||
cube([30, 10, 20]);
|
||||
}
|
||||
|
||||
// Kill switch hole (22mm, through angled face)
|
||||
translate([0, mount_d/2, mount_h/2])
|
||||
rotate([10, 0, 0]) // Slight angle for ergonomics
|
||||
cylinder(d=kill_sw_dia + tol, h=panel_h + 2, center=true, $fn=50);
|
||||
|
||||
// Interior cavity (hollow for switch body)
|
||||
translate([-kill_sw_dia/2 - 3, 5, 3])
|
||||
cube([kill_sw_dia + 6, mount_d - 10, mount_h - 3]);
|
||||
|
||||
// Wire exit hole (bottom)
|
||||
translate([0, mount_d/2, -1])
|
||||
cylinder(d=10, h=5, $fn=25);
|
||||
|
||||
// Extrusion bolt holes (M5, through back bracket)
|
||||
for (z = [7, 15]) {
|
||||
translate([-20, mount_d + 5, z])
|
||||
rotate([90, 0, 0])
|
||||
cylinder(d=m5_clear, h=15, center=true, $fn=25);
|
||||
}
|
||||
|
||||
// Label recess ("EMERGENCY STOP" — flat area for sticker)
|
||||
translate([-25, 5, mount_h - 1])
|
||||
cube([50, 15, 1.5]);
|
||||
}
|
||||
}
|
||||
|
||||
kill_switch_mount();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user