Julian Bilcke
commited on
Commit
·
3605c07
1
Parent(s):
2200f2f
debugging keyboard event issues
Browse files- websocket_pipeline.py +49 -24
websocket_pipeline.py
CHANGED
|
@@ -30,47 +30,72 @@ class WebSocketStreamingPipeline(CausalInferenceStreamingPipeline):
|
|
| 30 |
Get current action from stored WebSocket data instead of stdin
|
| 31 |
Returns the same format as get_current_action()
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
"""
|
| 39 |
-
#
|
| 40 |
if self.current_keyboard is None:
|
| 41 |
-
ws_keyboard = [0, 0, 0, 0, 0, 0]
|
| 42 |
else:
|
| 43 |
ws_keyboard = self.current_keyboard
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
if mode == 'universal':
|
| 47 |
-
#
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
elif mode == 'gta_drive':
|
| 50 |
-
#
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
elif mode == 'templerun':
|
| 53 |
-
#
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
else:
|
| 56 |
-
# Default to universal
|
| 57 |
-
keyboard =
|
| 58 |
|
| 59 |
-
#
|
| 60 |
if mode == 'templerun':
|
| 61 |
-
# Temple Run doesn't use mouse
|
| 62 |
mouse = [0, 0]
|
| 63 |
else:
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
else:
|
| 67 |
-
mouse = self.current_mouse
|
| 68 |
|
| 69 |
-
# Convert to tensors
|
| 70 |
mouse_tensor = torch.tensor(mouse, dtype=torch.float32).cuda()
|
| 71 |
keyboard_tensor = torch.tensor(keyboard, dtype=torch.float32).cuda()
|
| 72 |
|
| 73 |
-
logger.debug(f"WebSocket action for mode {mode}:
|
| 74 |
|
| 75 |
return {
|
| 76 |
'mouse': mouse_tensor,
|
|
|
|
| 30 |
Get current action from stored WebSocket data instead of stdin
|
| 31 |
Returns the same format as get_current_action()
|
| 32 |
|
| 33 |
+
The original pipeline expects SINGLE ACTION vectors, not multi-action states:
|
| 34 |
+
- Universal: keyboard [1,0,0,0] = forward only, [0,0,1,0] = left only
|
| 35 |
+
- WebSocket gives: [forward, back, left, right, jump, attack] with multiple 1s
|
| 36 |
+
|
| 37 |
+
We need to convert multi-action to dominant single action.
|
| 38 |
"""
|
| 39 |
+
# Get WebSocket format: [forward, back, left, right, jump, attack]
|
| 40 |
if self.current_keyboard is None:
|
| 41 |
+
ws_keyboard = [0, 0, 0, 0, 0, 0]
|
| 42 |
else:
|
| 43 |
ws_keyboard = self.current_keyboard
|
| 44 |
|
| 45 |
+
if self.current_mouse is None:
|
| 46 |
+
ws_mouse = [0, 0]
|
| 47 |
+
else:
|
| 48 |
+
ws_mouse = self.current_mouse
|
| 49 |
+
|
| 50 |
+
# Convert WebSocket multi-action to single dominant action
|
| 51 |
if mode == 'universal':
|
| 52 |
+
# Pipeline expects: [forward, back, left, right] as single action
|
| 53 |
+
# Priority order: forward > back > left > right > no action
|
| 54 |
+
if ws_keyboard[0]: # forward
|
| 55 |
+
keyboard = [1, 0, 0, 0]
|
| 56 |
+
elif ws_keyboard[1]: # back
|
| 57 |
+
keyboard = [0, 1, 0, 0]
|
| 58 |
+
elif ws_keyboard[2]: # left
|
| 59 |
+
keyboard = [0, 0, 1, 0]
|
| 60 |
+
elif ws_keyboard[3]: # right
|
| 61 |
+
keyboard = [0, 0, 0, 1]
|
| 62 |
+
else: # no action
|
| 63 |
+
keyboard = [0, 0, 0, 0]
|
| 64 |
+
|
| 65 |
elif mode == 'gta_drive':
|
| 66 |
+
# Pipeline expects: [forward, back] as single action
|
| 67 |
+
if ws_keyboard[0]: # forward
|
| 68 |
+
keyboard = [1, 0]
|
| 69 |
+
elif ws_keyboard[1]: # back
|
| 70 |
+
keyboard = [0, 1]
|
| 71 |
+
else: # no action
|
| 72 |
+
keyboard = [0, 0]
|
| 73 |
+
|
| 74 |
elif mode == 'templerun':
|
| 75 |
+
# Pipeline expects: [left, right] as single action
|
| 76 |
+
if ws_keyboard[2]: # left
|
| 77 |
+
keyboard = [1, 0]
|
| 78 |
+
elif ws_keyboard[3]: # right
|
| 79 |
+
keyboard = [0, 1]
|
| 80 |
+
else: # no action
|
| 81 |
+
keyboard = [0, 0]
|
| 82 |
else:
|
| 83 |
+
# Default to universal
|
| 84 |
+
keyboard = [0, 0, 0, 0]
|
| 85 |
|
| 86 |
+
# Mouse handling - use raw WebSocket values for most modes
|
| 87 |
if mode == 'templerun':
|
| 88 |
+
# Temple Run doesn't use mouse
|
| 89 |
mouse = [0, 0]
|
| 90 |
else:
|
| 91 |
+
# Use WebSocket mouse values directly (they should be in [-1, 1] range)
|
| 92 |
+
mouse = ws_mouse
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
# Convert to tensors
|
| 95 |
mouse_tensor = torch.tensor(mouse, dtype=torch.float32).cuda()
|
| 96 |
keyboard_tensor = torch.tensor(keyboard, dtype=torch.float32).cuda()
|
| 97 |
|
| 98 |
+
logger.debug(f"WebSocket action for mode {mode}: ws_kb={ws_keyboard}, ws_mouse={ws_mouse} -> kb={keyboard}, mouse={mouse}")
|
| 99 |
|
| 100 |
return {
|
| 101 |
'mouse': mouse_tensor,
|