Spaces:
Sleeping
Sleeping
Comprehensive README update with architecture, troubleshooting, and development history
Browse files
README.md
CHANGED
|
@@ -14,9 +14,39 @@ Web-based IDE for writing, verifying, and executing rmscript code on Reachy Mini
|
|
| 14 |
|
| 15 |
## Architecture
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
## Quick Start
|
| 22 |
|
|
@@ -77,12 +107,30 @@ uv run python app.py
|
|
| 77 |
To deploy this demo to HuggingFace Spaces:
|
| 78 |
|
| 79 |
1. **Prepare the repository structure:**
|
| 80 |
-
- Copy the `rmscript` and `reachy_mini` directories
|
| 81 |
```bash
|
| 82 |
cd rmscript_space_demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
cp -r ../rmscript ./rmscript
|
| 84 |
cp -r ../reachy_mini ./reachy_mini
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
```
|
|
|
|
| 86 |
- Your structure should be:
|
| 87 |
```
|
| 88 |
rmscript_space_demo/
|
|
@@ -91,8 +139,8 @@ To deploy this demo to HuggingFace Spaces:
|
|
| 91 |
βββ .dockerignore
|
| 92 |
βββ backend/
|
| 93 |
βββ frontend/
|
| 94 |
-
βββ rmscript/ β copied source
|
| 95 |
-
βββ reachy_mini/ β copied source (
|
| 96 |
```
|
| 97 |
|
| 98 |
2. **Create a new Space:**
|
|
@@ -109,7 +157,211 @@ To deploy this demo to HuggingFace Spaces:
|
|
| 109 |
|
| 110 |
## Development
|
| 111 |
|
| 112 |
-
|
| 113 |
-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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
## Architecture
|
| 16 |
|
| 17 |
+
### Components
|
| 18 |
+
|
| 19 |
+
- **Frontend** (`frontend/`): Pure HTML/CSS/JavaScript web IDE
|
| 20 |
+
- `index.html`: UI layout with embedded CSS styling
|
| 21 |
+
- `app.js`: Application logic, compilation API calls, robot communication
|
| 22 |
+
- Auto-detects environment (file:// for local, web server for production)
|
| 23 |
+
|
| 24 |
+
- **Backend** (`backend/`): FastAPI server (Python 3.11)
|
| 25 |
+
- `app.py`: REST API for rmscript compilation and validation
|
| 26 |
+
- Serves frontend files via static file mounting
|
| 27 |
+
- Runs on port 8001 (local) or port 7860 (HuggingFace Spaces)
|
| 28 |
+
|
| 29 |
+
- **Robot Daemon**: Reachy Mini daemon (expected on localhost:8000)
|
| 30 |
+
- REST API: `/api/move/goto` (with duration support)
|
| 31 |
+
- WebSocket API: `/api/move/ws/set_target` (streaming, no duration)
|
| 32 |
+
- State API: `/api/state/*` (robot current state)
|
| 33 |
+
|
| 34 |
+
### Communication Flow
|
| 35 |
+
|
| 36 |
+
1. **Script Verification/Compilation**:
|
| 37 |
+
- Frontend β Backend (`/api/verify` or `/api/compile`)
|
| 38 |
+
- Backend compiles rmscript using the rmscript package
|
| 39 |
+
- Returns IR (Intermediate Representation) + errors/warnings
|
| 40 |
+
|
| 41 |
+
2. **Script Execution** (Local):
|
| 42 |
+
- Frontend β Robot Daemon (`POST /api/move/goto`)
|
| 43 |
+
- Each IR action sent with duration and interpolation mode
|
| 44 |
+
- Proper timing with minimum-jerk interpolation
|
| 45 |
+
|
| 46 |
+
3. **Script Execution** (HuggingFace Spaces):
|
| 47 |
+
- Frontend β Robot Daemon (WebSocket `/api/move/ws/set_target`)
|
| 48 |
+
- Fallback due to HTTPS β HTTP localhost blocking
|
| 49 |
+
- No duration control - moves are instant
|
| 50 |
|
| 51 |
## Quick Start
|
| 52 |
|
|
|
|
| 107 |
To deploy this demo to HuggingFace Spaces:
|
| 108 |
|
| 109 |
1. **Prepare the repository structure:**
|
| 110 |
+
- Copy the `rmscript` and `reachy_mini` directories (without `.git` and binary files):
|
| 111 |
```bash
|
| 112 |
cd rmscript_space_demo
|
| 113 |
+
|
| 114 |
+
# Option 1: Using rsync (recommended - cleaner)
|
| 115 |
+
rsync -av --exclude='.git' --exclude='.venv' --exclude='__pycache__' \
|
| 116 |
+
--exclude='*.pyc' ../rmscript/ ./rmscript/
|
| 117 |
+
rsync -av --exclude='.git' --exclude='.venv' --exclude='__pycache__' \
|
| 118 |
+
--exclude='*.pyc' ../reachy_mini/ ./reachy_mini/
|
| 119 |
+
|
| 120 |
+
# Option 2: Using cp then cleanup
|
| 121 |
cp -r ../rmscript ./rmscript
|
| 122 |
cp -r ../reachy_mini ./reachy_mini
|
| 123 |
+
rm -rf ./rmscript/.git ./reachy_mini/.git
|
| 124 |
+
rm -rf ./rmscript/.venv ./reachy_mini/.venv
|
| 125 |
+
|
| 126 |
+
# Remove binary files that HuggingFace Spaces rejects
|
| 127 |
+
rm -rf ./reachy_mini/src/reachy_mini/assets/*.wav
|
| 128 |
+
rm -rf ./reachy_mini/src/reachy_mini/daemon/app/dashboard/static/fonts/*.ttf
|
| 129 |
+
rm -rf ./reachy_mini/docs ./reachy_mini/examples
|
| 130 |
+
rm -rf ./reachy_mini/src/reachy_mini/descriptions/reachy_mini/mjcf
|
| 131 |
+
rm -rf ./rmscript/examples ./rmscript/tests
|
| 132 |
```
|
| 133 |
+
|
| 134 |
- Your structure should be:
|
| 135 |
```
|
| 136 |
rmscript_space_demo/
|
|
|
|
| 139 |
βββ .dockerignore
|
| 140 |
βββ backend/
|
| 141 |
βββ frontend/
|
| 142 |
+
βββ rmscript/ β copied source (no .git, no binaries)
|
| 143 |
+
βββ reachy_mini/ β copied source (no .git, no binaries)
|
| 144 |
```
|
| 145 |
|
| 146 |
2. **Create a new Space:**
|
|
|
|
| 157 |
|
| 158 |
## Development
|
| 159 |
|
| 160 |
+
### File Structure
|
| 161 |
+
|
| 162 |
+
```
|
| 163 |
+
rmscript_space_demo/
|
| 164 |
+
βββ Dockerfile # Docker build config for HuggingFace Spaces
|
| 165 |
+
βββ .dockerignore # Excludes .git, .venv, __pycache__, etc.
|
| 166 |
+
βββ README.md # This file (includes HF Space metadata in YAML)
|
| 167 |
+
βββ backend/
|
| 168 |
+
β βββ app.py # FastAPI server (compilation + static file serving)
|
| 169 |
+
β βββ pyproject.toml # Python dependencies
|
| 170 |
+
βββ frontend/
|
| 171 |
+
βββ index.html # Web IDE UI (with embedded CSS)
|
| 172 |
+
βββ app.js # Frontend logic (compilation + execution)
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
### Key Implementation Details
|
| 176 |
+
|
| 177 |
+
**Matrix to Euler Conversion** (`frontend/app.js:328-355`):
|
| 178 |
+
- Converts 4x4 pose matrices (from rmscript IR) to euler angles (roll, pitch, yaw)
|
| 179 |
+
- Uses XYZ euler convention to match `scipy.spatial.transform.Rotation.as_euler("xyz")`
|
| 180 |
+
- Required because WebSocket API expects `{x, y, z, roll, pitch, yaw}` format
|
| 181 |
+
|
| 182 |
+
**Environment Detection** (`frontend/app.js:9-11`):
|
| 183 |
+
- Detects `file://` protocol β uses `http://localhost:8001` for backend
|
| 184 |
+
- Detects web server β uses relative URLs (same origin)
|
| 185 |
+
- Script loading path adapts similarly for `app.js` imports
|
| 186 |
+
|
| 187 |
+
**Execution Strategy** (`frontend/app.js:357-427`):
|
| 188 |
+
- **Tries** `POST /api/move/goto` with duration (works locally)
|
| 189 |
+
- **Catches** fetch failures β falls back to WebSocket (for Spaces)
|
| 190 |
+
- Logs warnings when fallback is used
|
| 191 |
+
|
| 192 |
+
### Modifying the Demo
|
| 193 |
+
|
| 194 |
+
**Frontend Changes:**
|
| 195 |
+
- Edit `frontend/app.js` for logic changes
|
| 196 |
+
- Edit `frontend/index.html` for UI/styling changes
|
| 197 |
+
- Test by opening `index.html` directly in browser (local mode)
|
| 198 |
+
|
| 199 |
+
**Backend Changes:**
|
| 200 |
+
- Edit `backend/app.py` for API changes
|
| 201 |
+
- Run locally: `cd backend && uv run python app.py`
|
| 202 |
+
- Test API at `http://localhost:8001/docs` (FastAPI Swagger UI)
|
| 203 |
+
|
| 204 |
+
**Deployment:**
|
| 205 |
+
- Changes auto-deploy when pushed to HuggingFace Space repo
|
| 206 |
+
- Build logs visible in Space's "Build" tab
|
| 207 |
+
- Runtime logs visible in Space's "Logs" tab
|
| 208 |
+
|
| 209 |
+
## Technical Notes
|
| 210 |
+
|
| 211 |
+
### Browser Security & Mixed Content
|
| 212 |
+
|
| 213 |
+
**The Problem:**
|
| 214 |
+
- HuggingFace Spaces serve content over HTTPS
|
| 215 |
+
- Robot daemon runs on `http://localhost:8000` (HTTP, not HTTPS)
|
| 216 |
+
- Modern browsers block HTTPS β HTTP requests (mixed content policy)
|
| 217 |
+
- This blocks `fetch()` to the robot's REST API
|
| 218 |
+
|
| 219 |
+
**Current Solution:**
|
| 220 |
+
- WebSocket connections are allowed (less strict security)
|
| 221 |
+
- Use WebSocket `/ws/set_target` as fallback
|
| 222 |
+
- Limitation: No duration control via WebSocket
|
| 223 |
+
|
| 224 |
+
**Why We Can't Fix This:**
|
| 225 |
+
- Robot daemon is on user's local machine
|
| 226 |
+
- Space backend runs on HuggingFace servers (can't reach localhost)
|
| 227 |
+
- Can't proxy through Space backend
|
| 228 |
+
- Can't get robot's current state for client-side interpolation
|
| 229 |
+
|
| 230 |
+
**Alternative Approaches (Not Implemented):**
|
| 231 |
+
1. **Client-side interpolation**: Would need current robot state (blocked by same security issue)
|
| 232 |
+
2. **Local HTTPS proxy**: Too complex for end users
|
| 233 |
+
3. **Run robot daemon on HTTPS**: Requires SSL certificates for localhost
|
| 234 |
+
|
| 235 |
+
### Deployment Gotchas
|
| 236 |
+
|
| 237 |
+
**Binary Files:**
|
| 238 |
+
- HuggingFace Spaces reject binary files (WAV, TTF, PNG, etc.)
|
| 239 |
+
- Must remove from `reachy_mini/` and `rmscript/` copies before pushing
|
| 240 |
+
- Already removed: docs/, examples/, assets/, fonts/
|
| 241 |
+
|
| 242 |
+
**OpenGL Dependencies:**
|
| 243 |
+
- OpenCV (cv2) requires system libraries: `libgl1`, `libglib2.0-0`, etc.
|
| 244 |
+
- Must install in Dockerfile (see lines 8-15)
|
| 245 |
+
- Package name changed from `libgl1-mesa-glx` β `libgl1` in newer Debian
|
| 246 |
+
|
| 247 |
+
**Git Submodules:**
|
| 248 |
+
- Don't copy `.git` directories from `rmscript/` and `reachy_mini/`
|
| 249 |
+
- Use `rsync --exclude='.git'` or remove after copying
|
| 250 |
+
- Otherwise Space treats them as submodules (causes issues)
|
| 251 |
+
|
| 252 |
+
## Future Improvements
|
| 253 |
+
|
| 254 |
+
### Potential Enhancements
|
| 255 |
+
|
| 256 |
+
1. **Sound & Picture Support:**
|
| 257 |
+
- Currently IR supports these actions but execution skips them
|
| 258 |
+
- Would need to implement in `frontend/app.js:executeScript()`
|
| 259 |
+
|
| 260 |
+
2. **Syntax Highlighting:**
|
| 261 |
+
- Add CodeMirror or Monaco Editor for better editing experience
|
| 262 |
+
- Custom rmscript syntax highlighting rules
|
| 263 |
+
|
| 264 |
+
3. **Save/Load Scripts:**
|
| 265 |
+
- localStorage for saving scripts in browser
|
| 266 |
+
- Or integrate with HuggingFace Datasets for cloud storage
|
| 267 |
+
|
| 268 |
+
4. **Real-time Error Highlighting:**
|
| 269 |
+
- Show errors inline in editor (like VS Code)
|
| 270 |
+
- Currently only shows in console panel
|
| 271 |
+
|
| 272 |
+
5. **Movement Visualization:**
|
| 273 |
+
- 3D preview of robot movements before execution
|
| 274 |
+
- Using Three.js or similar
|
| 275 |
+
|
| 276 |
+
6. **Execution Controls:**
|
| 277 |
+
- Pause/resume execution
|
| 278 |
+
- Step through script line-by-line
|
| 279 |
+
- Stop/cancel running script
|
| 280 |
+
|
| 281 |
+
### Known Issues
|
| 282 |
+
|
| 283 |
+
- **Spaces timing limitation**: Cannot be fixed without changing browser security or deployment architecture
|
| 284 |
+
- **Cached IR bug**: Fixed - now always compiles fresh editor content
|
| 285 |
+
- **Euler angle conversion**: Works but could add gimbal lock handling improvements
|
| 286 |
+
|
| 287 |
+
### Development History & Fixes
|
| 288 |
+
|
| 289 |
+
**Issues Fixed During Development:**
|
| 290 |
+
|
| 291 |
+
1. **Robot not executing moves** (2025-11-26):
|
| 292 |
+
- **Problem**: Robot daemon connected but moves didn't execute
|
| 293 |
+
- **Cause**: Frontend was extracting translation but hardcoding euler angles to 0
|
| 294 |
+
- **Fix**: Implemented `matrixToEulerXYZ()` to properly extract rotation from 4x4 matrices
|
| 295 |
+
- **Location**: `frontend/app.js:328-355`
|
| 296 |
+
|
| 297 |
+
2. **Modified scripts not executing** (2025-11-26):
|
| 298 |
+
- **Problem**: Editing script in editor didn't affect execution - same old script ran
|
| 299 |
+
- **Cause**: `executeScript()` was using cached IR instead of compiling fresh
|
| 300 |
+
- **Fix**: Always compile editor content before execution
|
| 301 |
+
- **Location**: `frontend/app.js:285-290`
|
| 302 |
+
|
| 303 |
+
3. **Local development broken after Space changes** (2025-11-26):
|
| 304 |
+
- **Problem**: Opening `index.html` locally didn't load `app.js`
|
| 305 |
+
- **Cause**: Changed script path to `/static/app.js` for Space deployment
|
| 306 |
+
- **Fix**: Auto-detect environment and load appropriate path
|
| 307 |
+
- **Location**: `frontend/index.html:320-329`
|
| 308 |
+
|
| 309 |
+
4. **Binary files rejected during Space deployment** (2025-11-26):
|
| 310 |
+
- **Problem**: HuggingFace push rejected due to WAV/TTF/PNG files
|
| 311 |
+
- **Cause**: HuggingFace Spaces don't allow binary files without LFS
|
| 312 |
+
- **Fix**: Remove docs, examples, assets from copied dependencies
|
| 313 |
+
- **Commands**: See deployment section step 1
|
| 314 |
+
|
| 315 |
+
5. **Docker build failing on Spaces** (2025-11-26):
|
| 316 |
+
- **Problem**: `libgl1-mesa-glx` package not found during build
|
| 317 |
+
- **Cause**: Package renamed in newer Debian (Trixie)
|
| 318 |
+
- **Fix**: Changed to `libgl1` in Dockerfile
|
| 319 |
+
- **Location**: `Dockerfile:10`
|
| 320 |
+
|
| 321 |
+
6. **Duration not respected in execution** (2025-11-26):
|
| 322 |
+
- **Problem**: All moves happened instantly regardless of specified duration
|
| 323 |
+
- **Cause**: Using WebSocket `/ws/set_target` which doesn't support duration
|
| 324 |
+
- **Fix**: Switch to REST API `POST /api/move/goto` with duration parameter
|
| 325 |
+
- **Location**: `frontend/app.js:394-405`
|
| 326 |
+
|
| 327 |
+
7. **Fetch failures on HuggingFace Spaces** (2025-11-26):
|
| 328 |
+
- **Problem**: "Failed to fetch" errors when executing on Space
|
| 329 |
+
- **Cause**: Browser mixed content policy blocks HTTPS β HTTP localhost
|
| 330 |
+
- **Fix**: Fallback to WebSocket when fetch fails (timing limitation accepted)
|
| 331 |
+
- **Location**: `frontend/app.js:407-426`
|
| 332 |
+
|
| 333 |
+
## Troubleshooting
|
| 334 |
+
|
| 335 |
+
**Backend won't start locally:**
|
| 336 |
+
```bash
|
| 337 |
+
# Make sure rmscript is installed
|
| 338 |
+
cd ../rmscript && uv sync
|
| 339 |
+
cd ../rmscript_space_demo/backend
|
| 340 |
+
|
| 341 |
+
# Install backend deps
|
| 342 |
+
uv sync
|
| 343 |
+
uv run python app.py
|
| 344 |
+
```
|
| 345 |
+
|
| 346 |
+
**Robot not connecting:**
|
| 347 |
+
- Check robot daemon is running: `curl http://localhost:8000/api/health`
|
| 348 |
+
- Check WebSocket connection in browser console
|
| 349 |
+
- Try reloading the page
|
| 350 |
+
|
| 351 |
+
**Space build fails:**
|
| 352 |
+
- Check build logs in Space's "Build" tab
|
| 353 |
+
- Common issues: binary files not removed, missing system dependencies
|
| 354 |
+
- Dockerfile may need updating for new Debian versions
|
| 355 |
+
|
| 356 |
+
**Compilation errors:**
|
| 357 |
+
- Check rmscript syntax in examples
|
| 358 |
+
- Use "Verify" button before "Execute"
|
| 359 |
+
- Check console for detailed error messages
|
| 360 |
+
|
| 361 |
+
## Credits
|
| 362 |
+
|
| 363 |
+
Built with:
|
| 364 |
+
- [rmscript](../rmscript/) - Kid-friendly robot programming language
|
| 365 |
+
- [reachy_mini](../reachy_mini/) - Reachy Mini SDK
|
| 366 |
+
- [FastAPI](https://fastapi.tiangolo.com/) - Backend framework
|
| 367 |
+
- [HuggingFace Spaces](https://huggingface.co/spaces) - Deployment platform
|