renamed calibrate class to calibrator,

removed updown calibration process,
changed controls accordingly
This commit is contained in:
Adam Saudagar 2021-04-17 22:01:19 +05:30
parent 23488d4c3d
commit 96db413f61
3 changed files with 25 additions and 51 deletions

View File

@ -47,7 +47,7 @@ def _get_factor(key):
return config.get("full_auto_factors", {}).get(key) return config.get("full_auto_factors", {}).get(key)
class Calibrate: class Calibrator:
def __init__(self, engine: FullAuto): def __init__(self, engine: FullAuto):
self._callibrate_state = -1 self._callibrate_state = -1
self.engine = engine self.engine = engine
@ -60,10 +60,6 @@ class Calibrate:
def rot_factor(self): def rot_factor(self):
return _get_factor("rot_factor") return _get_factor("rot_factor")
@property
def time_to_reach_bottom(self):
return _get_factor("time_to_reach_bottom")
# endregion # endregion
def all_callibrated(self): def all_callibrated(self):
@ -72,7 +68,7 @@ class Calibrate:
def toggle_show(self): def toggle_show(self):
self.engine.show_crop = not self.engine.show_crop self.engine.show_crop = not self.engine.show_crop
def walk_calibrate(self): def _walk_calibrate(self):
walking_time = 3 walking_time = 3
coods = self.engine.get_coods() coods = self.engine.get_coods()
@ -95,7 +91,7 @@ class Calibrate:
_update_factor("move_factor", move_factor) _update_factor("move_factor", move_factor)
logging.info("done") logging.info("done")
def rotate_calibrate(self): def _rotate_calibrate(self):
rotate_times = 50 rotate_times = 50
coods = self.engine.get_coods() coods = self.engine.get_coods()
@ -119,25 +115,7 @@ class Calibrate:
_update_factor("rot_factor", rot_factor) _update_factor("rot_factor", rot_factor)
logging.info("done") logging.info("done")
def time_to_reach_bottom_callibrate(self): def calibrate(self):
self._callibrate_state = 0 self._walk_calibrate()
self._rotate_calibrate()
def _f8_pressed():
self._callibrate_state += 1
logging.info("look straight up and press f8")
hotkey.set_hotkey(Key.F8, _f8_pressed)
wait_until(lambda: self._callibrate_state == 1)
logging.info("as soon as you look on the floor, press f8 again")
y_cal_start_time = time.time()
while self._callibrate_state == 1:
mse.move(0, FullAuto.rotate_by)
time.sleep(0.05)
hotkey.free_key(Key.F8)
time_to_reach_bottom = time.time() - y_cal_start_time
_update_factor("time_to_reach_bottom", time_to_reach_bottom)
logging.info("done")

View File

@ -11,16 +11,10 @@ def get_controls(engine: FullAuto):
from fishy.engine.fullautofisher.player import Player from fishy.engine.fullautofisher.player import Player
controls = [ controls = [
("MODE_SELECT", { ("MODE_SELECT", {
Key.RIGHT: (lambda: engine.controls.select_mode("CALIBRATE"), "calibrate mode"), Key.RIGHT: (Recorder(engine).toggle_recording, "start/stop record"),
Key.UP: (lambda: engine.controls.select_mode("TEST1"), "test mode"), Key.UP: (engine.calibrator.calibrate, "calibrate mode"),
Key.LEFT: (Player(engine).toggle_move, "start/stop play"), Key.LEFT: (Player(engine).toggle_move, "start/stop play"),
Key.DOWN: (Recorder(engine).toggle_recording, "start/stop record"), Key.DOWN: (lambda: engine.controls.select_mode("TEST1"), "test mode"),
}),
("CALIBRATE", {
Key.RIGHT: (None, ""),
Key.UP: (engine.calibrate.walk_calibrate, "walking"),
Key.LEFT: (engine.calibrate.rotate_calibrate, "rotation"),
Key.DOWN: (engine.calibrate.time_to_reach_bottom_callibrate, "look up down")
}), }),
("TEST1", { ("TEST1", {
Key.RIGHT: (engine.test.print_coods, "print coordinates"), Key.RIGHT: (engine.test.print_coods, "print coordinates"),

View File

@ -14,6 +14,7 @@ import time
import numpy as np import numpy as np
import pytesseract import pytesseract
from fishy.constants import libgps, fishyqr, lam2
from fishy.engine.fullautofisher.qr_detection import get_values_from_image, get_qr_location from fishy.engine.fullautofisher.qr_detection import get_values_from_image, get_qr_location
from fishy.engine.semifisher.fishing_mode import FishingMode from fishy.engine.semifisher.fishing_mode import FishingMode
@ -24,9 +25,9 @@ from fishy.engine.semifisher import fishing_mode, fishing_event
from fishy.engine.common.IEngine import IEngine from fishy.engine.common.IEngine import IEngine
from pynput import keyboard, mouse from pynput import keyboard, mouse
from fishy.helper import hotkey, helper from fishy.helper import hotkey, helper, hotkey_process
from fishy.helper.config import config from fishy.helper.config import config
from fishy.helper.helper import sign from fishy.helper.helper import sign, addon_exists
from fishy.helper.hotkey import Key from fishy.helper.hotkey import Key
mse = mouse.Controller() mse = mouse.Controller()
@ -56,7 +57,7 @@ class FullAuto(IEngine):
def __init__(self, gui_ref): def __init__(self, gui_ref):
from fishy.engine.fullautofisher.controls import Controls from fishy.engine.fullautofisher.controls import Controls
from fishy.engine.fullautofisher import controls from fishy.engine.fullautofisher import controls
from fishy.engine.fullautofisher.calibrate import Calibrate from fishy.engine.fullautofisher.calibrator import Calibrator
from fishy.engine.fullautofisher.test import Test from fishy.engine.fullautofisher.test import Test
super().__init__(gui_ref) super().__init__(gui_ref)
@ -64,7 +65,7 @@ class FullAuto(IEngine):
self._curr_rotate_y = 0 self._curr_rotate_y = 0
self.fisher = SemiFisherEngine(None) self.fisher = SemiFisherEngine(None)
self.calibrate = Calibrate(self) self.calibrator = Calibrator(self)
self.test = Test(self) self.test = Test(self)
self.controls = Controls(controls.get_controls(self)) self.controls = Controls(controls.get_controls(self))
self.show_crop = False self.show_crop = False
@ -73,19 +74,20 @@ class FullAuto(IEngine):
FullAuto.state = State.NONE FullAuto.state = State.NONE
self.gui.bot_started(True) self.gui.bot_started(True)
fishing_event.unsubscribe()
self.fisher.toggle_start()
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug") self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
try: try:
self.window.crop = get_qr_location(self.window.get_capture()) self.window.crop = get_qr_location(self.window.get_capture())
if self.window.crop is None: if self.window.crop is None:
print("FishyQR not found") logging.warning("FishyQR not found")
self.start = False self.start = False
raise Exception("FishyQR not found")
if not self.calibrate.all_callibrated(): if not self.calibrator.all_callibrated():
logging.error("you need to callibrate first") logging.error("you need to calibrate first")
self.fisher.toggle_start()
fishing_event.unsubscribe()
self.controls.initialize() self.controls.initialize()
while self.start and WindowClient.running(): while self.start and WindowClient.running():
@ -115,7 +117,7 @@ class FullAuto(IEngine):
logging.error("set target first") logging.error("set target first")
return return
if not self.calibrate.all_callibrated(): if not self.calibrator.all_callibrated():
logging.error("you need to callibrate first") logging.error("you need to callibrate first")
return return
@ -134,7 +136,7 @@ class FullAuto(IEngine):
self.rotate_to(target_angle, from_angle) self.rotate_to(target_angle, from_angle)
walking_time = dist / self.calibrate.move_factor walking_time = dist / self.calibrator.move_factor
print(f"walking for {walking_time}") print(f"walking for {walking_time}")
kb.press('w') kb.press('w')
time.sleep(walking_time) time.sleep(walking_time)
@ -156,7 +158,7 @@ class FullAuto(IEngine):
if abs(angle_diff) > 180: if abs(angle_diff) > 180:
angle_diff = (360 - abs(angle_diff)) * sign(angle_diff) * -1 angle_diff = (360 - abs(angle_diff)) * sign(angle_diff) * -1
rotate_times = int(angle_diff / self.calibrate.rot_factor) * -1 rotate_times = int(angle_diff / self.calibrator.rot_factor) * -1
print(f"rotate_times: {rotate_times}") print(f"rotate_times: {rotate_times}")
@ -177,7 +179,7 @@ class FullAuto(IEngine):
fishing_mode.subscribers.append(found_hole) fishing_mode.subscribers.append(found_hole)
t = 0 t = 0
while not self._hole_found_flag and t <= self.calibrate.time_to_reach_bottom / 3: while not self._hole_found_flag and t <= 4.47:
mse.move(0, FullAuto.rotate_by) mse.move(0, FullAuto.rotate_by)
time.sleep(0.05) time.sleep(0.05)
t += 0.05 t += 0.05