Update deployer/simulator_interface.py
Browse files- deployer/simulator_interface.py +14 -49
deployer/simulator_interface.py
CHANGED
|
@@ -3,65 +3,30 @@ import logging
|
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
class VirtualRobot:
|
| 6 |
-
"""Enhanced virtual robot with state management and logging."""
|
| 7 |
-
|
| 8 |
def __init__(self):
|
| 9 |
-
"""Initialize the virtual robot with default state."""
|
| 10 |
self.state = "IDLE"
|
| 11 |
-
|
| 12 |
-
logging.info("
|
| 13 |
-
|
| 14 |
-
def _setup_logging(self):
|
| 15 |
-
"""Configure logging settings."""
|
| 16 |
-
logging.basicConfig(
|
| 17 |
-
level=logging.INFO,
|
| 18 |
-
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 19 |
-
handlers=[logging.StreamHandler()]
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
def perform_action(self, action: str) -> str:
|
| 23 |
-
"""
|
| 24 |
-
Process robot actions with validation and error handling.
|
| 25 |
-
|
| 26 |
-
Args:
|
| 27 |
-
action: The action command (e.g., "wave" or "say hello")
|
| 28 |
-
|
| 29 |
-
Returns:
|
| 30 |
-
Response string from the robot
|
| 31 |
-
"""
|
| 32 |
-
if not action or not isinstance(action, str):
|
| 33 |
-
logging.warning("Invalid action command received")
|
| 34 |
-
return "β Invalid command"
|
| 35 |
-
|
| 36 |
action = action.lower().strip()
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
logging.warning("Unknown action: %s", action)
|
| 45 |
-
return "β Unknown action - try 'wave' or 'say [message]'"
|
| 46 |
-
except Exception as e:
|
| 47 |
-
logging.error("Action failed: %s", str(e))
|
| 48 |
-
return f"β Error: {str(e)}"
|
| 49 |
-
|
| 50 |
def _wave(self) -> str:
|
| 51 |
-
"""Perform waving animation."""
|
| 52 |
self.state = "WAVING"
|
| 53 |
-
|
| 54 |
-
time.sleep(0.8) # Simulate animation time
|
| 55 |
self.state = "IDLE"
|
| 56 |
-
return "π
|
| 57 |
-
|
| 58 |
def _speak(self, message: str) -> str:
|
| 59 |
-
"""Generate speech response."""
|
| 60 |
if not message:
|
| 61 |
-
return "β
|
| 62 |
-
|
| 63 |
self.state = "SPEAKING"
|
| 64 |
-
|
| 65 |
-
time.sleep(max(0.5, len(message)*0.07)) # Dynamic delay
|
| 66 |
self.state = "IDLE"
|
| 67 |
return f"π£οΈ {message.capitalize()}"
|
|
|
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
class VirtualRobot:
|
|
|
|
|
|
|
| 6 |
def __init__(self):
|
|
|
|
| 7 |
self.state = "IDLE"
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logging.info("Robot initialized")
|
| 10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def perform_action(self, action: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
action = action.lower().strip()
|
| 13 |
|
| 14 |
+
if action == "wave":
|
| 15 |
+
return self._wave()
|
| 16 |
+
elif action.startswith("say"):
|
| 17 |
+
return self._speak(action[3:].strip())
|
| 18 |
+
return "β Unknown command"
|
| 19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def _wave(self) -> str:
|
|
|
|
| 21 |
self.state = "WAVING"
|
| 22 |
+
time.sleep(0.5)
|
|
|
|
| 23 |
self.state = "IDLE"
|
| 24 |
+
return "π Wave complete!"
|
| 25 |
+
|
| 26 |
def _speak(self, message: str) -> str:
|
|
|
|
| 27 |
if not message:
|
| 28 |
+
return "β No message provided"
|
|
|
|
| 29 |
self.state = "SPEAKING"
|
| 30 |
+
time.sleep(max(0.3, len(message)*0.05))
|
|
|
|
| 31 |
self.state = "IDLE"
|
| 32 |
return f"π£οΈ {message.capitalize()}"
|