crazy
Former-commit-id: 7df457400907998e272578e9cc6ce08e767916bf
This commit is contained in:
66
main.py
66
main.py
@ -85,9 +85,13 @@ class MAT:
|
||||
if self.history.is_empty():
|
||||
self.control_logger.error("未预期的没有可用的历史记录")
|
||||
return ret
|
||||
if self.crazy < 3:
|
||||
self._display_status(im, ret, rate, val)
|
||||
return ret
|
||||
|
||||
|
||||
# === 状态进入逻辑 ===
|
||||
if now - self._start_time<17:
|
||||
if now - self._start_time<10:
|
||||
self._display_status(im, ret, rate, val)
|
||||
return ret
|
||||
# 1. middle: predictor返回middle立即进入slow状态
|
||||
@ -199,7 +203,7 @@ class MAT:
|
||||
rate = val/tot
|
||||
if self.history.base is not None:
|
||||
base = self.history.base
|
||||
thr = (base*5, base*10, base*30)
|
||||
thr = (base*5, base*9, 0.75)
|
||||
if rate < thr[0]:
|
||||
return "transport",rate
|
||||
elif rate <thr[1]:
|
||||
@ -257,28 +261,48 @@ class MAT:
|
||||
self.ch340_init()
|
||||
cnt = 0
|
||||
self._start_time = time.time()
|
||||
self.crazy = 4
|
||||
|
||||
while self.running:
|
||||
if not self.ch340.running:
|
||||
if 12 * cnt - self.total_volume < 0.5:
|
||||
self.ch340_pull()
|
||||
cnt += 1
|
||||
time.sleep(0.01)
|
||||
|
||||
# 简化的推送逻辑
|
||||
should_push = False
|
||||
if self.state.is_fast_mode():
|
||||
should_push = True
|
||||
elif self.state.is_slow_mode() and time.time() - self.ch340.start > mid_time:
|
||||
should_push = True
|
||||
elif self.state.is_about_mode() and time.time() - self.ch340.start > end_time:
|
||||
should_push = True
|
||||
|
||||
if should_push:
|
||||
speed = self.speeds[self.state.mode.value]
|
||||
self.volume_logger.info(f"当前体积: {self.total_volume:.2f} ml, 加入速度: {speed:.2f} ml/次")
|
||||
self.ch340_push(speed)
|
||||
self.total_volume += speed
|
||||
if self.crazy < 3:
|
||||
match self.crazy:
|
||||
case 0:
|
||||
self.control_logger.info("crazy 0")
|
||||
self.ch340_pull()
|
||||
self.ch340.speed = 1.00
|
||||
self.ch340.push_async(vol=12)
|
||||
self.crazy = 1
|
||||
case 1:
|
||||
self.control_logger.info("crazy 1")
|
||||
self.ch340.pull_async(vol=12)
|
||||
self.crazy = 2
|
||||
case 2:
|
||||
self.control_logger.info("crazy 2")
|
||||
self.ch340.push_async(vol=8)
|
||||
self.total_volume = 20
|
||||
cnt = 2
|
||||
self.crazy = 3
|
||||
else:
|
||||
if 12 * cnt - self.total_volume < 0.5:
|
||||
self.ch340_pull()
|
||||
cnt += 1
|
||||
time.sleep(0.01)
|
||||
|
||||
# 简化的推送逻辑
|
||||
should_push = False
|
||||
if self.state.is_fast_mode():
|
||||
should_push = True
|
||||
elif self.state.is_slow_mode() and time.time() - self.ch340.start > mid_time:
|
||||
should_push = True
|
||||
elif self.state.is_about_mode() and time.time() - self.ch340.start > end_time:
|
||||
should_push = True
|
||||
|
||||
if should_push:
|
||||
speed = self.speeds[self.state.mode.value]
|
||||
self.volume_logger.info(f"当前体积: {self.total_volume:.2f} ml, 加入速度: {speed:.2f} ml/次")
|
||||
self.ch340_push(speed)
|
||||
self.total_volume += speed
|
||||
|
||||
if self._pred() is None:
|
||||
self.control_logger.error("预测失败,跳过当前帧")
|
||||
|
Reference in New Issue
Block a user