11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
33"""
4- Factory Calibration Tool Setup Script
5- 检查并安装必要的依赖
4+ Seeed_RoboController 环境检查脚本
5+ 运行: python setup.py
66"""
77
8- import subprocess
9- import sys
108import os
9+ import sys
10+ import platform
11+ import subprocess
12+
1113
1214def install_package (package ):
13- """安装Python包 """
15+ """安装 Python 包 """
1416 try :
1517 subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , package ])
16- print (f"[OK] { package } installed successfully " )
18+ print (f"[OK] { package } 安装成功 " )
1719 return True
1820 except subprocess .CalledProcessError :
19- print (f"[ERROR] Failed to install { package } " )
21+ print (f"[ERROR] { package } 安装失败 " )
2022 return False
2123
22- def check_import (module_name , package_name = None ):
24+
25+ def check_import (module_name , package_name = None , install = False ):
2326 """检查模块是否可导入"""
2427 try :
2528 __import__ (module_name )
26- print (f"[OK] { module_name } is available " )
29+ print (f"[OK] { module_name } 可导入 " )
2730 return True
2831 except ImportError :
29- print (f"[ERROR] { module_name } is not available " )
30- if package_name :
31- print (f" Installing { package_name } ..." )
32+ print (f"[ERROR] { module_name } 无法导入 " )
33+ if install and package_name :
34+ print (f" 正在安装 { package_name } ..." )
3235 return install_package (package_name )
3336 return False
3437
38+
39+ def check_python_version ():
40+ """检查 Python 版本"""
41+ version = sys .version_info
42+ print (f"[INFO] Python 版本: { version .major } .{ version .minor } .{ version .micro } " )
43+ if version < (3 , 8 ):
44+ print ("[ERROR] 需要 Python >= 3.8" )
45+ return False
46+ print ("[OK] Python 版本符合要求" )
47+ return True
48+
49+
50+ def check_files ():
51+ """检查关键文件是否存在"""
52+ print ("\n 检查项目文件完整性..." )
53+ required_files = [
54+ "requirements.txt" ,
55+ "src/port_utils.py" ,
56+ "src/calibration_manager.py" ,
57+ "src/tools/scan_id.py" ,
58+ "src/tools/lerobot_calibrate.py" ,
59+ "src/tools/run_calibration_middle.py" ,
60+ "src/gui/factory_calibration_tool.py" ,
61+ "src/gui/calibration_wizard.py" ,
62+ "scservo_sdk/port_handler.py" ,
63+ "scservo_sdk/sms_sts.py" ,
64+ "scservo_sdk/scservo_def.py" ,
65+ ]
66+
67+ all_ok = True
68+ for f in required_files :
69+ if os .path .exists (f ):
70+ print (f"[OK] { f } " )
71+ else :
72+ print (f"[ERROR] 缺失: { f } " )
73+ all_ok = False
74+ return all_ok
75+
76+
3577def main ():
36- print ("=== Factory Calibration Tool Setup ===" )
37- print ("Checking dependencies...\n " )
78+ print ("=" * 50 )
79+ print ("Seeed_RoboController 环境检查" )
80+ print ("=" * 50 )
81+ print (f"平台: { platform .system ()} { platform .release ()} " )
82+ print (f"机器: { platform .machine ()} " )
83+ print ("" )
84+
85+ all_ok = True
3886
39- # 检查必要的Python包
87+ if not check_python_version ():
88+ all_ok = False
89+
90+ # 检查依赖
91+ print ("\n 检查 Python 依赖..." )
4092 dependencies = [
4193 ("PySide6" , "PySide6" ),
4294 ("serial" , "pyserial" ),
4395 ]
44-
45- all_ok = True
4696 for module , package in dependencies :
4797 if not check_import (module , package ):
4898 all_ok = False
4999
50- # 检查文件完整性
51- print ("\n Checking file integrity..." )
52- required_files = [
53- "factory_calibration_tool.py" ,
54- "servo_middle_calibration.py" ,
55- "servo_quick_calibration.py" ,
56- "servo_center_test.py" ,
57- "servo_disable.py" ,
58- "servo_remote_control.py" ,
59- "scservo_sdk/port_handler.py" ,
60- "scservo_sdk/sms_sts.py" ,
61- "scservo_sdk/scservo_def.py" ,
100+ # 检查项目模块
101+ print ("\n 检查项目模块..." )
102+ project_modules = [
103+ "src.port_utils" ,
104+ "src.calibration_manager" ,
62105 ]
106+ for module in project_modules :
107+ if not check_import (module ):
108+ all_ok = False
63109
64- for file in required_files :
65- if os .path .exists (file ):
66- print (f"[OK] { file } " )
67- else :
68- print (f"[ERROR] { file } is missing" )
110+ # 检查 SDK
111+ print ("\n 检查 SCServo SDK..." )
112+ sdk_modules = [
113+ "scservo_sdk.port_handler" ,
114+ "scservo_sdk.sms_sts" ,
115+ "scservo_sdk.scservo_def" ,
116+ ]
117+ for module in sdk_modules :
118+ if not check_import (module ):
69119 all_ok = False
70120
121+ # 检查文件
122+ if not check_files ():
123+ all_ok = False
124+
125+ print ("" )
71126 if all_ok :
72- print ("\n === Setup Complete! ===" )
73- print ("You can now run the calibration tool:" )
74- print (" python factory_calibration_tool.py" )
75- print ("\n The tool will auto-detect available serial ports." )
76- print ("Or manually specify ports:" )
77- import platform
78- if platform .system () == "Windows" :
79- print (" python factory_calibration_tool.py --port1 COM1 --port2 COM2" )
80- else :
81- # macOS/Linux: Show actual detected ports if available
82- try :
83- from port_utils import get_available_ports , list_ports_for_user
84- ports = get_available_ports ()
85- if len (ports ) >= 2 :
86- print (f" python factory_calibration_tool.py --port1 { ports [0 ].device } --port2 { ports [1 ].device } " )
87- elif len (ports ) == 1 :
88- print (f" python factory_calibration_tool.py --port1 { ports [0 ].device } " )
89- print (" (Note: Only one port detected, connect another adapter)" )
90- else :
91- print (" python factory_calibration_tool.py --port1 /dev/ttyUSB0 --port2 /dev/ttyUSB1" )
92- print (" (No ports detected, please connect USB-to-Serial adapter)" )
93- except ImportError :
94- print (" python factory_calibration_tool.py --port1 /dev/ttyUSB0 --port2 /dev/ttyUSB1" )
127+ print ("=" * 50 )
128+ print ("[OK] 环境检查通过,可以运行项目" )
129+ print ("=" * 50 )
130+ print ("\n 常用命令:" )
131+ print (" python -m src.tools.scan_id --list" )
132+ print (" python -m src.tools.scan_id" )
133+ print (" python -m src.gui.factory_calibration_tool" )
134+ print (" python -m src.tools.lerobot_calibrate" )
135+ print (" python -m src.tools.run_calibration_middle" )
136+ return 0
95137 else :
96- print ("\n === Setup Failed ===" )
97- print ("Please fix the issues above before running the tool." )
98- sys .exit (1 )
138+ print ("=" * 50 )
139+ print ("[ERROR] 环境检查未通过,请修复上述问题" )
140+ print ("=" * 50 )
141+ print ("\n 可尝试手动安装:" )
142+ print (" python3 -m venv .venv" )
143+ print (" source .venv/bin/activate" )
144+ print (" pip install -r requirements.txt" )
145+ return 1
146+
99147
100148if __name__ == "__main__" :
101- main ()
149+ sys . exit ( main () )
0 commit comments