File size: 9,158 Bytes
02eac4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# LeRobot Arena Demo

A comprehensive SvelteKit demo application showcasing the LeRobot Arena robotics control platform with real-time 6-DOF robot arm control and monitoring.

## ๐Ÿš€ Features

### Dashboard
- **Real-time server status monitoring**
- **Active rooms overview**
- **Quick access to all signal types**
- **Clean, modern interface**

### Robotics Control
- **6-DOF robot arm control** with real-time sliders
- **Producer/Consumer pattern** for robot control and monitoring
- **Room management** - create, delete, and join rooms
- **Live joint state monitoring** with trend visualization
- **Command history tracking**
- **Emergency stop functionality**
- **WebSocket-based real-time communication**

### Architecture
- **Frontend**: Svelte 5, TypeScript, Tailwind CSS, Vite
- **Client Library**: Custom TypeScript/JavaScript client
- **Communication**: WebSocket for real-time control, REST API for management
- **Build System**: Bun for fast development and building

## ๐Ÿ“ Project Structure

```
demo/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ +layout.svelte           # Main layout with navigation
โ”‚   โ”‚   โ”œโ”€โ”€ +page.svelte             # Dashboard homepage
โ”‚   โ”‚   โ”œโ”€โ”€ robotics/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ +page.svelte         # Robotics control dashboard
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ producer/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ +page.svelte     # Producer interface
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [roomId]/+page.svelte  # Room-specific producer
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ consumer/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ +page.svelte     # Consumer interface
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ [roomId]/+page.svelte  # Room-specific consumer
โ”‚   โ”‚   โ””โ”€โ”€ video/
โ”‚   โ”‚       โ””โ”€โ”€ +page.svelte         # Video placeholder
โ”‚   โ”œโ”€โ”€ app.css                      # Tailwind CSS and custom styles
โ”‚   โ”œโ”€โ”€ app.d.ts                     # TypeScript declarations
โ”‚   โ””โ”€โ”€ app.html                     # HTML template
โ”œโ”€โ”€ package.json                     # Dependencies and scripts
โ”œโ”€โ”€ tsconfig.json                    # TypeScript configuration
โ”œโ”€โ”€ tailwind.config.ts               # Tailwind configuration
โ”œโ”€โ”€ vite.config.ts                   # Vite configuration
โ””โ”€โ”€ test-demo.js                     # Demo verification script
```

## ๐Ÿ› ๏ธ Prerequisites

1. **Bun** >= 1.0.0 ([Install Bun](https://bun.sh/))
2. **LeRobot Arena Server** running on port 8000
3. **Built JavaScript Client** (automatically installed as dependency)

## ๐Ÿš€ Quick Start

### 1. Install Dependencies

```bash
cd demo
bun install
```

### 2. Start Development Server

```bash
bun run dev
```

The demo will be available at http://localhost:5173

### 3. Test the Setup

```bash
node test-demo.js
```

## ๐Ÿ“Š Available Routes

| Route | Description |
|-------|-------------|
| `/` | **Dashboard** - Server status, room overview, quick actions |
| `/robotics` | **Robotics Control** - Room management and overview |
| `/robotics/producer` | **Producer Interface** - Create rooms and control robots |
| `/robotics/consumer` | **Consumer Interface** - Monitor robot state and commands |
| `/robotics/producer/[roomId]` | **Room Producer** - Direct control of specific room |
| `/robotics/consumer/[roomId]` | **Room Consumer** - Direct monitoring of specific room |
| `/video` | **Video Placeholder** - Future video streaming functionality |

## ๐ŸŽฎ Using the Demo

### Dashboard
1. **Monitor server status** - Real-time connection indicator
2. **View active rooms** - See all current robotics sessions
3. **Quick launch** - One-click access to producer/consumer interfaces

### Robot Control (Producer)
1. **Create or join a room**
2. **Control 6-DOF robot arm** with real-time sliders:
   - Base rotation (-180ยฐ to 180ยฐ)
   - Shoulder movement (-90ยฐ to 90ยฐ)
   - Elbow movement (-135ยฐ to 135ยฐ)
   - Wrist 1 rotation (-180ยฐ to 180ยฐ)
   - Wrist 2 movement (-90ยฐ to 90ยฐ)
   - Gripper control (0-100%, open to closed)
3. **Send commands** - State sync, emergency stop, heartbeat
4. **Monitor history** - Real-time command tracking

### Robot Monitoring (Consumer)
1. **Connect to existing room**
2. **Live joint monitoring** with trend visualization
3. **Real-time statistics** - Update counts, timing
4. **Command history** - Joint updates and state syncs
5. **Error tracking** - Connection and communication errors

### Room Management
1. **Create rooms** with custom IDs
2. **Delete rooms** when no longer needed
3. **View participants** - Producers and consumers
4. **Monitor activity** - Joint counts and connection status

## ๐Ÿ”ง Development

### Scripts

```bash
# Development server
bun run dev

# Build for production
bun run build

# Preview production build
bun run preview

# Type checking
bun run check

# Linting and formatting
bun run lint
bun run format
```

### Client Library Integration

The demo uses the local `lerobot-arena-client` package:

```typescript
import { robotics } from 'lerobot-arena-client';

// Create clients
const producer = new robotics.RoboticsProducer('http://localhost:8000');
const consumer = new robotics.RoboticsConsumer('http://localhost:8000');

// Use factory functions
const producer = await robotics.createProducerClient();
const consumer = await robotics.createConsumerClient(roomId);
```

## ๐ŸŽจ UI/UX Features

### Modern Design
- **Tailwind CSS** for responsive, utility-first styling
- **Custom components** with consistent design system
- **Status indicators** for real-time connection feedback
- **Interactive sliders** for intuitive robot control

### Real-time Feedback
- **Live joint values** with degree precision
- **Trend visualization** showing joint movement history
- **Connection status** with visual indicators
- **Command history** with timestamps and details

### Responsive Layout
- **Mobile-friendly** design for all screen sizes
- **Grid layouts** that adapt to viewport
- **Navigation** with active route highlighting
- **Modal dialogs** for room creation

## ๐Ÿ”’ Safety Features

### Emergency Stop
- **Manual emergency stop** button in producer interface
- **Propagation to all consumers** for immediate notification
- **Error tracking** for safety incident monitoring

### Connection Management
- **Automatic reconnection** handling
- **Timeout configurations** for reliable communication
- **Error reporting** with user-friendly messages

## ๐Ÿš€ Production Deployment

### Build

```bash
bun run build
```

### Environment Variables

```bash
# Server URL (default: http://localhost:8000)
VITE_SERVER_URL=http://your-server.com:8000
```

### Hosting

The built application can be deployed to any static hosting service:
- Vercel
- Netlify
- GitHub Pages
- AWS S3 + CloudFront
- Any web server

## ๐Ÿงช Testing

### Manual Testing

1. **Start the LeRobot Arena server** on port 8000
2. **Run the demo** with `bun run dev`
3. **Test workflows**:
   - Create room as producer
   - Control robot with sliders
   - Connect as consumer in another tab
   - Monitor real-time updates
   - Test emergency stop
   - Verify command history

### Integration Testing

The demo includes integration with the JS client test suite. See `../client/js/tests/` for comprehensive testing.

## ๐ŸŽฏ Use Cases

### Development & Testing
- **Client library testing** - Interactive validation of API
- **Server testing** - Real-time load and functionality testing
- **UI/UX prototyping** - Design validation for robotics interfaces

### Demonstrations
- **Product demos** - Showcase robotics control capabilities
- **Educational tool** - Learn producer/consumer patterns
- **Integration examples** - Reference implementation for developers

### Real-world Applications
- **Remote robot control** - Control robots from anywhere
- **Multi-user collaboration** - Multiple operators monitoring one robot
- **Training simulations** - Safe environment for learning robot control

## ๐Ÿค Contributing

1. **Fork the repository**
2. **Create feature branch** (`git checkout -b feature/amazing-feature`)
3. **Make changes** and add tests
4. **Run linting** (`bun run lint`)
5. **Test thoroughly** with demo application
6. **Commit changes** (`git commit -m 'Add amazing feature'`)
7. **Push to branch** (`git push origin feature/amazing-feature`)
8. **Open Pull Request**

## ๐Ÿ“ License

MIT License - see LICENSE file for details

---

## ๐Ÿ†˜ Troubleshooting

### Connection Issues
- **Server not running**: Ensure LeRobot Arena server is active on port 8000
- **CORS errors**: Check server CORS configuration
- **WebSocket failures**: Verify firewall settings

### Build Issues
- **Import errors**: Ensure client library is built (`cd ../client/js && bun run build`)
- **Type errors**: Run `bun run check` for detailed TypeScript diagnostics
- **Dependency issues**: Try `rm -rf node_modules && bun install`

### Runtime Issues
- **Slow performance**: Check browser dev tools for console errors
- **UI not updating**: Verify WebSocket connection in network tab
- **Commands not working**: Check server logs for error messages

For more help, see the main project documentation or open an issue on GitHub.