Skip to content

Commit a9b2b90

Browse files
committed
.
1 parent 7f61572 commit a9b2b90

File tree

4 files changed

+78
-11
lines changed

4 files changed

+78
-11
lines changed

apex.py

+33-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import winsound
1212
from simple_pid import PID
1313

14+
import matplotlib
15+
import matplotlib.pyplot as plt
16+
1417
ads = 'ads'
1518
pidc = 'pidc'
1619
size = 'size'
@@ -20,6 +23,7 @@
2023
head = 'head'
2124
left = 'left'
2225
title = 'title'
26+
debug = 'debug'
2327
region = 'region'
2428
center = 'center'
2529
radius = 'radius'
@@ -42,7 +46,8 @@
4246
show: False, # 显示, Down
4347
head: False, # 瞄头, Up
4448
pidc: False, # 是否启用 PID Controller, 还未完善, Left
45-
left: False, # 左键锁, PgDn, 按左键时锁
49+
left: False, # 左键锁, Right, 按鼠标左键时锁
50+
debug: False, # Debug 模式, 用来调试 PID 值
4651
}
4752

4853

@@ -90,10 +95,11 @@ def release(key):
9095
data[pidc] = not data[pidc]
9196
winsound.Beep(800 if data[pidc] else 400, 200)
9297
elif key == Key.right:
93-
pass
94-
elif key == Key.page_down:
9598
data[left] = not data[left]
9699
winsound.Beep(800 if data[left] else 400, 200)
100+
elif key == Key.page_down:
101+
data[debug] = not data[debug]
102+
winsound.Beep(800 if data[debug] else 400, 200)
97103

98104
with Listener(on_release=release, on_press=press) as k:
99105
k.join()
@@ -169,8 +175,10 @@ def follow(aims):
169175
return targets[index]
170176

171177
text = 'Realtime Screen Capture Detect'
172-
pidx = PID(2, 0, 0, setpoint=0)
173-
pidy = PID(2, 0, 0, setpoint=0)
178+
pidx = PID(2, 0, 0.02, setpoint=0)
179+
pidx.output_limits = [-50, 50]
180+
pidy = PID(2, 0, 0.02, setpoint=0)
181+
times, targets, distances = [], [], [] # 用于绘图
174182

175183
# 主循环
176184
while True:
@@ -210,14 +218,33 @@ def follow(aims):
210218
x = sx - cx
211219
y = sy - cy
212220
if data[pidc]:
221+
if data[debug]: # 用于绘图
222+
times.append(time.time())
223+
targets.append(0)
224+
distances.append(x)
213225
px = int(pidx(x))
214226
py = int(pidy(y))
215227
move(-px, -py)
216228
else:
217229
ax = int(x * data[ads])
218230
ay = int(y * data[ads])
219231
move(ax, ay)
220-
232+
else: # 用于绘图
233+
if data[debug] and len(times) != 0:
234+
try:
235+
plt.plot(times, targets, label='target')
236+
plt.plot(times, distances, label='distance')
237+
plt.legend() # 图例
238+
plt.xlabel('time')
239+
plt.ylabel('distance')
240+
times.clear()
241+
targets.clear()
242+
distances.clear()
243+
matplotlib.use('TkAgg') # TkAgg, module://backend_interagg
244+
winsound.Beep(600, 200)
245+
plt.show()
246+
except:
247+
pass
221248
# 显示检测
222249
if data[show] and img is not None:
223250
cv2.namedWindow(text, cv2.WINDOW_AUTOSIZE)

readme.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
- Down: 仅游戏中有效, 是否显示推理结果
2828
- Up: 仅游戏中有效, 是否瞄头
2929
- 该瞄头是通过身体范围大致推断出来的头的位置, 正面效果比较好, 侧面可能瞄不到头
30-
- Right: 仅游戏中有效, 左右移动时添加一定的反向瞄准偏移
31-
- Left: 仅游戏中有效, 是否预瞄
32-
- 卡尔曼滤波器不适用于3D视角可动的场景, 这里将就用一下
30+
- Left: 仅游戏中有效, 是否启用 PID 控制
31+
- Right: 仅游戏中有效, 按鼠标左键时锁
3332

3433
其他说明:
3534
- 显示器关闭 `缩放`

test.matplotlib.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import matplotlib.pyplot as plt
2+
print(plt.get_backend())
3+
import matplotlib
4+
matplotlib.use('module://backend_interagg') # ['GTK3Agg', 'GTK3Cairo', 'GTK4Agg', 'GTK4Cairo', 'MacOSX', 'nbAgg', 'QtAgg', 'QtCairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
5+
print(plt.get_backend())
6+
7+
8+
x = [1, 2, 3]
9+
y1 = [1, 2, 3]
10+
y2 = [2, 4, 1]
11+
plt.plot(x, y1, label='a')
12+
plt.plot(x, y2, label='b')
13+
plt.legend() # 图例
14+
plt.xlabel('time')
15+
plt.ylabel('distance')
16+
plt.show()
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+

test.pid.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import time
2-
import matplotlib
3-
matplotlib.use('TkAgg')
42
from matplotlib import pyplot as plt
53
from simple_pid import PID
64

0 commit comments

Comments
 (0)