-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandshake.py
More file actions
executable file
·48 lines (42 loc) · 1.32 KB
/
handshake.py
File metadata and controls
executable file
·48 lines (42 loc) · 1.32 KB
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
import stretch_body.robot
import time
import os
import subprocess
from datetime import datetime
def log_error(error_message):
log_dir = "/tmp/stretch_logs"
os.makedirs(log_dir, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
log_path = os.path.join(log_dir, f"robot_startup_error_{timestamp}.txt")
with open(log_path, "w") as f:
f.write(f"[{timestamp}] Startup Error:\n{error_message}\n")
print(f"⚠️ Error logged to: {log_path}")
def reboot_robot():
password = os.getenv("robot_pass")
if not password:
print("❌ Environment variable 'robot_pass' is not set!")
return
print("🔁 Rebooting the robot system now...")
try:
subprocess.run(
["sudo", "-S", "reboot"],
input=(password + "\n").encode(),
check=True
)
except subprocess.CalledProcessError as e:
print(f"❌ Failed to reboot: {e}")
r = stretch_body.robot.Robot()
did_succeed = False
while not did_succeed:
try:
did_succeed = r.startup()
except Exception as e:
error_message = str(e)
print(f"❌ Error during robot startup: {error_message}")
log_error(error_message)
reboot_robot()
break
finally:
r.stop()
if did_succeed:
print("✅ Successfully connected to Stretch!")