Skip to content

Commit

Permalink
fix orpm calculation (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juice-XIJ authored Jun 7, 2022
1 parent 0b90a93 commit 1f7b58d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down
14 changes: 7 additions & 7 deletions forza.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions gear_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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})')

Expand Down

0 comments on commit 1f7b58d

Please sign in to comment.