mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
pause Instead of shutting off engine when qr doesn't get read
This commit is contained in:
parent
41232cc723
commit
db3def3948
@ -121,20 +121,21 @@ class FullAuto(IEngine):
|
||||
self.start = False
|
||||
Thread(target=func).start()
|
||||
|
||||
def get_coods(self):
|
||||
def get_coords(self):
|
||||
"""
|
||||
There is chance that this function give None instead of a QR.
|
||||
Need to handle manually
|
||||
todo find a better way of handling None: switch from start bool to state which knows
|
||||
todo its waiting for qr which doesn't block the engine when commanded to close
|
||||
"""
|
||||
img = self.window.processed_image(func=image_pre_process)
|
||||
return get_values_from_image(img)
|
||||
|
||||
def move_to(self, target):
|
||||
if target is None:
|
||||
logging.error("set target first")
|
||||
return
|
||||
def move_to(self, target) -> bool:
|
||||
current = self.get_coords()
|
||||
if not current:
|
||||
return False
|
||||
|
||||
if not self.calibrator.all_calibrated():
|
||||
logging.error("you need to calibrate first")
|
||||
return
|
||||
|
||||
current = self.get_coods()
|
||||
print(f"Moving from {(current[0], current[1])} to {target}")
|
||||
move_vec = target[0] - current[0], target[1] - current[1]
|
||||
|
||||
@ -142,12 +143,13 @@ class FullAuto(IEngine):
|
||||
print(f"distance: {dist}")
|
||||
if dist < 5e-05:
|
||||
print("distance very small skipping")
|
||||
return
|
||||
return True
|
||||
|
||||
target_angle = math.degrees(math.atan2(-move_vec[1], move_vec[0])) + 90
|
||||
from_angle = current[2]
|
||||
|
||||
self.rotate_to(target_angle, from_angle)
|
||||
if not self.rotate_to(target_angle, from_angle):
|
||||
return False
|
||||
|
||||
walking_time = dist / self.calibrator.move_factor
|
||||
print(f"walking for {walking_time}")
|
||||
@ -155,10 +157,14 @@ class FullAuto(IEngine):
|
||||
time.sleep(walking_time)
|
||||
kb.release('w')
|
||||
print("done")
|
||||
return True
|
||||
|
||||
def rotate_to(self, target_angle, from_angle=None):
|
||||
def rotate_to(self, target_angle, from_angle=None) -> bool:
|
||||
if from_angle is None:
|
||||
_, _, from_angle = self.get_coods()
|
||||
coords = self.get_coords()
|
||||
if not coords:
|
||||
return False
|
||||
_, _, from_angle = coords
|
||||
|
||||
if target_angle < 0:
|
||||
target_angle = 360 + target_angle
|
||||
@ -179,7 +185,9 @@ class FullAuto(IEngine):
|
||||
mse.move(sign(rotate_times) * FullAuto.rotate_by * -1, 0)
|
||||
time.sleep(0.05)
|
||||
|
||||
def look_for_hole(self):
|
||||
return True
|
||||
|
||||
def look_for_hole(self) -> bool:
|
||||
self._hole_found_flag = False
|
||||
|
||||
if FishingMode.CurrentMode == fishing_mode.State.LOOKING:
|
||||
|
@ -75,7 +75,7 @@ class Calibrator(IMode):
|
||||
def _walk_calibrate(self):
|
||||
walking_time = 3
|
||||
|
||||
coods = self.engine.get_coods()
|
||||
coods = self.engine.get_coords()
|
||||
if coods is None:
|
||||
return
|
||||
|
||||
@ -86,7 +86,7 @@ class Calibrator(IMode):
|
||||
kb.release('w')
|
||||
time.sleep(0.5)
|
||||
|
||||
coods = self.engine.get_coods()
|
||||
coods = self.engine.get_coords()
|
||||
if coods is None:
|
||||
return
|
||||
x2, y2, rot2 = coods
|
||||
@ -100,7 +100,7 @@ class Calibrator(IMode):
|
||||
|
||||
rotate_times = 50
|
||||
|
||||
coods = self.engine.get_coods()
|
||||
coods = self.engine.get_coords()
|
||||
if coods is None:
|
||||
return
|
||||
_, _, rot2 = coods
|
||||
@ -109,7 +109,7 @@ class Calibrator(IMode):
|
||||
mse.move(FullAuto.rotate_by, 0)
|
||||
time.sleep(0.05)
|
||||
|
||||
coods = self.engine.get_coods()
|
||||
coods = self.engine.get_coords()
|
||||
if coods is None:
|
||||
return
|
||||
x3, y3, rot3 = coods
|
||||
|
@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import math
|
||||
import pickle
|
||||
import time
|
||||
from pprint import pprint
|
||||
|
||||
import typing
|
||||
@ -58,6 +59,7 @@ class Player(IMode):
|
||||
self._init()
|
||||
while self.engine.start:
|
||||
self._loop()
|
||||
time.sleep(0.1)
|
||||
logging.info("player stopped")
|
||||
|
||||
def _init(self):
|
||||
@ -66,16 +68,26 @@ class Player(IMode):
|
||||
log_raise("data not found, can't start")
|
||||
logging.info("starting player")
|
||||
|
||||
self.i = find_nearest(self.timeline, self.engine.get_coods())[0]
|
||||
coords = self.engine.get_coords()
|
||||
if not coords:
|
||||
log_raise("QR not found")
|
||||
|
||||
self.i = find_nearest(self.timeline, coords)[0]
|
||||
|
||||
def _loop(self):
|
||||
action = self.timeline[self.i]
|
||||
|
||||
if action[0] == "move_to":
|
||||
self.engine.move_to(action[1])
|
||||
if not self.engine.move_to(action[1]):
|
||||
return
|
||||
elif action[0] == "check_fish":
|
||||
self.engine.move_to(action[1])
|
||||
self.engine.rotate_to(action[1][2])
|
||||
if not self.engine.move_to(action[1]):
|
||||
return
|
||||
|
||||
if not self.engine.rotate_to(action[1][2]):
|
||||
return
|
||||
|
||||
# todo swap the order of below two lines
|
||||
fishing_event.subscribe()
|
||||
fishing_mode.subscribers.append(self._hole_complete_callback)
|
||||
# scan for fish hole
|
||||
@ -92,6 +104,9 @@ class Player(IMode):
|
||||
fishing_event.unsubscribe()
|
||||
fishing_mode.subscribers.remove(self._hole_complete_callback)
|
||||
|
||||
self.next()
|
||||
|
||||
def next(self):
|
||||
self.i += 1 if self.forward else -1
|
||||
if self.i >= len(self.timeline):
|
||||
self.forward = False
|
||||
|
@ -12,7 +12,7 @@ from tkinter.filedialog import asksaveasfile
|
||||
from fishy.engine.fullautofisher.mode import player
|
||||
from fishy.helper import helper
|
||||
|
||||
from fishy.helper.helper import empty_function
|
||||
from fishy.helper.helper import empty_function, log_raise
|
||||
|
||||
from fishy.helper.popup import PopUp
|
||||
from playsound import playsound
|
||||
@ -36,7 +36,10 @@ class Recorder(IMode):
|
||||
self.timeline = []
|
||||
|
||||
def _mark_hole(self):
|
||||
coods = self.engine.get_coods()
|
||||
coods = self.engine.get_coords()
|
||||
if not coods:
|
||||
logging.warning("QR not found, couldn't record hole")
|
||||
return
|
||||
self.timeline.append(("check_fish", coods))
|
||||
playsound(helper.manifest_file("beep.wav"), False)
|
||||
logging.info("check_fish")
|
||||
@ -47,8 +50,12 @@ class Recorder(IMode):
|
||||
if config.get("edit_recorder_mode"):
|
||||
logging.info("moving to nearest coord in recording")
|
||||
old_timeline = player.get_rec_file()
|
||||
start_from = player.find_nearest(old_timeline, self.engine.get_coods())
|
||||
self.engine.move_to(start_from[2])
|
||||
coords = self.engine.get_coords()
|
||||
if not coords:
|
||||
log_raise("QR not found")
|
||||
start_from = player.find_nearest(old_timeline, coords)
|
||||
if not self.engine.move_to(start_from[2]):
|
||||
log_raise("QR not found")
|
||||
|
||||
logging.info("starting, press LMB to mark hole")
|
||||
hk = HotKey()
|
||||
@ -58,9 +65,11 @@ class Recorder(IMode):
|
||||
|
||||
while self.engine.start:
|
||||
start_time = time.time()
|
||||
coods = None
|
||||
while not coods:
|
||||
coods = self.engine.get_coods()
|
||||
coods = self.engine.get_coords()
|
||||
if not coods:
|
||||
time.sleep(0.1)
|
||||
continue
|
||||
|
||||
self.timeline.append(("move_to", (coods[0], coods[1])))
|
||||
|
||||
time_took = time.time() - start_time
|
||||
@ -73,7 +82,13 @@ class Recorder(IMode):
|
||||
|
||||
if config.get("edit_recorder_mode"):
|
||||
logging.info("moving to nearest coord in recording")
|
||||
end = player.find_nearest(old_timeline, self.engine.get_coods())
|
||||
|
||||
# todo allow the user the chance to wait for qr
|
||||
coords = self.engine.get_coords()
|
||||
if not coords:
|
||||
log_raise("QR not found")
|
||||
|
||||
end = player.find_nearest(old_timeline, coords)
|
||||
self.engine.move_to(end[2])
|
||||
part1 = old_timeline[:start_from[0]]
|
||||
part2 = old_timeline[end[0]:]
|
||||
|
@ -42,7 +42,7 @@ def get_values_from_image(img):
|
||||
vals = qr.data.decode('utf-8').split(",")
|
||||
return float(vals[0]), float(vals[1]), float(vals[2])
|
||||
|
||||
logging.error("FishyQR not found, try restarting the engine")
|
||||
logging.error("FishyQR not found")
|
||||
return None
|
||||
except Exception:
|
||||
logging.error("Couldn't read coods, make sure 'crop' calibration is correct")
|
||||
|
@ -8,11 +8,12 @@ class Test:
|
||||
self.engine = engine
|
||||
self.target = None
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
def print_coods(self):
|
||||
logging.info(self.engine.get_coods())
|
||||
logging.info(self.engine.get_coords())
|
||||
|
||||
def set_target(self):
|
||||
self.target = self.engine.get_coods()
|
||||
self.target = self.engine.get_coords()
|
||||
logging.info(f"target_coods are {self.target}")
|
||||
|
||||
def move_to_target(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user