-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwheel.py
More file actions
58 lines (46 loc) · 1.96 KB
/
Copy pathwheel.py
File metadata and controls
58 lines (46 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
import math
def calculate_track_parameters(belt_length, num_teeth, hub_slots, thickness):
"""
计算带动态啮合比例的履带参数
:param belt_length: 履带总周长(cm)
:param num_teeth: 履带总齿数(偶数)
:param hub_slots: 单个轮毂槽数(偶数)
:param thickness: 履带厚度(cm)
:return: (实际轮毂半径, 中心距)
"""
# 输入校验
if num_teeth % 2 != 0 or hub_slots % 2 != 0:
raise ValueError("齿数和槽数必须为偶数")
if thickness < 0:
raise ValueError("厚度不能为负")
pitch = belt_length / num_teeth # 计算齿距
print(f"齿距{pitch:.2f}cm")
# 动态计算啮合齿数 (四舍五入取整)
engaged_per_hub = 0.56 * hub_slots # 每个轮毂啮合数
total_engaged = engaged_per_hub * 2 # 总啮合齿数
print(f"总啮合齿数{total_engaged}")
# 异常校验
if total_engaged > num_teeth:
raise ValueError(f"总啮合齿数{total_engaged}超过履带总齿数{num_teeth}")
if engaged_per_hub > hub_slots:
raise ValueError(f"单个轮毂啮合数{engaged_per_hub}超过槽数{hub_slots}")
# 计算轮毂参数
hub_circumference = hub_slots * pitch # 轮毂周长
theoretical_radius = hub_circumference / (2 * math.pi)
actual_radius = theoretical_radius - thickness
if actual_radius <= 0:
raise ValueError(f"厚度{thickness}cm超过理论半径{theoretical_radius:.2f}cm")
# 计算中心距
engaged_length = total_engaged * pitch
remaining_length = belt_length - engaged_length
if remaining_length < 0:
raise ValueError("啮合长度超过总周长")
center_distance = remaining_length / 2
return round(actual_radius, 2), round(center_distance, 2)
# 测试用例
if __name__ == "__main__":
# case = (170, 20, 8, 1.4)
case = (280, 36, 12, 1.4)
r, d = calculate_track_parameters(*case)
print(f"输入:{case}")
print(f"半径:{r}mm 中心距:{d}mm\n")