Skip to content

Commit

Permalink
support RWD up/down shifting logic (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juice-XIJ authored Apr 26, 2022
1 parent 702203e commit 57d6741
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions forza.py
Original file line number Diff line number Diff line change
@@ -258,20 +258,30 @@ def shifting(self, iteration, fdp):
rpm = fdp.current_engine_rpm
accel = fdp.accel
fired = False

# up shift logic
if gear < self.maxGear:
target_rpm = self.shift_point[gear]['rpmo'] * self.shift_point_factor
target_up_speed = int(self.shift_point[gear]['speed'] * self.shift_point_factor)
if rpm > target_rpm and slip < 1 and accel and speed > target_up_speed:

# if the car is RWD, then up gear when at gear 1
if self.car_drivetrain == 1 and gear == 1:
self.logger.debug(f'[{iteration}] up shift triggerred since RWD at gear 1. rpm {rpm}, speed {speed}, slip {slip}, accel {accel}')
fired = True
elif rpm > target_rpm and slip < 1 and accel 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}), slip {slip}, accel {accel}')
gear_helper.up_shift_handle(gear, self)
fired = True

# down shift logic
if not fired and gear > self.minGear:
lower_gear = gear - 1 if gear - 1 <= len(self.shift_point) else len(self.shift_point) - 1
target_down_speed = self.shift_point[lower_gear]['speed'] * self.shift_point_factor
if speed < target_down_speed * 0.95 and slip < 1:
self.logger.debug(f'[{iteration}] down shift triggerred. speed < target down speed ({speed} < {target_down_speed}), fired {fired}')
gear_helper.down_shift_handle(gear, self)
# don't down shift to gear 1 when RWD
if not (self.car_drivetrain == 1 and gear == 2):
lower_gear = gear - 1 if gear - 1 <= len(self.shift_point) else len(self.shift_point) - 1
target_down_speed = self.shift_point[lower_gear]['speed'] * self.shift_point_factor
if speed < target_down_speed * 0.95 and slip < 1:
self.logger.debug(f'[{iteration}] down shift triggerred. speed < target down speed ({speed} < {target_down_speed}), fired {fired}')
gear_helper.down_shift_handle(gear, self)

return iteration

0 comments on commit 57d6741

Please sign in to comment.