Update deployer/simulator_interface.py
Browse files- deployer/simulator_interface.py +24 -12
deployer/simulator_interface.py
CHANGED
@@ -2,26 +2,38 @@ import time
|
|
2 |
import logging
|
3 |
|
4 |
class VirtualRobot:
|
|
|
|
|
5 |
def __init__(self):
|
6 |
self.state = "IDLE"
|
7 |
-
logging.info("π€ Robot initialized")
|
8 |
-
|
9 |
-
def perform_action(self, command):
|
|
|
10 |
command = (command or "").strip().lower()
|
11 |
|
12 |
-
if command
|
13 |
-
return
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
self.state = "WAVING"
|
20 |
time.sleep(0.5)
|
21 |
self.state = "IDLE"
|
22 |
return "π Wave complete!"
|
23 |
-
|
24 |
-
def _speak(self, message):
|
|
|
25 |
if not message:
|
26 |
return "β No message provided"
|
27 |
self.state = "SPEAKING"
|
|
|
2 |
import logging
|
3 |
|
4 |
class VirtualRobot:
|
5 |
+
"""Enhanced virtual robot with state management"""
|
6 |
+
|
7 |
def __init__(self):
|
8 |
self.state = "IDLE"
|
9 |
+
logging.info("π€ Virtual Robot initialized")
|
10 |
+
|
11 |
+
def perform_action(self, command: str) -> str:
|
12 |
+
"""Main action processor with validation"""
|
13 |
command = (command or "").strip().lower()
|
14 |
|
15 |
+
if not command:
|
16 |
+
return "β Please enter a command"
|
17 |
+
|
18 |
+
try:
|
19 |
+
if command == "wave":
|
20 |
+
return self._wave()
|
21 |
+
elif command.startswith("say"):
|
22 |
+
return self._speak(command[3:].strip())
|
23 |
+
return "β Try 'wave' or 'say [message]'"
|
24 |
+
except Exception as e:
|
25 |
+
logging.error(f"Action failed: {str(e)}")
|
26 |
+
return f"β οΈ Error: {str(e)}"
|
27 |
+
|
28 |
+
def _wave(self) -> str:
|
29 |
+
"""Handle wave action"""
|
30 |
self.state = "WAVING"
|
31 |
time.sleep(0.5)
|
32 |
self.state = "IDLE"
|
33 |
return "π Wave complete!"
|
34 |
+
|
35 |
+
def _speak(self, message: str) -> str:
|
36 |
+
"""Handle speak action"""
|
37 |
if not message:
|
38 |
return "β No message provided"
|
39 |
self.state = "SPEAKING"
|