Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electric motor in a vehicle has much less power when the vehicle is going backwards #38165

Closed
l29ah opened this issue Feb 19, 2020 · 5 comments · Fixed by #38212
Closed

Electric motor in a vehicle has much less power when the vehicle is going backwards #38165

l29ah opened this issue Feb 19, 2020 · 5 comments · Fixed by #38212
Labels
<Bug> This needs to be fixed Vehicles Vehicles, parts, mechanics & interactions

Comments

@l29ah
Copy link
Contributor

l29ah commented Feb 19, 2020

Describe the bug

Steps To Reproduce

Install an electric motor on a heavy vehicle and find out it is not powerful enough to move backwards at all.

Expected behavior

It should be the same, since electric motors don't care about the direction of the rotation.

Screenshots

Versions and configuration

  • OS: Linux
    • OS Version:
  • Game Version: 0.D-12404-g1d23fcce1e-dirty [64-bit]
  • Graphics Version: Curses
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    Alternative Map Key [alt_map_key],
    Modular Turrets [modular_turrets],
    Salvaged Robots [Salvaged_Robots]
    ]

Additional context

@wapcaplet
Copy link
Contributor

wapcaplet commented Feb 21, 2020

It took a few tries, but I was able to reproduce the problem with an electric car, after replacing the regular electric motor with a "small electric motor", and adding a bunch of heavy frames and armor until the vehicle weighed over 5300 lbs. (Thanks to the Debug Hammer-space mutation!)

Now, I can accelerate forward (very slowly), but cannot move at all in reverse.

image

Glancing at the code, I see these lines in src/vehicle_move.cpp that appear to calculate the maximum reverse velocity as 1/4 of the forward velocity when cruise control is on. And, because it's doing integer division, I guess if forward velocity is any less than 3, reverse will bottom out to 0.

int max_vel = max_velocity();
int max_rev_vel = -max_vel / 4;

Whether a vehicle uses a gearbox or not, I should think if forward movement is possible, then reverse movement should also be possible, even if it's slower. I will try a fix and submit a PR.

The corresponding math when you have cruise control turned off is a little different:

//accelerate 60% if going backward
vel_inc = .6 * vel_inc;

Here it's at least using floating-point math, but in my testing I found that weight was even more of a problem with cruise control off. For example:

  • 4224 lbs, cruise control on: can go forward, not reverse
  • 4224 lbs, cruise control off: cannot move
  • 3800 lbs, cruise control off: can go forward, not reverse
  • 3700 lbs, cruise control off: can go forward and reverse

Edit Now I'm not sure I can trust these numbers, because I just loaded up the same car past 4500 lbs, and it can still drive with the small electric motor. Until I parked it on pavement and tried to drive it again - then I got "The Electric Car is too heavy for its engine(s)!" - I wonder if there's a similar vehicle weight calculation bug to what I observed in #38177 , where a STR 5 character was able to pull 200 kg of bricks in an unwheeled shopping cart.

@kevingranade
Copy link
Member

Whether a vehicle uses a gearbox or not, I should think if forward movement is possible, then reverse movement should also be possible, even if it's slower.

That is not correct, if reverse has less torque than 1st gear, it can absolutely stall the vehicle.

I agree it should not be applied for electric motors.

@eilaattwood
Copy link
Contributor

eilaattwood commented Feb 21, 2020

if reverse has less torque than 1st gear, it can absolutely stall the vehicle.

In almost all real gearboxes 1st gear and reverse are made almost equal, as far as i know.

@wapcaplet
Copy link
Contributor

In almost all real gearboxes 1st gear and reverse are made almost equal, as far as i know.

This is kind of what I was assuming too, at least from a gameplay perspective. It looks like gearboxes are not modeled at all in the current vehicle system; electric-power, pedal-power, animal-power, and diesel-power all have their reverse acceleration nerfed by the same amount. This crudely simulates the fact that real-world gearboxes only have a single reverse gear, while typically having multiple forward gears.

I guess it would be harder to pedal a bicycle in reverse without a lot of practice, but I don't see any mechanical reason pedals should be slower or have less torque in reverse. I've never ridden a unicycle, but they would seem ideally symmetrical, the seat being directly over the pedals.

Horses, I would have to do some more research but it's probably safe to assume they won't win any races running backwards.

My thinking for now is to simply check whether the vehicle has any battery-powered engines active, and avoid the power-reduction if so. Full gearbox implementation I think will have to wait.

@l29ah
Copy link
Contributor Author

l29ah commented Feb 21, 2020

As a side note, i wonder if modern car gasoline engines could actually rotate in reverse if the firmware understood such a mode of operation, or the valves are still operated mechanically by the engine shaft?

wapcaplet added a commit to wapcaplet/Cataclysm-DDA that referenced this issue Feb 21, 2020
Due to the downscaling of reverse power/speed for vehicle engines, it
can happen that a vehicle is so heavy, it can move forward but not
backward.

Because battery-powered electric motors can turn in either direction
with equal speed and torque, vehicles with electric motors should be
exempt from the power-reduction for reverse speeds.

This commit adds a new `vehicle::max_reverse_velocity` function as the
counterpart to `vehicle::max_velocity`, where an exception is made for
battery-powered motors. Here I suppose is where the maximum reverse
speed multiplier for horses, bicycles, and jet turbines would eventually
be made; for now it just checks for battery-powered motors.

Note, how *much* the motor is contributing to overall torque is not
calculated; the simple presence of any electric motor in the drivetrain
(no matter how small) ought to negate the reverse-power penalty.

Fixed CleverRaven#38165
@Night-Pryanik Night-Pryanik added <Bug> This needs to be fixed Vehicles Vehicles, parts, mechanics & interactions labels Feb 25, 2020
ZhilkinSerg pushed a commit that referenced this issue Apr 2, 2020
* Make electric motors go in reverse better

Due to the downscaling of reverse power/speed for vehicle engines, it
can happen that a vehicle is so heavy, it can move forward but not
backward.

Because battery-powered electric motors can turn in either direction
with equal speed and torque, vehicles with electric motors should be
exempt from the power-reduction for reverse speeds.

This commit adds a new `vehicle::max_reverse_velocity` function as the
counterpart to `vehicle::max_velocity`, where an exception is made for
battery-powered motors. Here I suppose is where the maximum reverse
speed multiplier for horses, bicycles, and jet turbines would eventually
be made; for now it just checks for battery-powered motors.

Note, how *much* the motor is contributing to overall torque is not
calculated; the simple presence of any electric motor in the drivetrain
(no matter how small) ought to negate the reverse-power penalty.

Fixed #38165

* Refactor vehicle_power_test.cpp for readability

This is mainly preliminary work for adding new test cases to cover the
changes I have made to maximum reverse speed; this vehicle power test
seemed like a suitable place to put them.

I had trouble understanding what this test was doing; refactoring it
into BDD-style expressions helped me grok it while making it a whole lot
easier for others to read in the future.

* Add vehicle reverse velocity tests

To minimally test the new `max_reverse_velocity` function, this commit
adds two test vehicles (scooter and electric scooter), and checks that:

- Combustion engine reverse velocity is 1/4 of forward
- Electric engine reverse velocity is equivalent to forward

Some additional refactoring of the helper functions is also done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bug> This needs to be fixed Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants