From 1f7b58d07e5451ac9a11f808b5eeecad53091dd8 Mon Sep 17 00:00:00 2001 From: Juice-XIJ Date: Tue, 7 Jun 2022 13:33:06 -0700 Subject: [PATCH] fix orpm calculation (#46) --- README.md | 2 +- constants.py | 2 +- forza.py | 14 +++++++------- gear_helper.py | 5 +++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0afbc57..55452d4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ forza_auto_gear is a tool for Forza Horizon 5. It will help us understand the be ## Quick View GUI Demo -![gui demo](./img/demo.gif) +[Demo](https://www.bilibili.com/video/BV11R4y1A7jA/) A800, GTR93, Aerodromo Drag Strip - Automatic (00:27.665): diff --git a/constants.py b/constants.py index 18c8438..86b4357 100644 --- a/constants.py +++ b/constants.py @@ -96,7 +96,7 @@ class ConfigVersion(enum.Enum): blipThrottleDuration = 0.12 # blip the throttle duration. Should be short since keyboard is 100% acceleration output # === Gear Shift Settings === -shift_factor = 0.99 +shift_factor = 0.97 offroad_rally_shift_factor = 0.93 # === Test Settings === diff --git a/forza.py b/forza.py index 78a6586..cade3bb 100644 --- a/forza.py +++ b/forza.py @@ -300,7 +300,7 @@ def shifting(self, iteration, fdp): # When gear < 3, the upshift target rpm and speed would be a little bit (95%) lower than AWD when (slip >= 1 or angle_slip >= 1) # at low gear (<= 3) if gear < 3 and (angle_slip >= 1 or slip >= 1): - fired = self.__up_shift(rpm, target_rpm * 0.95, speed, target_up_speed * 0.95, slips, iteration, gear, fdp) + fired = self.__up_shift(rpm, target_rpm, speed, target_up_speed, slips, iteration, gear, fdp) else: fired = self.__up_shift(rpm, target_rpm, speed, target_up_speed, slips, iteration, gear, fdp) else: @@ -319,8 +319,8 @@ def shifting(self, iteration, fdp): # RWD logic if self.car_drivetrain == 1: - # don't down shift to gear 1, 2 when RWD - if gear >= 4: + # don't down shift to gear 1 when RWD + if gear >= 3: self.__down_shift(speed, target_down_speed, slips, iteration, gear, fdp) else: self.__down_shift(speed, target_down_speed, slips, iteration, gear, fdp) @@ -343,8 +343,8 @@ def __up_shift(self, rpm, target_rpm, speed, target_up_speed, slips, iteration, Returns: _type_: _description_ """ - if rpm > target_rpm and slips[0] < 1 and slips[1] < 1 and speed > target_up_speed: - self.logger.debug(f'[{iteration}] up shift triggerred. rpm > target rmp({rpm} > {target_rpm}), speed > target up speed ({speed} > {target_up_speed}), slips {slips}') + if rpm > target_rpm and slips[0] < 1 and speed > target_up_speed: + self.logger.debug(f'[{iteration}] up shift triggered. rpm > target rmp({rpm} > {target_rpm}), speed > target up speed ({speed} > {target_up_speed}), slips {slips}') gear_helper.up_shift_handle(gear, self) return True else: @@ -361,8 +361,8 @@ def __down_shift(self, speed, target_down_speed, slips, iteration, gear, fdp): gear (int): current gear fdp (ForzaPackage): Forza Package """ - if speed < target_down_speed * 0.95 and slips[0] < 1 and slips[1] < 1 and slips[2] < 0.9 and slips[3] < 0.9: - self.logger.debug(f'[{iteration}] down shift triggerred. speed < target down speed ({speed} < {target_down_speed}), slips {slips}') + if speed < target_down_speed * 0.95 and slips[0] < 1: + self.logger.debug(f'[{iteration}] down shift triggered. speed < target down speed ({speed} < {target_down_speed}), slips {slips}') gear_helper.down_shift_handle(gear, self) def run(self, update_tree_func=lambda *args: None, update_car_gui_func=lambda *args: None): diff --git a/gear_helper.py b/gear_helper.py index 16ba49d..94384a2 100644 --- a/gear_helper.py +++ b/gear_helper.py @@ -199,7 +199,7 @@ def calculate_optimal_shift_point(forza: CarInfo): torque = get_torque(r, rpm_to_torque) / ratio torque1 = get_torque(r / ratio1 * ratio, rpm_to_torque1) / ratio1 delta = torque - torque1 - if abs(delta) < min_dt_torque and torque > torqueo: + if abs(delta) < min_dt_torque and torque >= torqueo and r >= rpmo: rpmo = r min_dt_torque = delta torqueo = torque @@ -233,7 +233,6 @@ def up_shift_handle(gear: int, forza: CarInfo): cur = time.time() if gear < forza.maxGear and cur - forza.last_upshift >= constants.upShiftCoolDown: forza.logger.info(f'[UpShift] up shift fired. gear < maxGear ({gear}, {forza.maxGear}) and gap >= upShiftCoolDown ({cur - forza.last_upshift}, {constants.upShiftCoolDown})') - forza.last_upshift = cur if forza.clutch: def press(): @@ -252,6 +251,8 @@ def press(): # release clutch keyboard_helper.release_str(forza.clutch) forza.logger.debug(f'[UpShift] clutch {forza.clutch} up on {gear}') + + forza.last_upshift = cur else: forza.logger.debug(f'[UpShift] skip up shift. gear >= maxGear ({gear}, {forza.maxGear}) or gap < upShiftCoolDown ({cur - forza.last_upshift}, {constants.upShiftCoolDown})')