mgbam commited on
Commit
dab61c8
Β·
verified Β·
1 Parent(s): 4cf3f7e

Update deployer/simulator_interface.py

Browse files
Files changed (1) hide show
  1. 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
- self._setup_logging()
12
- logging.info("πŸ€– Virtual Robot initialized in %s state", self.state)
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
- try:
39
- if action == "wave":
40
- return self._wave()
41
- elif action.startswith("say"):
42
- return self._speak(action[3:].strip())
43
- else:
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
- logging.info("Performing wave action")
54
- time.sleep(0.8) # Simulate animation time
55
  self.state = "IDLE"
56
- return "πŸ‘‹ *waves enthusiastically*"
57
-
58
  def _speak(self, message: str) -> str:
59
- """Generate speech response."""
60
  if not message:
61
- return "❌ Please provide something to say"
62
-
63
  self.state = "SPEAKING"
64
- logging.info("Speaking: '%s'", message)
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()}"