gpue commited on
Commit
be47e69
·
1 Parent(s): a091821

Enhance README.md with architecture and data flow details

Browse files

- Added a comprehensive architecture diagram illustrating the system components and their interactions.
- Included a detailed data flow description outlining user input, command processing, and state broadcasting.
- Expanded WebSocket event documentation to clarify client-server communication, including payload structures for commands and state updates.
- Updated HTTP endpoint descriptions for better clarity on usage.

Files changed (1) hide show
  1. README.md +168 -8
README.md CHANGED
@@ -153,6 +153,92 @@ docker run --gpus all -p 3004:3004 \
153
  - **Robot selector**: Switch between G1 and Spot
154
  - **Reset button**: Reset robot to standing pose
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  ## Project Structure
157
 
158
  ```
@@ -205,18 +291,92 @@ env = SpotEnv(controller_type='trot')
205
 
206
  ### WebSocket Events
207
 
208
- **Client to Server:**
209
- - `command`: `{vx, vy, vyaw}` - Velocity command
210
- - `reset`: Reset robot to initial pose
211
- - `switch_robot`: `{robot: "g1" | "spot"}` - Switch robot type
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
 
213
- **Server to Client:**
214
- - `state`: Robot state data (position, orientation, joint angles)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  ### HTTP Endpoints
217
 
218
- - `GET /` - Web interface
219
- - `GET /video_feed` - MJPEG video stream
 
 
 
 
 
 
 
220
 
221
  ## License
222
 
 
153
  - **Robot selector**: Switch between G1 and Spot
154
  - **Reset button**: Reset robot to standing pose
155
 
156
+ ## Architecture
157
+
158
+ ```
159
+ ┌─────────────────────────────────────────────────────────────────────────┐
160
+ │ Browser │
161
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
162
+ │ │ Video Player │ │ Control Panel │ │ State Display │ │
163
+ │ │ (MJPEG img) │ │ (buttons/keys) │ │ (joint data) │ │
164
+ │ └────────┬────────┘ └────────┬────────┘ └────────▲────────┘ │
165
+ └───────────┼──────────────────────┼──────────────────────┼──────────────┘
166
+ │ HTTP GET │ WebSocket │ WebSocket
167
+ │ /video_feed │ command/reset │ state
168
+ ▼ ▼ │
169
+ ┌─────────────────────────────────────────────────────────────────────────┐
170
+ │ mujoco_server.py │
171
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
172
+ │ │ Flask + WSGI │ │SocketIO Handler │ │ Render Thread │ │
173
+ │ │ HTTP endpoints │ │ cmd, reset, │ │ 60 FPS loop │ │
174
+ │ │ │ │ switch_robot │ │ MJPEG encode │ │
175
+ │ └─────────────────┘ └────────┬────────┘ └────────┬────────┘ │
176
+ │ │ │ │
177
+ │ ▼ ▼ │
178
+ │ ┌───────────────────────────────────┐ │
179
+ │ │ Active Environment (env) │ │
180
+ │ │ G1Env or SpotEnv (Gymnasium) │ │
181
+ │ └───────────────────────────────────┘ │
182
+ └─────────────────────────────────────────────────────────────────────────┘
183
+
184
+ │ env.step(action)
185
+
186
+ ┌─────────────────────────────────────────────────────────────────────────┐
187
+ │ Robot Environments │
188
+ │ │
189
+ │ ┌────────────────────────────┐ ┌────────────────────────────┐ │
190
+ │ │ G1Env │ │ SpotEnv │ │
191
+ │ │ ┌──────────────────────┐ │ │ ┌──────────────────────┐ │ │
192
+ │ │ │ MuJoCo Model (XML) │ │ │ │ MuJoCo Model (XML) │ │ │
193
+ │ │ │ g1_29dof.xml │ │ │ │ spot.xml │ │ │
194
+ │ │ └──────────────────────┘ │ │ └──────────────────────┘ │ │
195
+ │ │ ┌──────────────────────┐ │ │ ┌──────────────────────┐ │ │
196
+ │ │ │ Controller │ │ │ │ Controller │ │ │
197
+ │ │ │ rl_policy.py │ │ │ │ (selectable) │ │ │
198
+ │ │ │ (PyTorch .pt file) │ │ │ │ - mpc_gait.py │ │ │
199
+ │ │ └──────────────────────┘ │ │ │ - pympc_controller │ │ │
200
+ │ │ │ │ │ - trot_gait.py │ │ │
201
+ │ │ 29 DOF Humanoid │ │ └──────────────────────┘ │ │
202
+ │ │ - Torso, arms, legs │ │ │ │
203
+ │ │ - RL locomotion policy │ │ 12 DOF Quadruped │ │
204
+ │ └────────────────────────────┘ │ - 4 legs × 3 joints │ │
205
+ │ │ - Gait-based locomotion │ │
206
+ │ └────────────────────────────┘ │
207
+ └─────────────────────────────────────────────────────────────────────────┘
208
+
209
+ │ mujoco.mj_step()
210
+
211
+ ┌─────────────────────────────────────────────────────────────────────────┐
212
+ │ MuJoCo Physics Engine │
213
+ │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
214
+ │ │ Rigid Body │ │ Collision │ │ Rendering │ │
215
+ │ │ Dynamics │ │ Detection │ │ (OpenGL/ │ │
216
+ │ │ │ │ │ │ OSMesa/EGL) │ │
217
+ │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
218
+ └─────────────────────────────────────────────────────────────────────────┘
219
+ ```
220
+
221
+ ### Data Flow
222
+
223
+ 1. **User Input** → Browser captures keyboard/button events
224
+ 2. **WebSocket** → Commands sent as `{vx, vy, vyaw}` velocity targets
225
+ 3. **Controller** → Converts velocity commands to joint position targets
226
+ 4. **MuJoCo** → Simulates physics at 500Hz (0.002s timestep)
227
+ 5. **Renderer** → Captures frames at 60 FPS (native) or 30 FPS (Docker)
228
+ 6. **MJPEG Stream** → Frames encoded as JPEG and streamed to browser
229
+ 7. **State Broadcast** → Robot state sent via WebSocket at render rate
230
+
231
+ ### Controller Architecture
232
+
233
+ **G1 (Humanoid)**: Uses a pre-trained RL policy (PyTorch) that maps observations (body orientation, joint positions/velocities, commands) to joint position targets.
234
+
235
+ **Spot (Quadruped)**: Uses gait-based controllers:
236
+ - **MPC Gait**: Phase-based trot with feedback balance control
237
+ - **PyMPC**: Integrates Quadruped-PyMPC's gait generator for timing
238
+ - **Trot**: Simple open-loop sinusoidal gait pattern
239
+
240
+ All controllers output joint position targets; MuJoCo's built-in PD control tracks these targets.
241
+
242
  ## Project Structure
243
 
244
  ```
 
291
 
292
  ### WebSocket Events
293
 
294
+ Connect to `ws://localhost:3004/socket.io/` using Socket.IO client.
295
+
296
+ #### Client Server
297
+
298
+ | Event | Payload | Description |
299
+ |-------|---------|-------------|
300
+ | `command` | `{vx, vy, vyaw}` | Set velocity command |
301
+ | `reset` | *(none)* | Reset robot to standing pose |
302
+ | `switch_robot` | `{robot}` | Switch active robot |
303
+ | `camera` | `{type, ...}` | Camera control |
304
+ | `camera_follow` | `{follow}` | Toggle camera follow mode |
305
+
306
+ **`command` payload:**
307
+ ```json
308
+ {
309
+ "vx": 0.5, // Forward/backward velocity [-1, 1]
310
+ "vy": 0.0, // Left/right strafe velocity [-1, 1]
311
+ "vyaw": 0.0 // Turn rate [-1, 1]
312
+ }
313
+ ```
314
 
315
+ **`reset`:** No payload - emit the event name only:
316
+ ```javascript
317
+ socket.emit('reset'); // No second argument
318
+ ```
319
+ Resets the robot to its initial standing pose and resets the camera position.
320
+
321
+ **`switch_robot` payload:**
322
+ ```json
323
+ {
324
+ "robot": "g1" // "g1" or "spot"
325
+ }
326
+ ```
327
+
328
+ **`camera` payload:**
329
+ ```json
330
+ // Rotate camera
331
+ {"type": "rotate", "dx": 10, "dy": 5}
332
+
333
+ // Zoom camera
334
+ {"type": "zoom", "dz": -50}
335
+
336
+ // Pan camera
337
+ {"type": "pan", "dx": 10, "dy": 5}
338
+
339
+ // Set absolute distance
340
+ {"type": "set_distance", "distance": 3.0}
341
+ ```
342
+
343
+ **`camera_follow` payload:**
344
+ ```json
345
+ {
346
+ "follow": true // true to follow robot, false for fixed camera
347
+ }
348
+ ```
349
+
350
+ #### Server → Client
351
+
352
+ | Event | Payload | Description |
353
+ |-------|---------|-------------|
354
+ | `state` | `{robot, base_height, ...}` | Robot state (broadcast at render rate) |
355
+
356
+ **`state` payload:**
357
+ ```json
358
+ {
359
+ "robot": "spot", // Current robot type
360
+ "base_height": 0.46, // Robot base height in meters
361
+ "upright": 0.98, // Uprightness metric [0-1] (1 = perfectly upright)
362
+ "steps": 1234, // Simulation step count
363
+ "vx": 0.5, // Current forward velocity command
364
+ "vy": 0.0, // Current strafe velocity command
365
+ "vyaw": 0.0 // Current turn rate command
366
+ }
367
+ ```
368
 
369
  ### HTTP Endpoints
370
 
371
+ | Endpoint | Method | Description |
372
+ |----------|--------|-------------|
373
+ | `/` | GET | Web interface (HTML/JS) |
374
+ | `/video_feed` | GET | MJPEG video stream |
375
+
376
+ **Video stream usage:**
377
+ ```html
378
+ <img src="http://localhost:3004/video_feed" />
379
+ ```
380
 
381
  ## License
382